Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JavaScript] Add SQL embedding #4094

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions JavaScript/Embeddings/SQL (for JS template).sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
# highlight tagged template strings
scope: source.sql.js-template
version: 1
hidden: true

extends: Packages/SQL/SQL.sublime-syntax

contexts:
prototype:
- meta_prepend: true
- include: scope:source.js#text-interpolations
14 changes: 14 additions & 0 deletions JavaScript/Embeddings/SQL (for TS template).sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
# highlight tagged template strings
scope: source.sql.ts-template
version: 1
hidden: true

extends: Packages/SQL/SQL.sublime-syntax

contexts:
prototype:
- meta_prepend: true
- include: scope:source.ts#text-interpolations
12 changes: 12 additions & 0 deletions JavaScript/JavaScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,18 @@ contexts:
0: meta.string.template.js string.quoted.other.js
1: punctuation.definition.string.end.js
pop: 1
- match: (sql|SQL)\s*((\`){{trailing_wspace}}?)
captures:
1: variable.function.tagged-template.js
2: meta.string.template.js string.quoted.other.js
3: punctuation.definition.string.begin.js
embed: scope:source.sql.js-template
embed_scope: meta.string.template.js source.sql.embedded.js
escape: '{{leading_wspace}}?(\`)'
escape_captures:
0: meta.string.template.js string.quoted.other.js
1: punctuation.definition.string.end.js
pop: 1
- match: (?:({{identifier_name}})\s*)?(\`)
captures:
1: variable.function.tagged-template.js
Expand Down
12 changes: 12 additions & 0 deletions JavaScript/TypeScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,18 @@ contexts:
0: meta.string.template.js string.quoted.other.js
1: punctuation.definition.string.end.js
pop: 1
- match: (sql|SQL)\s*((\`){{trailing_wspace}}?)
captures:
1: variable.function.tagged-template.js
2: meta.string.template.js string.quoted.other.js
3: punctuation.definition.string.begin.js
embed: scope:source.sql.ts-template
embed_scope: meta.string.template.js source.sql.embedded.js
escape: '{{leading_wspace}}?(\`)'
escape_captures:
0: meta.string.template.js string.quoted.other.js
1: punctuation.definition.string.end.js
pop: 1
- match: (?:({{identifier_name}})\s*)?(\`)
captures:
1: variable.function.tagged-template.js
Expand Down
54 changes: 54 additions & 0 deletions JavaScript/tests/syntax_test_js_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,60 @@ var style = css`
/* ^ punctuation.definition.string.end.js */
/* ^ - meta.string */

/*
* SQL Templates
*/

var sql = sql`SELECT * FROM "foo";`
/* ^^^^^^^^^^^^^^^^^^^^^^ meta.string.template.js */
/* ^ string.quoted.other.js punctuation.definition.string.begin.js - source.sql.embedded */
/* ^^^^^^^^^^^^^^^^^^^^ source.sql.embedded.js */
/* ^ string.quoted.other.js punctuation.definition.string.end.js - source.sql.embedded */


var sql = SQL`SELECT * FROM "foo";`
/* ^^^^^^^^^^^^^^^^^^^^^^ meta.string.template.js */
/* ^ string.quoted.other.js punctuation.definition.string.begin.js - source.sql.embedded */
/* ^^^^^^^^^^^^^^^^^^^^ source.sql.embedded.js */
/* ^ string.quoted.other.js punctuation.definition.string.end.js - source.sql.embedded */

var sql = sql`
/* ^^^ variable.function.tagged-template */
/* ^^ meta.string.template.js string.quoted.other.js */
/* ^ punctuation.definition.string.begin.js */
/* ^ - source.sql.embedded */

SELECT *,
/* ^^^ keyword.other.DML.sql */
/* ^ constant.other.wildcard.asterisk.sql */
f.id AS database_id
/* ^^ keyword.operator.assignment.alias.sql */
FROM foo
WHERE f.a IS NULL
/* ^^ keyword.other.DML.sql */
/* ^^ keyword.operator.logical.sql */
/* ^^^^ constant.language.null.sql */
AND f.b IS NOT NULL
/* ^^^ keyword.operator.logical.sql */
/* ^^ keyword.operator.logical.sql */
/* ^^^ keyword.operator.logical.sql */
/* ^^^^ constant.language.null.sql */

`
/* <- meta.string.template.js string.quoted.other.js - source.sql.embedded */
/*^^^ meta.string.template.js string.quoted.other.js - source.sql.embedded */
/* ^ punctuation.definition.string.end.js */
/* ^ - meta.string */

var sql = sql`SELECT * FROM ${users};`
/* ^^^^^^^^^^^^^^ meta.string.template.js source.sql.embedded.js - meta.interpolation.js */
/* ^^^^^^^^ meta.string.template.js source.sql.embedded.js meta.interpolation.js */
/* ^^ punctuation.section.interpolation.begin.js */
/* ^^^^^ source.js.embedded variable.other.readwrite.js */
/* ^ punctuation.section.interpolation.end.js */
/* ^ punctuation.terminator.statement.sql - meta.interpolation.js */
/* ^ string.quoted.other.js punctuation.definition.string.end.js */

/*
* Unknown Template
*/
Expand Down
54 changes: 54 additions & 0 deletions JavaScript/tests/syntax_test_typescript_template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,60 @@ var style = css`
/* ^ punctuation.definition.string.end.js */
/* ^ - meta.string */

/*
* SQL Templates
*/

var sql = sql`SELECT * FROM "foo";`
/* ^^^^^^^^^^^^^^^^^^^^^^ meta.string.template.js */
/* ^ string.quoted.other.js punctuation.definition.string.begin.js - source.sql.embedded */
/* ^^^^^^^^^^^^^^^^^^^^ source.sql.embedded.js */
/* ^ string.quoted.other.js punctuation.definition.string.end.js - source.sql.embedded */


var sql = SQL`SELECT * FROM "foo";`
/* ^^^^^^^^^^^^^^^^^^^^^^ meta.string.template.js */
/* ^ string.quoted.other.js punctuation.definition.string.begin.js - source.sql.embedded */
/* ^^^^^^^^^^^^^^^^^^^^ source.sql.embedded.js */
/* ^ string.quoted.other.js punctuation.definition.string.end.js - source.sql.embedded */

var sql = sql`
/* ^^^ variable.function.tagged-template */
/* ^^ meta.string.template.js string.quoted.other.js */
/* ^ punctuation.definition.string.begin.js */
/* ^ - source.sql.embedded */

SELECT *,
/* ^^^ keyword.other.DML.sql */
/* ^ constant.other.wildcard.asterisk.sql */
f.id AS database_id
/* ^^ keyword.operator.assignment.alias.sql */
FROM foo
WHERE f.a IS NULL
/* ^^ keyword.other.DML.sql */
/* ^^ keyword.operator.logical.sql */
/* ^^^^ constant.language.null.sql */
AND f.b IS NOT NULL
/* ^^^ keyword.operator.logical.sql */
/* ^^ keyword.operator.logical.sql */
/* ^^^ keyword.operator.logical.sql */
/* ^^^^ constant.language.null.sql */

`
/* <- meta.string.template.js string.quoted.other.js - source.sql.embedded */
/*^^^ meta.string.template.js string.quoted.other.js - source.sql.embedded */
/* ^ punctuation.definition.string.end.js */
/* ^ - meta.string */

var sql = sql`SELECT * FROM ${users};`
/* ^^^^^^^^^^^^^^ meta.string.template.js source.sql.embedded.js - meta.interpolation.js */
/* ^^^^^^^^ meta.string.template.js source.sql.embedded.js meta.interpolation.js */
/* ^^ punctuation.section.interpolation.begin.js */
/* ^^^^^ source.js.embedded variable.other.readwrite.js */
/* ^ punctuation.section.interpolation.end.js */
/* ^ punctuation.terminator.statement.sql - meta.interpolation.js */
/* ^ string.quoted.other.js punctuation.definition.string.end.js */

/*
* Unknown Template
*/
Expand Down