parser

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrecedenceLowest      int
	PrecedenceAssignment  // =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=
	PrecedenceOr          // ||
	PrecedenceAnd         // &&
	PrecedenceEquals      // == !=
	PrecedenceLessGreater // < > <= >=
	PrecedenceBitwiseOr   // |
	PrecedenceBitwiseXor  // ^
	PrecedenceBitwiseAnd  // &
	PrecedenceShift       // << >>
	PrecedenceSum         // + -
	PrecedenceProduct     // * / %
	PrecedencePrefix      // -x !x ~x
	PrecedenceCall        // function()
	PrecedenceIndex       // array[index]
	PrecedenceMember      // obj.member
	PrecedencePostfix     // i++ i--
)

Operator precedence levels

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessModifier

type AccessModifier int

AccessModifier represents the access level of class members

const (
	AccessPublic AccessModifier = iota
	AccessPrivate
	AccessProtected
)

type ArrayLiteral

type ArrayLiteral struct {
	Token    Token // '[' token
	Elements []Expression
}

ArrayLiteral represents an array literal

func (*ArrayLiteral) Column

func (al *ArrayLiteral) Column() int

func (*ArrayLiteral) Line

func (al *ArrayLiteral) Line() int

func (*ArrayLiteral) TokenLiteral

func (al *ArrayLiteral) TokenLiteral() string

type AssignmentExpression

type AssignmentExpression struct {
	Token    Token // The assignment operator token
	Left     Expression
	Operator string
	Right    Expression
}

AssignmentExpression represents an assignment expression (e.g., x = 5, y += 3)

func (*AssignmentExpression) Column

func (ae *AssignmentExpression) Column() int

func (*AssignmentExpression) Line

func (ae *AssignmentExpression) Line() int

func (*AssignmentExpression) TokenLiteral

func (ae *AssignmentExpression) TokenLiteral() string

type BlockStatement

type BlockStatement struct {
	Token      Token // '{' token
	Statements []Statement
}

BlockStatement represents a block of statements enclosed in braces

func (*BlockStatement) Column

func (bs *BlockStatement) Column() int

func (*BlockStatement) Line

func (bs *BlockStatement) Line() int

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

type BoolLiteral

type BoolLiteral struct {
	Token Token
	Value types.Bool
}

BoolLiteral represents a boolean literal

func (*BoolLiteral) Column

func (bl *BoolLiteral) Column() int

func (*BoolLiteral) Line

func (bl *BoolLiteral) Line() int

func (*BoolLiteral) TokenLiteral

func (bl *BoolLiteral) TokenLiteral() string

type BreakStatement

type BreakStatement struct {
	Token Token // 'break' token
}

BreakStatement represents a break statement

func (*BreakStatement) Column

func (bs *BreakStatement) Column() int

func (*BreakStatement) Line

func (bs *BreakStatement) Line() int

func (*BreakStatement) TokenLiteral

func (bs *BreakStatement) TokenLiteral() string

type CallExpression

type CallExpression struct {
	Token     Token // '(' token
	Function  Expression
	Arguments []Expression
}

CallExpression represents a function call expression

func (*CallExpression) Column

func (ce *CallExpression) Column() int

func (*CallExpression) Line

func (ce *CallExpression) Line() int

func (*CallExpression) TokenLiteral

func (ce *CallExpression) TokenLiteral() string

type CaseStatement

type CaseStatement struct {
	Token       Token // 'case' token
	Expressions []Expression
	Body        *BlockStatement
}

CaseStatement represents a case clause in a switch statement

func (*CaseStatement) Column

func (cs *CaseStatement) Column() int

func (*CaseStatement) Line

func (cs *CaseStatement) Line() int

func (*CaseStatement) TokenLiteral

func (cs *CaseStatement) TokenLiteral() string

type CatchStatement

type CatchStatement struct {
	Token      Token // 'catch' token
	Param      *Identifier
	CatchBlock *BlockStatement
}

