*/
// {{/* a comment */}}
// A comment; discarded. May contain newlines.
-// Comments do not nest.
+// Comments do not nest and must start and end at the
+// delimiters, as shown here.
/*
{{pipeline}}
// lexComment scans a comment. The left comment marker is known to be present.
func lexComment(l *lexer) stateFn {
l.pos += Pos(len(leftComment))
- i := strings.Index(l.input[l.pos:], rightComment+l.rightDelim)
+ i := strings.Index(l.input[l.pos:], rightComment)
if i < 0 {
return l.errorf("unclosed comment")
}
- l.pos += Pos(i + len(rightComment) + len(l.rightDelim))
+ l.pos += Pos(i + len(rightComment))
+ if !strings.HasPrefix(l.input[l.pos:], l.rightDelim) {
+ return l.errorf("comment ends before closing delimiter")
+
+ }
+ l.pos += Pos(len(l.rightDelim))
l.ignore()
return lexText
}
{itemText, 0, "hello-"},
{itemError, 0, `unclosed comment`},
}},
+ {"text with comment close separted from delim", "hello-{{/* */ }}-world", []item{
+ {itemText, 0, "hello-"},
+ {itemError, 0, `comment ends before closing delimiter`},
+ }},
}
// collect gathers the emitted items into a slice.