Terminate when tokens end position is undefined

This ensures the position is advanced for zero-length
matches and only terminates when the end position for
the tokens is no longer valid.
This commit is contained in:
Kevin Sawicki 2012-09-27 19:07:06 -07:00
parent d37a0dd916
commit 4ccaa6f714

View File

@ -41,20 +41,21 @@ class TextMateGrammar
{ nextTokens, tokensStartPosition, tokensEndPosition} = _.last(stack).getNextTokens(stack, line, position)
if nextTokens
if position < tokensStartPosition # unmatched text preceding next tokens
tokens.push
value: line[position...tokensStartPosition]
scopes: scopes
if position < tokensStartPosition # unmatched text before next tokens
tokens.push
value: line[position...tokensStartPosition]
scopes: scopes
tokens.push(nextTokens...)
position = tokensEndPosition
else if tokensEndPosition - tokensStartPosition != 0 # break unless it was a zero length match
tokens.push(nextTokens...) if nextTokens
if tokensEndPosition is undefined # unmatched text after last token
tokens.push
value: line[position...line.length]
scopes: scopes
break
position = tokensEndPosition
{ tokens, stack }
ruleForInclude: (name) ->