Check that scope name is present before comparing

Previously if the last 2 rules in the stack had no scope
name and the position wasn't advancing then the last rule
would be popped.

This caused Java single line comments to not parse properly
since the push rules for comment blocks have no scope name.
This commit is contained in:
Kevin Sawicki 2013-05-31 09:26:07 -07:00
parent 9e7a9e6210
commit 9431a8c3ac
2 changed files with 18 additions and 1 deletions

View File

@ -597,3 +597,20 @@ describe "TextMateGrammar", ->
tokens = lines[1]
expect(tokens[2].value).toBe '@"'
expect(tokens[2].scopes).toEqual ["source.objc++", "meta.function.c", "meta.block.c", "string.quoted.double.objc", "punctuation.definition.string.begin.objc"]
describe "Java", ->
beforeEach ->
atom.activatePackage('java-tmbundle', sync: true)
grammar = syntax.selectGrammar('Function.java')
lines = grammar.tokenizeLines """
public void test() {
//comment
}
"""
it "correctly parses single line comments", ->
tokens = lines[1]
expect(tokens[0].scopes).toEqual ["source.java", "comment.line.double-slash.java", "punctuation.definition.comment.java"]
expect(tokens[0].value).toEqual '//'
expect(tokens[1].scopes).toEqual ["source.java", "comment.line.double-slash.java"]
expect(tokens[1].value).toEqual 'comment'

View File

@ -159,7 +159,7 @@ class TextMateGrammar
ruleStack.pop()
[penultimateRule, lastRule] = ruleStack[-2..]
if lastRule? and penultimateRule.scopeName == lastRule.scopeName
if lastRule?.scopeName? and penultimateRule.scopeName == lastRule.scopeName
ruleStack.pop()
tokens.push(new Token(
value: line[position...line.length]