core

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	LOWEST      int
	EQUALS      // ==
	LESSGREATER // > or <
	SUM         // +
	PRODUCT     // *
	PREFIX      // -X or !X
	MEMBER      // obj.prop
	CALL        // myFunction(X)
	INDEX       // arr[i]
)

Variables

View Source
var (
	BREAK_SIGNAL    = &BreakSignal{}
	CONTINUE_SIGNAL = &ContinueSignal{}
)
View Source
var (
	NULL    = &Null{}
	TRUE    = &Boolean{Value: true}
	FALSE   = &Boolean{Value: false}
	ENVPKG  = &Package{Name: "env"}
	SYNCPKG = &Package{Name: "sync"}
)
View Source
var NativeFns = make(map[string]*NativeFunction)

Functions

func Fold

func Fold(program *Program)

Fold performs constant folding on the parsed AST. It evaluates pure literal sub-expressions at parse time and replaces them with their computed results. This reduces runtime overhead for expressions like `3 + 4 * 2` (→ 11) or `"a" + "b"` (→ "ab").

func Resolve

func Resolve(program *Program)

Resolve performs a variable resolution pass on the parsed AST. It walks the tree, tracking declarations and scope depth, and marks each Identifier with the scope depth and slot index where its value lives. At runtime, resolved identifiers use O(1) slice indexing instead of O(depth) map lookups.

Types

type Array

type Array struct {
	ElemType ObjectType
	Elements []Object
}

func (*Array) Inspect

func (a *Array) Inspect() string

func (*Array) Type

func (a *Array) Type() ObjectType

type ArrayLiteral

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

func (*ArrayLiteral) String

func (al *ArrayLiteral) String() string

func (*ArrayLiteral) TokenLiteral

func (al *ArrayLiteral) TokenLiteral() string

type AssignStatement

type AssignStatement struct {
	Token  Token      // the := or = token
	Names  []string   // variable names: [x] for single, [x, y] for multi-assign
	Target Expression // non-nil for index assignment: arr[i] = val
	Value  Expression
	// Resolver fields for = reassignment fast path
	ResolvedScopeDepth int // -1 = unresolved
	ResolvedSlotIndex  int // -1 = unresolved
}

func (*AssignStatement) String

func (as *AssignStatement) String() string

func (*AssignStatement) TokenLiteral

func (as *AssignStatement) TokenLiteral() string

type BackgroundStatement

type BackgroundStatement struct {
	Token Token // the & token
	Stmt  Statement
}

func (*BackgroundStatement) String

func (bs *BackgroundStatement) String() string

func (*BackgroundStatement) TokenLiteral

func (bs *BackgroundStatement) TokenLiteral() string

type BlockStatement

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

func (*BlockStatement) String

func (bs *BlockStatement) String() string

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

type Boolean

type Boolean struct {
	Value bool
}

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

func (*Boolean) Type

func (b *Boolean) Type() ObjectType

type BooleanLiteral

type BooleanLiteral struct {
	Token Token
	Value bool
}

func (*BooleanLiteral) String

func (bl *BooleanLiteral) String() string

func (*BooleanLiteral) TokenLiteral

func (bl *BooleanLiteral) TokenLiteral() string

type BreakSignal

type BreakSignal struct{}

func (*BreakSignal) Inspect

func (b *BreakSignal) Inspect() string

func (*BreakSignal) Type

func (b *BreakSignal) Type() ObjectType

type BreakStatement

type BreakStatement struct {
	Token Token
}

func (*BreakStatement) String

func (bs *BreakStatement) String() string

func (*BreakStatement) TokenLiteral

func (bs *BreakStatement) TokenLiteral() string

type CallExpression

type CallExpression struct {
	Token     Token
	Function  Expression
	Arguments []Expression
}

func (*CallExpression) String

func (ce *CallExpression) String() string

func (*CallExpression) TokenLiteral

func (ce *CallExpression) TokenLiteral() string

type CaseClause

type CaseClause struct {
	Token        Token        // case or default keyword
	Values       []Expression // case values; nil for default
	Body         *BlockStatement
	IntConsts    []int64  // pre-computed integer literal values (Parser stage)
	StringConsts []string // pre-computed string literal values (Parser stage)
	HasConstVals bool     // true when all Values are same-type literals
}

func (*CaseClause) String

func (cc *CaseClause) String() string

