expr

package
v0.0.0-...-261b5b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2016 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Expression structures, ie the `a = b` type expression syntax including parser, node types, boolean logic check, functions.

Package expr is a generated protocol buffer package.

It is generated from these files:
	node.proto

It has these top-level messages:
	NodePb
	BinaryNodePb
	UnaryNodePb
	FuncNodePb
	TriNodePb
	ArrayNodePb
	StringNodePb
	IdentityNodePb
	NumberNodePb
	ValueNodePb

Index

Constants

This section is empty.

Variables

View Source
var (

	// Standard errors
	ErrNotSupported   = fmt.Errorf("qlbridge Not supported")
	ErrNotImplemented = fmt.Errorf("qlbridge Not implemented")
	ErrUnknownCommand = fmt.Errorf("qlbridge Unknown Command")
	ErrInternalError  = fmt.Errorf("qlbridge Internal Error")
)
View Source
var (
	ErrInvalidLengthNode = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowNode   = fmt.Errorf("proto: integer overflow")
)

We have a default Dialect, which is the "Language" or rule-set of ql

Functions

func AggFuncAdd

func AggFuncAdd(name string, fn interface{})

AggFuncAdd Adding Aggregate functions which are special functions

that perform aggregation operations

func FindAllIdentityField

func FindAllIdentityField(node Node) []string

Recursively descend down a node looking for all Identity Fields

min(year)                 == {year}
eq(min(item), max(month)) == {item, month}

func FindIdentityField

func FindIdentityField(node Node) string

Recursively descend down a node looking for first Identity Field

min(year)                 == year
eq(min(item), max(month)) == item

func FindIdentityName

func FindIdentityName(depth int, node Node, prefix string) string

Recursively descend down a node looking for first Identity Field

and combine with outermost expression to create an alias

  min(year)                 == min_year
  eq(min(year), max(month)) == eq_year

func FuncAdd

func FuncAdd(name string, fn interface{})

FuncAdd Global add Functions to the VM func registry occurs here.

Functions have the following pseudo interface.

    1.  They must have expr.ContextReader as first argument
    2.  They must accept 1 OR variadic number of value.Value arguments
    3.  Return must be a value.Value, or anything that implements value Interface
         and bool

    func(ctx expr.ContextReader, value.Value...) (value.Value, bool) {
        // function
    }
    func(ctx expr.ContextReader, value.Value...) (value.StringValue, bool) {
        // function
    }
    func(ctx expr.ContextReader, value.Value, value.Value) (value.NumberValue, bool) {
        // function
    }

func FuncsGet

func FuncsGet() map[string]Func

FuncsGet get the global func registry

func HasDateMath

func HasDateMath(node Node) bool

Determine if this expression node uses datemath (ie, "now-4h") - only works on right-hand of equation - doesn't work on args of a function

func IdentityEscape

func IdentityEscape(quote rune, ident string) string

func IdentityMaybeQuote

func IdentityMaybeQuote(quote byte, ident string) string

Quote an identity if need be (has illegal characters or spaces)

func IdentityMaybeQuoteStrict

func IdentityMaybeQuoteStrict(quote byte, ident string) string

Quote an identity if need be (has illegal characters or spaces)

First character MUST be alpha (not numeric or any other character)

func IsAgg

func IsAgg(name string) bool

IsAgg is this a aggregate function?

func LeftRight

func LeftRight(val string) (string, string, bool)

Return left, right values if is of form `table.column` or `schema`.`table` also return true/false for if it even has left/right

func NodesEqual

func NodesEqual(n1, n2 Node) bool

func ValueArray

func ValueArray(pg TokenPager) (value.Value, error)

ValueArray

IN ("a","b","c")
["a","b","c"]

func ValueTypeFromNode

func ValueTypeFromNode(n Node) value.ValueType

Infer Value type from Node

Types

type ArrayNode

type ArrayNode struct {
	Args []Node
	// contains filtered or unexported fields
}

Array Node for holding multiple similar elements

arg0 IN (arg1,arg2.....)
5 in (1,2,3,4)

func NewArrayNode

func NewArrayNode() *ArrayNode

