mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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'
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user