type CommandStatement

type CommandStatement struct {
	Token     Token
	Name      string
	Arguments []Expression
}

func (*CommandStatement) String

func (cs *CommandStatement) String() string

func (*CommandStatement) TokenLiteral

func (cs *CommandStatement) TokenLiteral() string

type ContinueSignal

type ContinueSignal struct{}

func (*ContinueSignal) Inspect

func (c *ContinueSignal) Inspect() string

func (*ContinueSignal) Type

func (c *ContinueSignal) Type() ObjectType

type ContinueStatement

type ContinueStatement struct {
	Token Token
}

func (*ContinueStatement) String

func (cs *ContinueStatement) String() string

func (*ContinueStatement) TokenLiteral

func (cs *ContinueStatement) TokenLiteral() string

type EnvEntry

type EnvEntry struct {
	Owner *Environment
	Name  string
	Value Object
}

EnvEntry holds a variable's value for pointer reference support.

type Environment

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

func NewEmptyEnvironment

func NewEmptyEnvironment() *Environment

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

func NewEnvironment

func NewEnvironment() *Environment

func NewFunctionCallEnvironment

func NewFunctionCallEnvironment(outer *Environment, paramCapacity int) *Environment

func NewSandboxEnvironment

func NewSandboxEnvironment() *Environment

func NewScriptEnvironment

func NewScriptEnvironment(outer *Environment) *Environment

func (*Environment) Assign

func (e *Environment) Assign(name string, val Object)

func (*Environment) Cancelled

func (e *Environment) Cancelled() bool

Cancelled returns true if the root context has been cancelled (timeout or manual).

func (*Environment) Clone

func (e *Environment) Clone() *Environment

func (*Environment) DeclareSlot

func (e *Environment) DeclareSlot(name string, val Object, typeName string) int

DeclareSlot allocates a slot in the current scope and stores the value. Also stores in the map for backward compatibility (pointer ops, Keys(), etc.). If the variable already has a slot, updates the existing slot instead of allocating a new one. Returns the allocated slot index.

func (*Environment) DeletePackageValue

func (e *Environment) DeletePackageValue(pkg, name string) bool

func (*Environment) ExternalCmdAllowed

func (e *Environment) ExternalCmdAllowed() bool

ExternalCmdAllowed returns true if external commands are allowed. Traverses the outer chain to handle inherited sandbox settings.

func (*Environment) Get

func (e *Environment) Get(name string) (any, bool)

func (*Environment) GetBySlot

func (e *Environment) GetBySlot(depth, index int) Object

GetBySlot retrieves a value by scope depth and slot index. depth=0 means current scope, depth=1 means one level up, etc.

func (*Environment) GetContext

func (e *Environment) GetContext() context.Context

GetContext returns the root cancellation context. Returns context.Background() if no context has been set.

func (*Environment) GetObject

func (e *Environment) GetObject(name string) (Object, bool)

func (*Environment) GetPackageValue

func (e *Environment) GetPackageValue(pkg, name string) (string, bool)

func (*Environment) GetRef

func (e *Environment) GetRef(name string) (*EnvEntry, bool)

GetRef returns an EnvEntry for pointer operations. Creates the entry in refStore if it doesn't exist.

func (*Environment) GetString

func (e *Environment) GetString(name string) (string, bool)

func (*Environment) GetType

func (e *Environment) GetType(name string) (string, bool)

func (*Environment) IsBuiltinAllowed

func (e *Environment) IsBuiltinAllowed(name string) bool

IsBuiltinAllowed checks if a builtin command is allowed in this environment. Traverses the outer chain to handle inherited sandbox settings.

func (*Environment) IsConstant

func (e *Environment) IsConstant(name string) bool

IsConstant checks if a name is a constant.

func (*Environment) IsSandboxed

func (e *Environment) IsSandboxed() bool

IsSandboxed returns true if this or any outer environment is sandboxed.

func (*Environment) Keys

func (e *Environment) Keys() []string

func (*Environment) MarkConstant

func (e *Environment) MarkConstant(name string)

MarkConstant marks a name as a constant (from func declarations). Constants cannot be reassigned via =.

func (*Environment) PackageSnapshot

func (e *Environment) PackageSnapshot(pkg string) map[string]string

func (*Environment) ResolveForAssign

func (e *Environment) ResolveForAssign(name string) (*Environment, string, bool)