Create an array of Nodes which is a valid node type for boolean IN operator

func NewArrayNodeArgs

func NewArrayNodeArgs(args []Node) *ArrayNode

func (*ArrayNode) Append

func (m *ArrayNode) Append(n Node)

func (*ArrayNode) Check

func (m *ArrayNode) Check() error

func (*ArrayNode) Equal

func (m *ArrayNode) Equal(n Node) bool

func (*ArrayNode) FingerPrint

func (m *ArrayNode) FingerPrint(r rune) string

func (*ArrayNode) FromPB

func (m *ArrayNode) FromPB(n *NodePb) Node

func (*ArrayNode) String

func (m *ArrayNode) String() string

func (*ArrayNode) ToPB

func (m *ArrayNode) ToPB() *NodePb

func (*ArrayNode) Type

func (m *ArrayNode) Type() reflect.Value

type ArrayNodePb

type ArrayNodePb struct {
	Wrap             *int32   `protobuf:"varint,1,req,name=wrap" json:"wrap,omitempty"`
	Args             []NodePb `protobuf:"bytes,3,rep,name=args" json:"args"`
	XXX_unrecognized []byte   `json:"-"`
}

Array Node

func (*ArrayNodePb) Marshal

func (m *ArrayNodePb) Marshal() (data []byte, err error)

func (*ArrayNodePb) MarshalTo

func (m *ArrayNodePb) MarshalTo(data []byte) (int, error)

func (*ArrayNodePb) ProtoMessage

func (*ArrayNodePb) ProtoMessage()

func (*ArrayNodePb) Reset

func (m *ArrayNodePb) Reset()

func (*ArrayNodePb) Size

func (m *ArrayNodePb) Size() (n int)

func (*ArrayNodePb) String

func (m *ArrayNodePb) String() string

func (*ArrayNodePb) Unmarshal

func (m *ArrayNodePb) Unmarshal(data []byte) error

type BinaryNode

type BinaryNode struct {
	Paren    bool
	Args     []Node
	Operator lex.Token
}

Binary node is x op y, two nodes (left, right) and an operator operators can be a variety of:

+, -, *, %, /, LIKE, CONTAINS, INTERSECTS

Also, parenthesis may wrap these

func NewBinaryNode

func NewBinaryNode(operator lex.Token, lhArg, rhArg Node) *BinaryNode

Create a Binary node

 @operator = * + - %/ / && || = ==
 @operator =  and, or, "is not"
@lhArg, rhArg the left, right side of binary

func (*BinaryNode) Check

func (m *BinaryNode) Check() error

func (*BinaryNode) Equal

func (m *BinaryNode) Equal(n Node) bool

func (*BinaryNode) FingerPrint

func (m *BinaryNode) FingerPrint(r rune) string

func (*BinaryNode) FromPB

func (m *BinaryNode) FromPB(n *NodePb) Node

func (*BinaryNode) String

func (m *BinaryNode) String() string

func (*BinaryNode) StringNegate

func (m *BinaryNode) StringNegate() string

func (*BinaryNode) ToPB

func (m *BinaryNode) ToPB() *NodePb

func (*BinaryNode) Type

func (m *BinaryNode) Type() reflect.Value

type BinaryNodePb

type BinaryNodePb struct {
	Op               int32    `protobuf:"varint,1,req,name=op" json:"op"`
	Paren            bool     `protobuf:"varint,2,opt,name=paren" json:"paren"`
	Args             []NodePb `protobuf:"bytes,3,rep,name=args" json:"args"`
	XXX_unrecognized []byte   `json:"-"`
}

Binary Node, two child args

func (*BinaryNodePb) Marshal

func (m *BinaryNodePb) Marshal() (data []byte, err error)

func (*BinaryNodePb) MarshalTo

func (m *BinaryNodePb) MarshalTo(data []byte) (int, error)

func (*BinaryNodePb) ProtoMessage

func (*BinaryNodePb) ProtoMessage()

func (*BinaryNodePb) Reset

func (m *BinaryNodePb) Reset()

func (*BinaryNodePb) Size

