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

Commit

Permalink
Add DQL support
Browse files Browse the repository at this point in the history
  • Loading branch information
eexit committed Jan 20, 2022
1 parent 36a073b commit 5535df5
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions grammars/php.cson
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@
]
}
{
'begin': '(<<<)\\s*("?)(SQL)(\\2)(\\s*)$'
'begin': '(<<<)\\s*("?)((D|S)QL)(\\2)(\\s*)$'
'beginCaptures':
'0':
'name': 'punctuation.section.embedded.begin.php'
Expand Down Expand Up @@ -1985,7 +1985,7 @@
]
}
{
'begin': '(<<<)\\s*\'(SQL)\'(\\s*)$'
'begin': '(<<<)\\s*\'((D|S)QL)\'(\\s*)$'
'beginCaptures':
'0':
'name': 'punctuation.section.embedded.begin.php'
Expand Down
68 changes: 68 additions & 0 deletions spec/php-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3450,6 +3450,74 @@ describe 'PHP grammar', ->
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']
expect(lines[2][1]).toEqual value: ';', scopes: ['source.php', 'punctuation.terminator.expression.php']

it 'should tokenize a heredoc with embedded DQL correctly', ->
waitsForPromise ->
atom.packages.activatePackage('language-sql')

runs ->
lines = grammar.tokenizeLines '''
$a = <<<DQL
SELECT * FROM table
DQL;
'''

expect(lines[0][0]).toEqual value: '$', scopes: ['source.php', 'variable.other.php', 'punctuation.definition.variable.php']
expect(lines[0][1]).toEqual value: 'a', scopes: ['source.php', 'variable.other.php']
expect(lines[0][2]).toEqual value: ' ', scopes: ['source.php']
expect(lines[0][3]).toEqual value: '=', scopes: ['source.php', 'keyword.operator.assignment.php']
expect(lines[0][4]).toEqual value: ' ', scopes: ['source.php']
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']
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']
expect(lines[1][0].value).toEqual 'SELECT'
expect(lines[1][0].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
expect(lines[1][1].value).toEqual ' '
expect(lines[1][1].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
expect(lines[1][2].value).toEqual '*'
expect(lines[1][2].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
expect(lines[1][3].value).toEqual ' '
expect(lines[1][3].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
expect(lines[1][4].value).toEqual 'FROM'
expect(lines[1][4].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
expect(lines[1][5].value).toEqual ' table'
expect(lines[1][5].scopes).toContainAll ['source.php', 'string.unquoted.heredoc.php', 'meta.embedded.sql', 'source.sql']
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']
expect(lines[2][1]).toEqual value: ';', scopes: ['source.php', 'punctuation.terminator.expression.php']

it 'should tokenize a nowdoc with embedded DQL correctly', ->
waitsForPromise ->
atom.packages.activatePackage('language-sql')

runs ->
lines = grammar.tokenizeLines '''
$a = <<<'DQL'
SELECT * FROM table
DQL;
'''

expect(lines[0][0]).toEqual value: '$', scopes: ['source.php', 'variable.other.php', 'punctuation.definition.variable.php']
expect(lines[0][1]).toEqual value: 'a', scopes: ['source.php', 'variable.other.php']
expect(lines[0][2]).toEqual value: ' ', scopes: ['source.php']
expect(lines[0][3]).toEqual value: '=', scopes: ['source.php', 'keyword.operator.assignment.php']
expect(lines[0][4]).toEqual value: ' ', scopes: ['source.php']
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']
expect(lines[0][6]).toEqual value: '\'', scopes: ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.begin.php']
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']
expect(lines[0][8]).toEqual value: '\'', scopes: ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'punctuation.section.embedded.begin.php']
expect(lines[1][0].value).toEqual 'SELECT'
expect(lines[1][0].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
expect(lines[1][1].value).toEqual ' '
expect(lines[1][1].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
expect(lines[1][2].value).toEqual '*'
expect(lines[1][2].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
expect(lines[1][3].value).toEqual ' '
expect(lines[1][3].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
expect(lines[1][4].value).toEqual 'FROM'
expect(lines[1][4].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
expect(lines[1][5].value).toEqual ' table'
expect(lines[1][5].scopes).toContainAll ['source.php', 'string.unquoted.nowdoc.php', 'meta.embedded.sql', 'source.sql']
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']
expect(lines[2][1]).toEqual value: ';', scopes: ['source.php', 'punctuation.terminator.expression.php']

it 'should tokenize a heredoc with embedded javascript correctly', ->
waitsForPromise ->
atom.packages.activatePackage('language-javascript')
Expand Down

0 comments on commit 5535df5

Please sign in to comment.