func (*Environment) Set

func (e *Environment) Set(name string, val any)

func (*Environment) SetAllowExternalCmd

func (e *Environment) SetAllowExternalCmd(allow bool)

SetAllowExternalCmd controls whether external commands are allowed.

func (*Environment) SetAllowedBuiltins

func (e *Environment) SetAllowedBuiltins(names []string)

SetAllowedBuiltins sets the builtin whitelist (nil = all allowed).

func (*Environment) SetBlockedBuiltins

func (e *Environment) SetBlockedBuiltins(names []string)

SetBlockedBuiltins sets the builtin blacklist.

func (*Environment) SetByPointer

func (e *Environment) SetByPointer(ref *EnvEntry, val Object)

SetByPointer sets a value through a pointer reference.

func (*Environment) SetContext

func (e *Environment) SetContext(ctx context.Context)

SetContext attaches a cancellation context to the root environment.

func (*Environment) SetMaxRecursionDepth

func (e *Environment) SetMaxRecursionDepth(depth int)

SetMaxRecursionDepth sets the maximum function call recursion depth.

func (*Environment) SetObject

func (e *Environment) SetObject(name string, val Object)

func (*Environment) SetPackageValue

func (e *Environment) SetPackageValue(pkg, name, value string)

func (*Environment) SetSandboxed

func (e *Environment) SetSandboxed(s bool)

SetSandboxed marks this environment as a sandbox (true) or removes sandbox status (false).

func (*Environment) SetSlot

func (e *Environment) SetSlot(depth, index int, val Object)

SetSlot sets a value by scope depth and slot index.

func (*Environment) SetSlotByName

func (e *Environment) SetSlotByName(name string, val Object) bool

SetSlotByName sets a value in the slot associated with name (if any). Returns true if a slot was found and updated.

func (*Environment) SetString

func (e *Environment) SetString(name string, val string)

func (*Environment) SetWithType

func (e *Environment) SetWithType(name string, val Object, typeName string)

type Error

type Error struct {
	Message string
	Code    int
	Op      string
}

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Type

func (e *Error) Type() ObjectType

type ExecStatement

type ExecStatement struct {
	Token      Token        // the exec token
	CommandStr Expression   // deprecated string form: exec "echo hello"
	Args       []Expression // keyword form: exec echo hello
}

func (*ExecStatement) String

func (es *ExecStatement) String() string

func (*ExecStatement) TokenLiteral

func (es *ExecStatement) TokenLiteral() string

type Expression

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

type ExpressionStatement

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

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

func (*ExpressionStatement) TokenLiteral

func (es *ExpressionStatement) TokenLiteral() string

type Float

type Float struct {
	Value float64
}

func (*Float) Inspect

func (f *Float) Inspect() string

func (*Float) Type

func (f *Float) Type() ObjectType

type FloatLiteral

type FloatLiteral struct {
	Token Token
	Value float64
	Obj   *Float
	Err   string
}

func (*FloatLiteral) String

func (fl *FloatLiteral) String() string

func (*FloatLiteral) TokenLiteral

func (fl *FloatLiteral) TokenLiteral() string

type ForStatement

type ForStatement struct {
	Token       Token      // the for token
	Init        Statement  // init statement (3-clause: i := 0), nil for while-style
	Condition   Expression // condition expression, nil for infinite loop
	Post        Statement  // post statement (3-clause: i = i + 1), nil for while-style
	Consequence *BlockStatement
	// Pre-analyzed increment pattern (Parser stage)
	IncVarName string // variable name for i = i + N pattern
	IncDelta   int64  // +1 or -1 for i = i +/- 1
	HasInc     bool   // true if body is a single i = i +/- 1 assignment
	// Resolver fields for increment fast path
	IncScopeDepth int // -1 = unresolved
	IncSlotIndex  int // -1 = unresolved
	// Iterator range (for v := range iter(args) { ... })
	IsIterRange bool       // true if this is a range-over-function
	IterCall    Expression // the iterator call expression (e.g. iter(args))
	IterVars    []string   // variable names: ["v"] or ["k", "v"]
}

func (*ForStatement) String

func (fs *ForStatement) String() string

func (*ForStatement) TokenLiteral

func (fs *ForStatement) TokenLiteral() string

type Function

