Documentation ¶
Index ¶
- func NewLexer(input string) *lexer
- func NewParser(lex *lexer, scope Scope) *parser
- type EvalContext
- type Expression
- type Function
- type Scope
- type Value
- func (v Value) AsBool() bool
- func (v Value) AsError() error
- func (v Value) AsInt() int64
- func (v Value) AsInterface() interface{}
- func (v Value) AsList() []Value
- func (v Value) AsString() string
- func (v Value) AsUint64() uint64
- func (v Value) Dump() string
- func (v Value) IsError() bool
- func (v Value) IsInt() bool
- func (v Value) IsList() bool
- func (v Value) IsString() bool
- type Variable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EvalContext ¶
type EvalContext interface{}
EvalContext is a context in which to evaluate an Expression. It is not used directly by cparse, but is passed to the Get methods of Function and Variable objects to get their value in the current context.
type Expression ¶
type Expression interface { // Evaluate the Expression in a given context. Can be called multiple times // with different contexts. If IsConstant() returns true, can be called with // nil context. Value(ctx EvalContext) Value // Return a string representation of the result of parsing the expression for // debugging. Dump() string // Returns true if the expression is constant (no function calls, all referenced // variables are ConstantVariables). If true, Value() will always return the // same value for any context, including nil. IsConstant() bool }
Expression is a parsed expression. Use Value(ctx) to evaluate it in a given context.
func CallFunction ¶
func CallFunction(function Function, name string, args []Expression) Expression
CallFunction returns an Expression that evaluates to the the value of the function called with the given argument expression.
func CastExpression ¶
func CastExpression(val Expression, size int, signed bool) Expression
CastExpression returns an Expression that evaluates to the the value of the given expression cast to the given integer type.
type Function ¶
type Function interface { // Called during Expression.Value(context) with the evaluation context and // the values of the arguments, and returns the value of the result Get(ctx EvalContext, args []Value) Value }
A Function object is a handle to call a function when an Expression is being evaluated
type Scope ¶
type Scope interface { GetVariable(name string) Variable GetFunction(name string) Function GetType(name string) string }
Scope is the scope in which to parse and Expression. Unknown symbols are passed to the methods of the Scope object to get a Variable or Function object, which is used during evaluation to get the value in the evaluation context.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
a placeholder for a string, an int64, an array of values, or a valueError
func (Value) AsInterface ¶
func (v Value) AsInterface() interface{}
As interface (for use in sprintf)
type Variable ¶
type Variable interface { // Called during Expression.Value(context) with the evaluation context returns // the value of the variable in the evaluation context Get(ctx EvalContext) Value }
A Function object is a handle to get the value of a variable when an Expression is being evaluated
func NewConstantVariable ¶
NewConstantVariable is a helper for use inside Scope.GetVariable if the value of the variable never changes. It allows the parser to optimize the expression by collapsing operators on constant values at parse time instead of evaluating them at evaluation time.