CatchStatement represents a catch clause in a try statement

func (*CatchStatement) Column

func (cs *CatchStatement) Column() int

func (*CatchStatement) Line

func (cs *CatchStatement) Line() int

func (*CatchStatement) TokenLiteral

func (cs *CatchStatement) TokenLiteral() string

type CharLiteral

type CharLiteral struct {
	Token Token
	Value types.Char
}

CharLiteral represents a character literal

func (*CharLiteral) Column

func (cl *CharLiteral) Column() int

func (*CharLiteral) Line

func (cl *CharLiteral) Line() int

func (*CharLiteral) TokenLiteral

func (cl *CharLiteral) TokenLiteral() string

type ClassDeclaration

type ClassDeclaration struct {
	Token       Token // 'class' token
	Name        *Identifier
	SuperClass  *Identifier
	Implements  []*Identifier // List of interfaces this class implements
	Constructor *FunctionLiteral
	Methods     []*FunctionLiteral
	Fields      []Statement // Instance and static field declarations
}

ClassDeclaration represents a class declaration

func (*ClassDeclaration) Column

func (cd *ClassDeclaration) Column() int

func (*ClassDeclaration) Line

func (cd *ClassDeclaration) Line() int

func (*ClassDeclaration) TokenLiteral

func (cd *ClassDeclaration) TokenLiteral() string

type ConstStatement

type ConstStatement struct {
	Token Token // 'const' token
	Name  *Identifier
	Value Expression
}

ConstStatement represents a constant declaration

func (*ConstStatement) Column

func (cs *ConstStatement) Column() int

func (*ConstStatement) Line

func (cs *ConstStatement) Line() int

func (*ConstStatement) TokenLiteral

func (cs *ConstStatement) TokenLiteral() string

type ContinueStatement

type ContinueStatement struct {
	Token Token // 'continue' token
}

ContinueStatement represents a continue statement

func (*ContinueStatement) Column

func (cs *ContinueStatement) Column() int

func (*ContinueStatement) Line

func (cs *ContinueStatement) Line() int

func (*ContinueStatement) TokenLiteral

func (cs *ContinueStatement) TokenLiteral() string

type DefaultStatement

type DefaultStatement struct {
	Token Token // 'default' token
	Body  *BlockStatement
}

DefaultStatement represents a default clause in a switch statement

func (*DefaultStatement) Column

func (ds *DefaultStatement) Column() int

func (*DefaultStatement) Line

func (ds *DefaultStatement) Line() int

func (*DefaultStatement) TokenLiteral

func (ds *DefaultStatement) TokenLiteral() string

type DeferStatement

type DeferStatement struct {
	Token Token // 'defer' token
	Call  *CallExpression
}

DeferStatement represents a defer statement

func (*DeferStatement) Column

func (ds *DeferStatement) Column() int

func (*DeferStatement) Line

func (ds *DeferStatement) Line() int

func (*DeferStatement) TokenLiteral

func (ds *DeferStatement) TokenLiteral() string

type DefineStatement

type DefineStatement struct {
	Token Token // ':=' token
	Name  *Identifier
	Value Expression
}

DefineStatement represents a short variable declaration using ':='

func (*DefineStatement) Column

func (ds *DefineStatement) Column() int

func (*DefineStatement) Line

func (ds *DefineStatement) Line() int

func (*DefineStatement) TokenLiteral

func (ds *DefineStatement) TokenLiteral() string

type DoWhileStatement

type DoWhileStatement struct {
	Token     Token // 'do' token
	Body      *BlockStatement
	Condition Expression
}

DoWhileStatement represents a do-while loop statement

func (*DoWhileStatement) Column

func (dws *DoWhileStatement) Column() int

func (*DoWhileStatement) Line

func (dws *DoWhileStatement) Line() int

func (*DoWhileStatement) TokenLiteral

func (dws *DoWhileStatement) TokenLiteral() string

type ExportSpec