type Function struct {
	Parameters   []Parameter
	ReturnTypes  []string
	Body         *BlockStatement
	Env          *Environment
	SlotCapacity int // number of slots needed for parameters (set by Resolver)
}

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Type

func (f *Function) Type() ObjectType

type FunctionLiteral

type FunctionLiteral struct {
	Token       Token // the func token
	Parameters  []Parameter
	ReturnTypes []string
	Body        *BlockStatement
}

func (*FunctionLiteral) String

func (fl *FunctionLiteral) String() string

func (*FunctionLiteral) TokenLiteral

func (fl *FunctionLiteral) TokenLiteral() string

type FunctionStatement

type FunctionStatement struct {
	Token       Token // the func token
	Name        string
	Parameters  []Parameter
	ReturnTypes []string // empty = void, len=1 single, len>1 multi-return
	Body        *BlockStatement
	Obj         *Function
}

func (*FunctionStatement) String

func (fs *FunctionStatement) String() string

func (*FunctionStatement) TokenLiteral

func (fs *FunctionStatement) TokenLiteral() string

type GoExpression

type GoExpression struct {
	Token Token // the go token
	Node  Node  // BlockStatement or CommandStatement or Function call
}

func (*GoExpression) String

func (ge *GoExpression) String() string

func (*GoExpression) TokenLiteral

func (ge *GoExpression) TokenLiteral() string

type GoStatement

type GoStatement struct {
	Token Token // the go token
	Node  Node  // BlockStatement or CommandStatement or Function call
}

func (*GoStatement) String

func (gs *GoStatement) String() string

func (*GoStatement) TokenLiteral

func (gs *GoStatement) TokenLiteral() string

type Identifier

type Identifier struct {
	Token      Token
	Value      string
	ScopeDepth int // -1 = unresolved; 0 = current scope, 1 = outer, etc.
	SlotIndex  int // -1 = unresolved; >= 0 = slot index in that scope
}

func NewIdentifier

func NewIdentifier(tok Token, val string) *Identifier

NewIdentifier creates an Identifier with unresolved scope defaults.

func (*Identifier) String

func (i *Identifier) String() string

func (*Identifier) TokenLiteral

func (i *Identifier) TokenLiteral() string

type IfStatement

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

func (*IfStatement) String

func (is *IfStatement) String() string

func (*IfStatement) TokenLiteral

func (is *IfStatement) TokenLiteral() string

type ImportStatement

type ImportStatement struct {
	Token Token  // the import token
	Path  string // import path like "Go" or "Go/fmt"
}

func (*ImportStatement) String

func (is *ImportStatement) String() string

func (*ImportStatement) TokenLiteral

func (is *ImportStatement) TokenLiteral() string

type IndexExpression

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

func (*IndexExpression) String

func (ie *IndexExpression) String() string

func (*IndexExpression) TokenLiteral

func (ie *IndexExpression) TokenLiteral() string

type InfixExpression

type InfixExpression struct {
	Token    Token // The operator token, e.g. +
	Left     Expression
	Operator string
	Right    Expression
}

func (*InfixExpression) String

func (ie *InfixExpression) String() string

func (*InfixExpression) TokenLiteral

func (ie *InfixExpression) TokenLiteral() string

type Integer

type Integer struct {
	Value int64
}

func GetInteger

func GetInteger(value int64) *Integer

func (*Integer) Inspect

func (i *Integer) Inspect() string

func (*Integer) Type

func (i *Integer) Type() ObjectType

type IntegerLiteral

type IntegerLiteral struct {
	Token Token
	Value int64
	Obj   *Integer
	Err   string
}

func (*IntegerLiteral) String

func (il *IntegerLiteral) String() string

func (*IntegerLiteral) TokenLiteral

func (il *IntegerLiteral) TokenLiteral() string

type InvalidStatement

type InvalidStatement struct {
	Token   Token
	Message string
}

func (*InvalidStatement) String

func (is *InvalidStatement) String() string

func (*InvalidStatement) TokenLiteral

func (is *InvalidStatement) TokenLiteral() string

type Lexer

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

func NewLexer

func NewLexer(input string) *Lexer

func (*Lexer) Errors

func (l *Lexer) Errors() []string

func (*Lexer) GetPosition

func (l *Lexer) GetPosition() LexerState

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

func (*Lexer) SetPosition

func (l *Lexer) SetPosition(state LexerState)

type LexerState

