bosun.org: bosun.org/cmd/bosun/expr/parse Index | Files

package parse

import "bosun.org/cmd/bosun/expr/parse"

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

Package Files

lex.go node.go parse.go

func Walk Uses

func Walk(n Node, f func(Node))

Walk invokes f on n and sub-nodes of n.

type BinaryNode Uses

type BinaryNode struct {
    NodeType
    Pos
    Args     [2]Node
    Operator item
    OpStr    string
}

BinaryNode holds two arguments and an operator.

func (*BinaryNode) Check Uses

func (b *BinaryNode) Check(t *Tree) error

func (*BinaryNode) Return Uses

func (b *BinaryNode) Return() models.FuncType

func (*BinaryNode) String Uses

func (b *BinaryNode) String() string

func (*BinaryNode) StringAST Uses

func (b *BinaryNode) StringAST() string

func (*BinaryNode) Tags Uses

func (b *BinaryNode) Tags() (Tags, error)

type ExprNode Uses

type ExprNode struct {
    NodeType
    Pos
    Text string
    Tree *Tree
}

func (*ExprNode) Check Uses

func (s *ExprNode) Check(*Tree) error

func (*ExprNode) Return Uses

func (s *ExprNode) Return() models.FuncType

func (*ExprNode) String Uses

func (s *ExprNode) String() string

func (*ExprNode) StringAST Uses

func (s *ExprNode) StringAST() string

func (*ExprNode) Tags Uses

func (s *ExprNode) Tags() (Tags, error)

type Func Uses

type Func struct {
    Args          []models.FuncType
    Return        models.FuncType
    Tags          func([]Node) (Tags, error)
    F             interface{}
    VArgs         bool
    VArgsPos      int
    VArgsOmit     bool
    MapFunc       bool // Func is only valid in map expressions
    PrefixEnabled bool
    PrefixKey     bool
    VariantReturn bool
    Check         func(*Tree, *FuncNode) error
}

type FuncNode Uses

type FuncNode struct {
    NodeType
    Pos
    Name   string
    F      *Func
    Args   []Node
    Prefix string
}

FuncNode holds a function invocation.

func (*FuncNode) Check Uses

func (f *FuncNode) Check(t *Tree) error

func (*FuncNode) Return Uses

func (f *FuncNode) Return() models.FuncType

func (*FuncNode) String Uses

func (f *FuncNode) String() string

func (*FuncNode) StringAST Uses

func (f *FuncNode) StringAST() string

func (*FuncNode) Tags Uses

func (f *FuncNode) Tags() (Tags, error)

type Node Uses

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() models.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 NodeType Uses

type NodeType int

NodeType identifies the type of a parse tree node.

const (
    NodeFunc   NodeType = iota // A function call.
    NodeBinary                 // Binary operator: math, logical, compare
    NodeUnary                  // Unary operator: !, -
    NodeString                 // A string constant.
    NodeNumber                 // A numerical constant.
    NodeExpr                   // A sub expression
    NodePrefix                 // A host prefix [""]
)

func (NodeType) Type Uses

func (t NodeType) Type() NodeType

Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes.

type NumberNode Uses

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 Uses

func (n *NumberNode) Check(*Tree) error

func (*NumberNode) Return Uses

func (n *NumberNode) Return() models.FuncType

func (*NumberNode) String Uses

func (n *NumberNode) String() string

func (*NumberNode) StringAST Uses

func (n *NumberNode) StringAST() string

func (*NumberNode) Tags Uses

func (n *NumberNode) Tags() (Tags, error)

type Pos Uses

type Pos int

Pos represents a byte position in the original input text from which this template was parsed.

func (Pos) Position Uses

func (p Pos) Position() Pos

type PrefixNode Uses

type PrefixNode struct {
    NodeType
    Pos
    Arg  Node
    Text string
}

Prefix holds a string constant.

func (*PrefixNode) Check Uses

func (p *PrefixNode) Check(t *Tree) error

func (*PrefixNode) Return Uses

func (p *PrefixNode) Return() models.FuncType

func (*PrefixNode) String Uses

func (p *PrefixNode) String() string

func (*PrefixNode) StringAST Uses

func (p *PrefixNode) StringAST() string

func (*PrefixNode) Tags Uses

func (p *PrefixNode) Tags() (Tags, error)

type StringNode Uses

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 Uses

func (s *StringNode) Check(*Tree) error

func (*StringNode) Return Uses

func (s *StringNode) Return() models.FuncType

func (*StringNode) String Uses

func (s *StringNode) String() string

func (*StringNode) StringAST Uses

func (s *StringNode) StringAST() string

func (*StringNode) Tags Uses

func (s *StringNode) Tags() (Tags, error)

type Tags Uses

type Tags map[string]struct{}

func (Tags) Equal Uses

func (t Tags) Equal(o Tags) bool

func (Tags) Intersection Uses

func (t Tags) Intersection(o Tags) Tags

Intersection returns Tags common to both tagsets.

func (Tags) String Uses

func (t Tags) String() string

func (Tags) Subset Uses

func (t Tags) Subset(o Tags) bool

Subset returns true if o is a subset of t.

type Tree Uses

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 New Uses

func New(funcs ...map[string]Func) *Tree

New allocates a new parse tree with the given name.

func Parse Uses

func Parse(text string, funcs ...map[string]Func) (t *Tree, err error)

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.

func ParseSub Uses

func ParseSub(text string, funcs ...map[string]Func) (t *Tree, err error)

func (*Tree) A Uses

func (t *Tree) A() Node

func (*Tree) C Uses

func (t *Tree) C() Node

func (*Tree) E Uses

func (t *Tree) E() Node

func (*Tree) F Uses

func (t *Tree) F() Node

func (*Tree) Func Uses

func (t *Tree) Func() (f *FuncNode)

func (*Tree) GetFunction Uses

func (t *Tree) GetFunction(name string) (v Func, ok bool)

func (*Tree) M Uses

func (t *Tree) M() Node

func (*Tree) O Uses

func (t *Tree) O() Node

expr:

func (*Tree) P Uses

func (t *Tree) P() Node

func (*Tree) Parse Uses

func (t *Tree) Parse(text string, funcs ...map[string]Func) (err error)

Parse parses the expression definition string to construct a representation of the expression for execution.

func (*Tree) SetFunction Uses

func (t *Tree) SetFunction(name string, F interface{}) error

func (*Tree) String Uses

func (t *Tree) String() string

type UnaryNode Uses

type UnaryNode struct {
    NodeType
    Pos
    Arg      Node
    Operator item
    OpStr    string
}

UnaryNode holds one argument and an operator.

func (*UnaryNode) Check Uses

func (u *UnaryNode) Check(t *Tree) error

func (*UnaryNode) Return Uses

func (u *UnaryNode) Return() models.FuncType

func (*UnaryNode) String Uses

func (u *UnaryNode) String() string

func (*UnaryNode) StringAST Uses

func (u *UnaryNode) StringAST() string

func (*UnaryNode) Tags Uses

func (u *UnaryNode) Tags() (Tags, error)

Package parse imports 8 packages (graph) and is imported by 3 packages. Updated 2019-02-25. Refresh now. Tools for package owners.