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