type LexerState struct {
	Position     int
	ReadPosition int
	Ch           byte
	PrevToken    TokenType
	Line         int
	Column       int
}

type LogicalStatement

type LogicalStatement struct {
	Token    Token // && or ||
	Left     Statement
	Operator string
	Right    Statement
}

func (*LogicalStatement) String

func (ls *LogicalStatement) String() string

func (*LogicalStatement) TokenLiteral

func (ls *LogicalStatement) TokenLiteral() string

type MemberExpression

type MemberExpression struct {
	Token    Token
	Object   Expression
	Property string
}

func (*MemberExpression) String

func (me *MemberExpression) String() string

func (*MemberExpression) TokenLiteral

func (me *MemberExpression) TokenLiteral() string

type MethodCallBlockStatement

type MethodCallBlockStatement struct {
	Token  Token           // the object token (e.g., "wg")
	Object Expression      // the object expression (e.g., Identifier{Value: "wg"})
	Method string          // the method name (e.g., "Go")
	Body   *BlockStatement // the block body
}

func (*MethodCallBlockStatement) String

func (mcb *MethodCallBlockStatement) String() string

func (*MethodCallBlockStatement) TokenLiteral

func (mcb *MethodCallBlockStatement) TokenLiteral() string

type NativeFunction

type NativeFunction struct {
	Fn func(env *Environment, args ...Object) Object
}

func (*NativeFunction) Inspect

func (nf *NativeFunction) Inspect() string

func (*NativeFunction) Type

func (nf *NativeFunction) Type() ObjectType

type NilLiteral

type NilLiteral struct {
	Token Token
}

func (*NilLiteral) String

func (nl *NilLiteral) String() string

func (*NilLiteral) TokenLiteral

func (nl *NilLiteral) TokenLiteral() string

type Node

type Node interface {
	TokenLiteral() string
	String() string
}

type Null

type Null struct{}

func (*Null) Inspect

func (n *Null) Inspect() string

func (*Null) Type

func (n *Null) Type() ObjectType

type Object

type Object interface {
	Type() ObjectType
	Inspect() string
}

func Eval

func Eval(node Node, env *Environment) Object

func EvalWithIO

func EvalWithIO(node Node, env *Environment, stdin io.Reader, stdout io.Writer, stderr io.Writer) Object

func Run

func Run(input string, opts ...RunOption) (Object, error)

Run executes a Kamishell script with the default sandbox environment. Returns the result object and any error.

Example
result, err := Run(`func add(a int, b int) int { return a + b }; add(3, 4)`, WithEnvironment(NewEmptyEnvironment()))
if err != nil {
	fmt.Printf("error: %v", err)
	return
}
fmt.Println(result.Inspect())
Output:
7

func RunWithIO

func RunWithIO(input string, stdin io.Reader, stdout io.Writer, stderr io.Writer, opts ...RunOption) (Object, error)

RunWithIO executes a Kamishell script with explicit IO and options.

Example
var buf strings.Builder
_, err := RunWithIO(`print "hello from kami"`, nil, &buf, os.Stderr, WithEnvironment(NewEmptyEnvironment()))
if err != nil {
	fmt.Printf("error: %v", err)
	return
}
fmt.Print(buf.String())
Output:
hello from kami

type ObjectType

type ObjectType string
const (
	INTEGER_OBJ      ObjectType = "INTEGER"
	FLOAT_OBJ        ObjectType = "FLOAT"
	BOOLEAN_OBJ      ObjectType = "BOOLEAN"
	STRING_OBJ       ObjectType = "STRING"
	NULL_OBJ         ObjectType = "NULL"
	RETURN_VALUE_OBJ ObjectType = "RETURN_VALUE"
	ERROR_OBJ        ObjectType = "ERROR"
	FUNCTION_OBJ     ObjectType = "FUNCTION"
	PACKAGE_OBJ      ObjectType = "PACKAGE"
	WAITGROUP_OBJ    ObjectType = "WAITGROUP"
	TASK_OBJ         ObjectType = "TASK"
	BREAK_OBJ        ObjectType = "BREAK"
	CONTINUE_OBJ     ObjectType = "CONTINUE"
	ARRAY_OBJ        ObjectType = "ARRAY"
	TUPLE_OBJ        ObjectType = "TUPLE"
)

type Package

type Package struct {
	Name string
}

func (*Package) Inspect

func (p *Package) Inspect() string

