diff --git a/JavaScript/Embeddings/SQL (JS template).sublime-syntax b/JavaScript/Embeddings/SQL (JS template).sublime-syntax new file mode 100644 index 0000000000..2ddebb3dee --- /dev/null +++ b/JavaScript/Embeddings/SQL (JS template).sublime-syntax @@ -0,0 +1,18 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/syntax.html +# highlight tagged template strings +scope: source.sql.js-template +version: 2 +hidden: true + +extends: Packages/SQL/SQL.sublime-syntax + +contexts: + prototype: + - meta_prepend: true + - include: scope:source.js#text-interpolations + + strings-content: + - meta_prepend: true + - include: scope:source.js#string-interpolations diff --git a/JavaScript/Embeddings/SQL (TS template).sublime-syntax b/JavaScript/Embeddings/SQL (TS template).sublime-syntax new file mode 100644 index 0000000000..bcbef26074 --- /dev/null +++ b/JavaScript/Embeddings/SQL (TS template).sublime-syntax @@ -0,0 +1,18 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/syntax.html +# highlight tagged template strings +scope: source.sql.ts-template +version: 2 +hidden: true + +extends: Packages/SQL/SQL.sublime-syntax + +contexts: + prototype: + - meta_prepend: true + - include: scope:source.ts#text-interpolations + + strings-content: + - meta_prepend: true + - include: scope:source.ts#string-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 8001a9c727..bcf938b6ab 100644 --- a/JavaScript/tests/syntax_test_js_template.js +++ b/JavaScript/tests/syntax_test_js_template.js @@ -209,6 +209,51 @@ 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 */ + /* * Unknown Template */ diff --git a/JavaScript/tests/syntax_test_typescript_template.ts b/JavaScript/tests/syntax_test_typescript_template.ts index 5b3148f7bf..607ca142cc 100644 --- a/JavaScript/tests/syntax_test_typescript_template.ts +++ b/JavaScript/tests/syntax_test_typescript_template.ts @@ -225,6 +225,51 @@ 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 */ + /* * Unknown Template */