Skip to content

Commit

Permalink
[SQL] split large match pattern into smaller ones/separate contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-hall committed Sep 19, 2021
1 parent c6eecfe commit c4ec9c3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Markdown/syntax_test_markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -2578,9 +2578,9 @@ okay
```sql
|^^^^^ meta.code-fence.definition.begin.sql
| ^^^ constant.other.language-name
SELECT TOP 10 *
|^^^^^^^^^^^^^^^ markup.raw.code-fence.sql
|^^^^^^^^^ keyword.other.DML.sql
SELECT 10 *
|^^^^^^^^^^^ markup.raw.code-fence.sql
|^^^^^ keyword.other.DML.sql
FROM TableName
```
|^^ meta.code-fence.definition.end.sql punctuation.definition.raw.code-fence.end - markup
Expand Down
10 changes: 10 additions & 0 deletions SQL/MySQL.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,13 @@ contexts:
- meta_append: true
- match: (?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b)
scope: keyword.other.LUW.sql

dml-statements:
- meta_append: true
- match: (?i)\b(?:using|limit)\b
scope: keyword.other.DML.sql

joins:
- meta_append: true
- match: (?i)\b(?:straight_join|natural)\b
scope: keyword.other.DML.sql
20 changes: 19 additions & 1 deletion SQL/SQL (basic).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,25 @@ contexts:
scope: keyword.other.authorization.sql

dml-statements:
- match: (?i:\b(select(\s+(distinct|top))?|insert(\s+(ignore\s+)?into)?|update|delete|truncate|from|set|where|group\s+by|with|union(\s+all)?|using|order\s+by|limit|(inner|cross)\s+join|join|straight_join|(left|right)(\s+outer)?\s+join|natural(\s+(left|right)(\s+outer)?)?\s+join)\b)
- match: (?i:\bselect\b)
scope: keyword.other.DML.sql
- match: (?i:\bunion(?:\s+all)?\b)
scope: keyword.other.DML.sql
- match: (?i:\b(?:insert(\s+(?:ignore\s+)?into)?|update|delete|truncate)\b)
scope: keyword.other.DML.sql
push: single-identifier
- match: (?i:\b(?:set|with)\b)
scope: keyword.other.DML.sql
- match: (?i:\bvalues\b)
scope: keyword.other.DML.II.sql
- include: joins
- match: \b(?i:distinct)\b
scope: keyword.other.DML.sql
- match: \b(?i:group\s+by|order\s+by|having|where)\b
scope: keyword.other.DML.sql
- match: \b(?i:from)\b
scope: keyword.other.DML.sql

joins:
- match: (?i)\b(?:inner|(?:full\s+)?outer|cross|left|right)\s+join\b
scope: keyword.other.DML.sql
2 changes: 2 additions & 0 deletions SQL/TSQL.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ contexts:
scope: keyword.other.tsql
- match: \b(?i:for\s+xml\s+path)\b
scope: keyword.other.tsql
- match: \b(?i:top)\b
scope: keyword.other.DML.tsql

built-in-scalar-function-calls:
- meta_append: true
Expand Down
3 changes: 2 additions & 1 deletion SQL/syntax_test_tsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ DECLARE @Example INT = 5
-- ^ constant.numeric

SELECT TOP 1 @Example = 4 FROM [dbo].[TableName]
-- ^^^^^^^ keyword.other.DML
-- ^^^ keyword.other.DML
-- ^^^ keyword.other.DML
-- ^ constant.numeric
-- ^^^^^^^^ variable.other.readwrite
-- ^ keyword.operator
Expand Down

0 comments on commit c4ec9c3

Please sign in to comment.