func (*Package) Type

func (p *Package) Type() ObjectType

type Parameter

type Parameter struct {
	Name     string
	TypeName string
}

func (Parameter) String

func (p Parameter) String() string

type Parser

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

func NewParser

func NewParser(l *Lexer) *Parser

func (*Parser) Errors

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

func (*Parser) ParseProgram

func (p *Parser) ParseProgram() *Program

type PipeStatement

type PipeStatement struct {
	Token    Token       // The | token
	Commands []Statement // The commands in the pipeline (usually CommandStatements)
}

func (*PipeStatement) String

func (ps *PipeStatement) String() string

func (*PipeStatement) TokenLiteral

func (ps *PipeStatement) TokenLiteral() string

type Pointer

type Pointer struct {
	Ref *EnvEntry
	Env *Environment
}

func (*Pointer) Inspect

func (p *Pointer) Inspect() string

func (*Pointer) Type

func (p *Pointer) Type() ObjectType

type PointerAssignStatement

type PointerAssignStatement struct {
	Token  Token      // the = token
	Target Expression // the *p expression
	Value  Expression
}

func (*PointerAssignStatement) String

func (pas *PointerAssignStatement) String() string

func (*PointerAssignStatement) TokenLiteral

func (pas *PointerAssignStatement) TokenLiteral() string

type PrefixExpression

type PrefixExpression struct {
	Token    Token // The operator token, e.g. & or *
	Operator string
	Right    Expression
}

func (*PrefixExpression) String

func (pe *PrefixExpression) String() string

func (*PrefixExpression) TokenLiteral

func (pe *PrefixExpression) TokenLiteral() string

type PrintStatement

type PrintStatement struct {
	Token      Token
	Expression Expression
}

func (*PrintStatement) String

func (ps *PrintStatement) String() string

func (*PrintStatement) TokenLiteral

func (ps *PrintStatement) TokenLiteral() string

type Program

type Program struct {
	Statements []Statement
}

func Parse

func Parse(input string) (*Program, []error)

Parse parses input into an AST program without executing it. Returns parse errors as a slice of errors.

Example
program, errs := Parse(`x := 1; if x > 0 { print x }`)
if len(errs) > 0 {
	fmt.Printf("parse errors: %v", errs)
	return
}
fmt.Printf("parsed %d statements", len(program.Statements))
Output:
parsed 2 statements

func (*Program) String

func (p *Program) String() string

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

type RedirectStatement

type RedirectStatement struct {
	Token  Token // > or >>
	Source Statement
	Target Expression
	Append bool
}

func (*RedirectStatement) String

func (rs *RedirectStatement) String() string

func (*RedirectStatement) TokenLiteral

func (rs *RedirectStatement) TokenLiteral() string

type ReturnStatement

type ReturnStatement struct {
	Token        Token // the return token
	ReturnValues []Expression
}

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

type ReturnValue

type ReturnValue struct {
	Value Object
}

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

func (*ReturnValue) Type

func (rv *ReturnValue) Type() ObjectType

type RunOption

type RunOption func(*runConfig)

RunOption configures the execution behavior.

func SandboxMode

func SandboxMode() RunOption

SandboxMode disables external commands on the current environment. If the environment is not already a sandbox, it is marked as one.

func WithEnvironment

func WithEnvironment(env *Environment) RunOption

WithEnvironment sets a custom execution environment.

func WithTimeout

func WithTimeout(d time.Duration) RunOption

WithTimeout sets an execution timeout. Zero means no timeout.

type Statement

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

type String

type String struct {
	Value string
}

func (*String) Inspect

func (s *String) Inspect() string

func (*String) Type

func (s *String) Type() ObjectType

type StringLiteral

type StringLiteral struct {
	Token Token
	Value string
	Obj   *String
	Parts []StringPart // pre-parsed interpolation segments (nil = no $)
}

func (*StringLiteral) String

func (sl *StringLiteral) String() string

func (*StringLiteral) TokenLiteral

func (sl *StringLiteral) TokenLiteral() string

type StringPart

type StringPart struct {
	Text string // literal text (empty if Var is set)
	Var  string // variable name (empty if Text is set)
}

StringPart represents a segment of a string literal. If Var is non-empty, it's a variable reference; otherwise Text is a literal.

type SwitchStatement

