aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/parse/node.go
diff options
context:
space:
mode:
authorTim Cooper <tim.cooper@layeh.com>2017-09-26 21:14:03 -0300
committerRob Pike <r@golang.org>2017-10-17 02:06:15 +0000
commit3be5d551801a97a76e236a2a53489b1c9c22e665 (patch)
tree99281e70b044f736eef5def74773045673392747 /src/text/template/parse/node.go
parent0b2cb89196967030ae005076f0166ad7d6024083 (diff)
downloadgo-3be5d551801a97a76e236a2a53489b1c9c22e665.tar.xz
text/template: add break, continue actions in ranges
Adds the two range control actions "break" and "continue". They act the same as the Go keywords break and continue, but are simplified in that only the innermost range statement can be broken out of or continued. Fixes #20531 Change-Id: I4412b3bbfd4dadb0ab74ae718e308c1ac7a0a1e9 Reviewed-on: https://go-review.googlesource.com/66410 Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/text/template/parse/node.go')
-rw-r--r--src/text/template/parse/node.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/text/template/parse/node.go b/src/text/template/parse/node.go
index 55ff46c17a..7e16349b31 100644
--- a/src/text/template/parse/node.go
+++ b/src/text/template/parse/node.go
@@ -69,6 +69,8 @@ const (
NodeTemplate // A template invocation action.
NodeVariable // A $ variable.
NodeWith // A with action.
+ NodeBreak // A break action.
+ NodeContinue // A continue action.
)
// Nodes.
@@ -796,6 +798,68 @@ func (r *RangeNode) Copy() Node {
return r.tr.newRange(r.Pos, r.Line, r.Pipe.CopyPipe(), r.List.CopyList(), r.ElseList.CopyList())
}
+// BreakNode represents a {{break}} action.
+type BreakNode struct {
+ NodeType
+ Pos
+ tr *Tree
+}
+
+func (t *Tree) newBreak(pos Pos) *BreakNode {
+ return &BreakNode{NodeType: NodeBreak, Pos: pos, tr: t}
+}
+
+func (b *BreakNode) Type() NodeType {
+ return b.NodeType
+}
+
+func (b *BreakNode) String() string {
+ return "{{break}}"
+}
+
+func (b *BreakNode) Copy() Node {
+ return b.tr.newBreak(b.Pos)
+}
+
+func (b *BreakNode) Position() Pos {
+ return b.Pos
+}
+
+func (b *BreakNode) tree() *Tree {
+ return b.tr
+}
+
+// ContinueNode represents a {{continue}} action.
+type ContinueNode struct {
+ NodeType
+ Pos
+ tr *Tree
+}
+
+func (t *Tree) newContinue(pos Pos) *ContinueNode {
+ return &ContinueNode{NodeType: NodeContinue, Pos: pos, tr: t}
+}
+
+func (c *ContinueNode) Type() NodeType {
+ return c.NodeType
+}
+
+func (c *ContinueNode) String() string {
+ return "{{continue}}"
+}
+
+func (c *ContinueNode) Copy() Node {
+ return c.tr.newContinue(c.Pos)
+}
+
+func (c *ContinueNode) Position() Pos {
+ return c.Pos
+}
+
+func (c *ContinueNode) tree() *Tree {
+ return c.tr
+}
+
// WithNode represents a {{with}} action and its commands.
type WithNode struct {
BranchNode