diff options
Diffstat (limited to 'src/text/template/parse/node.go')
-rw-r--r-- | src/text/template/parse/node.go | 33 |
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 |