1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
package parse
// Node is an element in the parse tree.
type Node interface {
node()
}
// empty string node
var empty = new(TextNode)
// a template is represented by a tree consisting of one
// or more of the following nodes.
type (
// TextNode represents a string of text.
TextNode struct {
Value string
}
// FuncNode represents a string function.
FuncNode struct {
Param string
Name string
Args []Node
}
// ListNode represents a list of nodes.
ListNode struct {
Nodes []Node
}
// ParamNode struct{
// Name string
// }
//
// CaseNode struct {
// Name string
// First bool
// }
//
// LowerNode struct {
// Name string
// First bool
// }
//
// SubstrNode struct {
// Name string
// Pos Node
// Len Node
// }
//
// ReplaceNode struct {
// Name string
// Substring Node
// Replacement Node
// }
//
// TrimNode struct{
//
// }
//
// DefaultNode struct {
// Name string
// Default Node
// }
)
// newTextNode returns a new TextNode.
func newTextNode(text string) *TextNode {
return &TextNode{Value: text}
}
// newListNode returns a new ListNode.
func newListNode(nodes ...Node) *ListNode {
return &ListNode{Nodes: nodes}
}
// newFuncNode returns a new FuncNode.
func newFuncNode(name string) *FuncNode {
return &FuncNode{Param: name}
}
// node() defines the node in a parse tree
func (*TextNode) node() {}
func (*ListNode) node() {}
func (*FuncNode) node() {}
|