Skip to content

Commit 60fc36f

Browse files
committed
Fix for atom#91 and atom#96
Updated invalid comment begin rule to reduce number of tokens generated
1 parent 15d1f0a commit 60fc36f

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

grammars/xml.cson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
'name': 'comment.block.xml'
419419
'patterns': [
420420
{
421-
'begin': '--(?!>)'
421+
'begin': '(?=--(?!>))'
422422
'end': '(?<!-)(?=-->)'
423423
'name': 'invalid.illegal.bad-comments-or-CDATA.xml'
424424
}

spec/xml-spec.coffee

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,27 @@ describe "XML grammar", ->
3434
{tokens} = grammar.tokenizeLine('<!-- invalid comment --->')
3535
expect(tokens[0]).toEqual value: '<!--', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
3636
expect(tokens[1]).toEqual value: ' invalid comment ', scopes: ['text.xml', 'comment.block.xml']
37-
expect(tokens[2]).toEqual value: '--', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
38-
expect(tokens[3]).toEqual value: '->', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
37+
expect(tokens[2]).toEqual value: '--->', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
3938

4039
it 'tokenizes comments with two dashes not followed by ">" as invalid', ->
4140
{tokens} = grammar.tokenizeLine('<!-- invalid -- comment -->')
4241
expect(tokens[0]).toEqual value: '<!--', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
4342
expect(tokens[1]).toEqual value: ' invalid ', scopes: ['text.xml', 'comment.block.xml']
44-
expect(tokens[2]).toEqual value: '--', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
45-
expect(tokens[3]).toEqual value: ' comment ', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
46-
expect(tokens[4]).toEqual value: '-->', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
43+
expect(tokens[2]).toEqual value: '-- comment ', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
44+
expect(tokens[3]).toEqual value: '-->', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
4745

4846
it 'tokenizes after invalid comment only if comment was properly closed', ->
4947
{tokens} = grammar.tokenizeLine('<!-- invalid -- comment ---><n></n>--><n></n>')
5048
expect(tokens[0]).toEqual value: '<!--', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
5149
expect(tokens[1]).toEqual value: ' invalid ', scopes: ['text.xml', 'comment.block.xml']
52-
expect(tokens[2]).toEqual value: '--', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
53-
expect(tokens[3]).toEqual value: ' comment ---><n></n>', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
54-
expect(tokens[4]).toEqual value: '-->', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
55-
expect(tokens[5]).toEqual value: '<', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
56-
expect(tokens[6]).toEqual value: 'n', scopes: ['text.xml', 'meta.tag.no-content.xml', 'entity.name.tag.xml', 'entity.name.tag.localname.xml']
57-
expect(tokens[7]).toEqual value: '>', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
58-
expect(tokens[8]).toEqual value: '</', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
59-
expect(tokens[9]).toEqual value: 'n', scopes: ['text.xml', 'meta.tag.no-content.xml', 'entity.name.tag.xml', 'entity.name.tag.localname.xml']
60-
expect(tokens[10]).toEqual value: '>', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
50+
expect(tokens[2]).toEqual value: '-- comment ---><n></n>', scopes: ['text.xml', 'comment.block.xml', 'invalid.illegal.bad-comments-or-CDATA.xml']
51+
expect(tokens[3]).toEqual value: '-->', scopes: ['text.xml', 'comment.block.xml', 'punctuation.definition.comment.xml']
52+
expect(tokens[4]).toEqual value: '<', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
53+
expect(tokens[5]).toEqual value: 'n', scopes: ['text.xml', 'meta.tag.no-content.xml', 'entity.name.tag.xml', 'entity.name.tag.localname.xml']
54+
expect(tokens[6]).toEqual value: '>', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
55+
expect(tokens[7]).toEqual value: '</', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
56+
expect(tokens[8]).toEqual value: 'n', scopes: ['text.xml', 'meta.tag.no-content.xml', 'entity.name.tag.xml', 'entity.name.tag.localname.xml']
57+
expect(tokens[9]).toEqual value: '>', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']
6158

6259
it "tokenizes empty element meta.tag.no-content.xml", ->
6360
{tokens} = grammar.tokenizeLine('<n></n>')

0 commit comments

Comments
 (0)