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 HTMLEscape(w io.Writer, b []byte)
- func HTMLEscapeString(s string) string
- func HTMLEscaper(args ...interface{}) string
- func IsDomFuncs(name string) bool
- func IsEmptyTree(n Node) bool
- func JSEscape(w io.Writer, b []byte)
- func JSEscapeString(s string) string
- func JSEscaper(args ...interface{}) string
- func MergeMaps(items ...map[string]string) map[string]string
- func Parse(name, text, leftDelim, rightDelim string, maps FuncMaps, ...) (map[string]*Tree, error)
- func URLQueryEscaper(args ...interface{}) string
- type ActionNode
- type AttrList
- type AttrNode
- type BaseTypeNode
- type BoolNode
- type BranchNode
- type ChainNode
- type CollectionType
- type CollectionTypeNode
- type CommandNode
- type DOMIdentifier
- type DotNode
- type FieldNode
- type FinishNode
- type FuncMaps
- type HTMLNode
- type IdentifierNode
- type IfNode
- type ImportDeclr
- type ImportedFieldFunc
- func (s *ImportedFieldFunc) Copy() Node
- func (s *ImportedFieldFunc) IsField() bool
- func (s *ImportedFieldFunc) IsFunc() bool
- func (s *ImportedFieldFunc) String() string
- func (s *ImportedFieldFunc) ToIdentifier() *IdentifierNode
- func (s *ImportedFieldFunc) ToName() string
- func (s *ImportedFieldFunc) ToTextIdentifier() *TextIdentifierNode
- type ListNode
- type MethodNode
- type ModelNode
- type ModelTypeNode
- type MountLiveNode
- type MountNode
- type NilNode
- type Node
- type NodeType
- type NodeTyper
- type NumberNode
- type PipeNode
- type Pos
- type RangeNode
- type RefNode
- type RootNode
- type StringNode
- type TemplateNode
- type TextIdentifierNode
- type TextList
- type TextNode
- type ThemeList
- type Tree
- type VariableNode
- type WithNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTMLEscape ¶
HTMLEscape writes to w the escaped HTML equivalent of the plain text data b.
func HTMLEscapeString ¶
HTMLEscapeString returns the escaped HTML equivalent of the plain text data s.
func HTMLEscaper ¶
func HTMLEscaper(args ...interface{}) string
HTMLEscaper returns the escaped HTML equivalent of the textual representation of its arguments.
func IsDomFuncs ¶
IsDomFuncs returns true/false if the name is a dom function.
func IsEmptyTree ¶
IsEmptyTree reports whether this tree (node) is empty of everything but space.
func JSEscapeString ¶
JSEscapeString returns the escaped JavaScript equivalent of the plain text data s.
func JSEscaper ¶
func JSEscaper(args ...interface{}) string
JSEscaper returns the escaped JavaScript equivalent of the textual representation of its arguments.
func Parse ¶
func Parse(name, text, leftDelim, rightDelim string, maps FuncMaps, treeSet map[string]*Tree) (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.
func URLQueryEscaper ¶
func URLQueryEscaper(args ...interface{}) string
URLQueryEscaper returns the escaped value of the textual representation of its arguments in a form suitable for embedding in a URL query.
Types ¶
type ActionNode ¶
type ActionNode struct {
NodeType
Pos
Line int // The line number in the input. Deprecated: Kept for compatibility.
Pipe *PipeNode // The pipeline in the action.
InHTML bool
HasDOMMount bool
// contains filtered or unexported fields
}
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 (a *ActionNode) Copy() Node
func (*ActionNode) String ¶
func (a *ActionNode) String() string
type AttrNode ¶
type AttrNode struct {
NodeType
Pos
IsTheme bool
Quoted string // The original text of the string, with quotes.
Key string // The string, after quote processing.
Values *ListNode
// contains filtered or unexported fields
}
AttrNode holds a string constant. The value has been "unquoted".
type BaseTypeNode ¶
type BaseTypeNode struct {
NodeType
Typ string
Pos
InHTML bool
// contains filtered or unexported fields
}
BaseTypeNode holds a boolean constant.
func (*BaseTypeNode) Copy ¶
func (b *BaseTypeNode) Copy() Node
func (*BaseTypeNode) String ¶
func (b *BaseTypeNode) String() string
type BoolNode ¶
type BoolNode struct {
NodeType
Pos
True bool // The value of the boolean constant.
InHTML bool
// contains filtered or unexported fields
}
BoolNode holds a boolean constant.
type BranchNode ¶
type BranchNode struct {
NodeType
Pos
Line int // The line number in the input. Deprecated: Kept for compatibility.
Pipe *PipeNode // The pipeline to be evaluated.
List *ListNode // What to execute if the value is non-empty.
ElseList *ListNode // What to execute if the value is empty (nil if absent).
// contains filtered or unexported fields
}
BranchNode is the common representation of if, range, and with.
func (*BranchNode) Copy ¶
func (b *BranchNode) Copy() Node
func (*BranchNode) String ¶
func (b *BranchNode) String() string
type ChainNode ¶
type ChainNode struct {
NodeType
Pos
Node Node
Field []string // The identifiers in lexical order.
InHTML bool
// contains filtered or unexported fields
}
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.
type CollectionTypeNode ¶
type CollectionTypeNode struct {
NodeType
Typ CollectionType
Detail *ListNode
Pos
// contains filtered or unexported fields
}
CollectionTypeNode holds a boolean constant.
func (*CollectionTypeNode) Copy ¶
func (b *CollectionTypeNode) Copy() Node
func (*CollectionTypeNode) String ¶
func (b *CollectionTypeNode) String() string
type CommandNode ¶
type CommandNode struct {
NodeType
Pos
Line int
Args []Node // Arguments in lexical order: Identifier, field, or constant.
InHTML bool
HasDOMMount bool
// contains filtered or unexported fields
}
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 DOMIdentifier ¶
DOMIdentifier holds plain text.
func (*DOMIdentifier) Copy ¶
func (t *DOMIdentifier) Copy() Node
func (*DOMIdentifier) String ¶
func (t *DOMIdentifier) String() string
type FieldNode ¶
type FieldNode struct {
NodeType
Pos
Ident []string // The identifiers in lexical order.
InHTML bool
// contains filtered or unexported fields
}
FieldNode holds a field (identifier starting with '.'). The names may be chained ('.x.y'). The period is dropped from each ident.
type FinishNode ¶
FinishNode holds the special identifier 'nil' representing an untyped nil constant.
func (*FinishNode) Copy ¶
func (n *FinishNode) Copy() Node
func (*FinishNode) String ¶
func (n *FinishNode) String() string
func (*FinishNode) Type ¶
func (n *FinishNode) Type() NodeType
type FuncMaps ¶
type FuncMaps struct {
Funcs map[string]string
ModelSet map[string]*ModelNode
ModelTypeSet map[string]*ModelTypeNode
MethodSet map[string]*MethodNode
DefinedBlocks map[string]string
}
FuncMaps provides a wrapper of fields.
type HTMLNode ¶
type HTMLNode struct {
NodeType
Pos
Tag string
Closing bool
Line int // The line number in the input. Deprecated: Kept for compatibility.
Attr AttrList // The pipeline to be evaluated.
Children *ListNode // What are the children nodes for this.
// contains filtered or unexported fields
}
HTMLNode is the common representation of html node.
type IdentifierNode ¶
type IdentifierNode struct {
NodeType
Pos
Ident string // The identifier's name.
IsInbuiltFunc bool
InHTML bool
// contains filtered or unexported fields
}
IdentifierNode holds an identifier.
func NewIdentifier ¶
func NewIdentifier(ident string) *IdentifierNode
NewIdentifier returns a new IdentifierNode with the given identifier name.
func NewMethodIdentifier ¶
func NewMethodIdentifier(ident string) *IdentifierNode
NewMethodIdentifier returns a new IdentifierNode with the given identifier name.
func (*IdentifierNode) Copy ¶
func (i *IdentifierNode) Copy() Node
func (*IdentifierNode) SetPos ¶
func (i *IdentifierNode) SetPos(pos Pos) *IdentifierNode
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 ¶
func (i *IdentifierNode) SetTree(t *Tree) *IdentifierNode
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 ¶
func (i *IdentifierNode) String() string
type IfNode ¶
type IfNode struct {
BranchNode
}
IfNode represents an {{if}} action and its commands.
type ImportDeclr ¶
type ImportDeclr struct {
NodeType
Pos
Alias string
Path string // The string, after quote processing.
// contains filtered or unexported fields
}
ImportDeclr holds a string constant. The value has been "unquoted".
func (*ImportDeclr) Copy ¶
func (s *ImportDeclr) Copy() Node
func (*ImportDeclr) String ¶
func (s *ImportDeclr) String() string
type ImportedFieldFunc ¶
type ImportedFieldFunc struct {
NodeType
Pos
Text string // The string, after quote processing.
AsArgument bool
Fields []Node
Commands []*CommandNode
InHTML bool
HasDOMMount bool
IsNoOp bool
// contains filtered or unexported fields
}
ImportedFieldFunc holds a string constant. The value has been "unquoted".
func (*ImportedFieldFunc) Copy ¶
func (s *ImportedFieldFunc) Copy() Node
func (*ImportedFieldFunc) IsField ¶
func (s *ImportedFieldFunc) IsField() bool
func (*ImportedFieldFunc) IsFunc ¶
func (s *ImportedFieldFunc) IsFunc() bool
func (*ImportedFieldFunc) String ¶
func (s *ImportedFieldFunc) String() string
func (*ImportedFieldFunc) ToIdentifier ¶
func (s *ImportedFieldFunc) ToIdentifier() *IdentifierNode
func (*ImportedFieldFunc) ToName ¶
func (s *ImportedFieldFunc) ToName() string
func (*ImportedFieldFunc) ToTextIdentifier ¶
func (s *ImportedFieldFunc) ToTextIdentifier() *TextIdentifierNode
type ListNode ¶
type ListNode struct {
NodeType
Pos
Nodes []Node // The element nodes in lexical order.
InHTML bool
HasDOMMount bool
// contains filtered or unexported fields
}
ListNode holds a sequence of nodes.
type MethodNode ¶
type MethodNode struct {
NodeType
Pos
Model string
Arguments []*RefNode
Body *ListNode
// contains filtered or unexported fields
}
MethodNode holds a boolean constant.
func (*MethodNode) Copy ¶
func (b *MethodNode) Copy() Node
func (*MethodNode) HasArgument ¶
func (b *MethodNode) HasArgument(argName string) bool
func (*MethodNode) String ¶
func (b *MethodNode) String() string
type ModelNode ¶
type ModelNode struct {
NodeType
Model string
Pos
Fields *ListNode
// contains filtered or unexported fields
}
ModelNode holds a boolean constant.
type ModelTypeNode ¶
type ModelTypeNode struct {
NodeType
Typ string
Detail Node
Pos
// contains filtered or unexported fields
}
ModelTypeNode holds a boolean constant.
func (*ModelTypeNode) Copy ¶
func (b *ModelTypeNode) Copy() Node
func (*ModelTypeNode) String ¶
func (b *ModelTypeNode) String() string
type MountLiveNode ¶
type MountLiveNode struct {
NodeType
Pos
Target Node
IsList bool
Name string // The string, after quote processing.
Route string
// contains filtered or unexported fields
}
MountLiveNode holds a string constant. The value has been "unquoted".
func (*MountLiveNode) Copy ¶
func (s *MountLiveNode) Copy() Node
func (*MountLiveNode) String ¶
func (s *MountLiveNode) String() string
type MountNode ¶
type MountNode struct {
NodeType
Pos
Target Node
IsList bool
Name string // The string, after quote processing.
// contains filtered or unexported fields
}
MountNode holds a string constant. The value has been "unquoted".
type Node ¶
type Node interface {
NodeTyper
String() string
// Copy does a deep copy of the Node and all its components.
// To agroundlayer type assertions, some XxxNodes also have specialized
// CopyXxx methods that return *XxxNode.
Copy() Node
Position() Pos // byte position of start of node in full original input string
// 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 ( NodeText NodeType = iota // Plain text. NodeDOM // DOM identifer. NodeAction // A non-control action such as a field evaluation. NodeBool // A boolean constant. NodeChain // A sequence of field accesses. NodeCommand // An element of a pipeline. NodeDot // The cursor, dot. NodeField // A field or method name. NodeIdentifier // An identifier; always a function name. NodeTextIdentifier // An identifier; always a function name. NodeMethodIdentifier // An identifier; always a function name. NodeIf // An if action. NodeTag // A html tag . NodeImport // A import declaration NodeImportedFunc // A imported func declaration NodeImportedField // A imported field declaration NodeModel // A model declaration NodeModelType // A model type declaration NodeModelField // A model field declaration NodeModelTypeField // A model type field declaration NodeMethod // A method declaration NodeAttr // A html attr node . NodeKids // A html attr node . NodeList // A list of Nodes. NodeNil // An untyped nil constant. NodeNumber // A numerical constant. NodePipe // A pipeline of commands. NodeRange // A range action. NodeString // A string constant. NodeRoot // A root node constant. NodeKomponent // A komponent node constant. NodeKomponentMount // A Mountkomponent node constant. NodeTemplate // A template invocation action. NodeVariable // A $ variable. NodeWith // A with action. )
type NumberNode ¶
type NumberNode struct {
NodeType
Pos
IsInt bool // Number has an integral value.
IsUint bool // Number has an unsigned integral value.
IsFloat bool // Number has a floating-point value.
IsComplex bool // Number is complex.
Int64 int64 // The signed integer value.
Uint64 uint64 // The unsigned integer value.
Float64 float64 // The floating-point value.
Complex128 complex128 // The complex value.
Text string // The original textual representation from the input.
InHTML bool
// contains filtered or unexported fields
}
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
Pos
Line int // The line number in the input. Deprecated: Kept for compatibility.
IsAssign bool // The variables are being assigned, not declared.
Decl []*VariableNode // Variables in lexical order.
Cmds []*CommandNode // The commands in lexical order.
HasDOMMount bool
// contains filtered or unexported fields
}
PipeNode holds a pipeline with optional declaration
type Pos ¶
type Pos int
Pos represents a byte position in the original input text from which this template was parsed.
type RangeNode ¶
type RangeNode struct {
BranchNode
}
RangeNode represents a {{range}} action and its commands.
type RefNode ¶
type RefNode struct {
NodeType
Pos
Name string
Typ string
Detail Node
// contains filtered or unexported fields
}
RefNode holds a reference to a type constant.
type RootNode ¶
type RootNode struct {
NodeType
Pos
Quoted string // The original text of the string, with quotes.
Text string // The string, after quote processing.
// contains filtered or unexported fields
}
RootNode holds a string constant. The value has been "unquoted".
type StringNode ¶
type StringNode struct {
NodeType
Pos
Quoted string // The original text of the string, with quotes.
Text string // The string, after quote processing.
InHTML bool
// contains filtered or unexported fields
}
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 ¶
type TemplateNode struct {
NodeType
Pos
Line int // The line number in the input. Deprecated: Kept for compatibility.
Name string // The name of the template (unquoted).
Pipe *PipeNode // The command to evaluate as dot for the template.
// contains filtered or unexported fields
}
TemplateNode represents a {{template}} action.
func (*TemplateNode) Copy ¶
func (t *TemplateNode) Copy() Node
func (*TemplateNode) String ¶
func (t *TemplateNode) String() string
type TextIdentifierNode ¶
type TextIdentifierNode struct {
NodeType
Pos
Text string
// contains filtered or unexported fields
}
TextIdentifierNode holds plain text.
func (*TextIdentifierNode) Copy ¶
func (t *TextIdentifierNode) Copy() Node
func (*TextIdentifierNode) String ¶
func (t *TextIdentifierNode) String() string
type TextNode ¶
type TextNode struct {
NodeType
Pos
Text []byte // The text; may span newlines.
InTheme bool
// contains filtered or unexported fields
}
TextNode holds plain text.
type Tree ¶
type Tree struct {
FuncMaps
FromDefinition bool
Name string // name of the template represented by the tree.
ParseName string // name of the top-level template during parsing, for error messages.
TypeName string
Root *ListNode // top-level root of the tree.
// contains filtered or unexported fields
}
Tree is the representation of a single parsed template.
func NewWithParseMap ¶
NewWithParseMap allocates a new parse tree with the given name.
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 ¶
func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, maps FuncMaps) (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 ¶
type VariableNode struct {
NodeType
Pos
Ident []string // Variable name and fields in lexical order.
InHTML bool
// contains filtered or unexported fields
}
AssignNode holds a list of variable names, possibly with chained field accesses. The dollar sign is part of the (first) name.
func (*VariableNode) Copy ¶
func (v *VariableNode) Copy() Node
func (*VariableNode) String ¶
func (v *VariableNode) String() string