Documentation
¶
Overview ¶
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Index ¶
- func Print(node Node, options ...PrettyPrinterOption) error
- func Walk(v Visitor, node Node)
- type ADTEnumBody
- type AnyLiteral
- type ArrayLiteralExpr
- type ArrayType
- type AsExpr
- type AssignStmt
- type AssociatedEnumBody
- type BasicEnumBody
- type BasicLit
- type BinaryExpr
- type BlockStmt
- type BreakStmt
- type CallExpr
- type CascadeExpr
- type CaseClause
- type CatchClause
- type ClassDecl
- type CmdStmt
- type CmdSubstExpr
- type Comment
- type CommentGroup
- type ComptimeExpr
- type ComptimeStmt
- type ConditionalExpr
- type ConditionalType
- type ConstModifier
- type ConstructorDecl
- type ContinueStmt
- type DeclareDecl
- type Decorator
- type DeferStmt
- type DoWhileStmt
- type EllipsisModifier
- type EnumBody
- type EnumDecl
- type EnumMember
- type EnumMethod
- type EnumValue
- type EnumVariant
- type Expr
- type ExprStmt
- type ExtensionBody
- type ExtensionClass
- type ExtensionDecl
- type ExtensionEnum
- type ExtensionMod
- type ExtensionTrait
- type ExtensionType
- type ExternDecl
- type FalseLiteral
- type Field
- type FieldList
- type File
- type FinalModifier
- type FinallyStmt
- type ForInStmt
- type ForStmt
- type ForeachStmt
- type FuncDecl
- type FunctionType
- type GetAccessor
- type Ident
- type IfStmt
- type ImplDecl
- type ImplDeclBinding
- type ImplDeclBody
- type Import
- type ImportAll
- type ImportField
- type ImportMulti
- type ImportSingle
- type IncDecExpr
- type IndexExpr
- type IndexListExpr
- type InferType
- type IntersectionType
- type KeyValueExpr
- type LabelStmt
- type LambdaExpr
- type LiteralType
- type MatchStmt
- type ModAccessExpr
- type ModDecl
- type Modifier
- type ModifierKind
- type NamedObjectLiteralExpr
- type NamedParameters
- type NamedTupleLiteralExpr
- type NewDelExpr
- type Node
- type NullLiteral
- type NullableType
- type NumericLiteral
- type ObjectLiteralExpr
- type OperatorDecl
- type Package
- type Parameter
- type PrettyPrinterOption
- type PubModifier
- type RangeExpr
- type ReadonlyModifier
- type RefExpr
- type RequiredModifier
- type ReturnStmt
- type SelectExpr
- type SetAccessor
- type SetLiteralExpr
- type SetType
- type SliceExpr
- type StaticModifier
- type Stmt
- type StringLiteral
- type ThrowStmt
- type TraitDecl
- type TrueLiteral
- type TryStmt
- type TupleLiteralExpr
- type TupleType
- type TypeDecl
- type TypeLiteral
- type TypeParameter
- type TypeReference
- type TypeofExpr
- type UnaryExpr
- type UnionType
- type UnsafeStmt
- type UseDecl
- type Visitor
- type WhileStmt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Print ¶
func Print(node Node, options ...PrettyPrinterOption) error
Types ¶
type ADTEnumBody ¶
type ADTEnumBody struct {
Lbrace token.Pos // position of "{"
Variants []*EnumVariant // enum variants
Methods []Stmt // methods
Rbrace token.Pos // position of "}"
}
ADTEnumBody represents an algebraic data type enum. enum NetworkPacket { TCP { src_port: num, dst_port: num }, UDP { port: num } }
func (*ADTEnumBody) End ¶
func (b *ADTEnumBody) End() token.Pos
func (*ADTEnumBody) Pos ¶
func (b *ADTEnumBody) Pos() token.Pos
type AnyLiteral ¶
An AnyLiteral node represents the 'any' type literal.
func (*AnyLiteral) End ¶
func (x *AnyLiteral) End() token.Pos
func (*AnyLiteral) Pos ¶
func (x *AnyLiteral) Pos() token.Pos
func (*AnyLiteral) String ¶
func (x *AnyLiteral) String() string
type ArrayLiteralExpr ¶
type ArrayLiteralExpr struct {
Lbrack token.Pos // position of "["
Elems []Expr
Rbrack token.Pos // position of "]"
}
An ArrayLiteralExpr node represents an array literal.
func (*ArrayLiteralExpr) End ¶
func (x *ArrayLiteralExpr) End() token.Pos
func (*ArrayLiteralExpr) Pos ¶
func (x *ArrayLiteralExpr) Pos() token.Pos
func (*ArrayLiteralExpr) String ¶
func (x *ArrayLiteralExpr) String() string
type ArrayType ¶
type ArrayType struct {
Name Expr
}
An ArrayType node represents an array type. e.g., T[]
type AssignStmt ¶
type AssignStmt struct {
Docs *CommentGroup
Scope token.Token // const | var | let
ScopePos token.Pos
Lhs Expr
Colon token.Pos // position of ":"
Type Expr
Tok token.Token // assignment token, e.g., := or =
Rhs Expr
}
An AssignStmt node represents an assignment or a short variable declaration.
func (*AssignStmt) End ¶
func (s *AssignStmt) End() token.Pos
func (*AssignStmt) Pos ¶
func (s *AssignStmt) Pos() token.Pos
type AssociatedEnumBody ¶
type AssociatedEnumBody struct {
Lbrace token.Pos // position of "{"
Fields *FieldList // associated fields declaration
Values []*EnumValue // enum values with data
Methods []Stmt // methods
Rbrace token.Pos // position of "}"
}
AssociatedEnumBody represents an enum with associated values. enum Protocol { port: num; tcp(6), udp(17) } Complex associated enum: enum Protocol { final port: num; const Protocol(...); tcp(6), udp(17); fn get_port() -> num { ... } }
func (*AssociatedEnumBody) End ¶
func (b *AssociatedEnumBody) End() token.Pos
func (*AssociatedEnumBody) Pos ¶
func (b *AssociatedEnumBody) Pos() token.Pos
type BasicEnumBody ¶
type BasicEnumBody struct {
Lbrace token.Pos // position of "{"
Values []*EnumValue // enum values
Rbrace token.Pos // position of "}"
}
BasicEnumBody represents a simple enum with basic values. enum Status { Pending, Approved, Rejected } enum HttpCode { OK = 200, NotFound = 404 }
func (*BasicEnumBody) End ¶
func (b *BasicEnumBody) End() token.Pos
func (*BasicEnumBody) Pos ¶
func (b *BasicEnumBody) Pos() token.Pos
type BasicLit ¶
type BasicLit struct {
Kind token.Token // token.NUM, token.STR, token.IDENT
Value string // literal string; e.g. 42, 0x7f, 3.14, "foo"
ValuePos token.Pos // literal position
}
A BasicLit node represents a literal of basic type.
type BinaryExpr ¶
type BinaryExpr struct {
X Expr // left operand
OpPos token.Pos // position of Op
Op token.Token // operator
Y Expr // right operand
}
A BinaryExpr node represents a binary expression.
func (*BinaryExpr) End ¶
func (x *BinaryExpr) End() token.Pos
func (*BinaryExpr) Pos ¶
func (x *BinaryExpr) Pos() token.Pos
func (*BinaryExpr) String ¶
func (x *BinaryExpr) String() string
type BlockStmt ¶
type BlockStmt struct {
Lbrace token.Pos // position of "{"
List []Stmt
Rbrace token.Pos // position of "}"
}
A BlockStmt node represents a braced statement list.
type BreakStmt ¶
type BreakStmt struct {
Docs *CommentGroup
Break token.Pos // position of "break"
Label *Ident
}
A BreakStmt node represents a break statement.
type CallExpr ¶
type CallExpr struct {
Fun Expr // function expression
Lt token.Pos // position of "<"
TypeParams []Expr // type arguments for a generic function call
Gt token.Pos // position of ">"
Lparen token.Pos // position of "("
Recv []Expr // function arguments; or nil
Rparen token.Pos // position of ")"
}
A CallExpr node represents an expression followed by an argument list.
type CascadeExpr ¶
A CascadeExpr node represents a cascade expression. e.g., x..a()..b()
func (*CascadeExpr) End ¶
func (x *CascadeExpr) End() token.Pos
func (*CascadeExpr) Pos ¶
func (x *CascadeExpr) Pos() token.Pos
func (*CascadeExpr) String ¶
func (x *CascadeExpr) String() string
type CaseClause ¶
type CaseClause struct {
Cond Expr
DArrow token.Pos // position of "=>"
Body *BlockStmt
Comma token.Pos // position of ","
}
A CaseClause represents a case of an expression or type match statement.
type CatchClause ¶
type CatchClause struct {
Docs *CommentGroup
Catch token.Pos // position of "catch"
Lparen token.Pos // position of "("
Cond Expr
Rparen token.Pos // position of ")"
Body *BlockStmt
}
A CatchClause node represents a catch block.
func (*CatchClause) End ¶
func (s *CatchClause) End() token.Pos
func (*CatchClause) Pos ¶
func (s *CatchClause) Pos() token.Pos
type ClassDecl ¶
type ClassDecl struct {
Docs *CommentGroup // associated documentation
Decs []*Decorator // decorators
Modifiers []Modifier // modifiers array (pub, etc.)
Pub token.Pos // position of "pub" keyword, if any
Class token.Pos // position of "class" keyword
Name *Ident // class name
Lt token.Pos // position of "<", if any
TypeParams []Expr // type parameters for a generic class
Gt token.Pos // position of ">", if any
Extends token.Pos // position of "extends" keyword, if any
Parent *Ident // parent classes
Lbrace token.Pos // position of "{"
Fields *FieldList // list of fields
Ctors []*ConstructorDecl // list of constructors
Methods []*FuncDecl // list of methods
Rbrace token.Pos // position of "}"
}
A ClassDecl node represents a class declaration.
type CmdStmt ¶
type CmdStmt struct {
Docs *CommentGroup
Name Expr
Recv []Expr
}
A CmdStmt node represents a command statement.
type CmdSubstExpr ¶
type CmdSubstExpr struct {
Dollar token.Pos
Lparen token.Pos
Fun Expr
Recv []Expr
Rparen token.Pos
}
A CmdSubstExpr node represents a command substitution. e.g. $(...)
func (*CmdSubstExpr) End ¶
func (x *CmdSubstExpr) End() token.Pos
func (*CmdSubstExpr) Pos ¶
func (x *CmdSubstExpr) Pos() token.Pos
func (*CmdSubstExpr) String ¶
func (x *CmdSubstExpr) String() string
type Comment ¶
type Comment struct {
Slash token.Pos // position of "/" starting the comment
Text string // comment text (excluding '\n' for //-style comments)
}
A Comment node represents a single //-style or /*-style comment.
The Text field contains the comment text without carriage returns (\r) that may have been present in the source. Because a comment's end position is computed using len(Text), the position reported by End() does not match the true source end position for comments containing carriage returns.
type CommentGroup ¶
type CommentGroup struct {
List []*Comment // len(List) > 0
}
A CommentGroup represents a sequence of comments with no other tokens and no empty lines between.
func (*CommentGroup) End ¶
func (g *CommentGroup) End() token.Pos
func (*CommentGroup) Pos ¶
func (g *CommentGroup) Pos() token.Pos
type ComptimeExpr ¶
A ComptimeExpr node represents a compile-time expression.
func (*ComptimeExpr) End ¶
func (x *ComptimeExpr) End() token.Pos
func (*ComptimeExpr) Pos ¶
func (x *ComptimeExpr) Pos() token.Pos
func (*ComptimeExpr) String ¶
func (x *ComptimeExpr) String() string
type ComptimeStmt ¶
A ComptimeStmt node represents a compile-time execution block.
func (*ComptimeStmt) End ¶
func (s *ComptimeStmt) End() token.Pos
func (*ComptimeStmt) Pos ¶
func (s *ComptimeStmt) Pos() token.Pos
type ConditionalExpr ¶
type ConditionalExpr struct {
Cond Expr
Quest token.Pos // position of "?"
WhenTrue Expr
Colon token.Pos // position of ":"
WhneFalse Expr
}
A ConditionalExpr node represents a conditional expression. e.g., cond ? a : b
func (*ConditionalExpr) End ¶
func (x *ConditionalExpr) End() token.Pos
func (*ConditionalExpr) Pos ¶
func (x *ConditionalExpr) Pos() token.Pos
func (*ConditionalExpr) String ¶
func (x *ConditionalExpr) String() string
type ConditionalType ¶
type ConditionalType struct {
CheckType Expr
Extends token.Pos // position of "extends"
ExtendsType Expr
Quest token.Pos // position of "?"
TrueType Expr
Colon token.Pos // position of ":"
FalseType Expr
}
A ConditionalType node represents a conditional type. e.g., T extends U ? X : Y
func (*ConditionalType) End ¶
func (x *ConditionalType) End() token.Pos
func (*ConditionalType) Pos ¶
func (x *ConditionalType) Pos() token.Pos
func (*ConditionalType) String ¶
func (x *ConditionalType) String() string
type ConstModifier ¶
ConstModifier represents a "const" modifier.
func (*ConstModifier) End ¶
func (m *ConstModifier) End() token.Pos
func (*ConstModifier) Kind ¶
func (m *ConstModifier) Kind() ModifierKind
func (*ConstModifier) Pos ¶
func (m *ConstModifier) Pos() token.Pos
type ConstructorDecl ¶
type ConstructorDecl struct {
Docs *CommentGroup // associated documentation
Decs []*Decorator // decorators
Modifiers []Modifier // modifiers array (const, pub, etc.)
ClsName *Ident // class name (same as class name)
Name *Ident // constructor name
Lparen token.Pos // position of "("
Recv []Expr // constructor parameters
Rparen token.Pos // position of ")"
InitFields []Expr // init fields
Body *BlockStmt // constructor body
}
A ConstructorDecl node represents a constructor declaration. e.g., const Constants(pi: num, e: num) $this.PI = $pi, $this.E = $e {}
func (*ConstructorDecl) End ¶
func (d *ConstructorDecl) End() token.Pos
func (*ConstructorDecl) Pos ¶
func (d *ConstructorDecl) Pos() token.Pos
type ContinueStmt ¶
type ContinueStmt struct {
Docs *CommentGroup
Continue token.Pos // position of "continue"
}
A ContinueStmt node represents a continue statement.
func (*ContinueStmt) End ¶
func (s *ContinueStmt) End() token.Pos
func (*ContinueStmt) Pos ¶
func (s *ContinueStmt) Pos() token.Pos
type DeclareDecl ¶
type DeclareDecl struct {
Docs *CommentGroup
Declare token.Pos // position of "declare"
X Node
}
A DeclareDecl node represents a declare declaration.
func (*DeclareDecl) End ¶
func (d *DeclareDecl) End() token.Pos
func (*DeclareDecl) Pos ¶
func (d *DeclareDecl) Pos() token.Pos
type DeferStmt ¶
type DeferStmt struct {
Docs *CommentGroup
Defer token.Pos // position of "defer"
X Node
}
A DeferStmt node represents a defer statement. defer {...} or defer fn()
type DoWhileStmt ¶
type DoWhileStmt struct {
Do token.Pos // position of "do"
Body *BlockStmt
Loop token.Pos // position of "loop"
Lparen token.Pos // position of "("
Cond Expr
Rparen token.Pos // position of ")"
}
A DoWhileStmt node represents a do..while statement.
func (*DoWhileStmt) End ¶
func (s *DoWhileStmt) End() token.Pos
func (*DoWhileStmt) Pos ¶
func (s *DoWhileStmt) Pos() token.Pos
type EllipsisModifier ¶
EllipsisModifier represents a "..." modifier.
func (*EllipsisModifier) End ¶
func (m *EllipsisModifier) End() token.Pos
func (*EllipsisModifier) Kind ¶
func (m *EllipsisModifier) Kind() ModifierKind
func (*EllipsisModifier) Pos ¶
func (m *EllipsisModifier) Pos() token.Pos
type EnumBody ¶
type EnumBody interface {
Node
// contains filtered or unexported methods
}
EnumBody represents the body of an enum declaration.
type EnumDecl ¶
type EnumDecl struct {
Docs *CommentGroup // associated documentation
Decs []*Decorator // decorators
Modifiers []Modifier // modifiers array (final, const, pub, etc.)
Enum token.Pos // position of "enum" keyword
Name *Ident // enum name
Lt token.Pos // position of "<", if any
TypeParams []Expr // type parameters for a generic enum
Gt token.Pos // position of ">", if any
Body EnumBody // enum body
}
An EnumDecl node represents an enum declaration.
type EnumMethod ¶
An EnumMethod represents a method within an enum.
type EnumValue ¶
type EnumValue struct {
Docs *CommentGroup // associated documentation
Name *Ident // value name
Assign token.Pos // position of "=", if any
Value Expr // value expression, if any
Lparen token.Pos // position of "(", for associated values
Data []Expr // associated data, if any
Rparen token.Pos // position of ")"
Comma token.Pos // position of ","
}
EnumValue represents a single enum value.
type EnumVariant ¶
type EnumVariant struct {
Docs *CommentGroup // associated documentation
Name *Ident // variant name
Lbrace token.Pos // position of "{"
Fields *FieldList // variant fields
Rbrace token.Pos // position of "}"
Comma token.Pos // position of ","
}
EnumVariant represents a variant in an ADT enum.
func (*EnumVariant) End ¶
func (v *EnumVariant) End() token.Pos
func (*EnumVariant) Pos ¶
func (v *EnumVariant) Pos() token.Pos
type ExprStmt ¶
type ExprStmt struct {
Docs *CommentGroup
Decs []*Decorator
X Expr // expression
}
An ExprStmt node represents a (stand-alone) expression in a statement list.
type ExtensionBody ¶
type ExtensionBody interface {
Node
// contains filtered or unexported methods
}
ExtensionBody represents the body of an extension declaration.
type ExtensionClass ¶
An ExtensionClass node represents a class extension.
func (*ExtensionClass) End ¶
func (e *ExtensionClass) End() token.Pos
func (*ExtensionClass) Pos ¶
func (e *ExtensionClass) Pos() token.Pos
type ExtensionDecl ¶
type ExtensionDecl struct {
Docs *CommentGroup // associated documentation
Extension token.Pos // position of "extension" keyword
Name *Ident
Body ExtensionBody // the extension body
}
An ExtensionDecl node represents an extension declaration.
func (*ExtensionDecl) End ¶
func (d *ExtensionDecl) End() token.Pos
func (*ExtensionDecl) Pos ¶
func (d *ExtensionDecl) Pos() token.Pos
type ExtensionEnum ¶
An ExtensionEnum node represents an enum extension.
func (*ExtensionEnum) End ¶
func (e *ExtensionEnum) End() token.Pos
func (*ExtensionEnum) Pos ¶
func (e *ExtensionEnum) Pos() token.Pos
type ExtensionMod ¶
An ExtensionMod node represents a module extension.
func (*ExtensionMod) End ¶
func (e *ExtensionMod) End() token.Pos
func (*ExtensionMod) Pos ¶
func (e *ExtensionMod) Pos() token.Pos
type ExtensionTrait ¶
An ExtensionTrait node represents a trait extension.
func (*ExtensionTrait) End ¶
func (e *ExtensionTrait) End() token.Pos
func (*ExtensionTrait) Pos ¶
func (e *ExtensionTrait) Pos() token.Pos
type ExtensionType ¶
An ExtensionType node represents a type extension.
func (*ExtensionType) End ¶
func (e *ExtensionType) End() token.Pos
func (*ExtensionType) Pos ¶
func (e *ExtensionType) Pos() token.Pos
type ExternDecl ¶
An ExternDecl represents a foreign function interface declaration.
func (*ExternDecl) End ¶
func (d *ExternDecl) End() token.Pos
func (*ExternDecl) Pos ¶
func (d *ExternDecl) Pos() token.Pos
type FalseLiteral ¶
A FalseLiteral node represents the boolean literal 'false'.
func (*FalseLiteral) End ¶
func (x *FalseLiteral) End() token.Pos
func (*FalseLiteral) Pos ¶
func (x *FalseLiteral) Pos() token.Pos
func (*FalseLiteral) String ¶
func (x *FalseLiteral) String() string
type Field ¶
type Field struct {
Docs *CommentGroup
Decs []*Decorator
Modifiers []Modifier
Name *Ident
Colon token.Pos // position of ":"
Type Expr
Assign token.Pos // position of '='
Value Expr // default value
}
A Field represents a field in a struct or a parameter in a function. e.g., (pub | const | final) x: str | num = defaultValue
type FieldList ¶
type File ¶
type File struct {
Docs []*CommentGroup
Name *Ident // filename
Imports map[string]*Import
Stmts []Stmt
Decls []Stmt
}
A File node represents a Hulo source file.
type FinalModifier ¶
FinalModifier represents a "final" modifier.
func (*FinalModifier) End ¶
func (m *FinalModifier) End() token.Pos
func (*FinalModifier) Kind ¶
func (m *FinalModifier) Kind() ModifierKind
func (*FinalModifier) Pos ¶
func (m *FinalModifier) Pos() token.Pos
Implementation methods for modifier types
type FinallyStmt ¶
type FinallyStmt struct {
Docs *CommentGroup
Finally token.Pos // position of "finally"
Body *BlockStmt
}
A FinallyStmt node represents a finally block.
func (*FinallyStmt) End ¶
func (s *FinallyStmt) End() token.Pos
func (*FinallyStmt) Pos ¶
func (s *FinallyStmt) Pos() token.Pos
type ForInStmt ¶
type ForInStmt struct {
Loop token.Pos // position of "loop"
Index *Ident
In token.Pos // position of "in"
RangeExpr
Body *BlockStmt
}
A ForInStmt node represents a for-range statement.
type ForStmt ¶
type ForStmt struct {
Loop token.Pos // position of "loop"
Lparen token.Pos // position of "("
Init Stmt
Comma1 token.Pos // position of ";"
Cond Expr
Comma2 token.Pos // position of ";"
Post Expr
Rparen token.Pos // position of ")"
Body *BlockStmt
}
A ForStmt node represents a for statement.
type ForeachStmt ¶
type ForeachStmt struct {
Loop token.Pos // position of "loop"
Lparen token.Pos // position of "("
Index Expr
Value Expr
Rparen token.Pos // position of ")"
Tok token.Token // Token.IN or Token.OF
TokPos token.Pos // position of "in" or "of"
Var Expr
Body *BlockStmt
}
A ForeachStmt node represents a for-each statement.
func (*ForeachStmt) End ¶
func (s *ForeachStmt) End() token.Pos
func (*ForeachStmt) Pos ¶
func (s *ForeachStmt) Pos() token.Pos
type FuncDecl ¶
type FuncDecl struct {
Docs *CommentGroup // associated documentation
Decs []*Decorator // decorators
Modifiers []Modifier // modifiers array (const, comptime, pub, etc.)
Fn token.Pos // position of "fn" keyword
Name *Ident // function name
Lt token.Pos // position of "<", if any
TypeParams []Expr // type parameters for a generic function
Gt token.Pos // position of ">", if any
Recv []Expr // function parameters
Throw bool // if the function can throw an exception
Type Expr // result type
Body *BlockStmt // function body
}
A FuncDecl node represents a function declaration.
type FunctionType ¶
A FunctionType node represents a function type. e.g., (int, string) -> bool
func (*FunctionType) End ¶
func (x *FunctionType) End() token.Pos
func (*FunctionType) Pos ¶
func (x *FunctionType) Pos() token.Pos
func (*FunctionType) String ¶
func (x *FunctionType) String() string
type GetAccessor ¶
A GetAccessor represents a getter in a property.
func (*GetAccessor) End ¶
func (d *GetAccessor) End() token.Pos
func (*GetAccessor) Pos ¶
func (d *GetAccessor) Pos() token.Pos
type IfStmt ¶
type IfStmt struct {
Docs *CommentGroup
If token.Pos // position of "if"
Cond Expr
Body *BlockStmt
Else Stmt
}
An IfStmt node represents an if statement.
type ImplDecl ¶
type ImplDecl struct {
Docs *CommentGroup // associated documentation
Impl token.Pos // position of "impl" keyword
Trait *Ident // trait being implemented
For token.Pos // position of "for" keyword
*ImplDeclBody
*ImplDeclBinding
}
An ImplDecl node represents an implementation of a trait for a type.
type ImplDeclBinding ¶
type ImplDeclBinding struct {
Classes []*Ident // classes implementing the trait
}
An ImplDeclBinding represents the implementation for multiple classes.
type ImplDeclBody ¶
type ImplDeclBody struct {
Class *Ident // class implementing the trait
Body *BlockStmt // implementation body
}
An ImplDeclBody represents the implementation for a single class.
type Import ¶
type Import struct {
Docs *CommentGroup
ImportPos token.Pos // position of "import"
*ImportAll
*ImportSingle
*ImportMulti
}
An Import node represents an import statement.
type ImportAll ¶
type ImportAll struct {
Mul token.Pos // position of "*"
As token.Pos // position of "as"
Alias string
From token.Pos // position of "from"
Path string
}
An ImportAll node represents an 'import * as ...' declaration. import * as <alias> from <path>
type ImportField ¶
An ImportField node represents a single imported entity in a multi-import declaration. <field> as <alias>
type ImportMulti ¶
type ImportMulti struct {
Lbrace token.Pos // position of "{"
List []*ImportField
Rbrace token.Pos // position of "}"
From token.Pos // position of "from"
Path string
}
An ImportMulti node represents an 'import { ... } from ...' declaration. import { <p1> as <alias1>, <p2> } from <path>
type ImportSingle ¶
An ImportSingle node represents an 'import ... as ...' declaration. import <path> as <alias>
type IncDecExpr ¶
type IncDecExpr struct {
Pre bool // true if it's a prefix operator, false for postfix
X Expr
Tok token.Token // INC or DEC
TokPos token.Pos // position of "++" or "--"
}
An IncDecExpr node represents an increment or decrement expression.
func (*IncDecExpr) End ¶
func (x *IncDecExpr) End() token.Pos
func (*IncDecExpr) Pos ¶
func (x *IncDecExpr) Pos() token.Pos
func (*IncDecExpr) String ¶
func (x *IncDecExpr) String() string
type IndexExpr ¶
type IndexExpr struct {
X Expr // expression
Quest bool // true if optional chaining is used, e.g., a?[i]
Lbrack token.Pos // position of "["
Index Expr // index expression
Rbrack token.Pos // position of "]"
}
An IndexExpr node represents an expression followed by an index.
type IndexListExpr ¶
An IndexListExpr node represents an expression followed by multiple indices. e.g., a[i, j]
func (*IndexListExpr) String ¶
func (x *IndexListExpr) String() string
type InferType ¶
An InferType node represents a type inference variable in a conditional type. e.g. infer T
type IntersectionType ¶
type IntersectionType struct {
Types []Expr
}
An IntersectionType node represents an intersection type. e.g., T & U
func (*IntersectionType) End ¶
func (x *IntersectionType) End() token.Pos
func (*IntersectionType) Pos ¶
func (x *IntersectionType) Pos() token.Pos
func (*IntersectionType) String ¶
func (x *IntersectionType) String() string
type KeyValueExpr ¶
type KeyValueExpr struct {
Docs *CommentGroup
Decs []*Decorator
Mod Modifier
Key Expr
Quest bool // true if the key is optional
Colon token.Pos // position of ":"
Value Expr
}
A KeyValueExpr node represents (key : value) pairs in composite literals.
func (*KeyValueExpr) End ¶
func (x *KeyValueExpr) End() token.Pos
func (*KeyValueExpr) Pos ¶
func (x *KeyValueExpr) Pos() token.Pos
func (*KeyValueExpr) String ¶
func (x *KeyValueExpr) String() string
type LambdaExpr ¶
type LambdaExpr struct {
Lparen token.Pos // position of "("
Recv []Expr
Rparen token.Pos // position of ")"
DArrow token.Pos // position of "=>"
Body *BlockStmt
}
A LambdaExpr node represents a lambda expression. TODO: This might be converted to a regular anonymous function during analysis.
func (*LambdaExpr) End ¶
func (x *LambdaExpr) End() token.Pos
func (*LambdaExpr) Pos ¶
func (x *LambdaExpr) Pos() token.Pos
func (*LambdaExpr) String ¶
func (*LambdaExpr) String() string
type MatchStmt ¶
type MatchStmt struct {
Docs *CommentGroup
Match token.Pos // position of "match"
Expr Expr // expression being matched
Lbrace token.Pos // position of "{"
Cases []*CaseClause
Default *CaseClause
Rbrace token.Pos // position of "}"
}
A MatchStmt node represents a match statement.
type ModAccessExpr ¶
A ModAccessExpr node represents a module access expression. e.g., X::Y
func (*ModAccessExpr) End ¶
func (x *ModAccessExpr) End() token.Pos
func (*ModAccessExpr) Pos ¶
func (x *ModAccessExpr) Pos() token.Pos
func (*ModAccessExpr) String ¶
func (x *ModAccessExpr) String() string
type ModDecl ¶
type ModDecl struct {
Docs *CommentGroup // associated documentation
Pub token.Pos // position of "pub" keyword, if any
Mod token.Pos // position of "mod" keyword
Name *Ident // module name
Lbrace token.Pos // position of "{"
Body *BlockStmt // module body
Rbrace token.Pos // position of "}"
}
A ModDecl node represents a module declaration.
type Modifier ¶
type Modifier interface {
Node
Kind() ModifierKind
}
TODO add position infromation Modifier represents a set of modifiers that can be applied to declarations
type ModifierKind ¶
type ModifierKind uint8
ModifierKind represents the type of modifier.
const ( ModKindNone ModifierKind = iota ModKindFinal ModKindConst ModKindPub ModKindStatic ModKindRequired ModKindReadonly ModKindEllipsis )
Modifier kind constants
type NamedObjectLiteralExpr ¶
type NamedObjectLiteralExpr struct {
Name Expr // Type name, e.g., 'User'.
Lbrace token.Pos // Position of "{"
Props []Expr // List of elements, typically KeyValueExpr.
Rbrace token.Pos // Position of "}"
}
A NamedObjectLiteralExpr node represents a composite literal expression, used for instantiating a struct or class. e.g. User{name: "root", pwd: "123456"}
func (*NamedObjectLiteralExpr) End ¶
func (x *NamedObjectLiteralExpr) End() token.Pos
func (*NamedObjectLiteralExpr) Pos ¶
func (x *NamedObjectLiteralExpr) Pos() token.Pos
func (*NamedObjectLiteralExpr) String ¶
func (x *NamedObjectLiteralExpr) String() string
type NamedParameters ¶
type NamedParameters struct {
Lbrace token.Pos // position of "{"
Params []Expr
Rbrace token.Pos // position of "}"
}
ANamedParameters node represents a set of named parameters.
func (*NamedParameters) End ¶
func (x *NamedParameters) End() token.Pos
func (*NamedParameters) Pos ¶
func (x *NamedParameters) Pos() token.Pos
func (*NamedParameters) String ¶
func (x *NamedParameters) String() string
type NamedTupleLiteralExpr ¶
type NamedTupleLiteralExpr struct {
Lparen token.Pos // position of "("
Elems []Expr
Rparen token.Pos // position of ")"
}
A NamedTupleLiteralExpr node represents a named tuple literal.
func (*NamedTupleLiteralExpr) End ¶
func (x *NamedTupleLiteralExpr) End() token.Pos
func (*NamedTupleLiteralExpr) Pos ¶
func (x *NamedTupleLiteralExpr) Pos() token.Pos
func (*NamedTupleLiteralExpr) String ¶
func (x *NamedTupleLiteralExpr) String() string
type NewDelExpr ¶
type NewDelExpr struct {
TokPos token.Pos // position of "new" or "delete"
Tok token.Token // Token.NEW or Token.DELETE
X Expr
}
A NewDelExpr node represents a new or delete expression.
func (*NewDelExpr) End ¶
func (x *NewDelExpr) End() token.Pos
func (*NewDelExpr) Pos ¶
func (x *NewDelExpr) Pos() token.Pos
func (*NewDelExpr) String ¶
func (x *NewDelExpr) String() string
type NullLiteral ¶
A NullLiteral node represents the 'null' literal.
func (*NullLiteral) End ¶
func (x *NullLiteral) End() token.Pos
func (*NullLiteral) Pos ¶
func (x *NullLiteral) Pos() token.Pos
func (*NullLiteral) String ¶
func (x *NullLiteral) String() string
type NullableType ¶
type NullableType struct {
X Expr
}
A NullableType node represents a nullable type. e.g., T?
func (*NullableType) End ¶
func (x *NullableType) End() token.Pos
func (*NullableType) Pos ¶
func (x *NullableType) Pos() token.Pos
func (*NullableType) String ¶
func (x *NullableType) String() string
type NumericLiteral ¶
A NumericLiteral node represents a numeric literal.
func Num ¶
func Num(val string) *NumericLiteral
func (*NumericLiteral) End ¶
func (x *NumericLiteral) End() token.Pos
func (*NumericLiteral) Pos ¶
func (x *NumericLiteral) Pos() token.Pos
func (*NumericLiteral) String ¶
func (x *NumericLiteral) String() string
type ObjectLiteralExpr ¶
type ObjectLiteralExpr struct {
Lbrace token.Pos // position of "{"
Props []Expr
Rbrace token.Pos // position of "}"
}
An ObjectLiteralExpr node represents an object literal.
func (*ObjectLiteralExpr) End ¶
func (x *ObjectLiteralExpr) End() token.Pos
func (*ObjectLiteralExpr) Pos ¶
func (x *ObjectLiteralExpr) Pos() token.Pos
func (*ObjectLiteralExpr) String ¶
func (x *ObjectLiteralExpr) String() string
type OperatorDecl ¶
type OperatorDecl struct {
Docs *CommentGroup // associated documentation
Decs []*Decorator // decorators
Operator token.Pos // position of "operator" keyword
Name token.Token // operator token
Lparen token.Pos // position of "("
Params []Expr // parameters
Rparen token.Pos // position of ")"
Arrow token.Pos // position of "->"
Type Expr // result type
Body *BlockStmt // function body
}
An OperatorDecl node represents an operator declaration.
func (*OperatorDecl) End ¶
func (d *OperatorDecl) End() token.Pos
func (*OperatorDecl) Pos ¶
func (d *OperatorDecl) Pos() token.Pos
type Parameter ¶
type Parameter struct {
TokPos token.Pos // position of "required" or "..."
Modifier Modifier
Name *Ident
Colon token.Pos // position of ":"
Type Expr
Assign token.Pos // position of "="
Value Expr // default value
}
A Parameter node represents a parameter in a function declaration. e.g. required x: type = value
type PrettyPrinterOption ¶
type PrettyPrinterOption func(*prettyPrinter) error
func WithIndentSpace ¶
func WithIndentSpace(space string) PrettyPrinterOption
type PubModifier ¶
PubModifier represents a "pub" modifier.
func (*PubModifier) End ¶
func (m *PubModifier) End() token.Pos
func (*PubModifier) Kind ¶
func (m *PubModifier) Kind() ModifierKind
func (*PubModifier) Pos ¶
func (m *PubModifier) Pos() token.Pos
type RangeExpr ¶
type RangeExpr struct {
Start Expr
DblColon1 token.Pos // position of ".."
End_ Expr
DblColon2 token.Pos // position of ".."
Step Expr
}
A RangeExpr node represents a range expression. e.g., 1..5..0.1 or 1..0.5..-0.1
type ReadonlyModifier ¶
ReadonlyModifier represents a "readonly" modifier.
func (*ReadonlyModifier) End ¶
func (m *ReadonlyModifier) End() token.Pos
func (*ReadonlyModifier) Kind ¶
func (m *ReadonlyModifier) Kind() ModifierKind
func (*ReadonlyModifier) Pos ¶
func (m *ReadonlyModifier) Pos() token.Pos
type RefExpr ¶
type RefExpr struct {
Dollar token.Pos // position of "$"
Lbrace token.Pos // position of "{"
X Expr
Rbrace token.Pos // position of "}"
}
A RefExpr node represents a reference expression. e.g., ${x} or $x
type RequiredModifier ¶
RequiredModifier represents a "required" modifier.
func (*RequiredModifier) End ¶
func (m *RequiredModifier) End() token.Pos
func (*RequiredModifier) Kind ¶
func (m *RequiredModifier) Kind() ModifierKind
func (*RequiredModifier) Pos ¶
func (m *RequiredModifier) Pos() token.Pos
type ReturnStmt ¶
type ReturnStmt struct {
Docs *CommentGroup
Return token.Pos // position of "return"
X Expr
}
A ReturnStmt node represents a return statement.
func (*ReturnStmt) End ¶
func (s *ReturnStmt) End() token.Pos
func (*ReturnStmt) Pos ¶
func (s *ReturnStmt) Pos() token.Pos
type SelectExpr ¶
type SelectExpr struct {
X Expr
Quest bool // true if optional chaining is used, e.g., X?.Y
Dot token.Pos // position of "."
Y Expr
}
A SelectExpr node represents a selector expression. e.g., X.Y
func (*SelectExpr) End ¶
func (x *SelectExpr) End() token.Pos
func (*SelectExpr) Pos ¶
func (x *SelectExpr) Pos() token.Pos
func (*SelectExpr) String ¶
func (x *SelectExpr) String() string
type SetAccessor ¶
A SetAccessor represents a setter in a property.
func (*SetAccessor) End ¶
func (d *SetAccessor) End() token.Pos
func (*SetAccessor) Pos ¶
func (d *SetAccessor) Pos() token.Pos
type SetLiteralExpr ¶
type SetLiteralExpr struct {
Lbrace token.Pos // position of "{"
Elems []Expr
Rbrace token.Pos // position of "}"
}
A SetLiteralExpr node represents a set literal.
func (*SetLiteralExpr) End ¶
func (x *SetLiteralExpr) End() token.Pos
func (*SetLiteralExpr) Pos ¶
func (x *SetLiteralExpr) Pos() token.Pos
func (*SetLiteralExpr) String ¶
func (x *SetLiteralExpr) String() string
type SetType ¶
type SetType struct {
Types []Expr
}
A SetType node represents a set type. e.g., {int}
type SliceExpr ¶
type SliceExpr struct {
X Expr // expression
Lbrack token.Pos // position of "["
Low Expr // begin of slice range; or nil
DblCol token.Pos // position of ".."
High Expr // end of slice range; or nil
DblCol2 token.Pos // position of ".."
Max Expr // maximum capacity of slice; or nil
Rbrack token.Pos // position of "]"
}
A SliceExpr node represents an expression followed by slice indices.
type StaticModifier ¶
StaticModifier represents a "static" modifier.
func (*StaticModifier) End ¶
func (m *StaticModifier) End() token.Pos
func (*StaticModifier) Kind ¶
func (m *StaticModifier) Kind() ModifierKind
func (*StaticModifier) Pos ¶
func (m *StaticModifier) Pos() token.Pos
type Stmt ¶
type Stmt interface {
Node
// contains filtered or unexported methods
}
All statement nodes implement the Stmt interface.
type StringLiteral ¶
A StringLiteral node represents a string literal.
func Str ¶
func Str(val string) *StringLiteral
func (*StringLiteral) End ¶
func (x *StringLiteral) End() token.Pos
func (*StringLiteral) Pos ¶
func (x *StringLiteral) Pos() token.Pos
func (*StringLiteral) String ¶
func (x *StringLiteral) String() string
type ThrowStmt ¶
type ThrowStmt struct {
Docs *CommentGroup
Throw token.Pos // position of "throw"
X Expr
}
A ThrowStmt node represents a throw statement.
type TraitDecl ¶
type TraitDecl struct {
Docs *CommentGroup // associated documentation
Modifiers []Modifier
Trait token.Pos // position of "trait" keyword
Name *Ident // trait name
Lbrace token.Pos // position of "{"
Fields *FieldList // list of method signatures
Rbrace token.Pos // position of "}"
}
A TraitDecl node represents a trait declaration.
type TrueLiteral ¶
A TrueLiteral node represents the boolean literal 'true'.
func (*TrueLiteral) End ¶
func (x *TrueLiteral) End() token.Pos
func (*TrueLiteral) Pos ¶
func (x *TrueLiteral) Pos() token.Pos
func (*TrueLiteral) String ¶
func (x *TrueLiteral) String() string
type TryStmt ¶
type TryStmt struct {
Docs *CommentGroup
Try token.Pos // position of "try"
Body *BlockStmt
Catches []*CatchClause
Finally *FinallyStmt
}
A TryStmt node represents a try-catch-finally statement.
type TupleLiteralExpr ¶
type TupleLiteralExpr struct {
Lbrack token.Pos // position of "["
Elems []Expr
Rbrack token.Pos // position of "]"
}
A TupleLiteralExpr node represents a tuple literal.
func (*TupleLiteralExpr) End ¶
func (x *TupleLiteralExpr) End() token.Pos
func (*TupleLiteralExpr) Pos ¶
func (x *TupleLiteralExpr) Pos() token.Pos
func (*TupleLiteralExpr) String ¶
func (x *TupleLiteralExpr) String() string
type TupleType ¶
type TupleType struct {
Types []Expr
}
A TupleType node represents a tuple type. e.g., [int, string]
type TypeDecl ¶
type TypeDecl struct {
Docs *CommentGroup // associated documentation
Type token.Pos // position of "type" keyword
Name *Ident // type name
Assign token.Pos // position of "="
Value Expr // type value
}
A TypeDecl node represents a type declaration (type alias).
type TypeLiteral ¶
type TypeLiteral struct {
Members []Expr
}
A TypeLiteral node represents a type literal. e.g., { a: int, b: string }
func (*TypeLiteral) End ¶
func (x *TypeLiteral) End() token.Pos
func (*TypeLiteral) Pos ¶
func (x *TypeLiteral) Pos() token.Pos
func (*TypeLiteral) String ¶
func (x *TypeLiteral) String() string
type TypeParameter ¶
type TypeParameter struct {
Name Expr
Extends token.Pos // position of "extends"
Constraints []Expr
}
A TypeParameter node represents a type parameter in a generic declaration. e.g. RW extends Readable + Writable
func (*TypeParameter) End ¶
func (x *TypeParameter) End() token.Pos
func (*TypeParameter) Pos ¶
func (x *TypeParameter) Pos() token.Pos
func (*TypeParameter) String ¶
func (x *TypeParameter) String() string
type TypeReference ¶
A TypeReference node represents a reference to a type. e.g., MyMap<T, U>
func (*TypeReference) End ¶
func (x *TypeReference) End() token.Pos
func (*TypeReference) Pos ¶
func (x *TypeReference) Pos() token.Pos
func (*TypeReference) String ¶
func (x *TypeReference) String() string
type TypeofExpr ¶
A TypeofExpr node represents a typeof expression. e.g. typeof X
func (*TypeofExpr) End ¶
func (x *TypeofExpr) End() token.Pos
func (*TypeofExpr) Pos ¶
func (x *TypeofExpr) Pos() token.Pos
func (*TypeofExpr) String ¶
func (x *TypeofExpr) String() string
type UnaryExpr ¶
type UnaryExpr struct {
OpPos token.Pos // position of Op
Op token.Token // operator
X Expr // operand
}
A UnaryExpr node represents a unary expression.
type UnionType ¶
type UnionType struct {
Types []Expr
}
A UnionType node represents a union type. e.g., T | U
type UnsafeStmt ¶
type UnsafeStmt struct {
Docs *CommentGroup
Unsafe token.Pos // position of "unsafe" or "$"
Start token.Pos // position of `{`
Text string
EndPos token.Pos // position of `}`
}
An UnsafeStmt node represents an unsafe block. unsafe { ... } or ${ ... }
func (*UnsafeStmt) End ¶
func (s *UnsafeStmt) End() token.Pos
func (*UnsafeStmt) Pos ¶
func (s *UnsafeStmt) Pos() token.Pos