func (m *BinaryNodePb) Size() (n int)

func (*BinaryNodePb) String

func (m *BinaryNodePb) String() string

func (*BinaryNodePb) Unmarshal

func (m *BinaryNodePb) Unmarshal(data []byte) error

type ContextReadWriter

type ContextReadWriter interface {
	ContextReader
	ContextWriter
}

type ContextReader

type ContextReader interface {
	Get(key string) (value.Value, bool)
	Row() map[string]value.Value
	Ts() time.Time
}

Context Reader is a key-value interface to read the context of message/row

using a  Get("key") interface.  Used by vm to evaluate messages

type ContextWriter

type ContextWriter interface {
	Put(col SchemaInfo, readCtx ContextReader, v value.Value) error
	Delete(row map[string]value.Value) error
}

For evaluation storage

vm writes results to this after evaluation

type EvalContext

type EvalContext interface {
	ContextReader
}

Eval context, used to contain info for usage/lookup at runtime evaluation

type Func

type Func struct {
	Name      string
	Aggregate bool // is this aggregate func?
	// The arguments we expect
	Args            []reflect.Value
	VariadicArgs    bool
	Return          reflect.Value
	ReturnValueType value.ValueType
	// The actual Go Function
	F reflect.Value
}

Describes a function which wraps and allows native go functions

to be called (via reflection) via scripting

type FuncNode

type FuncNode struct {
	Name    string // Name of func
	F       Func   // The actual function that this AST maps to
	Missing bool
	Args    []Node // Arguments are them-selves nodes
}

FuncNode holds a Func, which desribes a go Function as well as fulfilling the Pos, String() etc for a Node

interfaces: Node

func NewFuncNode

func NewFuncNode(name string, f Func) *FuncNode

func (*FuncNode) Check

func (c *FuncNode) Check() error

func (*FuncNode) Equal

func (m *FuncNode) Equal(n Node) bool

func (*FuncNode) FingerPrint

func (c *FuncNode) FingerPrint(r rune) string

func (*FuncNode) FromPB

func (m *FuncNode) FromPB(n *NodePb) Node

func (*FuncNode) String

func (c *FuncNode) String() string

func (*FuncNode) ToPB

func (m *FuncNode) ToPB() *NodePb

func (*FuncNode) Type

func (f *FuncNode) Type() reflect.Value

type FuncNodePb

type FuncNodePb struct {
	Name             string   `protobuf:"bytes,1,req,name=name" json:"name"`
	Args             []NodePb `protobuf:"bytes,2,rep,name=args" json:"args"`
	XXX_unrecognized []byte   `json:"-"`
}

Func Node, args are children

func (*FuncNodePb) Marshal

func (m *FuncNodePb) Marshal() (data []byte, err error)

func (*FuncNodePb) MarshalTo

func (m *FuncNodePb) MarshalTo(data []byte) (int, error)

func (*FuncNodePb) ProtoMessage

func (*FuncNodePb) ProtoMessage()

func (*FuncNodePb) Reset

func (m *FuncNodePb) Reset()

func (*FuncNodePb) Size

func (m *FuncNodePb) Size() (n int)

func (*FuncNodePb) String

func (m *FuncNodePb) String() string

func (*FuncNodePb) Unmarshal

func (m *FuncNodePb) Unmarshal(data []byte) error

type FuncRegistry

type FuncRegistry struct {
	// contains filtered or unexported fields
}

func NewFuncRegistry

func NewFuncRegistry() *FuncRegistry

func (*FuncRegistry) Add

func (m *FuncRegistry) Add(name string, fn interface{})

func (*FuncRegistry) FuncGet

func (m *FuncRegistry) FuncGet(name string) (Func, bool)

type FuncResolver

type FuncResolver interface {
	FuncGet(name string) (Func, bool)
}

FuncResolver is a function resolution service that allows

local/namespaced function resolution

type IdentityNode

type IdentityNode struct {
	Quote byte
	Text  string
	// contains filtered or unexported fields
}

IdentityNode will look up a value out of a env bag

also identities of sql objects (tables, columns, etc)
we often need to rewrite these as in sql it is `table.column`