type ExportSpec struct {
	Name  *Identifier // Name of the exported item
	Alias *Identifier // Optional alias name
}

ExportSpec represents a single export specifier in an export statement

type ExportStatement

type ExportStatement struct {
	Token       Token         // 'export' token
	Specs       []*ExportSpec // List of export specifiers
	Declaration Statement     // Optional declaration being exported (func, const, etc.)
	IsDefault   bool          // Whether this is a default export
}

ExportStatement represents an export statement

func (*ExportStatement) Column

func (es *ExportStatement) Column() int

func (*ExportStatement) Line

func (es *ExportStatement) Line() int

func (*ExportStatement) TokenLiteral

func (es *ExportStatement) TokenLiteral() string

type Expression

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

Expression is the interface for all expression nodes

type ExpressionStatement

type ExpressionStatement struct {
	Token      Token // The first token of the expression
	Expression Expression
}

ExpressionStatement represents a statement that is just an expression (e.g., function call)

func (*ExpressionStatement) Column

func (es *ExpressionStatement) Column() int

func (*ExpressionStatement) Line

func (es *ExpressionStatement) Line() int

func (*ExpressionStatement) TokenLiteral

func (es *ExpressionStatement) TokenLiteral() string

type FallthroughStatement

type FallthroughStatement struct {
	Token Token // 'fallthrough' token
}

FallthroughStatement represents a fallthrough statement in switch case

func (*FallthroughStatement) Column

func (fs *FallthroughStatement) Column() int

func (*FallthroughStatement) Line

func (fs *FallthroughStatement) Line() int

func (*FallthroughStatement) TokenLiteral

func (fs *FallthroughStatement) TokenLiteral() string

type FinallyStatement

type FinallyStatement struct {
	Token        Token // 'finally' token
	FinallyBlock *BlockStatement
}

FinallyStatement represents a finally clause in a try statement

func (*FinallyStatement) Column

func (fs *FinallyStatement) Column() int

func (*FinallyStatement) Line

func (fs *FinallyStatement) Line() int

func (*FinallyStatement) TokenLiteral

func (fs *FinallyStatement) TokenLiteral() string

type FloatLiteral

type FloatLiteral struct {
	Token Token
	Value types.Float
}

FloatLiteral represents a floating point literal

func (*FloatLiteral) Column

func (fl *FloatLiteral) Column() int

func (*FloatLiteral) Line

func (fl *FloatLiteral) Line() int

func (*FloatLiteral) TokenLiteral

func (fl *FloatLiteral) TokenLiteral() string

type ForStatement

type ForStatement struct {
	Token     Token // 'for' token
	Init      Statement
	Condition Expression
	Update    Statement
	Body      *BlockStatement

	// For...in specific fields
	IsForIn        bool        // Whether this is a for...in loop
	IsNumericRange bool        // Whether iterating over a numeric range
	Key            *Identifier // Key variable for for...in
	Value          *Identifier // Value variable for for...in (optional)
	Iterate        Expression  // The expression to iterate over
}

ForStatement represents a for loop statement

func (*ForStatement) Column

func (fs *ForStatement) Column() int

func (*ForStatement) Line

func (fs *ForStatement) Line() int

func (*ForStatement) TokenLiteral

func (fs *ForStatement) TokenLiteral() string

type FunctionDeclaration

type FunctionDeclaration struct {
	Token      Token // 'func' token
	Name       *Identifier
	Parameters []*FunctionParameter
	Body       *BlockStatement
}

FunctionDeclaration represents a top-level function declaration

func (*FunctionDeclaration) Column

func (fd *FunctionDeclaration) Column() int

func (*FunctionDeclaration) Line

func (fd *FunctionDeclaration) Line() int

func (*FunctionDeclaration) TokenLiteral

func (fd *FunctionDeclaration) TokenLiteral() string

type FunctionLiteral

