Documentation ¶
Index ¶
- Constants
- Variables
- type Builder
- type Kind
- type Node
- func (n Node) End() int
- func (n Node) Err() error
- func (n Node) FindDescendant(pos int) Node
- func (n Node) FirstChild() Node
- func (n Node) FirstToken() Node
- func (n Node) Inspect(f func(n Node) bool)
- func (n Node) IsNonTerminal() bool
- func (n Node) IsTerminal() bool
- func (n Node) IsToken() bool
- func (n Node) IsValid() bool
- func (n Node) Kind() Kind
- func (n Node) LastToken() Node
- func (n Node) Len() int
- func (n Node) Next() Node
- func (n Node) Parent() Node
- func (n Node) Pos() int
- func (n Node) Span() Span
- func (n Node) Text() string
- type NodeError
- type Position
- type Scanner
- type Span
Constants ¶
const ( AddToken eventType = iota OpenNode CloseNode )
Variables ¶
var ( // Nil is the zero value of a Node. Nil = Node{} )
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
A Builder is used to build a syntax tree. The zero value is ready to use.
func (*Builder) Pop ¶
func (b *Builder) Pop()
Pop finishes a non-terminal. Invalid pop calls will panic.
type Kind ¶
type Kind int32
Kind describes the kind of a syntax node.
const ( EOF Kind = iota Unknown Malformed Unterminated Comment Preproc Name Bitstring Float Identifier Integer Modifier String AddressKeyword AllKeyword AltKeyword AltstepKeyword And4bKeyword AndKeyword AnyKeyword CaseKeyword CatchKeyword CharstringKeyword ClassKeyword ComponentKeyword ConfigurationKeyword ConnectKeyword ConstKeyword ControlKeyword CreateKeyword DisplayKeyword DoKeyword ElseKeyword EncodeKeyword EnumeratedKeyword ExceptKeyword ExceptionKeyword ExecuteKeyword ExtendsKeyword ExtensionKeyword ExternalKeyword FinallyKeyword ForKeyword FriendKeyword FromKeyword FunctionKeyword GotoKeyword GroupKeyword IfKeyword ImportKeyword InKeyword InoutKeyword InterleaveKeyword LabelKeyword LanguageKeyword LengthKeyword MapKeyword MessageKeyword ModKeyword ModifiesKeyword ModuleKeyword ModuleparKeyword MtcKeyword NoblockKeyword Not4bKeyword NotKeyword NullKeyword OfKeyword OmitKeyword OnKeyword OptionalKeyword Or4bKeyword OrKeyword OutKeyword OverrideKeyword ParamKeyword PortKeyword PresentKeyword PrivateKeyword ProcedureKeyword PublicKeyword RealtimeKeyword RecordKeyword RemKeyword ReturnKeyword RunsKeyword SelectKeyword SelfKeyword SetKeyword SignatureKeyword StreamKeyword SystemKeyword TemplateKeyword TestcaseKeyword ThisKeyword TimerKeyword ToKeyword TypeKeyword UnionKeyword UniversalKeyword UnmapKeyword ValueKeyword VarKeyword VariantKeyword WhileKeyword WithKeyword Xor4bKeyword XorKeyword Add Any Arrow Assign AtDefault AtLocal Colon ColonColon Comma Concat Div Dot DotDot DoubleArrow Equal ErrorLiteral Exclude FailLiteral FalseLiteral Greater GreaterEqual InconcLiteral LeftBrace LeftBracket LeftParen Less LessEqual Mul NoneLiteral NotANumber NotEqual PassLiteral RightBrace RightBracket RightParen RotateLeft RotateRight Semicolon ShiftLeft ShiftRight Sub TrueLiteral Root SyntaxError Module Decl Group Friend Import ExceptSpec ExceptStmt ImportSpec ImportStmt ImportKind Signature Component Port PortKind PortSpec PortAttribute PortElement PortTranslation SubType Struct StructKind StructMember List ListKind Enum EnumLabel Map Class Constructor Control Destructor TestcaseType FunctionType AltstepType VarDecl TimerDecl PortDecl Template Testcase Function Configuration Altstep Stmt IfStmt SelectStmt ForStmt WhileStmt DoStmt GotoStmt LabelStmt ReturnStmt AltStmt AssignStmt GuardStmt Block BasicBlock Exprs Expr PrimaryExpr DotExpr IndexExpr CallExpr Literal UnaryExpr BinaryExpr Ref TypePars TypePar With WithStmt WithQualifier WithKind Refs Extends Language Return ConfigSpec Exception Visibility FormalTypePars FormalTypePar FormalPars FormalPar Declarator ArrayDef TemplateRestriction NestedTemplate NestedType NestedStruct NestedList NestedEnum )
func (Kind) IsLiteral ¶
IsLiteral returns true if the kind is a literal token. Literal tokens are tokens which have a value, such as identifier, integer, ...
func (Kind) IsNonTerminal ¶
IsNonTerminal returns true if the kind is a non terminal. Non terminals are produced by the parser and usually have other non terminals or tokens as children.
func (Kind) IsTerminal ¶
IsTerminal returns true if the kind is a terminal. Terminals are also known as leave nodes, lexemes, tokens, ...
func (Kind) IsToken ¶
IsToken returns true if the kind is a token. This function is the same as IsTerminal.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a syntax node.
func (Node) End ¶
End returns the end position of the node in the source code. Or -1 if none was available.
func (Node) Err ¶
Err returns the error of the subtree. Errors without a position are attached to the root node.
func (Node) FindDescendant ¶
FindDescendant finds the last descendant of this node whose span includes the given position. If no such node exists, it returns Nil.
func (Node) FirstChild ¶
FirstChild returns the first child of the node or nil if there is none.
func (Node) FirstToken ¶
FirstToken returns the first token/terminal of a syntax node or Nil if there is none.
func (Node) Inspect ¶
Inspect traverses the syntax tree in depth-first order. It calls f for each node recursively. If n is a non-terminal the call is followed by a call of f(Nil).
func (Node) IsNonTerminal ¶
IsNonTerminal returns true if the node is a non-terminal node.
func (Node) IsTerminal ¶
IsTerminal returns true if the node is a terminal node.
func (Node) Kind ¶
Kind returns the syntax node kind of the node, such as Comment, Identifier, VarDecl, etc.
func (Node) LastToken ¶
LastToken returns the last token/terminal of a syntax node or Nil if none is available.
func (Node) Pos ¶
Pos returns the position (offset) of the node in the source code. Or -1 if no position was available.
type Position ¶
type Position struct {
Line, Column int
}
Position is a cursor position in a source file. Lines and columns are 1-based.