Documentation
¶
Overview ¶
Package ast contains the Vibescript abstract syntax tree node types and related lexical primitives. It is an internal package: only code within the github.com/mgomes/vibescript module can import it.
Index ¶
- Constants
- func CanonicalRuntimeErrorType(name string) (string, bool)
- func FormatTypeExpr(ty *TypeExpr) string
- func IsIdentifierRune(r rune) bool
- func IsIdentifierStart(r rune) bool
- type ArrayLiteral
- type AssignStmt
- type BinaryExpr
- type BlockLiteral
- type BoolLiteral
- type BreakStmt
- type CallExpr
- type CaseExpr
- type CaseWhenClause
- type ClassStmt
- type ClassVarExpr
- type EnumMemberStmt
- type EnumStmt
- type ExprStmt
- type Expression
- type FloatLiteral
- type ForStmt
- type FunctionStmt
- type HashLiteral
- type HashPair
- type Identifier
- type IfStmt
- type IndexExpr
- type IntegerLiteral
- type InterpolatedString
- type IvarExpr
- type KeywordArg
- type MemberExpr
- type NextStmt
- type NilLiteral
- type Node
- type Param
- type Position
- type Program
- type PropertyDecl
- type RaiseStmt
- type RangeExpr
- type ReturnStmt
- type ScopeExpr
- type Statement
- type StringExpr
- type StringLiteral
- type StringPart
- type StringText
- type SymbolLiteral
- type Token
- type TokenType
- type TryStmt
- type TypeExpr
- type TypeKind
- type UnaryExpr
- type UntilStmt
- type WhileStmt
- type YieldExpr
Constants ¶
const ( RuntimeErrorTypeBase = "RuntimeError" RuntimeErrorTypeAssertion = "AssertionError" RuntimeErrorTypeLimit = "LimitError" )
Canonical runtime error type names recognized by both the parser (for rescue-clause validation) and the runtime (for classifying errors). Kept here so the parser does not need to depend on the runtime package.
Variables ¶
This section is empty.
Functions ¶
func CanonicalRuntimeErrorType ¶
CanonicalRuntimeErrorType returns the canonical spelling of a recognized runtime error type name and reports whether it is known.
func FormatTypeExpr ¶
FormatTypeExpr returns a stable textual representation of a TypeExpr suitable for use in error messages.
func IsIdentifierRune ¶
IsIdentifierRune reports whether r can appear in a Vibescript identifier after the first rune.
func IsIdentifierStart ¶
IsIdentifierStart reports whether r can be the first rune of a Vibescript identifier.
Types ¶
type ArrayLiteral ¶
type ArrayLiteral struct {
Elements []Expression
Position Position
}
ArrayLiteral represents an array literal expression.
func (*ArrayLiteral) Pos ¶
func (e *ArrayLiteral) Pos() Position
type AssignStmt ¶
type AssignStmt struct {
Target Expression
Value Expression
Position Position
}
AssignStmt represents a variable assignment.
func (*AssignStmt) Pos ¶
func (s *AssignStmt) Pos() Position
type BinaryExpr ¶
type BinaryExpr struct {
Left Expression
Operator TokenType
Right Expression
Position Position
}
BinaryExpr represents a binary operator expression (e.g. a + b).
func (*BinaryExpr) Pos ¶
func (e *BinaryExpr) Pos() Position
type BlockLiteral ¶
BlockLiteral represents an inline block (closure) expression.
func (*BlockLiteral) Pos ¶
func (b *BlockLiteral) Pos() Position
type BoolLiteral ¶
BoolLiteral represents a boolean constant (true or false).
func (*BoolLiteral) Pos ¶
func (e *BoolLiteral) Pos() Position
type BreakStmt ¶
type BreakStmt struct {
Position Position
}
BreakStmt represents a break statement that exits a loop.
type CallExpr ¶
type CallExpr struct {
Callee Expression
Args []Expression
KwArgs []KeywordArg
Block *BlockLiteral
Position Position
}
CallExpr represents a function or method call.
type CaseExpr ¶
type CaseExpr struct {
Target Expression
Clauses []CaseWhenClause
ElseExpr Expression
Position Position
}
CaseExpr represents a case/when expression.
type CaseWhenClause ¶
type CaseWhenClause struct {
Values []Expression
Result Expression
}
CaseWhenClause represents a single when branch in a case expression.
type ClassStmt ¶
type ClassStmt struct {
Name string
Methods []*FunctionStmt
ClassMethods []*FunctionStmt
Properties []PropertyDecl
Body []Statement
Position Position
}
ClassStmt represents a class definition.
type ClassVarExpr ¶
ClassVarExpr represents a class variable reference (e.g. @@count).
func (*ClassVarExpr) Pos ¶
func (e *ClassVarExpr) Pos() Position
type EnumMemberStmt ¶
EnumMemberStmt represents a single member in an enum definition.
type EnumStmt ¶
type EnumStmt struct {
Name string
Members []EnumMemberStmt
Position Position
}
EnumStmt represents an enum definition.
type ExprStmt ¶
type ExprStmt struct {
Expr Expression
Position Position
}
ExprStmt wraps an expression used as a statement.
type Expression ¶
type Expression interface {
Node
// contains filtered or unexported methods
}
Expression is the interface implemented by all expression AST nodes.
type FloatLiteral ¶
FloatLiteral represents a floating-point constant.
func (*FloatLiteral) Pos ¶
func (e *FloatLiteral) Pos() Position
type ForStmt ¶
type ForStmt struct {
Iterator string
Iterable Expression
Body []Statement
Position Position
}
ForStmt represents a for-in loop.
type FunctionStmt ¶
type FunctionStmt struct {
Name string
Params []Param
ReturnTy *TypeExpr
Body []Statement
IsClassMethod bool
Exported bool
Private bool
Position Position
}
FunctionStmt represents a function or method definition.
func (*FunctionStmt) Pos ¶
func (s *FunctionStmt) Pos() Position
type HashLiteral ¶
HashLiteral represents a hash/map literal expression.
func (*HashLiteral) Pos ¶
func (e *HashLiteral) Pos() Position
type HashPair ¶
type HashPair struct {
Key Expression
Value Expression
}
HashPair represents a single key-value pair in a hash literal.
type Identifier ¶
Identifier represents a named reference in an expression.
func (*Identifier) Pos ¶
func (e *Identifier) Pos() Position
type IfStmt ¶
type IfStmt struct {
Condition Expression
Consequent []Statement
ElseIf []*IfStmt
Alternate []Statement
Position Position
}
IfStmt represents an if/elsif/else conditional statement.
type IndexExpr ¶
type IndexExpr struct {
Object Expression
Index Expression
Position Position
}
IndexExpr represents a bracket-index access (e.g. arr[0]).
type IntegerLiteral ¶
IntegerLiteral represents an integer constant.
func (*IntegerLiteral) Pos ¶
func (e *IntegerLiteral) Pos() Position
type InterpolatedString ¶
type InterpolatedString struct {
Parts []StringPart
Position Position
}
InterpolatedString represents a string containing embedded expressions.
func (*InterpolatedString) Pos ¶
func (s *InterpolatedString) Pos() Position
type KeywordArg ¶
type KeywordArg struct {
Name string
Value Expression
}
KeywordArg represents a named argument in a function call.
type MemberExpr ¶
type MemberExpr struct {
Object Expression
Property string
Position Position
}
MemberExpr represents a dot-access property lookup (e.g. obj.prop).
func (*MemberExpr) Pos ¶
func (e *MemberExpr) Pos() Position
type NextStmt ¶
type NextStmt struct {
Position Position
}
NextStmt represents a next statement that skips to the next loop iteration.
type NilLiteral ¶
type NilLiteral struct {
Position Position
}
NilLiteral represents the nil literal.
func (*NilLiteral) Pos ¶
func (e *NilLiteral) Pos() Position
type Node ¶
type Node interface {
Pos() Position
}
Node is the interface implemented by all AST nodes.
type Param ¶
type Param struct {
Name string
Type *TypeExpr
DefaultVal Expression
IsIvar bool
}
Param represents a function or block parameter.
func CloneParams ¶
CloneParams returns a deep copy of the given parameter list.
type Position ¶
Position is an alias for source.Position so that AST consumers can receive positions without importing the source package directly.
type Program ¶
type Program struct {
Statements []Statement
}
Program represents the top-level AST node containing all statements.
type PropertyDecl ¶
PropertyDecl represents a property, getter, or setter declaration in a class.
type RaiseStmt ¶
type RaiseStmt struct {
Value Expression
Position Position
}
RaiseStmt represents a raise statement that throws an error.
type RangeExpr ¶
type RangeExpr struct {
Start Expression
End Expression
Position Position
}
RangeExpr represents a range expression (e.g. 1..10).
type ReturnStmt ¶
type ReturnStmt struct {
Value Expression
Position Position
}
ReturnStmt represents a return statement.
func (*ReturnStmt) Pos ¶
func (s *ReturnStmt) Pos() Position
type ScopeExpr ¶
type ScopeExpr struct {
Object Expression
Property string
Position Position
}
ScopeExpr represents a scope-resolution access (e.g. Mod::Name).
type Statement ¶
type Statement interface {
Node
// contains filtered or unexported methods
}
Statement is the interface implemented by all statement AST nodes.
func CloneStatements ¶
CloneStatements returns a deep copy of the given statement slice.
type StringExpr ¶
type StringExpr struct {
Expr Expression
}
StringExpr represents an embedded expression segment in an interpolated string.
type StringLiteral ¶
StringLiteral represents a plain string constant.
func (*StringLiteral) Pos ¶
func (e *StringLiteral) Pos() Position
type StringPart ¶
type StringPart interface {
// contains filtered or unexported methods
}
StringPart is the interface for parts of an interpolated string.
type StringText ¶
type StringText struct {
Text string
}
StringText represents a literal text segment in an interpolated string.
type SymbolLiteral ¶
SymbolLiteral represents a symbol literal (e.g. :foo).
func (*SymbolLiteral) Pos ¶
func (e *SymbolLiteral) Pos() Position
type Token ¶
type Token struct {
Type TokenType
Literal string
Pos source.Position
// End is the exclusive position just past the token's final rune,
// stamped by the lexer from the source text. It is the zero
// Position only for EOF.
End source.Position
}
Token captures lexical information for the parser.
type TokenType ¶
type TokenType string
TokenType identifies the lexical category of a token.
const ( TokenIllegal TokenType = "ILLEGAL" TokenEOF TokenType = "EOF" TokenIdent TokenType = "IDENT" TokenInt TokenType = "INT" TokenFloat TokenType = "FLOAT" TokenString TokenType = "STRING" TokenSymbol TokenType = "SYMBOL" TokenAssign TokenType = "=" TokenPlus TokenType = "+" TokenMinus TokenType = "-" TokenBang TokenType = "!" TokenAsterisk TokenType = "*" TokenSlash TokenType = "/" TokenPercent TokenType = "%" TokenLT TokenType = "<" TokenGT TokenType = ">" TokenLTE TokenType = "<=" TokenGTE TokenType = ">=" TokenEQ TokenType = "==" TokenNotEQ TokenType = "!=" TokenAnd TokenType = "&&" TokenOr TokenType = "||" TokenComma TokenType = "," TokenColon TokenType = ":" TokenScope TokenType = "::" TokenDot TokenType = "." TokenRange TokenType = ".." TokenLParen TokenType = "(" TokenRParen TokenType = ")" TokenLBrace TokenType = "{" TokenRBrace TokenType = "}" TokenLBracket TokenType = "[" TokenRBracket TokenType = "]" TokenPipe TokenType = "|" TokenArrow TokenType = "=>" TokenIvar TokenType = "IVAR" TokenClassVar TokenType = "CLASSVAR" TokenDef TokenType = "DEF" TokenClass TokenType = "CLASS" TokenEnum TokenType = "ENUM" TokenExport TokenType = "EXPORT" TokenSelf TokenType = "SELF" TokenPrivate TokenType = "PRIVATE" TokenProperty TokenType = "PROPERTY" TokenGetter TokenType = "GETTER" TokenSetter TokenType = "SETTER" TokenBegin TokenType = "BEGIN" TokenRescue TokenType = "RESCUE" TokenEnsure TokenType = "ENSURE" TokenRaise TokenType = "RAISE" TokenEnd TokenType = "END" TokenReturn TokenType = "RETURN" TokenYield TokenType = "YIELD" TokenDo TokenType = "DO" TokenFor TokenType = "FOR" TokenWhile TokenType = "WHILE" TokenUntil TokenType = "UNTIL" TokenBreak TokenType = "BREAK" TokenNext TokenType = "NEXT" TokenIn TokenType = "IN" TokenIf TokenType = "IF" TokenCase TokenType = "CASE" TokenWhen TokenType = "WHEN" TokenElsif TokenType = "ELSIF" TokenElse TokenType = "ELSE" TokenTrue TokenType = "TRUE" TokenFalse TokenType = "FALSE" TokenNil TokenType = "NIL" )
func LookupIdent ¶
LookupIdent returns the TokenType for an identifier literal, falling back to TokenIdent when the input is not a reserved keyword.
type TryStmt ¶
type TryStmt struct {
Body []Statement
RescueTy *TypeExpr
Rescue []Statement
Ensure []Statement
Position Position
}
TryStmt represents a begin/rescue/ensure error-handling block.
type TypeExpr ¶
type TypeExpr struct {
Name string
Kind TypeKind
Nullable bool
TypeArgs []*TypeExpr
Shape map[string]*TypeExpr
Union []*TypeExpr
Position Position
}
TypeExpr represents a type annotation in the source code.
func CloneTypeExpr ¶
CloneTypeExpr returns a deep copy of the given type expression.
type TypeKind ¶
type TypeKind int
TypeKind identifies the category of a type expression.
func ResolveType ¶
ResolveType maps a textual type name (with optional trailing "?" to mark nullability) to its TypeKind. It returns TypeUnknown when the name does not match a built-in type.
type UnaryExpr ¶
type UnaryExpr struct {
Operator TokenType
Right Expression
Position Position
}
UnaryExpr represents a unary operator expression (e.g. -x, !y).
type UntilStmt ¶
type UntilStmt struct {
Condition Expression
Body []Statement
Position Position
}
UntilStmt represents an until loop (loops while condition is false).
type WhileStmt ¶
type WhileStmt struct {
Condition Expression
Body []Statement
Position Position
}
WhileStmt represents a while loop.