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

Commit 5535df5

Browse files
committed
Add DQL support
1 parent 36a073b commit 5535df5

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

grammars/php.cson

+2-2
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@
17071707
]
17081708
}
17091709
{
1710-
'begin': '(<<<)\\s*("?)(SQL)(\\2)(\\s*)$'
1710+
'begin': '(<<<)\\s*("?)((D|S)QL)(\\2)(\\s*)$'
17111711
'beginCaptures':
17121712
'0':
17131713
'name': 'punctuation.section.embedded.begin.php'
@@ -1985,7 +1985,7 @@
19851985
]
19861986
}
19871987
{
1988-
'begin': '(<<<)\\s*\'(SQL)\'(\\s*)$'
1988+
'begin': '(<<<)\\s*\'((D|S)QL)\'(\\s*)$'
19891989
'beginCaptures':
19901990
'0':
19911991
'name': 'punctuation.section.embedded.begin.php'

spec/php-spec.coffee

+68
Original file line numberDiff line numberDiff line change
@@ -3450,6 +3450,74 @@ describe 'PHP grammar', ->
34503450
expect(lines[2][0]).toEqual value: 'SQL', scopes: ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.end.php', 'keyword.operator.nowdoc.php']
34513451
expect(lines[2][1]).toEqual value: ';', scopes: ['source.php', 'punctuation.terminator.expression.php']
34523452

3453+
it 'should tokenize a heredoc with embedded DQL correctly', ->
3454+
waitsForPromise ->
3455+
atom.packages.activatePackage('language-sql')
3456+
3457+
runs ->
3458+
lines = grammar.tokenizeLines '''
3459+
$a = <<<DQL
3460+
SELECT * FROM table
3461+
DQL;
3462+
'''
3463+
3464+
expect(lines[0][0]).toEqual value: '$', scopes: ['source.php', 'variable.other.php', 'punctuation.definition.variable.php']
3465+
expect(lines[0][1]).toEqual value: 'a', scopes: ['source.php', 'variable.other.php']
3466+
expect(lines[0][2]).toEqual value: ' ', scopes: ['source.php']
3467+
expect(lines[0][3]).toEqual value: '=', scopes: ['source.php', 'keyword.operator.assignment.php']
3468+
expect(lines[0][4]).toEqual value: ' ', scopes: ['source.php']
3469+
expect(lines[0][5]).toEqual value: '<<<', scopes: ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.begin.php', 'punctuation.definition.string.php']
3470+
expect(lines[0][6]).toEqual value: 'DQL', scopes: ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.begin.php', 'keyword.operator.heredoc.php']
3471+
expect(lines[1][0].value).toEqual 'SELECT'
3472+
expect(lines[1][0].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
3473+
expect(lines[1][1].value).toEqual ' '
3474+
expect(lines[1][1].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
3475+
expect(lines[1][2].value).toEqual '*'
3476+
expect(lines[1][2].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
3477+
expect(lines[1][3].value).toEqual ' '
3478+
expect(lines[1][3].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
3479+
expect(lines[1][4].value).toEqual 'FROM'
3480+
expect(lines[1][4].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
3481+
expect(lines[1][5].value).toEqual ' table'
3482+
expect(lines[1][5].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
3483+
expect(lines[2][0]).toEqual value: 'DQL', scopes: ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.end.php', 'keyword.operator.heredoc.php']
3484+
expect(lines[2][1]).toEqual value: ';', scopes: ['source.php', 'punctuation.terminator.expression.php']
3485+
3486+
it 'should tokenize a nowdoc with embedded DQL correctly', ->
3487+
waitsForPromise ->
3488+
atom.packages.activatePackage('language-sql')
3489+
3490+
runs ->
3491+
lines = grammar.tokenizeLines '''
3492+
$a = <<<'DQL'
3493+
SELECT * FROM table
3494+
DQL;
3495+
'''
3496+
3497+
expect(lines[0][0]).toEqual value: '$', scopes: ['source.php', 'variable.other.php', 'punctuation.definition.variable.php']
3498+
expect(lines[0][1]).toEqual value: 'a', scopes: ['source.php', 'variable.other.php']
3499+
expect(lines[0][2]).toEqual value: ' ', scopes: ['source.php']
3500+
expect(lines[0][3]).toEqual value: '=', scopes: ['source.php', 'keyword.operator.assignment.php']
3501+
expect(lines[0][4]).toEqual value: ' ', scopes: ['source.php']
3502+
expect(lines[0][5]).toEqual value: '<<<', scopes: ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.begin.php', 'punctuation.definition.string.php']
3503+
expect(lines[0][6]).toEqual value: '\'', scopes: ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.begin.php']
3504+
expect(lines[0][7]).toEqual value: 'DQL', scopes: ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.begin.php', 'keyword.operator.nowdoc.php']
3505+
expect(lines[0][8]).toEqual value: '\'', scopes: ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.begin.php']
3506+
expect(lines[1][0].value).toEqual 'SELECT'
3507+
expect(lines[1][0].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
3508+
expect(lines[1][1].value).toEqual ' '
3509+
expect(lines[1][1].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
3510+
expect(lines[1][2].value).toEqual '*'
3511+
expect(lines[1][2].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
3512+
expect(lines[1][3].value).toEqual ' '
3513+
expect(lines[1][3].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
3514+
expect(lines[1][4].value).toEqual 'FROM'
3515+
expect(lines[1][4].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
3516+
expect(lines[1][5].value).toEqual ' table'
3517+
expect(lines[1][5].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
3518+
expect(lines[2][0]).toEqual value: 'DQL', scopes: ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.end.php', 'keyword.operator.nowdoc.php']
3519+
expect(lines[2][1]).toEqual value: ';', scopes: ['source.php', 'punctuation.terminator.expression.php']
3520+
34533521
it 'should tokenize a heredoc with embedded javascript correctly', ->
34543522
waitsForPromise ->
34553523
atom.packages.activatePackage('language-javascript')

0 commit comments

Comments
 (0)