diff --git a/src/app/text-mate-grammar.coffee b/src/app/text-mate-grammar.coffee index b77025342..d78446461 100644 --- a/src/app/text-mate-grammar.coffee +++ b/src/app/text-mate-grammar.coffee @@ -38,23 +38,22 @@ class TextMateGrammar break if position == line.length - { nextTokens, tokensStartPosition, tokensEndPosition } = _.last(stack).getNextTokens(stack, line, position) + if match = _.last(stack).getNextTokens(stack, line, position) + { nextTokens, tokensStartPosition, tokensEndPosition } = match + if position < tokensStartPosition # unmatched text before 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 - - if nextTokens tokens.push(nextTokens...) - else # unmatched text after last token + position = tokensEndPosition + + else # push filler token for unmatched text at end of line tokens.push value: line[position...line.length] scopes: scopes break - position = tokensEndPosition - { tokens, stack } ruleForInclude: (name) -> @@ -91,7 +90,7 @@ class Rule getNextTokens: (stack, line, position) -> patterns = @getIncludedPatterns() - return {} unless result = @getScanner().findNextMatch(line, position) + return null unless result = @getScanner().findNextMatch(line, position) { index, captureIndices } = result [firstCaptureIndex, firstCaptureStart, firstCaptureEnd] = captureIndices