func NewIdentityNode

func NewIdentityNode(tok *lex.Token) *IdentityNode

func NewIdentityNodeVal

func NewIdentityNodeVal(val string) *IdentityNode

func (*IdentityNode) Bool

func (m *IdentityNode) Bool() bool

func (*IdentityNode) Check

func (m *IdentityNode) Check() error

func (*IdentityNode) Equal

func (m *IdentityNode) Equal(n Node) bool

func (*IdentityNode) FingerPrint

func (m *IdentityNode) FingerPrint(r rune) string

func (*IdentityNode) FromPB

func (m *IdentityNode) FromPB(n *NodePb) Node

func (*IdentityNode) IsBooleanIdentity

func (m *IdentityNode) IsBooleanIdentity() bool

func (*IdentityNode) LeftRight

func (m *IdentityNode) LeftRight() (string, string, bool)

Return left, right values if is of form `table.column` or `schema`.`table` and also return true/false for if it even has left & right syntax

func (*IdentityNode) String

func (m *IdentityNode) String() string

func (*IdentityNode) ToPB

func (m *IdentityNode) ToPB() *NodePb

func (*IdentityNode) Type

func (m *IdentityNode) Type() reflect.Value

type IdentityNodePb

type IdentityNodePb struct {
	Quote            *int32 `protobuf:"varint,1,opt,name=quote" json:"quote,omitempty"`
	Text             string `protobuf:"bytes,3,opt,name=text" json:"text"`
	XXX_unrecognized []byte `json:"-"`
}

Identity

func (*IdentityNodePb) Marshal

func (m *IdentityNodePb) Marshal() (data []byte, err error)

func (*IdentityNodePb) MarshalTo

func (m *IdentityNodePb) MarshalTo(data []byte) (int, error)

func (*IdentityNodePb) ProtoMessage

func (*IdentityNodePb) ProtoMessage()

func (*IdentityNodePb) Reset

func (m *IdentityNodePb) Reset()

func (*IdentityNodePb) Size

func (m *IdentityNodePb) Size() (n int)

func (*IdentityNodePb) String

func (m *IdentityNodePb) String() string

func (*IdentityNodePb) Unmarshal

func (m *IdentityNodePb) Unmarshal(data []byte) error

type LexTokenPager

type LexTokenPager struct {
	// contains filtered or unexported fields
}

TokenPager is responsible for determining end of current tree (column, etc)

func NewLexTokenPager

func NewLexTokenPager(lex *lex.Lexer) *LexTokenPager

func (*LexTokenPager) Backup

func (m *LexTokenPager) Backup()

backup backs the input stream up one token.

func (*LexTokenPager) ClauseEnd

func (m *LexTokenPager) ClauseEnd() bool

ClauseEnd are we at end of clause

func (*LexTokenPager) Cur

func (m *LexTokenPager) Cur() lex.Token

Returns the current token, does not advance

func (*LexTokenPager) IsEnd

func (m *LexTokenPager) IsEnd() bool

IsEnd determines if pager is at end of statement

func (*LexTokenPager) Lexer

func (m *LexTokenPager) Lexer() *lex.Lexer

Lexer get the underlying lexer

func (*LexTokenPager) Next

func (m *LexTokenPager) Next() lex.Token

Next returns the current token and advances cursor to next one

func (*LexTokenPager) Peek

func (m *LexTokenPager) Peek() lex.Token

Peek returns but does not consume the next token.

type NegateableNode

type NegateableNode interface {
	StringNegate() string
}

A negateable node requires a special type of String() function due to an enclosing urnary NOT being inserted into middle of string syntax

<expression> [NOT] IN ("a","b")
<expression> [NOT] BETWEEN <expression> AND <expression>
<expression> [NOT] LIKE <expression>
<expression> [NOT] CONTAINS <expression>
<expression> [NOT] INTERSECTS ("a", "b")

type Node

