import "github.com/dev-kas/virtlang-go/v4/ast"- type ArrayLiteral
- type BinaryExpr
- type BinaryOperator
- type BreakStmt
- type CallExpr
- type Class
- type ClassMethod
- type ClassProperty
- type CompareExpr
- type CompareOperator
- type ContinueStmt
- type Declaration
- type DestructureArrayElement
- type DestructureArrayPattern
- type DestructureDeclaration
- type DestructureObjectPattern
- type DestructureObjectProperty
- type DestructurePattern
- type Expr
- type FnDeclaration
- type Identifier
- type IfStatement
- type LogicalExpr
- type LogicalOperator
- type MemberExpr
- type NodeType
- type NumericLiteral
- type ObjectLiteral
- type Program
- type Property
- type ReturnStmt
- type SourceMetadata
- type Stmt
- type StringLiteral
- type TryCatchStmt
- type VarAssignmentExpr
- type VarDeclaration
- type WhileLoop
type ArrayLiteral struct {
Elements []Expr
SourceMetadata
}func (o *ArrayLiteral) GetSourceMetadata() SourceMetadatafunc (o *ArrayLiteral) GetType() NodeTypetype BinaryExpr struct {
LHS Expr
RHS Expr
Operator BinaryOperator
SourceMetadata
}func (b *BinaryExpr) GetSourceMetadata() SourceMetadatafunc (b *BinaryExpr) GetType() NodeTypetype BinaryOperator stringconst (
Plus BinaryOperator = "+"
Minus BinaryOperator = "-"
Multiply BinaryOperator = "*"
Divide BinaryOperator = "/"
Modulo BinaryOperator = "%"
)type BreakStmt struct {
SourceMetadata
}func (r *BreakStmt) GetSourceMetadata() SourceMetadatafunc (r *BreakStmt) GetType() NodeTypetype CallExpr struct {
Args []Expr
Callee Expr
SourceMetadata
}func (c *CallExpr) GetSourceMetadata() SourceMetadatafunc (c *CallExpr) GetType() NodeTypetype Class struct {
Name string
Body []Stmt
Constructor *ClassMethod
SourceMetadata
}func (c *Class) GetSourceMetadata() SourceMetadatafunc (c *Class) GetType() NodeTypetype ClassMethod struct {
Name string
Body []Stmt
Params []string
IsPublic bool
SourceMetadata
}func (c *ClassMethod) GetSourceMetadata() SourceMetadatafunc (c *ClassMethod) GetType() NodeTypetype ClassProperty struct {
Name string
Value Expr
IsPublic bool
SourceMetadata
}func (c *ClassProperty) GetSourceMetadata() SourceMetadatafunc (c *ClassProperty) GetType() NodeTypetype CompareExpr struct {
LHS Expr
RHS Expr
Operator CompareOperator
SourceMetadata
}func (c *CompareExpr) GetSourceMetadata() SourceMetadatafunc (c *CompareExpr) GetType() NodeTypetype CompareOperator stringconst (
LessThanEqual CompareOperator = "<="
LessThan CompareOperator = "<"
GreaterThanEqual CompareOperator = ">="
GreaterThan CompareOperator = ">"
Equal CompareOperator = "=="
NotEqual CompareOperator = "!="
)type ContinueStmt struct {
SourceMetadata
}func (r *ContinueStmt) GetSourceMetadata() SourceMetadatafunc (r *ContinueStmt) GetType() NodeTypetype Declaration interface {
Stmt
// contains filtered or unexported methods
}type DestructureArrayElement struct {
Default Expr
Name string
DeconstructChildren DestructurePattern
Skipped bool
SourceMetadata
}func (v *DestructureArrayElement) GetSourceMetadata() SourceMetadatafunc (v *DestructureArrayElement) GetType() NodeTypetype DestructureArrayPattern struct {
Elements []DestructureArrayElement
Rest *string
SourceMetadata
}func (v *DestructureArrayPattern) GetSourceMetadata() SourceMetadatafunc (v *DestructureArrayPattern) GetType() NodeTypetype DestructureDeclaration struct {
Constant bool
Pattern DestructurePattern
Value Expr
SourceMetadata
}func (v *DestructureDeclaration) GetSourceMetadata() SourceMetadatafunc (v *DestructureDeclaration) GetType() NodeTypetype DestructureObjectPattern struct {
Properties []DestructureObjectProperty
Rest *string
SourceMetadata
}func (v *DestructureObjectPattern) GetSourceMetadata() SourceMetadatafunc (v *DestructureObjectPattern) GetType() NodeTypetype DestructureObjectProperty struct {
Key string
Default Expr
Name string
DeconstructChildren DestructurePattern
SourceMetadata
}func (v *DestructureObjectProperty) GetSourceMetadata() SourceMetadatafunc (v *DestructureObjectProperty) GetType() NodeTypetype DestructurePattern interface {
Expr
// contains filtered or unexported methods
}type Expr interface {
GetType() NodeType
GetSourceMetadata() SourceMetadata
}type FnDeclaration struct {
Params []string
Name string
Body []Stmt
Anonymous bool
SourceMetadata
}func (f *FnDeclaration) GetSourceMetadata() SourceMetadatafunc (f *FnDeclaration) GetType() NodeTypetype Identifier struct {
Symbol string
SourceMetadata
}func (i *Identifier) GetSourceMetadata() SourceMetadatafunc (i *Identifier) GetType() NodeTypetype IfStatement struct {
Body []Stmt
Condition Expr
Else []Stmt // Optional else block
ElseIf []*IfStatement // Optional else-if branches
SourceMetadata
}func (i *IfStatement) GetSourceMetadata() SourceMetadatafunc (i *IfStatement) GetType() NodeTypetype LogicalExpr struct {
LHS *Expr // Optional LHS for unary operators
RHS Expr
Operator LogicalOperator
SourceMetadata
}func (l *LogicalExpr) GetSourceMetadata() SourceMetadatafunc (l *LogicalExpr) GetType() NodeTypetype LogicalOperator stringconst (
LogicalAND LogicalOperator = "&&"
LogicalOR LogicalOperator = "||"
LogicalNilCoalescing LogicalOperator = "??"
LogicalNOT LogicalOperator = "!"
)type MemberExpr struct {
Object Expr
Value Expr
Computed bool
SourceMetadata
}func (m *MemberExpr) GetSourceMetadata() SourceMetadatafunc (m *MemberExpr) GetType() NodeTypetype NodeType intconst (
ProgramNode NodeType = iota
VarDeclarationNode
FnDeclarationNode
IfStatementNode
ClassNode
ClassMethodNode
ClassPropertyNode
WhileLoopNode
VarAssignmentExprNode
TryCatchStmtNode
MemberExprNode
ReturnStmtNode
BreakStmtNode
ContinueStmtNode
CallExprNode
PropertyNode
ObjectLiteralNode
ArrayLiteralNode
NumericLiteralNode
StringLiteralNode
IdentifierNode
CompareExprNode
BinaryExprNode
LogicalExprNode
DestructureDeclarationNode
DestructureArrayPatternNode
DestructureArrayElementNode
DestructureObjectPatternNode
DestructureObjectPropertyNode
)func (n NodeType) String() stringtype NumericLiteral struct {
Value float64
SourceMetadata
}func (n *NumericLiteral) GetSourceMetadata() SourceMetadatafunc (n *NumericLiteral) GetType() NodeTypetype ObjectLiteral struct {
Properties []Property
SourceMetadata
}func (o *ObjectLiteral) GetSourceMetadata() SourceMetadatafunc (o *ObjectLiteral) GetType() NodeTypetype Program struct {
Stmts []Stmt
SourceMetadata
}func (p *Program) GetSourceMetadata() SourceMetadatafunc (p *Program) GetType() NodeTypetype Property struct {
Key string
Value Expr
SourceMetadata
}func (p *Property) GetSourceMetadata() SourceMetadatafunc (p *Property) GetType() NodeTypetype ReturnStmt struct {
Value Expr
SourceMetadata
}func (r *ReturnStmt) GetSourceMetadata() SourceMetadatafunc (r *ReturnStmt) GetType() NodeTypetype SourceMetadata struct {
StartLine int
StartColumn int
EndLine int
EndColumn int
Filename string
}type Stmt interface {
GetType() NodeType
GetSourceMetadata() SourceMetadata
}type StringLiteral struct {
Value string
SourceMetadata
}func (s *StringLiteral) GetSourceMetadata() SourceMetadatafunc (s *StringLiteral) GetType() NodeTypetype TryCatchStmt struct {
Try []Stmt
Catch []Stmt
CatchVar string
SourceMetadata
}func (t *TryCatchStmt) GetSourceMetadata() SourceMetadatafunc (t *TryCatchStmt) GetType() NodeTypetype VarAssignmentExpr struct {
Assignee Expr
Value Expr
SourceMetadata
}func (v *VarAssignmentExpr) GetSourceMetadata() SourceMetadatafunc (v *VarAssignmentExpr) GetType() NodeTypetype VarDeclaration struct {
Constant bool
Identifier string
Value Expr
SourceMetadata
}func (v *VarDeclaration) GetSourceMetadata() SourceMetadatafunc (v *VarDeclaration) GetType() NodeTypetype WhileLoop struct {
Body []Stmt
Condition Expr
SourceMetadata
}func (w *WhileLoop) GetSourceMetadata() SourceMetadatafunc (w *WhileLoop) GetType() NodeTypeimport "github.com/dev-kas/virtlang-go/v4/debugger"- Variables
- type BreakpointManager
- type CallStack
- type Debugger
- func NewDebugger(env *environment.Environment) *Debugger
- func (d *Debugger) Continue() error
- func (d *Debugger) IsDebuggable(nodeType ast.NodeType) bool
- func (d *Debugger) Pause() error
- func (d *Debugger) PopFrame()
- func (d *Debugger) PushFrame(frame StackFrame)
- func (d *Debugger) ShouldStop(filename string, line int) bool
- func (d *Debugger) StepInto() error
- func (d *Debugger) StepOut() error
- func (d *Debugger) StepOver() error
- func (d *Debugger) TakeSnapshot()
- func (d *Debugger) WaitIfPaused(nodeType ast.NodeType)
- type Snapshot
- type Snapshots
- type StackFrame
- type State
- type StepType
var Debuggables = map[ast.NodeType]struct{}{
ast.VarDeclarationNode: {},
ast.VarAssignmentExprNode: {},
ast.IfStatementNode: {},
ast.WhileLoopNode: {},
ast.ReturnStmtNode: {},
ast.ContinueStmtNode: {},
ast.BreakStmtNode: {},
ast.TryCatchStmtNode: {},
ast.CallExprNode: {},
ast.FnDeclarationNode: {},
ast.ClassNode: {},
ast.ClassMethodNode: {},
ast.ClassPropertyNode: {},
ast.ProgramNode: {},
}type BreakpointManager struct {
Breakpoints map[string]bool
}func NewBreakpointManager() *BreakpointManagerfunc (bm *BreakpointManager) Clear()func (bm *BreakpointManager) Has(file string, line int) boolfunc (bm *BreakpointManager) Remove(file string, line int)func (bm *BreakpointManager) Set(file string, line int)type CallStack []StackFramefunc DeepCopyCallStack(stack CallStack) CallStackDeepCopyCallStack creates a deep copy of the call stack
type Debugger struct {
BreakpointManager BreakpointManager
Environment *environment.Environment
State State
CurrentFile string
CurrentLine int
CallStack CallStack
Snapshots Snapshots
// contains filtered or unexported fields
}func NewDebugger(env *environment.Environment) *Debuggerfunc (d *Debugger) Continue() errorfunc (d *Debugger) IsDebuggable(nodeType ast.NodeType) boolfunc (d *Debugger) Pause() errorfunc (d *Debugger) PopFrame()func (d *Debugger) PushFrame(frame StackFrame)func (d *Debugger) ShouldStop(filename string, line int) boolfunc (d *Debugger) StepInto() errorfunc (d *Debugger) StepOut() errorfunc (d *Debugger) StepOver() errorfunc (d *Debugger) TakeSnapshot()func (d *Debugger) WaitIfPaused(nodeType ast.NodeType)type Snapshot struct {
Stack CallStack
Env *environment.Environment
}type Snapshots []Snapshottype StackFrame struct {
Name string
Filename string
Line int
}type State stringconst (
RunningState State = "running"
PausedState State = "paused"
SteppingState State = "stepping"
)type StepType stringconst (
StepInto StepType = "step_into"
StepOver StepType = "step_over"
StepOut StepType = "step_out"
)import "github.com/dev-kas/virtlang-go/v4/environment"- type Environment
- func DeepCopy(env *Environment) *Environment
- func NewEnvironment(fork *Environment) *Environment
- func (e *Environment) AssignVar(name string, value shared.RuntimeValue) (*shared.RuntimeValue, *errors.RuntimeError)
- func (e *Environment) DeclareVar(name string, value shared.RuntimeValue, constant bool) (*shared.RuntimeValue, *errors.RuntimeError)
- func (e *Environment) LookupVar(name string) (*shared.RuntimeValue, *errors.RuntimeError)
- func (e *Environment) Resolve(varname string) (*Environment, *errors.RuntimeError)
type Environment struct {
Parent *Environment
Variables map[string]*shared.RuntimeValue
Constants map[string]struct{}
Global bool
Mutex sync.RWMutex
}func DeepCopy(env *Environment) *EnvironmentDeepCopy creates a deep copy of the environment
func NewEnvironment(fork *Environment) *Environmentfunc (e *Environment) AssignVar(name string, value shared.RuntimeValue) (*shared.RuntimeValue, *errors.RuntimeError)func (e *Environment) DeclareVar(name string, value shared.RuntimeValue, constant bool) (*shared.RuntimeValue, *errors.RuntimeError)func (e *Environment) LookupVar(name string) (*shared.RuntimeValue, *errors.RuntimeError)func (e *Environment) Resolve(varname string) (*Environment, *errors.RuntimeError)import "github.com/dev-kas/virtlang-go/v4/errors"- type InternalCommunicationProtocol
- type InternalCommunicationProtocolTypes
- type LexerError
- type ParserError
- type Position
- type RuntimeError
- type SyntaxError
type InternalCommunicationProtocol struct {
Type InternalCommunicationProtocolTypes
RValue *shared.RuntimeValue
}--- InternalCommunicationProtocol ---
type InternalCommunicationProtocolTypes intconst (
ICP_Return InternalCommunicationProtocolTypes = iota
ICP_Continue
ICP_Break
)--- LexerError ---
type LexerError struct {
Character rune // The problematic character
Pos Position // Position (Line/Col) of the character
Message string // Optional: for specific messages like "unclosed comment"
}func NewLexerError(char rune, pos Position) *LexerErrorNewLexerError creates a new LexerError for an unexpected character (Message will be empty).
func NewLexerErrorf(pos Position, charForContext rune, format string, args ...interface{}) *LexerErrorNewLexerErrorf creates a new LexerError with a custom message. 'charForContext' can be the opening delimiter (e.g., '/' for unclosed comment) or 0 if not relevant. The Message field will be populated by the formatted string.
func (e *LexerError) Error() string--- ParserError --- Often, ParserError is very similar to SyntaxError.
type ParserError struct {
Token string // The literal of the unexpected token
Start Position // Start position of the token
End Position // End position of the token
Message string // Optional: More specific message about why it's an error
}func NewParserError(tokenLiteral string, start, end Position) *ParserErrorNewParserError creates a new ParserError for an unexpected token.
func NewParserErrorf(start, end Position, format string, args ...interface{}) *ParserErrorNewParserErrorf creates a new ParserError with a custom formatted message.
func (e *ParserError) Error() stringtype Position struct {
Line int // 1-based line number
Col int // 1-based column number
}--- RuntimeError ---
type RuntimeError struct {
Message string
InternalCommunicationProtocol *InternalCommunicationProtocol
}func (e *RuntimeError) Error() string--- SyntaxError ---
type SyntaxError struct {
Expected string // What was expected
Got string // What was actually found (e.g., token literal or type)
Start Position // Start position of the problematic syntax
End Position // End position of the problematic syntax
Message string // Optional additional message
}func NewSyntaxError(expected string, gotLiteral string, start, end Position) *SyntaxErrorNewSyntaxError creates a new SyntaxError. 'gotLiteral' is often the token.Literal that caused the error. 'start' and 'end' define the span of the problematic token/syntax.
func NewSyntaxErrorf(start, end Position, format string, args ...interface{}) *SyntaxErrorNewSyntaxErrorf creates a new SyntaxError with a custom message.
func (e *SyntaxError) Error() stringimport "github.com/dev-kas/virtlang-go/v4/evaluator"func Evaluate(astNode ast.Stmt, env *environment.Environment, dbgr *debugger.Debugger) (*shared.RuntimeValue, *errors.RuntimeError)`dbgr` circulates the evaluator
import "github.com/dev-kas/virtlang-go/v4/helpers"func IsTruthy(value *shared.RuntimeValue) boolIsTruthy determines whether a VirtLang RuntimeValue should be considered "truthy" in boolean contexts (like if statements and while loops).
Truthiness rules: - Boolean: true is truthy, false is falsy - Number: non-zero is truthy, zero is falsy - String: non-empty is truthy, empty is falsy - Nil: always falsy - Object: always truthy (even empty objects) - Array: always truthy (even empty arrays) - Function: always truthy - NativeFN: always truthy - ClassInstance: always truthy - Class: always truthy - Unknown: always truthy
import "github.com/dev-kas/virtlang-go/v4/lexer"- Variables
- func IsAlpha(r rune) bool
- func IsAlphaNumeric(r rune) bool
- func IsBinaryOperator(r rune) bool
- func IsComparisonOperator(r string) bool
- func IsLogicalOperator(r string) bool
- func IsNumeric(r rune) bool
- func IsSkippable(r rune) bool
- func Stringify(t TokenType) string
- func UnescapeString(s string) (string, error)
- type Token
- type TokenType
var KEYWORDS = map[string]TokenType{
"let": Let,
"const": Const,
"fn": Fn,
"if": If,
"else": Else,
"while": WhileLoop,
"try": Try,
"catch": Catch,
"return": Return,
"break": Break,
"continue": Continue,
"class": Class,
"public": Public,
"private": Private,
}var REVERSE_KEYWORDS = make(map[TokenType]string, len(KEYWORDS))func IsAlpha(r rune) boolfunc IsAlphaNumeric(r rune) boolfunc IsBinaryOperator(r rune) boolfunc IsComparisonOperator(r string) boolfunc IsLogicalOperator(r string) boolfunc IsNumeric(r rune) boolfunc IsSkippable(r rune) boolfunc Stringify(t TokenType) stringfunc UnescapeString(s string) (string, error)type Token struct {
Type TokenType
Literal string
StartLine int
StartCol int
EndLine int
EndCol int
}func NewToken(value string, tokenType TokenType, startLine, startCol, endLine, endCol int) Tokenfunc Tokenize(srcCode string) ([]Token, *errors.LexerError)type TokenType intconst (
Number TokenType = iota // 0 - 9
Identifier // a - z A - Z 0 - 9 _ $
Equals // =
BinOperator // / * + _
OParen // (
CParen // )
Let // let
Const // const
SemiColon // ;
Comma // ,
Colon // :
OBrace // {
CBrace // }
OBracket // [
CBracket // ]
Dot // .
Fn // fn
ComOperator // < == > != <= >=
If // if
Else // else
String // '...' "..."
WhileLoop // while
Comment // /*...*/ //...
Try // try
Catch // catch
Return // return
Break // break
Continue // continue
Class // class
Public // public
Private // private
LogicalOperator // && || ?? !
EOF // end of file
)import "github.com/dev-kas/virtlang-go/v4/parser"type Parser struct {
// contains filtered or unexported fields
}func New(filename string) *Parserfunc (p *Parser) ProduceAST(srcCode string) (*ast.Program, error)import "github.com/dev-kas/virtlang-go/v4/shared"func Stringify(v ValueType) stringtype RuntimeValue struct {
Type ValueType
Value any
}type ValueType intconst (
Nil ValueType = iota
Number
Boolean
Object
Array
NativeFN
Function
String
Class
ClassInstance
)import "github.com/dev-kas/virtlang-go/v4/values"- func MK_ARRAY(value []shared.RuntimeValue) shared.RuntimeValue
- func MK_BOOL(value bool) shared.RuntimeValue
- func MK_CLASS(name string, body []ast.Stmt, constructor *ast.ClassMethod, declarationEnv *environment.Environment) shared.RuntimeValue
- func MK_CLASS_INSTANCE(class *ClassValue, publics map[string]bool, data *environment.Environment) shared.RuntimeValue
- func MK_NATIVE_FN(fn NativeFunction) shared.RuntimeValue
- func MK_NIL() shared.RuntimeValue
- func MK_NUMBER(value float64) shared.RuntimeValue
- func MK_OBJECT(value map[string]*shared.RuntimeValue) shared.RuntimeValue
- func MK_STRING(value string) shared.RuntimeValue
- type ClassInstanceValue
- type ClassValue
- type FunctionValue
- type NativeFunction
func MK_ARRAY(value []shared.RuntimeValue) shared.RuntimeValuefunc MK_BOOL(value bool) shared.RuntimeValuefunc MK_CLASS(name string, body []ast.Stmt, constructor *ast.ClassMethod, declarationEnv *environment.Environment) shared.RuntimeValuefunc MK_CLASS_INSTANCE(class *ClassValue, publics map[string]bool, data *environment.Environment) shared.RuntimeValuefunc MK_NATIVE_FN(fn NativeFunction) shared.RuntimeValuefunc MK_NIL() shared.RuntimeValuefunc MK_NUMBER(value float64) shared.RuntimeValuefunc MK_OBJECT(value map[string]*shared.RuntimeValue) shared.RuntimeValuefunc MK_STRING(value string) shared.RuntimeValuetype ClassInstanceValue struct {
Type shared.ValueType
Class ClassValue
Publics map[string]bool
Data *environment.Environment
}type ClassValue struct {
Type shared.ValueType
Value any
Name string
Body []ast.Stmt
DeclarationEnv *environment.Environment
Constructor *ast.ClassMethod
}type FunctionValue struct {
Type shared.ValueType
Value any
Name string
Params []string
DeclarationEnv *environment.Environment
Body []ast.Stmt
}type NativeFunction func(args []shared.RuntimeValue, env *environment.Environment) (*shared.RuntimeValue, *errors.RuntimeError)import "github.com/dev-kas/virtlang-go/v4/internal/testhelpers"- func EvalNode(t *testing.T, node ast.Expr) *shared.RuntimeValue
- func ExpectParseError(t *testing.T, src string)
- func MustEval(t *testing.T, src string) (*shared.RuntimeValue, *environment.Environment)
- func MustParse(t *testing.T, src string) *ast.Program
func EvalNode(t *testing.T, node ast.Expr) *shared.RuntimeValueEvalNode evaluates a manually constructed AST node directly
func ExpectParseError(t *testing.T, src string)ExpectParseError checks that parsing fails for invalid sources
func MustEval(t *testing.T, src string) (*shared.RuntimeValue, *environment.Environment)MustEval evaluates source code fully (parse -> eval) and returns the value and environment
func MustParse(t *testing.T, src string) *ast.ProgramMustParse parses source code and returns AST program or fails the test
Generated by gomarkdoc