Documentation
¶
Index ¶
- Constants
- Variables
- func Collect(name, src, left, right string) (items []item)
- func NewLexerFromString(name, data string, initState stateFn) *lexer
- func PrintCollection(items []item)
- type ActionNode
- type BranchNode
- type CRNode
- type CTagNode
- type ChainNode
- type CommandNode
- type CommentNode
- type DotNode
- type FieldNode
- type IdentifierNode
- type IfNode
- type InvertedNode
- type ListNode
- type NLNode
- type Node
- type NodeType
- type ParentNode
- type PartialNode
- type PipeNode
- type Pos
- type RangeNode
- type SpaceNode
- type TemplateNode
- type TextNode
- type VariableNode
- type WithNode
Constants ¶
const ( // Special items ERROR itemType = iota EOF )
The list of items.
const ( OTag = "{{" OLen = 2 ORune = '{' CTag = "}}" CLen = 2 CRune = '}' )
Variables ¶
var ItemStrings = [...]string{ ERROR: "ERROR", EOF: "EOF", // contains filtered or unexported fields }
itemStrings provides string descriptions to the item.
var ItemToNode map[itemType]NodeType // itemTypes to NodeTypes (for ident declarations)
var NodeStrings map[NodeType]string
NodeStrings gives a string description for the NodeType
Functions ¶
func Collect ¶
func Collect(name, src, left, right string) (items []item)
collect gathers the emitted items into a slice.-- for development
func NewLexerFromString ¶
func NewLexerFromString(name, data string, initState stateFn) *lexer
Returns a new, initialized lexer with the tag defaults set to {{}}.
Types ¶
type ActionNode ¶
type ActionNode struct {
NodeType
Typ itemType
Pos
Line int
Pipe *PipeNode // The pipeline in the action.
}
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 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).
}
BranchNode is the common representation of if, range, and with.
func (*BranchNode) String ¶
func (b *BranchNode) String() string
type ChainNode ¶
type ChainNode struct {
NodeType
Pos
Node Node
Field []string // The identifiers in lexical order.
}
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 CommandNode ¶
type CommandNode struct {
NodeType
Pos
Args []Node // Arguments in lexical order: Identifier, field, or constant.
}
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 CommentNode ¶
CommentNode holds a tag
func (*CommentNode) Copy ¶
func (t *CommentNode) Copy() Node
func (*CommentNode) String ¶
func (t *CommentNode) String() string
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(typ NodeType, ident string) *IdentifierNode
NewIdentifier 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) String ¶
func (i *IdentifierNode) String() string
type IfNode ¶
type IfNode struct {
BranchNode
}
IfNode represents an {{if}} action and its commands.
type InvertedNode ¶
InvertedNode holds an identifier.
func (*InvertedNode) Copy ¶
func (i *InvertedNode) Copy() Node
func (*InvertedNode) SetPos ¶
func (i *InvertedNode) SetPos(pos Pos) *InvertedNode
SetPos sets the position. ParentNode is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day?
func (*InvertedNode) String ¶
func (i *InvertedNode) String() string
type Node ¶
type Node interface {
Type() NodeType
String() string
// 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.
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. NodeNL // NL are evaluated separately NodeCR // CRs need to be handled too NodeSpace // Space..we classify that differently NodeComment NodeEscaped NodeUnescaped NodeSection NodeInverted NodePartial NodeParent NodeList // A list of nodes NodePipe // A pipeline of commands. NodeTemplate // A template invocation action. NodeIdentifier NodeCommand NodeVariable NodeCTag NodeBranch NodeIf NodeElse NodeRange NodeWith NodeAction // A non-control action such as a field evaluation. NodeChain NodeField NodeDot NodeEnd )
type ParentNode ¶
ParentNode holds an identifier.
func (*ParentNode) Copy ¶
func (i *ParentNode) Copy() Node
func (*ParentNode) SetPos ¶
func (i *ParentNode) SetPos(pos Pos) *ParentNode
SetPos sets the position. ParentNode is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day?
func (*ParentNode) String ¶
func (i *ParentNode) String() string
type PartialNode ¶
PartialNode holds an identifier.
func (*PartialNode) Copy ¶
func (i *PartialNode) Copy() Node
func (*PartialNode) SetPos ¶
func (i *PartialNode) SetPos(pos Pos) *PartialNode
SetPos sets the position. NewIdentifier is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day?
func (*PartialNode) String ¶
func (i *PartialNode) String() string
type PipeNode ¶
type PipeNode struct {
NodeType
Pos
Line int // The line number in the input (deprecated; kept for compatibility)
Decl []*VariableNode
Cmds []*CommandNode // The commands in lexical order.
}
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 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.
}
TemplateNode represents a {{template}} action.
func (*TemplateNode) Copy ¶
func (t *TemplateNode) Copy() Node
func (*TemplateNode) String ¶
func (t *TemplateNode) String() string
type VariableNode ¶
type VariableNode struct {
NodeType
Typ itemType // Variables can be escaped or unescaped; this is for that.
Pos
Ident []string // Variable name and fields in lexical order
}
VariableNode holds an escaped variable
func (*VariableNode) Copy ¶
func (v *VariableNode) Copy() Node
func (*VariableNode) String ¶
func (v *VariableNode) String() string