aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/parse/lex.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/lex.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/lex.go')
-rw-r--r--src/text/template/parse/lex.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/text/template/parse/lex.go b/src/text/template/parse/lex.go
index 30371f2862..e41373a002 100644
--- a/src/text/template/parse/lex.go
+++ b/src/text/template/parse/lex.go
@@ -41,6 +41,7 @@ const (
itemBool // boolean constant
itemChar // printable ASCII character; grab bag for comma etc.
itemCharConstant // character constant
+ itemComment // comment text
itemComplex // complex constant (1+2i); imaginary is just a number
itemAssign // equals ('=') introducing an assignment
itemDeclare // colon-equals (':=') introducing a declaration
@@ -112,6 +113,7 @@ type lexer struct {
leftDelim string // start of action
rightDelim string // end of action
trimRightDelim string // end of action with trim marker
+ emitComment bool // emit itemComment tokens.
pos Pos // current position in the input
start Pos // start position of this item
width Pos // width of last rune read from input
@@ -203,7 +205,7 @@ func (l *lexer) drain() {
}
// lex creates a new scanner for the input string.
-func lex(name, input, left, right string) *lexer {
+func lex(name, input, left, right string, emitComment bool) *lexer {
if left == "" {
left = leftDelim
}
@@ -216,6 +218,7 @@ func lex(name, input, left, right string) *lexer {
leftDelim: left,
rightDelim: right,
trimRightDelim: rightTrimMarker + right,
+ emitComment: emitComment,
items: make(chan item),
line: 1,
startLine: 1,
@@ -323,6 +326,9 @@ func lexComment(l *lexer) stateFn {
if !delim {
return l.errorf("comment ends before closing delimiter")
}
+ if l.emitComment {
+ l.emit(itemComment)
+ }
if trimSpace {
l.pos += trimMarkerLen
}