type Node interface {
	// string representation of Node parseable back to itself
	String() string

	// string representation of Node but with values replaced by @rune (`?` generally)
	//  used to allow statements to be deterministically cached/prepared even without
	//  usage of keyword prepared
	FingerPrint(r rune) string

	// performs type and syntax checking for itself and sub-nodes, evaluates
	// validity of the expression/node in advance of evaluation
	Check() error

	// Protobuf helpers that convert to serializeable format and marshall
	ToPB() *NodePb
	FromPB(*NodePb) Node

	// for testing purposes
	Equal(Node) bool
}

A Node is an element in the expression tree, implemented by different types (binary, urnary, func, identity, etc)

  • qlbridge does not currently implement statements (if, for, switch, etc) just expressions, and operators

func NodeFromNodePb

func NodeFromNodePb(n *NodePb) Node

func NodeFromPb

func NodeFromPb(pb []byte) (Node, error)

Create a node from pb

func NodesFromNodesPb

func NodesFromNodesPb(pb []NodePb) []Node

func NodesFromNodesPbPtr

func NodesFromNodesPbPtr(pb []*NodePb) []Node

type NodePb

type NodePb struct {
	Bn               *BinaryNodePb   `protobuf:"bytes,1,opt,name=bn" json:"bn,omitempty"`
	Un               *UnaryNodePb    `protobuf:"bytes,2,opt,name=un" json:"un,omitempty"`
	Fn               *FuncNodePb     `protobuf:"bytes,3,opt,name=fn" json:"fn,omitempty"`
	Tn               *TriNodePb      `protobuf:"bytes,4,opt,name=tn" json:"tn,omitempty"`
	An               *ArrayNodePb    `protobuf:"bytes,5,opt,name=an" json:"an,omitempty"`
	Nn               *NumberNodePb   `protobuf:"bytes,10,opt,name=nn" json:"nn,omitempty"`
	Vn               *ValueNodePb    `protobuf:"bytes,11,opt,name=vn" json:"vn,omitempty"`
	In               *IdentityNodePb `protobuf:"bytes,12,opt,name=in" json:"in,omitempty"`
	Sn               *StringNodePb   `protobuf:"bytes,13,opt,name=sn" json:"sn,omitempty"`
	XXX_unrecognized []byte          `json:"-"`
}

The generic Node, must be exactly one of these types

func NodesPbFromNodes

func NodesPbFromNodes(nodes []Node) []*NodePb

func (*NodePb) Marshal

func (m *NodePb) Marshal() (data []byte, err error)

func (*NodePb) MarshalTo

func (m *NodePb) MarshalTo(data []byte) (int, error)

func (*NodePb) ProtoMessage

func (*NodePb) ProtoMessage()

func (*NodePb) Reset

func (m *NodePb) Reset()

func (*NodePb) Size

func (m *NodePb) Size() (n int)

func (*NodePb) String

func (m *NodePb) String() string

func (*NodePb) Unmarshal

func (m *NodePb) Unmarshal(data []byte) error

type NodeValueType

type NodeValueType interface {
	// describes the enclosed value type
	Type() reflect.Value
}

Node that has a Type Value, similar to a literal, but can

contain value's such as []string, etc

type NullNode

type NullNode struct{}

func NewNull

func NewNull(operator lex.Token) *NullNode

func (*NullNode) Check

func (n *NullNode) Check() error

func (*NullNode) Equal

func (m *NullNode) Equal(n Node) bool

func (*NullNode) FingerPrint

func (m *NullNode) FingerPrint(r rune) string

func (*NullNode) FromPB

func (m *NullNode) FromPB(n *NodePb) Node

func (*NullNode) String

func (m *NullNode) String() string

func (*NullNode) ToPB

func (m *NullNode) ToPB() *NodePb

func (*NullNode) Type

func (m *NullNode) Type() reflect.Value

type NumberNode

type NumberNode struct {
	IsInt   bool    // Number has an integer value.
	IsFloat bool    // Number has a floating-point value.
	Int64   int64   // The integer value.
	Float64 float64 // The floating-point value.
	Text    string  // The original textual representation from the input.
}

NumberNode holds a number: signed or unsigned integer or float. The value is parsed and stored under all the types that can represent the value. This simulates in a small amount of code the behavior of Go's ideal constants.

