Skip to content

Commit f67928d

Browse files
jan-heroutsauerbraten
authored andcommitted
fix issue #187
1 parent 69af0cf commit f67928d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lex.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,14 @@ func (l *lexer) run() {
287287
// state functions
288288
func lexText(l *lexer) stateFn {
289289
for {
290-
if i := strings.IndexByte(l.input[l.pos:], l.leftDelim[0]); i == -1 {
290+
// without breaking the API, this seems like a reasonable workaround to correctly parse comments
291+
i := strings.IndexByte(l.input[l.pos:], l.leftDelim[0]) // index of suspected left delimiter
292+
ic := strings.IndexByte(l.input[l.pos:], leftComment[0]) // index of suspected left comment marker
293+
if ic > -1 && ic < i { // use whichever is lower for future lexing
294+
i = ic
295+
}
296+
// if no tokn is found, skip till the end of template
297+
if i == -1 {
291298
l.pos = Pos(len(l.input))
292299
break
293300
} else {

testData/custom_delimiters.jet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[[ . ]]
1+
{* comment *}[[ . ]]
22
[[ singleValue ]]
33
[[ nil ]]
44
[[ "" ]]

0 commit comments

Comments
 (0)