Documentation
¶
Overview ¶
Package dfl provides the interfaces, embedded structs, and implementing code for parsing, compiling, and evaluating Dynamic Filter Language (DFL) expressions.
Usage ¶
You can import dfl as a package into your own Go project or use the command line interface. A common architecture is to have a client application generate a DFL expression string and submit to a Go application using a rest interface.
import ( "github.com/spatialcurrent/go-dfl/pkg/dfl" ) root, err := dfl.Parse("<YOUR EXPRESSION>") if err != nil { panic(err) } root = root.Compile() // Flattens tree for performance if possible. result := root.Evaluate(Context{<YOUR KEY:VALUE Context>})
DFL ¶
DFL is another query or filter language like SQL, CQL, or ECQL. DFL aims to be easily understood by humans in a variety of contexts, such as in a url, in an editor, or in a python terminal. The principals are as follows:
- Easy to Read - The "@" in front of every attribute.
- Clean - Quotes are optional (unless required because of spaces in an element)
- Strict Execution Path - Use of parentheses is strongly encouraged o maximize performance over large datasets.
- Dynamically typed - Operators support multiple types and try to cast if possible. Fails hard if not valid.
- Embeddable - Easily written in other languages, such as Python, Javascript, or Shell, without endless worry about escaping.
DFL aims to cover a wide variety of filters while keeping the language expressive and easy to read. DFL currently supports:
- Boolean: Not, And, Or
- Numeric: LessThan, LessThanOrEqual, Equal, NotEqual, GreaterThan, GreaterThanOrEqual, Add, Subtract
- String: Like, ILike, In
- Time: Before, After
- Array/Set: In
- Function: Function
Command Line Interface ¶
See the github.com/go-dfl/cmd/dfl package for a command line tool for testing DFL expressions.
Projects ¶
go-dfl is used by the railgun and go-osm project.
- https://godoc.org/github.com/spatialcurrent/railgun/railgun
- https://godoc.org/github.com/spatialcurrent/go-osm/osm
- https://godoc.org/github.com/spatialcurrent/go-dfl/dfl
Examples ¶
Below are some simple examples.
import ( "github.com/spatialcurrent/go-dfl/pkg/dfl" ) root, err := dfl.Parse("(@amenity in [restaurant, bar]) or (@craft in [brewery, distillery])") if err != nil { panic(err) } root = root.Compile() valid := root.Evaluate(Context{"amenity": "bar", "name": "John's Whiskey Bar"})
Index ¶
- Variables
- func AttachLeft(root Node, left Node) error
- func CompareNumbers(a interface{}, b interface{}) (int, error)
- func CompareStrings(lvs string, rvs string) (bool, error)
- func CompareTimes(a interface{}, b interface{}) (int, error)
- func CreateGroups(depth int) interface{}
- func DivideNumbers(a interface{}, b interface{}) (interface{}, error)
- func EscapeString(in string) string
- func EvaluateArray(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func EvaluateBool(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, bool, error)
- func EvaluateFloat64(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, float64, error)
- func EvaluateInt(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, int, error)
- func EvaluateMap(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func EvaluateString(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, string, error)
- func Extract(path string, obj interface{}, vars map[string]interface{}, ctx interface{}, ...) (interface{}, error)
- func FormatList(values []string, delim string, pretty bool, tabs int) string
- func FormatNodes(nodes []Node, quotes []string, pretty bool, tabs int) []string
- func FormatSql(value interface{}, pretty bool, tabs int) string
- func MustParseCompileEvaluate(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{})
- func ParseAndCompileExpressions(expressions map[string]string) (map[string]Node, error)
- func ParseCompileEvaluate(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func ParseCompileEvaluateInt(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, int, error)
- func ParseCompileEvaluateMap(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func ParseCompileEvaluateString(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, string, error)
- func ParseKeyValue(in string) (map[Node]Node, error)
- func RemoveComments(in string) string
- func TryConvertArray(a []interface{}) interface{}
- func TryConvertMap(m interface{}) interface{}
- func TryConvertString(s string) interface{}
- func TryFormatLiteral(value interface{}, quotes []string, pretty bool, tabs int) string
- func UnescapeString(in string) string
- func WithinRange(value interface{}, start interface{}, end interface{}) (bool, error)
- type Add
- func (a Add) Compile() Node
- func (a Add) Dfl(quotes []string, pretty bool, tabs int) string
- func (a Add) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (a Add) Map() map[string]interface{}
- func (a Add) Sql(pretty bool, tabs int) string
- type After
- func (a After) Compile() Node
- func (a After) Dfl(quotes []string, pretty bool, tabs int) string
- func (a After) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (a After) Map() map[string]interface{}
- func (a After) Sql(pretty bool, tabs int) string
- type And
- func (a And) Compile() Node
- func (a And) Dfl(quotes []string, pretty bool, tabs int) string
- func (a And) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (a And) Map() map[string]interface{}
- func (a And) Sql(pretty bool, tabs int) string
- type Array
- func (a Array) Attributes() []string
- func (a Array) Compile() Node
- func (a Array) Dfl(quotes []string, pretty bool, tabs int) string
- func (a Array) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (a Array) Len() int
- func (a Array) Map() map[string]interface{}
- func (a Array) Sql(pretty bool, tabs int) string
- func (a Array) Variables() []string
- type Assign
- func (a Assign) Compile() Node
- func (a Assign) Dfl(quotes []string, pretty bool, tabs int) string
- func (a Assign) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (a Assign) Map() map[string]interface{}
- func (a Assign) Sql(pretty bool, tabs int) string
- type AssignAdd
- func (a AssignAdd) Compile() Node
- func (a AssignAdd) Dfl(quotes []string, pretty bool, tabs int) string
- func (a AssignAdd) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (a AssignAdd) Map() map[string]interface{}
- func (a AssignAdd) Sql(pretty bool, tabs int) string
- type AssignMultiply
- func (a AssignMultiply) Compile() Node
- func (a AssignMultiply) Dfl(quotes []string, pretty bool, tabs int) string
- func (a AssignMultiply) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (a AssignMultiply) Map() map[string]interface{}
- func (a AssignMultiply) Sql(pretty bool, tabs int) string
- type AssignSubtract
- func (a AssignSubtract) Compile() Node
- func (a AssignSubtract) Dfl(quotes []string, pretty bool, tabs int) string
- func (a AssignSubtract) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (a AssignSubtract) Map() map[string]interface{}
- func (a AssignSubtract) Sql(pretty bool, tabs int) string
- type Attribute
- func (a Attribute) Attributes() []string
- func (a Attribute) Compile() Node
- func (a Attribute) Dfl(quotes []string, pretty bool, tabs int) string
- func (a Attribute) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (a Attribute) Map() map[string]interface{}
- func (a Attribute) Sql(pretty bool, tabs int) string
- func (a Attribute) Variables() []string
- type Before
- func (b Before) Compile() Node
- func (b Before) Dfl(quotes []string, pretty bool, tabs int) string
- func (b Before) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (b Before) Map() map[string]interface{}
- func (b Before) Sql(pretty bool, tabs int) string
- type BinaryOperator
- func (bo BinaryOperator) Attributes() []string
- func (bo BinaryOperator) Builder(operator string, quotes []string, tabs int) builder.Builder
- func (bo BinaryOperator) Dfl(operator string, quotes []string, pretty bool, tabs int) string
- func (bo BinaryOperator) EvaluateLeftAndRight(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, interface{}, error)
- func (bo BinaryOperator) Map(operator string, left Node, right Node) map[string]interface{}
- func (bo BinaryOperator) Sql(operator string, pretty bool, tabs int) string
- func (bo BinaryOperator) Variables() []string
- type Coalesce
- func (c Coalesce) Compile() Node
- func (c Coalesce) Dfl(quotes []string, pretty bool, tabs int) string
- func (c Coalesce) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (c Coalesce) Map() map[string]interface{}
- func (c Coalesce) Sql(pretty bool, tabs int) string
- type Concat
- func (c Concat) Compile() Node
- func (c Concat) Dfl(quotes []string, pretty bool, tabs int) string
- func (c Concat) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (c Concat) Map() map[string]interface{}
- func (c Concat) Sql(pretty bool, tabs int) string
- func (c Concat) Suffix() string
- type Context
- type Dictionary
- func (d Dictionary) Attributes() []string
- func (d Dictionary) Compile() Node
- func (d Dictionary) Dfl(quotes []string, pretty bool, tabs int) string
- func (d Dictionary) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (d Dictionary) Len() int
- func (d Dictionary) Map() map[string]interface{}
- func (d Dictionary) Sql(pretty bool, tabs int) string
- func (d Dictionary) Variables() []string
- type Divide
- func (d Divide) Compile() Node
- func (d Divide) Dfl(quotes []string, pretty bool, tabs int) string
- func (d Divide) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (d Divide) Map() map[string]interface{}
- func (d Divide) Sql(pretty bool, tabs int) string
- type Equal
- func (e Equal) Compile() Node
- func (e Equal) Dfl(quotes []string, pretty bool, tabs int) string
- func (e Equal) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (e Equal) Map() map[string]interface{}
- func (e Equal) Sql(pretty bool, tabs int) string
- type ErrParseTernary
- type ErrorEvaluate
- type Function
- func (f Function) Compile() Node
- func (f Function) Dfl(quotes []string, pretty bool, tabs int) string
- func (f Function) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (f Function) Map() map[string]interface{}
- func (f Function) Sql(pretty bool, tabs int) string
- type FunctionMap
- type GreaterThan
- func (gt GreaterThan) Compile() Node
- func (gt GreaterThan) Dfl(quotes []string, pretty bool, tabs int) string
- func (gt GreaterThan) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (gt GreaterThan) Map() map[string]interface{}
- func (gt GreaterThan) Sql(pretty bool, tabs int) string
- type GreaterThanOrEqual
- func (gte GreaterThanOrEqual) Compile() Node
- func (gte GreaterThanOrEqual) Dfl(quotes []string, pretty bool, tabs int) string
- func (gte GreaterThanOrEqual) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (gte GreaterThanOrEqual) Map() map[string]interface{}
- func (gte GreaterThanOrEqual) Sql(pretty bool, tabs int) string
- type IIn
- func (i IIn) Compile() Node
- func (i IIn) Dfl(quotes []string, pretty bool, tabs int) string
- func (i IIn) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (i IIn) Map() map[string]interface{}
- func (i IIn) Sql(pretty bool, tabs int) string
- type ILike
- func (i ILike) Compile() Node
- func (i ILike) Dfl(quotes []string, pretty bool, tabs int) string
- func (i ILike) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (i ILike) Map() map[string]interface{}
- func (i ILike) Sql(pretty bool, tabs int) string
- type In
- func (i In) Compile() Node
- func (i In) Dfl(quotes []string, pretty bool, tabs int) string
- func (i In) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (i In) Map() map[string]interface{}
- func (i In) Sql(pretty bool, tabs int) string
- type Lengther
- type LessThan
- func (lt LessThan) Compile() Node
- func (lt LessThan) Dfl(quotes []string, pretty bool, tabs int) string
- func (lt LessThan) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (lt LessThan) Map() map[string]interface{}
- func (lt LessThan) Sql(pretty bool, tabs int) string
- type LessThanOrEqual
- func (lte LessThanOrEqual) Compile() Node
- func (lte LessThanOrEqual) Dfl(quotes []string, pretty bool, tabs int) string
- func (lte LessThanOrEqual) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (lte LessThanOrEqual) Map() map[string]interface{}
- func (lte LessThanOrEqual) Sql(pretty bool, tabs int) string
- type Like
- func (l Like) Compile() Node
- func (l Like) Dfl(quotes []string, pretty bool, tabs int) string
- func (l Like) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (l Like) Map() map[string]interface{}
- func (l Like) Sql(pretty bool, tabs int) string
- type Literal
- func (l Literal) Attributes() []string
- func (l Literal) Compile() Node
- func (l Literal) Dfl(quotes []string, pretty bool, tabs int) string
- func (l Literal) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (l Literal) Map() map[string]interface{}
- func (l Literal) Sql(pretty bool, tabs int) string
- func (l Literal) Variables() []string
- type MultiOperator
- type Multiply
- func (m Multiply) Compile() Node
- func (m Multiply) Dfl(quotes []string, pretty bool, tabs int) string
- func (m Multiply) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (m Multiply) Map() map[string]interface{}
- func (m Multiply) Sql(pretty bool, tabs int) string
- type Node
- func MustParseCompile(expression string) Node
- func Parse(in string) (Node, string, error)
- func ParseArray(in string, remainder string) (Node, string, error)
- func ParseAttribute(in string, remainder string) (Node, string, error)
- func ParseCompile(expression string) (Node, error)
- func ParseFunction(in string, remainder string) (Node, string, error)
- func ParseList(in string) ([]Node, error)
- func ParseListOrKeyValue(in string) (bool, []Node, map[Node]Node, error)
- func ParseLiteral(v interface{}, remainder string) (Node, string, error)
- func ParseSetOrDictionary(in string, remainder string) (Node, string, error)
- func ParseSub(s string, remainder string) (Node, string, error)
- func ParseVariable(in string, remainder string) (Node, string, error)
- type Not
- func (n Not) Compile() Node
- func (n Not) Dfl(quotes []string, pretty bool, tabs int) string
- func (n Not) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (n Not) Map() map[string]interface{}
- func (n Not) Sql(pretty bool, tabs int) string
- type NotEqual
- func (ne NotEqual) Compile() Node
- func (ne NotEqual) Dfl(quotes []string, pretty bool, tabs int) string
- func (ne NotEqual) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (ne NotEqual) Map() map[string]interface{}
- func (ne NotEqual) Sql(pretty bool, tabs int) string
- type Null
- type NumericBinaryOperator
- type Or
- func (o Or) Compile() Node
- func (o Or) Dfl(quotes []string, pretty bool, tabs int) string
- func (o Or) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (o Or) Map() map[string]interface{}
- func (o Or) Sql(pretty bool, tabs int) string
- type Pipe
- func (p Pipe) Compile() Node
- func (p Pipe) Dfl(quotes []string, pretty bool, tabs int) string
- func (p Pipe) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (p Pipe) Last() Node
- func (p Pipe) Map() map[string]interface{}
- func (p Pipe) Sql(pretty bool, tabs int) string
- type Pipeline
- func (p Pipeline) Attributes() []string
- func (p Pipeline) Compile() Node
- func (p Pipeline) Dfl(quotes []string, pretty bool, tabs int) string
- func (p Pipeline) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (p Pipeline) Len() int
- func (p Pipeline) Map() map[string]interface{}
- func (p Pipeline) Sql(pretty bool, tabs int) string
- func (p Pipeline) Variables() []string
- type Print
- func (p Print) Compile() Node
- func (p Print) Dfl(quotes []string, pretty bool, tabs int) string
- func (p Print) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (p Print) Map() map[string]interface{}
- func (p Print) Sql(pretty bool, tabs int) string
- type Reader
- type Set
- func (a Set) Attributes() []string
- func (a Set) Compile() Node
- func (s Set) Dfl(quotes []string, pretty bool, tabs int) string
- func (a Set) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (s Set) Len() int
- func (a Set) Map() map[string]interface{}
- func (s Set) Sql(pretty bool, tabs int) string
- func (a Set) Variables() []string
- type StringSet
- func (set StringSet) Add(values ...string)
- func (set StringSet) Contains(x string) bool
- func (set StringSet) Dfl(quotes []string, pretty bool, tabs int) string
- func (set StringSet) Intersection(values interface{}) StringSet
- func (set StringSet) Intersects(values interface{}) bool
- func (set StringSet) Len() int
- func (set StringSet) Slice(sorted bool) sort.StringSlice
- func (set StringSet) Union(values interface{}) StringSet
- type Subtract
- func (s Subtract) Compile() Node
- func (s Subtract) Dfl(quotes []string, pretty bool, tabs int) string
- func (s Subtract) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (s Subtract) Map() map[string]interface{}
- func (s Subtract) Sql(pretty bool, tabs int) string
- type TemporalBinaryOperator
- type TernaryOperator
- func (to TernaryOperator) Attributes() []string
- func (to TernaryOperator) Compile() Node
- func (to TernaryOperator) Dfl(quotes []string, pretty bool, tabs int) string
- func (to TernaryOperator) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (to TernaryOperator) Map() map[string]interface{}
- func (to TernaryOperator) Sql(pretty bool, tabs int) string
- func (to TernaryOperator) Variables() []string
- type TestCase
- type UnaryOperator
- type Variable
- func (v Variable) Attributes() []string
- func (v Variable) Compile() Node
- func (v Variable) Dfl(quotes []string, pretty bool, tabs int) string
- func (v Variable) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (v Variable) Map() map[string]interface{}
- func (v Variable) Sql(pretty bool, tabs int) string
- func (v Variable) Variables() []string
- type Within
- func (w Within) Compile() Node
- func (w Within) Dfl(quotes []string, pretty bool, tabs int) string
- func (w Within) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (w Within) Map() map[string]interface{}
- func (w Within) Sql(pretty bool, tabs int) string
- type Xor
- func (x Xor) Compile() Node
- func (x Xor) Dfl(quotes []string, pretty bool, tabs int) string
- func (x Xor) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, ...) (map[string]interface{}, interface{}, error)
- func (x Xor) Map() map[string]interface{}
- func (x Xor) Sql(pretty bool, tabs int) string
Constants ¶
This section is empty.
Variables ¶
var DefaultFunctionMap = NewFuntionMapWithDefaults()
var DefaultQuotes = []string{"'", "\"", "`"}
var DefaultTab = " "
var NoContext = map[string]interface{}{}
var NoVars = map[string]interface{}{}
var SqlArrayPrefix = "{"
var SqlArraySuffix = "}"
var SqlQuote = "'"
var Version = "0.0.11"
Functions ¶
func AttachLeft ¶
AttachLeft attaches the left Node as the left child node to the parent root Node.
func CompareNumbers ¶
CompareNumbers compares parameter a and parameter b. The parameters may be of type uint8, int, int64, or float64. If a > b, then returns 1. If a < b, then returns -1. If a == b, then return 0.
func CompareStrings ¶
CompareStrings compares parameter a and parameter b. The parameters must be of type string. Returns true if a like b.
func CompareTimes ¶
CompareTimes compares parameter a and parameter b. The parameters may be of type string, time.Time, or *time.Time. If a is after b, then returns 1. If a is before b, then returns -1. If a is at the same time as b, then return 0.
func CreateGroups ¶
func CreateGroups(depth int) interface{}
func DivideNumbers ¶
func DivideNumbers(a interface{}, b interface{}) (interface{}, error)
DivideNumbers divides the first number by the second number and returns the results. The parameters can be an int, int64, or float64. The parameters will be cast as applicable. For example you can divide two integers with
total := DivideNumbers(1, 2)
or you could divide an int with a float64.
total := DivideNumbers(4, 3.2)
func EscapeString ¶
func EvaluateArray ¶
func EvaluateArray(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
EvaluateArray returns the array/slice value of a node given a context. If the result is not an array or slice, then returns an error.
func EvaluateBool ¶
func EvaluateBool(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, bool, error)
EvaluateBool returns the boolean value of a node given a context. If the result is not a bool, then returns an error.
func EvaluateFloat64 ¶
func EvaluateFloat64(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, float64, error)
EvaluateFloat64 returns the float64 value of a node given a context. If the result is not a float64, then returns an error.
func EvaluateInt ¶
func EvaluateInt(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, int, error)
EvaluateInt returns the int value of a node given a context. If the result is not an int, then returns an error.
func EvaluateMap ¶
func EvaluateMap(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
EvaluateMap returns the map value of a node given a context. If the result is not a map, then returns an error.
func EvaluateString ¶
func EvaluateString(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, string, error)
EvaluateString returns the string value of a node given a context. If the result is not a string, then returns an error.
func Extract ¶
func Extract(path string, obj interface{}, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (interface{}, error)
Extract is a function to extract a value from an object. Extract supports a standard dot (.) and null-safe (?.) indexing. Extract also supports wildcard indexing using *. Extract also support array indexing, including [A], [A:B], [A:], and [:B].
func FormatNodes ¶
FormatNodes formats an array of nodes to a string.
func MustParseCompileEvaluate ¶
func MustParseCompileEvaluate(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{})
MustParseCompileEvaluate parses the expression, compiles the node, and evaluates on the given context. Panics if any error.
func ParseAndCompileExpressions ¶
ParseAndCompileExpressions is a usability function to parse and compile multiple expressions.
func ParseCompileEvaluate ¶
func ParseCompileEvaluate(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
ParseCompileEvaluate parses the expression, compiles the node, and evaluates on the given context.
func ParseCompileEvaluateInt ¶
func ParseCompileEvaluateInt(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, int, error)
ParseCompileEvaluateInt parses the expression, compiles the node, evaluates on the given context, and returns a result of type int if valid, otherwise returns and error.
func ParseCompileEvaluateMap ¶
func ParseCompileEvaluateMap(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
ParseCompileEvaluateMap parses the expression, compiles the node, evaluates on the given context, and returns a result of kind map if valid, otherwise returns and error.
func ParseCompileEvaluateString ¶
func ParseCompileEvaluateString(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, string, error)
ParseCompileEvaluateString parses the expression, compiles the node, evaluates on the given context, and returns a result of kind string if valid, otherwise returns and error.
func ParseKeyValue ¶
ParseKeyValue parses a sequence of key value pairs
func RemoveComments ¶
RemoveComments removes comments from a multi-line dfl expression
func TryConvertArray ¶
func TryConvertArray(a []interface{}) interface{}
TryConvertArray attempts to convert the []interface{} array into []int, []int64, []float64, or []string, if possible.
func TryConvertMap ¶
func TryConvertMap(m interface{}) interface{}
TryConvertMap attempts to convert the interface{} map into a typed version
func TryConvertString ¶
func TryConvertString(s string) interface{}
TryConvertString attempts to parse the string parameter s into an appropriate literal value of type string, bool, int, float64, or time.Time. The functions evaluates the following rules in order. It returns the first success. The rules are:
- "null", "none", "" => ""
- "true" => true (bool)
- "false" => false (bool)
- "0.234" => float64
- 131238 => int
- time.Parse(time.RFC3339Nano, s)
- time.Parse(time.RFC3339, s)
- time.Parse("2006-01-02", s)
- If no rules pass without error, then just return the input value
For example:
TryConvertString("a") => "a" (string) TryConvertString("true") => true (bool) TryConvertString("123.31") => 123.31 (float64) TryConvertString("4") => 4 (int) TryConvertString("2018-05-01") => 2018-05-01T00:00:00Z (time.Time)
func TryFormatLiteral ¶
func UnescapeString ¶
UnescapeString unescapes a string
- \\ => \
- \n => new line
- \r => carriage return
- \t => horizontal tab
- \s => space
- \u1234 => unicode value
func WithinRange ¶
WithinRange returns true if value is in the range [start, end]
Types ¶
type Add ¶
type Add struct {
*BinaryOperator
}
Add is a BinaryOperator that represents the addition of two nodes.
func (Add) Compile ¶
Compile returns a compiled version of this node. If the left and right values are both compiled as literals, then returns the compiled Literal with that value set. Otherwise returns a clone of this node.
func (Add) Evaluate ¶
func (a Add) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
Evaluate returns the value of this node given Context ctx, and an error if any.
type After ¶
type After struct {
*TemporalBinaryOperator // Extends the TemporalBinaryOperator struct
}
After is a TemporalBinaryOperator evaluating to true if the left value is after the right value. The left and right values must be string, time.Time, or *time.Time.
type And ¶
type And struct {
*BinaryOperator
}
And is a BinaryOperator which represents the logical boolean AND operation of left and right values.
func (And) Compile ¶
Compile returns a compiled version of this node. If the left value and right value are both compiled as Literals, then returns the logical boolean AND operation of the left and right value. Otherwise, returns a clone.
type Array ¶
type Array struct {
Nodes []Node
}
Array is a Node representing an array of values, which can be either a Literal or Attribute.
func (Array) Attributes ¶
func (Array) Compile ¶
Compile returns a compiled version of this node. If all the values of an Set are literals, returns a single Literal with the corresponding array as its value. Otherwise returns the original node..
type Assign ¶
type Assign struct {
*BinaryOperator
}
Assign is a BinaryOperator which sets the value of the right side to the attribute or variable defined by the left side.
type AssignAdd ¶
type AssignAdd struct {
*BinaryOperator
}
AssignAdd is a BinaryOperator which sets the added value of the left side and right side to the attribute or variable defined by the left side.
type AssignMultiply ¶
type AssignMultiply struct {
*BinaryOperator
}
AssignMultiply is a BinaryOperator which sets the multiplied value of the left side and right side to the attribute or variable defined by the left side.
func (AssignMultiply) Compile ¶
func (a AssignMultiply) Compile() Node
Compile returns a compiled version of this node.
func (AssignMultiply) Dfl ¶
func (a AssignMultiply) Dfl(quotes []string, pretty bool, tabs int) string
func (AssignMultiply) Evaluate ¶
func (a AssignMultiply) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
func (AssignMultiply) Map ¶
func (a AssignMultiply) Map() map[string]interface{}
type AssignSubtract ¶
type AssignSubtract struct {
*BinaryOperator
}
AssignSubtract is a BinaryOperator which sets the value of the left side subtracted by the right side to the attribute or variable defined by the left side.
func (AssignSubtract) Compile ¶
func (a AssignSubtract) Compile() Node
Compile returns a compiled version of this node.
func (AssignSubtract) Dfl ¶
func (a AssignSubtract) Dfl(quotes []string, pretty bool, tabs int) string
func (AssignSubtract) Evaluate ¶
func (a AssignSubtract) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
func (AssignSubtract) Map ¶
func (a AssignSubtract) Map() map[string]interface{}
type Attribute ¶
type Attribute struct {
Name string
}
Attribute is a Node representing the value of an attribute in the context map. Attributes start with a "@" and follow with the name or full path into the object if multiple levels deep. For example, @a and @a.b.c.d. You can also use a null-safe operator, e.g., @a?.b?.c?.d
func (Attribute) Attributes ¶
type Before ¶
type Before struct {
*TemporalBinaryOperator // Extends the TemporalBinaryOperator struct
}
Before is a TemporalBinaryOperator evaluating to true if the left value is before the right value. The left and right values must be string, time.Time, or *time.Time.
type BinaryOperator ¶
BinaryOperator is a DFL Node that represents the binary operator of a left value and right value. This struct functions as an embedded struct for many comparator operations.
func (BinaryOperator) Attributes ¶
func (bo BinaryOperator) Attributes() []string
Attributes returns a slice of all attributes used in the evaluation of this node, including a children nodes. Attributes de-duplicates values from the left node and right node using a set.
func (BinaryOperator) EvaluateLeftAndRight ¶
func (bo BinaryOperator) EvaluateLeftAndRight(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, interface{}, error)
EvaluateLeftAndRight evaluates the value of the left node and right node given a context map (ctx) and function map (funcs). Returns a 3 value tuple of left value, right value, and error.
func (BinaryOperator) Map ¶
func (bo BinaryOperator) Map(operator string, left Node, right Node) map[string]interface{}
func (BinaryOperator) Sql ¶
func (bo BinaryOperator) Sql(operator string, pretty bool, tabs int) string
func (BinaryOperator) Variables ¶
func (bo BinaryOperator) Variables() []string
Variables returns a slice of all variables used in the evaluation of this node, including a children nodes. Attributes de-duplicates values from the left node and right node using a set.
type Coalesce ¶
type Coalesce struct {
*BinaryOperator
}
Coalesce is a BinaryOperator which returns the left value if not null otherwise the right value.
func (Coalesce) Compile ¶
Compile returns a compiled version of this node. If the left value is compiled as a Literal, then returns the left value. Otherwise, returns a clone.
type Concat ¶
type Concat struct {
*MultiOperator
}
Concat concatenates the string representation of all the arguments
type Context ¶
type Context struct {
Data map[string]interface{}
}
Context is a simple alias for a map[string]interface{} that is used for containing the context for evaluating a DFL Node. The values in a context are essentially the input parameters for a DFL expression and match up with the Attribute. The Context is built from the trailing command line arguments. For example the arguments from the following command line
./dfl -filter "(@amenity like bar) and (open > 0)" amenity=bar popularity=10 open=1
Would be interpreted as the following Context
ctx := Context{"amenity": "bar", "popularity": 10, "open": 1}
type Dictionary ¶
Dictionary is a Node representing a dictionary of key value pairs.
func NewDictionary ¶
func NewDictionary(m map[string]interface{}) *Dictionary
func (Dictionary) Attributes ¶
func (d Dictionary) Attributes() []string
func (Dictionary) Compile ¶
func (d Dictionary) Compile() Node
Compile returns a compiled version of this node.
func (Dictionary) Evaluate ¶
func (d Dictionary) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
func (Dictionary) Len ¶
func (d Dictionary) Len() int
Len returns the length of the underlying array.
func (Dictionary) Map ¶
func (d Dictionary) Map() map[string]interface{}
func (Dictionary) Sql ¶
func (d Dictionary) Sql(pretty bool, tabs int) string
Sql returns the SQL representation of this node as a string
func (Dictionary) Variables ¶
func (d Dictionary) Variables() []string
type Divide ¶
type Divide struct {
*NumericBinaryOperator
}
Divide is a NumericBinaryOperator that represents the mathematical division of two nodes.
func (Divide) Evaluate ¶
func (d Divide) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
Evaluate evaluates this node given the variables "vars" and context "ctx" and returns the output, and an error if any.
type Equal ¶
type Equal struct {
*BinaryOperator
}
Equal is a BinaryOperator that evaluating to true if parameter a is equal to parameter b. The parameters may be of type int, int64, or float64.
type ErrParseTernary ¶
type ErrParseTernary struct { Original string // original Condition string // the condition True string // the true value False string // the false value }
ErrParseTernary is an error when parsing ternary expressions.
func (ErrParseTernary) Error ¶
func (e ErrParseTernary) Error() string
Error returns the error as a string.
type ErrorEvaluate ¶
type ErrorEvaluate struct { Node Node // the name of the Function Quotes []string // the quotes to use }
ErrorEvaluate is an error returned when an error occurs during evaluation of a Node.
func (ErrorEvaluate) Error ¶
func (e ErrorEvaluate) Error() string
Error returns the error as a string.
type Function ¶
type Function struct { *MultiOperator Name string `json:"name" bson:"name" yaml:"name" hcl:"name"` // name of the function }
Function is a refrenced function in a DFL filter. The actual function in a given FunctionMap is derefernced by name.
type FunctionMap ¶
type FunctionMap map[string]func(FunctionMap, map[string]interface{}, interface{}, []interface{}, []string) (interface{}, error)
FunctionMap is a map of functions by string that are reference by name in the Function Node.
func NewFuntionMapWithDefaults ¶
func NewFuntionMapWithDefaults() FunctionMap
type GreaterThan ¶
type GreaterThan struct {
*NumericBinaryOperator
}
GreaterThan is a NumericBinaryOperator that evaluating to true if parameter a is greater than parameter b. The parameters may be of type int, int64, or float64.
func (GreaterThan) Compile ¶
func (gt GreaterThan) Compile() Node
func (GreaterThan) Evaluate ¶
func (gt GreaterThan) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
func (GreaterThan) Map ¶
func (gt GreaterThan) Map() map[string]interface{}
type GreaterThanOrEqual ¶
type GreaterThanOrEqual struct {
*NumericBinaryOperator
}
GreaterThanOrEqual is a NumericBinaryOperator that evaluating to true if parameter a is greater than or equal to parameter b. The parameters may be of type int, int64, or float64.
func (GreaterThanOrEqual) Compile ¶
func (gte GreaterThanOrEqual) Compile() Node
func (GreaterThanOrEqual) Dfl ¶
func (gte GreaterThanOrEqual) Dfl(quotes []string, pretty bool, tabs int) string
func (GreaterThanOrEqual) Evaluate ¶
func (gte GreaterThanOrEqual) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
func (GreaterThanOrEqual) Map ¶
func (gte GreaterThanOrEqual) Map() map[string]interface{}
type IIn ¶
type IIn struct {
*BinaryOperator
}
In is a BinaryOperator that evaluates to true if the left value is in the right value. Unlike "in", it is case insensitive. If the right value is an array/slice, then evaluated to true if the left value is in the array/slice. Otherwise, evaluates to true if the right string is contained by the left string.
type In ¶
type In struct {
*BinaryOperator
}
In is a BinaryOperator that evaluates to true if the left value is in the right value. The left value is cast as a string using "fmt.Sprint(lv)". If the right value is an array/slice, then evaluated to true if the left value is in the array/slice. Otherwise, evaluates to true if the right string is contained by the left string.
type LessThan ¶
type LessThan struct {
*NumericBinaryOperator
}
LessThan is a NumericBinaryOperator that evaluating to true if parameter a is less than parameter b. The parameters may be of type int, int64, or float64.
type LessThanOrEqual ¶
type LessThanOrEqual struct {
*NumericBinaryOperator
}
LessThanOrEqual is a NumericBinaryOperator that evaluating to true if parameter a is less than or equal to parameter b. The parameters may be of type int, int64, or float64.
func (LessThanOrEqual) Compile ¶
func (lte LessThanOrEqual) Compile() Node
func (LessThanOrEqual) Dfl ¶
func (lte LessThanOrEqual) Dfl(quotes []string, pretty bool, tabs int) string
Sql returns the DFL representation of this node as a string
func (LessThanOrEqual) Evaluate ¶
func (lte LessThanOrEqual) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
func (LessThanOrEqual) Map ¶
func (lte LessThanOrEqual) Map() map[string]interface{}
type Like ¶
type Like struct {
*BinaryOperator
}
Like is a BinaryOperator that evaluates the SQL standard like expression. It is similar to the ILike BinaryOperator but is case sensitive. The parameters must be of type string. The right parameter may have "%" characters that are interpreted as (.*) in a regular expression test.
type Literal ¶
type Literal struct {
Value interface{} // the field containing the actual value
}
Literal is a Node representing a literal/static value regardless of the context. The value may be of any type; however, it will likely a bool, int, or string. For example
Literal{Value: ""} Literal{Value: 0.0}
func (Literal) Attributes ¶
type MultiOperator ¶
type MultiOperator struct {
Arguments []Node `json:"arguments" bson:"arguments" yaml:"arguments" hcl:"arguments"` // list of function arguments
}
MultiOperator represents an operator with a dynamic list of arguments.
func (MultiOperator) Attributes ¶
func (mo MultiOperator) Attributes() []string
func (MultiOperator) First ¶
func (mo MultiOperator) First() Node
First returns the last argument for this operator, if exists.
func (MultiOperator) Last ¶
func (mo MultiOperator) Last() Node
Last returns the last argument for this operator, if exists.
func (MultiOperator) Map ¶
func (mo MultiOperator) Map(operator string) map[string]interface{}
func (MultiOperator) Variables ¶
func (mo MultiOperator) Variables() []string
type Multiply ¶
type Multiply struct {
*NumericBinaryOperator
}
Multiply is a NumericBinaryOperator that represents the mathematical multiplication of two nodes.
func (Multiply) Evaluate ¶
func (m Multiply) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
Evaluate evaluates this node given the variables "vars" and context "ctx" and returns the output, and an error if any.
type Node ¶
type Node interface { Dfl(quotes []string, pretty bool, tabs int) string // returns the DFL expression representation of this node Sql(pretty bool, tabs int) string // returns the SQL representation of this node Map() map[string]interface{} // returns a map representing this node Compile() Node // compiles this node (and all children). Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error) // evaluates the value of a node given a context Attributes() []string // returns a slice of all attributes used by this node (and all children nodes) Variables() []string // returns a slice of all variables used by this node (and all children nodes) }
Node is the interface for representing the constructs of the Dyanmic Filter Language in an Abstract Syntax Tree. This interface is inherited by most structs in the dfl package.
func MustParseCompile ¶
MustParseCompile parses the input expression and compiles the DFL node. Panics if any error.
func Parse ¶
Parse parses a DFL expression into an an Abstract Synatax Tree (AST). Parse returns the AST, remainder, and error if any.
func ParseArray ¶
ParseArray parses an array of nodes. If parameter "in" is gramatically a child node, then return the parent node. DFL arrays can include Attribute or Literal Nodes. As all attribute references must start with an "@" character, parantheses are optional for literals except if a comma exists. Below are some example inputs
[bank, bureau_de_change, atm] [1, 2, @target] [Taco, Tacos, Burrito, Burritos, "Mexican Food", @example]
func ParseAttribute ¶
ParseAttribute parses an Attribute Node from an input string If parameter "in" is gramatically a child node, then return the parent node. All attribute references must start with an "@" character and have no spaces. For example, @amenity, @shop, @population, etc. Given those rules the remainder, if any, if simply parsed from the input strings Examples:
node, err := ParseAttribute("@amenity in [bar, restaurant]")
func ParseCompile ¶
ParseCompile parses the input expression and compiles the DFL node.
func ParseFunction ¶
ParseFunction parses a function from in and attaches the remainder.
func ParseListOrKeyValue ¶
ParseList parses a list of values.
func ParseLiteral ¶
ParseLiteral wraps parameter v in a Literal Node and parses a remainder, if any. ParseLiteral does not additional parsing of parameter v. TryConvertString is used to parse an int, float64, or time from a string representation. If parameter "in" is gramatically a child node, then return the parent node. For example, @amenity, @shop, @population, etc. Given those rules the remainder, if any, if simply parsed from the input strings Examples:
node, err := ParseLiteral("brewery")
func ParseSetOrDictionary ¶
ParseSetOrDictionary parses a Set or Dictionary Node and recursively any remainder. If parameter "in" is gramatically a child node, then return the parent node. DFL sets/dictionaries can include Attribute or Literal Nodes. As all attribute references must start with an "@" character, parentheses are optional for literals except if a comma exists. Below are some example inputs
{bank, bureau_de_change, atm} {1, 2, @target} {Taco, Tacos, Burrito, Burritos, "Mexican Food", @example} {amenity: bank}
func ParseSub ¶
ParseSub is used to parse a sub-expression and the remainder, if any. A sub-expression is usually enclosed by parantheses. The parantheses are removed before being passed to ParseSub. If parameter "in" is gramatically a child node, then return the parent node. For Example with an input string "(@cuisine like mexican) or (@name ilike %burrito%)",
node, err : ParseSub("@cuisine like mexican", "or (@name ilike %burrito%)")
func ParseVariable ¶
ParseVariable parses a Variable Node from an input string If parameter "in" is gramatically a child node, then return the parent node. All variable references must start with an "$" character and have no spaces. For example, $amenity, $shop, $population, etc. Given those rules the remainder, if any, if simply parsed from the input strings Examples:
node, err := ParseAttribute("$amenities := [bar, restaurant]")
type Not ¶
type Not struct {
*UnaryOperator
}
Not is a UnaryOperator that inverts the boolean value of the children Node.
func (Not) Compile ¶
Compile returns a compiled version of this node. If the the child Node is compiled as a boolean Literal, then returns an inverse Literal Node. Otherwise returns a clone of this node.
func (Not) Evaluate ¶
func (n Not) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
Evaluate evaluates this node within a context and returns the bool result, and error if any.
type NotEqual ¶
type NotEqual struct {
*BinaryOperator
}
NotEqual is a BinaryOperator that evaluates to true if the left value is not equal to the right value. The values may be of type int, int64, or float64.
func (NotEqual) Dfl ¶
Dfl returns the DFL expression representation of the node as a string value. For example
"( @amenity != shop )"
type Null ¶
type Null struct{}
Null is used as return value for Extract and DFL functions instead of returning nil pointers.
type NumericBinaryOperator ¶
type NumericBinaryOperator struct {
*BinaryOperator // Extends the BinaryOperator struct
}
NumericBinaryOperator is an abstract struct extending the BinaryOperator struct. NumericBinaryOperator is a convience struct that attaches to EvaluateAndCompare function that is used by structs implementing the Node interface.
func (NumericBinaryOperator) EvaluateAndCompare ¶
func (nbo NumericBinaryOperator) EvaluateAndCompare(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, int, error)
EvaluateAndCompare returns the value of the node given the Context ctx, and error if any. If the left value and right value are mathematically equal, returns 0. If the left value is less than the right value, returns -1. if the left value is greater than the right value, returns 1.
type Or ¶
type Or struct {
*BinaryOperator
}
Or is a BinaryOperator which represents the logical boolean OR operation of left and right values.
func (Or) Compile ¶
Compile returns a compiled version of this node. If the left value and right value are both compiled as Literals, then returns the logical boolean AND operation of the left and right value. Otherwise, returns a clone.
type Pipe ¶
type Pipe struct {
*BinaryOperator
}
Pipe is a BinaryOperator which represents the "|" pipe operation of left and right values.
func (Pipe) Compile ¶
Compile returns a compiled version of this node. If the left value and right value are both compiled as Literals, then returns the logical boolean AND operation of the left and right value. Otherwise, returns a clone.
type Pipeline ¶
type Pipeline struct {
Nodes []Node
}
Pipeline is a Node representing a pipeline of nodes where the output of each node is used as the input for the next.
func (Pipeline) Attributes ¶
func (Pipeline) Compile ¶
Compile returns a compiled version of this node. If all the values of an Set are literals, returns a single Literal with the corresponding array as its value. Otherwise returns the original node..
type Print ¶
type Print struct {
*UnaryOperator
}
Print is a UnaryOperator that prints a value to stdout
func (Print) Compile ¶
Compile returns a compiled version of this node. If the the child Node is compiled as a boolean Literal, then returns an inverse Literal Node. Otherwise returns a clone of this node.
func (Print) Evaluate ¶
func (p Print) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
Evaluate evaluates this node within a context and returns the bool result, and error if any.
type Set ¶
type Set struct {
Nodes []Node
}
Set is a Node representing a set of values, which can be either a Literal or Attribute.
func (Set) Attributes ¶
func (Set) Compile ¶
Compile returns a compiled version of this node. If all the values of an Set are literals, returns a single Literal with the corresponding Set/slice as its value. Otherwise returns the original node..
type StringSet ¶
type StringSet map[string]struct{}
StringSet is a logical set of string values using a map[string]struct{} backend. The use of a string -> empty struct backend provides a higher write performance versus a slice backend.
func (StringSet) Intersection ¶
func (StringSet) Intersects ¶
type TemporalBinaryOperator ¶
type TemporalBinaryOperator struct {
*BinaryOperator // Extends the BinaryOperator struct
}
TemporalBinaryOperator is an abstract struct NumericBinaryOperator is a convience struct that attaches to EvaluateAndCompare function that is used by structs implementing the Node interface.
func (TemporalBinaryOperator) EvaluateAndCompare ¶
func (tbo TemporalBinaryOperator) EvaluateAndCompare(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, int, error)
EvaluateAndCompare returns the value of the node given the Context ctx, and error if any. If the left value and right value are at the same time, returns 0. If the left value is before the right value, returns -1. if the left value is after the right value, returns 1.
type TernaryOperator ¶
TernaryOperator is a DFL Node that represents the ternary operator of a condition, true value, and false value.
func (TernaryOperator) Attributes ¶
func (to TernaryOperator) Attributes() []string
Attributes returns a slice of all attributes used in the evaluation of this node, including a children nodes. Attributes de-duplicates values from the condition, true, and false nodes using a set.
func (TernaryOperator) Compile ¶
func (to TernaryOperator) Compile() Node
func (TernaryOperator) Dfl ¶
func (to TernaryOperator) Dfl(quotes []string, pretty bool, tabs int) string
func (TernaryOperator) Evaluate ¶
func (to TernaryOperator) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
func (TernaryOperator) Map ¶
func (to TernaryOperator) Map() map[string]interface{}
func (TernaryOperator) Variables ¶
func (to TernaryOperator) Variables() []string
Variables returns a slice of all variables used in the evaluation of this node, including a children nodes. Variables de-duplicates values from the condition, true, and false nodes using a set.
type TestCase ¶
type TestCase struct { Expression string // the DFL expression Context interface{} // the Context to use for evaluation Result interface{} // The result of the evaluation }
TestCase is a struct containing the variables for a unit test of expression evaluation.
func NewTestCase ¶
NewTestCase returns a new TestCase
type UnaryOperator ¶
type UnaryOperator struct {
Node Node
}
UnaryOperator is an abstract Node the represents an operator with only 1 operand. THe only implementing struct is the "Not" struct.
func (UnaryOperator) Attributes ¶
func (uo UnaryOperator) Attributes() []string
Attributes returns the context attributes used by the child node, if any.
func (UnaryOperator) Variables ¶
func (uo UnaryOperator) Variables() []string
Variables returns the variables used by the child node, if any.
type Variable ¶
type Variable struct {
Name string
}
Variable is a Node representing the value of a temporary variable. Variables start with a "#" and follow with the name or full path into the object if multiple levels deep. For example, #a and #a.b.c.d. You can also use a null-safe operator, e.g., #a?.b?.c?.d
func (Variable) Attributes ¶
type Within ¶
type Within struct {
*BinaryOperator
}
Within is a BinaryOperator that represents that the left value is between
func (Within) Compile ¶
Compile returns a compiled version of this node. If the left and right values are both compiled as literals, then returns the compiled Literal with that value set. Otherwise returns a clone of this node.
func (Within) Evaluate ¶
func (w Within) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)
Evaluate returns the value of this node given Context ctx, and an error if any.
type Xor ¶
type Xor struct {
*BinaryOperator // Extends the BinaryOperator struct
}
Xor is a BinaryOperator which represents the logical boolean XOR operation of left and right values.
func (Xor) Compile ¶
Compile returns a compiled version of this node. If the left value and right value are both compiled as Literals, then returns the logical boolean XOR operation of the left and right value. Otherwise, returns a clone.
Source Files
¶
- Add.go
- After.go
- And.go
- Array.go
- Assign.go
- AssignAdd.go
- AssignMultiply.go
- AssignSubtract.go
- AttachLeft.go
- Attribute.go
- Before.go
- BinaryOperator.go
- Coalesce.go
- CompareNumbers.go
- CompareStrings.go
- CompareTimes.go
- Concat.go
- Context.go
- Dictionary.go
- Divide.go
- DivideNumbers.go
- Equal.go
- ErrParseTernary.go
- ErrorEvaluate.go
- EscapeString.go
- EvaluateArray.go
- EvaluateBool.go
- EvaluateFloat64.go
- EvaluateInt.go
- EvaluateMap.go
- EvaluateString.go
- Extract.go
- FormatList.go
- FormatNodes.go
- FormatSql.go
- Function.go
- FunctionMap.go
- GreaterThan.go
- GreaterThanOrEqual.go
- IIn.go
- ILike.go
- In.go
- LessThan.go
- LessThanOrEqual.go
- Like.go
- Literal.go
- MultiOperator.go
- Multiply.go
- MustParseCompile.go
- MustParseCompileEvaluate.go
- Node.go
- Not.go
- NotEqual.go
- Null.go
- NumericBinaryOperator.go
- Or.go
- Parse.go
- ParseAndCompileExpressions.go
- ParseArray.go
- ParseAttribute.go
- ParseCompile.go
- ParseCompileEvaluate.go
- ParseCompileEvaluateInt.go
- ParseCompileEvaluateMap.go
- ParseCompileEvaluateString.go
- ParseFunction.go
- ParseKeyValue.go
- ParseList.go
- ParseListOrKeyValue.go
- ParseLiteral.go
- ParseSetOrDictionary.go
- ParseSub.go
- ParseVariable.go
- Pipe.go
- Pipeline.go
- Print.go
- Reader.go
- RemoveComments.go
- Set.go
- StringSet.go
- Subtract.go
- TemporalBinaryOperator.go
- TernaryOperator.go
- TestCase.go
- TryConvertArray.go
- TryConvertMap.go
- TryConvertString.go
- TryFormatLiteral.go
- UnaryOperator.go
- UnescapeString.go
- Variable.go
- Version.go
- Within.go
- WithinRange.go
- Xor.go
- dfl.go
- functions.go
- reflect.go