func NewNumber

func NewNumber(fv float64) (*NumberNode, error)

func NewNumberStr

func NewNumberStr(text string) (*NumberNode, error)

NewNumberStr is a little weird in that this Node accepts string @text and uses go to parse into Int, AND Float.

func (*NumberNode) Check

func (n *NumberNode) Check() error

func (*NumberNode) Equal

func (m *NumberNode) Equal(n Node) bool

func (*NumberNode) FingerPrint

func (n *NumberNode) FingerPrint(r rune) string

func (*NumberNode) FromPB

func (m *NumberNode) FromPB(n *NodePb) Node

func (*NumberNode) String

func (n *NumberNode) String() string

func (*NumberNode) ToPB

func (m *NumberNode) ToPB() *NodePb

func (*NumberNode) Type

func (n *NumberNode) Type() reflect.Value

type NumberNodePb

type NumberNodePb struct {
	Isint            bool    `protobuf:"varint,1,opt,name=isint" json:"isint"`
	Isfloat          bool    `protobuf:"varint,2,opt,name=isfloat" json:"isfloat"`
	Iv               int64   `protobuf:"varint,3,req,name=iv" json:"iv"`
	Fv               float64 `protobuf:"fixed64,4,req,name=fv" json:"fv"`
	Text             string  `protobuf:"bytes,5,req,name=text" json:"text"`
	XXX_unrecognized []byte  `json:"-"`
}

Number Node

func (*NumberNodePb) Marshal

func (m *NumberNodePb) Marshal() (data []byte, err error)

func (*NumberNodePb) MarshalTo

func (m *NumberNodePb) MarshalTo(data []byte) (int, error)

func (*NumberNodePb) ProtoMessage

func (*NumberNodePb) ProtoMessage()

func (*NumberNodePb) Reset

func (m *NumberNodePb) Reset()

func (*NumberNodePb) Size

func (m *NumberNodePb) Size() (n int)

func (*NumberNodePb) String

func (m *NumberNodePb) String() string

func (*NumberNodePb) Unmarshal

func (m *NumberNodePb) Unmarshal(data []byte) error

type RowWriter

type RowWriter interface {
	Commit(rowInfo []SchemaInfo, row RowWriter) error
	Put(col SchemaInfo, readCtx ContextReader, v value.Value) error
}

for commiting row ops (insert, update)

type SchemaInfo

type SchemaInfo interface {
	Key() string
}

SchemaInfo is interface for a Column type

type SchemaInfoString

type SchemaInfoString string

SchemaInfoString implements schemaInfo Key()

func (SchemaInfoString) Key

func (m SchemaInfoString) Key() string

type StringNode

type StringNode struct {
	Text string
	// contains filtered or unexported fields
}

StringNode holds a value literal, quotes not included

func NewStringNoQuoteNode

func NewStringNoQuoteNode(text string) *StringNode

func NewStringNode

func NewStringNode(text string) *StringNode

func (*StringNode) Check

func (m *StringNode) Check() error

func (*StringNode) Equal

func (m *StringNode) Equal(n Node) bool

func (*StringNode) FingerPrint

func (n *StringNode) FingerPrint(r rune) string

func (*StringNode) FromPB

func (m *StringNode) FromPB(n *NodePb) Node

func (*StringNode) String

func (m *StringNode) String() string

func (*StringNode) ToPB

func (m *StringNode) ToPB() *NodePb

type StringNodePb

type StringNodePb struct {
	Noquote          *bool  `protobuf:"varint,1,opt,name=noquote" json:"noquote,omitempty"`
	Text             string `protobuf:"bytes,2,opt,name=text" json:"text"`
	XXX_unrecognized []byte `json:"-"`
}

String literal, no children

func (*StringNodePb) Marshal

func (m *StringNodePb) Marshal() (data []byte, err error)

func (*StringNodePb) MarshalTo

func (m *StringNodePb) MarshalTo(data []byte) (int, error)

func (*StringNodePb) ProtoMessage

func (*StringNodePb) ProtoMessage()

func (*StringNodePb) Reset

func (m *StringNodePb) Reset()