type FunctionLiteral struct {
	Token          Token // 'func' token
	Name           string
	Parameters     []*FunctionParameter
	Body           *BlockStatement
	IsStatic       bool           // Whether this is a static method
	AccessModifier AccessModifier // Access level of the method
	IsGetter       bool           // Whether this is a getter property
	IsSetter       bool           // Whether this is a setter property
}

FunctionLiteral represents a function literal/expression

func (*FunctionLiteral) Column

func (fl *FunctionLiteral) Column() int

func (*FunctionLiteral) Line

func (fl *FunctionLiteral) Line() int

func (*FunctionLiteral) TokenLiteral

func (fl *FunctionLiteral) TokenLiteral() string

type FunctionParameter

type FunctionParameter struct {
	Name         *Identifier
	DefaultValue Expression
	Variadic     bool
}

FunctionParameter represents a parameter in a function definition

type Identifier

type Identifier struct {
	Token Token
	Value string
}

Identifier represents an identifier (variable name, function name, etc.)

func (*Identifier) Column

func (i *Identifier) Column() int

func (*Identifier) Line

func (i *Identifier) Line() int

func (*Identifier) TokenLiteral

func (i *Identifier) TokenLiteral() string

type IfStatement

type IfStatement struct {
	Token       Token // 'if' token
	Condition   Expression
	Consequence *BlockStatement
	Alternative *BlockStatement
}

IfStatement represents an if statement with optional else clause

func (*IfStatement) Column

func (is *IfStatement) Column() int

func (*IfStatement) Line

func (is *IfStatement) Line() int

func (*IfStatement) TokenLiteral

func (is *IfStatement) TokenLiteral() string

type ImportSpec

type ImportSpec struct {
	Name  *Identifier // Name of the export from the module
	Alias *Identifier // Optional local alias name
}

ImportSpec represents a single import specifier in an import statement

type ImportStatement

type ImportStatement struct {
	Token         Token          // 'import' token
	Specs         []*ImportSpec  // List of import specifiers
	ModulePath    *StringLiteral // Module path for namespace imports
	Namespace     *Identifier    // Optional namespace for import * as
	DefaultImport *Identifier    // Optional default import name
}

ImportStatement represents an import statement

func (*ImportStatement) Column

func (is *ImportStatement) Column() int

func (*ImportStatement) Line

func (is *ImportStatement) Line() int

func (*ImportStatement) TokenLiteral

func (is *ImportStatement) TokenLiteral() string

type IndexExpression

type IndexExpression struct {
	Token Token // '[' token
	Left  Expression
	Index Expression
}

IndexExpression represents an array/index access expression (e.g., arr[0])

func (*IndexExpression) Column

func (ie *IndexExpression) Column() int

func (*IndexExpression) Line

func (ie *IndexExpression) Line() int

func (*IndexExpression) TokenLiteral

func (ie *IndexExpression) TokenLiteral() string

type InfixExpression

type InfixExpression struct {
	Token    Token // The operator token
	Left     Expression
	Operator string
	Right    Expression
}

InfixExpression represents an infix operator expression (e.g., x + y, a * b)

func (*InfixExpression) Column

func (ie *InfixExpression) Column() int

func (*InfixExpression) Line

func (ie *InfixExpression) Line() int

func (*InfixExpression) TokenLiteral

func (ie *InfixExpression) TokenLiteral() string

type IntLiteral

type IntLiteral struct {
	Token Token
	Value types.Int
}

IntLiteral represents an integer literal

func (*IntLiteral) Column

func (il *IntLiteral) Column() int

func (*IntLiteral) Line

func (il *IntLiteral) Line() int

func (*IntLiteral) TokenLiteral

func (il *IntLiteral) TokenLiteral() string

type InterfaceDeclaration

type InterfaceDeclaration struct {
	Token   Token // 'interface' token
	Name    *Identifier
	Methods []*InterfaceMethod
}

InterfaceDeclaration represents an interface declaration

func (*InterfaceDeclaration) Column

func (id *InterfaceDeclaration) Column() int

func (*InterfaceDeclaration) Line

