Documentation
¶
Overview ¶
Package parse builds parse trees for templates as defined by text/template and html/template. Clients should use those packages to construct templates rather than this one, which provides shared internal data structures not intended for general use.
Index ¶
- func IsEmptyTree(n Node) bool
- func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (treeSet map[string]*Tree, err error)
- type ActionNode
- type BoolNode
- type BranchNode
- type CommandNode
- type DotNode
- type FieldNode
- type IdentifierNode
- type IfNode
- type ListNode
- type Node
- type NodeType
- type NumberNode
- type PipeNode
- type RangeNode
- type StringNode
- type TemplateNode
- type TextNode
- type Tree
- type VariableNode
- type WithNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsEmptyTree ¶
IsEmptyTree reports whether this tree (node) is empty of everything but space.
func Parse ¶
func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (treeSet map[string]*Tree, err error)
Parse returns a map from template name to parse.Tree, created by parsing the templates described in the argument string. The top-level template will be given the specified name. If an error is encountered, parsing stops and an empty map is returned with the error.
Types ¶
type ActionNode ¶
ActionNode holds an action (something bounded by delimiters). Control actions have their own nodes; ActionNode represents simple ones such as field evaluations.
func (*ActionNode) Copy ¶
func (a *ActionNode) Copy() Node
func (*ActionNode) String ¶
func (a *ActionNode) String() string
type BranchNode ¶
BranchNode is the common representation of if, range, and with.
func (*BranchNode) String ¶
func (b *BranchNode) String() string
type CommandNode ¶
CommandNode holds a command (a pipeline inside an evaluating action).
func (*CommandNode) Copy ¶
func (c *CommandNode) Copy() Node
func (*CommandNode) String ¶
func (c *CommandNode) String() string
type DotNode ¶
type DotNode bool
DotNode holds the special identifier '.'. It is represented by a nil pointer.
type FieldNode ¶
FieldNode holds a field (identifier starting with '.'). The names may be chained ('.x.y'). The period is dropped from each ident.
type IdentifierNode ¶
IdentifierNode holds an identifier.
func NewIdentifier ¶
func NewIdentifier(ident string) *IdentifierNode
NewIdentifier returns a new IdentifierNode with the given identifier name.
func (*IdentifierNode) Copy ¶
func (i *IdentifierNode) Copy() Node
func (*IdentifierNode) String ¶
func (i *IdentifierNode) String() string
type IfNode ¶
type IfNode struct {
BranchNode
}
IfNode represents an {{if}} action and its commands.
type NumberNode ¶
type NumberNode struct {
NodeType
IsInt bool
IsUint bool
IsFloat bool
IsComplex bool
Int64 int64
Uint64 uint64
Float64 float64
Complex128 complex128
Text string
}
NumberNode holds a number: signed or unsigned integer, float, or complex. 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) Copy ¶
func (n *NumberNode) Copy() Node
func (*NumberNode) String ¶
func (n *NumberNode) String() string
type PipeNode ¶
type PipeNode struct {
NodeType
Line int
Decl []*VariableNode
Cmds []*CommandNode
}
PipeNode holds a pipeline with optional declaration
type RangeNode ¶
type RangeNode struct {
BranchNode
}
RangeNode represents a {{range}} action and its commands.
type StringNode ¶
StringNode holds a string constant. The value has been "unquoted".
func (*StringNode) Copy ¶
func (s *StringNode) Copy() Node
func (*StringNode) String ¶
func (s *StringNode) String() string
type TemplateNode ¶
TemplateNode represents a {{template}} action.
func (*TemplateNode) Copy ¶
func (t *TemplateNode) Copy() Node
func (*TemplateNode) String ¶
func (t *TemplateNode) String() string
type Tree ¶
Tree is the representation of a single parsed template.
func (*Tree) Parse ¶
func (t *Tree) Parse(s, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]interface{}) (tree *Tree, 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.
type VariableNode ¶
VariableNode holds a list of variable names. The dollar sign is part of the name.
func (*VariableNode) Copy ¶
func (v *VariableNode) Copy() Node
func (*VariableNode) String ¶
func (v *VariableNode) String() string