From 72f2f039dafea2b71484c84d3e56a099d6aff85b Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Sat, 5 Feb 2022 21:40:36 +1100 Subject: [PATCH 1/7] SQL: allow lowercase keywords to start SQL highlighting --- grammars/php.cson | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grammars/php.cson b/grammars/php.cson index a3e6868..abb57ec 100644 --- a/grammars/php.cson +++ b/grammars/php.cson @@ -2759,7 +2759,7 @@ 'match': '\\\\(?:\\\\(?:\\\\[\\\\\']?|[^\'])|.)' 'name': 'constant.character.escape.php' 'sql-string-double-quoted': - 'begin': '"\\s*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b)' + 'begin': '(?i:"\\s*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' 'beginCaptures': '0': 'name': 'punctuation.definition.string.begin.php' @@ -2828,7 +2828,7 @@ } ] 'sql-string-single-quoted': - 'begin': '\'\\s*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b)' + 'begin': '(?i:\'\\s*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' 'beginCaptures': '0': 'name': 'punctuation.definition.string.begin.php' From 47710082d1ffb3d9b47d0ecc51c82caa1cf00d45 Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Sat, 5 Feb 2022 22:20:54 +1100 Subject: [PATCH 2/7] SQL: allow SQL beginning with paranthesis to be highlighted --- grammars/php.cson | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grammars/php.cson b/grammars/php.cson index abb57ec..f7fd0b7 100644 --- a/grammars/php.cson +++ b/grammars/php.cson @@ -2759,7 +2759,7 @@ 'match': '\\\\(?:\\\\(?:\\\\[\\\\\']?|[^\'])|.)' 'name': 'constant.character.escape.php' 'sql-string-double-quoted': - 'begin': '(?i:"\\s*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' + 'begin': '(?i:"(?=\\s*\\(?\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' 'beginCaptures': '0': 'name': 'punctuation.definition.string.begin.php' @@ -2828,7 +2828,7 @@ } ] 'sql-string-single-quoted': - 'begin': '(?i:\'\\s*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' + 'begin': '(?i:\'(?=\\s*\\(?\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' 'beginCaptures': '0': 'name': 'punctuation.definition.string.begin.php' From 38178073de039c0d60878304968bc9af1117010d Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Sat, 5 Feb 2022 22:21:36 +1100 Subject: [PATCH 3/7] SQL: highlight on --sql hint at the start of a string --- grammars/php.cson | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grammars/php.cson b/grammars/php.cson index f7fd0b7..e5b4a27 100644 --- a/grammars/php.cson +++ b/grammars/php.cson @@ -2759,7 +2759,7 @@ 'match': '\\\\(?:\\\\(?:\\\\[\\\\\']?|[^\'])|.)' 'name': 'constant.character.escape.php' 'sql-string-double-quoted': - 'begin': '(?i:"(?=\\s*\\(?\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' + 'begin': '(?i:"(?=\\s*\\(?\\s*(--\\s*SQL|SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' 'beginCaptures': '0': 'name': 'punctuation.definition.string.begin.php' @@ -2828,7 +2828,7 @@ } ] 'sql-string-single-quoted': - 'begin': '(?i:\'(?=\\s*\\(?\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' + 'begin': '(?i:\'(?=\\s*\\(?\\s*(--\\s*SQL|SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' 'beginCaptures': '0': 'name': 'punctuation.definition.string.begin.php' From 165ae837cda10de25ecc66f1a3f5a1eff992ca38 Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Sun, 6 Feb 2022 13:18:18 +1100 Subject: [PATCH 4/7] SQL: Change `--sql` hint to be at least `-- sql` instead Since --sql is not a valid comment and will create errors if applying blindly. --- grammars/php.cson | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grammars/php.cson b/grammars/php.cson index e5b4a27..4b874c5 100644 --- a/grammars/php.cson +++ b/grammars/php.cson @@ -2759,7 +2759,7 @@ 'match': '\\\\(?:\\\\(?:\\\\[\\\\\']?|[^\'])|.)' 'name': 'constant.character.escape.php' 'sql-string-double-quoted': - 'begin': '(?i:"(?=\\s*\\(?\\s*(--\\s*SQL|SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' + 'begin': '(?i:"(?=\\s*\\(?\\s*(--\\s+SQL|SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' 'beginCaptures': '0': 'name': 'punctuation.definition.string.begin.php' @@ -2828,7 +2828,7 @@ } ] 'sql-string-single-quoted': - 'begin': '(?i:\'(?=\\s*\\(?\\s*(--\\s*SQL|SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' + 'begin': '(?i:\'(?=\\s*\\(?\\s*(--\\s+SQL|SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' 'beginCaptures': '0': 'name': 'punctuation.definition.string.begin.php' From d9899071c78710f22f6186e962c19a6d64e99cfa Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Thu, 10 Feb 2022 18:11:21 +1100 Subject: [PATCH 5/7] Update grammars/php.cson Co-authored-by: KapitanOczywisty <44417092+KapitanOczywisty@users.noreply.github.com> --- grammars/php.cson | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammars/php.cson b/grammars/php.cson index 4b874c5..9a91d7d 100644 --- a/grammars/php.cson +++ b/grammars/php.cson @@ -2759,7 +2759,7 @@ 'match': '\\\\(?:\\\\(?:\\\\[\\\\\']?|[^\'])|.)' 'name': 'constant.character.escape.php' 'sql-string-double-quoted': - 'begin': '(?i:"(?=\\s*\\(?\\s*(--\\s+SQL|SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' + 'begin': '(?i)"(?=\\s*\\(?\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b)' 'beginCaptures': '0': 'name': 'punctuation.definition.string.begin.php' From b82f7518ad4e0aaa4e87f25d657bec7114c0f026 Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Thu, 10 Feb 2022 18:11:28 +1100 Subject: [PATCH 6/7] Update grammars/php.cson Co-authored-by: KapitanOczywisty <44417092+KapitanOczywisty@users.noreply.github.com> --- grammars/php.cson | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammars/php.cson b/grammars/php.cson index 9a91d7d..bb89852 100644 --- a/grammars/php.cson +++ b/grammars/php.cson @@ -2828,7 +2828,7 @@ } ] 'sql-string-single-quoted': - 'begin': '(?i:\'(?=\\s*\\(?\\s*(--\\s+SQL|SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b))' + 'begin': '(?i)\'(?=\\s*\\(?\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|AND|WITH)\\b)' 'beginCaptures': '0': 'name': 'punctuation.definition.string.begin.php' From 169b9a49f7bc1b387bdb41a52bde6e8fb658ead2 Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Thu, 10 Feb 2022 18:39:32 +1100 Subject: [PATCH 7/7] SQL: Add tests for new behaviours - Check for case insensitivity which will allow for `Select`, `select` and sPoNgebOB notation keyword starters - Check for starting round brackets as it may also be used at times --- spec/php-spec.coffee | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/php-spec.coffee b/spec/php-spec.coffee index 73e4c8e..2918218 100644 --- a/spec/php-spec.coffee +++ b/spec/php-spec.coffee @@ -2948,6 +2948,24 @@ describe 'PHP grammar', -> expect(tokens[2]).toEqual value: ' something', scopes: ['source.php', scope, 'source.sql.embedded.php'] expect(tokens[3]).toEqual value: delim, scopes: ['source.php', scope, 'punctuation.definition.string.end.php'] + {tokens} = grammar.tokenizeLine "#{delim}sEleCT something#{delim}" + + # Case insensitive + expect(tokens[0]).toEqual value: delim, scopes: ['source.php', scope, 'punctuation.definition.string.begin.php'] + expect(tokens[1]).toEqual value: 'sEleCT', scopes: ['source.php', scope, 'source.sql.embedded.php', 'keyword.other.DML.sql'] + expect(tokens[2]).toEqual value: ' something', scopes: ['source.php', scope, 'source.sql.embedded.php'] + expect(tokens[3]).toEqual value: delim, scopes: ['source.php', scope, 'punctuation.definition.string.end.php'] + + {tokens} = grammar.tokenizeLine "#{delim}(select something)#{delim}" + + # Surrounded by brackets + expect(tokens[0]).toEqual value: delim, scopes: ['source.php', scope, 'punctuation.definition.string.begin.php'] + expect(tokens[1]).toEqual value: '(', scopes: ['source.php', scope, 'source.sql.embedded.php', 'punctuation.definition.section.bracket.round.begin.sql'] + expect(tokens[2]).toEqual value: 'select', scopes: ['source.php', scope, 'source.sql.embedded.php', 'keyword.other.DML.sql'] + expect(tokens[3]).toEqual value: ' something', scopes: ['source.php', scope, 'source.sql.embedded.php'] + expect(tokens[4]).toEqual value: ')', scopes: ['source.php', scope, 'source.sql.embedded.php', 'punctuation.definition.section.bracket.round.end.sql'] + expect(tokens[5]).toEqual value: delim, scopes: ['source.php', scope, 'punctuation.definition.string.end.php'] + lines = grammar.tokenizeLines """ #{delim}SELECT something -- uh oh a comment SELECT#{delim}