Skip to content

Commit d67b5d8

Browse files
Prevent matching goto label in ternary atom#386
1 parent b1281fa commit d67b5d8

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

grammars/php.cson

+12
Original file line numberDiff line numberDiff line change
@@ -3668,6 +3668,18 @@
36683668
'0':
36693669
'name': 'keyword.operator.ternary.php'
36703670
'patterns': [
3671+
{
3672+
# prevent matching goto label in ternary
3673+
# See https://github.com/atom/language-php/issues/386
3674+
'match': '(?i)^\\s*([a-z_\\x{7f}-\\x{7fffffff}][a-z0-9_\\x{7f}-\\x{7fffffff}]*)\\s*(?=:(?!:))'
3675+
'captures':
3676+
'1':
3677+
'patterns': [
3678+
{
3679+
'include': '$self'
3680+
}
3681+
]
3682+
}
36713683
{
36723684
'include': '$self'
36733685
}

spec/php-spec.coffee

+16
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,22 @@ describe 'PHP grammar', ->
317317
expect(tokens[9]).toEqual value: ':', scopes: ["source.php", "keyword.operator.ternary.php"]
318318
expect(tokens[12]).toEqual value: '::', scopes: ["source.php", "keyword.operator.class.php"]
319319

320+
it 'should NOT tokenize goto label in ternary', ->
321+
# See https://github.com/atom/language-php/issues/386
322+
lines = grammar.tokenizeLines '''
323+
$a ?
324+
null :
325+
$b
326+
'''
327+
328+
expect(lines[0][0]).toEqual value: '$', scopes: ['source.php', 'variable.other.php', 'punctuation.definition.variable.php']
329+
expect(lines[0][1]).toEqual value: 'a', scopes: ['source.php', 'variable.other.php']
330+
expect(lines[0][3]).toEqual value: '?', scopes: ['source.php', 'keyword.operator.ternary.php']
331+
expect(lines[1][1]).toEqual value: 'null', scopes: ['source.php', 'constant.language.php']
332+
expect(lines[1][3]).toEqual value: ':', scopes: ['source.php', 'keyword.operator.ternary.php']
333+
expect(lines[2][1]).toEqual value: '$', scopes: ['source.php', 'variable.other.php', 'punctuation.definition.variable.php']
334+
expect(lines[2][2]).toEqual value: 'b', scopes: ['source.php', 'variable.other.php']
335+
320336
describe 'identifiers', ->
321337
it 'tokenizes identifiers with only letters', ->
322338
{tokens} = grammar.tokenizeLine '$abc'

0 commit comments

Comments
 (0)