diff --git a/JavaScript/Embeddings/SQL (for JS template).sublime-syntax b/JavaScript/Embeddings/SQL (for JS template).sublime-syntax new file mode 100644 index 0000000000..207040cf31 --- /dev/null +++ b/JavaScript/Embeddings/SQL (for JS template).sublime-syntax @@ -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 diff --git a/JavaScript/Embeddings/SQL (for TS template).sublime-syntax b/JavaScript/Embeddings/SQL (for TS template).sublime-syntax new file mode 100644 index 0000000000..e0c82123ed --- /dev/null +++ b/JavaScript/Embeddings/SQL (for TS template).sublime-syntax @@ -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 diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index e9eb96bf20..035704d713 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -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 diff --git a/JavaScript/TypeScript.sublime-syntax b/JavaScript/TypeScript.sublime-syntax index 980fbacde6..844e88d513 100644 --- a/JavaScript/TypeScript.sublime-syntax +++ b/JavaScript/TypeScript.sublime-syntax @@ -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 diff --git a/JavaScript/tests/syntax_test_js_template.js b/JavaScript/tests/syntax_test_js_template.js index 4f5e5ba1b0..958ddabcee 100644 --- a/JavaScript/tests/syntax_test_js_template.js +++ b/JavaScript/tests/syntax_test_js_template.js @@ -267,6 +267,60 @@ var style = css`color:${color}`; /* ^ punctuation.terminator.statement.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 */ diff --git a/JavaScript/tests/syntax_test_typescript_template.ts b/JavaScript/tests/syntax_test_typescript_template.ts index 113e169a89..17c8221b46 100644 --- a/JavaScript/tests/syntax_test_typescript_template.ts +++ b/JavaScript/tests/syntax_test_typescript_template.ts @@ -266,6 +266,60 @@ var style = css`color:${color}`; /* ^ string.quoted.other.js punctuation.definition.string.end.js */ /* ^ punctuation.terminator.statement.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 */