Documentation ¶
Index ¶
- Constants
- func GetGrammer() string
- func InjectRuntime(context *Context)
- func ReadProgram(filename string) string
- type Addition
- type Assignment
- type BoolValue
- type BreakError
- type Call
- type CallArgs
- type CallChain
- type CallIndex
- type CallProperty
- type Comparison
- type Context
- type ContinueError
- type DictKV
- type DictLiteral
- type DictValue
- type Equality
- type Expr
- type ForStatement
- type FuncLiteral
- type FunctionValue
- type IdentifierValue
- type IfStatement
- type ListLiteral
- type ListValue
- func (listValue ListValue) Append(other Value)
- func (listValue ListValue) Equals(other Value) (bool, error)
- func (listValue *ListValue) Get(index int) (Value, error)
- func (listValue ListValue) Popat(index int) (Value, error)
- func (listValue ListValue) Prepend(other Value)
- func (listValue ListValue) String() string
- type LogicAnd
- type LogicOr
- type Multiplication
- type NativeFunctionValue
- type NumberValue
- type Primary
- type Program
- type ReferenceValue
- type ReturnError
- type ReturnStatement
- type StackFrame
- type Statement
- type StringValue
- type SubExpression
- type Unary
- type UndefinedValue
- type Value
- type WhileStatement
Constants ¶
View Source
const VERSION = 0.1
Variables ¶
This section is empty.
Functions ¶
func GetGrammer ¶
func GetGrammer() string
func InjectRuntime ¶
func InjectRuntime(context *Context)
Given a root content, add runtime functions to the module's scope
func ReadProgram ¶
Types ¶
type Addition ¶
type Addition struct { Pos lexer.Position Multiplication *Multiplication `@@` Op *string `[ @( "-" | "+" )` Next *Addition ` @@ ]` }
type Assignment ¶
type Assignment struct { Pos lexer.Position Let *string `@"let"?` LogicOr *LogicOr `@@` Op *string `( @"="` Next *Assignment ` @@ )?` }
func (Assignment) Eval ¶
func (assignment Assignment) Eval(frame *StackFrame) (Value, error)
func (Assignment) String ¶
func (assignment Assignment) String() string
type BreakError ¶
type BreakError struct {
// contains filtered or unexported fields
}
func (BreakError) Error ¶
func (b BreakError) Error() string
type CallProperty ¶
type CallProperty struct {
Ident *string `"." @Ident`
}
type Comparison ¶
type Comparison struct { Pos lexer.Position Addition *Addition `@@` Op *string `[ @( ">" "=" | ">" | "<" "=" | "<" )` Next *Comparison ` @@ ]` }
func (Comparison) Eval ¶
func (comparison Comparison) Eval(frame *StackFrame) (Value, error)
func (Comparison) String ¶
func (comparison Comparison) String() string
type ContinueError ¶
type ContinueError struct {
// contains filtered or unexported fields
}
func (ContinueError) Error ¶
func (c ContinueError) Error() string
type DictLiteral ¶
func (DictLiteral) Eval ¶
func (dictLiteral DictLiteral) Eval(frame *StackFrame) (Value, error)
func (DictLiteral) String ¶
func (dictLiteral DictLiteral) String() string
type Equality ¶
type Equality struct { Pos lexer.Position Comparison *Comparison `@@` Op *string `[ @( "!" "=" | "=" "=" )` Next *Equality ` @@ ]` }
type Expr ¶
type Expr struct { Pos lexer.Position Assignment *Assignment `@@` }
type ForStatement ¶
type ForStatement struct { Pos lexer.Position Init *Expr `"for" "(" @@? ";"` Condition *Expr `@@? ";"` Post *Expr `@@? ")"` Block []*Statement `"{" @@* "}"` }
func (ForStatement) Eval ¶
func (forStatement ForStatement) Eval(frame *StackFrame) (Value, error)
func (ForStatement) String ¶
func (forStatement ForStatement) String() string
type FuncLiteral ¶
type FuncLiteral struct { Pos lexer.Position Params []string `"func" "(" ( @Ident ( "," @Ident )* )? ")"` Block []*Statement `"{" @@* "}"` }
func (FuncLiteral) Eval ¶
func (functionLiteral FuncLiteral) Eval(frame *StackFrame) (Value, error)
func (FuncLiteral) String ¶
func (functionLiteral FuncLiteral) String() string
type FunctionValue ¶
type FunctionValue struct {
// contains filtered or unexported fields
}
func (FunctionValue) Exec ¶
func (functionValue FunctionValue) Exec(position string, args []Value) (Value, error)
func (FunctionValue) String ¶
func (functionValue FunctionValue) String() string
type IdentifierValue ¶
type IdentifierValue struct {
// contains filtered or unexported fields
}
func (IdentifierValue) Equals ¶
func (identifierValue IdentifierValue) Equals(other Value) (bool, error)
func (IdentifierValue) String ¶
func (identifierValue IdentifierValue) String() string
type IfStatement ¶
type IfStatement struct { Pos lexer.Position Condition *Expr `"if" "(" @@ ")"` If []*Statement `"{" @@* "}"` Else []*Statement `("else" "{" @@* "}")?` }
func (IfStatement) Eval ¶
func (ifStatement IfStatement) Eval(frame *StackFrame) (Value, error)
func (IfStatement) String ¶
func (ifStatement IfStatement) String() string
type ListLiteral ¶
func (ListLiteral) Eval ¶
func (listLiteral ListLiteral) Eval(frame *StackFrame) (Value, error)
func (ListLiteral) String ¶
func (listLiteral ListLiteral) String() string
type LogicAnd ¶
type LogicOr ¶
type Multiplication ¶
type Multiplication struct { Pos lexer.Position Unary *Unary `@@` Op *string `[ @( "/" | "*" | "%" )` Next *Multiplication ` @@ ]` }
func (Multiplication) Equals ¶
func (multiplication Multiplication) Equals(other Value) (bool, error)
func (Multiplication) Eval ¶
func (multiplication Multiplication) Eval(frame *StackFrame) (Value, error)
func (Multiplication) String ¶
func (multiplication Multiplication) String() string
type NativeFunctionValue ¶
type NativeFunctionValue struct { Exec func(*StackFrame, string, []Value) (Value, error) // contains filtered or unexported fields }
func (NativeFunctionValue) Equals ¶
func (nativeFunctionValue NativeFunctionValue) Equals(other Value) (bool, error)
func (NativeFunctionValue) String ¶
func (nativeFunctionValue NativeFunctionValue) String() string
type NumberValue ¶
type NumberValue struct {
// contains filtered or unexported fields
}
func (NumberValue) String ¶
func (numberValue NumberValue) String() string
type Primary ¶
type Primary struct { Pos lexer.Position FuncLiteral *FuncLiteral `@@` ListLiteral *ListLiteral `| @@` DictLiteral *DictLiteral `| @@` Call *Call `| @@` SubExpression *SubExpression `| @@` Number *float64 `| ( @Float | @Int )` Str *string `| @String` True *bool `| @"true"` False *bool `| @"false"` Undefined *string `| @"undefined"` Ident *string `| @Ident` }
type Program ¶
func GenerateAST ¶
type ReferenceValue ¶
type ReferenceValue struct {
// contains filtered or unexported fields
}
Sometimes we want to bubble up a reference to a list or dict item so that it can be reassigned. Use `unref` to turn into a plain value
func (ReferenceValue) Equals ¶
func (referenceValue ReferenceValue) Equals(other Value) (bool, error)
func (ReferenceValue) String ¶
func (referenceValue ReferenceValue) String() string
type ReturnError ¶
type ReturnError struct {
// contains filtered or unexported fields
}
func (ReturnError) Error ¶
func (r ReturnError) Error() string
type ReturnStatement ¶
type StackFrame ¶
type StackFrame struct {
// contains filtered or unexported fields
}
func (*StackFrame) Get ¶
func (frame *StackFrame) Get(key string) (Value, error)
Get a variable's value by looking through every scope (bottom to top)
func (*StackFrame) GetChild ¶
func (frame *StackFrame) GetChild(trace string) *StackFrame
func (*StackFrame) Set ¶
func (frame *StackFrame) Set(key string, value Value)
Set a variable by looking through every scope (bottom to top) until an existing variable is found. If there is no matching variable, declare a new variable in the current scope
func (*StackFrame) String ¶
func (frame *StackFrame) String() string
type Statement ¶
type Statement struct { Pos lexer.Position If *IfStatement `@@` For *ForStatement `| @@` While *WhileStatement `| @@` // These optional semi-colons could cause problems Return *ReturnStatement `| @@ ";"?` Break *string `| @"break" ";"?` Continue *string `| @"continue" ";"?` // -- Expr *Expr `| @@ ";"` }
type StringValue ¶
type StringValue struct {
// contains filtered or unexported fields
}
func (StringValue) String ¶
func (stringValue StringValue) String() string
type SubExpression ¶
type SubExpression struct { Pos lexer.Position Expr *Expr `"(" @@ ")" ` CallChain *CallChain `@@?` }
func (SubExpression) Eval ¶
func (subExpression SubExpression) Eval(frame *StackFrame) (Value, error)
func (SubExpression) String ¶
func (subExpression SubExpression) String() string
type Unary ¶
type UndefinedValue ¶
type UndefinedValue struct{}
func (UndefinedValue) Equals ¶
func (undefinedValue UndefinedValue) Equals(other Value) (bool, error)
func (UndefinedValue) String ¶
func (undefinedValue UndefinedValue) String() string
type WhileStatement ¶
type WhileStatement struct { Pos lexer.Position Condition *Expr `"while" "(" @@? ")"` Block []*Statement `"{" @@* "}"` }
func (WhileStatement) Equals ¶
func (whileStatement WhileStatement) Equals(other Value) (bool, error)
func (WhileStatement) Eval ¶
func (whileStatement WhileStatement) Eval(frame *StackFrame) (Value, error)
func (WhileStatement) String ¶
func (whileStatement WhileStatement) String() string
Click to show internal directories.
Click to hide internal directories.