Documentation ¶
Index ¶
- Variables
- func Eval(expr Expr, m map[string]interface{}, multivaluer bool) bool
- func ScanString(r io.RuneScanner) (string, error)
- func Walk(v Visitor, node Node)
- func WalkFunc(node Node, fn func(Node))
- type BinaryExpr
- type BoolLiteral
- type CallValuer
- type DecimalLiteral
- type Expr
- type FieldLiteral
- type Function
- type FunctionDef
- type FunctionValuer
- type IPLiteral
- type IntegerLiteral
- type ListLiteral
- type MapValuer
- type Node
- type NotExpr
- type ParenExpr
- type ParseError
- type Parser
- type StringLiteral
- type UnsignedLiteral
- type Valuer
- type ValuerEval
- type Visitor
Constants ¶
This section is empty.
Variables ¶
var ( // ErrArgumentTypeMismatch signals an invalid argument type ErrArgumentTypeMismatch = func(i int, keyword string, fn functions.Fn, types []functions.ArgType) error { argTypes := make([]string, len(types)) for i, typ := range types { argTypes[i] = typ.String() } return fmt.Errorf("argument #%d (%s) in function %s should be one of: %v", i+1, keyword, fn, strings.Join(argTypes, "|")) } // ErrUndefinedFunction is thrown when an unknown function is supplied ErrUndefinedFunction = func(name string) error { return fmt.Errorf("%s function is undefined. Did you mean one of %s%s", name, strings.Join(functionNames(), "|"), "?") } // ErrFunctionSignature is thrown when the function signature is not satisfied ErrFunctionSignature = func(desc functions.FunctionDesc, givenArguments int) error { return fmt.Errorf("%s function requires %d argument(s) but %d argument(s) given", desc.Name, desc.RequiredArgs(), givenArguments) } )
Functions ¶
func ScanString ¶
func ScanString(r io.RuneScanner) (string, error)
ScanString reads a quoted string from a rune reader.
Types ¶
type BinaryExpr ¶
BinaryExpr represents an operation between two expressions.
func (*BinaryExpr) String ¶
func (e *BinaryExpr) String() string
String returns a string representation of the binary expression.
type BoolLiteral ¶
type BoolLiteral struct {
Value bool
}
BoolLiteral represents the logical true/false literal.
func (BoolLiteral) String ¶
func (b BoolLiteral) String() string
type CallValuer ¶
type CallValuer interface { Valuer // Call is invoked to evaluate a function call (if possible). Call(name string, args []interface{}) (interface{}, bool) }
CallValuer implements the Call method for evaluating function calls.
type DecimalLiteral ¶
type DecimalLiteral struct {
Value float64
}
DecimalLiteral represents an floating point number literal.
func (DecimalLiteral) String ¶
func (d DecimalLiteral) String() string
type Expr ¶
type Expr interface { Node }
Expr represents an expression that can be evaluated to a value.
type FieldLiteral ¶
type FieldLiteral struct {
Value string
}
FieldLiteral represents a field literal.
func (FieldLiteral) String ¶
func (f FieldLiteral) String() string
type FunctionDef ¶
type FunctionDef interface { // Call is the main function method that contains the implementation logic. Call(args []interface{}) (interface{}, bool) // Desc returns the function descriptor. Desc() functions.FunctionDesc // Name returns the function name. Name() functions.Fn }
FunctionDef is the interface that all function definitions have to satisfy.
type FunctionValuer ¶
type FunctionValuer struct {
// contains filtered or unexported fields
}
FunctionValuer implements the CallValuer interface and delegates the evaluation of function calls to the corresponding functions.
func (FunctionValuer) Call ¶
func (FunctionValuer) Call(name string, args []interface{}) (interface{}, bool)
func (FunctionValuer) Value ¶
func (f FunctionValuer) Value(key string) (interface{}, bool)
type IntegerLiteral ¶
type IntegerLiteral struct {
Value int64
}
IntegerLiteral represents a signed number literal.
func (IntegerLiteral) String ¶
func (i IntegerLiteral) String() string
type ListLiteral ¶
type ListLiteral struct {
Values []string
}
ListLiteral represents a list of tag key literals.
func (*ListLiteral) String ¶
func (s *ListLiteral) String() string
String returns a string representation of the literal.
type MapValuer ¶
type MapValuer map[string]interface{}
MapValuer is a valuer that substitutes values for the mapped interface.
type Node ¶
type Node interface {
String() string
}
Node represents a node in the abstract syntax tree.
type ParenExpr ¶
type ParenExpr struct {
Expr Expr
}
ParenExpr represents a parenthesized expression.
type ParseError ¶
ParseError represents an error that occurred during parsing.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
Error returns the string representation of the error.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser builds the binary expression tree from the filter string.
type StringLiteral ¶
type StringLiteral struct {
Value string
}
StringLiteral represents a string literal.
func (StringLiteral) String ¶
func (s StringLiteral) String() string
type UnsignedLiteral ¶
type UnsignedLiteral struct {
Value uint64
}
UnsignedLiteral represents an unsigned number literal.
func (UnsignedLiteral) String ¶
func (u UnsignedLiteral) String() string
type Valuer ¶
type Valuer interface { // Value returns the value and existence flag for a given key. Value(key string) (interface{}, bool) }
Valuer is the interface that wraps the Value() method.
func MultiValuer ¶
MultiValuer returns a Valuer that iterates over multiple Valuer instances to find a match.
type ValuerEval ¶
type ValuerEval struct { Valuer Valuer // IntegerFloatDivision will set the eval system to treat // a division between two integers as a floating point division. IntegerFloatDivision bool }
ValuerEval will evaluate an expression using the Valuer.
func (*ValuerEval) Eval ¶
func (v *ValuerEval) Eval(expr Expr) interface{}
Eval evaluates an expression and returns a value.