Documentation
¶
Index ¶
- Variables
- func BinOp_from_kind(token SyntaxKind) option.Option[BinOp]
- func Expr_cast_with_space(node *SyntaxNode) option.Option[Expr]
- func Expr_from_untyped(node *SyntaxNode) option.Option[Expr]
- func Expr_hash(expr Expr) bool
- func Expr_is_literal(expr Expr) bool
- func GraphemeLen(str string) (int, bool)
- func Node_is_ident(node *LinkedNode) bool
- func PrintNode(out io.Writer, node *SyntaxNode)
- func PrintRoot(root *SyntaxNode)
- func SyntaxNode_cast[T AstNode](node *SyntaxNode) option.Option[T]
- func SyntaxNode_cast_first[T AstNode](node *SyntaxNode) T
- func SyntaxNode_cast_last[T AstNode](node *SyntaxNode) T
- func SyntaxNode_is[T AstNode](node *SyntaxNode) bool
- func SyntaxNode_try_cast_first[T AstNode](node *SyntaxNode) option.Option[T]
- func SyntaxNode_try_cast_last[T AstNode](node *SyntaxNode) option.Option[T]
- func UnOp_from_kind(token SyntaxKind) option.Option[UnOp]
- type Arg
- type Arg_Named
- type Arg_Pos
- type Arg_Spread
- type Args
- type Array
- type ArrayItem
- type ArrayItem_Pos
- type ArrayItem_Spread
- type Assoc
- type AstNode
- type AtNewline
- type AtNewline_ContextualContinue
- type AtNewline_Continue
- type AtNewline_RequireColumn
- type AtNewline_Stop
- type AtNewline_StopParBreak
- type Auto
- type BinOp
- type Binary
- type Bool
- type Checkpoint
- type Closure
- type Code
- type CodeBlock
- type Conditional
- type ContentBlock
- type Contextual
- type DestructAssignment
- type Destructuring
- type DestructuringItem
- type DestructuringItem_Named
- type DestructuringItem_Pattern
- type DestructuringItem_Spread
- type Dict
- type DictItem
- type DictItem_Keyed
- type DictItem_Named
- type DictItem_Spread
- type Emph
- type EnumItem
- type Equation
- type ErrorNode
- type Escape
- type Expr
- type FieldAccess
- type FileID
- type Float
- type ForLoop
- type FuncCall
- type FuncReturn
- type GroupState
- type Heading
- type Ident
- type ImportItem
- type ImportItemPath
- type ImportItem_Renamed
- type ImportItem_Simple
- type ImportItems
- type Imports
- type Imports_Items
- type Imports_Wildcard
- type InnerNode
- type Int
- type Interner
- type Keyed
- type Label
- type LeafNode
- type LetBinding
- type LetBindingKind
- type LetBindingKind_Closure
- type LetBindingKind_Normal
- type Lexer
- type Line
- type Linebreak
- type Lines
- func (l *Lines) ByteToColumn(byteIdx uint) (uint, bool)
- func (l *Lines) ByteToLine(byteIdx uint) (uint, bool)
- func (l *Lines) ByteToLineColumn(byteIdx uint) (Position, bool)
- func (l *Lines) ByteToUtf16(byteIdx uint) (uint, bool)
- func (l *Lines) Edit(replace ranges.Range, with string)
- func (l *Lines) LenBytes() uint
- func (l *Lines) LenLines() uint
- func (l *Lines) LenUtf16() uint
- func (l *Lines) LineColumnToByte(lineIdx uint, columnIdx uint) (uint, bool)
- func (l *Lines) LineToByte(lineIdx uint) (uint, bool)
- func (l *Lines) LineToRange(lineIdx uint) (ranges.Range, bool)
- func (l *Lines) Replace(new string) bool
- func (l *Lines) ReplacementRange(new string) (ReplacementRange, bool)
- func (l *Lines) Utf16ToByte(utf16Idx uint) (uint, bool)
- type Link
- type LinkedChildren
- type LinkedNode
- type ListItem
- type LoopBreak
- type LoopContinue
- type Marker
- type Markup
- type Math
- type MathAlignPoint
- type MathAttach
- type MathDelimited
- type MathFrac
- type MathIdent
- type MathOp
- type MathPrimes
- type MathRoot
- type MathShorthand
- type MathText
- type MathTextKind
- type MathTextKind_Character
- type MathTextKind_Number
- type MemoArena
- type MemoCheckpoint
- type MemoKey
- type MemoPair
- type ModuleImport
- type ModuleInclude
- type Named
- type Newline
- type None
- type Numeric
- type PackageInfo
- type PackageManifest
- type PackageSpec
- type PackageVersion
- func (v PackageVersion) MatchesEQ(bound *VersionBound) bool
- func (v PackageVersion) MatchesGE(bound *VersionBound) bool
- func (v PackageVersion) MatchesGT(bound *VersionBound) bool
- func (v PackageVersion) MatchesLE(bound *VersionBound) bool
- func (v PackageVersion) MatchesLT(bound *VersionBound) bool
- func (v PackageVersion) String() string
- func (v *PackageVersion) UnmarshalText(text []byte) error
- type Pair
- type Param
- type Param_Named
- type Param_Pos
- type Param_Spread
- type Params
- type Parbreak
- type Parenthesized
- type Parser
- type PartialState
- type Pattern
- type Pattern_Destructuring
- type Pattern_Normal
- type Pattern_Parenthesized
- type Pattern_Placeholder
- type Position
- type Raw
- type RawDelim
- type RawLang
- type Ref
- type RenamedImportItem
- type ReplacementRange
- type Repr
- type SetRule
- type Shorthand
- type ShowRule
- type Side
- type SmartQuote
- type Source
- type Space
- type Span
- func AstNode_span(node AstNode) Span
- func FindFirstNonDetached(spans iter.Seq[Span]) Span
- func NewDetachedSpan() Span
- func NewSpanFromNumber(id FileID, number uint64) (Span, bool)
- func NewSpanFromRange(id FileID, byteRange ranges.Range) Span
- func NewSpanFromUint64(v uint64) Span
- func NewSpanPacked(id FileID, low uint64) Span
- type Spanned
- type Spread
- type Str
- type Strong
- type SyntaxError
- type SyntaxKind
- func (kind SyntaxKind) IsBlock() bool
- func (kind SyntaxKind) IsError() bool
- func (kind SyntaxKind) IsGrouping() bool
- func (kind SyntaxKind) IsKeyword() bool
- func (kind SyntaxKind) IsStmt() bool
- func (kind SyntaxKind) IsTerminator() bool
- func (kind SyntaxKind) IsTrivia() bool
- func (kind SyntaxKind) Name() string
- func (kind SyntaxKind) String() string
- type SyntaxMode
- type SyntaxNode
- func NewError(error *SyntaxError, text string) *SyntaxNode
- func NewInner(kind SyntaxKind, children []*SyntaxNode) *SyntaxNode
- func NewLeaf(kind SyntaxKind, text string) *SyntaxNode
- func Parse(text string) *SyntaxNode
- func SyntaxNode_Default() *SyntaxNode
- func SyntaxNode_placeholder(kind SyntaxKind) *SyntaxNode
- type SyntaxSet
- type Tag
- type TemplateInfo
- type TermItem
- type Text
- type Token
- type ToolInfo
- type UnOp
- type Unary
- type Underscore
- type Unit
- type UnknownFields
- type VersionBound
- type VersionlessPackageSpec
- type VirtualPath
- type WhileLoop
Constants ¶
This section is empty.
Variables ¶
var ( // There is no statically resolvable binding name. ErrBareImport_Dynamic = errors.New("there is no statically resolvable binding name") // The import source is not a valid path or the path stem not a valid // identifier. ErrBareImport_PathInvalid = errors.New("the import source is not a valid path or the path stem not a valid identifier") // The import source is not a valid package spec. ErrBareImport_PackageInvalid = errors.New("the import source is not a valid package spec") )
Reasons why a bare name cannot be determined for an import source.
BareImportError
var ArgSet = CodeExprSet.Add(SyntaxKindDots)
ArgSet contains syntax kinds that can start an argument in a function call.
var ArrayOrDictItemSet = CodeExprSet.Add(SyntaxKindDots)
ArrayOrDictItemSet contains syntax kinds that can start an argument in a function call.
var AtomicCodeExprSet = AtomicCodePrimarySet
AtomicCodeExprSet contains syntax kinds that can start an atomic code expression.
var AtomicCodePrimarySet = NewSyntaxSet( SyntaxKindIdent, SyntaxKindLeftBrace, SyntaxKindLeftBracket, SyntaxKindLeftParen, SyntaxKindDollar, SyntaxKindLet, SyntaxKindSet, SyntaxKindShow, SyntaxKindContext, SyntaxKindIf, SyntaxKindWhile, SyntaxKindFor, SyntaxKindImport, SyntaxKindInclude, SyntaxKindBreak, SyntaxKindContinue, SyntaxKindReturn, SyntaxKindNone, SyntaxKindAuto, SyntaxKindInt, SyntaxKindFloat, SyntaxKindBool, SyntaxKindNumeric, SyntaxKindStr, SyntaxKindLabel, SyntaxKindRaw, )
AtomicCodePrimarySet contains syntax kinds that can start an atomic code primary.
var BinaryOpSet = NewSyntaxSet( SyntaxKindPlus, SyntaxKindMinus, SyntaxKindStar, SyntaxKindSlash, SyntaxKindAnd, SyntaxKindOr, SyntaxKindEqEq, SyntaxKindExclEq, SyntaxKindLt, SyntaxKindLtEq, SyntaxKindGt, SyntaxKindGtEq, SyntaxKindEq, SyntaxKindIn, SyntaxKindPlusEq, SyntaxKindHyphEq, SyntaxKindStarEq, SyntaxKindSlashEq, )
BinaryOpSet contains syntax kinds that are binary operators.
var CodeExprSet = CodePrimarySet.Union(UnaryOpSet)
CodeExprSet contains syntax kinds that can start a code expression.
var CodePrimarySet = AtomicCodePrimarySet.Add(SyntaxKindUnderscore)
CodePrimarySet contains syntax kinds that can start a code primary.
var DestructuringItemSet = PatternSet.Add(SyntaxKindDots)
DestructuringItemSet contains syntax kinds that can start a destructuring item.
var ErrUnnumberable = errors.New("cannot number within this interval")
Indicates that a node cannot be numbered within a given interval.
var MathExprSet = NewSyntaxSet( SyntaxKindHash, SyntaxKindMathIdent, SyntaxKindFieldAccess, SyntaxKindDot, SyntaxKindComma, SyntaxKindSemicolon, SyntaxKindRightParen, SyntaxKindText, SyntaxKindMathText, SyntaxKindMathShorthand, SyntaxKindLinebreak, SyntaxKindMathAlignPoint, SyntaxKindEscape, SyntaxKindStr, SyntaxKindRoot, SyntaxKindPrime, )
MathExprSet contains syntax kinds that can start a math expression.
var MathShorthand_LIST = map[string]rune{
"...": '…',
"-": '−',
"*": '∗',
"~": '∼',
"!=": '≠',
":=": '≔',
"::=": '⩴',
"=:": '≕',
"<<": '≪',
"<<<": '⋘',
">>": '≫',
">>>": '⋙',
"<=": '≤',
">=": '≥',
"->": '→',
"-->": '⟶',
"|->": '↦',
">->": '↣',
"->>": '↠',
"<-": '←',
"<--": '⟵',
"<-<": '↢',
"<<-": '↞',
"<->": '↔',
"<-->": '⟷',
"~>": '⇝',
"~~>": '⟿',
"<~": '⇜',
"<~~": '⬳',
"=>": '⇒',
"|=>": '⤇',
"==>": '⟹',
"<==": '⟸',
"<=>": '⇔',
"<==>": '⟺',
"[|": '⟦',
"|]": '⟧',
"||": '‖',
}
A list of all shorthands in math mode.
var ParamSet = PatternSet.Add(SyntaxKindDots)
ParamSet contains syntax kinds that can start a parameter in a parameter list.
var PatternLeafSet = AtomicCodeExprSet
PatternLeafSet contains syntax kinds that can start a pattern leaf.
var PatternSet = PatternLeafSet.Add(SyntaxKindLeftParen).Add(SyntaxKindUnderscore)
PatternSet contains syntax kinds that can start a pattern.
var Shorthand_LIST = map[string]rune{
"...": '…',
"~": '\u00A0',
"-": '\u2212',
"--": '\u2013',
"---": '\u2014',
"-?": '\u00AD',
}
A list of all shorthands in markup mode.
LIST
var ( // The full range of numbers available for source file span numbering. SpanFull = ranges.NewRange(2, rangeBase) )
var StmtSet = NewSyntaxSet( SyntaxKindLet, SyntaxKindSet, SyntaxKindShow, SyntaxKindImport, SyntaxKindInclude, SyntaxKindReturn, )
StmtSet contains syntax kinds that can start a statement.
var TABLE = [128]bool{ ' ': true, '\t': true, '\n': true, '\x0b': true, '\x0c': true, '\r': true, '\\': true, '/': true, '[': true, ']': true, '~': true, '-': true, '.': true, '\'': true, '"': true, '*': true, '_': true, ':': true, 'h': true, '`': true, '$': true, '<': true, '>': true, '@': true, '#': true, }
var UnaryOpSet = NewSyntaxSet( SyntaxKindPlus, SyntaxKindMinus, SyntaxKindNot, )
UnaryOpSet contains syntax kinds that are unary operators.
Functions ¶
func BinOp_from_kind ¶
func BinOp_from_kind(token SyntaxKind) option.Option[BinOp]
Try to convert the token into a binary operation.
from_kind
func Expr_cast_with_space ¶
func Expr_cast_with_space(node *SyntaxNode) option.Option[Expr]
cast_with_space
func Node_is_ident ¶
func Node_is_ident(node *LinkedNode) bool
Whether the node is one of the two identifier nodes.
is_ident
func PrintNode ¶
func PrintNode(out io.Writer, node *SyntaxNode)
func PrintRoot ¶
func PrintRoot(root *SyntaxNode)
func SyntaxNode_cast ¶
func SyntaxNode_cast[T AstNode](node *SyntaxNode) option.Option[T]
Try to convert the node to a typed AST node.
cast
func SyntaxNode_cast_first ¶
func SyntaxNode_cast_first[T AstNode](node *SyntaxNode) T
Get the first child of AST type `T` or a placeholder if none.
cast_first
func SyntaxNode_cast_last ¶
func SyntaxNode_cast_last[T AstNode](node *SyntaxNode) T
Get the last child of AST type `T` or a placeholder if none.
cast_last
func SyntaxNode_is ¶
func SyntaxNode_is[T AstNode](node *SyntaxNode) bool
Whether the node can be cast to the given AST node.
is
func SyntaxNode_try_cast_first ¶
func SyntaxNode_try_cast_first[T AstNode](node *SyntaxNode) option.Option[T]
Find the first child that can cast to the AST type `T`.
try_cast_first
func SyntaxNode_try_cast_last ¶
func SyntaxNode_try_cast_last[T AstNode](node *SyntaxNode) option.Option[T]
Find the last child that can cast to the AST type `T`.
try_cast_last
func UnOp_from_kind ¶
func UnOp_from_kind(token SyntaxKind) option.Option[UnOp]
Try to convert the token into a unary operation.
Types ¶
type Arg ¶
type Arg interface { AstNode // contains filtered or unexported methods }
An argument to a function call.
type Arg_Named ¶
type Arg_Named struct {
// contains filtered or unexported fields
}
A named argument: `draw: false`.
Named
type Arg_Pos ¶
type Arg_Pos struct {
// contains filtered or unexported fields
}
A positional argument: `12`.
Pos
type Arg_Spread ¶
type Arg_Spread struct {
// contains filtered or unexported fields
}
A spread argument: `..things`.
Spread
type Args ¶
type Args struct {
*SyntaxNode
}
A function call's argument list: `(12pt, y)`.
func Args_default ¶
func Args_default() *Args
type Array ¶
type Array struct {
*SyntaxNode
}
An array: `(1, "hi", 12cm)`.
func Array_default ¶
func Array_default() *Array
type ArrayItem ¶
type ArrayItem interface { AstNode // contains filtered or unexported methods }
An item in an array.
type ArrayItem_Pos ¶
type ArrayItem_Pos struct {
// contains filtered or unexported fields
}
A bare expression: `12`.
Pos
type ArrayItem_Spread ¶
type ArrayItem_Spread struct {
// contains filtered or unexported fields
}
A spread expression: `..things`.
Spread
type AstNode ¶
type AstNode interface {
// contains filtered or unexported methods
}
A typed AST node.
type AtNewline ¶
type AtNewline interface {
// contains filtered or unexported methods
}
How to proceed with parsing when at a newline.
type AtNewline_ContextualContinue ¶
type AtNewline_ContextualContinue struct{}
Continue only if there is a continuation with `else` or `.` (Code only).
ContextualContinue
type AtNewline_RequireColumn ¶
type AtNewline_RequireColumn struct {
// contains filtered or unexported fields
}
Require that the token's column be greater or equal to a column (Markup only). If this is `0`, acts like `Continue`; if this is `usize::MAX`, acts like `Stop`.
RequireColumn
func NewAtNewline_RequireColumn ¶
func NewAtNewline_RequireColumn(min_col uint) *AtNewline_RequireColumn
type AtNewline_StopParBreak ¶
type AtNewline_StopParBreak struct{}
Stop only at a parbreak, not normal newlines (Markup only).
StopParBreak
type Auto ¶
type Auto struct {
*SyntaxNode
}
The `auto` literal.
func Auto_default ¶
func Auto_default() *Auto
type BinOp ¶
type BinOp uint8
A binary operator.
const ( // The addition operator: `+`. // // Add BinOp_Add BinOp = iota + 1 // The subtraction operator: `-`. // // Sub BinOp_Sub // The multiplication operator: `*`. // // Mul BinOp_Mul // The division operator: `/`. // // Div BinOp_Div // The short-circuiting boolean `and`. // // And BinOp_And // The short-circuiting boolean `or`. // // Or BinOp_Or // The equality operator: `==`. // // Eq BinOp_Eq // The inequality operator: `!=`. // // Neq BinOp_Neq // The less-than operator: `<`. // // Lt BinOp_Lt // The less-than or equal operator: `<=`. // // Leq BinOp_Leq // The greater-than operator: `>`. // // Gt BinOp_Gt // The greater-than or equal operator: `>=`. // // Geq BinOp_Geq // The assignment operator: `=`. // // Assign BinOp_Assign // The containment operator: `in`. // // In BinOp_In // The inverse containment operator: `not in`. // // NotIn BinOp_NotIn // The add-assign operator: `+=`. // // AddAssign BinOp_AddAssign // The subtract-assign operator: `-=`. // // SubAssign BinOp_SubAssign // The multiply-assign operator: `*=`. // // MulAssign BinOp_MulAssign // The divide-assign operator: `/=`. // // DivAssign BinOp_DivAssign )
type Binary ¶
type Binary struct {
*SyntaxNode
}
A binary operation: `a + b`.
func Binary_default ¶
func Binary_default() *Binary
type Bool ¶
type Bool struct {
*SyntaxNode
}
A boolean: `true`, `false`.
func Bool_default ¶
func Bool_default() *Bool
type Checkpoint ¶
type Checkpoint struct {
// contains filtered or unexported fields
}
A checkpoint of the parser which can fully restore it to a previous state.
type Closure ¶
type Closure struct {
*SyntaxNode
}
A closure: `(x, y) => z`.
func Closure_default ¶
func Closure_default() *Closure
type Code ¶
type Code struct {
*SyntaxNode
}
The body of a code block.
func Code_default ¶
func Code_default() *Code
type CodeBlock ¶
type CodeBlock struct {
*SyntaxNode
}
A code block: `{ let x = 1; x + 2 }`.
func CodeBlock_default ¶
func CodeBlock_default() *CodeBlock
type Conditional ¶
type Conditional struct {
*SyntaxNode
}
An if-else conditional: `if x { y } else { z }`.
func Conditional_default ¶
func Conditional_default() *Conditional
type ContentBlock ¶
type ContentBlock struct {
*SyntaxNode
}
A content block: `[*Hi* there!]`.
func ContentBlock_default ¶
func ContentBlock_default() *ContentBlock
type Contextual ¶
type Contextual struct {
*SyntaxNode
}
A contextual expression: `context text.lang`.
func Contextual_default ¶
func Contextual_default() *Contextual
type DestructAssignment ¶
type DestructAssignment struct {
*SyntaxNode
}
An assignment expression `(x, y) = (1, 2)`.
func DestructAssignment_default ¶
func DestructAssignment_default() *DestructAssignment
type Destructuring ¶
type Destructuring struct {
*SyntaxNode
}
A destructuring pattern: `x` or `(x, _, ..y)`.
func Destructuring_default ¶
func Destructuring_default() *Destructuring
type DestructuringItem ¶
type DestructuringItem interface { AstNode // contains filtered or unexported methods }
The kind of an element in a destructuring pattern.
type DestructuringItem_Named ¶
type DestructuringItem_Named struct {
// contains filtered or unexported fields
}
A renamed destructuring: `x: y`.
Named
type DestructuringItem_Pattern ¶
type DestructuringItem_Pattern struct {
// contains filtered or unexported fields
}
A sub-pattern: `x`.
Pattern
type DestructuringItem_Spread ¶
type DestructuringItem_Spread struct {
// contains filtered or unexported fields
}
A destructuring sink: `..y` or `..`.
Spread
type Dict ¶
type Dict struct {
*SyntaxNode
}
A dictionary: `(thickness: 3pt, dash: "solid")`.
func Dict_default ¶
func Dict_default() *Dict
type DictItem ¶
type DictItem interface { AstNode // contains filtered or unexported methods }
An item in an dictionary expression.
type DictItem_Keyed ¶
type DictItem_Keyed struct {
// contains filtered or unexported fields
}
A keyed pair: `"spacy key": true`.
Keyed
type DictItem_Named ¶
type DictItem_Named struct {
// contains filtered or unexported fields
}
A named pair: `thickness: 3pt`.
Named
type DictItem_Spread ¶
type DictItem_Spread struct {
// contains filtered or unexported fields
}
A spread expression: `..things`.
Spread
type Emph ¶
type Emph struct {
*SyntaxNode
}
Emphasized content: `_Emphasized_`.
func Emph_default ¶
func Emph_default() *Emph
type EnumItem ¶
type EnumItem struct {
*SyntaxNode
}
An item in an enumeration (numbered list): `+ ...` or `1. ...`.
func EnumItem_default ¶
func EnumItem_default() *EnumItem
type Equation ¶
type Equation struct {
*SyntaxNode
}
A mathematical equation: `$x$`, `$ x^2 $`.
func Equation_default ¶
func Equation_default() *Equation
type ErrorNode ¶
type ErrorNode struct { // The source text of the node. Text string // The syntax error. Error *SyntaxError }
An error node in the untyped syntax tree.
func NewErrorNode ¶
func NewErrorNode(error *SyntaxError, text string) *ErrorNode
Create new error node.
new
func (*ErrorNode) SyntaxKind ¶
func (*ErrorNode) SyntaxKind() SyntaxKind
type Escape ¶
type Escape struct {
*SyntaxNode
}
An escape sequence: `\#`, `\u{1F5FA}`.
func Escape_default ¶
func Escape_default() *Escape
type Expr ¶
type Expr interface { AstNode // contains filtered or unexported methods }
An expression in markup, math or code.
type FieldAccess ¶
type FieldAccess struct {
*SyntaxNode
}
A field access: `properties.age`.
func FieldAccess_default ¶
func FieldAccess_default() *FieldAccess
type FileID ¶
type FileID uint16 // NonZeroU16
FileID identifies a file in a project or package.
This type is globally interned and thus cheap to copy, compare, and hash.
func FileIDFromUint16 ¶
FileIDFromUint16 constructs a FileID from a raw number.
Should only be used with numbers retrieved via Uint16. Misuse may result in panics.
func NewFakeFileID ¶
func NewFakeFileID(vpath *VirtualPath) FileID
NewFakeFileID creates a new unique ("fake") file specification, which is not accessible by vpath.
Caution: the ID returned is the *only* identifier of the file. Constructing a file ID with a path will not reuse it, even if the path is the same. This method should only be used for generating "virtual" file IDs such as content read from stdin.
func NewFileID ¶
func NewFileID(spec option.Option[*PackageSpec], vpath *VirtualPath) FileID
NewFileID creates a new interned file specification.
The path must start with a `/` or this function will panic. The path is normalized before interning.
func (FileID) Spec ¶
func (id FileID) Spec() option.Option[*PackageSpec]
Spec returns the package the file resides in, if any.
func (FileID) VPath ¶
func (id FileID) VPath() *VirtualPath
VPath returns the absolute and normalized path to the file within the project or package.
func (FileID) WithExtension ¶
WithExtension returns the same file location but with a different extension.
type Float ¶
type Float struct {
*SyntaxNode
}
A floating-point number: `1.2`, `10e-4`.
func Float_default ¶
func Float_default() *Float
type ForLoop ¶
type ForLoop struct {
*SyntaxNode
}
A for loop: `for x in y { z }`.
func ForLoop_default ¶
func ForLoop_default() *ForLoop
type FuncCall ¶
type FuncCall struct {
*SyntaxNode
}
An invocation of a function or method: `f(x, y)`.
func FuncCall_default ¶
func FuncCall_default() *FuncCall
type FuncReturn ¶
type FuncReturn struct {
*SyntaxNode
}
A return from a function: `return`, `return x + 1`.
func FuncReturn_default ¶
func FuncReturn_default() *FuncReturn
type GroupState ¶
type GroupState struct {
// contains filtered or unexported fields
}
State for array/dictionary parsing.
type Heading ¶
type Heading struct {
*SyntaxNode
}
A section heading: `= Introduction`.
func Heading_default ¶
func Heading_default() *Heading
type Ident ¶
type Ident struct {
*SyntaxNode
}
An identifier: `it`.
func Ident_default ¶
func Ident_default() *Ident
type ImportItem ¶
type ImportItem interface {
// contains filtered or unexported methods
}
An imported item, potentially renamed to another identifier.
type ImportItemPath ¶
type ImportItemPath struct {
*SyntaxNode
}
A path to a submodule's imported name: `a.b.c`.
func ImportItemPath_default ¶
func ImportItemPath_default() *ImportItemPath
type ImportItem_Renamed ¶
type ImportItem_Renamed struct {
// contains filtered or unexported fields
}
A renamed import (the item was bound to a different name in the scope than the one it was defined as).
Renamed
type ImportItem_Simple ¶
type ImportItem_Simple struct {
// contains filtered or unexported fields
}
A non-renamed import (the item's name in the scope is the same as its name).
Simple
type ImportItems ¶
type ImportItems struct {
*SyntaxNode
}
Items to import from a module: `a, b, c`.
func ImportItems_default ¶
func ImportItems_default() *ImportItems
type Imports ¶
type Imports interface {
// contains filtered or unexported methods
}
The items that ought to be imported from a file.
type Imports_Items ¶
type Imports_Items struct {
// contains filtered or unexported fields
}
The specified items from the file should be imported.
Items
type Imports_Wildcard ¶
type Imports_Wildcard struct { }
All items in the scope of the file should be imported.
Wildcard
type InnerNode ¶
type InnerNode struct { // What kind of node this is (each kind would have its own struct in a // strongly typed AST). Kind SyntaxKind // The byte length of the node in the source. Len uint // The node's span. Span Span // The number of nodes in the whole subtree, including this node. Descendants uint // Whether this node or any of its children are erroneous. Erroneous bool // The upper bound of this node's numbering range. Upper uint64 // This node's children, losslessly make up this node. Children []*SyntaxNode }
An inner node in the untyped syntax tree.
func NewInnerNode ¶
func NewInnerNode(kind SyntaxKind, children []*SyntaxNode) *InnerNode
Create a new inner node with the given kind and children.
new
func (*InnerNode) SyntaxKind ¶
func (node *InnerNode) SyntaxKind() SyntaxKind
type Int ¶
type Int struct {
*SyntaxNode
}
An integer: `120`.
func Int_default ¶
func Int_default() *Int
type Keyed ¶
type Keyed struct {
*SyntaxNode
}
A keyed pair: `"spacy key": true`.
func Keyed_default ¶
func Keyed_default() *Keyed
type Label ¶
type Label struct {
*SyntaxNode
}
A label: `<intro>`.
func Label_default ¶
func Label_default() *Label
type LeafNode ¶
type LeafNode struct { // What kind of node this is (each kind would have its own struct in a // strongly typed AST). Kind SyntaxKind // The source text of the node. Text string // The node's span. Span Span }
A leaf node in the untyped syntax tree.
func NewLeafNode ¶
func NewLeafNode(kind SyntaxKind, text string) *LeafNode
Create a new leaf node.
new
func (*LeafNode) SyntaxKind ¶
func (node *LeafNode) SyntaxKind() SyntaxKind
type LetBinding ¶
type LetBinding struct {
*SyntaxNode
}
A let binding: `let x = 1`.
func LetBinding_default ¶
func LetBinding_default() *LetBinding
type LetBindingKind ¶
type LetBindingKind interface {
// contains filtered or unexported methods
}
The kind of a let binding, either a normal one or a closure.
type LetBindingKind_Closure ¶
type LetBindingKind_Closure struct {
// contains filtered or unexported fields
}
A closure binding: `let f(x) = 1`.
Closure
type LetBindingKind_Normal ¶
type LetBindingKind_Normal struct {
// contains filtered or unexported fields
}
A normal binding: `let x = 1`.
Normal
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
An iterator over a source code string which returns tokens.
func NewLexer ¶
func NewLexer(text string, mode SyntaxMode) *Lexer
Create a new lexer with the given mode and a prefix to offset column calculations.
new
type Line ¶
type Line struct { // The UTF-8 byte offset where the line starts. ByteIdx uint // The UTF-16 code unit offset where the line starts. Utf16Idx uint }
Line represents metadata about a line.
type Linebreak ¶
type Linebreak struct {
*SyntaxNode
}
A forced line break: `\`.
func Linebreak_default ¶
func Linebreak_default() *Linebreak
type Lines ¶
Lines is a text buffer and metadata about lines.
This is internally reference-counted and thus cheap to clone.
func (*Lines) ByteToColumn ¶
ByteToColumn returns the index of the column at the byte index.
The column is defined as the number of characters in the line before the byte index. It returns false if the byte index is out of bounds.
func (*Lines) ByteToLine ¶
ByteToLine returns the index of the line that contains the given byte index.
It returns false if the byte index is out of bounds.
func (*Lines) ByteToLineColumn ¶
ByteToLineColumn returns the index of the line and column at the byte index.
It returns false if the byte index is out of bounds.
func (*Lines) ByteToUtf16 ¶
ByteToUtf16 returns the index of the UTF-16 code unit at the byte index.
It returns false if the byte index is out of bounds.
func (*Lines) Edit ¶
Edit edits the source file by replacing the given range.
The method panics if the replace range is out of bounds.
func (*Lines) LineColumnToByte ¶
LineColumnToByte returns the byte index of the given (line, column) pair.
The column defines the number of characters to go beyond the start of the line. It returns false if the line or column is out of bounds.
func (*Lines) LineToByte ¶
LineToByte returns the byte position at which the given line starts.
It returns false if the line index is out of bounds.
func (*Lines) LineToRange ¶
LineToRange returns the range which encloses the given line.
It returns false if the line index is out of bounds.
func (*Lines) Replace ¶
Replace fully replaces the source text.
It performs a naive (suffix/prefix-based) diff of the old and new text to produce the smallest single edit that transforms the old source into the new one.
It returns whether any changes were made.
func (*Lines) ReplacementRange ¶
func (l *Lines) ReplacementRange(new string) (ReplacementRange, bool)
ReplacementRange returns the common prefix and suffix lengths.
It returns false if the old and new strings are equal.
type Link ¶
type Link struct {
*SyntaxNode
}
A hyperlink: `https://typst.org`.
func Link_default ¶
func Link_default() *Link
type LinkedChildren ¶
type LinkedChildren struct {
// contains filtered or unexported fields
}
An iterator over the children of a linked node.
func (*LinkedChildren) Children ¶
func (l *LinkedChildren) Children() iter.Seq2[int, *LinkedNode]
func (*LinkedChildren) RevChildren ¶
func (l *LinkedChildren) RevChildren() iter.Seq2[int, *LinkedNode]
type LinkedNode ¶
type LinkedNode struct {
// contains filtered or unexported fields
}
A syntax node in a context.
Knows its exact offset in the file and provides access to its children, parent and siblings.
**Note that all sibling and leaf accessors skip over trivia!**
func NewLinkedNode ¶
func NewLinkedNode(root *SyntaxNode) *LinkedNode
Start a new traversal at a root node.
new
func (*LinkedNode) Range ¶
func (link *LinkedNode) Range() ranges.Range
The byte range of this node in the source file.
range
func (*LinkedNode) String ¶
func (link *LinkedNode) String() string
type ListItem ¶
type ListItem struct {
*SyntaxNode
}
An item in a bullet list: `- ...`.
func ListItem_default ¶
func ListItem_default() *ListItem
type LoopBreak ¶
type LoopBreak struct {
*SyntaxNode
}
A break from a loop: `break`.
func LoopBreak_default ¶
func LoopBreak_default() *LoopBreak
type LoopContinue ¶
type LoopContinue struct {
*SyntaxNode
}
A continue in a loop: `continue`.
func LoopContinue_default ¶
func LoopContinue_default() *LoopContinue
type Marker ¶
type Marker uint
A marker representing a node's position in the parser. Mainly used for wrapping, but can also index into the parser to access the node, like `p.index(m)`.
type Markup ¶
type Markup struct {
*SyntaxNode
}
The syntactical root capable of representing a full parsed document.
func Markup_default ¶
func Markup_default() *Markup
type Math ¶
type Math struct {
*SyntaxNode
}
The contents of a mathematical equation: `x^2 + 1`.
func Math_default ¶
func Math_default() *Math
type MathAlignPoint ¶
type MathAlignPoint struct {
*SyntaxNode
}
An alignment point in math: `&`.
func MathAlignPoint_default ¶
func MathAlignPoint_default() *MathAlignPoint
type MathAttach ¶
type MathAttach struct {
*SyntaxNode
}
A base with optional attachments in math: `a_1^2`.
func MathAttach_default ¶
func MathAttach_default() *MathAttach
type MathDelimited ¶
type MathDelimited struct {
*SyntaxNode
}
Matched delimiters in math: `[x + y]`.
func MathDelimited_default ¶
func MathDelimited_default() *MathDelimited
type MathFrac ¶
type MathFrac struct {
*SyntaxNode
}
A fraction in math: `x/2`
func MathFrac_default ¶
func MathFrac_default() *MathFrac
type MathIdent ¶
type MathIdent struct {
*SyntaxNode
}
An identifier in math: `pi`.
func MathIdent_default ¶
func MathIdent_default() *MathIdent
type MathPrimes ¶
type MathPrimes struct {
*SyntaxNode
}
Grouped primes in math: `a”'`.
func MathPrimes_default ¶
func MathPrimes_default() *MathPrimes
type MathRoot ¶
type MathRoot struct {
*SyntaxNode
}
A root in math: `√x`, `∛x` or `∜x`.
func MathRoot_default ¶
func MathRoot_default() *MathRoot
type MathShorthand ¶
type MathShorthand struct {
*SyntaxNode
}
A shorthand for a unicode codepoint in math: `a <= b`.
func MathShorthand_default ¶
func MathShorthand_default() *MathShorthand
type MathText ¶
type MathText struct {
*SyntaxNode
}
A lone text fragment in math: `x`, `25`, `3.1415`, `=`, `[`.
func MathText_default ¶
func MathText_default() *MathText
type MathTextKind ¶
type MathTextKind interface {
// contains filtered or unexported methods
}
The underlying text kind.
type MathTextKind_Character ¶
type MathTextKind_Character struct {
// contains filtered or unexported fields
}
type MathTextKind_Number ¶
type MathTextKind_Number struct {
// contains filtered or unexported fields
}
type MemoArena ¶
type MemoArena struct {
// contains filtered or unexported fields
}
Extra parser state for efficiently recovering from mispredicted parses.
This is the same idea as packrat parsing, but we use it only in the limited case of parenthesized structures. See [`expr_with_paren`] for more.
func NewMemoArena ¶
func NewMemoArena() *MemoArena
type MemoCheckpoint ¶
type MemoCheckpoint struct {
// contains filtered or unexported fields
}
type MemoKey ¶
type MemoKey uint
A type alias for the memo key so it doesn't get confused with other usizes.
The memo is keyed by the index into `text` of the current token's start.
type ModuleImport ¶
type ModuleImport struct {
*SyntaxNode
}
A module import: `import "utils.typ": a, b, c`.
func ModuleImport_default ¶
func ModuleImport_default() *ModuleImport
type ModuleInclude ¶
type ModuleInclude struct {
*SyntaxNode
}
A module include: `include "chapter1.typ"`.
func ModuleInclude_default ¶
func ModuleInclude_default() *ModuleInclude
type Named ¶
type Named struct {
*SyntaxNode
}
A named pair: `thickness: 3pt`.
func Named_default ¶
func Named_default() *Named
type Newline ¶
type Newline struct {
// contains filtered or unexported fields
}
Information about newlines in a group of trivia.
type None ¶
type None struct {
*SyntaxNode
}
The `none` literal.
func None_default ¶
func None_default() *None
type Numeric ¶
type Numeric struct {
*SyntaxNode
}
A numeric value with a unit: `12pt`, `3cm`, `2em`, `90deg`, `50%`.
func Numeric_default ¶
func Numeric_default() *Numeric
type PackageInfo ¶
type PackageInfo struct { // The name of the package within its namespace. Name string `toml:"name"` // The package's version. Version PackageVersion `toml:"version"` // The path of the entrypoint into the package. Entrypoint string `toml:"entrypoint"` // A list of the package's authors. Authors []string `toml:"authors,omitempty"` // The package's license. License string `toml:"license,omitempty"` // A short description of the package. Description string `toml:"description,omitempty"` // A link to the package's web presence. Homepage string `toml:"homepage,omitempty"` // A link to the repository where this package is developed. Repository string `toml:"repository,omitempty"` // An array of search keywords for the package. Keywords []string `toml:"keywords,omitempty"` // An array with up to three of the predefined categories to help users // discover the package. Categories []string `toml:"categories,omitempty"` // An array of disciplines defining the target audience for which the package // is useful. Disciplines []string `toml:"disciplines,omitempty"` // The minimum required compiler version for the package. Compiler *VersionBound `toml:"compiler,omitempty"` // An array of globs specifying files that should not be part of the // published bundle. Exclude []string `toml:"exclude,omitempty"` // All parsed but unknown fields, this can be used for validation. UnknownFields UnknownFields `toml:"-"` }
The `[package]` key in the manifest.
The `UnknownFields` contains fields which were found but not expected.
func NewPackageInfo ¶
func NewPackageInfo(name string, version PackageVersion, entrypoint string) *PackageInfo
NewPackageInfo creates a new package info with only required fields.
type PackageManifest ¶
type PackageManifest struct { // Details about the package itself. Pkg *PackageInfo `toml:"package"` // Details about the template, if the package is one. Template *TemplateInfo `toml:"template,omitempty"` // The tools section for third-party configuration. Tool *ToolInfo `toml:"tool,omitempty"` // All parsed but unknown fields, this can be used for validation. UnknownFields UnknownFields `toml:"-"` }
A parsed package manifest.
The `UnknownFields` contains fields which were found but not expected.
func NewPackageManifest ¶
func NewPackageManifest(pkg *PackageInfo) *PackageManifest
NewPackageManifest creates a new package manifest with the given package info.
func ParsePackageManifestFromToml ¶
func ParsePackageManifestFromToml(content string) (*PackageManifest, error)
func (*PackageManifest) Validate ¶
func (manifest *PackageManifest) Validate(spec *PackageSpec) error
Validate ensures that this manifest is indeed for the specified package.
type PackageSpec ¶
type PackageSpec struct { // The namespace the package lives in. Namespace string // The name of the package within its namespace. Name string // The package's version. Version PackageVersion }
PackageSpec identifies a package.
func ParsePackageSpec ¶
func ParsePackageSpec(str string) (*PackageSpec, error)
ParsePackageSpec parses a package spec from string.
func (*PackageSpec) Clone ¶
func (spec *PackageSpec) Clone() *PackageSpec
func (*PackageSpec) String ¶
func (spec *PackageSpec) String() string
func (*PackageSpec) Versionless ¶
func (spec *PackageSpec) Versionless() *VersionlessPackageSpec
type PackageVersion ¶
PackageVersion represents a package's version.
func CurrentCompilerVersion ¶
func CurrentCompilerVersion() PackageVersion
func ParsePackageVersion ¶
func ParsePackageVersion(str string) (PackageVersion, error)
ParsePackageVersion parses a version string.
func (PackageVersion) MatchesEQ ¶
func (v PackageVersion) MatchesEQ(bound *VersionBound) bool
MatchesEQ performs an `==` match with the given version bound. Version elements missing in the bound are ignored.
func (PackageVersion) MatchesGE ¶
func (v PackageVersion) MatchesGE(bound *VersionBound) bool
MatchesGE performs a `>=` match with the given versions. The match succeeds when either a `==` or `>` match does.
func (PackageVersion) MatchesGT ¶
func (v PackageVersion) MatchesGT(bound *VersionBound) bool
MatchesGT performs a `>` match with the given version bound. The match only succeeds if some version element in the bound is actually greater than that of the version.
func (PackageVersion) MatchesLE ¶
func (v PackageVersion) MatchesLE(bound *VersionBound) bool
MatchesLE performs a `<=` match with the given versions. The match succeeds when either a `==` or `<` match does.
func (PackageVersion) MatchesLT ¶
func (v PackageVersion) MatchesLT(bound *VersionBound) bool
MatchesLT performs a `<` match with the given version bound. The match only succeeds if some version element in the bound is actually less than that of the version.
func (PackageVersion) String ¶
func (v PackageVersion) String() string
func (*PackageVersion) UnmarshalText ¶
func (v *PackageVersion) UnmarshalText(text []byte) error
type Pair ¶
type Pair struct { Spec option.Option[*PackageSpec] VPath *VirtualPath }
Pair is an interned pair of a package specification and a path.
type Param ¶
type Param interface { AstNode // contains filtered or unexported methods }
A parameter to a closure.
type Param_Named ¶
type Param_Named struct {
// contains filtered or unexported fields
}
A named parameter with a default value: `draw: false`.
Named
type Param_Pos ¶
type Param_Pos struct {
// contains filtered or unexported fields
}
A positional parameter: `x`.
Pos
type Param_Spread ¶
type Param_Spread struct {
// contains filtered or unexported fields
}
An argument sink: `..args` or `..`.
Spread
type Params ¶
type Params struct {
*SyntaxNode
}
A closure's parameters: `(x, y)`.
func Params_default ¶
func Params_default() *Params
type Parbreak ¶
type Parbreak struct {
*SyntaxNode
}
A paragraph break, indicated by one or multiple blank lines.
func Parbreak_default ¶
func Parbreak_default() *Parbreak
type Parenthesized ¶
type Parenthesized struct {
*SyntaxNode
}
A grouped expression: `(1 + 2)`.
func Parenthesized_default ¶
func Parenthesized_default() *Parenthesized
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Manages parsing a stream of tokens into a tree of [`SyntaxNode`]s.
The implementation presents an interface that investigates a current `token` with a [`SyntaxKind`] and can take one of the following actions:
- Eat a token: push `token` onto the `nodes` vector as a [leaf node](`SyntaxNode::leaf`) and prepare a new `token` by calling into the lexer.
- Wrap nodes from a marker to the end of `nodes` (excluding `token` and any attached trivia) into an [inner node](`SyntaxNode::inner`) of a specific `SyntaxKind`.
- Produce or convert nodes into an [error node](`SyntaxNode::error`) when something expected is missing or something unexpected is found.
Overall the parser produces a nested tree of SyntaxNodes as a "_Concrete_ Syntax Tree." The raw Concrete Syntax Tree should contain the entire source text, and is used as-is for e.g. syntax highlighting and IDE features. In `ast.rs` the CST is interpreted as a lazy view over an "_Abstract_ Syntax Tree." The AST module skips over irrelevant tokens -- whitespace, comments, code parens, commas in function args, etc. -- as it iterates through the tree.
### Modes
The parser manages the transitions between the three modes of Typst through [syntax modes](`SyntaxMode`) and [newline modes](`AtNewline`).
The syntax modes map to the three Typst modes and are stored in the lexer, changing which `SyntaxKind`s it will generate.
The newline mode is used to determine whether a newline should end the current expression. If so, the parser temporarily changes `token`'s kind to a fake [`SyntaxKindEnd`]. When the parser exits the mode the original `SyntaxKind` is restored.
type PartialState ¶
type PartialState struct {
// contains filtered or unexported fields
}
State needed to restore the parser's current token and the lexer (but not the nodes vector).
func (*PartialState) Clone ¶
func (state *PartialState) Clone() *PartialState
type Pattern ¶
type Pattern interface { AstNode // contains filtered or unexported methods }
The kind of a pattern.
type Pattern_Destructuring ¶
type Pattern_Destructuring struct {
// contains filtered or unexported fields
}
A destructuring pattern: `(x, _, ..y)`.
Destructuring
type Pattern_Normal ¶
type Pattern_Normal struct {
// contains filtered or unexported fields
}
A single expression: `x`.
Normal
func Pattern_Normal_default ¶
func Pattern_Normal_default() *Pattern_Normal
type Pattern_Parenthesized ¶
type Pattern_Parenthesized struct {
// contains filtered or unexported fields
}
A parenthesized pattern.
Parenthesized
type Pattern_Placeholder ¶
type Pattern_Placeholder struct {
// contains filtered or unexported fields
}
A placeholder: `_`.
Placeholder
type Raw ¶
type Raw struct {
*SyntaxNode
}
Raw text with optional syntax highlighting: “ `...` “.
func Raw_default ¶
func Raw_default() *Raw
type RawDelim ¶
type RawDelim struct {
*SyntaxNode
}
A raw delimiter in single or 3+ backticks: “ ` “.
func RawDelim_default ¶
func RawDelim_default() *RawDelim
type RawLang ¶
type RawLang struct {
*SyntaxNode
}
A language tag at the start of raw element: “typ “.
func RawLang_default ¶
func RawLang_default() *RawLang
type Ref ¶
type Ref struct {
*SyntaxNode
}
A reference: `@target`, `@target[..]`.
func Ref_default ¶
func Ref_default() *Ref
type RenamedImportItem ¶
type RenamedImportItem struct {
*SyntaxNode
}
A renamed import item: `a as d`
func RenamedImportItem_default ¶
func RenamedImportItem_default() *RenamedImportItem
type ReplacementRange ¶
ReplacementRange holds the common prefix and suffix lengths.
type Repr ¶
type Repr interface { SyntaxKind() SyntaxKind // contains filtered or unexported methods }
The three internal representations.
type SetRule ¶
type SetRule struct {
*SyntaxNode
}
A set rule: `set text(...)`.
func SetRule_default ¶
func SetRule_default() *SetRule
type Shorthand ¶
type Shorthand struct {
*SyntaxNode
}
A shorthand for a unicode codepoint. For example, `~` for a non-breaking space or `-?` for a soft hyphen.
func Shorthand_default ¶
func Shorthand_default() *Shorthand
type ShowRule ¶
type ShowRule struct {
*SyntaxNode
}
A show rule: `show heading: it => emph(it.body)`.
func ShowRule_default ¶
func ShowRule_default() *ShowRule
type Side ¶
type Side uint8
Indicates whether the cursor is before the related byte index, or after.
type SmartQuote ¶
type SmartQuote struct {
*SyntaxNode
}
A smart quote: `'` or `"`.
func SmartQuote_default ¶
func SmartQuote_default() *SmartQuote
type Source ¶
type Source struct { // The ID of the source file. ID FileID // The root node of the file's untyped syntax tree. Root *SyntaxNode // An acceleration structure for conversion of UTF-8, UTF-16 and // line/column indices. Lines *Lines }
Source represents a source file.
All line and column indices start at zero, just like byte indices. For user-facing display, add 1 to them.
Values of this type are cheap to clone and hash.
func NewDetachedSource ¶
NewDetachedSource creates a source file without a real ID and path, usually for testing.
It panics if the text cannot be properly parsed.
func NewSource ¶
NewSource creates a new source file from an ID and text.
It panics if the text cannot be properly parsed.
func (*Source) Edit ¶
Edit edits the source file by replacing the given range.
It returns the range in the new source that was ultimately reparsed.
This method panics if the replace range is out of bounds.
func (*Source) Find ¶
func (s *Source) Find(span Span) (*LinkedNode, bool)
Find finds the node with the given span.
It returns None if the span does not point into this source file.
func (*Source) Range ¶
Range returns the byte range for the given span in this file.
It returns false if the span does not point into this source file.
Typically, it's easier to use `WorldExt::Range` instead.
func (*Source) Replace ¶
Replace fully replaces the source text.
It performs a naive (suffix/prefix-based) diff of the old and new text to produce the smallest single edit that transforms the old source into the new one. The method then calls Edit with this change.
Replace returns the range in the new source that was ultimately reparsed.
type Space ¶
type Space struct {
*SyntaxNode
}
Whitespace in markup or math. Has at most one newline in markup, as more indicate a paragraph break.
func Space_default ¶
func Space_default() *Space
type Span ¶
type Span uint64
A Span defines a range in a file.
It's used to track which source section an element stems from or an error applies to.
This type takes up 8 bytes and is copyable.
Data layout: | 16 bits file id | 48 bits number |
Number =
- 1 means detached
- 2..2^47-1 is a numbered span
- 2^47..2^48-1 is a raw range span. To retrieve it, you must subtract `rangeBase` and then use shifting/bitmasking to extract the components.
func FindFirstNonDetached ¶
FindFirstNonDetached finds the first non-detached span in the iterator.
func NewDetachedSpan ¶
func NewDetachedSpan() Span
NewDetachedSpan creates a span that does not point into any file.
func NewSpanFromNumber ¶
NewSpanFromNumber creates a new span from a file ID and a number.
It returns true if the number is within the valid range.
func NewSpanFromRange ¶
NewSpanFromRange creates a new span from a raw byte range. If a range part exceeds the maximum value (2^23), it is saturated.
func NewSpanFromUint64 ¶
NewSpanFromUint64 constructs a span from a raw number.
func NewSpanPacked ¶
NewSpanPacked packs a file ID and the low bits into a span.
func (Span) ID ¶
ID returns the ID of the file the span points into. It returns true if the span is not detached.
func (Span) IsDetached ¶
IsDetached returns whether the span is detached.
func (Span) RawRange ¶
RawRange extracts a raw byte range from the span. It returns true if the span is a raw range span.
func (Span) ResolvePath ¶
ResolvePath resolves a file location relative to this span's source.
type Spanned ¶
type Spanned[T any] struct { // The spanned value. Value T // The value's location in source code. Span Span }
A Spanned value with a span locating it in the source code.
func NewSpanned ¶
NewSpanned creates a new instance from a value and its span.
type Spread ¶
type Spread struct {
*SyntaxNode
}
A spread: `..x` or `..x.at(0)`.
func Spread_default ¶
func Spread_default() *Spread
type Str ¶
type Str struct {
*SyntaxNode
}
A quoted string: `"..."`.
func Str_default ¶
func Str_default() *Str
type Strong ¶
type Strong struct {
*SyntaxNode
}
Strong content: `*Strong*`.
func Strong_default ¶
func Strong_default() *Strong
type SyntaxError ¶
type SyntaxError struct { // The node's span. Span Span // The error message. Message string // Additional hints to the user, indicating how this error could be avoided // or worked around. Hints []string }
A syntactical error.
func NewSyntaxError ¶
func NewSyntaxError(message string) *SyntaxError
Create a new detached syntax error.
new
type SyntaxKind ¶
type SyntaxKind uint8
SyntaxKind is a syntactical building block of a Typst file.
It can be created by the lexer or by the parser.
const ( // The end of token stream. SyntaxKindEnd SyntaxKind = iota + 1 // An invalid sequence of characters. SyntaxKindError // A shebang: `#! ...` SyntaxKindShebang // A line comment: `// ...`. SyntaxKindLineComment // A block comment: `/* ... */`. SyntaxKindBlockComment // The contents of a file or content block. SyntaxKindMarkup // Plain text without markup. SyntaxKindText // Whitespace. Contains at most one newline in markup, as more indicate a // paragraph break. SyntaxKindSpace // A forced line break: `\`. SyntaxKindLinebreak // A paragraph break, indicated by one or multiple blank lines. SyntaxKindParbreak // An escape sequence: `\#`, `\u{1F5FA}`. SyntaxKindEscape // A shorthand for a unicode codepoint. For example, `~` for non-breaking // space or `-?` for a soft hyphen. SyntaxKindShorthand // A smart quote: `'` or `"`. SyntaxKindSmartQuote // Strong content: `*Strong*`. SyntaxKindStrong // Emphasized content: `_Emphasized_`. SyntaxKindEmph // Raw text with optional syntax highlighting: “ `...` “. SyntaxKindRaw // A language tag at the start of raw text: “typ “. SyntaxKindRawLang // A raw delimiter consisting of 1 or 3+ backticks: “ ` “. SyntaxKindRawDelim // A sequence of whitespace to ignore in a raw text: ` `. SyntaxKindRawTrimmed // A hyperlink: `https://typst.org`. SyntaxKindLink // A label: `<intro>`. SyntaxKindLabel // A reference: `@target`, `@target[..]`. SyntaxKindRef // Introduces a reference: `@target`. SyntaxKindRefMarker // A section heading: `= Introduction`. SyntaxKindHeading // Introduces a section heading: `=`, `==`, ... SyntaxKindHeadingMarker // An item in a bullet list: `- ...`. SyntaxKindListItem // Introduces a list item: `-`. SyntaxKindListMarker // An item in an enumeration (numbered list): `+ ...` or `1. ...`. SyntaxKindEnumItem // Introduces an enumeration item: `+`, `1.`. SyntaxKindEnumMarker // An item in a term list: `/ Term: Details`. SyntaxKindTermItem // Introduces a term item: `/`. SyntaxKindTermMarker // A mathematical equation: `$x$`, `$ x^2 $`. SyntaxKindEquation // The contents of a mathematical equation: `x^2 + 1`. SyntaxKindMath // A lone text fragment in math: `x`, `25`, `3.1415`, `=`, `|`, `[`. SyntaxKindMathText // An identifier in math: `pi`. SyntaxKindMathIdent // A shorthand for a unicode codepoint in math: `a <= b`. SyntaxKindMathShorthand // An alignment point in math: `&`. SyntaxKindMathAlignPoint // Matched delimiters in math: `[x + y]`. SyntaxKindMathDelimited // A base with optional attachments in math: `a_1^2`. SyntaxKindMathAttach // Grouped primes in math: `a”'`. SyntaxKindMathPrimes // A fraction in math: `x/2`. SyntaxKindMathFrac // A root in math: `√x`, `∛x` or `∜x`. SyntaxKindMathRoot // A hash that switches into code mode: `#`. SyntaxKindHash // A left curly brace, starting a code block: `{`. SyntaxKindLeftBrace // A right curly brace, terminating a code block: `}`. SyntaxKindRightBrace // A left square bracket, starting a content block: `[`. SyntaxKindLeftBracket // A right square bracket, terminating a content block: `]`. SyntaxKindRightBracket // A left round parenthesis, starting a grouped expression, collection // argument or parameter list: `(`. SyntaxKindLeftParen // A right round parenthesis, terminating a grouped expression, collection // argument or parameter list: `)`. SyntaxKindRightParen // A comma separator in a sequence: `,`. SyntaxKindComma // A semicolon terminating an expression: `;`. SyntaxKindSemicolon // A colon between name/key and value in a dictionary, argument or // parameter list, or between the term and body of a term list term: `:`. SyntaxKindColon // The strong text toggle, multiplication operator, and wildcard import // symbol: `*`. SyntaxKindStar // Toggles emphasized text and indicates a subscript in math: `_`. SyntaxKindUnderscore // Starts and ends a mathematical equation: `$`. SyntaxKindDollar // The unary plus and binary addition operator: `+`. SyntaxKindPlus // The unary negation and binary subtraction operator: `-`. SyntaxKindMinus // The division operator and fraction operator in math: `/`. SyntaxKindSlash // The superscript operator in math: `^`. SyntaxKindHat // The prime in math: `'`. SyntaxKindPrime // The field access and method call operator: `.`. SyntaxKindDot // The assignment operator: `=`. SyntaxKindEq // The equality operator: `==`. SyntaxKindEqEq // The inequality operator: `!=`. SyntaxKindExclEq // The less-than operator: `<`. SyntaxKindLt // The less-than or equal operator: `<=`. SyntaxKindLtEq // The greater-than operator: `>`. SyntaxKindGt // The greater-than or equal operator: `>=`. SyntaxKindGtEq // The add-assign operator: `+=`. SyntaxKindPlusEq // The subtract-assign operator: `-=`. SyntaxKindHyphEq // The multiply-assign operator: `*=`. SyntaxKindStarEq // The divide-assign operator: `/=`. SyntaxKindSlashEq // Indicates a spread or sink: `..`. SyntaxKindDots // An arrow between a closure's parameters and body: `=>`. SyntaxKindArrow // A root: `√`, `∛` or `∜`. SyntaxKindRoot // The `not` operator. SyntaxKindNot // The `and` operator. SyntaxKindAnd // The `or` operator. SyntaxKindOr // The `none` literal. SyntaxKindNone // The `auto` literal. SyntaxKindAuto // The `let` keyword. SyntaxKindLet // The `set` keyword. SyntaxKindSet // The `show` keyword. SyntaxKindShow // The `context` keyword. SyntaxKindContext // The `if` keyword. SyntaxKindIf // The `else` keyword. SyntaxKindElse // The `for` keyword. SyntaxKindFor // The `in` keyword. SyntaxKindIn // The `while` keyword. SyntaxKindWhile // The `break` keyword. SyntaxKindBreak // The `continue` keyword. SyntaxKindContinue // The `return` keyword. SyntaxKindReturn // The `import` keyword. SyntaxKindImport // The `include` keyword. SyntaxKindInclude // The `as` keyword. SyntaxKindAs // The contents of a code block. SyntaxKindCode // An identifier: `it`. SyntaxKindIdent // A boolean: `true`, `false`. SyntaxKindBool // An integer: `120`. SyntaxKindInt // A floating-point number: `1.2`, `10e-4`. SyntaxKindFloat // A numeric value with a unit: `12pt`, `3cm`, `2em`, `90deg`, `50%`. SyntaxKindNumeric // A quoted string: `"..."`. SyntaxKindStr // A code block: `{ let x = 1; x + 2 }`. SyntaxKindCodeBlock // A content block: `[*Hi* there!]`. SyntaxKindContentBlock // A grouped expression: `(1 + 2)`. SyntaxKindParenthesized // An array: `(1, "hi", 12cm)`. SyntaxKindArray // A dictionary: `(thickness: 3pt, dash: "solid")`. SyntaxKindDict // A named pair: `thickness: 3pt`. SyntaxKindNamed // A keyed pair: `"spacy key": true`. SyntaxKindKeyed // A unary operation: `-x`. SyntaxKindUnary // A binary operation: `a + b`. SyntaxKindBinary // A field access: `properties.age`. SyntaxKindFieldAccess // An invocation of a function or method: `f(x, y)`. SyntaxKindFuncCall // A function call's argument list: `(12pt, y)`. SyntaxKindArgs // Spread arguments or an argument sink: `..x`. SyntaxKindSpread // A closure: `(x, y) => z`. SyntaxKindClosure // A closure's parameters: `(x, y)`. SyntaxKindParams // A let binding: `let x = 1`. SyntaxKindLetBinding // A set rule: `set text(...)`. SyntaxKindSetRule // A show rule: `show heading: it => emph(it.body)`. SyntaxKindShowRule // A contextual expression: `context text.lang`. SyntaxKindContextual // An if-else conditional: `if x { y } else { z }`. SyntaxKindConditional // A while loop: `while x { y }`. SyntaxKindWhileLoop // A for loop: `for x in y { z }`. SyntaxKindForLoop // A module import: `import "utils.typ": a, b, c`. SyntaxKindModuleImport // Items to import from a module: `a, b, c`. SyntaxKindImportItems // A path to an imported name from a submodule: `a.b.c`. SyntaxKindImportItemPath // A renamed import item: `a as d`. SyntaxKindRenamedImportItem // A module include: `include "chapter1.typ"`. SyntaxKindModuleInclude // A break from a loop: `break`. SyntaxKindLoopBreak // A continue in a loop: `continue`. SyntaxKindLoopContinue // A return from a function: `return`, `return x + 1`. SyntaxKindFuncReturn // A destructuring pattern: `(x, _, ..y)`. SyntaxKindDestructuring // A destructuring assignment expression: `(x, y) = (1, 2)`. SyntaxKindDestructAssignment SyntaxKindFirst = SyntaxKindEnd SyntaxKindLast = SyntaxKindDestructAssignment NSyntaxKinds = uint(SyntaxKindLast - SyntaxKindFirst + 1) )
Syntax kinds.
func (SyntaxKind) IsBlock ¶
func (kind SyntaxKind) IsBlock() bool
IsBlock reports whether the node is a code or content block.
func (SyntaxKind) IsError ¶
func (kind SyntaxKind) IsError() bool
IsError reports Whether the node is an error.
func (SyntaxKind) IsGrouping ¶
func (kind SyntaxKind) IsGrouping() bool
IsGrouping reports whether the node is a bracket, brace, or parenthesis.
func (SyntaxKind) IsKeyword ¶
func (kind SyntaxKind) IsKeyword() bool
IsKeyword reports whether the node is a keyword.
func (SyntaxKind) IsStmt ¶
func (kind SyntaxKind) IsStmt() bool
IsStmt reports whether the node needs termination through a semicolon or linebreak.
func (SyntaxKind) IsTerminator ¶
func (kind SyntaxKind) IsTerminator() bool
IsTerminator reports whether the node terminates a preceding expression.
func (SyntaxKind) IsTrivia ¶
func (kind SyntaxKind) IsTrivia() bool
IsTrivia reports whether the node is automatically skipped by the parser in code and math mode.
func (SyntaxKind) Name ¶
func (kind SyntaxKind) Name() string
Name returns a human-readable name for the kind.
func (SyntaxKind) String ¶
func (kind SyntaxKind) String() string
type SyntaxMode ¶
type SyntaxMode uint8
SyntaxMode is a syntax mode of a portion of Typst code.
const ( // Text and markup, as in the top level. SyntaxModeMarkup SyntaxMode = iota + 1 // Math atoms, operators, etc., as in equations. SyntaxModeMath // Keywords, literals and operators, as after hashes. SyntaxModeCode )
Syntax modes.
type SyntaxNode ¶
type SyntaxNode struct {
Repr Repr
}
A node in the untyped syntax tree.
func NewError ¶
func NewError(error *SyntaxError, text string) *SyntaxNode
Create a new error node.
error
func NewInner ¶
func NewInner(kind SyntaxKind, children []*SyntaxNode) *SyntaxNode
Create a new inner node with children.
inner
func SyntaxNode_Default ¶
func SyntaxNode_Default() *SyntaxNode
func SyntaxNode_placeholder ¶
func SyntaxNode_placeholder(kind SyntaxKind) *SyntaxNode
Create a dummy node of the given kind.
Panics if `kind` is `SyntaxKind::Error`.
placeholder
func (*SyntaxNode) String ¶
func (node *SyntaxNode) String() string
func (*SyntaxNode) SyntaxKind ¶
func (node *SyntaxNode) SyntaxKind() SyntaxKind
type SyntaxSet ¶
type SyntaxSet struct {
// contains filtered or unexported fields
}
SyntaxSet represents a set of syntax kinds.
func NewSyntaxSet ¶
func NewSyntaxSet(kinds ...SyntaxKind) *SyntaxSet
NewSyntaxSet creates a new set from a slice of kinds.
func (*SyntaxSet) Add ¶
func (set *SyntaxSet) Add(kind SyntaxKind) *SyntaxSet
Add returns a new set with the given kind inserted. The original set is not modified.
func (*SyntaxSet) Contains ¶
func (set *SyntaxSet) Contains(kind SyntaxKind) bool
Contains reports whether the set contains the given syntax kind.
type Tag ¶
type Tag uint8
A syntax highlighting tag.
const ( // A line or block comment. // // Comment Tag_Comment Tag = iota + 1 // Punctuation in code. // // Punctuation Tag_Punctuation // An escape sequence or shorthand. // // Escape Tag_Escape // Strong markup. // // Strong Tag_Strong // Emphasized markup. // // Emph Tag_Emph // A hyperlink. // // Link Tag_Link // Raw text. // // Raw Tag_Raw // A label. // // Label Tag_Label // A reference to a label. // // Ref Tag_Ref // A section heading. // // Heading Tag_Heading // A marker of a list, enumeration, or term list. // // ListMarker Tag_ListMarker // A term in a term list. // // ListTerm Tag_ListTerm // The delimiters of an equation. // // MathDelimiter Tag_MathDelimiter // An operator with special meaning in an equation. // // MathOperator Tag_MathOperator // A keyword. // // Keyword Tag_Keyword // An operator in code. // // Operator Tag_Operator // A numeric literal. // // Number Tag_Number // A string literal. // // String Tag_String // A function or method name. // // Function Tag_Function // An interpolated variable in markup or math. // // Interpolated Tag_Interpolated // A syntax error. // // Error Tag_Error )
type TemplateInfo ¶
type TemplateInfo struct { // The directory within the package that contains the files that should be // copied into the user's new project directory. Path string `toml:"path"` // A path relative to the template's path that points to the file serving as // the compilation target. Entrypoint string `toml:"entrypoint"` // A path relative to the package's root that points to a PNG or lossless // WebP thumbnail for the template. Thumbnail string `toml:"thumbnail,omitempty"` // All parsed but unknown fields, this can be used for validation. UnknownFields UnknownFields `toml:"-"` }
The `[template]` key in the manifest.
The `UnknownFields` contains fields which were found but not expected.
func NewTemplateInfo ¶
func NewTemplateInfo(path, entrypoint string) *TemplateInfo
NewTemplateInfo creates a new template info with only required fields.
type TermItem ¶
type TermItem struct {
*SyntaxNode
}
An item in a term list: `/ Term: Details`.
func TermItem_default ¶
func TermItem_default() *TermItem
type Text ¶
type Text struct {
*SyntaxNode
}
Plain text without markup.
func Text_default ¶
func Text_default() *Text
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
A single token returned from the lexer with a cached [`SyntaxKind`] and a record of preceding trivia.
func Parser_lex ¶
Move the lexer forward and prepare the current token. In Code, this might insert a temporary [`SyntaxKindEnd`] based on our newline mode.
This is not a method on `self` because we need a valid token before we can initialize the parser.
lex
type ToolInfo ¶
type ToolInfo struct { // Any fields parsed in the tool section. Sections map[string]internaltoml.Table }
The `[tool]` key in the manifest. This field can be used to retrieve 3rd-party tool configuration.
type Unary ¶
type Unary struct {
*SyntaxNode
}
A unary operation: `-x`.
func Unary_default ¶
func Unary_default() *Unary
type Underscore ¶
type Underscore struct {
*SyntaxNode
}
An underscore: `_`
func Underscore_default ¶
func Underscore_default() *Underscore
type Unit ¶
type Unit uint8
Unit of a numeric value.
const ( // Points. // // Pt Unit_Pt Unit = iota + 1 // Millimeters. // // Mm Unit_Mm // Centimeters. // // Cm Unit_Cm // Inches. // // In Unit_In // Radians. // // Rad Unit_Rad // Degrees. // // Deg Unit_Deg // Font-relative: `1em` is the same as the font size. // // Em Unit_Em // Fractions: `fr`. // // Fr Unit_Fr // Percentage: `%`. // // Percent Unit_Percent )
type UnknownFields ¶
A type alias for a map of key-value pairs used to collect unknown fields.
type VersionBound ¶
type VersionBound struct { // The bounds's major version. Major uint32 // The bounds's minor version. Minor *uint32 // The bounds's patch version. Can only be present if minor is too. Patch *uint32 }
VersionBound represents a version bound for compatibility specification.
func ParseVersionBound ¶
func ParseVersionBound(str string) (*VersionBound, error)
ParseVersionBound parses a version bound from string.
func (*VersionBound) String ¶
func (v *VersionBound) String() string
func (*VersionBound) UnmarshalText ¶
func (v *VersionBound) UnmarshalText(buf []byte) error
UnmarshalText implements encoding.TextUnmarshaler (for toml).
type VersionlessPackageSpec ¶
type VersionlessPackageSpec struct { // The namespace the package lives in. Namespace string // The name of the package within its namespace. Name string }
VersionlessPackageSpec identifies a package, but not a specific version.
func ParseVersionlessPackageSpec ¶
func ParseVersionlessPackageSpec(str string) (*VersionlessPackageSpec, error)
ParseVersionlessPackageSpec parses a versionless package spec from string.
func (*VersionlessPackageSpec) At ¶
func (spec *VersionlessPackageSpec) At(version PackageVersion) *PackageSpec
At fills in the version to get a complete PackageSpec.
func (*VersionlessPackageSpec) String ¶
func (spec *VersionlessPackageSpec) String() string
type VirtualPath ¶
type VirtualPath struct {
Path string
}
VirtualPath is an absolute path in the virtual file system of a project or package.
func NewVirtualPath ¶
func NewVirtualPath(path string) *VirtualPath
NewVirtualPath creates a new virtual path.
Even if it doesn't start with `/` or `\`, it is still interpreted as starting from the root.
func (*VirtualPath) Join ¶
func (vpath *VirtualPath) Join(path string) *VirtualPath
Join resolves a path relative to this virtual path.
func (*VirtualPath) WithExtension ¶
func (vpath *VirtualPath) WithExtension(extension string) *VirtualPath
WithExtension returns the path, but with a different extension.
type WhileLoop ¶
type WhileLoop struct {
*SyntaxNode
}
A while loop: `while x { y }`.
func WhileLoop_default ¶
func WhileLoop_default() *WhileLoop