func (id *InterfaceDeclaration) Line() int

func (*InterfaceDeclaration) TokenLiteral

func (id *InterfaceDeclaration) TokenLiteral() string

type InterfaceMethod

type InterfaceMethod struct {
	Name       *Identifier
	Parameters []*FunctionParameter
}

InterfaceMethod represents a method signature in an interface

type LetStatement

type LetStatement struct {
	Token Token // 'let' token
	Name  *Identifier
	Value Expression
}

LetStatement represents a variable declaration with 'let' keyword

func (*LetStatement) Column

func (ls *LetStatement) Column() int

func (*LetStatement) Line

func (ls *LetStatement) Line() int

func (*LetStatement) TokenLiteral

func (ls *LetStatement) TokenLiteral() string

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer converts source code into a stream of tokens

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a new lexer for the given input

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

NextToken returns the next token from the input

type MapLiteral

type MapLiteral struct {
	Token Token // '{' token
	Pairs map[Expression]Expression
}

MapLiteral represents a map literal

func (*MapLiteral) Column

func (ml *MapLiteral) Column() int

func (*MapLiteral) Line

func (ml *MapLiteral) Line() int

func (*MapLiteral) TokenLiteral

func (ml *MapLiteral) TokenLiteral() string

type MemberExpression

type MemberExpression struct {
	Token  Token // '.' token
	Object Expression
	Member *Identifier
}

MemberExpression represents a member access expression (e.g., obj.property)

func (*MemberExpression) Column

func (me *MemberExpression) Column() int

func (*MemberExpression) Line

func (me *MemberExpression) Line() int

func (*MemberExpression) TokenLiteral

func (me *MemberExpression) TokenLiteral() string

type NewExpression

type NewExpression struct {
	Token Token // 'new' token
	Class Expression
	Args  []Expression
}

NewExpression represents a new operator expression (e.g., new ClassName())

func (*NewExpression) Column

func (ne *NewExpression) Column() int

func (*NewExpression) Line

func (ne *NewExpression) Line() int

func (*NewExpression) TokenLiteral

func (ne *NewExpression) TokenLiteral() string

type Node

type Node interface {
	// TokenLiteral returns the literal value of the token associated with this node
	TokenLiteral() string
	// Line returns the line number where this node starts
	Line() int
	// Column returns the column number where this node starts
	Column() int
}

Node is the base interface for all AST nodes

type NullLiteral

type NullLiteral struct {
	Token Token
}

NullLiteral represents a null literal

func (*NullLiteral) Column

func (nl *NullLiteral) Column() int

func (*NullLiteral) Line

func (nl *NullLiteral) Line() int

func (*NullLiteral) TokenLiteral

func (nl *NullLiteral) TokenLiteral() string

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser represents a recursive descent parser

func NewParser

func NewParser(lexer *Lexer) *Parser

NewParser creates a new parser for the given input

func (*Parser) Errors

func (p *Parser) Errors() []string

Errors returns the list of parsing errors

func (*Parser) ParseProgram

func (p *Parser) ParseProgram() *Program

ParseProgram parses the entire input into a Program AST node

type PostfixExpression

type PostfixExpression struct {
	Token    Token // The operator token
	Left     Expression
	Operator string
}

PostfixExpression represents a postfix operator expression (e.g., i++, i--)

func (*PostfixExpression) Column

func (pe *PostfixExpression) Column() int

func (*PostfixExpression) Line

func (pe *PostfixExpression) Line() int

func (*PostfixExpression) TokenLiteral

func (pe *PostfixExpression) TokenLiteral() string

type PrefixExpression

type PrefixExpression struct {
	Token    Token // The operator token
	Operator string
	Right    Expression
}

PrefixExpression represents a prefix operator expression (e.g., !x, -y)

func (*PrefixExpression) Column

func (pe *PrefixExpression) Column() int

func (*PrefixExpression) Line

func (pe *PrefixExpression) Line() int

