Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 4cdf06a

Browse files
Allow include with parentheses (#421)
1 parent 5a43136 commit 4cdf06a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

grammars/php.cson

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
'name': 'keyword.control.${1:/downcase}.php'
352352
}
353353
{
354-
'begin': '(?i)\\b((?:require|include)(?:_once)?)\\s+'
354+
'begin': '(?i)\\b((?:require|include)(?:_once)?)(\\s+|(?=\\())'
355355
'beginCaptures':
356356
'1':
357357
'name': 'keyword.control.import.include.php'

spec/php-spec.coffee

+34
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,40 @@ describe 'PHP grammar', ->
374374
expect(tokens[0]).toEqual value: '$', scopes: ['source.php', 'variable.other.php', 'punctuation.definition.variable.php']
375375
expect(tokens[1]).toEqual value: 'thistles', scopes: ['source.php', 'variable.other.php']
376376

377+
describe 'include', ->
378+
it 'should tokenize include and require correctly', ->
379+
{tokens} = grammar.tokenizeLine 'include "foo.php";'
380+
381+
expect(tokens[0]).toEqual value: 'include', scopes: ['source.php', 'meta.include.php', 'keyword.control.import.include.php']
382+
expect(tokens[2]).toEqual value: '"', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php', 'punctuation.definition.string.begin.php']
383+
expect(tokens[3]).toEqual value: 'foo.php', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php']
384+
expect(tokens[4]).toEqual value: '"', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php', 'punctuation.definition.string.end.php']
385+
386+
{tokens} = grammar.tokenizeLine 'require "foo.php";'
387+
388+
expect(tokens[0]).toEqual value: 'require', scopes: ['source.php', 'meta.include.php', 'keyword.control.import.include.php']
389+
expect(tokens[2]).toEqual value: '"', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php', 'punctuation.definition.string.begin.php']
390+
expect(tokens[3]).toEqual value: 'foo.php', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php']
391+
expect(tokens[4]).toEqual value: '"', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php', 'punctuation.definition.string.end.php']
392+
393+
it 'should tokenize include_once correctly', ->
394+
{tokens} = grammar.tokenizeLine 'include_once "foo.php";'
395+
396+
expect(tokens[0]).toEqual value: 'include_once', scopes: ['source.php', 'meta.include.php', 'keyword.control.import.include.php']
397+
expect(tokens[2]).toEqual value: '"', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php', 'punctuation.definition.string.begin.php']
398+
expect(tokens[3]).toEqual value: 'foo.php', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php']
399+
expect(tokens[4]).toEqual value: '"', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php', 'punctuation.definition.string.end.php']
400+
401+
it 'should tokenize parentheses correctly', ->
402+
{tokens} = grammar.tokenizeLine 'include("foo.php");'
403+
404+
expect(tokens[0]).toEqual value: 'include', scopes: ['source.php', 'meta.include.php', 'keyword.control.import.include.php']
405+
expect(tokens[1]).toEqual value: '(', scopes: ['source.php', 'meta.include.php', 'punctuation.definition.begin.bracket.round.php']
406+
expect(tokens[2]).toEqual value: '"', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php', 'punctuation.definition.string.begin.php']
407+
expect(tokens[3]).toEqual value: 'foo.php', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php']
408+
expect(tokens[4]).toEqual value: '"', scopes: ['source.php', 'meta.include.php', 'string.quoted.double.php', 'punctuation.definition.string.end.php']
409+
expect(tokens[5]).toEqual value: ')', scopes: ['source.php', 'meta.include.php', 'punctuation.definition.end.bracket.round.php']
410+
377411
describe 'declaring namespaces', ->
378412
it 'tokenizes namespaces', ->
379413
{tokens} = grammar.tokenizeLine 'namespace Test;'

0 commit comments

Comments
 (0)