func (*StringNodePb) Size

func (m *StringNodePb) Size() (n int)

func (*StringNodePb) String

func (m *StringNodePb) String() string

func (*StringNodePb) Unmarshal

func (m *StringNodePb) Unmarshal(data []byte) error

type TokenPager

type TokenPager interface {
	Peek() lex.Token
	Next() lex.Token
	Cur() lex.Token
	Backup()
	IsEnd() bool
	ClauseEnd() bool
	Lexer() *lex.Lexer
}

TokenPager wraps a Lexer, and implements the Logic to determine what is the end of this particular clause. Lexer's are stateless, while tokenpager implements state ontop of pager and allows forward/back etc

type Tree

type Tree struct {
	Root       Node // top-level root node of the tree
	TokenPager      // pager for grabbing next tokens, backup(), recognizing end
	// contains filtered or unexported fields
}

Tree is the representation of a single parsed expression

func NewTree

func NewTree(pager TokenPager) *Tree

func NewTreeFuncs

func NewTreeFuncs(pager TokenPager, fr FuncResolver) *Tree

func ParseExpression

func ParseExpression(expressionText string) (*Tree, error)

Parse a single Expression, returning a Tree

ParseExpression("5 * toint(item_name)")

func (*Tree) A

func (t *Tree) A(depth int) Node

func (*Tree) ArrayNode

func (t *Tree) ArrayNode(depth int) Node

ArrayNode parses multi-argument array nodes aka: IN (a,b,c).

func (*Tree) BuildTree

func (t *Tree) BuildTree(runCheck bool) (err error)

buildTree take the tokens and recursively build into expression tree node @runCheck Do we want to verify this tree? If being used as VM then yes.

func (*Tree) C

func (t *Tree) C(depth int) Node

func (*Tree) F

func (t *Tree) F(depth int) Node

func (*Tree) Func

func (t *Tree) Func(depth int, funcTok lex.Token) (fn *FuncNode)

func (*Tree) M

func (t *Tree) M(depth int) Node

func (*Tree) O

func (t *Tree) O(depth int) Node

expr:

func (*Tree) P

func (t *Tree) P(depth int) Node

func (*Tree) String

func (t *Tree) String() string

type TriNode

type TriNode struct {
	Args     []Node
	Operator lex.Token
}

Tri Node

ARG1 Between ARG2 AND ARG3

func NewTriNode

func NewTriNode(operator lex.Token, arg1, arg2, arg3 Node) *TriNode

Create a Tri node

@arg1 [NOT] BETWEEN @arg2 AND @arg3

func (*TriNode) Check

func (m *TriNode) Check() error

func (*TriNode) Equal

func (m *TriNode) Equal(n Node) bool

func (*TriNode) FingerPrint

func (m *TriNode) FingerPrint(r rune) string

func (*TriNode) FromPB

func (m *TriNode) FromPB(n *NodePb) Node

func (*TriNode) String

func (m *TriNode) String() string

func (*TriNode) StringNegate

func (m *TriNode) StringNegate() string

func (*TriNode) ToPB

func (m *TriNode) ToPB() *NodePb

func (*TriNode) Type

func (m *TriNode) Type() reflect.Value

type TriNodePb

type TriNodePb struct {
	Op               int32    `protobuf:"varint,1,req,name=op" json:"op"`
	Args             []NodePb `protobuf:"bytes,2,rep,name=args" json:"args"`
	XXX_unrecognized []byte   `json:"-"`
}

Tri Node, may hve children

func (*TriNodePb) Marshal

func (m *TriNodePb) Marshal() (data []byte, err error)

func (*TriNodePb) MarshalTo

func (m *TriNodePb) MarshalTo(data []byte) (int, error)

func (*TriNodePb) ProtoMessage

func (*TriNodePb) ProtoMessage()

func (*TriNodePb) Reset

func (m *TriNodePb) Reset()

func (*TriNodePb) Size

func (m *TriNodePb) Size() (n int)

func (*TriNodePb) String

func (m *TriNodePb) String() string

func (*TriNodePb) Unmarshal

func (m *TriNodePb) Unmarshal(data []byte) error

