ast

package
v0.29.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
const (
	RuntimeErrorTypeBase      = "RuntimeError"
	RuntimeErrorTypeAssertion = "AssertionError"
)

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

func CanonicalRuntimeErrorType(name string) (string, bool)

CanonicalRuntimeErrorType returns the canonical spelling of a recognized runtime error type name and reports whether it is known.

func FormatTypeExpr

func FormatTypeExpr(ty *TypeExpr) string

FormatTypeExpr returns a stable textual representation of a TypeExpr suitable for use in error messages.

func IsIdentifierRune

func IsIdentifierRune(r rune) bool

IsIdentifierRune reports whether r can appear in a Vibescript identifier after the first rune.

func IsIdentifierStart

func IsIdentifierStart(r rune) bool

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

type BlockLiteral struct {
	Params   []Param
	Body     []Statement
	Position Position
}

BlockLiteral represents an inline block (closure) expression.

func (*BlockLiteral) Pos

func (b *BlockLiteral) Pos() Position

type BoolLiteral

type BoolLiteral struct {
	Value    bool
	Position Position
}

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.

func (*BreakStmt) Pos

func (s *BreakStmt) Pos() Position

type CallExpr

type CallExpr struct {
	Callee   Expression
	Args     []Expression
	KwArgs   []KeywordArg
	Block    *BlockLiteral
	Position Position
}

CallExpr represents a function or method call.

func (*CallExpr) Pos

func (e *CallExpr) Pos() Position

type CaseExpr

type CaseExpr struct {
	Target   Expression
	Clauses  []CaseWhenClause
	ElseExpr Expression
	Position Position
}

CaseExpr represents a case/when expression.

func (*CaseExpr) Pos

func (e *CaseExpr) Pos() Position

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.

func (*ClassStmt) Pos

func (s *ClassStmt) Pos() Position

type ClassVarExpr

type ClassVarExpr struct {
	Name     string
	Position Position
}

ClassVarExpr represents a class variable reference (e.g. @@count).

func (*ClassVarExpr) Pos

func (e *ClassVarExpr) Pos() Position

type EnumMemberStmt

type EnumMemberStmt struct {
	Name     string
	Position Position
}

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.

func (*EnumStmt) Pos

func (s *EnumStmt) Pos() Position

type ExprStmt

type ExprStmt struct {
	Expr     Expression
	Position Position
}

ExprStmt wraps an expression used as a statement.

func (*ExprStmt) Pos

func (s *ExprStmt) Pos() Position

type Expression

type Expression interface {
	Node
	// contains filtered or unexported methods
}

Expression is the interface implemented by all expression AST nodes.

type FloatLiteral

type FloatLiteral struct {
	Value    float64
	Position Position
}

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.

func (*ForStmt) Pos

func (s *ForStmt) Pos() Position

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

type HashLiteral struct {
	Pairs    []HashPair
	Position Position
}

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

type Identifier struct {
	Name     string
	Position Position
}

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.

func (*IfStmt) Pos

func (s *IfStmt) Pos() Position

type IndexExpr

type IndexExpr struct {
	Object   Expression
	Index    Expression
	Position Position
}

IndexExpr represents a bracket-index access (e.g. arr[0]).

func (*IndexExpr) Pos

func (e *IndexExpr) Pos() Position

type IntegerLiteral

type IntegerLiteral struct {
	Value    int64
	Position Position
}

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 IvarExpr

type IvarExpr struct {
	Name     string
	Position Position
}

IvarExpr represents an instance variable reference (e.g. @name).

func (*IvarExpr) Pos

func (e *IvarExpr) 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.

func (*NextStmt) Pos

func (s *NextStmt) Pos() Position

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

func CloneParams(params []Param) []Param

CloneParams returns a deep copy of the given parameter list.

type Position

type Position = source.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.

func (*Program) Pos

func (p *Program) Pos() Position

type PropertyDecl

type PropertyDecl struct {
	Names    []string
	Kind     string // property/getter/setter
	Position Position
}

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.

func (*RaiseStmt) Pos

func (s *RaiseStmt) Pos() Position

type RangeExpr

type RangeExpr struct {
	Start    Expression
	End      Expression
	Position Position
}

RangeExpr represents a range expression (e.g. 1..10).

func (*RangeExpr) Pos

func (e *RangeExpr) Pos() Position

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).

func (*ScopeExpr) Pos

func (e *ScopeExpr) Pos() Position

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

Statement is the interface implemented by all statement AST nodes.

func CloneStatements

func CloneStatements(statements []Statement) []Statement

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

type StringLiteral struct {
	Value    string
	Position Position
}

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

type SymbolLiteral struct {
	Name     string
	Position Position
}

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
}

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

func LookupIdent(ident string) TokenType

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.

func (*TryStmt) Pos

func (s *TryStmt) Pos() Position

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

func CloneTypeExpr(ty *TypeExpr) *TypeExpr

CloneTypeExpr returns a deep copy of the given type expression.

type TypeKind

type TypeKind int

TypeKind identifies the category of a type expression.

const (
	// TypeAny is the unconstrained type that matches any value.
	TypeAny TypeKind = iota
	TypeInt
	TypeFloat
	TypeNumber
	TypeString
	TypeBool
	TypeNil
	TypeDuration
	TypeTime
	TypeMoney
	TypeArray
	TypeHash
	TypeFunction
	TypeShape
	TypeUnion
	TypeEnum
	TypeUnknown
)

func ResolveType

func ResolveType(name string) (TypeKind, bool)

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).

func (*UnaryExpr) Pos

func (e *UnaryExpr) Pos() Position

type UntilStmt

type UntilStmt struct {
	Condition Expression
	Body      []Statement
	Position  Position
}

UntilStmt represents an until loop (loops while condition is false).

func (*UntilStmt) Pos

func (s *UntilStmt) Pos() Position

type WhileStmt

type WhileStmt struct {
	Condition Expression
	Body      []Statement
	Position  Position
}

WhileStmt represents a while loop.

func (*WhileStmt) Pos

func (s *WhileStmt) Pos() Position

type YieldExpr

type YieldExpr struct {
	Args     []Expression
	Position Position
}

YieldExpr represents a yield call that invokes the enclosing block.

func (*YieldExpr) Pos

func (y *YieldExpr) Pos() Position

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL