package parse

import "text/template/parse"

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.

lex.go node.go parse.go

func IsEmptyTree

IsEmptyTree reports whether this tree (node) is empty of everything but space.

func Parse

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.

type ActionNode

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.

func (*ActionNode) Copy

func (*ActionNode) String

type BoolNode

BoolNode holds a boolean constant.

func (*BoolNode) Copy

func (*BoolNode) String

type BranchNode

BranchNode is the common representation of if, range, and with.

func (*BranchNode) Copy

func (*BranchNode) String

type ChainNode

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.

func (*ChainNode) Add

Add adds the named field (which should start with a period) to the end of the chain.

func (*ChainNode) Copy

func (*ChainNode) String

type CommandNode

CommandNode holds a command (a pipeline inside an evaluating action).

func (*CommandNode) Copy

func (*CommandNode) String

type DotNode

DotNode holds the special identifier '.'.

func (*DotNode) Copy

func (*DotNode) String

func (*DotNode) Type

type FieldNode

FieldNode holds a field (identifier starting with '.'). The names may be chained ('.x.y'). The period is dropped from each ident.

func (*FieldNode) Copy

func (*FieldNode) String

type IdentifierNode

IdentifierNode holds an identifier.

func NewIdentifier

NewIdentifier returns a new IdentifierNode with the given identifier name.

func (*IdentifierNode) Copy

func (*IdentifierNode) SetPos

SetPos sets the position. NewIdentifier is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day?

func (*IdentifierNode) SetTree

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?

func (*IdentifierNode) String

type IfNode

IfNode represents an {{if}} action and its commands.

func (*IfNode) Copy

type ListNode

ListNode holds a sequence of nodes.

func (*ListNode) Copy

func (*ListNode) CopyList

func (*ListNode) String

type NilNode

NilNode holds the special identifier 'nil' representing an untyped nil constant.

func (*NilNode) Copy

func (*NilNode) String

func (*NilNode) Type

type Node

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

NodeType identifies the type of a parse tree node.

func (NodeType) Type

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

type NumberNode

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 (*NumberNode) String

type PipeNode

PipeNode holds a pipeline with optional declaration

func (*PipeNode) Copy

func (*PipeNode) CopyPipe

func (*PipeNode) String

type Pos

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

func (Pos) Position

type RangeNode

RangeNode represents a {{range}} action and its commands.

func (*RangeNode) Copy

type StringNode

StringNode holds a string constant. The value has been "unquoted".

func (*StringNode) Copy

func (*StringNode) String

type TemplateNode

TemplateNode represents a {{template}} action.

func (*TemplateNode) Copy

func (*TemplateNode) String

type TextNode

TextNode holds plain text.

func (*TextNode) Copy

func (*TextNode) String

type Tree

Tree is the representation of a single parsed template.

func New

New allocates a new parse tree with the given name.

func (*Tree) Copy

Copy returns a copy of the Tree. Any parsing state is discarded.

func (*Tree) ErrorContext

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.

func (*Tree) Parse

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, possibly with chained field accesses. The dollar sign is part of the (first) name.

func (*VariableNode) Copy

func (*VariableNode) String

type WithNode

WithNode represents a {{with}} action and its commands.

func (*WithNode) Copy