Documentation ¶
Overview ¶
Package parse builds parse trees for expressions as defined by expr. Clients should use that package to construct expressions rather than this one, which provides shared internal data structures not intended for general use.
Index ¶
- func Walk(n Node, f func(Node))
- type BinaryNode
- type Func
- type FuncNode
- type FuncType
- type Node
- type NodeType
- type NumberNode
- type Pos
- type StringNode
- type Tags
- type Tree
- func (t *Tree) A() Node
- func (t *Tree) C() Node
- func (t *Tree) F() Node
- func (t *Tree) Func() (f *FuncNode)
- func (t *Tree) GetFunction(name string) (v Func, ok bool)
- func (t *Tree) M() Node
- func (t *Tree) O() Node
- func (t *Tree) P() Node
- func (t *Tree) Parse(text string, funcs ...map[string]Func) (err error)
- func (t *Tree) String() string
- type UnaryNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BinaryNode ¶
BinaryNode holds two arguments and an operator.
func (*BinaryNode) Check ¶
func (b *BinaryNode) Check(t *Tree) error
func (*BinaryNode) Return ¶
func (b *BinaryNode) Return() FuncType
func (*BinaryNode) String ¶
func (b *BinaryNode) String() string
func (*BinaryNode) StringAST ¶
func (b *BinaryNode) StringAST() string
func (*BinaryNode) Tags ¶
func (b *BinaryNode) Tags() (Tags, error)
type Node ¶
type Node interface { Type() NodeType String() string StringAST() string Position() Pos // byte position of start of node in full original input string Check(*Tree) error // performs type checking for itself and sub-nodes Return() FuncType Tags() (Tags, error) // contains filtered or unexported methods }
A Node is an element in the parse tree. The interface is trivial. The interface contains an unexported method so that only types local to this package can satisfy it.
type NumberNode ¶
type NumberNode struct { NodeType Pos IsUint bool // Number has an unsigned integral value. IsFloat bool // Number has a floating-point value. Uint64 uint64 // The unsigned 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 (*NumberNode) Check ¶
func (n *NumberNode) Check(*Tree) error
func (*NumberNode) Return ¶
func (n *NumberNode) Return() FuncType
func (*NumberNode) String ¶
func (n *NumberNode) String() string
func (*NumberNode) StringAST ¶
func (n *NumberNode) StringAST() string
func (*NumberNode) Tags ¶
func (n *NumberNode) Tags() (Tags, error)
type Pos ¶
type Pos int
Pos represents a byte position in the original input text from which this template was parsed.
type StringNode ¶
type StringNode struct { NodeType Pos Quoted string // The original text of the string, with quotes. Text string // The string, after quote processing. }
StringNode holds a string constant. The value has been "unquoted".
func (*StringNode) Check ¶
func (s *StringNode) Check(*Tree) error
func (*StringNode) Return ¶
func (s *StringNode) Return() FuncType
func (*StringNode) String ¶
func (s *StringNode) String() string
func (*StringNode) StringAST ¶
func (s *StringNode) StringAST() string
func (*StringNode) Tags ¶
func (s *StringNode) Tags() (Tags, error)
type Tags ¶
type Tags map[string]struct{}
func (Tags) Intersection ¶
Intersection returns Tags common to both tagsets.
type Tree ¶
type Tree struct { Text string // text parsed to create the expression. Root Node // top-level root of the tree, returns a number. // contains filtered or unexported fields }
Tree is the representation of a single parsed expression.
func Parse ¶
Parse returns a Tree, created by parsing the expression described in the argument string. If an error is encountered, parsing stops and an empty Tree is returned with the error.