type UnaryNode

type UnaryNode struct {
	Arg      Node
	Operator lex.Token
}

UnaryNode negates a single node argument

(  not <expression>  |   !<expression> )

 !eq(5,6)
 !true
 !(true OR false)
 !toint(now())

func NewUnary

func NewUnary(operator lex.Token, arg Node) *UnaryNode

Unary nodes

NOT
EXISTS

func (*UnaryNode) Check

func (n *UnaryNode) Check() error

func (*UnaryNode) Equal

func (m *UnaryNode) Equal(n Node) bool

func (*UnaryNode) FingerPrint

func (m *UnaryNode) FingerPrint(r rune) string

func (*UnaryNode) FromPB

func (m *UnaryNode) FromPB(n *NodePb) Node

func (*UnaryNode) String

func (m *UnaryNode) String() string

func (*UnaryNode) ToPB

func (m *UnaryNode) ToPB() *NodePb

func (*UnaryNode) Type

func (m *UnaryNode) Type() reflect.Value

type UnaryNodePb

type UnaryNodePb struct {
	Op               int32  `protobuf:"varint,1,req,name=op" json:"op"`
	Paren            bool   `protobuf:"varint,2,opt,name=paren" json:"paren"`
	Arg              NodePb `protobuf:"bytes,3,req,name=arg" json:"arg"`
	XXX_unrecognized []byte `json:"-"`
}

Unary Node, one child

func (*UnaryNodePb) Marshal

func (m *UnaryNodePb) Marshal() (data []byte, err error)

func (*UnaryNodePb) MarshalTo

func (m *UnaryNodePb) MarshalTo(data []byte) (int, error)

func (*UnaryNodePb) ProtoMessage

func (*UnaryNodePb) ProtoMessage()

func (*UnaryNodePb) Reset

func (m *UnaryNodePb) Reset()

func (*UnaryNodePb) Size

func (m *UnaryNodePb) Size() (n int)

func (*UnaryNodePb) String

func (m *UnaryNodePb) String() string

func (*UnaryNodePb) Unmarshal

func (m *UnaryNodePb) Unmarshal(data []byte) error

type ValueNode

type ValueNode struct {
	Value value.Value
	// contains filtered or unexported fields
}

Value holds a value.Value type

value.Values can be strings, numbers, arrays, objects, etc

func NewValueNode

func NewValueNode(val value.Value) *ValueNode

func (*ValueNode) Check

func (m *ValueNode) Check() error

func (*ValueNode) Equal

func (m *ValueNode) Equal(n Node) bool

func (*ValueNode) FingerPrint

func (n *ValueNode) FingerPrint(r rune) string

func (*ValueNode) FromPB

func (m *ValueNode) FromPB(n *NodePb) Node

func (*ValueNode) String

func (m *ValueNode) String() string

func (*ValueNode) ToPB

func (m *ValueNode) ToPB() *NodePb

func (*ValueNode) Type

func (m *ValueNode) Type() reflect.Value

type ValueNodePb

type ValueNodePb struct {
	Valuetype        int32  `protobuf:"varint,1,req,name=valuetype" json:"valuetype"`
	Value            []byte `protobuf:"bytes,2,req,name=value" json:"value,omitempty"`
	XXX_unrecognized []byte `json:"-"`
}

Value Node

func (*ValueNodePb) Marshal

func (m *ValueNodePb) Marshal() (data []byte, err error)

func (*ValueNodePb) MarshalTo

func (m *ValueNodePb) MarshalTo(data []byte) (int, error)

func (*ValueNodePb) ProtoMessage

func (*ValueNodePb) ProtoMessage()

func (*ValueNodePb) Reset

func (m *ValueNodePb) Reset()

func (*ValueNodePb) Size

func (m *ValueNodePb) Size() (n int)

func (*ValueNodePb) String

func (m *ValueNodePb) String() string

func (*ValueNodePb) Unmarshal

func (m *ValueNodePb) Unmarshal(data []byte) error

Directories

Path Synopsis
Builtin functions injected into expression vm.
Builtin functions injected into expression vm.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL