Documentation ¶
Index ¶
- Variables
- func Contains(tree, search Expr) bool
- func Format(n ast.Node) string
- type BlockStmt
- type Expr
- type LValue
- type ScalarFunction
- type ScalarIf
- type VectorFunction
- type VectorIf
- type World
- func (w *World) Compile(src string) (code *BlockStmt, e error)
- func (w *World) CompileExpr(src string) (code Expr, e error)
- func (w World) Const(name string, val interface{}, doc ...string)
- func (w *World) EnterScope()
- func (w *World) Eval(src string) (ret interface{}, err error)
- func (w *World) Exec(src string) error
- func (w *World) ExitScope()
- func (w World) Func(name string, f interface{}, doc ...string)
- func (w World) LValue(name string, v LValue, doc ...string)
- func (w *World) LoadStdlib()
- func (w *World) MustCompile(src string) Expr
- func (w *World) MustCompileExpr(src string) Expr
- func (w *World) MustEval(src string) interface{}
- func (w *World) MustExec(src string)
- func (w World) ROnly(name string, addr interface{}, doc ...string)
- func (w *World) Resolve(identifier string) (e Expr)
- func (w World) Var(name string, addr interface{}, doc ...string)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ScalarFunction_t = reflect.TypeOf(dummy_f).In(0) VectorFunction_t = reflect.TypeOf(dummy_f3).In(0) ScalarIf_t = reflect.TypeOf(dummy_scalarif).In(0) VectorIf_t = reflect.TypeOf(dummy_vectorif).In(0) )
common type definitions
View Source
var Debug bool // print debug info?
Functions ¶
Types ¶
type Expr ¶
type Expr interface { Eval() interface{} // evaluate and return result (nil for void) Type() reflect.Type // return type, nil for void Child() []Expr }
an expression can be evaluated
type LValue ¶
type LValue interface { Expr SetValue(interface{}) // assigns a new value }
left-hand value in (single) assign statement
type ScalarFunction ¶
type VectorFunction ¶
type World ¶
type World struct {
// contains filtered or unexported fields
}
World stores an interpreted program's state like declared variables and functions.
func (*World) Compile ¶
compiles source consisting of a number of statements. E.g.:
src = "a = 1; b = sin(x)" code, err := world.Compile(src) code.Eval()
func (*World) CompileExpr ¶
Compiles an expression, which can then be evaluated. E.g.:
expr, err := world.CompileExpr("1+1") expr.Eval() // returns 2
func (*World) EnterScope ¶
func (w *World) EnterScope()
func (*World) Eval ¶
Eval compiles and evaluates src, which must be an expression, and returns the result(s). E.g.:
world.Eval("1+1") // returns 2, nil
func (World) Func ¶
adds a native function to the world. E.g.:
world.Func("sin", math.Sin) world.MustEval("sin(0)") // returns 0
func (World) LValue ¶
adds a special variable to the world. Upon assignment, v's Set() will be called.
func (*World) MustCompile ¶
Like Compile but panics on error
func (*World) MustCompileExpr ¶
CompileExpr with panic on error.
Click to show internal directories.
Click to hide internal directories.