summaryrefslogtreecommitdiffstats
path: root/libgo/go/template/parse/node.go
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-10-26 23:57:58 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-10-26 23:57:58 +0000
commitfa5d125b5cfa5c935e46d27a2cbcd71ae37687ac (patch)
tree19d182df05ead7ff8ba7ee00a7d57555e1383fdf /libgo/go/template/parse/node.go
parente3d46e67996cf20ca3a75fccbb5a0007bfa3f992 (diff)
downloadppe42-gcc-fa5d125b5cfa5c935e46d27a2cbcd71ae37687ac.tar.gz
ppe42-gcc-fa5d125b5cfa5c935e46d27a2cbcd71ae37687ac.zip
Update Go library to last weekly.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@180552 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/template/parse/node.go')
-rw-r--r--libgo/go/template/parse/node.go74
1 files changed, 34 insertions, 40 deletions
diff --git a/libgo/go/template/parse/node.go b/libgo/go/template/parse/node.go
index 6f0b429b958..7411327a651 100644
--- a/libgo/go/template/parse/node.go
+++ b/libgo/go/template/parse/node.go
@@ -390,8 +390,8 @@ func (e *elseNode) String() string {
return "{{else}}"
}
-// IfNode represents an {{if}} action and its commands.
-type IfNode struct {
+// BranchNode is the common representation of if, range, and with.
+type BranchNode struct {
NodeType
Line int // The line number in the input.
Pipe *PipeNode // The pipeline to be evaluated.
@@ -399,35 +399,49 @@ type IfNode struct {
ElseList *ListNode // What to execute if the value is empty (nil if absent).
}
-func newIf(line int, pipe *PipeNode, list, elseList *ListNode) *IfNode {
- return &IfNode{NodeType: NodeIf, Line: line, Pipe: pipe, List: list, ElseList: elseList}
+func (b *BranchNode) String() string {
+ name := ""
+ switch b.NodeType {
+ case NodeIf:
+ name = "if"
+ case NodeRange:
+ name = "range"
+ case NodeWith:
+ name = "with"
+ default:
+ panic("unknown branch type")
+ }
+ if b.ElseList != nil {
+ return fmt.Sprintf("({{%s %s}} %s {{else}} %s)", name, b.Pipe, b.List, b.ElseList)
+ }
+ return fmt.Sprintf("({{%s %s}} %s)", name, b.Pipe, b.List)
}
-func (i *IfNode) String() string {
- if i.ElseList != nil {
- return fmt.Sprintf("({{if %s}} %s {{else}} %s)", i.Pipe, i.List, i.ElseList)
- }
- return fmt.Sprintf("({{if %s}} %s)", i.Pipe, i.List)
+// IfNode represents an {{if}} action and its commands.
+type IfNode struct {
+ BranchNode
+}
+
+func newIf(line int, pipe *PipeNode, list, elseList *ListNode) *IfNode {
+ return &IfNode{BranchNode{NodeType: NodeIf, Line: line, Pipe: pipe, List: list, ElseList: elseList}}
}
// RangeNode represents a {{range}} action and its commands.
type RangeNode struct {
- NodeType
- Line int // The line number in the input.
- 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
}
func newRange(line int, pipe *PipeNode, list, elseList *ListNode) *RangeNode {
- return &RangeNode{NodeType: NodeRange, Line: line, Pipe: pipe, List: list, ElseList: elseList}
+ return &RangeNode{BranchNode{NodeType: NodeRange, Line: line, Pipe: pipe, List: list, ElseList: elseList}}
}
-func (r *RangeNode) String() string {
- if r.ElseList != nil {
- return fmt.Sprintf("({{range %s}} %s {{else}} %s)", r.Pipe, r.List, r.ElseList)
- }
- return fmt.Sprintf("({{range %s}} %s)", r.Pipe, r.List)
+// WithNode represents a {{with}} action and its commands.
+type WithNode struct {
+ BranchNode
+}
+
+func newWith(line int, pipe *PipeNode, list, elseList *ListNode) *WithNode {
+ return &WithNode{BranchNode{NodeType: NodeWith, Line: line, Pipe: pipe, List: list, ElseList: elseList}}
}
// TemplateNode represents a {{template}} action.
@@ -448,23 +462,3 @@ func (t *TemplateNode) String() string {
}
return fmt.Sprintf("{{template %q %s}}", t.Name, t.Pipe)
}
-
-// WithNode represents a {{with}} action and its commands.
-type WithNode struct {
- NodeType
- Line int // The line number in the input.
- 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).
-}
-
-func newWith(line int, pipe *PipeNode, list, elseList *ListNode) *WithNode {
- return &WithNode{NodeType: NodeWith, Line: line, Pipe: pipe, List: list, ElseList: elseList}
-}
-
-func (w *WithNode) String() string {
- if w.ElseList != nil {
- return fmt.Sprintf("({{with %s}} %s {{else}} %s)", w.Pipe, w.List, w.ElseList)
- }
- return fmt.Sprintf("({{with %s}} %s)", w.Pipe, w.List)
-}
OpenPOWER on IntegriCloud