diff options
Diffstat (limited to 'src/pkg/exp/template/lex.go')
-rw-r--r-- | src/pkg/exp/template/lex.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/pkg/exp/template/lex.go b/src/pkg/exp/template/lex.go index 435762c03e..7230f5b025 100644 --- a/src/pkg/exp/template/lex.go +++ b/src/pkg/exp/template/lex.go @@ -209,8 +209,12 @@ func lex(name, input string) *lexer { // state functions -const leftMeta = "{{" -const rightMeta = "}}" +const ( + leftMeta = "{{" + rightMeta = "}}" + leftComment = "{{/*" + rightComment = "*/}}" +) // lexText scans until a metacharacter func lexText(l *lexer) stateFn { @@ -235,11 +239,25 @@ func lexText(l *lexer) stateFn { // leftMeta scans the left "metacharacter", which is known to be present. func lexLeftMeta(l *lexer) stateFn { + if strings.HasPrefix(l.input[l.pos:], leftComment) { + return lexComment + } l.pos += len(leftMeta) l.emit(itemLeftMeta) return lexInsideAction } +// lexComment scans a comment. The left comment marker is known to be present. +func lexComment(l *lexer) stateFn { + i := strings.Index(l.input[l.pos:], rightComment) + if i < 0 { + return l.errorf("unclosed comment") + } + l.pos += i + len(rightComment) + l.ignore() + return lexText +} + // rightMeta scans the right "metacharacter", which is known to be present. func lexRightMeta(l *lexer) stateFn { l.pos += len(rightMeta) |