aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/parse/node.go
diff options
context:
space:
mode:
authorAriel Mashraki <ariel@mashraki.co.il>2020-04-22 22:17:56 +0300
committerDaniel Martí <mvdan@mvdan.cc>2020-08-28 21:45:12 +0000
commitc8ea03828b0645b1fd5725888e44873b75fcfbb6 (patch)
treee6ce023202b96a0474d88bcf7eb6befa9f950ab0 /src/text/template/parse/node.go
parenta58a8d2e97d605f9f115a0e77ba09cd36bb82ba6 (diff)
downloadgo-c8ea03828b0645b1fd5725888e44873b75fcfbb6.tar.xz
text/template: add CommentNode to template parse tree
Fixes #34652 Change-Id: Icf6e3eda593fed826736f34f95a9d66f5450cc98 Reviewed-on: https://go-review.googlesource.com/c/go/+/229398 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/text/template/parse/node.go')
-rw-r--r--src/text/template/parse/node.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/text/template/parse/node.go b/src/text/template/parse/node.go
index dddc7752a2..177482f9b2 100644
--- a/src/text/template/parse/node.go
+++ b/src/text/template/parse/node.go
@@ -70,6 +70,7 @@ const (
NodeTemplate // A template invocation action.
NodeVariable // A $ variable.
NodeWith // A with action.
+ NodeComment // A comment.
)
// Nodes.
@@ -149,6 +150,38 @@ func (t *TextNode) Copy() Node {
return &TextNode{tr: t.tr, NodeType: NodeText, Pos: t.Pos, Text: append([]byte{}, t.Text...)}
}
+// CommentNode holds a comment.
+type CommentNode struct {
+ NodeType
+ Pos
+ tr *Tree
+ Text string // Comment text.
+}
+
+func (t *Tree) newComment(pos Pos, text string) *CommentNode {
+ return &CommentNode{tr: t, NodeType: NodeComment, Pos: pos, Text: text}
+}
+
+func (c *CommentNode) String() string {
+ var sb strings.Builder
+ c.writeTo(&sb)
+ return sb.String()
+}
+
+func (c *CommentNode) writeTo(sb *strings.Builder) {
+ sb.WriteString("{{")
+ sb.WriteString(c.Text)
+ sb.WriteString("}}")
+}
+
+func (c *CommentNode) tree() *Tree {
+ return c.tr
+}
+
+func (c *CommentNode) Copy() Node {
+ return &CommentNode{tr: c.tr, NodeType: NodeComment, Pos: c.Pos, Text: c.Text}
+}
+
// PipeNode holds a pipeline with optional declaration
type PipeNode struct {
NodeType