Skip to content

Commit

Permalink
[SQL] move heuristics for SQL inside Python and PHP strings to common…
Browse files Browse the repository at this point in the history
… syntax
  • Loading branch information
Keith Hall committed Jan 9, 2025
1 parent f615fed commit ba0b670
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
13 changes: 2 additions & 11 deletions PHP/PHP Source.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@ scope: source.php
hidden: true
version: 2

extends: Packages/SQL/SQL String Indicator.sublime-syntax

variables:
guarded_identifier: (?!{{reserved}}){{identifier}}
identifier: '{{identifier_start}}[[:alnum:]_]*'
identifier_start: '[[:alpha:]_]'

regex_modifier: '[eimsuxADJSUX]*'
sql_indicator: |-
(?x: \s* (?:
# dml statements
SELECT | INSERT | REPLACE | DELETE | TRUNCATE | UPDATE | MERGE\s+INTO
# ddl statements
| ADD | ALTER | CREATE | DROP
# conditional
| IF \s+ (?: NOT \s+ )? EXISTS
# declaration
| DECLARE | WITH | BEGIN
) \s )

# A pattern which terminates an incomplete expression at any point.
# `\?>` is for fixing one-liner ( https://github.com/sublimehq/Packages/issues/1545 )
Expand Down
14 changes: 2 additions & 12 deletions Python/Python.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ name: Python
scope: source.python
version: 2

extends: Packages/SQL/SQL String Indicator.sublime-syntax

file_extensions:
- py
- py3
Expand Down Expand Up @@ -60,18 +62,6 @@ variables:
# Prefer ranged quantifiers over python interpolation in raw f-strings
fstring_regexp_interpolation_begin: '\{(?!\d+(?:,\d*)?\})'

sql_indicator: |-
(?x: \s* (?:
# dml statements
SELECT | INSERT | REPLACE | DELETE | TRUNCATE | UPDATE | MERGE\s+INTO
# ddl statements
| ADD | ALTER | CREATE | DROP
# conditional
| IF \s+ (?: NOT \s+ )? EXISTS
# declaration
| DECLARE | WITH | BEGIN
) \s )
builtin_exceptions: |-
(?x:
ArithmeticError
Expand Down
22 changes: 22 additions & 0 deletions SQL/SQL String Indicator.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%YAML 1.2
---
# See http://www.sublimetext.com/docs/syntax.html
scope: source.sql.string
version: 2
hidden: true
variables:
sql_indicator: |-
(?x: \s* (?:
# dml statements
SELECT | INSERT | REPLACE | DELETE | TRUNCATE | UPDATE | MERGE\s+INTO
# ddl statements
| ADD | ALTER | CREATE | DROP
# conditional
| IF \s+ (?: NOT \s+ )? EXISTS
# declaration
| DECLARE | WITH | BEGIN
) \s )
contexts:
main:
- meta_append: true

0 comments on commit ba0b670

Please sign in to comment.