package parse

Import Path
	text/template/parse (on golang.org and go.dev)

Dependency Relation
	imports 7 packages, and imported by 2 packages

Involved Source Files
	    lex.go
	    node.go
	d-> parse.go

Exported Type Names

type ActionNode (struct) ActionNode holds an action (something bounded by delimiters). Control actions have their own nodes; ActionNode represents simple ones such as field evaluations and parenthesized pipelines. // The line number in the input. Deprecated: Kept for compatibility. NodeType NodeType // The pipeline in the action. Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type BoolNode (struct) BoolNode holds a boolean constant. NodeType NodeType Pos Pos // The value of the boolean constant. (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type BranchNode (struct) BranchNode is the common representation of if, range, and with. // What to execute if the value is empty (nil if absent). // The line number in the input. Deprecated: Kept for compatibility. // What to execute if the value is non-empty. NodeType NodeType // The pipeline to be evaluated. Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type ChainNode (struct) ChainNode holds a term followed by a chain of field accesses (identifier starting with '.'). The names may be chained ('.x.y'). The periods are dropped from each ident. // The identifiers in lexical order. Node Node NodeType NodeType Pos Pos Add adds the named field (which should start with a period) to the end of the chain. (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type CommandNode (struct) CommandNode holds a command (a pipeline inside an evaluating action). // Arguments in lexical order: Identifier, field, or constant. NodeType NodeType Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type DotNode (struct) DotNode holds the special identifier '.'. NodeType NodeType Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string (*T) Type() NodeType *T : Node *T : expvar.Var *T : fmt.Stringer
type FieldNode (struct) FieldNode holds a field (identifier starting with '.'). The names may be chained ('.x.y'). The period is dropped from each ident. // Variable name and fields in lexical order. NodeType NodeType Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type IdentifierNode (struct) IdentifierNode holds an identifier. // The identifier's name. NodeType NodeType Pos Pos (*T) Copy() Node ( T) Position() Pos SetPos sets the position. NewIdentifier is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day? SetTree sets the parent tree for the node. NewIdentifier is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day? (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer func NewIdentifier(ident string) *IdentifierNode func (*IdentifierNode).SetPos(pos Pos) *IdentifierNode func (*IdentifierNode).SetTree(t *Tree) *IdentifierNode
type IfNode (struct) IfNode represents an {{if}} action and its commands. BranchNode BranchNode // What to execute if the value is empty (nil if absent). // The line number in the input. Deprecated: Kept for compatibility. // What to execute if the value is non-empty. BranchNode.NodeType NodeType // The pipeline to be evaluated. BranchNode.Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type ListNode (struct) ListNode holds a sequence of nodes. NodeType NodeType // The element nodes in lexical order. Pos Pos (*T) Copy() Node (*T) CopyList() *ListNode ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer func (*ListNode).CopyList() *ListNode
type NilNode (struct) NilNode holds the special identifier 'nil' representing an untyped nil constant. NodeType NodeType Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string (*T) Type() NodeType *T : Node *T : expvar.Var *T : fmt.Stringer
type Node (interface) 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. Copy does a deep copy of the Node and all its components. To avoid type assertions, some XxxNodes also have specialized CopyXxx methods that return *XxxNode. // byte position of start of node in full original input string ( T) String() string ( T) Type() NodeType *ActionNode *BoolNode *BranchNode *ChainNode *CommandNode *DotNode *FieldNode *IdentifierNode *IfNode *ListNode *NilNode *NumberNode *PipeNode *RangeNode *StringNode *TemplateNode *TextNode *VariableNode *WithNode T : expvar.Var T : fmt.Stringer func (*ActionNode).Copy() Node func (*BoolNode).Copy() Node func (*BranchNode).Copy() Node func (*ChainNode).Copy() Node func (*CommandNode).Copy() Node func (*DotNode).Copy() Node func (*FieldNode).Copy() Node func (*IdentifierNode).Copy() Node func (*IfNode).Copy() Node func (*ListNode).Copy() Node func (*NilNode).Copy() Node func Node.Copy() Node func (*NumberNode).Copy() Node func (*PipeNode).Copy() Node func (*RangeNode).Copy() Node func (*StringNode).Copy() Node func (*TemplateNode).Copy() Node func (*TextNode).Copy() Node func (*VariableNode).Copy() Node func (*WithNode).Copy() Node func IsEmptyTree(n Node) bool func (*Tree).ErrorContext(n Node) (location, context string)
type NodeType int NodeType identifies the type of a parse tree node. Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. func (*DotNode).Type() NodeType func (*NilNode).Type() NodeType func Node.Type() NodeType func NodeType.Type() NodeType const NodeAction const NodeBool const NodeChain const NodeCommand const NodeDot const NodeField const NodeIdentifier const NodeIf const NodeList const NodeNil const NodeNumber const NodePipe const NodeRange const NodeString const NodeTemplate const NodeText const NodeVariable const NodeWith
type NumberNode (struct) 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. // The complex value. // The floating-point value. // The signed integer value. // Number is complex. // Number has a floating-point value. // Number has an integral value. // Number has an unsigned integral value. NodeType NodeType Pos Pos // The original textual representation from the input. // The unsigned integer value. (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type PipeNode (struct) PipeNode holds a pipeline with optional declaration // The commands in lexical order. // Variables in lexical order. // The variables are being assigned, not declared. // The line number in the input. Deprecated: Kept for compatibility. NodeType NodeType Pos Pos (*T) Copy() Node (*T) CopyPipe() *PipeNode ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer func (*PipeNode).CopyPipe() *PipeNode
type Pos int Pos represents a byte position in the original input text from which this template was parsed. ( T) Position() Pos func Node.Position() Pos func Pos.Position() Pos func (*IdentifierNode).SetPos(pos Pos) *IdentifierNode
type RangeNode (struct) RangeNode represents a {{range}} action and its commands. BranchNode BranchNode // What to execute if the value is empty (nil if absent). // The line number in the input. Deprecated: Kept for compatibility. // What to execute if the value is non-empty. BranchNode.NodeType NodeType // The pipeline to be evaluated. BranchNode.Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type StringNode (struct) StringNode holds a string constant. The value has been "unquoted". NodeType NodeType Pos Pos // The original text of the string, with quotes. // The string, after quote processing. (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type TemplateNode (struct) TemplateNode represents a {{template}} action. // The line number in the input. Deprecated: Kept for compatibility. // The name of the template (unquoted). NodeType NodeType // The command to evaluate as dot for the template. Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type TextNode (struct) TextNode holds plain text. NodeType NodeType Pos Pos // The text; may span newlines. (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type Tree (struct) Tree is the representation of a single parsed template. // name of the template represented by the tree. // name of the top-level template during parsing, for error messages. // top-level root of the tree. Copy returns a copy of the Tree. Any parsing state is discarded. ErrorContext returns a textual representation of the location of the node in the input text. The receiver is only used when the node does not have a pointer to the tree inside, which can occur in old code. 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 New(name string, funcs ...map[string]interface{}) *Tree func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (map[string]*Tree, error) func (*Tree).Copy() *Tree func (*Tree).Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]interface{}) (tree *Tree, err error) func (*IdentifierNode).SetTree(t *Tree) *IdentifierNode func (*Tree).Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]interface{}) (tree *Tree, err error) func text/template.(*Template).AddParseTree(name string, tree *Tree) (*template.Template, error) func html/template.(*Template).AddParseTree(name string, tree *Tree) (*template.Template, error)
type VariableNode (struct) VariableNode holds a list of variable names, possibly with chained field accesses. The dollar sign is part of the (first) name. // Variable name and fields in lexical order. NodeType NodeType Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
type WithNode (struct) WithNode represents a {{with}} action and its commands. BranchNode BranchNode // What to execute if the value is empty (nil if absent). // The line number in the input. Deprecated: Kept for compatibility. // What to execute if the value is non-empty. BranchNode.NodeType NodeType // The pipeline to be evaluated. BranchNode.Pos Pos (*T) Copy() Node ( T) Position() Pos (*T) String() string Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes. *T : Node *T : expvar.Var *T : fmt.Stringer
Exported Values
func IsEmptyTree(n Node) bool IsEmptyTree reports whether this tree (node) is empty of everything but space.
func New(name string, funcs ...map[string]interface{}) *Tree New allocates a new parse tree with the given name.
func NewIdentifier(ident string) *IdentifierNode NewIdentifier returns a new IdentifierNode with the given identifier name.
const NodeAction NodeType = 1 // A non-control action such as a field evaluation.
const NodeBool NodeType = 2 // A boolean constant.
const NodeChain NodeType = 3 // A sequence of field accesses.
const NodeCommand NodeType = 4 // An element of a pipeline.
const NodeDot NodeType = 5 // The cursor, dot.
const NodeField NodeType = 8 // A field or method name.
const NodeIdentifier NodeType = 9 // An identifier; always a function name.
const NodeIf NodeType = 10 // An if action.
const NodeList NodeType = 11 // A list of Nodes.
const NodeNil NodeType = 12 // An untyped nil constant.
const NodeNumber NodeType = 13 // A numerical constant.
const NodePipe NodeType = 14 // A pipeline of commands.
const NodeRange NodeType = 15 // A range action.
const NodeString NodeType = 16 // A string constant.
const NodeTemplate NodeType = 17 // A template invocation action.
const NodeText NodeType = 0 // Plain text.
const NodeVariable NodeType = 18 // A $ variable.
const NodeWith NodeType = 19 // A with action.
func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (map[string]*Tree, 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.