parse

package
v0.0.0-...-7afe134 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2014 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

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

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

Types

type BinaryNode

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

BinaryNode holds two arguments and an operator.

func (*BinaryNode) Check

func (b *BinaryNode) Check() 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

type Func

type Func struct {
	Args   []FuncType
	Return FuncType
	F      interface{}
}

type FuncNode

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

FuncNode holds a function invocation.

func (*FuncNode) Check

func (c *FuncNode) Check() error

func (*FuncNode) Return

func (f *FuncNode) Return() FuncType

func (*FuncNode) String

func (c *FuncNode) String() string

func (*FuncNode) StringAST

func (c *FuncNode) StringAST() string

type FuncType

type FuncType int
const (
	TYPE_STRING FuncType = iota
	TYPE_SCALAR
	TYPE_NUMBER
	TYPE_SERIES
)

func (FuncType) String

func (f FuncType) String() string

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() error  // performs type checking for itself and sub-nodes
	Return() FuncType
	// 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

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.
)

func (NodeType) Type

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

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() 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

type Pos

type Pos int

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

func (Pos) Position

func (p Pos) Position() Pos

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() 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

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 New

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

New allocates a new parse tree with the given name.

func Parse

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 (*Tree) A

func (t *Tree) A() Node

func (*Tree) C

func (t *Tree) C() Node

func (*Tree) F

func (t *Tree) F() Node

func (*Tree) Func

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

func (*Tree) M

func (t *Tree) M() Node

func (*Tree) O

func (t *Tree) O() Node

expr:

func (*Tree) P

func (t *Tree) P() Node

func (*Tree) Parse

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

Parse parses the template definition string to construct a representation of the template for execution. If either action delimiter string is empty, the default ("{{" or "}}") is used. Embedded template definitions are added to the treeSet map.

func (*Tree) String

func (t *Tree) String() string

type UnaryNode

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

UnaryNode holds one argument and an operator.

func (*UnaryNode) Check

func (u *UnaryNode) Check() error

func (*UnaryNode) Return

func (u *UnaryNode) Return() FuncType

func (*UnaryNode) String

func (u *UnaryNode) String() string

func (*UnaryNode) StringAST

func (u *UnaryNode) StringAST() string

Jump to

Keyboard shortcuts

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