Return empty token array for zero-length matches

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-09-28 09:31:15 -07:00
parent 255e58b4f8
commit 66ac4503a7

View File

@@ -38,16 +38,16 @@ class TextMateGrammar
break if position == line.length
{ nextTokens, tokensStartPosition, tokensEndPosition} = _.last(stack).getNextTokens(stack, line, position)
{ nextTokens, tokensStartPosition, tokensEndPosition } = _.last(stack).getNextTokens(stack, line, position)
if position < tokensStartPosition # unmatched text before next tokens
tokens.push
value: line[position...tokensStartPosition]
scopes: scopes
tokens.push(nextTokens...) if nextTokens
if tokensEndPosition is undefined # unmatched text after last token
if nextTokens
tokens.push(nextTokens...)
else # unmatched text after last token
tokens.push
value: line[position...line.length]
scopes: scopes
@@ -164,7 +164,7 @@ class Pattern
[start, end] = captureIndices[1..2]
zeroLengthMatch = end == start
if zeroLengthMatch
tokens = null
tokens = []
else
tokens = [{ value: line[start...end], scopes: scopes }]
if @pushRule