func (*PrefixExpression) TokenLiteral

func (pe *PrefixExpression) TokenLiteral() string

type Program

type Program struct {
	Statements []Statement
}

Program represents the root node of the AST

func (*Program) Column

func (p *Program) Column() int

Column implements Node interface

func (*Program) Line

func (p *Program) Line() int

Line implements Node interface

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

TokenLiteral implements Node interface

type ReturnStatement

type ReturnStatement struct {
	Token       Token // 'return' token
	ReturnValue Expression
}

ReturnStatement represents a return statement

func (*ReturnStatement) Column

func (rs *ReturnStatement) Column() int

func (*ReturnStatement) Line

func (rs *ReturnStatement) Line() int

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

type Statement

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

Statement is the interface for all statement nodes

type StringLiteral

type StringLiteral struct {
	Token Token
	Value types.String
}

StringLiteral represents a string literal

func (*StringLiteral) Column

func (sl *StringLiteral) Column() int

func (*StringLiteral) Line

func (sl *StringLiteral) Line() int

func (*StringLiteral) TokenLiteral

func (sl *StringLiteral) TokenLiteral() string

type SuperExpression

type SuperExpression struct {
	Token Token // 'super' token
}

SuperExpression represents a 'super' keyword expression

func (*SuperExpression) Column

func (se *SuperExpression) Column() int

func (*SuperExpression) Line

func (se *SuperExpression) Line() int

func (*SuperExpression) TokenLiteral

func (se *SuperExpression) TokenLiteral() string

type SwitchStatement

type SwitchStatement struct {
	Token       Token // 'switch' token
	Expression  Expression
	Cases       []*CaseStatement
	DefaultCase *DefaultStatement
}

SwitchStatement represents a switch statement

func (*SwitchStatement) Column

func (ss *SwitchStatement) Column() int

func (*SwitchStatement) Line

func (ss *SwitchStatement) Line() int

func (*SwitchStatement) TokenLiteral

func (ss *SwitchStatement) TokenLiteral() string

type TernaryExpression

type TernaryExpression struct {
	Token     Token // '?' token
	Condition Expression
	TrueExpr  Expression
	FalseExpr Expression
}

TernaryExpression represents a ternary conditional expression (e.g., condition ? true : false)

func (*TernaryExpression) Column

func (te *TernaryExpression) Column() int

func (*TernaryExpression) Line

func (te *TernaryExpression) Line() int

func (*TernaryExpression) TokenLiteral

func (te *TernaryExpression) TokenLiteral() string

type ThisExpression

type ThisExpression struct {
	Token Token // 'this' token
}

ThisExpression represents a 'this' keyword expression

func (*ThisExpression) Column

func (te *ThisExpression) Column() int

func (*ThisExpression) Line

func (te *ThisExpression) Line() int

func (*ThisExpression) TokenLiteral

func (te *ThisExpression) TokenLiteral() string

type ThrowStatement

type ThrowStatement struct {
	Token Token // 'throw' token
	Value Expression
}

ThrowStatement represents a throw statement

func (*ThrowStatement) Column

func (ts *ThrowStatement) Column() int

func (*ThrowStatement) Line

func (ts *ThrowStatement) Line() int

func (*ThrowStatement) TokenLiteral

func (ts *ThrowStatement) TokenLiteral() string

type Token

type Token struct {
	Type    TokenType
	Literal string
	Line    int
	Column  int
}

Token represents a lexical token with type, value, and position information

type TokenType

type TokenType int

TokenType represents the type of lexical token

const (
	// Special tokens
	TokenEOF TokenType = iota
	TokenError
	TokenComment

	// Literals
	TokenIdentifier // main, x, y
	TokenInt        // 12345
	TokenFloat      // 123.45
	TokenString     // "hello world"
	TokenChar       // 'a'
	TokenRawString  // `raw string`

	// Operators
	TokenPlus       // +
	TokenMinus      // -
	TokenAsterisk   // *
	TokenSlash      // /
	TokenPercent    // %
	TokenAmpersand  // &
	TokenPipe       // |
	TokenCaret      // ^
	TokenTilde      // ~
	TokenLeftShift  // <<
	TokenRightShift // >>
	TokenAnd        // &&
	TokenOr         // ||
	TokenBang       // !
	TokenQuestion   // ?
	TokenColon      // :
	TokenAssign     // =

	// Comparison operators
	TokenEqual    // ==
	TokenNotEqual // !=
	TokenLT       // <
	TokenLTE      // <=
	TokenGT       // >
	TokenGTE      // >=

	// Assignment operators
	TokenPlusAssign   // +=
	TokenMinusAssign  // -=
	TokenMulAssign    // *=
	TokenDivAssign    // /=
	TokenModAssign    // %=
	TokenAndAssign    // &=
	TokenOrAssign     // |=
	TokenXorAssign    // ^=
	TokenLShiftAssign // <<=
	TokenRShiftAssign // >>=
	TokenDefine       // :=
	TokenInc          // ++
	TokenDec          // --

	// Delimiters
	TokenLeftParen    // (
	TokenRightParen   // )
	TokenLeftBracket  // [
	TokenRightBracket // ]
	TokenLeftBrace    // {
	TokenRightBrace   // }
	TokenComma        // ,
	TokenDot          // .
	TokenSemicolon    // ;
	TokenEllipsis     // ...
	TokenArrow        // =>

	TokenVar
	TokenLet
	TokenConst
	TokenFunc
	TokenClass
	TokenIf
	TokenElse
	TokenFor
	TokenWhile
	TokenDo
	TokenSwitch
	TokenCase
	TokenDefault
	TokenBreak
	TokenContinue
	TokenFallthrough
	TokenIn
	TokenReturn
	TokenThrow
	TokenTry
	TokenCatch
	TokenFinally
	TokenDefer
	TokenImport
	TokenExport
	TokenAs
	TokenFrom
	TokenThis
	TokenSuper
	TokenNew
	TokenStatic
	TokenPublic
	TokenPrivate
	TokenProtected
	TokenGet
	TokenSet
	TokenInterface
	TokenImplements
	TokenNil
	TokenTrue
	TokenFalse
)

Token types

func LookupKeyword

func LookupKeyword(ident string) TokenType

LookupKeyword checks if an identifier is a keyword

func (TokenType) IsKeyword

func (t TokenType) IsKeyword() bool

IsKeyword returns true if the token type is a keyword

func (TokenType) String

func (t TokenType) String() string

String returns the string representation of the token type

type TryStatement

type TryStatement struct {
	Token    Token // 'try' token
	TryBlock *BlockStatement
	Catch    *CatchStatement
	Finally  *FinallyStatement
}

TryStatement represents a try-catch-finally statement

func (*TryStatement) Column

func (ts *TryStatement) Column() int

func (*TryStatement) Line

func (ts *TryStatement) Line() int

func (*TryStatement) TokenLiteral

func (ts *TryStatement) TokenLiteral() string

type VarStatement

type VarStatement struct {
	Token Token // 'var' token
	Name  *Identifier
	Value Expression
}

VarStatement represents a variable declaration with 'var' keyword

func (*VarStatement) Column

func (vs *VarStatement) Column() int

func (*VarStatement) Line

func (vs *VarStatement) Line() int

func (*VarStatement) TokenLiteral

func (vs *VarStatement) TokenLiteral() string

type WhileStatement

type WhileStatement struct {
	Token     Token // 'while' token
	Condition Expression
	Body      *BlockStatement
}

WhileStatement represents a while loop statement

func (*WhileStatement) Column

func (ws *WhileStatement) Column() int

func (*WhileStatement) Line

func (ws *WhileStatement) Line() int

func (*WhileStatement) TokenLiteral

func (ws *WhileStatement) TokenLiteral() string

Jump to

Keyboard shortcuts

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