type SwitchStatement struct {
	Token        Token      // the switch token
	Tag          Expression // optional, nil for tagless switch
	Cases        []CaseClause
	IntSwitch    bool // true if all non-default case values are integer literals
	StringSwitch bool // true if all non-default case values are string literals (no $)
}

func (*SwitchStatement) String

func (ss *SwitchStatement) String() string

func (*SwitchStatement) TokenLiteral

func (ss *SwitchStatement) TokenLiteral() string

type Task

type Task struct {
	ID     int
	Done   chan struct{}
	Result Object
}

func (*Task) Inspect

func (t *Task) Inspect() string

func (*Task) Type

func (t *Task) Type() ObjectType

type Token

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

type TokenType

type TokenType string
const (
	EOF     TokenType = "EOF"
	ILLEGAL TokenType = "ILLEGAL"

	// Identifiers + literals
	IDENT  TokenType = "IDENT"
	STRING TokenType = "STRING"
	NUMBER TokenType = "NUMBER"
	FLOAT  TokenType = "FLOAT"

	// Operators
	ASSIGN       TokenType = "="
	COLON_ASSIGN TokenType = ":="
	PIPE         TokenType = "|"
	GREATER      TokenType = ">"
	LESS         TokenType = "<"
	APPEND       TokenType = ">>"
	REDIRECT     TokenType = "->"
	AND          TokenType = "&&"
	AMPERSAND    TokenType = "&"
	OR           TokenType = "||"
	NOT          TokenType = "!"
	EQ           TokenType = "=="
	NEQ          TokenType = "!="
	GEQ          TokenType = ">="
	LEQ          TokenType = "<="
	PLUS         TokenType = "+"
	MINUS        TokenType = "-"
	ASTERISK     TokenType = "*"
	SLASH        TokenType = "/"
	MODULO       TokenType = "%"
	SEMICOLON    TokenType = ";"
	COMMA        TokenType = ","
	DOT          TokenType = "."
	LPAREN       TokenType = "("
	RPAREN       TokenType = ")"
	LBRACE       TokenType = "{"
	RBRACE       TokenType = "}"
	LBRACKET     TokenType = "["
	RBRACKET     TokenType = "]"
	DOLLAR       TokenType = "$"

	// Keywords
	IF        TokenType = "IF"
	ELSE      TokenType = "ELSE"
	FOR       TokenType = "FOR"
	RANGE     TokenType = "RANGE"
	FUNC      TokenType = "FUNC"
	RETURN    TokenType = "RETURN"
	GO        TokenType = "GO"
	VAR       TokenType = "VAR"
	PRINT     TokenType = "PRINT"
	EXEC      TokenType = "EXEC"
	NIL       TokenType = "NIL"
	TRUE_TOK  TokenType = "TRUE"
	FALSE_TOK TokenType = "FALSE"
	IMPORT    TokenType = "IMPORT"
	WAIT      TokenType = "WAIT"
	SWITCH    TokenType = "SWITCH"
	CASE      TokenType = "CASE"
	DEFAULT   TokenType = "DEFAULT"
	BREAK     TokenType = "BREAK"
	CONTINUE  TokenType = "CONTINUE"
	COLON     TokenType = ":"
)

func LookupIdent

func LookupIdent(ident string) TokenType

type Tuple

type Tuple struct {
	Elements []Object
}

func (*Tuple) Inspect

func (t *Tuple) Inspect() string

func (*Tuple) Type

func (t *Tuple) Type() ObjectType

type VarStatement

type VarStatement struct {
	Token    Token // the var token
	Name     string
	TypeName string
	Value    Expression // optional initial value
}

func (*VarStatement) String

func (vs *VarStatement) String() string

func (*VarStatement) TokenLiteral

func (vs *VarStatement) TokenLiteral() string

type WaitGroup

type WaitGroup struct {
	Wg any // *sync.WaitGroup - using interface{} to avoid import cycle
}

func (*WaitGroup) Inspect

func (wg *WaitGroup) Inspect() string

func (*WaitGroup) Type

func (wg *WaitGroup) Type() ObjectType

type WaitStatement

type WaitStatement struct {
	Token   Token      // the wait token
	Timeout Expression // optional timeout in seconds
}

func (*WaitStatement) String

func (ws *WaitStatement) String() string

func (*WaitStatement) TokenLiteral

func (ws *WaitStatement) TokenLiteral() string

Jump to

Keyboard shortcuts

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