From b2dda769d0757d0950f6854cd5e42243126f9033 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Thu, 16 Sep 2021 22:52:03 +0300 Subject: [PATCH 001/250] [SQL] use inheritance to support different dialects --- SQL/MySQL.sublime-syntax | 112 ++++++++++ SQL/SQL (basic).sublime-syntax | 221 +++++++++++++++++++ SQL/SQL.sublime-syntax | 377 +-------------------------------- SQL/TSQL.sublime-syntax | 147 +++++++++++++ SQL/syntax_test_mysql.sql | 192 +++++++++++++++++ SQL/syntax_test_sql.sql | 312 --------------------------- SQL/syntax_test_tsql.sql | 147 +++++++++++++ 7 files changed, 822 insertions(+), 686 deletions(-) create mode 100644 SQL/MySQL.sublime-syntax create mode 100644 SQL/SQL (basic).sublime-syntax create mode 100644 SQL/TSQL.sublime-syntax create mode 100644 SQL/syntax_test_mysql.sql delete mode 100644 SQL/syntax_test_sql.sql create mode 100644 SQL/syntax_test_tsql.sql diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax new file mode 100644 index 0000000000..b3d6fafae9 --- /dev/null +++ b/SQL/MySQL.sublime-syntax @@ -0,0 +1,112 @@ +%YAML 1.2 +--- +name: MySQL +scope: source.sql.mysql +version: 2 +extends: Packages/SQL/SQL (basic).sublime-syntax + +contexts: + main: + - meta_append: true + - include: regexps + + strings: + - meta_append: true + - match: "`" + scope: punctuation.definition.string.begin.sql + push: + - meta_include_prototype: false + - meta_scope: string.quoted.other.backtick.sql + - match: "`" + scope: punctuation.definition.string.end.sql + pop: true + - include: string-escape + - match: '"' + scope: punctuation.definition.string.begin.sql + push: + - meta_include_prototype: false + - meta_scope: string.quoted.double.sql + - match: '""' + scope: constant.character.escape.sql + - match: '"' + scope: punctuation.definition.string.end.sql + pop: true + - include: string-interpolation + - include: begin-interpolation + + begin-interpolation: + - match: '%\{' + scope: punctuation.definition.string.begin.sql + push: + - meta_include_prototype: false + - meta_scope: string.other.quoted.brackets.sql + - match: '\}' + scope: punctuation.definition.string.end.sql + pop: true + - include: string-interpolation + + string-interpolation: + - meta_include_prototype: false + - match: '(#\{)([^\}]*)(\})' + scope: string.interpolated.sql + captures: + 1: punctuation.definition.string.begin.sql + 3: punctuation.definition.string.end.sql + + regexps: + - match: /(?=\S.*/) + scope: punctuation.definition.string.begin.sql + push: + - meta_include_prototype: false + - meta_scope: string.regexp.sql + - match: / + scope: punctuation.definition.string.end.sql + pop: true + - include: string-interpolation + - match: \\/ + scope: constant.character.escape.slash.sql + + operators: + - meta_append: true + - match: \|\| + scope: keyword.operator.concatenation.sql + + types: + - match: |- + (?xi) + + # normal stuff, capture 1 + \b(bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|int|integer|line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext)\b + + # numeric suffix, capture 2 + 3i + |\b(bit\svarying|character\s+(?:varying)?|tinyint|var\schar|float|interval)\((\d+)\) + + # optional numeric suffix, capture 4 + 5i + |\b(char|number|nvarchar|varbinary|varchar\d?)\b(?:\((\d+)\))? + + # special case, capture 6 + 7i + 8i + |\b(numeric|decimal)\b(?:\((\d+),(\d+)\))? + + # special case, captures 9, 10i, 11 + |\b(times?)\b(?:\((\d+)\))?(\swith(?:out)?\s+time\s+zone\b)? + + # special case, captures 12, 13, 14i, 15 + |\b(timestamp)(?:(s|tz))?\b(?:\((\d+)\))?(\s(with|without)\s+time\s+zone\b)? + + + captures: + 1: storage.type.sql + 2: storage.type.sql + 3: constant.numeric.sql + 4: storage.type.sql + 5: constant.numeric.sql + 6: storage.type.sql + 7: constant.numeric.sql + 8: constant.numeric.sql + 9: storage.type.sql + 10: constant.numeric.sql + 11: storage.type.sql + 12: storage.type.sql + 13: storage.type.sql + 14: constant.numeric.sql + 15: storage.type.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax new file mode 100644 index 0000000000..34a7a6b427 --- /dev/null +++ b/SQL/SQL (basic).sublime-syntax @@ -0,0 +1,221 @@ +%YAML 1.2 +--- +name: SQL (Basic) +scope: source.sql.basic +hidden: true +version: 2 + +variables: + string_escape: (?:\\.) + dml_targets: (?:aggregate|conversion|database|domain|function|group|((?:fulltext|spatial|unique)\s+)?index|language|operator class|operator|procedure|rule|schema|sequence|table(?:space)?|trigger|type|user|view) + +contexts: + prototype: + - include: comments + + main: + - match: |- + (?xi) + \b(create(?:\s+or\s+replace)?)\s+ + ({{dml_targets}}) + \b\s* + (on)?\b + scope: meta.create.sql + captures: + 1: keyword.other.create.sql + 2: keyword.other.sql + 3: keyword.other.sql + push: create-condition + - match: (?i:\s*\b(drop)\s+({{dml_targets}})) + scope: meta.drop.sql + captures: + 1: keyword.other.create.sql + 2: keyword.other.sql + push: drop-condition + - match: (?i:\s*(drop)\s+(table)\s+(\w+)(\s+cascade)?\b) + scope: meta.drop.sql + captures: + 1: keyword.other.create.sql + 2: keyword.other.table.sql + 3: entity.name.function.sql + 4: keyword.other.cascade.sql + - match: (?i:\s*\b(alter)\s+{{dml_targets}}\s+) + scope: meta.alter.sql + captures: + 1: keyword.other.create.sql + 2: keyword.other.table.sql + - match: (?i:\s*\b(add)\s+(column|constraint|fulltext\s+(index|key)|index|spatial\s+(index|key))) + scope: meta.add.sql + captures: + 1: keyword.other.add.sql + 2: keyword.other.sql + - include: types + - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) + scope: storage.modifier.sql + - match: \b\d+\b + scope: constant.numeric.sql + - match: (?i:\b(true|false)\b) + scope: constant.language.boolean.sql + - match: (?i:\b(null)\b) + scope: constant.language.null.sql + - match: (?i:\b(select(\s+(distinct|top))?|insert(\s+(ignore\s+)?into)?|update|delete|truncate|from|set|where|group\s+by|with|case|when|then|else|end|union(\s+all)?|using|order\s+by|limit|(inner|cross)\s+join|join|straight_join|(left|right)(\s+outer)?\s+join|natural(\s+(left|right)(\s+outer)?)?\s+join)\b) + scope: keyword.other.DML.sql + - include: operators + - match: (?i:\bvalues\b) + scope: keyword.other.DML.II.sql + - match: (?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b) + scope: keyword.other.LUW.sql + - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) + scope: keyword.other.authorization.sql + - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) + scope: keyword.other.object-comments.sql + - match: (?i)\bas\b + scope: keyword.operator.assignment.alias.sql + - match: (?i)\b(asc|desc)\b + scope: keyword.other.order.sql + - match: \* + scope: variable.language.wildcard.asterisk.sql + - match: (?i)\b(CURRENT_(DATE|TIME(STAMP)?|USER)|(SESSION|SYSTEM)_USER)\b + comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + scope: support.function.scalar.sql + - match: (?i)\b(AVG|COUNT|MIN|MAX|SUM)(?=\s*\() + comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + scope: support.function.aggregate.sql + - match: (?i)\b(CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b + scope: support.function.string.sql + - include: strings + - match: (\()(\)) + comment: Allow for special ↩ behavior + scope: meta.block.sql + captures: + 1: punctuation.section.scope.begin.sql + 2: punctuation.section.scope.end.sql + - match: ',' + scope: punctuation.separator.sequence.sql + - match: ';' + scope: punctuation.terminator.statement.sql + + comments: + - meta_include_prototype: false + - match: '--' + scope: punctuation.definition.comment.sql + push: inside-double-dash-comment + - match: '#' + scope: punctuation.definition.comment.sql + push: inside-number-sign-comment + - match: /\* + scope: punctuation.definition.comment.begin.sql + push: inside-comment-block + + inside-double-dash-comment: + - meta_include_prototype: false + - meta_scope: comment.line.double-dash.sql + - match: \n + pop: true + + inside-number-sign-comment: + - meta_include_prototype: false + - meta_scope: comment.line.number-sign.sql + - match: \n + pop: true + + inside-comment-block: + - meta_include_prototype: false + - meta_scope: comment.block.sql + - match: \*/ + scope: punctuation.definition.comment.end.sql + pop: true + - match: ^\s*(\*)(?!/) + captures: + 1: punctuation.definition.comment.sql + + string-escape: + - meta_include_prototype: false + - match: '{{string_escape}}' + scope: constant.character.escape.sql + + strings: + - match: \' + scope: punctuation.definition.string.begin.sql + push: single-quoted-string + + single-quoted-string: + - meta_include_prototype: false + - meta_scope: string.quoted.single.sql + - match: (?:'') + scope: constant.character.escape.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: true + - include: string-escape + + identifier-create: + - meta_scope: meta.toc-list.full-identifier.sql entity.name.function.sql + - include: identifier + + identifier: + - include: simple-identifier + - include: single-quoted-identifier + - include: double-quoted-identifier + - include: backtick-quoted-identifier + - match: \. + scope: punctuation.accessor.dot.sql + - match: (?=\S|\s*\() + pop: true + + simple-identifier: + - match: \w+(?=\s*\.) + - match: \w+ + pop: true + + single-quoted-identifier: + - match: (')([^']+)(') + captures: + 1: punctuation.definition.identifier.begin.sql + 3: punctuation.definition.identifier.end.sql + + double-quoted-identifier: + - match: (")([^"]+)(") + captures: + 1: punctuation.definition.identifier.begin.sql + 3: punctuation.definition.identifier.end.sql + + backtick-quoted-identifier: + - match: (`)([^`]+)(`) + captures: + 1: punctuation.definition.identifier.begin.sql + 3: punctuation.definition.identifier.end.sql + + create-condition: + - include: dml-condition + - match: (?=\S) + set: identifier-create + + drop-condition: + - include: dml-condition + - match: (?=\S) + pop: true + + dml-condition: + - match: (?i:\b(if)\b) + scope: keyword.control.flow.sql + - include: logical-operators + + logical-operators: + - match: (?i:\b(and|or|having|exists|between|in|not|is)\b) + scope: keyword.operator.logical.sql + + operators: + - match: '<=>|[!<>]?=|<>|<|>' + scope: keyword.operator.comparison.sql + - match: '-|\+|/' + scope: keyword.operator.arithmetic.sql + - include: logical-operators + + types: + - match: \b(?i:bit|bool|boolean|datetime|int)\b + scope: storage.type.sql + - match: \b(?i:char|number|nvarchar|varbinary|varchar)\b(?:\s*\((\d+)\))? + captures: + 1: storage.type.sql + 2: constant.numeric.sql diff --git a/SQL/SQL.sublime-syntax b/SQL/SQL.sublime-syntax index 71f8a6935d..3306dd4409 100644 --- a/SQL/SQL.sublime-syntax +++ b/SQL/SQL.sublime-syntax @@ -6,380 +6,9 @@ file_extensions: - ddl - dml scope: source.sql - -variables: - end_identifier: (?=[ \t]*(?:[^\w'"`. \t]|$)) +version: 2 contexts: - prototype: - - include: comments main: - - match: |- - (?xi) - \b(create(?:\s+or\s+replace)?)\s+ - (aggregate|conversion|database|domain|function|group|((?:fulltext|spatial|unique)\s+)?index|language|operator class|operator|procedure|rule|schema|sequence|table(?:space)?|trigger|type|user|view) - \b\s* - scope: meta.create.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.sql - push: create-condition - - match: (?i:\s*\b(drop)\s+(aggregate|conversion|database|domain|function|group|index|language|operator class|operator|procedure|rule|schema|sequence|table|tablespace|trigger|type|user|view)) - scope: meta.drop.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.sql - push: drop-condition - - match: (?i:\s*(drop)\s+(table)\s+(\w+)(\s+cascade)?\b) - scope: meta.drop.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.table.sql - 3: entity.name.function.sql - 4: keyword.other.cascade.sql - - match: (?i:\s*\b(alter)\s+(aggregate|conversion|database|domain|function|group|index|language|operator class|operator|procedure|rule|schema|sequence|table|tablespace|trigger|type|user|view)\s+) - scope: meta.alter.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.table.sql - - match: (?i:\s*\b(add)\s+(column|constraint|fulltext\s+(index|key)|index|spatial\s+(index|key))) - scope: meta.add.sql - captures: - 1: keyword.other.add.sql - 2: keyword.other.sql - - match: |- - (?xi) - - # normal stuff, capture 1 - \b(bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|int|integer|line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext)\b - - # numeric suffix, capture 2 + 3i - |\b(bit\svarying|character\s+(?:varying)?|tinyint|var\schar|float|interval)\((\d+)\) - - # optional numeric suffix, capture 4 + 5i - |\b(char|number|nvarchar|varbinary|varchar\d?)\b(?:\((\d+)\))? - - # special case, capture 6 + 7i + 8i - |\b(numeric|decimal)\b(?:\((\d+),(\d+)\))? - - # special case, captures 9, 10i, 11 - |\b(times?)\b(?:\((\d+)\))?(\swith(?:out)?\s+time\s+zone\b)? - - # special case, captures 12, 13, 14i, 15 - |\b(timestamp)(?:(s|tz))?\b(?:\((\d+)\))?(\s(with|without)\s+time\s+zone\b)? - - - captures: - 1: storage.type.sql - 2: storage.type.sql - 3: constant.numeric.sql - 4: storage.type.sql - 5: constant.numeric.sql - 6: storage.type.sql - 7: constant.numeric.sql - 8: constant.numeric.sql - 9: storage.type.sql - 10: constant.numeric.sql - 11: storage.type.sql - 12: storage.type.sql - 13: storage.type.sql - 14: constant.numeric.sql - 15: storage.type.sql - - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) - scope: storage.modifier.sql - - match: \b\d+\b - scope: constant.numeric.sql - - match: (?i:\b(true|false)\b) - scope: constant.language.boolean.sql - - match: (?i:\b(null)\b) - scope: constant.language.null.sql - - match: (?i:\b(select(\s+(distinct|top))?|insert(\s+(ignore\s+)?into)?|update|delete|truncate|from|set|where|group\s+by|with|case|when|then|else|end|union(\s+all)?|using|order\s+by|limit|(inner|cross)\s+join|join|straight_join|(left|right)(\s+outer)?\s+join|natural(\s+(left|right)(\s+outer)?)?\s+join)\b) - scope: keyword.other.DML.sql - - include: logical-operators - - match: (?i:\blike\b) - scope: keyword.operator.logical.sql - branch_point: like-strings-branch - branch: - - like-string-not-followed-by-escape - - like-string-followed-by-escape-slash - - like-string-followed-by-escape-caret - - like-string-followed-by-unknown-escape - - match: (?i:\bvalues\b) - scope: keyword.other.DML.II.sql - - match: (?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b) - scope: keyword.other.LUW.sql - - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) - scope: keyword.other.authorization.sql - - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) - scope: keyword.other.object-comments.sql - - match: (?i)\bas\b - scope: keyword.operator.assignment.alias.sql - - match: (?i)\b(asc|desc)\b - scope: keyword.other.order.sql - - match: \* - scope: variable.language.wildcard.asterisk.sql - - match: "<=>|[!<>]?=|<>|<|>" - scope: keyword.operator.comparison.sql - - match: '-|\+|/' - scope: keyword.operator.arithmetic.sql - - match: \|\| - scope: keyword.operator.concatenation.sql - - match: (?i)\b(CURRENT_(DATE|TIME(STAMP)?|USER)|(SESSION|SYSTEM)_USER)\b - comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - scope: support.function.scalar.sql - - match: (?i)\b(AVG|COUNT|MIN|MAX|SUM)(?=\s*\() - comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - scope: support.function.aggregate.sql - - match: (?i)\b(CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b - scope: support.function.string.sql - - match: \b(\w+?)\.(\w+)\b - captures: - 1: constant.other.database-name.sql - 2: constant.other.table-name.sql - - include: strings - - include: regexps - - match: (\()(\)) - comment: Allow for special ↩ behavior - scope: meta.block.sql - captures: - 1: punctuation.section.scope.begin.sql - 2: punctuation.section.scope.end.sql - - match: (?i)\bon\b - scope: keyword.operator.word.sql - - match: ',' - scope: punctuation.separator.sequence.sql - - match: ';' - scope: punctuation.terminator.statement.sql - comments: - - meta_include_prototype: false - - match: '--' - scope: punctuation.definition.comment.sql - push: inside-double-dash-comment - - match: '#' - scope: punctuation.definition.comment.sql - push: inside-number-sign-comment - - match: /\* - scope: punctuation.definition.comment.begin.sql - push: inside-comment-block - inside-double-dash-comment: - - meta_include_prototype: false - - meta_scope: comment.line.double-dash.sql - - match: \n - pop: true - inside-number-sign-comment: - - meta_include_prototype: false - - meta_scope: comment.line.number-sign.sql - - match: \n - pop: true - inside-comment-block: - - meta_include_prototype: false - - meta_scope: comment.block.sql - - match: \*/ - scope: punctuation.definition.comment.end.sql - pop: true - - match: ^\s*(\*)(?!/) - captures: - 1: punctuation.definition.comment.sql - regexps: - - match: /(?=\S.*/) - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.regexp.sql - - match: / - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation - - match: \\/ - scope: constant.character.escape.slash.sql - - match: '%r\{' - comment: We should probably handle nested bracket pairs!?! -- Allan - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.regexp.modr.sql - - match: '\}' - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation - string-escape: - - meta_include_prototype: false - - match: \\. - scope: constant.character.escape.sql - string-interpolation: - - meta_include_prototype: false - - match: '(#\{)([^\}]*)(\})' - scope: string.interpolated.sql - captures: - 1: punctuation.definition.string.begin.sql - 3: punctuation.definition.string.end.sql - strings: - - match: "'" - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.quoted.single.sql - - match: "''" - scope: constant.character.escape.sql - - match: "'" - scope: punctuation.definition.string.end.sql - pop: true - - include: string-escape - - match: "`" - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.quoted.other.backtick.sql - - match: "`" - scope: punctuation.definition.string.end.sql - pop: true - - include: string-escape - - match: '"' - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.quoted.double.sql - - match: '""' - scope: constant.character.escape.sql - - match: '"' - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation - - match: '%\{' - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.other.quoted.brackets.sql - - match: '\}' - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation - identifier-create: - - meta_content_scope: meta.toc-list.full-identifier.sql - - match: '(?:(\w+)|''([^'']+)''|"([^"]+)"|`([^`]+)`){{end_identifier}}' - scope: meta.toc-list.full-identifier.sql - captures: - 1: entity.name.function.sql - 2: entity.name.function.sql - 3: entity.name.function.sql - 4: entity.name.function.sql - pop: true - # Schema identifiers - - match: (?:\w+|'[^']+'|"[^"]+"|`[^`]+`)\s*(\.) - captures: - 1: punctuation.accessor.dot.sql - # Handle situations where the schema and . - - match: '{{end_identifier}}' - pop: true - create-condition: - - include: dml-condition - - match: (?=\S) - set: identifier-create - drop-condition: - - include: dml-condition - - match: (?=\S) - pop: true - dml-condition: - - match: (?i:\b(if)\b) - scope: keyword.control.flow.sql - - include: logical-operators - logical-operators: - - match: (?i:\b(and|or|having|exists|between|in|not|is)\b) - scope: keyword.operator.logical.sql - like-string-not-followed-by-escape: - - match: \' - scope: punctuation.definition.string.begin.sql - set: [like-escape-fail, inside-like-single-quoted-string] - - match: (?=\S) - pop: true - like-string-followed-by-escape-slash: - - match: \' - scope: punctuation.definition.string.begin.sql - set: [like-escape-character-slash, like-escape-pop, inside-like-single-quoted-string-slash-escape] - - match: (?=\S) - pop: true - like-string-followed-by-escape-caret: - - match: \' - scope: punctuation.definition.string.begin.sql - set: [like-escape-character-caret, like-escape-pop, inside-like-single-quoted-string-caret-escape] - - match: (?=\S) - pop: true - like-string-followed-by-unknown-escape: - - match: \' - scope: punctuation.definition.string.begin.sql - set: [like-escape-character-any, like-escape-pop, inside-like-single-quoted-string] - - match: (?=\S) - pop: true - inside-like-single-quoted-string-slash-escape: - - meta_include_prototype: false - - meta_scope: meta.string.like.sql string.quoted.single.sql - - match: \\. - scope: constant.character.escape.sql - - include: inside-like-single-quoted-string - inside-like-single-quoted-string-caret-escape: - - meta_include_prototype: false - - meta_scope: meta.string.like.sql string.quoted.single.sql - - match: \^. - scope: constant.character.escape.sql - - include: inside-like-single-quoted-string - inside-like-single-quoted-string: - - meta_include_prototype: false - - meta_scope: meta.string.like.sql string.quoted.single.sql - - match: \' - scope: punctuation.definition.string.end.sql - pop: true - - match: |- - (?x) - (\[)(\^)? - (?:.|[^]'-]+?) - (?:(-)[^]'-]*)? - (\]) - scope: meta.set.like.sql - captures: - 1: keyword.control.set.begin.sql - 2: keyword.control.set.negation.sql - 3: constant.other.range.sql - 4: keyword.control.set.end.sql - - match: '[%_]' - scope: keyword.operator.wildcard.sql - like-escape-fail: - - match: (?i:\bescape\b) - fail: like-strings-branch - - match: (?=\S) - pop: true - like-escape-pop: - - match: (?i:\bescape\b) - scope: keyword.operator.word.sql - pop: true - - match: (?=\S) - pop: true - like-escape-character-any: - - match: (\')([^'])(\') - captures: - 0: meta.string.escape.sql string.quoted.single.sql - 1: punctuation.definition.string.begin.sql - 2: constant.character.escape.sql - 3: punctuation.definition.string.end.sql - pop: true - - match: (?=\S) - pop: true - like-escape-character-caret: - - match: (\')(\^)(\') - captures: - 0: meta.string.escape.sql string.quoted.single.sql - 1: punctuation.definition.string.begin.sql - 2: constant.character.escape.sql - 3: punctuation.definition.string.end.sql - pop: true - - match: (?=\S) - fail: like-strings-branch - like-escape-character-slash: - - match: (\')(\\)(\') - captures: - 0: meta.string.escape.sql string.quoted.single.sql - 1: punctuation.definition.string.begin.sql - 2: constant.character.escape.sql - 3: punctuation.definition.string.end.sql - pop: true - - match: (?=\S) - fail: like-strings-branch + - include: scope:source.sql.mysql + apply_prototype: true diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax new file mode 100644 index 0000000000..54d93fc911 --- /dev/null +++ b/SQL/TSQL.sublime-syntax @@ -0,0 +1,147 @@ +%YAML 1.2 +--- +name: T-SQL +scope: source.sql.tsql +version: 2 +extends: Packages/SQL/SQL (basic).sublime-syntax + +variables: + string_escape: (?:'') #(?:\\[tnr]) +contexts: + main: + - meta_prepend: true + - include: declarations + - include: variables + + declarations: + - match: \b(?i:declare)\b + scope: keyword.declaration.variable.tsql + + operators: + - meta_append: true + - match: (?i:\blike\b) + scope: keyword.operator.logical.sql + branch_point: like-strings-branch + branch: + - like-string-not-followed-by-escape + - like-string-followed-by-escape-slash + - like-string-followed-by-escape-caret + - like-string-followed-by-unknown-escape + + variables: + - match: (?:@\w+) + scope: variable.other.readwrite.tsql + + like-string-not-followed-by-escape: + - match: \' + scope: punctuation.definition.string.begin.sql + set: [like-escape-fail, inside-like-single-quoted-string] + - match: (?=\S) + pop: true + + like-string-followed-by-escape-slash: + - match: \' + scope: punctuation.definition.string.begin.sql + set: [like-escape-character-slash, like-escape-pop, inside-like-single-quoted-string-slash-escape] + - match: (?=\S) + pop: true + + like-string-followed-by-escape-caret: + - match: \' + scope: punctuation.definition.string.begin.sql + set: [like-escape-character-caret, like-escape-pop, inside-like-single-quoted-string-caret-escape] + - match: (?=\S) + pop: true + + like-string-followed-by-unknown-escape: + - match: \' + scope: punctuation.definition.string.begin.sql + set: [like-escape-character-any, like-escape-pop, inside-like-single-quoted-string] + - match: (?=\S) + pop: true + + inside-like-single-quoted-string-slash-escape: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \\. + scope: constant.character.escape.sql + - include: inside-like-single-quoted-string + + inside-like-single-quoted-string-caret-escape: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \^. + scope: constant.character.escape.sql + - include: inside-like-single-quoted-string + + inside-like-single-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: true + - match: |- + (?x) + (\[)(\^)? + (?:.|[^]'-]+?) + (?:(-)[^]'-]*)? + (\]) + scope: meta.set.like.sql + captures: + 1: keyword.control.set.begin.sql + 2: keyword.control.set.negation.sql + 3: constant.other.range.sql + 4: keyword.control.set.end.sql + - match: '[%_]' + scope: keyword.operator.wildcard.sql + + like-escape-fail: + - match: (?i:\bescape\b) + fail: like-strings-branch + - match: (?=\S) + pop: true + + like-escape-pop: + - match: (?i:\bescape\b) + scope: keyword.operator.word.sql + pop: true + - match: (?=\S) + pop: true + + like-escape-character-any: + - match: (\')([^'])(\') + captures: + 0: meta.string.escape.sql string.quoted.single.sql + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: true + - match: (?=\S) + pop: true + + like-escape-character-caret: + - match: (\')(\^)(\') + captures: + 0: meta.string.escape.sql string.quoted.single.sql + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: true + - match: (?=\S) + fail: like-strings-branch + + like-escape-character-slash: + - match: (\')(\\)(\') + captures: + 0: meta.string.escape.sql string.quoted.single.sql + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: true + - match: (?=\S) + fail: like-strings-branch + + types: + - meta_append: true + - match: (?i:\b(?:smallint|sysname)\b) + scope: storage.type.sql diff --git a/SQL/syntax_test_mysql.sql b/SQL/syntax_test_mysql.sql new file mode 100644 index 0000000000..bbacb7cb2c --- /dev/null +++ b/SQL/syntax_test_mysql.sql @@ -0,0 +1,192 @@ +-- SYNTAX TEST "Packages/SQL/SQL.sublime-syntax" + +SELECT 'Foo Bar'; +-- ^^^^^^^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ punctuation.definition.string.end +-- ^ punctuation.terminator.statement - string + +SELECT 'Foo '' Bar'; +-- ^^ constant.character.escape.sql + +SELECT "My "" Crazy Column Name" FROM my_table; +-- ^^ constant.character.escape.sql + +SELECT "My -- Crazy Column Name" FROM my_table; +-- ^^ - comment - punctuation + +SELECT "My /* Crazy Column Name" FROM my_table; +-- ^^ - comment - punctuation + + +;CREATE TABLE foo (id INTEGER PRIMARY KEY); + -- <- keyword.other.create +--^^^^^ keyword.other.create +-- ^^^^^ keyword.other +-- ^^^ entity.name.function +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - entity.name.function + +create table some_schema.test2( id serial ); +--^^^^ meta.create keyword.other.create +-- ^^^^^ meta.create keyword.other +-- ^^^^^^^^^^^^^^^^^ entity.name.function +-- ^ punctuation.accessor.dot +-- ^^^^^^^^^^^^^^ - entity.name.function + +create table some_schema . test2 ( id serial ); +--^^^^ meta.create keyword.other.create +-- ^^^^^ meta.create keyword.other +-- ^^^^^^^^^^^^^^^^^^^ entity.name +-- ^ punctuation.accessor.dot +-- ^^^^^^^^^^^^^^^ - entity.name.function + +create table "testing123" (id integer); +--^^^^ meta.create keyword.other.create +-- ^^^^^ meta.create keyword.other +-- ^ punctuation.definition.identifier.begin +-- ^^^^^^^^^^ entity.name.function +-- ^ punctuation.definition.identifier.end + +create table `dbo`."testing123" (id integer); +--^^^^ meta.create keyword.other.create +-- ^^^^^ meta.create keyword.other +-- ^^^^^^^^^^^^^^^^^^ entity.name.function +-- ^ punctuation.accessor.dot +-- ^^^^^^^^^^^^^^^ - entity.name.function + +create table IF NOT EXISTS `testing123` ( +-- ^^^^^^^^^^^^^^^^^^^^^^^^ - meta.toc-list +-- ^^ keyword.control.flow +-- ^^^ keyword.operator.logical +-- ^^^^^^ keyword.operator.logical + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `lastchanged` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +-- ^^^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^^^^^^^ support.function.scalar.sql +-- ^^^^^^^^^ storage.modifier.sql + `col` bool DEFAULT FALSE, +-- ^^^^ storage.type.sql +-- ^^^^^^^ storage.modifier.sql +-- ^^^^^ constant.language.boolean.sql +-- ^ punctuation.separator.sequence + `fkey` INT UNSIGNED NULL REFERENCES test2(id), +-- ^^^^^^^^^^ storage.modifier.sql + `version` tinytext DEFAULT NULL COMMENT 'important clarification', +-- ^^^^^^^^ storage.type.sql + `percentage` float DEFAULT '0', + UNIQUE KEY `testing123_search` (`col`, `version`), +-- ^^^^^^^^^^ storage.modifier.sql + KEY `testing123_col` (`col`), +-- ^^^ storage.modifier.sql + FULLTEXT KEY `testing123_version` (`version`) +) ENGINE=MyISAM AUTO_INCREMENT=42 DEFAULT CHARSET=utf8; + +create table fancy_table ( + id SERIAL, +-- ^^^^^^ storage.type.sql + foreign_id integer, +-- ^^^^^^^ storage.type.sql + myflag boolean DEFAULT false, +-- ^^^^^^^ storage.type.sql + mycount double precision DEFAULT 1, +-- ^^^^^^^^^^^^^^^^^ storage.type.sql + fancy_column character varying(42) DEFAULT 'nice'::character varying, +-- ^^^^^^^^^^^^^^^^^^ storage.type.sql + mytime timestamp(3) without time zone DEFAULT now(), +-- ^^^^^^^^^^^^^^^^^ storage.type.sql + mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, +-- ^^^^^^^^^^^^^^^^^^^ storage.type.sql + primary key (id), +-- ^^^^^^^^^^^ storage.modifier.sql + UNIQUE (foreign_id), + CONSTRAINT fancy_table_valid1 CHECK (id <> foreign_id) +-- ^^^^^^^^^^ storage.modifier.sql +-- ^^^^^ storage.modifier.sql +); + +CREATE INDEX ON fancy_table(mytime); +-- ^^^^^ keyword.other.sql +-- ^^ - entity.name.function.sql +-- ^^^^^^^^^^^ entity.name.function.sql + +CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); +-- ^^^^^ keyword.other.sql +-- ^^ - entity.name.function.sql + +CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; +-- ^^^^^^^^^^^^ keyword.other.sql +-- ^^ - entity.name.function.sql +-- ^^^^^^^^^^^ entity.name.function.sql +-- ^^^^^ keyword.other.DML.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql + +create fulltext index if not exists `myindex` ON mytable; +-- ^^^^^^^^^^^^^^ keyword.other.sql + +ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; +-- ^^^ keyword.other.add.sql +-- ^^^^^^ keyword.other.sql +-- ^^^^^^^^ storage.type.sql + +ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); +-- ^^^^ storage.type.sql + +DROP TABLE IF EXISTS testing123; +-- <- meta.drop.sql keyword.other.create.sql +-- ^^^^^^ keyword.operator.logical.sql + +select * +from some_table +where exists(select * from other_table where id = some_table.id) +-- ^^^^^^ keyword.operator.logical + +SELECT +( +SELECT CASE field +USING a +-- <- keyword.other.DML + WHEN 1 + THEN -- comment's say that +-- ^ comment.line.double-dash + EXISTS( + select 1) + ELSE NULL + END +) as result + + +/* +-- <- comment.block punctuation.definition.comment.begin +This is a +multiline comment +-- ^^^^^^^^^^^^^^^ source.sql comment.block.sql +*/ +-- <- comment.block punctuation.definition.comment.end + +/** + * +-- ^ punctuation.definition.comment.sql +*/ + +select + + + <=> +-- ^^^ keyword.operator.comparison.sql + +SELECT *, +-- ^^^ keyword.other.DML.sql +-- ^ variable.language.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 diff --git a/SQL/syntax_test_sql.sql b/SQL/syntax_test_sql.sql deleted file mode 100644 index 8b2f1f797b..0000000000 --- a/SQL/syntax_test_sql.sql +++ /dev/null @@ -1,312 +0,0 @@ --- SYNTAX TEST "Packages/SQL/SQL.sublime-syntax" - -SELECT 'Foo Bar'; --- ^^^^^^^^^ string.quoted.single --- ^ punctuation.definition.string.begin --- ^ punctuation.definition.string.end --- ^ punctuation.terminator.statement - string - -SELECT 'Foo '' Bar'; --- ^^ constant.character.escape.sql - -SELECT "My "" Crazy Column Name" FROM my_table; --- ^^ constant.character.escape.sql - -SELECT "My -- Crazy Column Name" FROM my_table; --- ^^ - comment - punctuation - -SELECT "My /* Crazy Column Name" FROM my_table; --- ^^ - comment - punctuation - - -;CREATE TABLE foo (id INTEGER PRIMARY KEY); - -- <- keyword.other.create ---^^^^^ keyword.other.create --- ^^^^^ keyword.other --- ^^^ entity.name.function --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - entity.name.function - -create table some_schema.test2( id serial ); ---^^^^ meta.create keyword.other.create --- ^^^^^ meta.create keyword.other --- ^^^^^^^^^^^^ - entity.name.function --- ^ punctuation.accessor.dot --- ^^^^^ entity.name.function --- ^^^^^^^^^^^^^^ - entity.name.function - -create table some_schema . test2 ( id serial ); ---^^^^ meta.create keyword.other.create --- ^^^^^ meta.create keyword.other --- ^^^^^^^^^^^^^^ - entity.name --- ^ punctuation.accessor.dot --- ^^^^^ entity.name.function --- ^^^^^^^^^^^^^^^ - entity.name.function - -create table "testing123" (id integer); ---^^^^ meta.create keyword.other.create --- ^^^^^ meta.create keyword.other --- ^ - entity.name.function --- ^^^^^^^^^^ entity.name.function --- ^^^^^^^^^^^^^^^^ - entity.name.function - -create table `dbo`."testing123" (id integer); ---^^^^ meta.create keyword.other.create --- ^^^^^ meta.create keyword.other --- ^^^^^^^ - entity.name.function --- ^ punctuation.accessor.dot --- ^^^^^^^^^^ entity.name.function --- ^^^^^^^^^^^^^^^^ - entity.name.function - -create table IF NOT EXISTS `testing123` ( --- ^^^^^^^^^^^^^^^^^^^^^^^^ - meta.toc-list --- ^^ keyword.control.flow --- ^^^ keyword.operator.logical --- ^^^^^^ keyword.operator.logical - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `lastchanged` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, --- ^^^^^^^^^ storage.type.sql --- ^^^^^^^^^^^^^^^^^ support.function.scalar.sql --- ^^^^^^^^^ storage.modifier.sql - `col` bool DEFAULT FALSE, --- ^^^^ storage.type.sql --- ^^^^^^^ storage.modifier.sql --- ^^^^^ constant.language.boolean.sql --- ^ punctuation.separator.sequence - `fkey` INT UNSIGNED NULL REFERENCES test2(id), --- ^^^^^^^^^^ storage.modifier.sql - `version` tinytext DEFAULT NULL COMMENT 'important clarification', --- ^^^^^^^^ storage.type.sql - `percentage` float DEFAULT '0', - UNIQUE KEY `testing123_search` (`col`, `version`), --- ^^^^^^^^^^ storage.modifier.sql - KEY `testing123_col` (`col`), --- ^^^ storage.modifier.sql - FULLTEXT KEY `testing123_version` (`version`) -) ENGINE=MyISAM AUTO_INCREMENT=42 DEFAULT CHARSET=utf8; - -create table fancy_table ( - id SERIAL, --- ^^^^^^ storage.type.sql - foreign_id integer, --- ^^^^^^^ storage.type.sql - myflag boolean DEFAULT false, --- ^^^^^^^ storage.type.sql - mycount double precision DEFAULT 1, --- ^^^^^^^^^^^^^^^^^ storage.type.sql - fancy_column character varying(42) DEFAULT 'nice'::character varying, --- ^^^^^^^^^^^^^^^^^^ storage.type.sql - mytime timestamp(3) without time zone DEFAULT now(), --- ^^^^^^^^^^^^^^^^^ storage.type.sql - mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, --- ^^^^^^^^^^^^^^^^^^^ storage.type.sql - primary key (id), --- ^^^^^^^^^^^ storage.modifier.sql - UNIQUE (foreign_id), - CONSTRAINT fancy_table_valid1 CHECK (id <> foreign_id) --- ^^^^^^^^^^ storage.modifier.sql --- ^^^^^ storage.modifier.sql -); - -CREATE INDEX ON fancy_table(mytime); --- ^^^^^ keyword.other.sql --- ^^ - entity.name.function.sql --- ^^^^^^^^^^^ entity.name.function.sql - -CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); --- ^^^^^ keyword.other.sql --- ^^ - entity.name.function.sql - -CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; --- ^^^^^^^^^^^^ keyword.other.sql --- ^^ - entity.name.function.sql --- ^^^^^^^^^^^ entity.name.function.sql --- ^^^^^ keyword.other.DML.sql --- ^^ keyword.operator.logical.sql --- ^^^^ constant.language.null.sql - -create fulltext index if not exists `myindex` ON mytable; --- ^^^^^^^^^^^^^^ keyword.other.sql - -ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; --- ^^^ keyword.other.add.sql --- ^^^^^^ keyword.other.sql --- ^^^^^^^^ storage.type.sql - -ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); --- ^^^^ storage.type.sql - -DROP TABLE IF EXISTS testing123; --- <- meta.drop.sql keyword.other.create.sql --- ^^^^^^ keyword.operator.logical.sql - -select * -from some_table -where exists(select * from other_table where id = some_table.id) --- ^^^^^^ keyword.operator.logical - -SELECT -( -SELECT CASE field -USING a --- <- keyword.other.DML - WHEN 1 - THEN -- comment's say that --- ^ comment.line.double-dash - EXISTS( - select 1) - ELSE NULL - END -) as result - - -/* --- <- comment.block punctuation.definition.comment.begin -This is a -multiline comment --- ^^^^^^^^^^^^^^^ source.sql comment.block.sql -*/ --- <- comment.block punctuation.definition.comment.end - -/** - * --- ^ punctuation.definition.comment.sql -*/ - -select - - - <=> --- ^^^ keyword.operator.comparison.sql - -SELECT *, --- ^^^ keyword.other.DML.sql --- ^ variable.language.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 - - -SELECT columns FROM table WHERE - column LIKE '%[[]SQL Server Driver]%' --- ^^^^ keyword.operator.logical --- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.like string.quoted.single --- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard --- ^^^ meta.set.like --- ^ keyword.control.set.begin --- ^ keyword.control.set.end --- ^^^^^^^^^^^^^^^^^^ - constant - keyword --- ^ keyword.operator.wildcard --- ^ punctuation.definition.string.end --- ^^ - meta.string - string - -SELECT columns FROM table WHERE - column LIKE '%[SQL Server Driver]%' --- ^^^^ keyword.operator.logical --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.string.like string.quoted.single --- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard --- ^^^^^^^^^^^^^^^^^^^ meta.set.like --- ^ keyword.control.set.begin --- ^ keyword.control.set.end --- ^^^^^^^^^^^^^^^ - constant - keyword --- ^ keyword.operator.wildcard --- ^ punctuation.definition.string.end --- ^^ - meta.string - string - -SELECT columns FROM table WHERE - column LIKE '%[^a-f]%' --- ^^^^ keyword.operator.logical --- ^^^^^^^^^^ meta.string.like string.quoted.single --- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard --- ^^^^^^ meta.set.like --- ^ keyword.control.set.begin --- ^ keyword.control.set.negation --- ^ constant.other.range --- ^ keyword.control.set.end --- ^ keyword.operator.wildcard --- ^ punctuation.definition.string.end --- ^^ - meta.string - string - -SELECT columns FROM table WHERE - column LIKE 'hello_world' --- ^^^^ keyword.operator.logical --- ^^^^^^^^^^^^ meta.string.like string.quoted.single --- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard --- ^ punctuation.definition.string.end --- ^^ - meta.string - string - -SELECT columns FROM table WHERE - column LIKE '%\[SQL Server Driver]^%\__' ESCAPE '\' --- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard --- ^^ constant.character.escape --- ^ - constant --- ^ keyword.operator.wildcard --- ^^ constant.character.escape --- ^ keyword.operator.wildcard --- ^^^^^^ keyword.operator.word --- ^^^ string.quoted.single --- ^ punctuation.definition.string.begin --- ^ constant.character.escape --- ^ punctuation.definition.string.end - -SELECT columns FROM table WHERE - column LIKE '%\[SQL Server Driver]^%\__' --- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard --- ^^ constant.character.escape --- ^ - constant --- ^ keyword.operator.wildcard --- ^^ constant.character.escape --- ^ keyword.operator.wildcard - ESCAPE '\' --- ^^^^^^ keyword.operator.word --- ^^^ string.quoted.single --- ^ punctuation.definition.string.begin --- ^ constant.character.escape --- ^ punctuation.definition.string.end - -SELECT columns FROM table WHERE - column LIKE '%\^[SQL Server Driver]^%_^_' ESCAPE '^' --- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard --- ^ - constant --- ^^ constant.character.escape --- ^^ constant.character.escape --- ^ keyword.operator.wildcard --- ^^ constant.character.escape --- ^^^^^^ keyword.operator.word --- ^^^ string.quoted.single --- ^ punctuation.definition.string.begin --- ^ constant.character.escape --- ^ punctuation.definition.string.end - -SELECT columns FROM table WHERE - column LIKE '%\^[SQL Server Driver]^%_^_\_{{--' ESCAPE '{' -- uncatered for escape char, scope operators as though unescaped --- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - constant --- ^^^^^^^^^^^^^^^^^^^ meta.set.like --- ^^^^^^^^^^^ - meta.set --- ^^ keyword.operator.wildcard --- ^ keyword.operator.wildcard --- ^ keyword.operator.wildcard --- ^^^^^^^^^^^^^^^ - comment --- ^^^^^^ keyword.operator.word --- ^^^ string.quoted.single --- ^ punctuation.definition.string.begin --- ^ constant.character.escape --- ^ punctuation.definition.string.end --- ^^ comment.line.double-dash punctuation.definition.comment diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql new file mode 100644 index 0000000000..2a598a98a1 --- /dev/null +++ b/SQL/syntax_test_tsql.sql @@ -0,0 +1,147 @@ +-- SYNTAX TEST "Packages/SQL/TSQL.sublime-syntax" + +SELECT columns FROM table WHERE + column LIKE '%[[]SQL Server Driver]%' +-- ^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.like string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ keyword.operator.wildcard +-- ^^^ meta.set.like +-- ^ keyword.control.set.begin +-- ^ keyword.control.set.end +-- ^^^^^^^^^^^^^^^^^^ - constant - keyword +-- ^ keyword.operator.wildcard +-- ^ punctuation.definition.string.end +-- ^^ - meta.string - string + +SELECT columns FROM table WHERE + column LIKE '%[SQL Server Driver]%' +-- ^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.string.like string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ keyword.operator.wildcard +-- ^^^^^^^^^^^^^^^^^^^ meta.set.like +-- ^ keyword.control.set.begin +-- ^ keyword.control.set.end +-- ^^^^^^^^^^^^^^^ - constant - keyword +-- ^ keyword.operator.wildcard +-- ^ punctuation.definition.string.end +-- ^^ - meta.string - string + +SELECT columns FROM table WHERE + column LIKE '%[^a-f]%' +-- ^^^^ keyword.operator.logical +-- ^^^^^^^^^^ meta.string.like string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ keyword.operator.wildcard +-- ^^^^^^ meta.set.like +-- ^ keyword.control.set.begin +-- ^ keyword.control.set.negation +-- ^ constant.other.range +-- ^ keyword.control.set.end +-- ^ keyword.operator.wildcard +-- ^ punctuation.definition.string.end +-- ^^ - meta.string - string + +SELECT columns FROM table WHERE + column LIKE 'hello_world' +-- ^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^ meta.string.like string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ keyword.operator.wildcard +-- ^ punctuation.definition.string.end +-- ^^ - meta.string - string + +SELECT columns FROM table WHERE + column LIKE '%\[SQL Server Driver]^%\__' ESCAPE '\' +-- ^^^^ keyword.operator.logical +-- ^ keyword.operator.wildcard +-- ^^ constant.character.escape +-- ^ - constant +-- ^ keyword.operator.wildcard +-- ^^ constant.character.escape +-- ^ keyword.operator.wildcard +-- ^^^^^^ keyword.operator.word +-- ^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.character.escape +-- ^ punctuation.definition.string.end + +SELECT columns FROM table WHERE + column LIKE '%\[SQL Server Driver]^%\__' +-- ^^^^ keyword.operator.logical +-- ^ keyword.operator.wildcard +-- ^^ constant.character.escape +-- ^ - constant +-- ^ keyword.operator.wildcard +-- ^^ constant.character.escape +-- ^ keyword.operator.wildcard + ESCAPE '\' +-- ^^^^^^ keyword.operator.word +-- ^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.character.escape +-- ^ punctuation.definition.string.end + +SELECT columns FROM table WHERE + column LIKE '%\^[SQL Server Driver]^%_^_' ESCAPE '^' +-- ^^^^ keyword.operator.logical +-- ^ keyword.operator.wildcard +-- ^ - constant +-- ^^ constant.character.escape +-- ^^ constant.character.escape +-- ^ keyword.operator.wildcard +-- ^^ constant.character.escape +-- ^^^^^^ keyword.operator.word +-- ^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.character.escape +-- ^ punctuation.definition.string.end + +SELECT columns FROM table WHERE + column LIKE '%\^[SQL Server Driver]^%_^_\_{{--' ESCAPE '{' -- uncatered for escape char, scope operators as though unescaped +-- ^^^^ keyword.operator.logical +-- ^ keyword.operator.wildcard +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - constant +-- ^^^^^^^^^^^^^^^^^^^ meta.set.like +-- ^^^^^^^^^^^ - meta.set +-- ^^ keyword.operator.wildcard +-- ^ keyword.operator.wildcard +-- ^ keyword.operator.wildcard +-- ^^^^^^^^^^^^^^^ - comment +-- ^^^^^^ keyword.operator.word +-- ^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ constant.character.escape +-- ^ punctuation.definition.string.end +-- ^^ comment.line.double-dash punctuation.definition.comment + +DECLARE @Example INT = 5 +-- ^^^^ keyword.declaration.variable +-- ^^^^^^^^ variable.other.readwrite +-- ^^^ storage.type +-- ^ keyword.operator +-- ^ constant.numeric + +SELECT TOP 1 @Example = 4 FROM [dbo].[TableName] +-- ^^^^^^^ keyword.other.DML +-- ^ constant.numeric +-- ^^^^^^^^ variable.other.readwrite +-- ^ keyword.operator +-- ^ constant.numeric +-- ^^^^ keyword.other.DML + +SET @Path = 'X:\nowayout\' +--^ keyword.other.DML +-- ^^^^^ variable.other.readwrite +-- ^ keyword.operator +-- ^^^^^^^^^^^^^^ string.quoted.single - constant +-- ^ punctuation.definition.string.begin +-- ^ punctuation.definition.string.end +-- ^ - string + +SET @Blah = 'He said, ''hello world''.' +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ - string +-- ^^ constant.character.escape +-- ^^ constant.character.escape From dd1bc8125d0955f8a29f4cf17081f4e9d0097f9b Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 17 Sep 2021 23:06:13 +0300 Subject: [PATCH 002/250] [SQL] split main context into more contexts --- SQL/MySQL.sublime-syntax | 28 ++++++ SQL/SQL (basic).sublime-syntax | 174 +++++++++++++++++++-------------- SQL/TSQL.sublime-syntax | 56 +++++++++-- SQL/syntax_test_mysql.sql | 7 ++ SQL/syntax_test_tsql.sql | 35 +++++++ 5 files changed, 216 insertions(+), 84 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index b3d6fafae9..c6955dd57c 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -10,6 +10,18 @@ contexts: - meta_append: true - include: regexps + comments: + - meta_append: true + - match: '#' + scope: punctuation.definition.comment.sql + push: inside-number-sign-comment + + double-dash-comments: + - meta_include_prototype: false + - match: '--(?=\s)' + scope: punctuation.definition.comment.sql + push: inside-double-dash-comment + strings: - meta_append: true - match: "`" @@ -110,3 +122,19 @@ contexts: 13: storage.type.sql 14: constant.numeric.sql 15: storage.type.sql + + inside-number-sign-comment: + - meta_include_prototype: false + - meta_scope: comment.line.number-sign.sql + - match: \n + pop: true + + expressions: + - meta_append: true + - match: (?i)\b(CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b + scope: support.function.string.sql + + statements: + - meta_append: true + - match: (?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b) + scope: keyword.other.LUW.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 34a7a6b427..a70ab9bcf8 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -14,59 +14,8 @@ contexts: - include: comments main: - - match: |- - (?xi) - \b(create(?:\s+or\s+replace)?)\s+ - ({{dml_targets}}) - \b\s* - (on)?\b - scope: meta.create.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.sql - 3: keyword.other.sql - push: create-condition - - match: (?i:\s*\b(drop)\s+({{dml_targets}})) - scope: meta.drop.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.sql - push: drop-condition - - match: (?i:\s*(drop)\s+(table)\s+(\w+)(\s+cascade)?\b) - scope: meta.drop.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.table.sql - 3: entity.name.function.sql - 4: keyword.other.cascade.sql - - match: (?i:\s*\b(alter)\s+{{dml_targets}}\s+) - scope: meta.alter.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.table.sql - - match: (?i:\s*\b(add)\s+(column|constraint|fulltext\s+(index|key)|index|spatial\s+(index|key))) - scope: meta.add.sql - captures: - 1: keyword.other.add.sql - 2: keyword.other.sql + - include: statements - include: types - - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) - scope: storage.modifier.sql - - match: \b\d+\b - scope: constant.numeric.sql - - match: (?i:\b(true|false)\b) - scope: constant.language.boolean.sql - - match: (?i:\b(null)\b) - scope: constant.language.null.sql - - match: (?i:\b(select(\s+(distinct|top))?|insert(\s+(ignore\s+)?into)?|update|delete|truncate|from|set|where|group\s+by|with|case|when|then|else|end|union(\s+all)?|using|order\s+by|limit|(inner|cross)\s+join|join|straight_join|(left|right)(\s+outer)?\s+join|natural(\s+(left|right)(\s+outer)?)?\s+join)\b) - scope: keyword.other.DML.sql - - include: operators - - match: (?i:\bvalues\b) - scope: keyword.other.DML.II.sql - - match: (?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b) - scope: keyword.other.LUW.sql - - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) - scope: keyword.other.authorization.sql - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) scope: keyword.other.object-comments.sql - match: (?i)\bas\b @@ -75,34 +24,25 @@ contexts: scope: keyword.other.order.sql - match: \* scope: variable.language.wildcard.asterisk.sql - - match: (?i)\b(CURRENT_(DATE|TIME(STAMP)?|USER)|(SESSION|SYSTEM)_USER)\b - comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - scope: support.function.scalar.sql - - match: (?i)\b(AVG|COUNT|MIN|MAX|SUM)(?=\s*\() - comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - scope: support.function.aggregate.sql - - match: (?i)\b(CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b - scope: support.function.string.sql - - include: strings - - match: (\()(\)) - comment: Allow for special ↩ behavior - scope: meta.block.sql - captures: - 1: punctuation.section.scope.begin.sql - 2: punctuation.section.scope.end.sql + - include: expressions - match: ',' scope: punctuation.separator.sequence.sql - match: ';' scope: punctuation.terminator.statement.sql comments: + - meta_include_prototype: false + - include: double-dash-comments + - include: block-comments + + double-dash-comments: - meta_include_prototype: false - match: '--' scope: punctuation.definition.comment.sql push: inside-double-dash-comment - - match: '#' - scope: punctuation.definition.comment.sql - push: inside-number-sign-comment + + block-comments: + - meta_include_prototype: false - match: /\* scope: punctuation.definition.comment.begin.sql push: inside-comment-block @@ -113,12 +53,6 @@ contexts: - match: \n pop: true - inside-number-sign-comment: - - meta_include_prototype: false - - meta_scope: comment.line.number-sign.sql - - match: \n - pop: true - inside-comment-block: - meta_include_prototype: false - meta_scope: comment.block.sql @@ -219,3 +153,91 @@ contexts: captures: 1: storage.type.sql 2: constant.numeric.sql + + expressions: + - match: \b\d+\b + scope: meta.number.integer.decimal.sql constant.numeric.value.sql + - match: (?i)\b(?:true|false)\b + scope: constant.language.boolean.sql + - match: (?i:\bnull\b) + scope: constant.language.null.sql + - match: (?i)\b(?:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() + comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + scope: support.function.aggregate.sql + - match: (?i)\b(CURRENT_(DATE|TIME(STAMP)?|USER)|(SESSION|SYSTEM)_USER)\b + comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + scope: support.function.scalar.sql + - include: strings + - include: operators + - match: \b(\w+)\s*(\() + captures: + 0: meta.function-call.sql + 1: support.function.sql + 2: meta.group.sql punctuation.section.parens.begin.sql + push: inside-method-call + - match: (\()(\)) + comment: Allow for special ↩ behavior + scope: meta.block.sql + captures: + 1: punctuation.section.scope.begin.sql + 2: punctuation.section.scope.end.sql + + inside-method-call: + - meta_content_scope: meta.group.sql + - match: \) + scope: meta.group.sql punctuation.section.parens.end.sql + pop: true + - match: ',' + scope: punctuation.separator.argument.sql + - include: expressions + + statements: + - include: ddl-statements + - include: dml-statements + + ddl-statements: + - match: |- + (?xi) + \b(create(?:\s+or\s+replace)?)\s+ + ({{dml_targets}}) + \b\s* + (on)?\b + scope: meta.create.sql + captures: + 1: keyword.other.create.sql + 2: keyword.other.sql + 3: keyword.other.sql + push: create-condition + - match: (?i:\s*\b(drop)\s+({{dml_targets}})) + scope: meta.drop.sql + captures: + 1: keyword.other.create.sql + 2: keyword.other.sql + push: drop-condition + - match: (?i:\s*(drop)\s+(table)\s+(\w+)(\s+cascade)?\b) + scope: meta.drop.sql + captures: + 1: keyword.other.create.sql + 2: keyword.other.table.sql + 3: entity.name.function.sql + 4: keyword.other.cascade.sql + - match: (?i:\s*\b(alter)\s+({{dml_targets}})\s+) + scope: meta.alter.sql + captures: + 1: keyword.other.create.sql + 2: keyword.other.table.sql + - match: (?i:\s*\b(add)\s+(column|constraint|fulltext\s+(index|key)|index|spatial\s+(index|key))) + scope: meta.add.sql + captures: + 1: keyword.other.add.sql + 2: keyword.other.sql + - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) + scope: storage.modifier.sql + - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) + scope: keyword.other.authorization.sql + + dml-statements: + - match: (?i:\b(select(\s+(distinct|top))?|insert(\s+(ignore\s+)?into)?|update|delete|truncate|from|set|where|group\s+by|with|union(\s+all)?|using|order\s+by|limit|(inner|cross)\s+join|join|straight_join|(left|right)(\s+outer)?\s+join|natural(\s+(left|right)(\s+outer)?)?\s+join)\b) + scope: keyword.other.DML.sql + - match: (?i:\bvalues\b) + scope: keyword.other.DML.II.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 54d93fc911..1b2cbdf1d3 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -8,14 +8,11 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') #(?:\\[tnr]) contexts: - main: - - meta_prepend: true - - include: declarations - - include: variables - - declarations: - - match: \b(?i:declare)\b - scope: keyword.declaration.variable.tsql + strings: + - meta_append: true + - match: N' + scope: punctuation.definition.string.begin.sql + push: single-quoted-string operators: - meta_append: true @@ -145,3 +142,46 @@ contexts: - meta_append: true - match: (?i:\b(?:smallint|sysname)\b) scope: storage.type.sql + + statements: + - meta_append: true + - include: declarations + - match: \b(?i:go)\b + scope: keyword.control.flow.tsql + - match: \b(?i:begin)\b + scope: keyword.control.flow.begin.tsql + - match: \b(?i:end)\b + scope: keyword.control.flow.end.tsql + - include: transaction-statements + + transaction-statements: + - match: (?i)\b(?:begin|commit|rollback)\s+tran(saction)?\b + scope: keyword.context.tsql + + declarations: + - match: \b(?i:declare)\b + scope: keyword.declaration.variable.tsql + + expressions: + - meta_append: true + - match: \b(?i:case)\b + scope: keyword.control.conditional.case.sql + push: inside-case-expression + - include: variables + + inside-case-expression: + - meta_scope: meta.statement.conditional.case.sql + - match: \b(?i:end)\b + scope: keyword.control.conditional.end.sql + pop: true + - match: \b(?i)(case)\s+(when)\b + captures: + 1: keyword.control.conditional.case.sql + 2: keyword.control.conditional.when.sql + - match: \b(?i:when)\b + scope: keyword.control.conditional.when.sql + - match: \b(?i:then)\b + scope: keyword.control.conditional.then.sql + - match: \b(?i:else)\b + scope: keyword.control.conditional.else.sql + - include: main diff --git a/SQL/syntax_test_mysql.sql b/SQL/syntax_test_mysql.sql index bbacb7cb2c..a79893847d 100644 --- a/SQL/syntax_test_mysql.sql +++ b/SQL/syntax_test_mysql.sql @@ -94,6 +94,11 @@ create table fancy_table ( -- ^^^^^^^^^^^^^^^^^^ storage.type.sql mytime timestamp(3) without time zone DEFAULT now(), -- ^^^^^^^^^^^^^^^^^ storage.type.sql +-- ^^^^^^^ storage.modifier +-- ^^^ meta.function-call support.function +-- ^ punctuation.section.parens.begin +-- ^ punctuation.section.parens.end +-- ^ punctuation.separator.sequence mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, -- ^^^^^^^^^^^^^^^^^^^ storage.type.sql primary key (id), @@ -125,6 +130,8 @@ create fulltext index if not exists `myindex` ON mytable; -- ^^^^^^^^^^^^^^ keyword.other.sql ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; +-- ^^ keyword.other +-- ^^^^^ keyword.other.table -- ^^^ keyword.other.add.sql -- ^^^^^^ keyword.other.sql -- ^^^^^^^^ storage.type.sql diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 2a598a98a1..706fe13f0d 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -145,3 +145,38 @@ SET @Blah = 'He said, ''hello world''.' -- ^ - string -- ^^ constant.character.escape -- ^^ constant.character.escape + +SET @Blah = CASE WHEN @x = 2 THEN 'Y' CASE WHEN @z = @x THEN 'N' ELSE NULL END +-- ^^^^ keyword.control.conditional.case +-- ^^^^ keyword.control.conditional.when +-- ^^ variable.other.readwrite +-- ^ keyword.operator.comparison +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^^^^ keyword.control.conditional.then +-- ^^^ string.quoted.single +-- ^^^^ keyword.control.conditional.case +-- ^^^^ keyword.control.conditional.when +-- ^^ variable.other.readwrite +-- ^ keyword.operator.comparison +-- ^^ variable.other.readwrite +-- ^^^^ keyword.control.conditional.then +-- ^^^ string.quoted.single +-- ^^^^ keyword.control.conditional.else +-- ^^^^ constant.language.null +-- ^^^ keyword.control.conditional.end +-- ^ - meta +SET @Blah = CASE @x WHEN 2 THEN 'Y' WHEN @z THEN 'N' ELSE NULL END +-- ^^^^ keyword.control.conditional.case +-- ^^ variable.other.readwrite +-- ^^^^ keyword.control.conditional.when +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^^^^ keyword.control.conditional.then +-- ^^^ string.quoted.single +-- ^^^^ keyword.control.conditional.when +-- ^^ variable.other.readwrite +-- ^^^^ keyword.control.conditional.then +-- ^^^ string.quoted.single +-- ^^^^ keyword.control.conditional.else +-- ^^^^ constant.language.null +-- ^^^ keyword.control.conditional.end +-- ^ - meta From 12a565175bb49199ec5f9748da16601bd36648b4 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 19 Sep 2021 00:24:20 +0300 Subject: [PATCH 003/250] [SQL] Transact-SQL improvements --- SQL/SQL (basic).sublime-syntax | 39 ++++++++++++++++++------- SQL/TSQL.sublime-syntax | 52 +++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 14 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index a70ab9bcf8..f37c052be3 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -18,8 +18,8 @@ contexts: - include: types - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) scope: keyword.other.object-comments.sql - - match: (?i)\bas\b - scope: keyword.operator.assignment.alias.sql + - match: (?i)\bon\b + scope: keyword.operator.join.sql - match: (?i)\b(asc|desc)\b scope: keyword.other.order.sql - match: \* @@ -87,6 +87,17 @@ contexts: - meta_scope: meta.toc-list.full-identifier.sql entity.name.function.sql - include: identifier + single-identifier-after-whitespace: + - match: \s+ + set: single-identifier + - match: '' + set: single-identifier + + single-identifier: + - include: identifier + - match: '' + pop: true + identifier: - include: simple-identifier - include: single-quoted-identifier @@ -151,10 +162,12 @@ contexts: scope: storage.type.sql - match: \b(?i:char|number|nvarchar|varbinary|varchar)\b(?:\s*\((\d+)\))? captures: - 1: storage.type.sql - 2: constant.numeric.sql + 0: storage.type.sql + 1: constant.numeric.sql expressions: + - match: (?i)\bas\b + scope: keyword.operator.assignment.alias.sql - match: \b\d+\b scope: meta.number.integer.decimal.sql constant.numeric.value.sql - match: (?i)\b(?:true|false)\b @@ -175,12 +188,11 @@ contexts: 1: support.function.sql 2: meta.group.sql punctuation.section.parens.begin.sql push: inside-method-call - - match: (\()(\)) - comment: Allow for special ↩ behavior - scope: meta.block.sql - captures: - 1: punctuation.section.scope.begin.sql - 2: punctuation.section.scope.end.sql + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-group + - match: \) + scope: invalid.illegal.trailing-paren.sql inside-method-call: - meta_content_scope: meta.group.sql @@ -191,6 +203,13 @@ contexts: scope: punctuation.separator.argument.sql - include: expressions + inside-group: + - meta_scope: meta.block.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: true + - include: main + statements: - include: ddl-statements - include: dml-statements diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 1b2cbdf1d3..eb27fad228 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -8,6 +8,16 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') #(?:\\[tnr]) contexts: + identifier: + - meta_prepend: true + - include: square-bracketed-identifier + + square-bracketed-identifier: + - match: (\[)([^]]+)(\]) + captures: + 1: punctuation.definition.identifier.begin.sql + 3: punctuation.definition.identifier.end.sql + strings: - meta_append: true - match: N' @@ -26,8 +36,14 @@ contexts: - like-string-followed-by-unknown-escape variables: - - match: (?:@\w+) - scope: variable.other.readwrite.tsql + - match: (@)\w+ + captures: + 0: variable.other.readwrite.sql + 1: punctuation.definition.variable.sql + - match: (@@)(?i:rowcount|trancount|error) + captures: + 0: support.variable.sql + 1: punctuation.definition.variable.sql like-string-not-followed-by-escape: - match: \' @@ -146,16 +162,31 @@ contexts: statements: - meta_append: true - include: declarations + - include: transaction-statements - match: \b(?i:go)\b scope: keyword.control.flow.tsql + - match: \b(?i:if|else|return|while)\b + scope: keyword.control.flow.tsql + - match: \b(?i:goto)\b + scope: keyword.control.flow.tsql + - match: \b(?i:exec)\b + scope: keyword.control.flow.tsql - match: \b(?i:begin)\b scope: keyword.control.flow.begin.tsql - match: \b(?i:end)\b scope: keyword.control.flow.end.tsql - - include: transaction-statements + - match: \b(?i:print)\b + scope: keyword.other.tsql + - match: \b(?i:use)\b + scope: keyword.context.tsql + push: single-identifier-after-whitespace + - match: \b(\w+)(:) + captures: + 1: entity.name.label.tsql + 2: punctuation.definition.label.tsql transaction-statements: - - match: (?i)\b(?:begin|commit|rollback)\s+tran(saction)?\b + - match: (?i)\b(?:begin|commit|rollback|save)\s+tran(saction)?\b scope: keyword.context.tsql declarations: @@ -168,6 +199,8 @@ contexts: scope: keyword.control.conditional.case.sql push: inside-case-expression - include: variables + - match: \b(?i:output|nowait)\b + scope: keyword.other.sql inside-case-expression: - meta_scope: meta.statement.conditional.case.sql @@ -185,3 +218,14 @@ contexts: - match: \b(?i:else)\b scope: keyword.control.conditional.else.sql - include: main + + dml-statements: + - meta_append: true + - match: \b(?i:bulk)\b + scope: keyword.other.tsql + - match: \b(?i:into)\b + scope: keyword.other.tsql + - match: \b(?i:off)\b + scope: keyword.other.tsql + - match: \b(?i:for\s+xml\s+path)\b + scope: keyword.other.tsql From c6eecfe73e9bf05fecd3d5ac66595c47442877f2 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 19 Sep 2021 23:11:14 +0300 Subject: [PATCH 004/250] [SQL] add TSQL tests, cleanup --- SQL/MySQL.sublime-syntax | 27 +++---- SQL/SQL (basic).sublime-syntax | 48 ++++++++---- SQL/TSQL.sublime-syntax | 28 +++++-- SQL/syntax_test_tsql.sql | 136 +++++++++++++++++++++++++++++++++ 4 files changed, 200 insertions(+), 39 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index c6955dd57c..a08d5c012a 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -86,26 +86,23 @@ contexts: types: - match: |- (?xi) + # normal stuff, capture 1 + \b(bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|int|integer|line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext)\b - # normal stuff, capture 1 - \b(bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|int|integer|line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext)\b + # numeric suffix, capture 2 + 3i + |\b(bit\svarying|character\s+(?:varying)?|tinyint|var\schar|float|interval)\((\d+)\) - # numeric suffix, capture 2 + 3i - |\b(bit\svarying|character\s+(?:varying)?|tinyint|var\schar|float|interval)\((\d+)\) + # optional numeric suffix, capture 4 + 5i + |\b(char|number|nvarchar|varbinary|varchar\d?)\b(?:\((\d+)\))? - # optional numeric suffix, capture 4 + 5i - |\b(char|number|nvarchar|varbinary|varchar\d?)\b(?:\((\d+)\))? - - # special case, capture 6 + 7i + 8i - |\b(numeric|decimal)\b(?:\((\d+),(\d+)\))? - - # special case, captures 9, 10i, 11 - |\b(times?)\b(?:\((\d+)\))?(\swith(?:out)?\s+time\s+zone\b)? - - # special case, captures 12, 13, 14i, 15 - |\b(timestamp)(?:(s|tz))?\b(?:\((\d+)\))?(\s(with|without)\s+time\s+zone\b)? + # special case, capture 6 + 7i + 8i + |\b(numeric|decimal)\b(?:\((\d+),(\d+)\))? + # special case, captures 9, 10i, 11 + |\b(times?)\b(?:\((\d+)\))?(\swith(?:out)?\s+time\s+zone\b)? + # special case, captures 12, 13, 14i, 15 + |\b(timestamp)(?:(s|tz))?\b(?:\((\d+)\))?(\s(with|without)\s+time\s+zone\b)? captures: 1: storage.type.sql 2: storage.type.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index f37c052be3..b821ea967c 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -161,8 +161,8 @@ contexts: - match: \b(?i:bit|bool|boolean|datetime|int)\b scope: storage.type.sql - match: \b(?i:char|number|nvarchar|varbinary|varchar)\b(?:\s*\((\d+)\))? + scope: storage.type.sql captures: - 0: storage.type.sql 1: constant.numeric.sql expressions: @@ -174,37 +174,53 @@ contexts: scope: constant.language.boolean.sql - match: (?i:\bnull\b) scope: constant.language.null.sql - - match: (?i)\b(?:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() - comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - scope: support.function.aggregate.sql - - match: (?i)\b(CURRENT_(DATE|TIME(STAMP)?|USER)|(SESSION|SYSTEM)_USER)\b - comment: List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - scope: support.function.scalar.sql - include: strings - include: operators - - match: \b(\w+)\s*(\() - captures: - 0: meta.function-call.sql - 1: support.function.sql - 2: meta.group.sql punctuation.section.parens.begin.sql - push: inside-method-call + - include: built-in-aggregate-function-calls + - include: built-in-scalar-function-calls + - include: user-defined-function-calls - match: \( scope: punctuation.section.group.begin.sql push: inside-group - match: \) scope: invalid.illegal.trailing-paren.sql + built-in-aggregate-function-calls: + # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + - match: (?i)\b(?:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() + scope: support.function.aggregate.sql + push: inside-method-call + + built-in-scalar-function-calls: + # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + - match: (?i)\b(CURRENT_(DATE|TIME(STAMP)?|USER)|(SESSION|SYSTEM)_USER)\b + scope: support.function.scalar.sql + + user-defined-function-calls: + - match: \b\w+(?=\s*\() + scope: support.function.sql + push: begin-method-call-paren + + begin-method-call-paren: + - meta_include_prototype: false + - meta_scope: meta.function-call.sql + - match: \( + scope: meta.group.sql punctuation.section.parens.begin.sql + set: inside-method-call + - match: (?=\S) + pop: true + inside-method-call: - - meta_content_scope: meta.group.sql + - meta_content_scope: meta.function-call.sql meta.group.sql - match: \) - scope: meta.group.sql punctuation.section.parens.end.sql + scope: meta.function-call.sql meta.group.sql punctuation.section.parens.end.sql pop: true - match: ',' scope: punctuation.separator.argument.sql - include: expressions inside-group: - - meta_scope: meta.block.sql + - meta_scope: meta.group.sql - match: \) scope: punctuation.section.group.end.sql pop: true diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index eb27fad228..011840473d 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -37,12 +37,16 @@ contexts: variables: - match: (@)\w+ + scope: variable.other.readwrite.sql captures: - 0: variable.other.readwrite.sql 1: punctuation.definition.variable.sql - - match: (@@)(?i:rowcount|trancount|error) + - match: |- + (?xi)(@@) + (?:cursor_rows|connections|cpu_busy|datefirst|dbts|error|fetch_status|identity|idle|io_busy|langid|language|lock_timeout| + max_connections|max_precision|nestlevel|options|packet_errors|pack_received|pack_sent|procid|remserver|rowcount| + servername|servicename|spid|textsize|timeticks|total_errors|total_read|total_write|trancount|version)\b + scope: support.variable.global.sql captures: - 0: support.variable.sql 1: punctuation.definition.variable.sql like-string-not-followed-by-escape: @@ -123,8 +127,8 @@ contexts: like-escape-character-any: - match: (\')([^'])(\') + scope: meta.string.escape.sql string.quoted.single.sql captures: - 0: meta.string.escape.sql string.quoted.single.sql 1: punctuation.definition.string.begin.sql 2: constant.character.escape.sql 3: punctuation.definition.string.end.sql @@ -134,8 +138,8 @@ contexts: like-escape-character-caret: - match: (\')(\^)(\') + scope: meta.string.escape.sql string.quoted.single.sql captures: - 0: meta.string.escape.sql string.quoted.single.sql 1: punctuation.definition.string.begin.sql 2: constant.character.escape.sql 3: punctuation.definition.string.end.sql @@ -145,8 +149,8 @@ contexts: like-escape-character-slash: - match: (\')(\\)(\') + scope: meta.string.escape.sql string.quoted.single.sql captures: - 0: meta.string.escape.sql string.quoted.single.sql 1: punctuation.definition.string.begin.sql 2: constant.character.escape.sql 3: punctuation.definition.string.end.sql @@ -194,14 +198,16 @@ contexts: scope: keyword.declaration.variable.tsql expressions: - - meta_append: true + - meta_prepend: true + - include: types - match: \b(?i:case)\b scope: keyword.control.conditional.case.sql push: inside-case-expression - include: variables - - match: \b(?i:output|nowait)\b + - match: \b(?i:output|nowait|cursor\s+for|open|fetch\s+next|close|deallocate)\b scope: keyword.other.sql + inside-case-expression: - meta_scope: meta.statement.conditional.case.sql - match: \b(?i:end)\b @@ -229,3 +235,9 @@ contexts: scope: keyword.other.tsql - match: \b(?i:for\s+xml\s+path)\b scope: keyword.other.tsql + + built-in-scalar-function-calls: + - meta_append: true + - match: (?i)\b(?:CONVERT|GETDATE)(?=\s*\() + scope: support.function.scalar.sql + push: begin-method-call-paren diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 706fe13f0d..3106894698 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -180,3 +180,139 @@ SET @Blah = CASE @x WHEN 2 THEN 'Y' WHEN @z THEN 'N' ELSE NULL END -- ^^^^ constant.language.null -- ^^^ keyword.control.conditional.end -- ^ - meta + + + +DECLARE @name SYSNAME -- database name +-- ^^^^ keyword.declaration.variable +-- ^ punctuation.definition.variable +-- ^^^^ variable.other.readwrite +-- ^^^^^^^ storage.type +-- ^^ comment.line.double-dash punctuation.definition.comment +DECLARE @path NVARCHAR(256) -- path for backup files +-- ^^^^ keyword.declaration.variable +-- ^ variable.other.readwrite punctuation.definition.variable +-- ^^^^ variable.other.readwrite +-- ^^^^^^^^^^^^^ storage.type +-- ^^^ constant.numeric +DECLARE @fileName NVARCHAR(256) -- filename for backup +DECLARE @fileDate VARCHAR(20) -- used for file name + +SET @path = 'C:\Backup\' + +SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) +-- ^ keyword.operator +-- ^^^^^^^ meta.function-call support.function.scalar +-- ^ meta.function-call meta.group punctuation.section.parens.begin +-- ^^^^^^^^^^^ storage.type +-- ^ punctuation.separator +-- ^^^^^^^ support.function.scalar +-- ^ punctuation.section.parens.begin +-- ^ punctuation.section.parens.end +-- ^ punctuation.separator.argument +-- ^^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.parens.end +-- ^ - meta.function-call - meta.group + +DECLARE db_cursor CURSOR FOR +-- ^^^^ keyword.declaration.variable +-- ^^^^^^^^^^ keyword.other + +SELECT name +FROM MASTER.dbo.sysdatabases +WHERE name NOT IN ('master','model','msdb','tempdb') + +OPEN db_cursor +-- ^ keyword.other +FETCH NEXT FROM db_cursor INTO @name +-- ^^^^^^^ keyword.other +-- ^^^^ keyword.other +-- ^^^^ keyword.other +-- ^^^^^ variable.other.readwrite + +WHILE @@FETCH_STATUS = 0 +-- ^^ keyword.control.flow +-- ^^^^^^^^^^^^^^ support.variable.global +-- ^^ support.variable.global +-- ^ keyword.operator.comparison +-- ^ meta.number.integer.decimal constant.numeric.value +BEGIN +-- ^^ keyword.control.flow.begin + SET @fileName = @path + @name + '_' + @fileDate + '.BAK' + BACKUP DATABASE @name TO DISK = @fileName + + FETCH NEXT FROM db_cursor INTO @name +END +-- <- keyword.control.flow.end + +CLOSE db_cursor +-- ^^ keyword.other +DEALLOCATE db_cursor +-- ^^^^^^^ keyword.other + +------------- + +DECLARE @FileExists INT +SET NOCOUNT ON +-- ^^ keyword +EXEC master.dbo.xp_fileexist @FromFile, @FileExists OUTPUT +-- ^ keyword.control.flow +-- ^^^^^^ keyword.other +SET NOCOUNT OFF +-- ^^^ keyword.other +IF @FileExists = 0 +BEGIN + RAISERROR ('File "%s" does not exist', 16, -1, @FromFile) + RETURN -1 + -- ^^^ keyword.control.flow + -- ^ keyword.operator.arithmetic + -- ^ meta.number.integer.decimal constant.numeric.value +END + +SET @Message = 'Importing data from file...' +RAISERROR (@Message, 0, 1) WITH NOWAIT +-- ^^^^^^ meta.function-call support.function +-- ^^^^ keyword.other +-- ^^^^^^ keyword.other + +SELECT COALESCE(a.field1, b.field2, c.field1) AS Blah, ISNULL(d.field1, 'default') as field1 +-- ^^^^^^^^ meta.function-call support.function +-- ^^ keyword.operator.assignment.alias +-- ^^^^^^ meta.function-call support.function +------------------------------- +EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'every 10 seconds', + @enabled=1, + @freq_type=4, + @freq_interval=1, + @freq_subday_type=2, + @freq_subday_interval=10, + @freq_relative_interval=0, + @freq_recurrence_factor=0, + @active_start_date=20150713, + @active_end_date=99991231, + @active_start_time=0, + @active_end_time=235959, + @schedule_uid=N'564354f8-4985-7408-80b7-afdc2bb92d3c' +IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback +-- ^^^^ keyword.control.flow +EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' +IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback +COMMIT TRANSACTION +-- ^^^^^^^^^^^^^^^ keyword.context +GOTO EndSave +QuitWithRollback: +-- ^^^^^^^^^^^^^ entity.name.label +-- ^ punctuation.definition.label + IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION + -- ^^^^^^^^^^^ meta.group support.variable.global + -- ^ keyword.operator.comparison +EndSave: + +------------- + +INSERT INTO my_table (foo, bar) +VALUES (2, 'two'), + (3, 'three') + + +-- merge, CTEs From c4ec9c32dd97c2e8c51bd7a1c1b334f5f89f7e43 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 19 Sep 2021 23:21:21 +0300 Subject: [PATCH 005/250] [SQL] split large match pattern into smaller ones/separate contexts --- Markdown/syntax_test_markdown.md | 6 +++--- SQL/MySQL.sublime-syntax | 10 ++++++++++ SQL/SQL (basic).sublime-syntax | 20 +++++++++++++++++++- SQL/TSQL.sublime-syntax | 2 ++ SQL/syntax_test_tsql.sql | 3 ++- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Markdown/syntax_test_markdown.md b/Markdown/syntax_test_markdown.md index 6cb5383c35..f78401f115 100644 --- a/Markdown/syntax_test_markdown.md +++ b/Markdown/syntax_test_markdown.md @@ -2578,9 +2578,9 @@ okay ```sql |^^^^^ meta.code-fence.definition.begin.sql | ^^^ constant.other.language-name -SELECT TOP 10 * -|^^^^^^^^^^^^^^^ markup.raw.code-fence.sql -|^^^^^^^^^ keyword.other.DML.sql +SELECT 10 * +|^^^^^^^^^^^ markup.raw.code-fence.sql +|^^^^^ keyword.other.DML.sql FROM TableName ``` |^^ meta.code-fence.definition.end.sql punctuation.definition.raw.code-fence.end - markup diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index a08d5c012a..d43700d238 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -135,3 +135,13 @@ contexts: - meta_append: true - match: (?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b) scope: keyword.other.LUW.sql + + dml-statements: + - meta_append: true + - match: (?i)\b(?:using|limit)\b + scope: keyword.other.DML.sql + + joins: + - meta_append: true + - match: (?i)\b(?:straight_join|natural)\b + scope: keyword.other.DML.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index b821ea967c..a5f97bc220 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -272,7 +272,25 @@ contexts: scope: keyword.other.authorization.sql dml-statements: - - match: (?i:\b(select(\s+(distinct|top))?|insert(\s+(ignore\s+)?into)?|update|delete|truncate|from|set|where|group\s+by|with|union(\s+all)?|using|order\s+by|limit|(inner|cross)\s+join|join|straight_join|(left|right)(\s+outer)?\s+join|natural(\s+(left|right)(\s+outer)?)?\s+join)\b) + - match: (?i:\bselect\b) + scope: keyword.other.DML.sql + - match: (?i:\bunion(?:\s+all)?\b) + scope: keyword.other.DML.sql + - match: (?i:\b(?:insert(\s+(?:ignore\s+)?into)?|update|delete|truncate)\b) + scope: keyword.other.DML.sql + push: single-identifier + - match: (?i:\b(?:set|with)\b) scope: keyword.other.DML.sql - match: (?i:\bvalues\b) scope: keyword.other.DML.II.sql + - include: joins + - match: \b(?i:distinct)\b + scope: keyword.other.DML.sql + - match: \b(?i:group\s+by|order\s+by|having|where)\b + scope: keyword.other.DML.sql + - match: \b(?i:from)\b + scope: keyword.other.DML.sql + + joins: + - match: (?i)\b(?:inner|(?:full\s+)?outer|cross|left|right)\s+join\b + scope: keyword.other.DML.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 011840473d..05925fc82c 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -235,6 +235,8 @@ contexts: scope: keyword.other.tsql - match: \b(?i:for\s+xml\s+path)\b scope: keyword.other.tsql + - match: \b(?i:top)\b + scope: keyword.other.DML.tsql built-in-scalar-function-calls: - meta_append: true diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 3106894698..fea20b5e0a 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -124,7 +124,8 @@ DECLARE @Example INT = 5 -- ^ constant.numeric SELECT TOP 1 @Example = 4 FROM [dbo].[TableName] --- ^^^^^^^ keyword.other.DML +-- ^^^ keyword.other.DML +-- ^^^ keyword.other.DML -- ^ constant.numeric -- ^^^^^^^^ variable.other.readwrite -- ^ keyword.operator From f5c2a7274816ae50eb756a5a9d2fd7417c11d509 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 19 Sep 2021 23:27:10 +0300 Subject: [PATCH 006/250] [SQL] small refactor for create statements --- SQL/SQL (basic).sublime-syntax | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index a5f97bc220..fc0dd90c29 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -7,7 +7,7 @@ version: 2 variables: string_escape: (?:\\.) - dml_targets: (?:aggregate|conversion|database|domain|function|group|((?:fulltext|spatial|unique)\s+)?index|language|operator class|operator|procedure|rule|schema|sequence|table(?:space)?|trigger|type|user|view) + dml_targets: (?i:aggregate|conversion|database|domain|function|group|((?:fulltext|spatial|unique)\s+)?index|language|operator class|operator|procedure|rule|schema|sequence|table(?:space)?|trigger|type|user|view) contexts: prototype: @@ -231,18 +231,9 @@ contexts: - include: dml-statements ddl-statements: - - match: |- - (?xi) - \b(create(?:\s+or\s+replace)?)\s+ - ({{dml_targets}}) - \b\s* - (on)?\b - scope: meta.create.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.sql - 3: keyword.other.sql - push: create-condition + - match: \b(?i:create(?:\s+or\s+replace)?)\b + scope: keyword.other.create.sql + push: ddl-create-target - match: (?i:\s*\b(drop)\s+({{dml_targets}})) scope: meta.drop.sql captures: @@ -271,6 +262,18 @@ contexts: - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) scope: keyword.other.authorization.sql + ddl-create-target: + - meta_scope: meta.create.sql + - match: |- + (?xi) + ({{dml_targets}})\b\s* + (on)?\b + captures: + 1: keyword.other.sql + set: create-condition + - match: (?=\S) + pop: true + dml-statements: - match: (?i:\bselect\b) scope: keyword.other.DML.sql From 0880aad8f0e5b0e79c722642206cf5904bd68b69 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 19 Sep 2021 23:36:45 +0300 Subject: [PATCH 007/250] [SQL] fix for table name and column list after "insert into" --- SQL/SQL (basic).sublime-syntax | 2 +- SQL/syntax_test_tsql.sql | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index fc0dd90c29..5f931c4be2 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -281,7 +281,7 @@ contexts: scope: keyword.other.DML.sql - match: (?i:\b(?:insert(\s+(?:ignore\s+)?into)?|update|delete|truncate)\b) scope: keyword.other.DML.sql - push: single-identifier + push: single-identifier-after-whitespace - match: (?i:\b(?:set|with)\b) scope: keyword.other.DML.sql - match: (?i:\bvalues\b) diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index fea20b5e0a..0cbc932235 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -312,7 +312,10 @@ EndSave: ------------- INSERT INTO my_table (foo, bar) +-- ^^^^^^^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^^ - meta.function-call - support VALUES (2, 'two'), +-- ^^^ keyword.other.DML.II (3, 'three') From e2492f76bcae13de1d2ead46fabda238614fd8fa Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 20 Sep 2021 22:02:58 +0300 Subject: [PATCH 008/250] [SQL] fix aggregate functions and scope db/table/column names in some places --- SQL/MySQL.sublime-syntax | 8 +++++++ SQL/SQL (basic).sublime-syntax | 41 +++++++++++++++++++++++----------- SQL/TSQL.sublime-syntax | 3 ++- SQL/syntax_test_mysql.sql | 1 + SQL/syntax_test_tsql.sql | 30 +++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 14 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index d43700d238..c8480f35a0 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -136,8 +136,16 @@ contexts: - match: (?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b) scope: keyword.other.LUW.sql + ddl-statements: + - meta_append: true + - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) + scope: keyword.other.object-comments.sql + dml-statements: - meta_append: true + - match: (?i:\binsert(\s+(?:ignore\s+)?into)?\b) + scope: keyword.other.DML.sql + push: [table-name, single-identifier-after-whitespace] - match: (?i)\b(?:using|limit)\b scope: keyword.other.DML.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 5f931c4be2..30352b7ee9 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -7,6 +7,7 @@ version: 2 variables: string_escape: (?:\\.) + simple_identifier: (?:\w+) dml_targets: (?i:aggregate|conversion|database|domain|function|group|((?:fulltext|spatial|unique)\s+)?index|language|operator class|operator|procedure|rule|schema|sequence|table(?:space)?|trigger|type|user|view) contexts: @@ -16,14 +17,6 @@ contexts: main: - include: statements - include: types - - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) - scope: keyword.other.object-comments.sql - - match: (?i)\bon\b - scope: keyword.operator.join.sql - - match: (?i)\b(asc|desc)\b - scope: keyword.other.order.sql - - match: \* - scope: variable.language.wildcard.asterisk.sql - include: expressions - match: ',' scope: punctuation.separator.sequence.sql @@ -109,8 +102,8 @@ contexts: pop: true simple-identifier: - - match: \w+(?=\s*\.) - - match: \w+ + - match: '{{simple_identifier}}(?=\s*\.)' + - match: '{{simple_identifier}}' pop: true single-quoted-identifier: @@ -168,6 +161,7 @@ contexts: expressions: - match: (?i)\bas\b scope: keyword.operator.assignment.alias.sql + push: [column-alias, single-identifier-after-whitespace] - match: \b\d+\b scope: meta.number.integer.decimal.sql constant.numeric.value.sql - match: (?i)\b(?:true|false)\b @@ -189,7 +183,7 @@ contexts: # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - match: (?i)\b(?:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() scope: support.function.aggregate.sql - push: inside-method-call + push: begin-method-call-paren built-in-scalar-function-calls: # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html @@ -279,9 +273,9 @@ contexts: scope: keyword.other.DML.sql - match: (?i:\bunion(?:\s+all)?\b) scope: keyword.other.DML.sql - - match: (?i:\b(?:insert(\s+(?:ignore\s+)?into)?|update|delete|truncate)\b) + - match: (?i:\b(?:insert\s+into|update|delete(?:\s+from)?|truncate)\b) scope: keyword.other.DML.sql - push: single-identifier-after-whitespace + push: [table-name, single-identifier-after-whitespace] - match: (?i:\b(?:set|with)\b) scope: keyword.other.DML.sql - match: (?i:\bvalues\b) @@ -293,7 +287,28 @@ contexts: scope: keyword.other.DML.sql - match: \b(?i:from)\b scope: keyword.other.DML.sql + - match: (?i)\b(asc|desc)\b + scope: keyword.other.order.sql + - match: (?i)\bon\b + scope: keyword.operator.join.sql + - match: \* + scope: variable.language.wildcard.asterisk.sql joins: - match: (?i)\b(?:inner|(?:full\s+)?outer|cross|left|right)\s+join\b scope: keyword.other.DML.sql + + column-alias: + - meta_content_scope: meta.column-name.sql constant.other.placeholder.sql + - match: '' + pop: true + + database-name: + - meta_content_scope: meta.database-name.sql constant.other.placeholder.sql + - match: '' + pop: true + + table-name: + - meta_content_scope: meta.table-name.sql constant.other.placeholder.sql + - match: '' + pop: true diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 05925fc82c..8861bce24b 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -7,6 +7,7 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') #(?:\\[tnr]) + simple_identifier: (?:#?\w+) contexts: identifier: - meta_prepend: true @@ -183,7 +184,7 @@ contexts: scope: keyword.other.tsql - match: \b(?i:use)\b scope: keyword.context.tsql - push: single-identifier-after-whitespace + push: [database-name, single-identifier-after-whitespace] - match: \b(\w+)(:) captures: 1: entity.name.label.tsql diff --git a/SQL/syntax_test_mysql.sql b/SQL/syntax_test_mysql.sql index a79893847d..5651a832fc 100644 --- a/SQL/syntax_test_mysql.sql +++ b/SQL/syntax_test_mysql.sql @@ -187,6 +187,7 @@ SELECT *, -- ^ variable.language.wildcard.asterisk.sql f.id AS database_id -- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^^^^^^ meta.column-name constant.other.placeholder FROM foo WHERE f.a IS NULL -- ^^ keyword.other.DML.sql diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 0cbc932235..a2454f7755 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -1,5 +1,9 @@ -- SYNTAX TEST "Packages/SQL/TSQL.sublime-syntax" +USE master +-- <- keyword.context - constant +-- ^^^^^^ meta.database-name constant.other.placeholder + SELECT columns FROM table WHERE column LIKE '%[[]SQL Server Driver]%' -- ^^^^ keyword.operator.logical @@ -314,9 +318,35 @@ EndSave: INSERT INTO my_table (foo, bar) -- ^^^^^^^^ keyword.other.DML -- ^^^^^^^^^^^^^^^^^^^^ - meta.function-call - support +-- ^^^^^^^^ meta.table-name constant.other.placeholder VALUES (2, 'two'), -- ^^^ keyword.other.DML.II (3, 'three') +INSERT INTO #my_table +-- ^^^^^^^^ keyword.other.DML +-- ^^^^^^^^^ meta.table-name constant.other.placeholder - meta.function-call - support +VALUES (2, 'two'), +-- ^^^ keyword.other.DML.II + (3, 'three') + + + +SELECT foo, COUNT(*) AS tally +-- ^^^ keyword.other.DML +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ meta.function-call +-- ^^^^^ support.function.aggregate +-- ^^^ meta.group +-- ^ punctuation.section.parens.begin +-- ^ punctuation.section.parens.end +-- ^^ keyword.operator.assignment.alias +-- ^^^^^ meta.column-name constant.other.placeholder +FROM bar +-- ^ keyword.other.DML +WHERE 1 = 1 +-- ^^ keyword.other.DML +GROUP BY foo +-- ^^^^^ keyword.other.DML -- merge, CTEs From 46083207bbf7b22972bc9a71e502366a8320f439 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 20 Sep 2021 22:43:52 +0300 Subject: [PATCH 009/250] [SQL] add scoping for cursors and labels in Transact-SQL syntax, table aliases --- SQL/MySQL.sublime-syntax | 7 ++++ SQL/SQL (basic).sublime-syntax | 21 +++++++++- SQL/TSQL.sublime-syntax | 26 +++++++++++-- SQL/syntax_test_tsql.sql | 70 ++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 5 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index c8480f35a0..e824fad5b3 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -153,3 +153,10 @@ contexts: - meta_append: true - match: (?i)\b(?:straight_join|natural)\b scope: keyword.other.DML.sql + + maybe-subquery: + - meta_include_prototype: false + - meta_prepend: true + - match: (?=#) + pop: true + - include: comments diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 30352b7ee9..299e5b0c46 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -168,6 +168,8 @@ contexts: scope: constant.language.boolean.sql - match: (?i:\bnull\b) scope: constant.language.null.sql + - match: \* + scope: variable.language.wildcard.asterisk.sql - include: strings - include: operators - include: built-in-aggregate-function-calls @@ -287,16 +289,16 @@ contexts: scope: keyword.other.DML.sql - match: \b(?i:from)\b scope: keyword.other.DML.sql + push: maybe-subquery - match: (?i)\b(asc|desc)\b scope: keyword.other.order.sql - match: (?i)\bon\b scope: keyword.operator.join.sql - - match: \* - scope: variable.language.wildcard.asterisk.sql joins: - match: (?i)\b(?:inner|(?:full\s+)?outer|cross|left|right)\s+join\b scope: keyword.other.DML.sql + push: maybe-subquery column-alias: - meta_content_scope: meta.column-name.sql constant.other.placeholder.sql @@ -312,3 +314,18 @@ contexts: - meta_content_scope: meta.table-name.sql constant.other.placeholder.sql - match: '' pop: true + + maybe-subquery: + - match: \( + scope: punctuation.section.group.begin.sql + set: [table-alias, inside-group] + - match: (?=\S) + set: [table-alias, table-name, single-identifier] + + table-alias: + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + - match: (?i)(?=\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|;|with)\b) + pop: true + - match: (?=\S) + set: [table-name, single-identifier] diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 8861bce24b..0f7a74cb3d 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -7,7 +7,7 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') #(?:\\[tnr]) - simple_identifier: (?:#?\w+) + simple_identifier: (?:[#@]?\w+) contexts: identifier: - meta_prepend: true @@ -174,6 +174,7 @@ contexts: scope: keyword.control.flow.tsql - match: \b(?i:goto)\b scope: keyword.control.flow.tsql + push: [label-name, single-identifier-after-whitespace] - match: \b(?i:exec)\b scope: keyword.control.flow.tsql - match: \b(?i:begin)\b @@ -197,6 +198,7 @@ contexts: declarations: - match: \b(?i:declare)\b scope: keyword.declaration.variable.tsql + push: after-declare expressions: - meta_prepend: true @@ -205,9 +207,11 @@ contexts: scope: keyword.control.conditional.case.sql push: inside-case-expression - include: variables - - match: \b(?i:output|nowait|cursor\s+for|open|fetch\s+next|close|deallocate)\b + - match: \b(?i:output|nowait)\b scope: keyword.other.sql - + - match: \b(?i:cursor\s+for|open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b + scope: keyword.other.sql + push: [cursor-name, single-identifier-after-whitespace] inside-case-expression: - meta_scope: meta.statement.conditional.case.sql @@ -244,3 +248,19 @@ contexts: - match: (?i)\b(?:CONVERT|GETDATE)(?=\s*\() scope: support.function.scalar.sql push: begin-method-call-paren + + label-name: + - meta_content_scope: meta.label-name.sql constant.other.placeholder.sql + - match: '' + pop: true + + cursor-name: + - meta_content_scope: meta.cursor-name.sql constant.other.placeholder.sql + - match: '' + pop: true + + after-declare: + - match: (?=\w+\s+(?i:cursor)\b) + set: [cursor-name, single-identifier] + - match: (?=\S) + pop: true diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index a2454f7755..9d6535be32 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -221,17 +221,23 @@ SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) DECLARE db_cursor CURSOR FOR -- ^^^^ keyword.declaration.variable +-- ^^^^^^^^^ meta.cursor-name constant.other.placeholder -- ^^^^^^^^^^ keyword.other SELECT name FROM MASTER.dbo.sysdatabases +-- ^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder WHERE name NOT IN ('master','model','msdb','tempdb') +-- ^^ keyword.other.DML OPEN db_cursor -- ^ keyword.other +-- ^^^^^^^^^ meta.cursor-name constant.other.placeholder FETCH NEXT FROM db_cursor INTO @name -- ^^^^^^^ keyword.other -- ^^^^ keyword.other +-- ^^^^^^^^^ meta.cursor-name constant.other.placeholder -- ^^^^ keyword.other -- ^^^^^ variable.other.readwrite @@ -252,8 +258,10 @@ END CLOSE db_cursor -- ^^ keyword.other +-- ^^^^^^^^^ meta.cursor-name constant.other.placeholder DEALLOCATE db_cursor -- ^^^^^^^ keyword.other +-- ^^^^^^^^^ meta.cursor-name constant.other.placeholder ------------- @@ -300,6 +308,7 @@ EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'every 10 @schedule_uid=N'564354f8-4985-7408-80b7-afdc2bb92d3c' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback -- ^^^^ keyword.control.flow +-- ^^^^^^^^^^^^^^^^ meta.label-name constant.other.placeholder EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback COMMIT TRANSACTION @@ -339,14 +348,75 @@ SELECT foo, COUNT(*) AS tally -- ^^^^^ support.function.aggregate -- ^^^ meta.group -- ^ punctuation.section.parens.begin +-- ^ variable.language.wildcard.asterisk -- ^ punctuation.section.parens.end -- ^^ keyword.operator.assignment.alias -- ^^^^^ meta.column-name constant.other.placeholder FROM bar -- ^ keyword.other.DML +-- ^^^ meta.table-name constant.other.placeholder WHERE 1 = 1 -- ^^ keyword.other.DML GROUP BY foo -- ^^^^^ keyword.other.DML +select * +from (select * from some_table) alias_table WITH (NOLOCK) +-- ^ keyword.other.DML +-- ^ punctuation.section.group.begin +-- ^^^^^^ keyword.other.DML +-- ^ variable.language.wildcard.asterisk +-- ^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^ punctuation.section.group.end +-- ^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^ keyword.other.DML +-- ^ meta.group punctuation.section.group.begin +-- ^ punctuation.section.group.end +where exists(select * from other_table where id = some_table.id) +-- ^^^^^^ keyword.operator.logical + +UPDATE TableAlias +-- ^^^ keyword.other.DML +-- ^^^^^^^^^^ meta.table-name constant.other.placeholder +SET column1 = v.column1, +-- <- keyword.other.DML +--^ keyword.other.DML + column2 = 'testing123 TODO: assert the = operator is scoped as assignment instead of comparison' +-- ^ keyword.operator +FROM RealTableName TableAlias WITH (UPDLOCK) +-- ^ keyword.other.DML +-- ^^^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^ keyword.other.DML +INNER JOIN some_view AS v WITH (NOLOCK) ON v.some_id = TableAlias.some_id +-- ^^^^^^^ keyword.other.DML +-- ^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^ keyword.operator.assignment.alias +-- ^ meta.table-name constant.other.placeholder +-- ^^^^ keyword.other.DML +-- ^^ keyword.operator.join +-- ^ keyword.operator.comparison +WHERE TableAlias.some_id IN ( +-- ^^ keyword.other.DML +-- ^^ keyword.operator.logical +-- ^ meta.group punctuation.section.group.begin + SELECT a.another_id_column +-- ^^^^^^ keyword.other.DML + FROM dbname..table_name_in_default_schema a +-- ^^^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^ meta.group meta.table-name constant.other.placeholder + WHERE a.another_id_column IS NOT NULL +-- ^^^^^ meta.group keyword.other.DML +-- ^^ keyword.operator.logical +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null + AND a.another_field IS NOT NULL +) +AND (v.column2 IS NULL OR ISNULL(TableAlias.column1, 0) != v.column1) +-- <- keyword.operator.logical +-- ^^ meta.group keyword.operator.logical +-- ^^^^^^ meta.function-call support.function +-- ^^ keyword.operator.comparison + -- merge, CTEs From 25417900490f40f3c0406c63c312b5701dd6c5ef Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 21 Sep 2021 23:14:01 +0300 Subject: [PATCH 010/250] [SQL] scope join columns and TSQL WITH contents --- Markdown/syntax_test_markdown.md | 4 +- PHP/tests/syntax_test_php.php | 4 +- SQL/SQL (basic).sublime-syntax | 111 ++++++++++++++++++++++--------- SQL/TSQL.sublime-syntax | 42 +++++++++++- SQL/syntax_test_mysql.sql | 26 +++++--- SQL/syntax_test_tsql.sql | 63 ++++++++++++++++-- 6 files changed, 197 insertions(+), 53 deletions(-) diff --git a/Markdown/syntax_test_markdown.md b/Markdown/syntax_test_markdown.md index f78401f115..a2cc25873d 100644 --- a/Markdown/syntax_test_markdown.md +++ b/Markdown/syntax_test_markdown.md @@ -2578,8 +2578,8 @@ okay ```sql |^^^^^ meta.code-fence.definition.begin.sql | ^^^ constant.other.language-name -SELECT 10 * -|^^^^^^^^^^^ markup.raw.code-fence.sql +SELECT * +|^^^^^^^^ markup.raw.code-fence.sql |^^^^^ keyword.other.DML.sql FROM TableName ``` diff --git a/PHP/tests/syntax_test_php.php b/PHP/tests/syntax_test_php.php index db38593122..07138d93d4 100644 --- a/PHP/tests/syntax_test_php.php +++ b/PHP/tests/syntax_test_php.php @@ -1639,12 +1639,12 @@ function generate2() // ^ meta.string.php string.quoted.double.php punctuation.definition.string.begin.php - meta.interpolation - string string // ^^^^^^^^^^^^^^^^^^^^ meta.string.php meta.interpolation.php source.sql - string.quoted.double.php // ^ meta.string.php string.quoted.double.php punctuation.definition.string.end.php - meta.interpolation - string string -// ^^^^^^ keyword.other.create.sql +// ^^^^^^ keyword.other.ddl.sql $sql = " CREATE TABLE `version`... // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php meta.interpolation.php source.sql - string.quoted.double.php -// ^^^^^^ keyword.other.create.sql +// ^^^^^^ keyword.other.ddl.sql "; // Do not highlight plain SQL indicator as SQL diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 299e5b0c46..aac30abee1 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -9,6 +9,7 @@ variables: string_escape: (?:\\.) simple_identifier: (?:\w+) dml_targets: (?i:aggregate|conversion|database|domain|function|group|((?:fulltext|spatial|unique)\s+)?index|language|operator class|operator|procedure|rule|schema|sequence|table(?:space)?|trigger|type|user|view) + reserved: (?i:\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|;|with)\b) contexts: prototype: @@ -132,7 +133,7 @@ contexts: drop-condition: - include: dml-condition - match: (?=\S) - pop: true + set: single-identifier-after-whitespace dml-condition: - match: (?i:\b(if)\b) @@ -228,31 +229,20 @@ contexts: ddl-statements: - match: \b(?i:create(?:\s+or\s+replace)?)\b - scope: keyword.other.create.sql + scope: keyword.other.ddl.sql push: ddl-create-target - - match: (?i:\s*\b(drop)\s+({{dml_targets}})) - scope: meta.drop.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.sql - push: drop-condition - - match: (?i:\s*(drop)\s+(table)\s+(\w+)(\s+cascade)?\b) - scope: meta.drop.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.table.sql - 3: entity.name.function.sql - 4: keyword.other.cascade.sql - - match: (?i:\s*\b(alter)\s+({{dml_targets}})\s+) - scope: meta.alter.sql - captures: - 1: keyword.other.create.sql - 2: keyword.other.table.sql - - match: (?i:\s*\b(add)\s+(column|constraint|fulltext\s+(index|key)|index|spatial\s+(index|key))) - scope: meta.add.sql - captures: - 1: keyword.other.add.sql - 2: keyword.other.sql + - match: (?i:\bdrop\s+table\b) + scope: keyword.other.ddl.sql + push: ddl-drop-table + - match: \b(?i:drop)\b + scope: keyword.other.ddl.sql + push: ddl-drop-target + - match: \b(?i:alter\s+table)\b + scope: keyword.other.ddl.sql + push: [ddl-alter-table, table-name, single-identifier-after-whitespace] + - match: \b(?i:alter)\b + scope: keyword.other.ddl.sql + push: ddl-alter-target - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) scope: storage.modifier.sql - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) @@ -270,6 +260,46 @@ contexts: - match: (?=\S) pop: true + ddl-drop-target: + - meta_scope: meta.drop.sql + - match: |- + (?xi) + \b{{dml_targets}}\b + captures: + 1: keyword.other.sql + set: drop-condition + - match: (?=\S) + set: drop-condition + + ddl-drop-table: + - meta_scope: meta.drop.sql + - include: dml-condition + - match: (?=\S) + set: [table-name, single-identifier-after-whitespace] + + ddl-alter-table: + - meta_scope: meta.alter.sql + - match: \b(?i:add(?:\s+column)?|alter\s+column)\b + scope: keyword.other.ddl.sql + push: [column-alias, single-identifier-after-whitespace] + - include: expressions + - include: ddl-alter-common + - match: (?=\S) + pop: true + + ddl-alter-target: + - meta_scope: meta.alter.sql + - include: ddl-alter-common + - match: (?=\S) + pop: true + + ddl-alter-common: + - match: (?i:\s*\b(add)\s+(constraint|(?:fulltext|spatial)\s+(index|key)|index)) + scope: meta.add.sql + captures: + 1: keyword.other.add.sql + 2: keyword.other.sql + dml-statements: - match: (?i:\bselect\b) scope: keyword.other.DML.sql @@ -278,8 +308,9 @@ contexts: - match: (?i:\b(?:insert\s+into|update|delete(?:\s+from)?|truncate)\b) scope: keyword.other.DML.sql push: [table-name, single-identifier-after-whitespace] - - match: (?i:\b(?:set|with)\b) + - match: (?i:\bset\b) scope: keyword.other.DML.sql + push: set - match: (?i:\bvalues\b) scope: keyword.other.DML.II.sql - include: joins @@ -292,13 +323,11 @@ contexts: push: maybe-subquery - match: (?i)\b(asc|desc)\b scope: keyword.other.order.sql - - match: (?i)\bon\b - scope: keyword.operator.join.sql joins: - match: (?i)\b(?:inner|(?:full\s+)?outer|cross|left|right)\s+join\b scope: keyword.other.DML.sql - push: maybe-subquery + push: [join-on, maybe-subquery] column-alias: - meta_content_scope: meta.column-name.sql constant.other.placeholder.sql @@ -325,7 +354,27 @@ contexts: table-alias: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql - - match: (?i)(?=\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|;|with)\b) + - match: (?={{reserved}}) + pop: true + - match: (?=\S) + set: [after-table-alias, table-name, single-identifier] + + after-table-alias: + - match: (?=\S) + pop: true + + join-on: + - match: (?i)\bon\b + scope: keyword.operator.join.sql + push: [join-operators, column-alias, single-identifier-after-whitespace] + - match: (?=\S) pop: true + + join-operators: + - include: operators - match: (?=\S) - set: [table-name, single-identifier] + set: [column-alias, single-identifier-after-whitespace] + + set: + - match: (?=\S) + pop: true diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 0f7a74cb3d..7247f0e6ed 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -161,7 +161,7 @@ contexts: types: - meta_append: true - - match: (?i:\b(?:smallint|sysname)\b) + - match: (?i:\b(?:smallint|sysname|uniqueidentifier|decimal)\b) scope: storage.type.sql statements: @@ -207,7 +207,8 @@ contexts: scope: keyword.control.conditional.case.sql push: inside-case-expression - include: variables - - match: \b(?i:output|nowait)\b + - include: with + - match: \b(?i:output|over|partition\s+by)\b scope: keyword.other.sql - match: \b(?i:cursor\s+for|open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b scope: keyword.other.sql @@ -264,3 +265,40 @@ contexts: set: [cursor-name, single-identifier] - match: (?=\S) pop: true + + set: + - meta_prepend: true + - match: \b(?i:nocount)\b + scope: constant.language.switch.tsql + - match: \b(?i:on|off)\b + scope: constant.language.boolean.tsql + - match: (?=\S) + pop: true + + after-table-alias: + - meta_prepend: true + - include: with + + with: + - match: (?i)\bwith\b + scope: keyword.other.DML.sql + push: with-paren + + with-paren: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-with-group + - match: \b(?i:nowait)\b + scope: keyword.other.tsql + - match: (?=\S) + pop: true + + inside-with-group: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: true + - match: \w+ + scope: constant.language.with.tsql + - match: ',' + scope: punctuation.separator.sequence.tsql diff --git a/SQL/syntax_test_mysql.sql b/SQL/syntax_test_mysql.sql index 5651a832fc..1d5d894faf 100644 --- a/SQL/syntax_test_mysql.sql +++ b/SQL/syntax_test_mysql.sql @@ -20,35 +20,35 @@ SELECT "My /* Crazy Column Name" FROM my_table; ;CREATE TABLE foo (id INTEGER PRIMARY KEY); - -- <- keyword.other.create ---^^^^^ keyword.other.create + -- <- meta.create keyword.other.ddl +--^^^^^ keyword.other.ddl -- ^^^^^ keyword.other -- ^^^ entity.name.function -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - entity.name.function create table some_schema.test2( id serial ); ---^^^^ meta.create keyword.other.create +--^^^^ meta.create keyword.other.ddl -- ^^^^^ meta.create keyword.other -- ^^^^^^^^^^^^^^^^^ entity.name.function -- ^ punctuation.accessor.dot -- ^^^^^^^^^^^^^^ - entity.name.function create table some_schema . test2 ( id serial ); ---^^^^ meta.create keyword.other.create +--^^^^ meta.create keyword.other.ddl -- ^^^^^ meta.create keyword.other -- ^^^^^^^^^^^^^^^^^^^ entity.name -- ^ punctuation.accessor.dot -- ^^^^^^^^^^^^^^^ - entity.name.function create table "testing123" (id integer); ---^^^^ meta.create keyword.other.create +--^^^^ meta.create keyword.other.ddl -- ^^^^^ meta.create keyword.other -- ^ punctuation.definition.identifier.begin -- ^^^^^^^^^^ entity.name.function -- ^ punctuation.definition.identifier.end create table `dbo`."testing123" (id integer); ---^^^^ meta.create keyword.other.create +--^^^^ meta.create keyword.other.ddl -- ^^^^^ meta.create keyword.other -- ^^^^^^^^^^^^^^^^^^ entity.name.function -- ^ punctuation.accessor.dot @@ -130,18 +130,22 @@ create fulltext index if not exists `myindex` ON mytable; -- ^^^^^^^^^^^^^^ keyword.other.sql ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; --- ^^ keyword.other --- ^^^^^ keyword.other.table --- ^^^ keyword.other.add.sql --- ^^^^^^ keyword.other.sql +-- ^^^^^^^^ meta.alter keyword.other.ddl +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.alter meta.column-name constant.other.placeholder -- ^^^^^^^^ storage.type.sql ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); -- ^^^^ storage.type.sql DROP TABLE IF EXISTS testing123; --- <- meta.drop.sql keyword.other.create.sql +-- <- meta.drop.sql keyword.other.ddl.sql +-- ^^^^^^^ meta.drop keyword.other.ddl +-- ^^ meta.drop keyword.control.flow -- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^ punctuation.terminator.statement select * from some_table diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 9d6535be32..64f451b383 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -267,12 +267,16 @@ DEALLOCATE db_cursor DECLARE @FileExists INT SET NOCOUNT ON --- ^^ keyword +--^ keyword.other.DML +-- ^^^^^^^ constant.language.switch +-- ^^ constant.language.boolean EXEC master.dbo.xp_fileexist @FromFile, @FileExists OUTPUT -- ^ keyword.control.flow -- ^^^^^^ keyword.other SET NOCOUNT OFF --- ^^^ keyword.other +--^ keyword.other.DML +-- ^^^^^^^ constant.language.switch +-- ^^^ constant.language.boolean IF @FileExists = 0 BEGIN RAISERROR ('File "%s" does not exist', 16, -1, @FromFile) @@ -370,7 +374,8 @@ from (select * from some_table) alias_table WITH (NOLOCK) -- ^ punctuation.section.group.end -- ^^^^^^^^^^^ meta.table-name constant.other.placeholder -- ^^^^ keyword.other.DML --- ^ meta.group punctuation.section.group.begin +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.group constant.language.with -- ^ punctuation.section.group.end where exists(select * from other_table where id = some_table.id) -- ^^^^^^ keyword.operator.logical @@ -383,19 +388,34 @@ SET column1 = v.column1, --^ keyword.other.DML column2 = 'testing123 TODO: assert the = operator is scoped as assignment instead of comparison' -- ^ keyword.operator -FROM RealTableName TableAlias WITH (UPDLOCK) +FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^ keyword.other.DML -- ^^^^^^^^^^^^^ meta.table-name constant.other.placeholder -- ^^^^^^^^^^ meta.table-name constant.other.placeholder --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ - meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^ constant.language.with +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ meta.group constant.language.with +-- ^ punctuation.section.group.end INNER JOIN some_view AS v WITH (NOLOCK) ON v.some_id = TableAlias.some_id -- ^^^^^^^ keyword.other.DML -- ^^^^^^^^^ meta.table-name constant.other.placeholder -- ^^ keyword.operator.assignment.alias -- ^ meta.table-name constant.other.placeholder -- ^^^^ keyword.other.DML +-- ^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^ constant.language.with +-- ^ punctuation.section.group.end -- ^^ keyword.operator.join +-- ^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^ punctuation.accessor.dot -- ^ keyword.operator.comparison +-- ^^^^^^^^^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^ punctuation.accessor.dot WHERE TableAlias.some_id IN ( -- ^^ keyword.other.DML -- ^^ keyword.operator.logical @@ -419,4 +439,37 @@ AND (v.column2 IS NULL OR ISNULL(TableAlias.column1, 0) != v.column1) -- ^^^^^^ meta.function-call support.function -- ^^ keyword.operator.comparison +drop table foobar +-- ^^^^^^^ meta.drop keyword.other.ddl +-- ^^^^^^ meta.table-name constant.other.placeholder + +alter table foo +-- ^^^^^^^^ meta.alter keyword.other.ddl +-- ^^^ meta.alter meta.table-name constant.other.placeholder +add bar uniqueidentifier +--^ meta.alter keyword.other.ddl +-- ^^^ meta.alter meta.column-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^ meta.alter storage.type + +alter table foo +--^^^^^^^^^ meta.alter keyword.other.ddl - meta.alter meta.alter +-- ^^^ meta.alter meta.table-name constant.other.placeholder +alter column bar uniqueidentifier not null +--^^^^^^^^^^ meta.alter keyword.other.ddl +-- ^^^ meta.alter meta.column-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^ meta.alter storage.type +-- ^^^ meta.alter keyword.operator.logical +-- ^^^^ meta.alter constant.language.null + +USE AdventureWorks2012; +GO +SELECT i.ProductID, p.Name, i.LocationID, i.Quantity + ,RANK() OVER + (PARTITION BY i.LocationID ORDER BY i.Quantity DESC) AS Rank +FROM Production.ProductInventory AS i +INNER JOIN Production.Product AS p + ON i.ProductID = p.ProductID +WHERE i.LocationID BETWEEN 3 AND 4 +ORDER BY i.LocationID; + -- merge, CTEs From 7f9d95f8781fe1bcd2397e8171a4102330ef1ec9 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 22 Sep 2021 21:35:48 +0300 Subject: [PATCH 011/250] [SQL] more reserved words --- SQL/MySQL.sublime-syntax | 10 +- SQL/SQL (basic).sublime-syntax | 61 ++++++----- SQL/TSQL.sublime-syntax | 62 ++++++++++- SQL/syntax_test_tsql.sql | 183 ++++++++++++++++++++++++++++++++- 4 files changed, 281 insertions(+), 35 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index e824fad5b3..d1a33e6b92 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -137,7 +137,10 @@ contexts: scope: keyword.other.LUW.sql ddl-statements: - - meta_append: true + - meta_prepend: true + - match: \b(?i:create\s+or\s+replace)\b + scope: keyword.other.ddl.sql + push: [ddl-create-target, create-condition, ddl-target] - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) scope: keyword.other.object-comments.sql @@ -149,6 +152,11 @@ contexts: - match: (?i)\b(?:using|limit)\b scope: keyword.other.DML.sql + ddl-target: + - meta_prepend: true + - match: \b(?i:on)\b + scope: keyword.other.mysql + joins: - meta_append: true - match: (?i)\b(?:straight_join|natural)\b diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index aac30abee1..25cfc45e81 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -8,8 +8,8 @@ version: 2 variables: string_escape: (?:\\.) simple_identifier: (?:\w+) - dml_targets: (?i:aggregate|conversion|database|domain|function|group|((?:fulltext|spatial|unique)\s+)?index|language|operator class|operator|procedure|rule|schema|sequence|table(?:space)?|trigger|type|user|view) - reserved: (?i:\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|;|with)\b) + reserved: (?i:\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|;|union|insert|delete|truncate|create|alter|drop)\b) + additional_reserved: '' contexts: prototype: @@ -82,9 +82,7 @@ contexts: - include: identifier single-identifier-after-whitespace: - - match: \s+ - set: single-identifier - - match: '' + - match: \s* set: single-identifier single-identifier: @@ -215,6 +213,7 @@ contexts: - match: ',' scope: punctuation.separator.argument.sql - include: expressions + - include: distinct inside-group: - meta_scope: meta.group.sql @@ -228,15 +227,15 @@ contexts: - include: dml-statements ddl-statements: - - match: \b(?i:create(?:\s+or\s+replace)?)\b + - match: \b(?i:create)\b scope: keyword.other.ddl.sql - push: ddl-create-target + push: [ddl-create-target, create-condition, ddl-target] - match: (?i:\bdrop\s+table\b) scope: keyword.other.ddl.sql push: ddl-drop-table - match: \b(?i:drop)\b scope: keyword.other.ddl.sql - push: ddl-drop-target + push: [ddl-drop-target, drop-condition, ddl-target] - match: \b(?i:alter\s+table)\b scope: keyword.other.ddl.sql push: [ddl-alter-table, table-name, single-identifier-after-whitespace] @@ -250,26 +249,24 @@ contexts: ddl-create-target: - meta_scope: meta.create.sql - - match: |- - (?xi) - ({{dml_targets}})\b\s* - (on)?\b - captures: - 1: keyword.other.sql - set: create-condition - - match: (?=\S) + - match: '' pop: true ddl-drop-target: - meta_scope: meta.drop.sql + - match: '' + pop: true + + ddl-target: - match: |- (?xi) - \b{{dml_targets}}\b - captures: - 1: keyword.other.sql - set: drop-condition + aggregate|conversion|database|domain|function|group| + (?:(?:fulltext|spatial|unique)\s+)?index| + language|operator class|operator|procedure|rule| + schema|sequence|table(?:space)?|trigger|type|user|view + scope: keyword.other.sql - match: (?=\S) - set: drop-condition + pop: true ddl-drop-table: - meta_scope: meta.drop.sql @@ -313,9 +310,8 @@ contexts: push: set - match: (?i:\bvalues\b) scope: keyword.other.DML.II.sql + - include: distinct - include: joins - - match: \b(?i:distinct)\b - scope: keyword.other.DML.sql - match: \b(?i:group\s+by|order\s+by|having|where)\b scope: keyword.other.DML.sql - match: \b(?i:from)\b @@ -324,8 +320,12 @@ contexts: - match: (?i)\b(asc|desc)\b scope: keyword.other.order.sql + distinct: + - match: \b(?i:distinct)\b + scope: keyword.other.DML.sql + joins: - - match: (?i)\b(?:inner|(?:full\s+)?outer|cross|left|right)\s+join\b + - match: (?i)\b(?:inner|(?:full|left\s+)?outer|cross|left|right)\s+join\b scope: keyword.other.DML.sql push: [join-on, maybe-subquery] @@ -354,7 +354,7 @@ contexts: table-alias: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql - - match: (?={{reserved}}) + - match: (?={{reserved}}|{{additional_reserved}}) pop: true - match: (?=\S) set: [after-table-alias, table-name, single-identifier] @@ -366,14 +366,19 @@ contexts: join-on: - match: (?i)\bon\b scope: keyword.operator.join.sql - push: [join-operators, column-alias, single-identifier-after-whitespace] + push: join-operators - match: (?=\S) pop: true join-operators: - - include: operators + - match: \( + scope: punctuation.section.group.begin.sql + push: [table-alias, inside-group] + - include: expressions + - match: (?=\S)(?!{{reserved}}|{{additional_reserved}}) + push: [column-alias, single-identifier-after-whitespace] - match: (?=\S) - set: [column-alias, single-identifier-after-whitespace] + pop: true set: - match: (?=\S) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 7247f0e6ed..b4971f59bc 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -7,7 +7,8 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') #(?:\\[tnr]) - simple_identifier: (?:[#@]?\w+) + simple_identifier: (?:(?:(?:##?)?|@)?\w+) # (one or two hashes OR an ampersand OR nothing) followed by a word + additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge)\b) contexts: identifier: - meta_prepend: true @@ -203,6 +204,9 @@ contexts: expressions: - meta_prepend: true - include: types + - match: \b(?i:cast)\b + scope: support.function.tsql + push: cast - match: \b(?i:case)\b scope: keyword.control.conditional.case.sql push: inside-case-expression @@ -213,6 +217,9 @@ contexts: - match: \b(?i:cursor\s+for|open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b scope: keyword.other.sql push: [cursor-name, single-identifier-after-whitespace] + - match: \b(?i:collate)\b + scope: keyword.other.tsql + push: collation inside-case-expression: - meta_scope: meta.statement.conditional.case.sql @@ -235,6 +242,9 @@ contexts: - meta_append: true - match: \b(?i:bulk)\b scope: keyword.other.tsql + - match: \b(?i:into)\b(?!\s*@) + scope: keyword.other.DML.tsql + push: [table-name, single-identifier-after-whitespace] - match: \b(?i:into)\b scope: keyword.other.tsql - match: \b(?i:off)\b @@ -244,6 +254,17 @@ contexts: - match: \b(?i:top)\b scope: keyword.other.DML.tsql + ddl-statements: + - meta_prepend: true + - match: \b(?i:create\s+or\s+alter)\b + scope: keyword.other.ddl.sql + push: [ddl-create-target, create-condition, ddl-target] + + ddl-target: + - meta_prepend: true + - match: \b(?i:proc)\b + scope: keyword.other.sql + built-in-scalar-function-calls: - meta_append: true - match: (?i)\b(?:CONVERT|GETDATE)(?=\s*\() @@ -275,14 +296,22 @@ contexts: - match: (?=\S) pop: true + table-alias: + - meta_prepend: true + - include: with + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-with-group + after-table-alias: - meta_prepend: true - include: with + - include: with-paren with: - match: (?i)\bwith\b scope: keyword.other.DML.sql - push: with-paren + push: with-paren-or-pop with-paren: - match: \( @@ -290,8 +319,11 @@ contexts: set: inside-with-group - match: \b(?i:nowait)\b scope: keyword.other.tsql + + with-paren-or-pop: + - include: with-paren - match: (?=\S) - pop: true + set: table-alias inside-with-group: - meta_scope: meta.group.sql @@ -302,3 +334,27 @@ contexts: scope: constant.language.with.tsql - match: ',' scope: punctuation.separator.sequence.tsql + + cast: + - meta_scope: meta.function-call.sql + - match: \( + scope: meta.group.sql punctuation.section.parens.begin.sql + set: inside-cast-method-call + - match: (?=\S) + pop: true + + inside-cast-method-call: + - meta_content_scope: meta.function-call.sql meta.group.sql + - match: \) + scope: meta.function-call.sql meta.group.sql punctuation.section.parens.end.sql + pop: true + - match: \b(?i:as)\b + scope: keyword.operator.assignment.tsql + - include: expressions + + collation: + - match: \w+ + scope: support.constant.tsql + pop: true + - match: (?=\S) + pop: true diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 64f451b383..df0c782435 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -464,12 +464,189 @@ alter column bar uniqueidentifier not null USE AdventureWorks2012; GO SELECT i.ProductID, p.Name, i.LocationID, i.Quantity - ,RANK() OVER - (PARTITION BY i.LocationID ORDER BY i.Quantity DESC) AS Rank + ,RANK() OVER (PARTITION BY i.LocationID ORDER BY i.Quantity DESC) AS Rank +-- ^ punctuation.separator.sequence +-- ^^^^ meta.function-call support.function +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^ meta.group keyword.other +-- ^^^^^^^^ meta.group keyword.other.DML +-- ^^^^ meta.group keyword.other.order +-- ^^ keyword.operator.assignment.alias +-- ^^^^ meta.column-name constant.other.placeholder FROM Production.ProductInventory AS i INNER JOIN Production.Product AS p ON i.ProductID = p.ProductID WHERE i.LocationID BETWEEN 3 AND 4 +-- ^^ keyword.other.DML +-- ^^^^^^^ keyword.operator.logical +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^^^ keyword.operator.logical +-- ^ meta.number.integer.decimal constant.numeric.value ORDER BY i.LocationID; --- merge, CTEs +PRINT 'Record with ID ' + CAST(@RecordID AS VARCHAR(10)) + ' has been updated.' +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ keyword.operator.arithmetic +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^^^^ support.function +-- ^ punctuation.section.parens.begin +-- ^^^^^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^^^^^^^^^^^ storage.type +-- ^ punctuation.section.parens.end + +UPDATE foo +SET Value = Bar.Value +FROM foo +INNER JOIN bar (NOLOCK) ON bar.Title = foo.Title COLLATE DATABASE_DEFAULT AND ISNULL(bar.some_id, 0) = ISNULL(foo.some_id, 0) +-- ^^^^^^^ keyword.other.DML +-- ^^^ meta.table-name constant.other.placeholder +-- ^^^^^^ meta.group constant.language.with +-- ^^ keyword.operator.join +-- ^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^ keyword.operator.comparison +-- ^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^ support.constant +-- ^^^ keyword.operator.logical +-- ^^^^^^ meta.function-call support.function +-- ^ keyword.operator.comparison +-- ^^^^^^ meta.function-call support.function + AND foo.a = '' +-- ^^^ keyword.operator.logical +-- ^^^^^ meta.column-name constant.other.placeholder +-- ^ keyword.operator.comparison +-- ^^ string.quoted.single + +SELECT DISTINCT * +INTO ##global_temp_table +-- ^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder +FROM some_long_table_name s +LEFT OUTER JOIN another_long_table_name (NOLOCK) a ON s.blah = a.blah AND ISNULL(p.ok, '') = ISNULL(a.ok, '') COLLATE DATABASE_DEFAULT +-- ^^^^^^^^^^^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^ meta.group constant.language.with +-- ^ meta.table-name constant.other.placeholder +-- ^^ keyword.operator.join +-- ^^^^^^ meta.column-name constant.other.placeholder +-- ^ keyword.operator.comparison +-- ^^^^^^ meta.column-name constant.other.placeholder +-- ^^^ keyword.operator.logical +-- ^^^^^^ meta.function-call support.function +-- ^^^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^ support.constant + +----------- + +USE MSSQLTipsDemo +GO + +CREATE OR ALTER PROC CreateOrAlterDemo +-- ^^^^^^^^^^^^ meta.create keyword.other.ddl +-- ^^^^ meta.create keyword.other +-- ^^^^^^^^^^^^^^^^^ meta.create meta.toc-list.full-identifier entity.name.function + @Count SMALLINT +AS +-- <- keyword.operator.assignment +BEGIN +-- <- keyword.control.flow.begin + SELECT TOP (@Count) * FROM [dbo].[CountryInfoNew] +-- ^^^^^^ keyword.other.DML +-- ^^^ keyword.other.DML +-- ^ meta.group punctuation.section.group.begin +-- ^ meta.group variable.other.readwrite punctuation.definition.variable +-- ^^^^^ meta.group variable.other.readwrite +-- ^ meta.group punctuation.section.group.end +-- ^ variable.language.wildcard.asterisk +END +-- <- keyword.control.flow.end +GO +-- <- keyword.control.flow + +--------------- + +select A.A + , CASE WHEN B.B IS NOT NULL THEN B.B ELSE DATEADD(d, 1 - DATEPART(d, GETDATE()), DATEADD(m, B.MonthsInFuture, DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0))) END AS FirstDayOfFutureMonth +-- ^ punctuation.separator.sequence +-- ^^^^ keyword.control.conditional.case +into #temp +-- ^ keyword.other.DML +-- ^^^^^ meta.table-name constant.other.placeholder +from @A A +-- ^ keyword.other.DML +-- ^^ meta.table-name constant.other.placeholder +-- ^ meta.table-name constant.other.placeholder +inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN(B.C) DESC) = B.ID +--^^^^^^^^ keyword.other.DML +-- ^ meta.table-name constant.other.placeholder +-- ^^ keyword.operator.join +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^ keyword.other.DML +-- ^ keyword.operator.comparison +-- ^^^^ meta.column-name constant.other.placeholder + +MERGE sales.category t + USING sales.category_staging s +ON (s.category_id = t.category_id) +WHEN MATCHED + THEN UPDATE SET + t.category_name = s.category_name, + t.amount = s.amount +WHEN NOT MATCHED BY TARGET + THEN INSERT (category_id, category_name, amount) + VALUES (s.category_id, s.category_name, s.amount) +WHEN NOT MATCHED BY SOURCE + THEN DELETE; + + +WITH Sales_CTE (SalesPersonID, TotalSales, SalesYear) +AS +-- Define the first CTE query. +( + SELECT SalesPersonID, SUM(TotalDue) AS TotalSales, YEAR(OrderDate) AS SalesYear + FROM Sales.SalesOrderHeader + WHERE SalesPersonID IS NOT NULL + GROUP BY SalesPersonID, YEAR(OrderDate) + +) +, -- Use a comma to separate multiple CTE definitions. + +-- Define the second CTE query, which returns sales quota data by year for each sales person. +Sales_Quota_CTE (BusinessEntityID, SalesQuota, SalesQuotaYear) +AS +( + SELECT BusinessEntityID, SUM(SalesQuota)AS SalesQuota, YEAR(QuotaDate) AS SalesQuotaYear + FROM Sales.SalesPersonQuotaHistory + GROUP BY BusinessEntityID, YEAR(QuotaDate) +) + +-- Define the outer query by referencing columns from both CTEs. +SELECT SalesPersonID + , SalesYear + , FORMAT(TotalSales,'C','en-us') AS TotalSales + , SalesQuotaYear + , FORMAT (SalesQuota,'C','en-us') AS SalesQuota + , FORMAT (TotalSales -SalesQuota, 'C','en-us') AS Amt_Above_or_Below_Quota +FROM Sales_CTE +JOIN Sales_Quota_CTE ON Sales_Quota_CTE.BusinessEntityID = Sales_CTE.SalesPersonID + AND Sales_CTE.SalesYear = Sales_Quota_CTE.SalesQuotaYear +ORDER BY SalesPersonID, SalesYear; + +WITH DirectReports(ManagerID, EmployeeID, Title, EmployeeLevel) AS +( + SELECT ManagerID, EmployeeID, Title, 0 AS EmployeeLevel + FROM dbo.MyEmployees + WHERE ManagerID IS NULL + UNION ALL + SELECT e.ManagerID, e.EmployeeID, e.Title, EmployeeLevel + 1 + FROM dbo.MyEmployees AS e + INNER JOIN DirectReports AS d + ON e.ManagerID = d.EmployeeID +) +SELECT ManagerID, EmployeeID, Title, EmployeeLevel +FROM DirectReports +ORDER BY ManagerID +OPTION (MAXRECURSION 3) From 786e3ba0cae3216246d7940b0413c037c77a66ba Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Thu, 23 Sep 2021 23:25:32 +0300 Subject: [PATCH 012/250] [SQL] rework column name matching --- SQL/MySQL.sublime-syntax | 35 +++++++-- SQL/SQL (basic).sublime-syntax | 130 +++++++++++++++++++++------------ SQL/TSQL.sublime-syntax | 35 +++------ SQL/syntax_test_mysql.sql | 24 ++++-- SQL/syntax_test_tsql.sql | 17 ++++- 5 files changed, 156 insertions(+), 85 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index d1a33e6b92..ec91fe4e0d 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -127,9 +127,11 @@ contexts: pop: true expressions: - - meta_append: true - - match: (?i)\b(CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b + - meta_prepend: true + - match: (?i)\b(?:CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b scope: support.function.string.sql + - match: (?i)\b(?:using)\b + scope: keyword.other.mysql statements: - meta_append: true @@ -149,22 +151,43 @@ contexts: - match: (?i:\binsert(\s+(?:ignore\s+)?into)?\b) scope: keyword.other.DML.sql push: [table-name, single-identifier-after-whitespace] - - match: (?i)\b(?:using|limit)\b + - match: (?i)\b(?:limit)\b scope: keyword.other.DML.sql - ddl-target: - - meta_prepend: true + ddl-target-common: - match: \b(?i:on)\b scope: keyword.other.mysql + push: [table-name, single-identifier-after-whitespace] + - match: (?i)\b(?:using)\b + scope: keyword.other.mysql + - match: (?=\() + pop: true + + create-condition: + - meta_prepend: true + - include: ddl-target-common + + ddl-target: + - meta_prepend: true + - include: ddl-target-common + + ddl-create-target: + - meta_prepend: true + - include: ddl-target-common joins: - meta_append: true - match: (?i)\b(?:straight_join|natural)\b scope: keyword.other.DML.sql - maybe-subquery: + table-name-or-subquery: - meta_include_prototype: false - meta_prepend: true - match: (?=#) pop: true - include: comments + + ddl-alter-table: + - meta_prepend: true + - match: \b(?i:change\s+column)\b + scope: keyword.other.ddl.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 25cfc45e81..3288fbf560 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -17,12 +17,10 @@ contexts: main: - include: statements - - include: types - - include: expressions - - match: ',' - scope: punctuation.separator.sequence.sql - match: ';' scope: punctuation.terminator.statement.sql + - include: types + - include: expressions comments: - meta_include_prototype: false @@ -79,54 +77,60 @@ contexts: identifier-create: - meta_scope: meta.toc-list.full-identifier.sql entity.name.function.sql - - include: identifier + - match: '' + pop: true single-identifier-after-whitespace: - match: \s* set: single-identifier single-identifier: - - include: identifier - match: '' - pop: true + set: [maybe-identifier-accessor, identifier-part] - identifier: - - include: simple-identifier - - include: single-quoted-identifier - - include: double-quoted-identifier - - include: backtick-quoted-identifier - - match: \. - scope: punctuation.accessor.dot.sql - - match: (?=\S|\s*\() + maybe-identifier-accessor: + - match: \s*(\.) + captures: + 1: punctuation.accessor.dot.sql + set: single-identifier-after-whitespace + - match: '' pop: true - simple-identifier: - - match: '{{simple_identifier}}(?=\s*\.)' + identifier-part: + - include: simple-identifier-part + - include: single-quoted-identifier-part + - include: double-quoted-identifier-part + - include: backtick-quoted-identifier-part + + simple-identifier-part: - match: '{{simple_identifier}}' pop: true - single-quoted-identifier: + single-quoted-identifier-part: - match: (')([^']+)(') captures: 1: punctuation.definition.identifier.begin.sql 3: punctuation.definition.identifier.end.sql + pop: true - double-quoted-identifier: + double-quoted-identifier-part: - match: (")([^"]+)(") captures: 1: punctuation.definition.identifier.begin.sql 3: punctuation.definition.identifier.end.sql + pop: true - backtick-quoted-identifier: + backtick-quoted-identifier-part: - match: (`)([^`]+)(`) captures: 1: punctuation.definition.identifier.begin.sql 3: punctuation.definition.identifier.end.sql + pop: true create-condition: - include: dml-condition - match: (?=\S) - set: identifier-create + set: [identifier-create, single-identifier] drop-condition: - include: dml-condition @@ -169,6 +173,9 @@ contexts: scope: constant.language.null.sql - match: \* scope: variable.language.wildcard.asterisk.sql + - match: \b(?i:case)\b + scope: keyword.control.conditional.case.sql + push: inside-case-expression - include: strings - include: operators - include: built-in-aggregate-function-calls @@ -179,6 +186,29 @@ contexts: push: inside-group - match: \) scope: invalid.illegal.trailing-paren.sql + - match: ',' + scope: punctuation.separator.sequence.sql + - match: (?=;) + pop: true + - match: (?=\S) + push: [column-alias, single-identifier] + + inside-case-expression: + - meta_scope: meta.statement.conditional.case.sql + - match: \b(?i:end)\b + scope: keyword.control.conditional.end.sql + pop: true + - match: \b(?i)(case)\s+(when)\b + captures: + 1: keyword.control.conditional.case.sql + 2: keyword.control.conditional.when.sql + - match: \b(?i:when)\b + scope: keyword.control.conditional.when.sql + - match: \b(?i:then)\b + scope: keyword.control.conditional.then.sql + - match: \b(?i:else)\b + scope: keyword.control.conditional.else.sql + - include: expressions built-in-aggregate-function-calls: # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html @@ -188,7 +218,7 @@ contexts: built-in-scalar-function-calls: # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - - match: (?i)\b(CURRENT_(DATE|TIME(STAMP)?|USER)|(SESSION|SYSTEM)_USER)\b + - match: (?i)\b(?:CURRENT_(?:DATE|TIME(?:STAMP)?|USER)|(?:SESSION|SYSTEM)_USER)\b scope: support.function.scalar.sql user-defined-function-calls: @@ -222,6 +252,13 @@ contexts: pop: true - include: main + inside-subquery-allow-table-alias: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + set: table-alias + - include: main + statements: - include: ddl-statements - include: dml-statements @@ -239,9 +276,9 @@ contexts: - match: \b(?i:alter\s+table)\b scope: keyword.other.ddl.sql push: [ddl-alter-table, table-name, single-identifier-after-whitespace] - - match: \b(?i:alter)\b - scope: keyword.other.ddl.sql - push: ddl-alter-target + # - match: \b(?i:alter)\b + # scope: keyword.other.ddl.sql + # push: ddl-alter-target - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) scope: storage.modifier.sql - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) @@ -249,7 +286,7 @@ contexts: ddl-create-target: - meta_scope: meta.create.sql - - match: '' + - match: (?=\S) pop: true ddl-drop-target: @@ -276,13 +313,14 @@ contexts: ddl-alter-table: - meta_scope: meta.alter.sql + - match: \s+ - match: \b(?i:add(?:\s+column)?|alter\s+column)\b scope: keyword.other.ddl.sql - push: [column-alias, single-identifier-after-whitespace] - - include: expressions - include: ddl-alter-common - - match: (?=\S) - pop: true + # - include: pop-on-top-level-reserved-word + - include: expressions + # - match: (?=\S) + # pop: true ddl-alter-target: - meta_scope: meta.alter.sql @@ -296,6 +334,8 @@ contexts: captures: 1: keyword.other.add.sql 2: keyword.other.sql + - include: types + - include: pop-on-top-level-reserved-word dml-statements: - match: (?i:\bselect\b) @@ -316,7 +356,7 @@ contexts: scope: keyword.other.DML.sql - match: \b(?i:from)\b scope: keyword.other.DML.sql - push: maybe-subquery + push: table-name-or-subquery - match: (?i)\b(asc|desc)\b scope: keyword.other.order.sql @@ -327,7 +367,7 @@ contexts: joins: - match: (?i)\b(?:inner|(?:full|left\s+)?outer|cross|left|right)\s+join\b scope: keyword.other.DML.sql - push: [join-on, maybe-subquery] + push: [join-on, table-name-or-subquery] column-alias: - meta_content_scope: meta.column-name.sql constant.other.placeholder.sql @@ -344,18 +384,20 @@ contexts: - match: '' pop: true - maybe-subquery: + subquery: - match: \( scope: punctuation.section.group.begin.sql - set: [table-alias, inside-group] + set: inside-subquery-allow-table-alias + + table-name-or-subquery: + - include: subquery - match: (?=\S) set: [table-alias, table-name, single-identifier] table-alias: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql - - match: (?={{reserved}}|{{additional_reserved}}) - pop: true + - include: pop-on-top-level-reserved-word - match: (?=\S) set: [after-table-alias, table-name, single-identifier] @@ -366,20 +408,16 @@ contexts: join-on: - match: (?i)\bon\b scope: keyword.operator.join.sql - push: join-operators - - match: (?=\S) pop: true - - join-operators: - - match: \( - scope: punctuation.section.group.begin.sql - push: [table-alias, inside-group] - - include: expressions - - match: (?=\S)(?!{{reserved}}|{{additional_reserved}}) - push: [column-alias, single-identifier-after-whitespace] - match: (?=\S) pop: true set: - match: (?=\S) pop: true + + pop-on-top-level-reserved-word: + - match: (?={{reserved}}|{{additional_reserved}}) + pop: true + - match: (?=\)) + pop: true diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index b4971f59bc..9dbb888b0a 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -10,15 +10,16 @@ variables: simple_identifier: (?:(?:(?:##?)?|@)?\w+) # (one or two hashes OR an ampersand OR nothing) followed by a word additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge)\b) contexts: - identifier: + identifier-part: - meta_prepend: true - - include: square-bracketed-identifier + - include: square-bracketed-identifier-part - square-bracketed-identifier: + square-bracketed-identifier-part: - match: (\[)([^]]+)(\]) captures: 1: punctuation.definition.identifier.begin.sql 3: punctuation.definition.identifier.end.sql + pop: true strings: - meta_append: true @@ -207,9 +208,6 @@ contexts: - match: \b(?i:cast)\b scope: support.function.tsql push: cast - - match: \b(?i:case)\b - scope: keyword.control.conditional.case.sql - push: inside-case-expression - include: variables - include: with - match: \b(?i:output|over|partition\s+by)\b @@ -221,23 +219,6 @@ contexts: scope: keyword.other.tsql push: collation - inside-case-expression: - - meta_scope: meta.statement.conditional.case.sql - - match: \b(?i:end)\b - scope: keyword.control.conditional.end.sql - pop: true - - match: \b(?i)(case)\s+(when)\b - captures: - 1: keyword.control.conditional.case.sql - 2: keyword.control.conditional.when.sql - - match: \b(?i:when)\b - scope: keyword.control.conditional.when.sql - - match: \b(?i:then)\b - scope: keyword.control.conditional.then.sql - - match: \b(?i:else)\b - scope: keyword.control.conditional.else.sql - - include: main - dml-statements: - meta_append: true - match: \b(?i:bulk)\b @@ -258,13 +239,19 @@ contexts: - meta_prepend: true - match: \b(?i:create\s+or\s+alter)\b scope: keyword.other.ddl.sql - push: [ddl-create-target, create-condition, ddl-target] + push: [ddl-create-target-expect-as, ddl-create-target, create-condition, ddl-target] ddl-target: - meta_prepend: true - match: \b(?i:proc)\b scope: keyword.other.sql + ddl-create-target-expect-as: + - match: (?i:\bas\b) + scope: keyword.context.block.sql + pop: true + - include: expressions + built-in-scalar-function-calls: - meta_append: true - match: (?i)\b(?:CONVERT|GETDATE)(?=\s*\() diff --git a/SQL/syntax_test_mysql.sql b/SQL/syntax_test_mysql.sql index 1d5d894faf..b71957d513 100644 --- a/SQL/syntax_test_mysql.sql +++ b/SQL/syntax_test_mysql.sql @@ -111,32 +111,42 @@ create table fancy_table ( CREATE INDEX ON fancy_table(mytime); -- ^^^^^ keyword.other.sql --- ^^ - entity.name.function.sql --- ^^^^^^^^^^^ entity.name.function.sql +-- ^^ keyword.other +-- ^^^^^^^^^^^ meta.table-name constant.other.placeholder CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); -- ^^^^^ keyword.other.sql --- ^^ - entity.name.function.sql +-- ^^ keyword.other +-- ^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^ keyword.other CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; -- ^^^^^^^^^^^^ keyword.other.sql --- ^^ - entity.name.function.sql --- ^^^^^^^^^^^ entity.name.function.sql +-- ^^ meta.create keyword.other +-- ^^^^^^^^^^^ meta.table-name constant.other.placeholder -- ^^^^^ keyword.other.DML.sql -- ^^ keyword.operator.logical.sql -- ^^^^ constant.language.null.sql create fulltext index if not exists `myindex` ON mytable; -- ^^^^^^^^^^^^^^ keyword.other.sql +-- ^^ keyword.control.flow +-- ^^^ keyword.operator.logical +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^ keyword.other +-- ^^^^^^^ meta.table-name constant.other.placeholder +-- ^ punctuation.terminator.statement ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; -- ^^^^^^^^ meta.alter keyword.other.ddl -- ^^^ keyword.other.ddl.sql -- ^^^^^^ keyword.other.ddl.sql --- ^^^^^^^^ meta.alter meta.column-name constant.other.placeholder +-- ^^^^^^^^ meta.column-name constant.other.placeholder -- ^^^^^^^^ storage.type.sql ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); +-- ^^^^^^^^^^^^^ meta.alter keyword.other.ddl -- ^^^^ storage.type.sql DROP TABLE IF EXISTS testing123; @@ -156,7 +166,7 @@ SELECT ( SELECT CASE field USING a --- <- keyword.other.DML +-- <- keyword.other WHEN 1 THEN -- comment's say that -- ^ comment.line.double-dash diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index df0c782435..366955aa45 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -547,9 +547,14 @@ CREATE OR ALTER PROC CreateOrAlterDemo -- ^^^^^^^^^^^^ meta.create keyword.other.ddl -- ^^^^ meta.create keyword.other -- ^^^^^^^^^^^^^^^^^ meta.create meta.toc-list.full-identifier entity.name.function - @Count SMALLINT + @Count SMALLINT +,@Other INT OUTPUT +-- <- punctuation.separator.sequence +--^^^^^ variable.other.readwrite +-- ^^^ storage.type +-- ^^^^^^ keyword.other AS --- <- keyword.operator.assignment +-- <- keyword.context.block BEGIN -- <- keyword.control.flow.begin SELECT TOP (@Count) * FROM [dbo].[CountryInfoNew] @@ -560,6 +565,14 @@ BEGIN -- ^^^^^ meta.group variable.other.readwrite -- ^ meta.group punctuation.section.group.end -- ^ variable.language.wildcard.asterisk +-- ^^^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^ punctuation.definition.identifier.begin +-- ^ punctuation.definition.identifier.end +-- ^ punctuation.accessor.dot +-- ^ punctuation.definition.identifier.begin +-- ^ punctuation.definition.identifier.end + END -- <- keyword.control.flow.end GO From 1aa3e9f95aa94412da2e621add7f408ce198ff81 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 24 Sep 2021 23:09:49 +0300 Subject: [PATCH 013/250] [SQL] Support types enclosed in square brackets in TSQL --- SQL/MySQL.sublime-syntax | 53 +++++++-------------- SQL/SQL (basic).sublime-syntax | 56 ++++++++++++++++------ SQL/TSQL.sublime-syntax | 60 +++++++++++++++++++++--- SQL/syntax_test_mysql.sql | 18 ++++++- SQL/syntax_test_tsql.sql | 85 ++++++++++++++++++++++++++-------- 5 files changed, 194 insertions(+), 78 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index ec91fe4e0d..26dae9b7cd 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -5,6 +5,21 @@ scope: source.sql.mysql version: 2 extends: Packages/SQL/SQL (basic).sublime-syntax +variables: + simple_types: |- + (?xi: + \b + (?:bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|int|integer| + line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext) + \b + ) + types_with_optional_number: |- + (?xi: + \b + (?:bit\s+varying|character\s+(?:varying)?|tinyint|var\schar|float|interval|numeric|decimal|times?|timestamp(?:s|tz)?) + \b + ) + contexts: main: - meta_append: true @@ -84,41 +99,9 @@ contexts: scope: keyword.operator.concatenation.sql types: - - match: |- - (?xi) - # normal stuff, capture 1 - \b(bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|int|integer|line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext)\b - - # numeric suffix, capture 2 + 3i - |\b(bit\svarying|character\s+(?:varying)?|tinyint|var\schar|float|interval)\((\d+)\) - - # optional numeric suffix, capture 4 + 5i - |\b(char|number|nvarchar|varbinary|varchar\d?)\b(?:\((\d+)\))? - - # special case, capture 6 + 7i + 8i - |\b(numeric|decimal)\b(?:\((\d+),(\d+)\))? - - # special case, captures 9, 10i, 11 - |\b(times?)\b(?:\((\d+)\))?(\swith(?:out)?\s+time\s+zone\b)? - - # special case, captures 12, 13, 14i, 15 - |\b(timestamp)(?:(s|tz))?\b(?:\((\d+)\))?(\s(with|without)\s+time\s+zone\b)? - captures: - 1: storage.type.sql - 2: storage.type.sql - 3: constant.numeric.sql - 4: storage.type.sql - 5: constant.numeric.sql - 6: storage.type.sql - 7: constant.numeric.sql - 8: constant.numeric.sql - 9: storage.type.sql - 10: constant.numeric.sql - 11: storage.type.sql - 12: storage.type.sql - 13: storage.type.sql - 14: constant.numeric.sql - 15: storage.type.sql + - meta_append: true + - match: (?i:\bwith(?:out)?\s+time\s+zone\b) + scope: storage.type.sql inside-number-sign-comment: - meta_include_prototype: false diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 3288fbf560..c5fc17e3a4 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -8,8 +8,10 @@ version: 2 variables: string_escape: (?:\\.) simple_identifier: (?:\w+) - reserved: (?i:\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|;|union|insert|delete|truncate|create|alter|drop)\b) - additional_reserved: '' + reserved: (?i:;|\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|union|insert|delete|truncate|create|alter|drop)\b) + additional_reserved: (?!) + simple_types: (?i:\b(?:bit|bool|boolean|datetime|int)\b) + types_with_optional_number: (?i:\b(?:char|number|nvarchar|varbinary|varchar)\b) contexts: prototype: @@ -20,7 +22,7 @@ contexts: - match: ';' scope: punctuation.terminator.statement.sql - include: types - - include: expressions + - include: expressions-or-column-name comments: - meta_include_prototype: false @@ -85,10 +87,15 @@ contexts: set: single-identifier single-identifier: + - include: pop-on-top-level-reserved-word - match: '' set: [maybe-identifier-accessor, identifier-part] maybe-identifier-accessor: + - match: \s*(\.)(?=\s*\*) + captures: + 1: punctuation.accessor.dot.sql + pop: true - match: \s*(\.) captures: 1: punctuation.accessor.dot.sql @@ -154,12 +161,22 @@ contexts: - include: logical-operators types: - - match: \b(?i:bit|bool|boolean|datetime|int)\b + - match: '{{simple_types}}' scope: storage.type.sql - - match: \b(?i:char|number|nvarchar|varbinary|varchar)\b(?:\s*\((\d+)\))? + - match: |- + (?xi) + {{types_with_optional_number}} + (?:\s*\((\d+)(?:\s*(,)\s*(\d+))?\))? scope: storage.type.sql captures: 1: constant.numeric.sql + 2: punctuation.separator.sequence.sql + 3: constant.numeric.sql + + expressions-or-column-name: + - include: expressions + - match: (?=\S) + push: [column-name, single-identifier] expressions: - match: (?i)\bas\b @@ -190,8 +207,6 @@ contexts: scope: punctuation.separator.sequence.sql - match: (?=;) pop: true - - match: (?=\S) - push: [column-alias, single-identifier] inside-case-expression: - meta_scope: meta.statement.conditional.case.sql @@ -208,7 +223,7 @@ contexts: scope: keyword.control.conditional.then.sql - match: \b(?i:else)\b scope: keyword.control.conditional.else.sql - - include: expressions + - include: expressions-or-column-name built-in-aggregate-function-calls: # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html @@ -242,8 +257,8 @@ contexts: pop: true - match: ',' scope: punctuation.separator.argument.sql - - include: expressions - include: distinct + - include: expressions-or-column-name inside-group: - meta_scope: meta.group.sql @@ -317,10 +332,7 @@ contexts: - match: \b(?i:add(?:\s+column)?|alter\s+column)\b scope: keyword.other.ddl.sql - include: ddl-alter-common - # - include: pop-on-top-level-reserved-word - - include: expressions - # - match: (?=\S) - # pop: true + - include: expressions-or-column-name ddl-alter-target: - meta_scope: meta.alter.sql @@ -365,15 +377,20 @@ contexts: scope: keyword.other.DML.sql joins: - - match: (?i)\b(?:inner|(?:full|left\s+)?outer|cross|left|right)\s+join\b + - match: (?i)\b(?:(?:inner|(?:full|left\s+)?outer|cross|left|right)\s+)?join\b scope: keyword.other.DML.sql push: [join-on, table-name-or-subquery] - column-alias: + column-name: - meta_content_scope: meta.column-name.sql constant.other.placeholder.sql - match: '' pop: true + column-alias: + - meta_content_scope: meta.column-alias.sql constant.other.placeholder.sql + - match: '' + pop: true + database-name: - meta_content_scope: meta.database-name.sql constant.other.placeholder.sql - match: '' @@ -384,6 +401,11 @@ contexts: - match: '' pop: true + procedure-name: + - meta_content_scope: meta.procedure-name.sql constant.other.placeholder.sql + - match: '' + pop: true + subquery: - match: \( scope: punctuation.section.group.begin.sql @@ -421,3 +443,7 @@ contexts: pop: true - match: (?=\)) pop: true + + assignment-operator: + - match: '=' + scope: keyword.operator.assignment.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 9dbb888b0a..47c6880fc5 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -8,7 +8,12 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') #(?:\\[tnr]) simple_identifier: (?:(?:(?:##?)?|@)?\w+) # (one or two hashes OR an ampersand OR nothing) followed by a word - additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge)\b) + additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec)\b) + enclosed_type_begin: (?:\[) + enclosed_type_end: (?:\]) + simple_types: (?i:\b(?:bit|bool|boolean|datetime|int|smallint|sysname|uniqueidentifier|text)\b) + types_with_optional_number: (?i:\b(?:n?char|numeric|n?varchar|varbinary|decimal|money)\b) + contexts: identifier-part: - meta_prepend: true @@ -163,8 +168,23 @@ contexts: types: - meta_append: true - - match: (?i:\b(?:smallint|sysname|uniqueidentifier|decimal)\b) + - match: |- + (?xi) + {{enclosed_type_begin}}? + {{simple_types}} + {{enclosed_type_end}}? scope: storage.type.sql + - match: |- + (?xi) + {{enclosed_type_begin}}? + {{types_with_optional_number}} + {{enclosed_type_end}}? + (?:\s*\((\d+)(?:\s*(,)\s*(\d+))?\))? + scope: storage.type.sql + captures: + 1: constant.numeric.sql + 2: punctuation.separator.sequence.sql + 3: constant.numeric.sql statements: - meta_append: true @@ -179,6 +199,7 @@ contexts: push: [label-name, single-identifier-after-whitespace] - match: \b(?i:exec)\b scope: keyword.control.flow.tsql + push: [expect-procedure-name, exec] - match: \b(?i:begin)\b scope: keyword.control.flow.begin.tsql - match: \b(?i:end)\b @@ -188,6 +209,12 @@ contexts: - match: \b(?i:use)\b scope: keyword.context.tsql push: [database-name, single-identifier-after-whitespace] + - match: \b(?i:backup(?:\s+database)?)\b # https://docs.microsoft.com/en-us/sql/t-sql/statements/backup-transact-sql?view=sql-server-ver15 + scope: keyword.other.tsql + - match: \b(?i:to)\b + scope: keyword.other.tsql + - match: \b(?i:disk|tape|url)\b + scope: keyword.other.tsql - match: \b(\w+)(:) captures: 1: entity.name.label.tsql @@ -210,9 +237,13 @@ contexts: push: cast - include: variables - include: with - - match: \b(?i:output|over|partition\s+by)\b + - match: \b(?i:output)\b + scope: storage.modifier.output.tsql + - match: \b(?i:over|partition\s+by)\b scope: keyword.other.sql - - match: \b(?i:cursor\s+for|open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b + - match: \b(?i:cursor\s+for)\b + scope: keyword.other.sql + - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b scope: keyword.other.sql push: [cursor-name, single-identifier-after-whitespace] - match: \b(?i:collate)\b @@ -250,7 +281,7 @@ contexts: - match: (?i:\bas\b) scope: keyword.context.block.sql pop: true - - include: expressions + - include: expressions-or-column-name built-in-scalar-function-calls: - meta_append: true @@ -337,7 +368,7 @@ contexts: pop: true - match: \b(?i:as)\b scope: keyword.operator.assignment.tsql - - include: expressions + - include: expressions-or-column-name collation: - match: \w+ @@ -345,3 +376,20 @@ contexts: pop: true - match: (?=\S) pop: true + + joins: + - meta_append: true + - match: (?i)\b(?:cross\s+)?apply\b + scope: keyword.other.DML.sql + push: table-name-or-subquery + + exec: + - include: assignment-operator + - include: pop-on-top-level-reserved-word + - include: expressions + - match: (?=\S) + pop: true + + expect-procedure-name: + - match: '' + set: [procedure-name, single-identifier-after-whitespace] diff --git a/SQL/syntax_test_mysql.sql b/SQL/syntax_test_mysql.sql index b71957d513..680ec5cf37 100644 --- a/SQL/syntax_test_mysql.sql +++ b/SQL/syntax_test_mysql.sql @@ -91,8 +91,10 @@ create table fancy_table ( mycount double precision DEFAULT 1, -- ^^^^^^^^^^^^^^^^^ storage.type.sql fancy_column character varying(42) DEFAULT 'nice'::character varying, --- ^^^^^^^^^^^^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ storage.type.sql mytime timestamp(3) without time zone DEFAULT now(), +-- ^^^^^^^^^^^^ storage.type.sql +-- ^ constant.numeric -- ^^^^^^^^^^^^^^^^^ storage.type.sql -- ^^^^^^^ storage.modifier -- ^^^ meta.function-call support.function @@ -101,12 +103,24 @@ create table fancy_table ( -- ^ punctuation.separator.sequence mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, -- ^^^^^^^^^^^^^^^^^^^ storage.type.sql + some_number numeric(5, 2) DEFAULT 0, +-- ^^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^^^^ storage.type +-- ^ constant.numeric +-- ^ punctuation.separator.sequence +-- ^ constant.numeric +-- ^^^^^^^ storage.modifier +-- ^ meta.number.integer.decimal constant.numeric.value primary key (id), -- ^^^^^^^^^^^ storage.modifier.sql UNIQUE (foreign_id), CONSTRAINT fancy_table_valid1 CHECK (id <> foreign_id) -- ^^^^^^^^^^ storage.modifier.sql -- ^^^^^ storage.modifier.sql +-- ^^^^^^^^^^^^^^^^^^ meta.group meta.group +-- ^^ meta.column-name constant.other.placeholder +-- ^^ keyword.operator.comparison +-- ^^^^^^^^^^ meta.column-name constant.other.placeholder ); CREATE INDEX ON fancy_table(mytime); @@ -201,7 +215,7 @@ SELECT *, -- ^ variable.language.wildcard.asterisk.sql f.id AS database_id -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^^ meta.column-alias constant.other.placeholder FROM foo WHERE f.a IS NULL -- ^^ keyword.other.DML.sql diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 366955aa45..4c6ca06035 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -223,13 +223,18 @@ DECLARE db_cursor CURSOR FOR -- ^^^^ keyword.declaration.variable -- ^^^^^^^^^ meta.cursor-name constant.other.placeholder -- ^^^^^^^^^^ keyword.other - -SELECT name -FROM MASTER.dbo.sysdatabases --- ^ keyword.other.DML --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder -WHERE name NOT IN ('master','model','msdb','tempdb') --- ^^ keyword.other.DML + SELECT name +-- ^^^^^^ keyword.other.DML +-- ^^^^ meta.column-name constant.other.placeholder + FROM MASTER.dbo.sysdatabases + -- ^ keyword.other.DML + -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder + WHERE name NOT IN ('master','model','msdb','tempdb') + -- ^^ keyword.other.DML + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group + -- ^^^^^^^^ string.quoted.single + -- ^ punctuation.separator.sequence + -- ^^^^^^^ string.quoted.single OPEN db_cursor -- ^ keyword.other @@ -251,6 +256,11 @@ BEGIN -- ^^ keyword.control.flow.begin SET @fileName = @path + @name + '_' + @fileDate + '.BAK' BACKUP DATABASE @name TO DISK = @fileName +-- ^^^^^^^^^^^^^^^ keyword.other +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.other +-- ^^^^ keyword.other +-- ^ keyword.operator FETCH NEXT FROM db_cursor INTO @name END @@ -272,7 +282,11 @@ SET NOCOUNT ON -- ^^ constant.language.boolean EXEC master.dbo.xp_fileexist @FromFile, @FileExists OUTPUT -- ^ keyword.control.flow --- ^^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name constant.other.placeholder +-- ^^^^^^^^^ variable.other.readwrite +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^ variable.other.readwrite +-- ^^^^^^ storage.modifier.output SET NOCOUNT OFF --^ keyword.other.DML -- ^^^^^^^ constant.language.switch @@ -314,6 +328,10 @@ IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback -- ^^^^ keyword.control.flow -- ^^^^^^^^^^^^^^^^ meta.label-name constant.other.placeholder EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' +-- ^ keyword.control.flow +-- ^^^^^^^^^^^ variable.other.readwrite +-- ^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name constant.other.placeholder IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback COMMIT TRANSACTION -- ^^^^^^^^^^^^^^^ keyword.context @@ -345,17 +363,20 @@ VALUES (2, 'two'), -SELECT foo, COUNT(*) AS tally +SELECT foo AS foobar, COUNT(*) AS tally -- ^^^ keyword.other.DML --- ^ punctuation.separator.sequence --- ^^^^^^^^ meta.function-call --- ^^^^^ support.function.aggregate --- ^^^ meta.group --- ^ punctuation.section.parens.begin --- ^ variable.language.wildcard.asterisk --- ^ punctuation.section.parens.end --- ^^ keyword.operator.assignment.alias --- ^^^^^ meta.column-name constant.other.placeholder +-- ^^^ meta.column-name constant.other.placeholder +-- ^^ keyword.operator.assignment.alias +-- ^^^^^^ meta.column-alias constant.other.placeholder +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ meta.function-call +-- ^^^^^ support.function.aggregate +-- ^^^ meta.group +-- ^ punctuation.section.parens.begin +-- ^ variable.language.wildcard.asterisk +-- ^ punctuation.section.parens.end +-- ^^ keyword.operator.assignment.alias +-- ^^^^^ meta.column-alias constant.other.placeholder FROM bar -- ^ keyword.other.DML -- ^^^ meta.table-name constant.other.placeholder @@ -472,7 +493,7 @@ SELECT i.ProductID, p.Name, i.LocationID, i.Quantity -- ^^^^^^^^ meta.group keyword.other.DML -- ^^^^ meta.group keyword.other.order -- ^^ keyword.operator.assignment.alias --- ^^^^ meta.column-name constant.other.placeholder +-- ^^^^ meta.column-alias constant.other.placeholder FROM Production.ProductInventory AS i INNER JOIN Production.Product AS p ON i.ProductID = p.ProductID @@ -552,7 +573,7 @@ CREATE OR ALTER PROC CreateOrAlterDemo -- <- punctuation.separator.sequence --^^^^^ variable.other.readwrite -- ^^^ storage.type --- ^^^^^^ keyword.other +-- ^^^^^^ storage.modifier.output AS -- <- keyword.context.block BEGIN @@ -584,6 +605,11 @@ select A.A , CASE WHEN B.B IS NOT NULL THEN B.B ELSE DATEADD(d, 1 - DATEPART(d, GETDATE()), DATEADD(m, B.MonthsInFuture, DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0))) END AS FirstDayOfFutureMonth -- ^ punctuation.separator.sequence -- ^^^^ keyword.control.conditional.case + , B.* +-- ^ punctuation.separator.sequence +-- ^^ meta.column-name constant.other.placeholder +-- ^ punctuation.accessor.dot +-- ^ variable.language.wildcard.asterisk into #temp -- ^ keyword.other.DML -- ^^^^^ meta.table-name constant.other.placeholder @@ -663,3 +689,22 @@ SELECT ManagerID, EmployeeID, Title, EmployeeLevel FROM DirectReports ORDER BY ManagerID OPTION (MAXRECURSION 3) + +CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)); +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other +-- ^^^ meta.toc-list.full-identifier entity.name.function +-- ^ punctuation.section.group.begin +-- ^^ meta.column-name constant.other.placeholder +-- ^^^^^ storage.type +-- ^^^^^^^^^^^ storage.modifier +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^^^^ storage.type +-- ^ constant.numeric +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement + +CREATE TABLE foo ([int] [int] PRIMARY KEY, [test'hello¬world'@"me"] [varchar] (5)); +-- ^^^^^ storage.type +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.column-name constant.other.placeholder From be2d354aec9f7b1f5abee8dd0abea2e9d21a2e32 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 24 Sep 2021 23:31:13 +0300 Subject: [PATCH 014/250] [SQL] support Common Table Expressions in TSQL --- SQL/TSQL.sublime-syntax | 32 +++++++++++++++++++ SQL/syntax_test_tsql.sql | 68 +++++++++++++++++++++++++++++++--------- 2 files changed, 85 insertions(+), 15 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 47c6880fc5..731d5b1fa4 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -265,6 +265,11 @@ contexts: scope: keyword.other.tsql - match: \b(?i:top)\b scope: keyword.other.DML.tsql + - match: \b(?i:(option))\b\s*(\() + captures: + 1: keyword.other.DML.tsql + 2: punctuation.section.group.begin.sql + push: inside-with-group ddl-statements: - meta_prepend: true @@ -327,6 +332,12 @@ contexts: - include: with-paren with: + - match: (?i)\bwith\b(?=\s*(?:\[\w+\]|\w+)\s*\() + scope: keyword.other.DML.sql + push: [cte-column-list-begin, cte-table-name, single-identifier] + - match: (?i)\bwith\b(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) + scope: keyword.other.DML.sql + push: [cte-as, cte-table-name, single-identifier] - match: (?i)\bwith\b scope: keyword.other.DML.sql push: with-paren-or-pop @@ -393,3 +404,24 @@ contexts: expect-procedure-name: - match: '' set: [procedure-name, single-identifier-after-whitespace] + + cte-column-list-begin: + - match: \( + scope: punctuation.section.group.begin.tsql + set: [cte-as, inside-group] + - match: (?=\S) + pop: true + + cte-as: + - match: (?i:\bas\b) + scope: keyword.operator.assignment.cte.tsql + - include: pop-on-top-level-reserved-word + - match: ',' + scope: punctuation.separator.sequence.cte.tsql + set: [cte-column-list-begin, cte-table-name, single-identifier-after-whitespace] + - include: expressions + + cte-table-name: + - meta_content_scope: meta.cte-table-name.sql constant.other.placeholder.sql + - match: '' + pop: true diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 4c6ca06035..adf9525545 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -627,43 +627,48 @@ inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN( -- ^ keyword.operator.comparison -- ^^^^ meta.column-name constant.other.placeholder -MERGE sales.category t - USING sales.category_staging s -ON (s.category_id = t.category_id) -WHEN MATCHED - THEN UPDATE SET - t.category_name = s.category_name, - t.amount = s.amount -WHEN NOT MATCHED BY TARGET - THEN INSERT (category_id, category_name, amount) - VALUES (s.category_id, s.category_name, s.amount) -WHEN NOT MATCHED BY SOURCE - THEN DELETE; - - WITH Sales_CTE (SalesPersonID, TotalSales, SalesYear) +-- ^ keyword.other.DML +-- ^^^^^^^^^ meta.cte-table-name constant.other.placeholder +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ meta.column-name constant.other.placeholder AS +-- <- keyword.operator.assignment.cte -- Define the first CTE query. +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-dash ( +-- <- meta.group punctuation.section.group.begin SELECT SalesPersonID, SUM(TotalDue) AS TotalSales, YEAR(OrderDate) AS SalesYear +-- ^^^^^^ meta.group keyword.other.DML FROM Sales.SalesOrderHeader WHERE SalesPersonID IS NOT NULL GROUP BY SalesPersonID, YEAR(OrderDate) ) , -- Use a comma to separate multiple CTE definitions. - +-- <- punctuation.separator.sequence.cte -- Define the second CTE query, which returns sales quota data by year for each sales person. Sales_Quota_CTE (BusinessEntityID, SalesQuota, SalesQuotaYear) +-- ^^^^^^^^^^^^ meta.cte-table-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group - meta.group meta.group +-- ^^^^^^^^^^^^^^^^ meta.column-name constant.other.placeholder AS +-- <- keyword.operator.assignment.cte ( +-- <- meta.group punctuation.section.group.begin SELECT BusinessEntityID, SUM(SalesQuota)AS SalesQuota, YEAR(QuotaDate) AS SalesQuotaYear +-- ^^^^^^ meta.group keyword.other.DML FROM Sales.SalesPersonQuotaHistory GROUP BY BusinessEntityID, YEAR(QuotaDate) ) -- Define the outer query by referencing columns from both CTEs. SELECT SalesPersonID +-- ^^^ keyword.other.DML , SalesYear , FORMAT(TotalSales,'C','en-us') AS TotalSales , SalesQuotaYear @@ -689,6 +694,26 @@ SELECT ManagerID, EmployeeID, Title, EmployeeLevel FROM DirectReports ORDER BY ManagerID OPTION (MAXRECURSION 3) +-- ^^^ keyword.other.DML +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.group constant.language.with +-- ^ meta.group constant.language.with +-- ^ meta.group punctuation.section.group.end + +WITH cte_table AS ( SELECT blah ) +-- ^ keyword.other.DML +-- ^^^^^^^^^ meta.cte-table-name constant.other.placeholder +-- ^^ keyword.operator.assignment.cte +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^ meta.group keyword.other.DML +-- ^^^^ meta.group meta.column-name constant.other.placeholder +-- ^ meta.group punctuation.section.group.end +SELECT cte_table.* FROM cte_table +-- ^^^ keyword.other.DML +-- ^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^ variable.language.wildcard.asterisk +-- ^^^^ keyword.other.DML +-- ^^^^^^^^^ meta.table-name constant.other.placeholder CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)); -- ^^^ keyword.other.ddl @@ -708,3 +733,16 @@ CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)); CREATE TABLE foo ([int] [int] PRIMARY KEY, [test'hello¬world'@"me"] [varchar] (5)); -- ^^^^^ storage.type -- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.column-name constant.other.placeholder + +MERGE sales.category t + USING sales.category_staging s +ON (s.category_id = t.category_id) +WHEN MATCHED + THEN UPDATE SET + t.category_name = s.category_name, + t.amount = s.amount +WHEN NOT MATCHED BY TARGET + THEN INSERT (category_id, category_name, amount) + VALUES (s.category_id, s.category_name, s.amount) +WHEN NOT MATCHED BY SOURCE + THEN DELETE; From be7d7fcdf5a4080bb3ffd525cdffecf0eadd5c2d Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 24 Sep 2021 23:41:02 +0300 Subject: [PATCH 015/250] [SQL] remove constant.other.placeholder scope from identifiers --- SQL/SQL (basic).sublime-syntax | 10 +-- SQL/TSQL.sublime-syntax | 6 +- SQL/syntax_test_mysql.sql | 25 ++++--- SQL/syntax_test_tsql.sql | 126 ++++++++++++++++----------------- 4 files changed, 86 insertions(+), 81 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index c5fc17e3a4..5c72afe993 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -382,27 +382,27 @@ contexts: push: [join-on, table-name-or-subquery] column-name: - - meta_content_scope: meta.column-name.sql constant.other.placeholder.sql + - meta_content_scope: meta.column-name.sql - match: '' pop: true column-alias: - - meta_content_scope: meta.column-alias.sql constant.other.placeholder.sql + - meta_content_scope: meta.column-alias.sql - match: '' pop: true database-name: - - meta_content_scope: meta.database-name.sql constant.other.placeholder.sql + - meta_content_scope: meta.database-name.sql - match: '' pop: true table-name: - - meta_content_scope: meta.table-name.sql constant.other.placeholder.sql + - meta_content_scope: meta.table-name.sql - match: '' pop: true procedure-name: - - meta_content_scope: meta.procedure-name.sql constant.other.placeholder.sql + - meta_content_scope: meta.procedure-name.sql - match: '' pop: true diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 731d5b1fa4..700cc5ab1d 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -295,12 +295,12 @@ contexts: push: begin-method-call-paren label-name: - - meta_content_scope: meta.label-name.sql constant.other.placeholder.sql + - meta_content_scope: meta.label-name.sql - match: '' pop: true cursor-name: - - meta_content_scope: meta.cursor-name.sql constant.other.placeholder.sql + - meta_content_scope: meta.cursor-name.sql - match: '' pop: true @@ -422,6 +422,6 @@ contexts: - include: expressions cte-table-name: - - meta_content_scope: meta.cte-table-name.sql constant.other.placeholder.sql + - meta_content_scope: meta.cte-table-name.sql - match: '' pop: true diff --git a/SQL/syntax_test_mysql.sql b/SQL/syntax_test_mysql.sql index 680ec5cf37..f04836f45c 100644 --- a/SQL/syntax_test_mysql.sql +++ b/SQL/syntax_test_mysql.sql @@ -104,7 +104,7 @@ create table fancy_table ( mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, -- ^^^^^^^^^^^^^^^^^^^ storage.type.sql some_number numeric(5, 2) DEFAULT 0, --- ^^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^^ meta.column-name -- ^^^^^^^^^^^^^ storage.type -- ^ constant.numeric -- ^ punctuation.separator.sequence @@ -118,26 +118,31 @@ create table fancy_table ( -- ^^^^^^^^^^ storage.modifier.sql -- ^^^^^ storage.modifier.sql -- ^^^^^^^^^^^^^^^^^^ meta.group meta.group --- ^^ meta.column-name constant.other.placeholder +-- ^^ meta.column-name -- ^^ keyword.operator.comparison --- ^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^ meta.column-name ); CREATE INDEX ON fancy_table(mytime); -- ^^^^^ keyword.other.sql -- ^^ keyword.other --- ^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^^ meta.table-name CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); -- ^^^^^ keyword.other.sql -- ^^ keyword.other --- ^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^^ meta.table-name -- ^^^^^ keyword.other CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; -- ^^^^^^^^^^^^ keyword.other.sql -- ^^ meta.create keyword.other --- ^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^^ meta.table-name +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.separator.sequence +-- ^^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.section.group.end -- ^^^^^ keyword.other.DML.sql -- ^^ keyword.operator.logical.sql -- ^^^^ constant.language.null.sql @@ -149,14 +154,14 @@ create fulltext index if not exists `myindex` ON mytable; -- ^^^^^^ keyword.operator.logical -- ^^^^^^^^^ meta.toc-list.full-identifier entity.name.function -- ^^ keyword.other --- ^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; -- ^^^^^^^^ meta.alter keyword.other.ddl -- ^^^ keyword.other.ddl.sql -- ^^^^^^ keyword.other.ddl.sql --- ^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^ meta.column-name -- ^^^^^^^^ storage.type.sql ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); @@ -168,7 +173,7 @@ DROP TABLE IF EXISTS testing123; -- ^^^^^^^ meta.drop keyword.other.ddl -- ^^ meta.drop keyword.control.flow -- ^^^^^^ keyword.operator.logical.sql --- ^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement select * @@ -215,7 +220,7 @@ SELECT *, -- ^ variable.language.wildcard.asterisk.sql f.id AS database_id -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^^^^^^^ meta.column-alias constant.other.placeholder +-- ^^^^^^^^^^^ meta.column-alias FROM foo WHERE f.a IS NULL -- ^^ keyword.other.DML.sql diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index adf9525545..4934323790 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -2,7 +2,7 @@ USE master -- <- keyword.context - constant --- ^^^^^^ meta.database-name constant.other.placeholder +-- ^^^^^^ meta.database-name SELECT columns FROM table WHERE column LIKE '%[[]SQL Server Driver]%' @@ -221,14 +221,14 @@ SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) DECLARE db_cursor CURSOR FOR -- ^^^^ keyword.declaration.variable --- ^^^^^^^^^ meta.cursor-name constant.other.placeholder +-- ^^^^^^^^^ meta.cursor-name -- ^^^^^^^^^^ keyword.other SELECT name -- ^^^^^^ keyword.other.DML --- ^^^^ meta.column-name constant.other.placeholder +-- ^^^^ meta.column-name FROM MASTER.dbo.sysdatabases -- ^ keyword.other.DML - -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder + -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name WHERE name NOT IN ('master','model','msdb','tempdb') -- ^^ keyword.other.DML -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group @@ -238,11 +238,11 @@ DECLARE db_cursor CURSOR FOR OPEN db_cursor -- ^ keyword.other --- ^^^^^^^^^ meta.cursor-name constant.other.placeholder +-- ^^^^^^^^^ meta.cursor-name FETCH NEXT FROM db_cursor INTO @name -- ^^^^^^^ keyword.other -- ^^^^ keyword.other --- ^^^^^^^^^ meta.cursor-name constant.other.placeholder +-- ^^^^^^^^^ meta.cursor-name -- ^^^^ keyword.other -- ^^^^^ variable.other.readwrite @@ -268,10 +268,10 @@ END CLOSE db_cursor -- ^^ keyword.other --- ^^^^^^^^^ meta.cursor-name constant.other.placeholder +-- ^^^^^^^^^ meta.cursor-name DEALLOCATE db_cursor -- ^^^^^^^ keyword.other --- ^^^^^^^^^ meta.cursor-name constant.other.placeholder +-- ^^^^^^^^^ meta.cursor-name ------------- @@ -282,7 +282,7 @@ SET NOCOUNT ON -- ^^ constant.language.boolean EXEC master.dbo.xp_fileexist @FromFile, @FileExists OUTPUT -- ^ keyword.control.flow --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name -- ^^^^^^^^^ variable.other.readwrite -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^ variable.other.readwrite @@ -326,12 +326,12 @@ EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'every 10 @schedule_uid=N'564354f8-4985-7408-80b7-afdc2bb92d3c' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback -- ^^^^ keyword.control.flow --- ^^^^^^^^^^^^^^^^ meta.label-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^ meta.label-name EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' -- ^ keyword.control.flow -- ^^^^^^^^^^^ variable.other.readwrite -- ^ keyword.operator.assignment --- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback COMMIT TRANSACTION -- ^^^^^^^^^^^^^^^ keyword.context @@ -349,14 +349,14 @@ EndSave: INSERT INTO my_table (foo, bar) -- ^^^^^^^^ keyword.other.DML -- ^^^^^^^^^^^^^^^^^^^^ - meta.function-call - support --- ^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^ meta.table-name VALUES (2, 'two'), -- ^^^ keyword.other.DML.II (3, 'three') INSERT INTO #my_table -- ^^^^^^^^ keyword.other.DML --- ^^^^^^^^^ meta.table-name constant.other.placeholder - meta.function-call - support +-- ^^^^^^^^^ meta.table-name - meta.function-call - support VALUES (2, 'two'), -- ^^^ keyword.other.DML.II (3, 'three') @@ -365,9 +365,9 @@ VALUES (2, 'two'), SELECT foo AS foobar, COUNT(*) AS tally -- ^^^ keyword.other.DML --- ^^^ meta.column-name constant.other.placeholder +-- ^^^ meta.column-name -- ^^ keyword.operator.assignment.alias --- ^^^^^^ meta.column-alias constant.other.placeholder +-- ^^^^^^ meta.column-alias -- ^ punctuation.separator.sequence -- ^^^^^^^^ meta.function-call -- ^^^^^ support.function.aggregate @@ -376,10 +376,10 @@ SELECT foo AS foobar, COUNT(*) AS tally -- ^ variable.language.wildcard.asterisk -- ^ punctuation.section.parens.end -- ^^ keyword.operator.assignment.alias --- ^^^^^ meta.column-alias constant.other.placeholder +-- ^^^^^ meta.column-alias FROM bar -- ^ keyword.other.DML --- ^^^ meta.table-name constant.other.placeholder +-- ^^^ meta.table-name WHERE 1 = 1 -- ^^ keyword.other.DML GROUP BY foo @@ -391,9 +391,9 @@ from (select * from some_table) alias_table WITH (NOLOCK) -- ^ punctuation.section.group.begin -- ^^^^^^ keyword.other.DML -- ^ variable.language.wildcard.asterisk --- ^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^ meta.table-name -- ^ punctuation.section.group.end --- ^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^^ meta.table-name -- ^^^^ keyword.other.DML -- ^ punctuation.section.group.begin -- ^^^^^^ meta.group constant.language.with @@ -403,7 +403,7 @@ where exists(select * from other_table where id = some_table.id) UPDATE TableAlias -- ^^^ keyword.other.DML --- ^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^ meta.table-name SET column1 = v.column1, -- <- keyword.other.DML --^ keyword.other.DML @@ -411,8 +411,8 @@ SET column1 = v.column1, -- ^ keyword.operator FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^ keyword.other.DML --- ^^^^^^^^^^^^^ meta.table-name constant.other.placeholder --- ^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^^^^ meta.table-name +-- ^^^^^^^^^^ meta.table-name -- ^^^^ keyword.other -- ^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ - meta.group @@ -423,19 +423,19 @@ FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^ punctuation.section.group.end INNER JOIN some_view AS v WITH (NOLOCK) ON v.some_id = TableAlias.some_id -- ^^^^^^^ keyword.other.DML --- ^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^ meta.table-name -- ^^ keyword.operator.assignment.alias --- ^ meta.table-name constant.other.placeholder +-- ^ meta.table-name -- ^^^^ keyword.other.DML -- ^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^ constant.language.with -- ^ punctuation.section.group.end -- ^^ keyword.operator.join --- ^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^ meta.column-name -- ^ punctuation.accessor.dot -- ^ keyword.operator.comparison --- ^^^^^^^^^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.accessor.dot WHERE TableAlias.some_id IN ( -- ^^ keyword.other.DML @@ -445,8 +445,8 @@ WHERE TableAlias.some_id IN ( -- ^^^^^^ keyword.other.DML FROM dbname..table_name_in_default_schema a -- ^^^^ keyword.other.DML --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder --- ^ meta.group meta.table-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^ meta.group meta.table-name WHERE a.another_id_column IS NOT NULL -- ^^^^^ meta.group keyword.other.DML -- ^^ keyword.operator.logical @@ -462,22 +462,22 @@ AND (v.column2 IS NULL OR ISNULL(TableAlias.column1, 0) != v.column1) drop table foobar -- ^^^^^^^ meta.drop keyword.other.ddl --- ^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^ meta.table-name alter table foo -- ^^^^^^^^ meta.alter keyword.other.ddl --- ^^^ meta.alter meta.table-name constant.other.placeholder +-- ^^^ meta.alter meta.table-name add bar uniqueidentifier --^ meta.alter keyword.other.ddl --- ^^^ meta.alter meta.column-name constant.other.placeholder +-- ^^^ meta.alter meta.column-name -- ^^^^^^^^^^^^^^^^ meta.alter storage.type alter table foo --^^^^^^^^^ meta.alter keyword.other.ddl - meta.alter meta.alter --- ^^^ meta.alter meta.table-name constant.other.placeholder +-- ^^^ meta.alter meta.table-name alter column bar uniqueidentifier not null --^^^^^^^^^^ meta.alter keyword.other.ddl --- ^^^ meta.alter meta.column-name constant.other.placeholder +-- ^^^ meta.alter meta.column-name -- ^^^^^^^^^^^^^^^^ meta.alter storage.type -- ^^^ meta.alter keyword.operator.logical -- ^^^^ meta.alter constant.language.null @@ -493,7 +493,7 @@ SELECT i.ProductID, p.Name, i.LocationID, i.Quantity -- ^^^^^^^^ meta.group keyword.other.DML -- ^^^^ meta.group keyword.other.order -- ^^ keyword.operator.assignment.alias --- ^^^^ meta.column-alias constant.other.placeholder +-- ^^^^ meta.column-alias FROM Production.ProductInventory AS i INNER JOIN Production.Product AS p ON i.ProductID = p.ProductID @@ -522,12 +522,12 @@ SET Value = Bar.Value FROM foo INNER JOIN bar (NOLOCK) ON bar.Title = foo.Title COLLATE DATABASE_DEFAULT AND ISNULL(bar.some_id, 0) = ISNULL(foo.some_id, 0) -- ^^^^^^^ keyword.other.DML --- ^^^ meta.table-name constant.other.placeholder +-- ^^^ meta.table-name -- ^^^^^^ meta.group constant.language.with -- ^^ keyword.operator.join --- ^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^ meta.column-name -- ^ keyword.operator.comparison --- ^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^ meta.column-name -- ^^^^^^^ keyword.other -- ^^^^^^^^^^^^^^^^ support.constant -- ^^^ keyword.operator.logical @@ -536,24 +536,24 @@ INNER JOIN bar (NOLOCK) ON bar.Title = foo.Title COLLATE DATABASE_DEFAULT AND IS -- ^^^^^^ meta.function-call support.function AND foo.a = '' -- ^^^ keyword.operator.logical --- ^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^ meta.column-name -- ^ keyword.operator.comparison -- ^^ string.quoted.single SELECT DISTINCT * INTO ##global_temp_table -- ^ keyword.other.DML --- ^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^^^^ meta.table-name FROM some_long_table_name s LEFT OUTER JOIN another_long_table_name (NOLOCK) a ON s.blah = a.blah AND ISNULL(p.ok, '') = ISNULL(a.ok, '') COLLATE DATABASE_DEFAULT -- ^^^^^^^^^^^^ keyword.other.DML --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^^^^^^ meta.group constant.language.with --- ^ meta.table-name constant.other.placeholder +-- ^ meta.table-name -- ^^ keyword.operator.join --- ^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^ meta.column-name -- ^ keyword.operator.comparison --- ^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^ meta.column-name -- ^^^ keyword.operator.logical -- ^^^^^^ meta.function-call support.function -- ^^^^^^^ keyword.other @@ -587,7 +587,7 @@ BEGIN -- ^ meta.group punctuation.section.group.end -- ^ variable.language.wildcard.asterisk -- ^^^^ keyword.other.DML --- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^ punctuation.definition.identifier.begin -- ^ punctuation.definition.identifier.end -- ^ punctuation.accessor.dot @@ -607,35 +607,35 @@ select A.A -- ^^^^ keyword.control.conditional.case , B.* -- ^ punctuation.separator.sequence --- ^^ meta.column-name constant.other.placeholder +-- ^^ meta.column-name -- ^ punctuation.accessor.dot -- ^ variable.language.wildcard.asterisk into #temp -- ^ keyword.other.DML --- ^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^ meta.table-name from @A A -- ^ keyword.other.DML --- ^^ meta.table-name constant.other.placeholder --- ^ meta.table-name constant.other.placeholder +-- ^^ meta.table-name +-- ^ meta.table-name inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN(B.C) DESC) = B.ID --^^^^^^^^ keyword.other.DML --- ^ meta.table-name constant.other.placeholder +-- ^ meta.table-name -- ^^ keyword.operator.join -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^ keyword.other.DML -- ^ keyword.operator.comparison --- ^^^^ meta.column-name constant.other.placeholder +-- ^^^^ meta.column-name WITH Sales_CTE (SalesPersonID, TotalSales, SalesYear) -- ^ keyword.other.DML --- ^^^^^^^^^ meta.cte-table-name constant.other.placeholder +-- ^^^^^^^^^ meta.cte-table-name -- ^ punctuation.section.group.begin --- ^^^^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.separator.sequence --- ^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^ meta.column-name -- ^ punctuation.separator.sequence --- ^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^ meta.column-name AS -- <- keyword.operator.assignment.cte -- Define the first CTE query. @@ -653,9 +653,9 @@ AS -- <- punctuation.separator.sequence.cte -- Define the second CTE query, which returns sales quota data by year for each sales person. Sales_Quota_CTE (BusinessEntityID, SalesQuota, SalesQuotaYear) --- ^^^^^^^^^^^^ meta.cte-table-name constant.other.placeholder +-- ^^^^^^^^^^^^ meta.cte-table-name -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group - meta.group meta.group --- ^^^^^^^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^ meta.column-name AS -- <- keyword.operator.assignment.cte ( @@ -702,29 +702,29 @@ OPTION (MAXRECURSION 3) WITH cte_table AS ( SELECT blah ) -- ^ keyword.other.DML --- ^^^^^^^^^ meta.cte-table-name constant.other.placeholder +-- ^^^^^^^^^ meta.cte-table-name -- ^^ keyword.operator.assignment.cte -- ^ meta.group punctuation.section.group.begin -- ^^^^^^ meta.group keyword.other.DML --- ^^^^ meta.group meta.column-name constant.other.placeholder +-- ^^^^ meta.group meta.column-name -- ^ meta.group punctuation.section.group.end SELECT cte_table.* FROM cte_table -- ^^^ keyword.other.DML --- ^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^ meta.column-name -- ^ variable.language.wildcard.asterisk -- ^^^^ keyword.other.DML --- ^^^^^^^^^ meta.table-name constant.other.placeholder +-- ^^^^^^^^^ meta.table-name CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)); -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other -- ^^^ meta.toc-list.full-identifier entity.name.function -- ^ punctuation.section.group.begin --- ^^ meta.column-name constant.other.placeholder +-- ^^ meta.column-name -- ^^^^^ storage.type -- ^^^^^^^^^^^ storage.modifier -- ^ punctuation.separator.sequence --- ^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^ meta.column-name -- ^^^^^^^^^^^^^ storage.type -- ^ constant.numeric -- ^ punctuation.section.group.end @@ -732,7 +732,7 @@ CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)); CREATE TABLE foo ([int] [int] PRIMARY KEY, [test'hello¬world'@"me"] [varchar] (5)); -- ^^^^^ storage.type --- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.column-name constant.other.placeholder +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.column-name MERGE sales.category t USING sales.category_staging s From dcd61cba74a1f1eca1b9f5711a786a21fbacd1f0 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 25 Sep 2021 23:57:29 +0300 Subject: [PATCH 016/250] [SQL] various TSQL fixes and syntax tests --- SQL/SQL (basic).sublime-syntax | 13 ++- SQL/TSQL.sublime-syntax | 60 ++++++++--- SQL/syntax_test_tsql.sql | 183 ++++++++++++++++++++++++++++++++- 3 files changed, 234 insertions(+), 22 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 5c72afe993..bcf07c7455 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -8,10 +8,10 @@ version: 2 variables: string_escape: (?:\\.) simple_identifier: (?:\w+) - reserved: (?i:;|\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|union|insert|delete|truncate|create|alter|drop)\b) + reserved: (?i:;|\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|union|insert|delete|update|truncate|create|alter|drop)\b) additional_reserved: (?!) simple_types: (?i:\b(?:bit|bool|boolean|datetime|int)\b) - types_with_optional_number: (?i:\b(?:char|number|nvarchar|varbinary|varchar)\b) + types_with_optional_number: (?i:\b(?:n?char|number|n?varchar|varbinary)\b) contexts: prototype: @@ -178,12 +178,17 @@ contexts: - match: (?=\S) push: [column-name, single-identifier] + numbers: + - match: \b\d+\.\d+\b + scope: meta.number.float.decimal.sql constant.numeric.value.sql + - match: \b\d+\b + scope: meta.number.integer.decimal.sql constant.numeric.value.sql + expressions: - match: (?i)\bas\b scope: keyword.operator.assignment.alias.sql push: [column-alias, single-identifier-after-whitespace] - - match: \b\d+\b - scope: meta.number.integer.decimal.sql constant.numeric.value.sql + - include: numbers - match: (?i)\b(?:true|false)\b scope: constant.language.boolean.sql - match: (?i:\bnull\b) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 700cc5ab1d..759034ef4f 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -8,11 +8,11 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') #(?:\\[tnr]) simple_identifier: (?:(?:(?:##?)?|@)?\w+) # (one or two hashes OR an ampersand OR nothing) followed by a word - additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec)\b) + additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec|go|bulk|insert)\b) enclosed_type_begin: (?:\[) enclosed_type_end: (?:\]) - simple_types: (?i:\b(?:bit|bool|boolean|datetime|int|smallint|sysname|uniqueidentifier|text)\b) - types_with_optional_number: (?i:\b(?:n?char|numeric|n?varchar|varbinary|decimal|money)\b) + simple_types: (?i:\b(?:bit|bool|boolean|datetime|int|smallint|sysname|uniqueidentifier|n?text|image|rowversion)\b) + types_with_optional_number: (?i:\b(?:n?char|numeric|n?varchar|binary|varbinary|decimal|money)\b) contexts: identifier-part: @@ -167,7 +167,7 @@ contexts: fail: like-strings-branch types: - - meta_append: true + - meta_prepend: true - match: |- (?xi) {{enclosed_type_begin}}? @@ -179,12 +179,13 @@ contexts: {{enclosed_type_begin}}? {{types_with_optional_number}} {{enclosed_type_end}}? - (?:\s*\((\d+)(?:\s*(,)\s*(\d+))?\))? + (?:\s*\(\s*(?:(\d+)|(MAX))\s*(?:(,)\s*(\d+))?\))? scope: storage.type.sql captures: 1: constant.numeric.sql - 2: punctuation.separator.sequence.sql - 3: constant.numeric.sql + 2: constant.language.max.sql + 3: punctuation.separator.sequence.sql + 4: constant.numeric.sql statements: - meta_append: true @@ -215,6 +216,8 @@ contexts: scope: keyword.other.tsql - match: \b(?i:disk|tape|url)\b scope: keyword.other.tsql + - match: \b(?i:pivot|unpivot)\b + scope: keyword.other.tsql - match: \b(\w+)(:) captures: 1: entity.name.label.tsql @@ -243,17 +246,17 @@ contexts: scope: keyword.other.sql - match: \b(?i:cursor\s+for)\b scope: keyword.other.sql - - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b - scope: keyword.other.sql - push: [cursor-name, single-identifier-after-whitespace] - match: \b(?i:collate)\b scope: keyword.other.tsql push: collation dml-statements: - meta_append: true - - match: \b(?i:bulk)\b + - match: \b(?i:bulk\s+insert)\b scope: keyword.other.tsql + - match: (?i:\binsert\b) + scope: keyword.other.DML.sql + push: [table-name, single-identifier-after-whitespace] - match: \b(?i:into)\b(?!\s*@) scope: keyword.other.DML.tsql push: [table-name, single-identifier-after-whitespace] @@ -261,8 +264,9 @@ contexts: scope: keyword.other.tsql - match: \b(?i:off)\b scope: keyword.other.tsql - - match: \b(?i:for\s+xml\s+path)\b + - match: \b(?i:for\s+xml)\b scope: keyword.other.tsql + push: for-xml - match: \b(?i:top)\b scope: keyword.other.DML.tsql - match: \b(?i:(option))\b\s*(\() @@ -270,10 +274,13 @@ contexts: 1: keyword.other.DML.tsql 2: punctuation.section.group.begin.sql push: inside-with-group + - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b + scope: keyword.other.sql + push: [cursor-name, single-identifier-after-whitespace] ddl-statements: - meta_prepend: true - - match: \b(?i:create\s+or\s+alter)\b + - match: \b(?i:create(?:\s+or\s+alter)?)\b scope: keyword.other.ddl.sql push: [ddl-create-target-expect-as, ddl-create-target, create-condition, ddl-target] @@ -286,7 +293,8 @@ contexts: - match: (?i:\bas\b) scope: keyword.context.block.sql pop: true - - include: expressions-or-column-name + - include: pop-on-top-level-reserved-word + - include: expressions built-in-scalar-function-calls: - meta_append: true @@ -363,6 +371,21 @@ contexts: scope: constant.language.with.tsql - match: ',' scope: punctuation.separator.sequence.tsql + - match: '=' + scope: keyword.operator.assignment.tsql + push: expressions-pop-at-comma + + expressions-pop-at-comma: + - match: (?=[,)]) + pop: true + - include: expressions + + maybe-identifier-accessor: + - meta_prepend: true + - match: \s*(\.{2,}) + captures: + 1: punctuation.accessor.dot.sql + set: single-identifier-after-whitespace cast: - meta_scope: meta.function-call.sql @@ -425,3 +448,12 @@ contexts: - meta_content_scope: meta.cte-table-name.sql - match: '' pop: true + + for-xml: + - match: \b(?i:raw|auto|elements|root)\b + scope: keyword.other.tsql + - match: \b(?:XSINIL|XMLSCHEMA)\b # case sensitive?! TODO: need to check + scope: keyword.other.tsql + - include: expressions + - match: (?=\S) + pop: true diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 4934323790..0e933d7f49 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -715,7 +715,7 @@ SELECT cte_table.* FROM cte_table -- ^^^^ keyword.other.DML -- ^^^^^^^^^ meta.table-name -CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)); +CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)) -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other -- ^^^ meta.toc-list.full-identifier entity.name.function @@ -728,13 +728,188 @@ CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)); -- ^^^^^^^^^^^^^ storage.type -- ^ constant.numeric -- ^ punctuation.section.group.end --- ^ punctuation.terminator.statement - +GO +-- <- keyword.control.flow CREATE TABLE foo ([int] [int] PRIMARY KEY, [test'hello¬world'@"me"] [varchar] (5)); -- ^^^^^ storage.type -- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.column-name -MERGE sales.category t +CREATE PROCEDURE [blah].[test] + @input1 INT, + @input2 [VARCHAR]( MAX ) +-- ^^^^^^^^^^^^^^^^ storage.type +-- ^^^ constant.language.max +AS +-- <- keyword.context.block +;WITH CTE AS (SELECT @input1 AS Input1) UPDATE Blah SET X = CTE.Input1 FROM CTE JOIN X ON X.Nonsense = 12.6 +-- <- punctuation.terminator.statement +--^^^ keyword.other.DML +-- ^^^ meta.cte-table-name +-- ^^ keyword.operator.assignment.cte +-- ^^^^^^ keyword.other.DML +-- ^^^^ meta.table-name +-- ^^^ keyword.other.DML +-- ^^^^ meta.number.float.decimal constant.numeric.value + +IF OBJECT_ID('tempdb..import') IS NOT NULL + DROP TABLE tempdb..import + -- ^^^^^^^^^^^^^^ meta.table-name + -- ^^ punctuation.accessor.dot +GO +CREATE TABLE tempdb..[import] (a varchar(10), b varchar(20) null) +GO +RAISERROR ('importing file...', 0, 1) WITH NOWAIT +-- import file +BULK INSERT +--^^^^^^^^^ keyword.other + tempdb..import +FROM + 'C:\temp_folder\filename.txt' +WITH ( + FIRSTROW = 1, +-- ^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.separator.sequence + FIELDTERMINATOR = ';', + ROWTERMINATOR = '\n', +-- ^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^^^ string.quoted.single +-- ^ punctuation.separator.sequence + CODEPAGE = '1257', + TABLOCK +-- ^^^^^^^ constant.language.with +) +-- <- punctuation.section.group.end +IF @@ERROR != 0 +-- <- keyword.control.flow +-- ^^^^^^^ support.variable.global +-- ^^ keyword.operator.comparison + UPDATE tempdb..continue_script SET proceed = 0 +GO +IF EXISTS (SELECT proceed FROM tempdb..continue_script WHERE proceed = 0) + RETURN +RAISERROR ('file imported', 0, 1) WITH NOWAIT + +--------- + +SELECT [EmpID] + ,[FirstName] + ,[LastName] + ,[Education] + ,[Occupation] + ,[YearlyIncome] + ,[Sales] + ,[HireDate] + FROM [NewEmployee] + FOR XML RAW, ELEMENTS; +-- ^^^^^^ keyword.other +-- ^^^ keyword.other +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ keyword.other + +SELECT [EmpID] + ,[FirstName] + ,[LastName] + ,[Education] + ,[Occupation] + ,[YearlyIncome] + ,[Sales] + ,[HireDate] + FROM [NewEmployee] + FOR XML RAW('Employee'), +--^^^^^^^ keyword.other +-- ^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^ string.quoted.single +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence + ROOT('EmployeeDetails'), ELEMENTS XSINIL, XMLSCHEMA('urn:tutorialgateway.org'); +-- ^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ keyword.other +-- ^^^^^^ keyword.other +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ keyword.other +------------------------ + +-- Pivot table with one row and five columns +SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days, + [0], [1], [2], [3], [4] +FROM +( + SELECT DaysToManufacture, StandardCost + FROM Production.Product +) AS SourceTable +PIVOT +( + AVG(StandardCost) + FOR DaysToManufacture IN ([0], [1], [2], [3], [4]) -- TODO: scope FOR correctly +) AS PivotTable; +------------ +-- Create the table and insert values as portrayed in the previous example. +CREATE TABLE pvt (VendorID INT, Emp1 INT, Emp2 INT, + Emp3 INT, Emp4 INT, Emp5 INT); +GO +INSERT INTO pvt VALUES (1,4,3,5,4,4); +INSERT INTO pvt VALUES (2,4,1,5,5,5); +INSERT INTO pvt VALUES (3,4,3,5,4,4); +INSERT INTO pvt VALUES (4,4,2,5,5,4); +INSERT INTO pvt VALUES (5,5,1,5,5,5); +GO +-- Unpivot the table. +SELECT VendorID, Employee, Orders +FROM + (SELECT VendorID, Emp1, Emp2, Emp3, Emp4, Emp5 + FROM pvt) p +UNPIVOT + (Orders FOR Employee IN -- TODO: scope FOR correctly + (Emp1, Emp2, Emp3, Emp4, Emp5) +)AS unpvt; +GO +------------- + +CREATE TABLE dbo.T1 ( column_1 int IDENTITY, column_2 VARCHAR(30)); +GO +INSERT T1 VALUES ('Row #1'); +--^^^^ keyword.other.DML +-- ^^ meta.table-name +-- ^^^^^^ keyword.other.DML.II +INSERT T1 (column_2) VALUES ('Row #2'); +GO +SET IDENTITY_INSERT T1 ON; -- TODO: scope me correctly +GO +INSERT INTO T1 (column_1,column_2) + VALUES (-99, 'Explicit identity value'); +GO +SELECT column_1, column_2 +FROM T1; +GO + +CREATE TABLE dbo.T1 +( + column_1 AS 'Computed column ' + column_2, -- TODO: scope the computed column expression correctly + column_2 varchar(30) + CONSTRAINT default_name DEFAULT ('my column default'), -- TODO: scope the constraint name correctly +-- ^^^^^^^^^^ storage.modifier + column_3 rowversion, +-- ^^^^^^^^ meta.column-name +-- ^^^^^^^^^^ storage.type + column_4 varchar(40) NULL +); +INSERT INTO T1 DEFAULT VALUES; +-- ^^^^^^^^ keyword.other.DML +-- ^^ meta.table-name +-- ^^^^^^^ storage.modifier +-- ^^^^^^ keyword.other.DML.II +-- ^ punctuation.terminator.statement + + +MERGE sales.category t -- TODO: scope this correctly USING sales.category_staging s ON (s.category_id = t.category_id) WHEN MATCHED From 1e431ae861d0da13159c685b7d180786e6eacadd Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 26 Sep 2021 00:18:51 +0300 Subject: [PATCH 017/250] [SQL] support OUTER APPLY in TSQL syntax --- SQL/TSQL.sublime-syntax | 2 +- SQL/syntax_test_tsql.sql | 60 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 759034ef4f..06b93a155c 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -413,7 +413,7 @@ contexts: joins: - meta_append: true - - match: (?i)\b(?:cross\s+)?apply\b + - match: (?i)\b(?:(?:cross|outer)\s+)?apply\b scope: keyword.other.DML.sql push: table-name-or-subquery diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 0e933d7f49..8860d4f095 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -837,6 +837,16 @@ SELECT [EmpID] -- ^^^^^^^^^ keyword.other ------------------------ +USE [AdventureWorks] +GO +SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name +FROM [Production].[ProductReview] PR +WITH (INDEX = IX_ProductReview_ProductID_Name) -- TODO: scope index name correctly +INNER JOIN [Production].[Product] PP +WITH (INDEX = [AK_Product_Name]) ON PR.ProductID = PP.ProductID -- TODO: scope index name correctly +----------------- + + -- Pivot table with one row and five columns SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days, [0], [1], [2], [3], [4] @@ -921,3 +931,53 @@ WHEN NOT MATCHED BY TARGET VALUES (s.category_id, s.category_name, s.amount) WHEN NOT MATCHED BY SOURCE THEN DELETE; + +-------------- + +CREATE TABLE [Employee]( + [EmployeeID] [int] NOT NULL PRIMARY KEY, + [FirstName] VARCHAR(250) NOT NULL, + [LastName] VARCHAR(250) NOT NULL, + [DepartmentID] [int] NOT NULL REFERENCES [Department](DepartmentID), -- TODO: scope reference table name correctly +) ON [PRIMARY] -- TODO: scope ON [Primary] correctly +GO +SELECT * FROM Department D +CROSS APPLY +--^^^^^^^^^ keyword.other.DML + ( + SELECT * FROM Employee E + WHERE E.DepartmentID = D.DepartmentID + ) A +GO +SELECT * FROM Department D +OUTER APPLY +-- ^^^^^^^^ keyword.other.DML + ( + SELECT * FROM Employee E + WHERE E.DepartmentID = D.DepartmentID + ) A +GO +-------------------- +IF EXISTS (SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'[fn_GetAllEmployeeOfADepartment]') AND type IN (N'IF')) +BEGIN + DROP FUNCTION dbo.fn_GetAllEmployeeOfADepartment -- TODO: scope this correctly +END +GO + +CREATE FUNCTION dbo.fn_GetAllEmployeeOfADepartment(@DeptID AS INT) +RETURNS TABLE -- TODO: scope this correctly +AS +RETURN + ( + SELECT * FROM Employee E + WHERE E.DepartmentID = @DeptID + ) +GO + +SELECT * FROM Department D +CROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) -- TODO: scope function call correctly in place of a table name/subquery +GO + +SELECT * FROM Department D +OUTER APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) +GO From a380ed3d7718a052f60548f2b78e404203f250a3 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 26 Sep 2021 22:56:22 +0300 Subject: [PATCH 018/250] [SQL] create extension point for TSQL to deal with UPDATE and DELETE TOP --- SQL/SQL (basic).sublime-syntax | 16 ++++- SQL/TSQL.sublime-syntax | 75 +++++++++++++++++--- SQL/syntax_test_tsql.sql | 123 ++++++++++++++++++++++++++++++++- 3 files changed, 202 insertions(+), 12 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index bcf07c7455..cccff0cfa2 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -359,7 +359,13 @@ contexts: scope: keyword.other.DML.sql - match: (?i:\bunion(?:\s+all)?\b) scope: keyword.other.DML.sql - - match: (?i:\b(?:insert\s+into|update|delete(?:\s+from)?|truncate)\b) + - match: (?i:\b(?:delete(?:\s+from)?)\b) + scope: keyword.other.DML.sql + set: dml-delete + - match: (?i:\b(?:update)\b) + scope: keyword.other.DML.sql + set: dml-update + - match: (?i:\b(?:insert\s+into|truncate)\b) scope: keyword.other.DML.sql push: [table-name, single-identifier-after-whitespace] - match: (?i:\bset\b) @@ -377,6 +383,14 @@ contexts: - match: (?i)\b(asc|desc)\b scope: keyword.other.order.sql + dml-delete: + - match: (?=\S) + set: [table-name, single-identifier] + + dml-update: + - match: (?=\S) + set: [table-name, single-identifier] + distinct: - match: \b(?i:distinct)\b scope: keyword.other.DML.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 06b93a155c..55c4e0f7d3 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -11,8 +11,18 @@ variables: additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec|go|bulk|insert)\b) enclosed_type_begin: (?:\[) enclosed_type_end: (?:\]) - simple_types: (?i:\b(?:bit|bool|boolean|datetime|int|smallint|sysname|uniqueidentifier|n?text|image|rowversion)\b) - types_with_optional_number: (?i:\b(?:n?char|numeric|n?varchar|binary|varbinary|decimal|money)\b) + + simple_types: |- + (?ix:\b(?: + (?:bigint|bit|float|int|real|smallint|tinyint) + | (?:date|datetime|datetime2|datetimeoffset|smalldatetime|time) + | (?:geometry|hierarchyid|image|n?text|rowversion|sql_variant|sysname|uniqueidentifier|xml) + )\b) + types_with_optional_number: |- + (?ix:\b(?: + (?:n?char|n?varchar|binary|varbinary) + | (?:decimal|money|numeric) + )\b) contexts: identifier-part: @@ -170,15 +180,15 @@ contexts: - meta_prepend: true - match: |- (?xi) - {{enclosed_type_begin}}? + {{enclosed_type_begin}} {{simple_types}} - {{enclosed_type_end}}? + {{enclosed_type_end}} scope: storage.type.sql - match: |- (?xi) - {{enclosed_type_begin}}? + {{enclosed_type_begin}} {{types_with_optional_number}} - {{enclosed_type_end}}? + {{enclosed_type_end}} (?:\s*\(\s*(?:(\d+)|(MAX))\s*(?:(,)\s*(\d+))?\))? scope: storage.type.sql captures: @@ -186,6 +196,12 @@ contexts: 2: constant.language.max.sql 3: punctuation.separator.sequence.sql 4: constant.numeric.sql + - match: |- + (?xi) + (?:{{enclosed_type_begin}}|\b) + table + (?:{{enclosed_type_end}}|\b) + scope: storage.type.sql statements: - meta_append: true @@ -244,8 +260,10 @@ contexts: scope: storage.modifier.output.tsql - match: \b(?i:over|partition\s+by)\b scope: keyword.other.sql - - match: \b(?i:cursor\s+for)\b - scope: keyword.other.sql + - match: \b(?i:(cursor)\s+(for))\b + captures: + 1: support.type.tsql + 2: keyword.other.sql - match: \b(?i:collate)\b scope: keyword.other.tsql push: collation @@ -267,8 +285,7 @@ contexts: - match: \b(?i:for\s+xml)\b scope: keyword.other.tsql push: for-xml - - match: \b(?i:top)\b - scope: keyword.other.DML.tsql + - include: top - match: \b(?i:(option))\b\s*(\() captures: 1: keyword.other.DML.tsql @@ -296,6 +313,23 @@ contexts: - include: pop-on-top-level-reserved-word - include: expressions + top: + - match: (?i)\b(top)\b(?:\s+(?:(\()\s*)?(\d+)(?:\s*(\)))?(?:\s+(percent\b))?)? + captures: + 1: keyword.other.DML.tsql + 2: meta.group.tsql punctuation.section.parens.begin.tsql + 3: meta.group.tsql meta.number.integer.decimal.tsql constant.numeric.value.tsql + 4: meta.group.tsql punctuation.section.parens.end.tsql + 5: keyword.other.DML.tsql + + dml-delete: + - meta_prepend: true + - include: top + + dml-update: + - meta_prepend: true + - include: top + built-in-scalar-function-calls: - meta_append: true - match: (?i)\b(?:CONVERT|GETDATE)(?=\s*\() @@ -417,6 +451,18 @@ contexts: scope: keyword.other.DML.sql push: table-name-or-subquery + table-name-or-subquery: + - meta_prepend: true + - match: \b(?i:OPENXML)\b + scope: support.function.tsql + push: begin-method-call-paren + - match: \b(?i:(OPENROWSET))\b\s*(\() + scope: meta.function-call.tsql + captures: + 1: support.function.tsql + 2: punctuation.section.group.begin.tsql + set: inside-openrowset-call + exec: - include: assignment-operator - include: pop-on-top-level-reserved-word @@ -457,3 +503,12 @@ contexts: - include: expressions - match: (?=\S) pop: true + + inside-openrowset-call: + - meta_content_scope: meta.group.sql + - match: ';' + scope: punctuation.separator.sequence.tsql + - match: \) + scope: meta.function-call.tsql meta.group.tsql punctuation.section.parens.end.sql + set: table-alias + - include: inside-method-call diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 8860d4f095..c8242d4b76 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -222,7 +222,8 @@ SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) DECLARE db_cursor CURSOR FOR -- ^^^^ keyword.declaration.variable -- ^^^^^^^^^ meta.cursor-name --- ^^^^^^^^^^ keyword.other +-- ^^^^^^ support.type +-- ^^^ keyword.other SELECT name -- ^^^^^^ keyword.other.DML -- ^^^^ meta.column-name @@ -966,6 +967,7 @@ GO CREATE FUNCTION dbo.fn_GetAllEmployeeOfADepartment(@DeptID AS INT) RETURNS TABLE -- TODO: scope this correctly +-- ^^^^^ storage.type AS RETURN ( @@ -981,3 +983,122 @@ GO SELECT * FROM Department D OUTER APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) GO + +SELECT DB_NAME(r.database_id) AS [Database], st.[text] AS [Query] +FROM sys.dm_exec_requests r +CROSS APPLY sys.dm_exec_sql_text(r.plan_handle) st +WHERE r.session_Id > 50 -- Consider spids for users only, no system spids. +AND r.session_Id NOT IN (@@SPID) -- Don't include request from current spid. + +SELECT p.BusinessEntityID , + p.FirstName , + p.MiddleName , + p.LastName , + pp.PhoneNumber +FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) -- TODO: scope correctly + LEFT OUTER JOIN Person.PersonPhone AS pp TABLESAMPLE (10 ROWS) + ON pp.BusinessEntityID = p.BusinessEntityID +ORDER BY p.BusinessEntityID DESC; + +-------- + +USE AdventureWorks2012; +GO +DECLARE @MyTableVar table( + EmpID INT NOT NULL, + OldVacationHours INT, + NewVacationHours INT, + ModifiedDate datetime); +UPDATE TOP (10) HumanResources.Employee +-- ^^^ keyword.other.DML +-- ^^^ keyword.other.DML +-- ^^^^ meta.group +-- ^ punctuation.section.parens.begin +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.parens.end +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +SET VacationHours = VacationHours * 1.25 -- TODO: the * here should be scoped as an operator +OUTPUT INSERTED.BusinessEntityID, + DELETED.VacationHours, + INSERTED.VacationHours, + INSERTED.ModifiedDate +INTO @MyTableVar; +--Display the result set of the table variable. +SELECT EmpID, OldVacationHours, NewVacationHours, ModifiedDate +FROM @MyTableVar; +GO +--Display the result set of the table. +--Note that ModifiedDate reflects the value generated by an +--AFTER UPDATE trigger. +SELECT TOP 10 percent BusinessEntityID, VacationHours, ModifiedDate +-- ^^^ keyword.other.DML +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^^^^^^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^ meta.column-name +FROM HumanResources.Employee; +GO +---------------- +DECLARE @XmlDocumentHandle int +DECLARE @XmlDocument nvarchar(1000) +SET @XmlDocument = N' + + VINET + Paul Henriot + + + + + + + LILAS + Carlos Gonzlez + + + + +' +-- Create an internal representation of the XML document. +EXEC sp_xml_preparedocument @XmlDocumentHandle OUTPUT, @XmlDocument +-- Execute a SELECT statement using OPENXML rowset provider. +SELECT * +FROM OPENXML (@XmlDocumentHandle, '/ROOT/Customer',2) -- TODO: apply xpath highlighting to the string +--^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^ - meta.function-call +-- ^^^^^^^ support.function +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.parens.begin +-- ^^^^^^^^^^^^^^^^^^ variable.other.readwrite + WITH (CustomerID varchar(10), -- TODO: scope correctly https://docs.microsoft.com/en-us/sql/t-sql/functions/openxml-transact-sql?view=sql-server-ver15 + ContactName varchar(20)) +EXEC sp_xml_removedocument @XmlDocumentHandle + +--Create an internal representation of the XML document. +EXEC sp_xml_preparedocument @idoc OUTPUT, @doc; + +-- SELECT stmt using OPENXML rowset provider +SELECT * +FROM OPENXML (@idoc, '/ROOT/Customer/Order/OrderDetail',2) + WITH (OrderID int '../@OrderID', + CustomerID varchar(10) '../@CustomerID', + OrderDate datetime '../@OrderDate', + ProdID int '@ProductID', + Qty int '@Quantity'); +----- +SELECT * +FROM table_name AS t1 + INNER JOIN (SELECT foo FROM bar) AS t2(id) ON t2.ID = t1.ID + +---- + +SELECT a.* + FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', + 'C:\SAMPLES\Northwind.mdb'; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence + 'admin'; + 'password', + Customers) AS a; +-- ^ meta.function-call meta.group punctuation.section.parens.end +-- ^^ keyword.operator.assignment.alias - meta.group - meta.function-call +-- ^ meta.table-name From bdfd46508fd4798942bb89921f3ca294aa163a4e Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 26 Sep 2021 23:14:04 +0300 Subject: [PATCH 019/250] [SQL] mark TSQL table hints without WITH as deprecated --- SQL/TSQL.sublime-syntax | 22 +++++++++++++++++++++- SQL/syntax_test_tsql.sql | 21 ++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 55c4e0f7d3..8a5bd6e036 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -27,6 +27,10 @@ variables: contexts: identifier-part: - meta_prepend: true + - match: \b(?i:inserted|deleted)(\.) + scope: constant.language.table.tsql + captures: + 1: punctuation.accessor.dot.tsql - include: square-bracketed-identifier-part square-bracketed-identifier-part: @@ -363,6 +367,7 @@ contexts: table-alias: - meta_prepend: true + - include: table-hint-without-with - include: with - match: \( scope: punctuation.section.group.begin.sql @@ -371,7 +376,22 @@ contexts: after-table-alias: - meta_prepend: true - include: with - - include: with-paren + - include: table-hint-without-with + - match: \( + scope: punctuation.section.group.begin.tsql + push: inside-group # column-alias-list + + table-hint-without-with: + - match: |- + (?xi) + (\()\s* + (NOLOCK|READUNCOMMITTED|UPDLOCK|REPEATABLEREAD|SERIALIZABLE|READCOMMITTED|TABLOCK|TABLOCKX|PAGLOCK|ROWLOCK|NOWAIT|READPAST|XLOCK|SNAPSHOT|NOEXPAND) + \s*(\)) + scope: meta.group.tsql invalid.deprecated.table-hint-without-with.tsql # https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-ver15#arguments + captures: + 1: punctuation.section.group.begin.tsql + 2: constant.language.table-hint.tsql + 3: punctuation.section.group.end.tsql with: - match: (?i)\bwith\b(?=\s*(?:\[\w+\]|\w+)\s*\() diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index c8242d4b76..461bfde8e4 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -524,7 +524,7 @@ FROM foo INNER JOIN bar (NOLOCK) ON bar.Title = foo.Title COLLATE DATABASE_DEFAULT AND ISNULL(bar.some_id, 0) = ISNULL(foo.some_id, 0) -- ^^^^^^^ keyword.other.DML -- ^^^ meta.table-name --- ^^^^^^ meta.group constant.language.with +-- ^^^^^^ meta.group invalid.deprecated.table-hint-without-with.tsql constant.language.table-hint.tsql -- ^^ keyword.operator.join -- ^^^^^^^^^ meta.column-name -- ^ keyword.operator.comparison @@ -549,7 +549,7 @@ FROM some_long_table_name s LEFT OUTER JOIN another_long_table_name (NOLOCK) a ON s.blah = a.blah AND ISNULL(p.ok, '') = ISNULL(a.ok, '') COLLATE DATABASE_DEFAULT -- ^^^^^^^^^^^^ keyword.other.DML -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name --- ^^^^^^ meta.group constant.language.with +-- ^^^^^^ invalid.deprecated.table-hint-without-with.tsql constant.language.table-hint.tsql -- ^ meta.table-name -- ^^ keyword.operator.join -- ^^^^^^ meta.column-name @@ -1019,7 +1019,16 @@ UPDATE TOP (10) HumanResources.Employee -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name SET VacationHours = VacationHours * 1.25 -- TODO: the * here should be scoped as an operator OUTPUT INSERTED.BusinessEntityID, +--^^^^ storage.modifier.output +-- ^^^^^^^^^ meta.column-name constant.language.table +-- ^ meta.column-name constant.language.table punctuation.accessor.dot +-- ^^^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence DELETED.VacationHours, +-- ^^^^^^^^ meta.column-name constant.language.table +-- ^ meta.column-name constant.language.table punctuation.accessor.dot +-- ^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence INSERTED.VacationHours, INSERTED.ModifiedDate INTO @MyTableVar; @@ -1088,7 +1097,13 @@ FROM OPENXML (@idoc, '/ROOT/Customer/Order/OrderDetail',2) SELECT * FROM table_name AS t1 INNER JOIN (SELECT foo FROM bar) AS t2(id) ON t2.ID = t1.ID - +-- ^^ keyword.operator.assignment.alias +-- ^^ meta.table-name +-- ^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^ keyword.operator.join ---- SELECT a.* From d966004ff68ee287da7e9c479f432b5314171164 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 27 Sep 2021 23:18:36 +0300 Subject: [PATCH 020/250] [SQL] scope table valued function calls correctly --- SQL/SQL (basic).sublime-syntax | 25 ++++++++++++++++++++++++- SQL/TSQL.sublime-syntax | 12 ++++++------ SQL/syntax_test_tsql.sql | 19 +++++++++++++++++-- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index cccff0cfa2..d29723d087 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -433,7 +433,21 @@ contexts: table-name-or-subquery: - include: subquery - match: (?=\S) - set: [table-alias, table-name, single-identifier] + branch_point: table-or-table-function + branch: + - table-name-not-function-call + - table-valued-function-call + + table-name-not-function-call: + - match: '' + push: [fail-if-function-call, table-name, single-identifier] + + fail-if-function-call: + - match: \( + fail: table-or-table-function # basically we are using branch points to avoid a complicated lookahead (which can be overridden by syntaxes extending this one) for an identifier followed by an open paren + - match: (?=\S) + set: table-alias + pop: 3 # one to pop 'fail-if-function-call', one to pop 'table-name-not-function-call' where we were forced to push to avoid the branch instantly succeeding, one because we are doing a set and ST gets confused without it?! it should set away from 'table-name-or-subquery' table-alias: - match: \b(?i:as)\b @@ -466,3 +480,12 @@ contexts: assignment-operator: - match: '=' scope: keyword.operator.assignment.sql + + table-valued-function-call: + - match: '' + set: [table-alias, begin-method-call-paren, table-valued-function-name, single-identifier] + + table-valued-function-name: + - meta_content_scope: meta.table-valued-function-name.sql + - match: '' + pop: true diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 8a5bd6e036..4fb1a71fda 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -367,11 +367,11 @@ contexts: table-alias: - meta_prepend: true - - include: table-hint-without-with - include: with - - match: \( - scope: punctuation.section.group.begin.sql - push: inside-with-group + + fail-if-function-call: + - meta_prepend: true + - include: table-hint-without-with after-table-alias: - meta_prepend: true @@ -474,12 +474,12 @@ contexts: table-name-or-subquery: - meta_prepend: true - match: \b(?i:OPENXML)\b - scope: support.function.tsql + scope: meta.table-valued-function-name.sql support.function.tsql push: begin-method-call-paren - match: \b(?i:(OPENROWSET))\b\s*(\() scope: meta.function-call.tsql captures: - 1: support.function.tsql + 1: meta.table-valued-function-name.sql support.function.tsql 2: punctuation.section.group.begin.tsql set: inside-openrowset-call diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 461bfde8e4..09a87196a4 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -977,7 +977,15 @@ RETURN GO SELECT * FROM Department D -CROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) -- TODO: scope function call correctly in place of a table name/subquery +CROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) AS func_call_results_table +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-valued-function-name +-- ^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.parens.begin +-- ^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.parens.end +-- ^^ keyword.operator.assignment.alias - meta.function-call +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name GO SELECT * FROM Department D @@ -987,6 +995,11 @@ GO SELECT DB_NAME(r.database_id) AS [Database], st.[text] AS [Query] FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.plan_handle) st +-- ^^^^^^^^^^^^^^^^^^^^ meta.function-call meta.table-valued-function-name +-- ^ meta.function-call meta.group punctuation.section.parens.begin +-- ^^^^^^^^^^^^^ meta.function-call meta.group meta.column-name +-- ^ meta.function-call meta.group punctuation.section.parens.end +-- ^^ meta.table-name WHERE r.session_Id > 50 -- Consider spids for users only, no system spids. AND r.session_Id NOT IN (@@SPID) -- Don't include request from current spid. @@ -1074,7 +1087,7 @@ FROM OPENXML (@XmlDocumentHandle, '/ROOT/Customer',2) -- TODO: apply xpath --^^ keyword.other.DML -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call -- ^ - meta.function-call --- ^^^^^^^ support.function +-- ^^^^^^^ meta.table-valued-function-name support.function -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.parens.begin -- ^^^^^^^^^^^^^^^^^^ variable.other.readwrite @@ -1108,6 +1121,8 @@ FROM table_name AS t1 SELECT a.* FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', +-- ^^^^ keyword.other.DML +-- ^^^^^^^^^^ meta.function-call meta.table-valued-function-name support.function 'C:\SAMPLES\Northwind.mdb'; -- ^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single -- ^ punctuation.separator.sequence From 5ffe63a288ce79220b60792f6c96379d7655978f Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 27 Sep 2021 23:30:21 +0300 Subject: [PATCH 021/250] [SQL] introduce separate scope for table aliases so they can be colored differently --- SQL/SQL (basic).sublime-syntax | 15 ++++++++++----- SQL/TSQL.sublime-syntax | 8 +++++--- SQL/syntax_test_tsql.sql | 32 +++++++++++++++++++++----------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index d29723d087..3f3bd56f57 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -276,7 +276,7 @@ contexts: - meta_scope: meta.group.sql - match: \) scope: punctuation.section.group.end.sql - set: table-alias + set: maybe-table-alias - include: main statements: @@ -420,6 +420,11 @@ contexts: - match: '' pop: true + table-alias-name: + - meta_content_scope: meta.table-alias-name.sql + - match: '' + pop: true + procedure-name: - meta_content_scope: meta.procedure-name.sql - match: '' @@ -446,15 +451,15 @@ contexts: - match: \( fail: table-or-table-function # basically we are using branch points to avoid a complicated lookahead (which can be overridden by syntaxes extending this one) for an identifier followed by an open paren - match: (?=\S) - set: table-alias + set: maybe-table-alias pop: 3 # one to pop 'fail-if-function-call', one to pop 'table-name-not-function-call' where we were forced to push to avoid the branch instantly succeeding, one because we are doing a set and ST gets confused without it?! it should set away from 'table-name-or-subquery' - table-alias: + maybe-table-alias: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql - include: pop-on-top-level-reserved-word - match: (?=\S) - set: [after-table-alias, table-name, single-identifier] + set: [after-table-alias, table-alias-name, single-identifier] after-table-alias: - match: (?=\S) @@ -483,7 +488,7 @@ contexts: table-valued-function-call: - match: '' - set: [table-alias, begin-method-call-paren, table-valued-function-name, single-identifier] + set: [maybe-table-alias, begin-method-call-paren, table-valued-function-name, single-identifier] table-valued-function-name: - meta_content_scope: meta.table-valued-function-name.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 4fb1a71fda..8a7f65b1bf 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -255,6 +255,8 @@ contexts: expressions: - meta_prepend: true - include: types + - match: 0x\h+ + scope: meta.number.integer.hexadecimal.tsql constant.numeric.value.tsql - match: \b(?i:cast)\b scope: support.function.tsql push: cast @@ -365,7 +367,7 @@ contexts: - match: (?=\S) pop: true - table-alias: + maybe-table-alias: - meta_prepend: true - include: with @@ -414,7 +416,7 @@ contexts: with-paren-or-pop: - include: with-paren - match: (?=\S) - set: table-alias + set: maybe-table-alias inside-with-group: - meta_scope: meta.group.sql @@ -530,5 +532,5 @@ contexts: scope: punctuation.separator.sequence.tsql - match: \) scope: meta.function-call.tsql meta.group.tsql punctuation.section.parens.end.sql - set: table-alias + set: maybe-table-alias - include: inside-method-call diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 09a87196a4..3c3566c8ba 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -394,7 +394,7 @@ from (select * from some_table) alias_table WITH (NOLOCK) -- ^ variable.language.wildcard.asterisk -- ^^^^^^^^^^ meta.table-name -- ^ punctuation.section.group.end --- ^^^^^^^^^^^ meta.table-name +-- ^^^^^^^^^^^ meta.table-alias-name -- ^^^^ keyword.other.DML -- ^ punctuation.section.group.begin -- ^^^^^^ meta.group constant.language.with @@ -410,10 +410,12 @@ SET column1 = v.column1, --^ keyword.other.DML column2 = 'testing123 TODO: assert the = operator is scoped as assignment instead of comparison' -- ^ keyword.operator + , col3 = 0xDEADC0DE +-- ^^^^^^^^^^ meta.number.integer.hexadecimal constant.numeric.value FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^ keyword.other.DML -- ^^^^^^^^^^^^^ meta.table-name --- ^^^^^^^^^^ meta.table-name +-- ^^^^^^^^^^ meta.table-alias-name -- ^^^^ keyword.other -- ^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ - meta.group @@ -426,7 +428,7 @@ INNER JOIN some_view AS v WITH (NOLOCK) ON v.some_id = TableAlias.some_id -- ^^^^^^^ keyword.other.DML -- ^^^^^^^^^ meta.table-name -- ^^ keyword.operator.assignment.alias --- ^ meta.table-name +-- ^ meta.table-alias-name -- ^^^^ keyword.other.DML -- ^^^^^^^^ meta.group -- ^ punctuation.section.group.begin @@ -447,7 +449,7 @@ WHERE TableAlias.some_id IN ( FROM dbname..table_name_in_default_schema a -- ^^^^ keyword.other.DML -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name --- ^ meta.group meta.table-name +-- ^ meta.group meta.table-alias-name WHERE a.another_id_column IS NOT NULL -- ^^^^^ meta.group keyword.other.DML -- ^^ keyword.operator.logical @@ -550,7 +552,7 @@ LEFT OUTER JOIN another_long_table_name (NOLOCK) a ON s.blah = a.blah AND ISNULL -- ^^^^^^^^^^^^ keyword.other.DML -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^^^^^^ invalid.deprecated.table-hint-without-with.tsql constant.language.table-hint.tsql --- ^ meta.table-name +-- ^ meta.table-alias-name -- ^^ keyword.operator.join -- ^^^^^^ meta.column-name -- ^ keyword.operator.comparison @@ -617,7 +619,7 @@ into #temp from @A A -- ^ keyword.other.DML -- ^^ meta.table-name --- ^ meta.table-name +-- ^ meta.table-alias-name inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN(B.C) DESC) = B.ID --^^^^^^^^ keyword.other.DML -- ^ meta.table-name @@ -985,11 +987,19 @@ CROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) AS func_call_resu -- ^^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.section.parens.end -- ^^ keyword.operator.assignment.alias - meta.function-call --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-alias-name GO SELECT * FROM Department D -OUTER APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) +OUTER APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID, 123, 'testing123') +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call meta.table-valued-function-name +-- ^ meta.function-call meta.group punctuation.section.parens.begin +-- ^^^^^^^^^^^^^^ meta.function-call meta.group meta.column-name +-- ^ meta.function-call meta.group punctuation.separator.argument +-- ^^^ meta.function-call meta.group meta.number.integer.decimal constant.numeric.value +-- ^ meta.function-call meta.group punctuation.separator.argument +-- ^^^^^^^^^^^^ meta.function-call meta.group string.quoted.single +-- ^ meta.function-call meta.group punctuation.section.parens.end GO SELECT DB_NAME(r.database_id) AS [Database], st.[text] AS [Query] @@ -999,7 +1009,7 @@ CROSS APPLY sys.dm_exec_sql_text(r.plan_handle) st -- ^ meta.function-call meta.group punctuation.section.parens.begin -- ^^^^^^^^^^^^^ meta.function-call meta.group meta.column-name -- ^ meta.function-call meta.group punctuation.section.parens.end --- ^^ meta.table-name +-- ^^ meta.table-alias-name WHERE r.session_Id > 50 -- Consider spids for users only, no system spids. AND r.session_Id NOT IN (@@SPID) -- Don't include request from current spid. @@ -1111,7 +1121,7 @@ SELECT * FROM table_name AS t1 INNER JOIN (SELECT foo FROM bar) AS t2(id) ON t2.ID = t1.ID -- ^^ keyword.operator.assignment.alias --- ^^ meta.table-name +-- ^^ meta.table-alias-name -- ^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^ meta.column-name @@ -1131,4 +1141,4 @@ SELECT a.* Customers) AS a; -- ^ meta.function-call meta.group punctuation.section.parens.end -- ^^ keyword.operator.assignment.alias - meta.group - meta.function-call --- ^ meta.table-name +-- ^ meta.table-alias-name From e22825eae4232da670ac578996375347655de951 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 29 Sep 2021 22:55:00 +0300 Subject: [PATCH 022/250] [SQL] initial support for MERGE --- SQL/SQL (basic).sublime-syntax | 1 + SQL/TSQL.sublime-syntax | 30 +++++++++++++- SQL/syntax_test_tsql.sql | 73 +++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 4 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 3f3bd56f57..e2c6d47f5d 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -436,6 +436,7 @@ contexts: set: inside-subquery-allow-table-alias table-name-or-subquery: + - include: pop-on-top-level-reserved-word - include: subquery - match: (?=\S) branch_point: table-or-table-function diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 8a7f65b1bf..f8542c142a 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -8,7 +8,7 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') #(?:\\[tnr]) simple_identifier: (?:(?:(?:##?)?|@)?\w+) # (one or two hashes OR an ampersand OR nothing) followed by a word - additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec|go|bulk|insert)\b) + additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec|go|bulk|insert|on|when)\b) enclosed_type_begin: (?:\[) enclosed_type_end: (?:\]) @@ -273,6 +273,9 @@ contexts: - match: \b(?i:collate)\b scope: keyword.other.tsql push: collation + - match: \b(?i:when\s+(?:not\s+)?matched)\b + scope: keyword.control.conditional.case.sql + push: merge-condition dml-statements: - meta_append: true @@ -300,6 +303,12 @@ contexts: - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b scope: keyword.other.sql push: [cursor-name, single-identifier-after-whitespace] + - match: \b(?i:merge)\b + scope: keyword.other.tsql + push: [maybe-table-alias, table-name, single-identifier-after-whitespace] + - match: \b(?i:using)\b + scope: keyword.other.tsql + push: [table-name-or-subquery, join-on, maybe-table-alias, table-name, single-identifier-after-whitespace] ddl-statements: - meta_prepend: true @@ -518,10 +527,12 @@ contexts: pop: true for-xml: - - match: \b(?i:raw|auto|elements|root)\b + - match: \b(?i:raw|auto|elements|root|path)\b scope: keyword.other.tsql - match: \b(?:XSINIL|XMLSCHEMA)\b # case sensitive?! TODO: need to check scope: keyword.other.tsql + - match: (?=\)) + pop: true - include: expressions - match: (?=\S) pop: true @@ -534,3 +545,18 @@ contexts: scope: meta.function-call.tsql meta.group.tsql punctuation.section.parens.end.sql set: maybe-table-alias - include: inside-method-call + + merge-condition: + - match: \b(?i:\s+by\s+(?:source|target))\b + scope: keyword.other.tsql + - match: \b(?i:then)\b + scope: keyword.other.tsql + - match: (?i:\binsert\b)(?=\s*\() + scope: keyword.other.DML.sql + push: values-or-expressions + - include: dml-statements + - include: pop-on-top-level-reserved-word + + values-or-expressions: + - include: dml-statements + - include: expressions diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 3c3566c8ba..e4352116c9 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -922,18 +922,65 @@ INSERT INTO T1 DEFAULT VALUES; -- ^ punctuation.terminator.statement -MERGE sales.category t -- TODO: scope this correctly +MERGE sales.category t +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ meta.table-alias-name USING sales.category_staging s +-- ^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^ meta.table-alias-name ON (s.category_id = t.category_id) +-- <- keyword.operator.join +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^^^^^^^^^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^^^^^^^^^^^^^ meta.column-name WHEN MATCHED +-- ^^^^^^^^^ keyword.control.conditional.case THEN UPDATE SET +-- ^^^^ keyword.other +-- ^^^^^^ keyword.other.DML +-- ^^^ keyword.other.DML t.category_name = s.category_name, +-- ^^^^^^^^^^^^^^^ meta.column-name +-- ^ keyword.operator +-- ^^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence t.amount = s.amount +-- ^^^^^^^^ meta.column-name +-- ^ keyword.operator +-- ^^^^^^^^ meta.column-name WHEN NOT MATCHED BY TARGET +--^^^^^^^^^^^^^^ keyword.control.conditional.case +-- ^^^^^^^^^ keyword.other THEN INSERT (category_id, category_name, amount) +-- ^^^^ keyword.other +-- ^^^^^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^ meta.column-name +-- ^ punctuation.section.group.end VALUES (s.category_id, s.category_name, s.amount) +-- ^^^^^^ keyword.other.DML.II +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end WHEN NOT MATCHED BY SOURCE +--^^^^^^^^^^^^^^ keyword.control.conditional.case +-- ^^^^^^^^^ keyword.other THEN DELETE; +-- ^^^^ keyword.other +-- ^^^^^^ keyword.other.DML +-- ^ punctuation.terminator.statement -------------- @@ -1017,7 +1064,8 @@ SELECT p.BusinessEntityID , p.FirstName , p.MiddleName , p.LastName , - pp.PhoneNumber + pp.PhoneNumber , + dbo.some_func(p.BusinessEntityID) -- TODO: scope correctly FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) -- TODO: scope correctly LEFT OUTER JOIN Person.PersonPhone AS pp TABLESAMPLE (10 ROWS) ON pp.BusinessEntityID = p.BusinessEntityID @@ -1142,3 +1190,24 @@ SELECT a.* -- ^ meta.function-call meta.group punctuation.section.parens.end -- ^^ keyword.operator.assignment.alias - meta.group - meta.function-call -- ^ meta.table-alias-name + +DECLARE @Data NVARCHAR(MAX) +SELECT @Data = ( + SELECT [CustomerID] as "@CustomerID", + [CustomerName], + [CustomerCategoryName], + [PrimaryContact], + [AlternateContact], + [PhoneNumber], + [FaxNumber], + [BuyingGroupName] AS '*', + [WebsiteURL] WebsiteLink, -- TODO: scope alias correctly when no explicit 'AS' + [DeliveryMethod] 'MethodOfDelivery' -- TODO: scope alias correctly when no explicit 'AS' + FROM [WideWorldImporters].[Website].[Customers] + WHERE CustomerID < 3 FOR XML PATH('Customer'), ROOT('Customers') +-- ^^^^^^^ keyword.other +-- ^^^^ keyword.other +-- ^ punctuation.separator.sequence +-- ^^^^ keyword.other +) +-- <- meta.group punctuation.section.group.end From 70ceaad4f92171bfa9ea0e93ff2c0376d46695a4 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Thu, 30 Sep 2021 22:49:49 +0300 Subject: [PATCH 023/250] [SQL] scope table definition columns separately, identify operators vs wildcards --- SQL/MySQL.sublime-syntax | 25 +++++++------- SQL/SQL (basic).sublime-syntax | 46 ++++++++++++++++++++------ SQL/TSQL.sublime-syntax | 30 ++++++++++++++--- SQL/syntax_test_mysql.sql | 11 +++++-- SQL/syntax_test_tsql.sql | 59 +++++++++++++++++++++++++++++----- 5 files changed, 133 insertions(+), 38 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 26dae9b7cd..39dd2c33ee 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -9,14 +9,15 @@ variables: simple_types: |- (?xi: \b - (?:bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|int|integer| - line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext) + (?:bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|integer| + line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext| + unsigned) \b ) types_with_optional_number: |- (?xi: \b - (?:bit\s+varying|character\s+(?:varying)?|tinyint|var\schar|float|interval|numeric|decimal|times?|timestamp(?:s|tz)?) + (?:bit\s+varying|character\s+(?:varying)?|tinyint|var\schar|float|int|interval|numeric|decimal|times?|timestamp(?:s|tz)?) \b ) @@ -39,15 +40,6 @@ contexts: strings: - meta_append: true - - match: "`" - scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.quoted.other.backtick.sql - - match: "`" - scope: punctuation.definition.string.end.sql - pop: true - - include: string-escape - match: '"' scope: punctuation.definition.string.begin.sql push: @@ -126,8 +118,6 @@ contexts: - match: \b(?i:create\s+or\s+replace)\b scope: keyword.other.ddl.sql push: [ddl-create-target, create-condition, ddl-target] - - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) - scope: keyword.other.object-comments.sql dml-statements: - meta_append: true @@ -174,3 +164,10 @@ contexts: - meta_prepend: true - match: \b(?i:change\s+column)\b scope: keyword.other.ddl.sql + + inside-ddl-table-creation-columns: + - meta_prepend: true + - match: \b(?i:auto_increment)\b + scope: keyword.other.mysql + - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) + scope: keyword.other.object-comments.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index e2c6d47f5d..5bc10323b2 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -21,7 +21,6 @@ contexts: - include: statements - match: ';' scope: punctuation.terminator.statement.sql - - include: types - include: expressions-or-column-name comments: @@ -95,7 +94,7 @@ contexts: - match: \s*(\.)(?=\s*\*) captures: 1: punctuation.accessor.dot.sql - pop: true + set: possible-wildcard - match: \s*(\.) captures: 1: punctuation.accessor.dot.sql @@ -156,7 +155,7 @@ contexts: operators: - match: '<=>|[!<>]?=|<>|<|>' scope: keyword.operator.comparison.sql - - match: '-|\+|/' + - match: '[-+/*]' scope: keyword.operator.arithmetic.sql - include: logical-operators @@ -174,9 +173,10 @@ contexts: 3: constant.numeric.sql expressions-or-column-name: + - include: wildcard-identifier - include: expressions - match: (?=\S) - push: [column-name, single-identifier] + push: [possible-operator, column-name, single-identifier] numbers: - match: \b\d+\.\d+\b @@ -185,6 +185,7 @@ contexts: scope: meta.number.integer.decimal.sql constant.numeric.value.sql expressions: + - include: types - match: (?i)\bas\b scope: keyword.operator.assignment.alias.sql push: [column-alias, single-identifier-after-whitespace] @@ -193,8 +194,6 @@ contexts: scope: constant.language.boolean.sql - match: (?i:\bnull\b) scope: constant.language.null.sql - - match: \* - scope: variable.language.wildcard.asterisk.sql - match: \b(?i:case)\b scope: keyword.control.conditional.case.sql push: inside-case-expression @@ -284,6 +283,9 @@ contexts: - include: dml-statements ddl-statements: + - match: \b(?i:create\s+table)\b + scope: keyword.other.ddl.sql + push: [ddl-create-target, ddl-table-creation-columns, create-condition] - match: \b(?i:create)\b scope: keyword.other.ddl.sql push: [ddl-create-target, create-condition, ddl-target] @@ -299,8 +301,6 @@ contexts: # - match: \b(?i:alter)\b # scope: keyword.other.ddl.sql # push: ddl-alter-target - - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) - scope: storage.modifier.sql - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) scope: keyword.other.authorization.sql @@ -309,6 +309,11 @@ contexts: - match: (?=\S) pop: true + ddl-table-creation-columns: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-ddl-table-creation-columns + ddl-drop-target: - meta_scope: meta.drop.sql - match: '' @@ -371,7 +376,7 @@ contexts: - match: (?i:\bset\b) scope: keyword.other.DML.sql push: set - - match: (?i:\bvalues\b) + - match: (?i:\b(?:default\s+)?values\b) scope: keyword.other.DML.II.sql - include: distinct - include: joins @@ -383,6 +388,15 @@ contexts: - match: (?i)\b(asc|desc)\b scope: keyword.other.order.sql + inside-ddl-table-creation-columns: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: true + - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) + scope: storage.modifier.sql + - include: expressions-or-column-name + dml-delete: - match: (?=\S) set: [table-name, single-identifier] @@ -495,3 +509,17 @@ contexts: - meta_content_scope: meta.table-valued-function-name.sql - match: '' pop: true + + possible-operator: + - include: operators + - match: (?=\S) + pop: true + + wildcard-identifier: + - match: \* + scope: variable.language.wildcard.asterisk.sql + + possible-wildcard: + - include: wildcard-identifier + - match: (?=\S) + pop: true diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index f8542c142a..69733b7e54 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -254,7 +254,6 @@ contexts: expressions: - meta_prepend: true - - include: types - match: 0x\h+ scope: meta.number.integer.hexadecimal.tsql constant.numeric.value.tsql - match: \b(?i:cast)\b @@ -312,7 +311,7 @@ contexts: ddl-statements: - meta_prepend: true - - match: \b(?i:create(?:\s+or\s+alter)?)\b + - match: (?i)\b(?:create(?:\s+or\s+alter)?)\b(?!\s*table\b) scope: keyword.other.ddl.sql push: [ddl-create-target-expect-as, ddl-create-target, create-condition, ddl-target] @@ -325,6 +324,8 @@ contexts: - match: (?i:\bas\b) scope: keyword.context.block.sql pop: true + - match: \b(?i:returns)\b + scope: keyword.other.tsql - include: pop-on-top-level-reserved-word - include: expressions @@ -438,7 +439,12 @@ contexts: scope: punctuation.separator.sequence.tsql - match: '=' scope: keyword.operator.assignment.tsql - push: expressions-pop-at-comma + push: with-assignment + + with-assignment: + - match: \b(?i:ON|OFF)\b + scope: constant.language.bool.tsql + - include: expressions-pop-at-comma expressions-pop-at-comma: - match: (?=[,)]) @@ -506,9 +512,9 @@ contexts: set: [procedure-name, single-identifier-after-whitespace] cte-column-list-begin: - - match: \( + - match: (?=\() scope: punctuation.section.group.begin.tsql - set: [cte-as, inside-group] + set: [cte-as, ddl-table-creation-columns] - match: (?=\S) pop: true @@ -560,3 +566,17 @@ contexts: values-or-expressions: - include: dml-statements - include: expressions + + inside-ddl-table-creation-columns: + - meta_prepend: true + - match: \b(?i:ROWGUIDCOL|CLUSTERED)\b + scope: storage.modifier.tsql + - match: \b(?i:AS)\b + scope: keyword.other.tsql + push: computed-column-definition + + computed-column-definition: + - meta_content_scope: meta.computed-column-definition.tsql + - match: (?=,) + pop: true + - include: expressions-or-column-name diff --git a/SQL/syntax_test_mysql.sql b/SQL/syntax_test_mysql.sql index f04836f45c..ce1b83ceda 100644 --- a/SQL/syntax_test_mysql.sql +++ b/SQL/syntax_test_mysql.sql @@ -59,7 +59,14 @@ create table IF NOT EXISTS `testing123` ( -- ^^ keyword.control.flow -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, -- TODO: is unsigned a modifier or part of the type? +-- ^^^^ meta.column-name +-- ^^^^^^^ storage.type +-- ^^^^^^^^ storage.type +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^^^^^^^^ keyword.other +-- ^ punctuation.separator.sequence `lastchanged` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- ^^^^^^^^^ storage.type.sql -- ^^^^^^^^^^^^^^^^^ support.function.scalar.sql @@ -101,7 +108,7 @@ create table fancy_table ( -- ^ punctuation.section.parens.begin -- ^ punctuation.section.parens.end -- ^ punctuation.separator.sequence - mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, + mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, -- TODO: seems like :: is a postgresql cast operator -- ^^^^^^^^^^^^^^^^^^^ storage.type.sql some_number numeric(5, 2) DEFAULT 0, -- ^^^^^^^^^^^ meta.column-name diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index e4352116c9..e4f38ba97d 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -633,6 +633,7 @@ inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN( WITH Sales_CTE (SalesPersonID, TotalSales, SalesYear) -- ^ keyword.other.DML -- ^^^^^^^^^ meta.cte-table-name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.separator.sequence @@ -657,7 +658,7 @@ AS -- Define the second CTE query, which returns sales quota data by year for each sales person. Sales_Quota_CTE (BusinessEntityID, SalesQuota, SalesQuotaYear) -- ^^^^^^^^^^^^ meta.cte-table-name --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group - meta.group meta.group +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns - meta.group meta.group -- ^^^^^^^^^^^^^^^^ meta.column-name AS -- <- keyword.operator.assignment.cte @@ -722,6 +723,7 @@ CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)) -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other -- ^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns -- ^ punctuation.section.group.begin -- ^^ meta.column-name -- ^^^^^ storage.type @@ -905,8 +907,17 @@ GO CREATE TABLE dbo.T1 ( - column_1 AS 'Computed column ' + column_2, -- TODO: scope the computed column expression correctly + column_1 AS 'Computed column ' + column_2, +-- ^^^^^^^^ meta.column-name +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.computed-column-definition +-- ^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ keyword.operator.arithmetic +-- ^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence - meta.computed-column-definition column_2 varchar(30) +-- ^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^ storage.type CONSTRAINT default_name DEFAULT ('my column default'), -- TODO: scope the constraint name correctly -- ^^^^^^^^^^ storage.modifier column_3 rowversion, @@ -917,8 +928,7 @@ CREATE TABLE dbo.T1 INSERT INTO T1 DEFAULT VALUES; -- ^^^^^^^^ keyword.other.DML -- ^^ meta.table-name --- ^^^^^^^ storage.modifier --- ^^^^^^ keyword.other.DML.II +-- ^^^^^^^^^^^^^^ keyword.other.DML.II -- ^ punctuation.terminator.statement @@ -983,13 +993,41 @@ WHEN NOT MATCHED BY SOURCE -- ^ punctuation.terminator.statement -------------- - +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [dbo].[be_Categories]( + [CategoryID] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [DF_be_Categories_CategoryID] DEFAULT (newid()), +-- ^^^^^^^^^^ storage.modifier + [CategoryName] [nvarchar](50) NULL, + [Description] [nvarchar](200) NULL, + [ParentID] [uniqueidentifier] NULL, + CONSTRAINT [PK_be_Categories] PRIMARY KEY CLUSTERED +-- ^^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^ storage.modifier + ( + [CategoryID] ASC +-- ^^^^^^^^^^^^ meta.column-name +-- ^^^ keyword.other.order + ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +-- ^^^^ keyword.other.DML +-- ^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^^ constant.language.bool +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^ constant.language.bool +) ON [PRIMARY] +GO +-------------- CREATE TABLE [Employee]( [EmployeeID] [int] NOT NULL PRIMARY KEY, [FirstName] VARCHAR(250) NOT NULL, [LastName] VARCHAR(250) NOT NULL, [DepartmentID] [int] NOT NULL REFERENCES [Department](DepartmentID), -- TODO: scope reference table name correctly -) ON [PRIMARY] -- TODO: scope ON [Primary] correctly +) ON [PRIMARY] -- TODO: scope on primary correctly GO SELECT * FROM Department D CROSS APPLY @@ -1015,10 +1053,13 @@ END GO CREATE FUNCTION dbo.fn_GetAllEmployeeOfADepartment(@DeptID AS INT) -RETURNS TABLE -- TODO: scope this correctly +RETURNS TABLE +--^^^^^ keyword.other -- ^^^^^ storage.type AS +-- <- keyword.context.block RETURN +-- ^^^ keyword.control.flow ( SELECT * FROM Employee E WHERE E.DepartmentID = @DeptID @@ -1088,7 +1129,9 @@ UPDATE TOP (10) HumanResources.Employee -- ^^ meta.number.integer.decimal constant.numeric.value -- ^ punctuation.section.parens.end -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -SET VacationHours = VacationHours * 1.25 -- TODO: the * here should be scoped as an operator +SET VacationHours = VacationHours * 1.25 +-- ^ keyword.operator.arithmetic +-- ^^^^ meta.number.float.decimal constant.numeric.value OUTPUT INSERTED.BusinessEntityID, --^^^^ storage.modifier.output -- ^^^^^^^^^ meta.column-name constant.language.table From 1d272b7ca0570ee3de039cba97ce5eae581ae6d3 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 1 Oct 2021 06:41:51 +0300 Subject: [PATCH 024/250] [SQL] add test for create index --- SQL/SQL (basic).sublime-syntax | 3 +++ SQL/TSQL.sublime-syntax | 4 +++- SQL/syntax_test_tsql.sql | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 5bc10323b2..68c0824af3 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -306,6 +306,9 @@ contexts: ddl-create-target: - meta_scope: meta.create.sql + - match: \b(?i:on)\b + scope: keyword.other.sql + push: [table-name, single-identifier-after-whitespace] - match: (?=\S) pop: true diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 69733b7e54..008da6a671 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -319,6 +319,8 @@ contexts: - meta_prepend: true - match: \b(?i:proc)\b scope: keyword.other.sql + - match: \b(?i:proc|unique|clustered|nonclustered)\b + scope: keyword.other.sql ddl-create-target-expect-as: - match: (?i:\bas\b) @@ -569,7 +571,7 @@ contexts: inside-ddl-table-creation-columns: - meta_prepend: true - - match: \b(?i:ROWGUIDCOL|CLUSTERED)\b + - match: \b(?i:ROWGUIDCOL|CLUSTERED|NONCLUSTERED)\b scope: storage.modifier.tsql - match: \b(?i:AS)\b scope: keyword.other.tsql diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index e4f38ba97d..c08e43476d 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -1254,3 +1254,21 @@ SELECT @Data = ( -- ^^^^ keyword.other ) -- <- meta.group punctuation.section.group.end + +------------------- +CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^ keyword.other.ddl +-- ^^^^^^ keyword.other +-- ^^^^^^^^^^^^ keyword.other +-- ^^^^^ keyword.other +-- ^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ meta.group punctuation.section.group.begin + some_column ASC +-- ^^^^^^^^^^^ meta.group meta.column-name +-- ^^^ meta.group keyword.other.order +) +-- <- meta.group punctuation.section.group.end +--^ - meta.group From 36a7d0283276928a9c24e0374fb833ec9fce5eba Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 1 Oct 2021 21:29:53 +0300 Subject: [PATCH 025/250] [SQL] add test for create index for MySQL --- SQL/syntax_test_mysql.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/SQL/syntax_test_mysql.sql b/SQL/syntax_test_mysql.sql index ce1b83ceda..db6dd477b8 100644 --- a/SQL/syntax_test_mysql.sql +++ b/SQL/syntax_test_mysql.sql @@ -238,3 +238,16 @@ WHERE f.a IS NULL -- ^^ keyword.operator.logical.sql -- ^^^ keyword.operator.logical.sql -- ^^^^ constant.language.null.sql + +CREATE INDEX IX_some_index ON dbo.some_table( +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other +-- ^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ meta.group punctuation.section.group.begin + some_column ASC +-- ^^^^^^^^^^^ meta.group meta.column-name +-- ^^^ meta.group keyword.other.order +) From f8b7d5bbc9d4780d90fc2ff5475b9ee0f43d8734 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 1 Oct 2021 23:05:55 +0300 Subject: [PATCH 026/250] [SQL] improve cursor and CTE support for TSQL --- SQL/SQL (basic).sublime-syntax | 8 +-- SQL/TSQL.sublime-syntax | 90 ++++++++++++++++++++++----- SQL/syntax_test_tsql.sql | 110 ++++++++++++++++++++++++++++++++- 3 files changed, 186 insertions(+), 22 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 68c0824af3..9f6612ad05 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -8,7 +8,7 @@ version: 2 variables: string_escape: (?:\\.) simple_identifier: (?:\w+) - reserved: (?i:;|\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|union|insert|delete|update|truncate|create|alter|drop)\b) + reserved: (?i:;|\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|union|insert|delete|update|truncate|create|alter|drop|return)\b) additional_reserved: (?!) simple_types: (?i:\b(?:bit|bool|boolean|datetime|int)\b) types_with_optional_number: (?i:\b(?:n?char|number|n?varchar|varbinary)\b) @@ -298,9 +298,9 @@ contexts: - match: \b(?i:alter\s+table)\b scope: keyword.other.ddl.sql push: [ddl-alter-table, table-name, single-identifier-after-whitespace] - # - match: \b(?i:alter)\b - # scope: keyword.other.ddl.sql - # push: ddl-alter-target + - match: \b(?i:alter)\b + scope: keyword.other.ddl.sql + push: [ddl-alter-target, ddl-target] - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) scope: keyword.other.authorization.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 008da6a671..cfde905310 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -211,6 +211,9 @@ contexts: - meta_append: true - include: declarations - include: transaction-statements + - include: cte-with + - match: (?=\b(?i:raiserror)\b) + push: raiserror-args - match: \b(?i:go)\b scope: keyword.control.flow.tsql - match: \b(?i:if|else|return|while)\b @@ -265,10 +268,9 @@ contexts: scope: storage.modifier.output.tsql - match: \b(?i:over|partition\s+by)\b scope: keyword.other.sql - - match: \b(?i:(cursor)\s+(for))\b - captures: - 1: support.type.tsql - 2: keyword.other.sql + - match: \b(?i:cursor)\b + scope: support.type.tsql + set: cursor-declaration - match: \b(?i:collate)\b scope: keyword.other.tsql push: collation @@ -317,10 +319,15 @@ contexts: ddl-target: - meta_prepend: true - - match: \b(?i:proc)\b - scope: keyword.other.sql - match: \b(?i:proc|unique|clustered|nonclustered)\b - scope: keyword.other.sql + scope: keyword.other.ddl.sql + + ddl-alter-target: + - meta_prepend: true + #- match: \b(?i:proc|procedure|function)\b + # scope: keyword.other.sql + - match: (?=\S) + set: [ddl-create-target-expect-as, expect-procedure-name] ddl-create-target-expect-as: - match: (?i:\bas\b) @@ -372,10 +379,14 @@ contexts: set: - meta_prepend: true - - match: \b(?i:nocount)\b + - match: \b(?i:nocount|ansi_nulls|quoted_identifier)\b scope: constant.language.switch.tsql - match: \b(?i:on|off)\b scope: constant.language.boolean.tsql + - include: variables + - match: '[-+/*%^|]=' + scope: keyword.operator.assignment.tsql + - include: operators - match: (?=\S) pop: true @@ -407,26 +418,23 @@ contexts: 2: constant.language.table-hint.tsql 3: punctuation.section.group.end.tsql - with: + cte-with: - match: (?i)\bwith\b(?=\s*(?:\[\w+\]|\w+)\s*\() scope: keyword.other.DML.sql push: [cte-column-list-begin, cte-table-name, single-identifier] - - match: (?i)\bwith\b(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) + - match: (?i)\bwith\b #(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) scope: keyword.other.DML.sql push: [cte-as, cte-table-name, single-identifier] + + with: - match: (?i)\bwith\b scope: keyword.other.DML.sql push: with-paren-or-pop - with-paren: + with-paren-or-pop: - match: \( scope: punctuation.section.group.begin.sql set: inside-with-group - - match: \b(?i:nowait)\b - scope: keyword.other.tsql - - with-paren-or-pop: - - include: with-paren - match: (?=\S) set: maybe-table-alias @@ -582,3 +590,53 @@ contexts: - match: (?=,) pop: true - include: expressions-or-column-name + + raiserror-args: + - match: \b(?i:with)\b + scope: keyword.other.tsql + set: raiserror-options + - include: pop-on-top-level-reserved-word + - include: expressions + + raiserror-options: + - match: \b(?i:nowait|log|seterror)\b + scope: keyword.other.tsql + - match: (?=\S) + pop: true + + cursor-declaration: + - meta_content_scope: meta.cursor-declaration.tsql + - match: (?i)\b(?:FORWARD_ONLY|SCROLL|STATIC|KEYSET|DYNAMIC|FAST_FORWARD|READ_ONLY|SCROLL_LOCKS|OPTIMISTIC|TYPE_WARNING)\b + scope: storage.modifier.tsql + - match: \b(?i:for)\b + scope: keyword.other.tsql + set: expect-cursor-select-statement + - match: (?=\S) + pop: true + + expect-cursor-select-statement: + - meta_content_scope: meta.cursor-declaration.tsql + - match: \b(?i:select)\b + scope: keyword.other.DML.sql + set: after-cursor-select-statement + - match: (?=\S) + pop: true + + after-cursor-select-statement: + - meta_content_scope: meta.cursor-declaration.tsql + - match: \b(?i:for)\b + scope: keyword.other.tsql + set: after-cursor-select-statement-for + - match: (?=\b(?i:open)\b) + pop: true + - include: main + #- include: pop-on-top-level-reserved-word + #- include: expressions-or-column-name + + after-cursor-select-statement-for: + - meta_scope: meta.cursor-declaration.tsql + - match: (?i)\b(?:READ\s+ONLY|UPDATE(?:\s+OF)?)\b + scope: storage.modifier.tsql + pop: true + - match: (?=\S) + pop: true diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index c08e43476d..5ec08f3430 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -219,11 +219,13 @@ SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) -- ^ punctuation.section.parens.end -- ^ - meta.function-call - meta.group -DECLARE db_cursor CURSOR FOR +DECLARE db_cursor CURSOR SCROLL DYNAMIC FOR -- ^^^^ keyword.declaration.variable -- ^^^^^^^^^ meta.cursor-name -- ^^^^^^ support.type --- ^^^ keyword.other +-- ^^^^^^ storage.modifier +-- ^^^^^^^ storage.modifier +-- ^^^ keyword.other SELECT name -- ^^^^^^ keyword.other.DML -- ^^^^ meta.column-name @@ -236,6 +238,12 @@ DECLARE db_cursor CURSOR FOR -- ^^^^^^^^ string.quoted.single -- ^ punctuation.separator.sequence -- ^^^^^^^ string.quoted.single + FOR UPDATE OF name +-- ^^^ meta.cursor-declaration keyword.other +-- ^^^^^^^^^ storage.modifier +-- ^^^^ meta.column-name +DECLARE @blah int +-- <- keyword.declaration.variable - meta.cursor-declaration OPEN db_cursor -- ^ keyword.other @@ -273,6 +281,32 @@ CLOSE db_cursor DEALLOCATE db_cursor -- ^^^^^^^ keyword.other -- ^^^^^^^^^ meta.cursor-name +GO +------- + +DECLARE db_cursor CURSOR FAST_FORWARD READ_ONLY FOR +-- ^^^^ keyword.declaration.variable +-- ^^^^^^^^^ meta.cursor-name +-- ^^^^^^ support.type +-- ^^^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^ storage.modifier +-- ^^^ keyword.other + SELECT name +-- ^^^^^^ keyword.other.DML +-- ^^^^ meta.column-name + FROM MASTER.dbo.sysdatabases + -- ^ keyword.other.DML + -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name + WHERE name NOT IN ('master','model','msdb','tempdb') + -- ^^ keyword.other.DML + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group + -- ^^^^^^^^ string.quoted.single + -- ^ punctuation.separator.sequence + -- ^^^^^^^ string.quoted.single + +OPEN db_cursor +-- ^ keyword.other - meta.cursor-declaration +-- ^^^^^^^^^ meta.cursor-name ------------- @@ -603,6 +637,23 @@ GO -- <- keyword.control.flow --------------- +ALTER PROC CreateOrAlterDemo +-- ^^ meta.alter keyword.other.ddl +-- ^^^^ meta.alter keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^ meta.procedure-name + @Count SMALLINT +,@Other INT OUTPUT +-- <- punctuation.separator.sequence +--^^^^^ variable.other.readwrite +-- ^^^ storage.type +-- ^^^^^^ storage.modifier.output +AS +-- <- keyword.context.block +BEGIN +-- <- keyword.control.flow.begin +END +-- <- keyword.control.flow.end +--- select A.A , CASE WHEN B.B IS NOT NULL THEN B.B ELSE DATEADD(d, 1 - DATEPART(d, GETDATE()), DATEADD(m, B.MonthsInFuture, DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0))) END AS FirstDayOfFutureMonth @@ -994,8 +1045,12 @@ WHEN NOT MATCHED BY SOURCE -------------- SET ANSI_NULLS ON +-- ^^^^^^^^^^ constant.language.switch +-- ^^ constant.language.boolean GO SET QUOTED_IDENTIFIER ON +-- ^^^^^^^^^^^^^^^^^ constant.language.switch +-- ^^ constant.language.boolean GO CREATE TABLE [dbo].[be_Categories]( [CategoryID] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [DF_be_Categories_CategoryID] DEFAULT (newid()), @@ -1272,3 +1327,54 @@ CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( ) -- <- meta.group punctuation.section.group.end --^ - meta.group + +WITH cols +--^^ keyword.other.DML +-- ^^^^ meta.cte-table-name +AS +-- <- keyword.operator.assignment.cte +( + SELECT table_name, column_name, + ROW_NUMBER() OVER(ORDER BY table_name, column_name) AS sequence, + COUNT(*) OVER() AS total_columns + FROM [INFORMATION_SCHEMA].columns +) +SELECT table_name, column_name, total_columns +FROM cols +ORDER BY sequence + +set @test += 2 +--^ keyword.other.DML +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test -= 2 +--^ keyword.other.DML +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test *= 2 +--^ keyword.other.DML +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test /= 2 +--^ keyword.other.DML +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test %= 2 +--^ keyword.other.DML +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test ^= 2 +--^ keyword.other.DML +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value +set @test |= 2 +--^ keyword.other.DML +-- ^^^^^ variable.other.readwrite +-- ^^ keyword.operator.assignment +-- ^ meta.number.integer.decimal constant.numeric.value From bd52fc28a8100b74053203d98e7d28b1b3d8bf7f Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 2 Oct 2021 22:16:29 +0300 Subject: [PATCH 027/250] [SQL] replace pop: true with pop: 1, name anonymous contexts --- SQL/MySQL.sublime-syntax | 62 ++++++++++++++++------------- SQL/SQL (basic).sublime-syntax | 68 ++++++++++++++++---------------- SQL/TSQL.sublime-syntax | 72 +++++++++++++++++----------------- 3 files changed, 104 insertions(+), 98 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 39dd2c33ee..e08a99becd 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -42,27 +42,31 @@ contexts: - meta_append: true - match: '"' scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.quoted.double.sql - - match: '""' - scope: constant.character.escape.sql - - match: '"' - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation + push: inside-double-quoted-string - include: begin-interpolation + inside-double-quoted-string: + - meta_include_prototype: false + - meta_scope: string.quoted.double.sql + - match: '""' + scope: constant.character.escape.sql + - match: '"' + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-interpolation + begin-interpolation: - match: '%\{' scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.other.quoted.brackets.sql - - match: '\}' - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation + push: inside-interpolation + + inside-interpolation: + - meta_include_prototype: false + - meta_scope: string.other.quoted.brackets.sql + - match: '\}' + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-interpolation string-interpolation: - meta_include_prototype: false @@ -75,15 +79,17 @@ contexts: regexps: - match: /(?=\S.*/) scope: punctuation.definition.string.begin.sql - push: - - meta_include_prototype: false - - meta_scope: string.regexp.sql - - match: / - scope: punctuation.definition.string.end.sql - pop: true - - include: string-interpolation - - match: \\/ - scope: constant.character.escape.slash.sql + push: inside-regexp + + inside-regexp: + - meta_include_prototype: false + - meta_scope: string.regexp.sql + - match: / + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-interpolation + - match: \\/ + scope: constant.character.escape.slash.sql operators: - meta_append: true @@ -99,7 +105,7 @@ contexts: - meta_include_prototype: false - meta_scope: comment.line.number-sign.sql - match: \n - pop: true + pop: 1 expressions: - meta_prepend: true @@ -134,7 +140,7 @@ contexts: - match: (?i)\b(?:using)\b scope: keyword.other.mysql - match: (?=\() - pop: true + pop: 1 create-condition: - meta_prepend: true @@ -157,7 +163,7 @@ contexts: - meta_include_prototype: false - meta_prepend: true - match: (?=#) - pop: true + pop: 1 - include: comments ddl-alter-table: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 9f6612ad05..26e25a60c9 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -44,14 +44,14 @@ contexts: - meta_include_prototype: false - meta_scope: comment.line.double-dash.sql - match: \n - pop: true + pop: 1 inside-comment-block: - meta_include_prototype: false - meta_scope: comment.block.sql - match: \*/ scope: punctuation.definition.comment.end.sql - pop: true + pop: 1 - match: ^\s*(\*)(?!/) captures: 1: punctuation.definition.comment.sql @@ -73,13 +73,13 @@ contexts: scope: constant.character.escape.sql - match: \' scope: punctuation.definition.string.end.sql - pop: true + pop: 1 - include: string-escape identifier-create: - meta_scope: meta.toc-list.full-identifier.sql entity.name.function.sql - match: '' - pop: true + pop: 1 single-identifier-after-whitespace: - match: \s* @@ -100,7 +100,7 @@ contexts: 1: punctuation.accessor.dot.sql set: single-identifier-after-whitespace - match: '' - pop: true + pop: 1 identifier-part: - include: simple-identifier-part @@ -110,28 +110,28 @@ contexts: simple-identifier-part: - match: '{{simple_identifier}}' - pop: true + pop: 1 single-quoted-identifier-part: - match: (')([^']+)(') captures: 1: punctuation.definition.identifier.begin.sql 3: punctuation.definition.identifier.end.sql - pop: true + pop: 1 double-quoted-identifier-part: - match: (")([^"]+)(") captures: 1: punctuation.definition.identifier.begin.sql 3: punctuation.definition.identifier.end.sql - pop: true + pop: 1 backtick-quoted-identifier-part: - match: (`)([^`]+)(`) captures: 1: punctuation.definition.identifier.begin.sql 3: punctuation.definition.identifier.end.sql - pop: true + pop: 1 create-condition: - include: dml-condition @@ -210,13 +210,13 @@ contexts: - match: ',' scope: punctuation.separator.sequence.sql - match: (?=;) - pop: true + pop: 1 inside-case-expression: - meta_scope: meta.statement.conditional.case.sql - match: \b(?i:end)\b scope: keyword.control.conditional.end.sql - pop: true + pop: 1 - match: \b(?i)(case)\s+(when)\b captures: 1: keyword.control.conditional.case.sql @@ -252,13 +252,13 @@ contexts: scope: meta.group.sql punctuation.section.parens.begin.sql set: inside-method-call - match: (?=\S) - pop: true + pop: 1 inside-method-call: - meta_content_scope: meta.function-call.sql meta.group.sql - match: \) scope: meta.function-call.sql meta.group.sql punctuation.section.parens.end.sql - pop: true + pop: 1 - match: ',' scope: punctuation.separator.argument.sql - include: distinct @@ -268,7 +268,7 @@ contexts: - meta_scope: meta.group.sql - match: \) scope: punctuation.section.group.end.sql - pop: true + pop: 1 - include: main inside-subquery-allow-table-alias: @@ -310,7 +310,7 @@ contexts: scope: keyword.other.sql push: [table-name, single-identifier-after-whitespace] - match: (?=\S) - pop: true + pop: 1 ddl-table-creation-columns: - match: \( @@ -320,7 +320,7 @@ contexts: ddl-drop-target: - meta_scope: meta.drop.sql - match: '' - pop: true + pop: 1 ddl-target: - match: |- @@ -331,7 +331,7 @@ contexts: schema|sequence|table(?:space)?|trigger|type|user|view scope: keyword.other.sql - match: (?=\S) - pop: true + pop: 1 ddl-drop-table: - meta_scope: meta.drop.sql @@ -351,7 +351,7 @@ contexts: - meta_scope: meta.alter.sql - include: ddl-alter-common - match: (?=\S) - pop: true + pop: 1 ddl-alter-common: - match: (?i:\s*\b(add)\s+(constraint|(?:fulltext|spatial)\s+(index|key)|index)) @@ -395,7 +395,7 @@ contexts: - meta_scope: meta.group.table-columns.sql - match: \) scope: punctuation.section.group.end.sql - pop: true + pop: 1 - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) scope: storage.modifier.sql - include: expressions-or-column-name @@ -420,32 +420,32 @@ contexts: column-name: - meta_content_scope: meta.column-name.sql - match: '' - pop: true + pop: 1 column-alias: - meta_content_scope: meta.column-alias.sql - match: '' - pop: true + pop: 1 database-name: - meta_content_scope: meta.database-name.sql - match: '' - pop: true + pop: 1 table-name: - meta_content_scope: meta.table-name.sql - match: '' - pop: true + pop: 1 table-alias-name: - meta_content_scope: meta.table-alias-name.sql - match: '' - pop: true + pop: 1 procedure-name: - meta_content_scope: meta.procedure-name.sql - match: '' - pop: true + pop: 1 subquery: - match: \( @@ -481,24 +481,24 @@ contexts: after-table-alias: - match: (?=\S) - pop: true + pop: 1 join-on: - match: (?i)\bon\b scope: keyword.operator.join.sql - pop: true + pop: 1 - match: (?=\S) - pop: true + pop: 1 set: - match: (?=\S) - pop: true + pop: 1 pop-on-top-level-reserved-word: - match: (?={{reserved}}|{{additional_reserved}}) - pop: true + pop: 1 - match: (?=\)) - pop: true + pop: 1 assignment-operator: - match: '=' @@ -511,12 +511,12 @@ contexts: table-valued-function-name: - meta_content_scope: meta.table-valued-function-name.sql - match: '' - pop: true + pop: 1 possible-operator: - include: operators - match: (?=\S) - pop: true + pop: 1 wildcard-identifier: - match: \* @@ -525,4 +525,4 @@ contexts: possible-wildcard: - include: wildcard-identifier - match: (?=\S) - pop: true + pop: 1 diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index cfde905310..bc6c9a2c94 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -38,7 +38,7 @@ contexts: captures: 1: punctuation.definition.identifier.begin.sql 3: punctuation.definition.identifier.end.sql - pop: true + pop: 1 strings: - meta_append: true @@ -76,28 +76,28 @@ contexts: scope: punctuation.definition.string.begin.sql set: [like-escape-fail, inside-like-single-quoted-string] - match: (?=\S) - pop: true + pop: 1 like-string-followed-by-escape-slash: - match: \' scope: punctuation.definition.string.begin.sql set: [like-escape-character-slash, like-escape-pop, inside-like-single-quoted-string-slash-escape] - match: (?=\S) - pop: true + pop: 1 like-string-followed-by-escape-caret: - match: \' scope: punctuation.definition.string.begin.sql set: [like-escape-character-caret, like-escape-pop, inside-like-single-quoted-string-caret-escape] - match: (?=\S) - pop: true + pop: 1 like-string-followed-by-unknown-escape: - match: \' scope: punctuation.definition.string.begin.sql set: [like-escape-character-any, like-escape-pop, inside-like-single-quoted-string] - match: (?=\S) - pop: true + pop: 1 inside-like-single-quoted-string-slash-escape: - meta_include_prototype: false @@ -118,7 +118,7 @@ contexts: - meta_scope: meta.string.like.sql string.quoted.single.sql - match: \' scope: punctuation.definition.string.end.sql - pop: true + pop: 1 - match: |- (?x) (\[)(\^)? @@ -138,14 +138,14 @@ contexts: - match: (?i:\bescape\b) fail: like-strings-branch - match: (?=\S) - pop: true + pop: 1 like-escape-pop: - match: (?i:\bescape\b) scope: keyword.operator.word.sql - pop: true + pop: 1 - match: (?=\S) - pop: true + pop: 1 like-escape-character-any: - match: (\')([^'])(\') @@ -154,9 +154,9 @@ contexts: 1: punctuation.definition.string.begin.sql 2: constant.character.escape.sql 3: punctuation.definition.string.end.sql - pop: true + pop: 1 - match: (?=\S) - pop: true + pop: 1 like-escape-character-caret: - match: (\')(\^)(\') @@ -165,7 +165,7 @@ contexts: 1: punctuation.definition.string.begin.sql 2: constant.character.escape.sql 3: punctuation.definition.string.end.sql - pop: true + pop: 1 - match: (?=\S) fail: like-strings-branch @@ -176,7 +176,7 @@ contexts: 1: punctuation.definition.string.begin.sql 2: constant.character.escape.sql 3: punctuation.definition.string.end.sql - pop: true + pop: 1 - match: (?=\S) fail: like-strings-branch @@ -332,7 +332,7 @@ contexts: ddl-create-target-expect-as: - match: (?i:\bas\b) scope: keyword.context.block.sql - pop: true + pop: 1 - match: \b(?i:returns)\b scope: keyword.other.tsql - include: pop-on-top-level-reserved-word @@ -364,18 +364,18 @@ contexts: label-name: - meta_content_scope: meta.label-name.sql - match: '' - pop: true + pop: 1 cursor-name: - meta_content_scope: meta.cursor-name.sql - match: '' - pop: true + pop: 1 after-declare: - match: (?=\w+\s+(?i:cursor)\b) set: [cursor-name, single-identifier] - match: (?=\S) - pop: true + pop: 1 set: - meta_prepend: true @@ -388,7 +388,7 @@ contexts: scope: keyword.operator.assignment.tsql - include: operators - match: (?=\S) - pop: true + pop: 1 maybe-table-alias: - meta_prepend: true @@ -442,7 +442,7 @@ contexts: - meta_scope: meta.group.sql - match: \) scope: punctuation.section.group.end.sql - pop: true + pop: 1 - match: \w+ scope: constant.language.with.tsql - match: ',' @@ -458,7 +458,7 @@ contexts: expressions-pop-at-comma: - match: (?=[,)]) - pop: true + pop: 1 - include: expressions maybe-identifier-accessor: @@ -474,13 +474,13 @@ contexts: scope: meta.group.sql punctuation.section.parens.begin.sql set: inside-cast-method-call - match: (?=\S) - pop: true + pop: 1 inside-cast-method-call: - meta_content_scope: meta.function-call.sql meta.group.sql - match: \) scope: meta.function-call.sql meta.group.sql punctuation.section.parens.end.sql - pop: true + pop: 1 - match: \b(?i:as)\b scope: keyword.operator.assignment.tsql - include: expressions-or-column-name @@ -488,9 +488,9 @@ contexts: collation: - match: \w+ scope: support.constant.tsql - pop: true + pop: 1 - match: (?=\S) - pop: true + pop: 1 joins: - meta_append: true @@ -515,7 +515,7 @@ contexts: - include: pop-on-top-level-reserved-word - include: expressions - match: (?=\S) - pop: true + pop: 1 expect-procedure-name: - match: '' @@ -526,7 +526,7 @@ contexts: scope: punctuation.section.group.begin.tsql set: [cte-as, ddl-table-creation-columns] - match: (?=\S) - pop: true + pop: 1 cte-as: - match: (?i:\bas\b) @@ -540,7 +540,7 @@ contexts: cte-table-name: - meta_content_scope: meta.cte-table-name.sql - match: '' - pop: true + pop: 1 for-xml: - match: \b(?i:raw|auto|elements|root|path)\b @@ -548,10 +548,10 @@ contexts: - match: \b(?:XSINIL|XMLSCHEMA)\b # case sensitive?! TODO: need to check scope: keyword.other.tsql - match: (?=\)) - pop: true + pop: 1 - include: expressions - match: (?=\S) - pop: true + pop: 1 inside-openrowset-call: - meta_content_scope: meta.group.sql @@ -588,7 +588,7 @@ contexts: computed-column-definition: - meta_content_scope: meta.computed-column-definition.tsql - match: (?=,) - pop: true + pop: 1 - include: expressions-or-column-name raiserror-args: @@ -602,7 +602,7 @@ contexts: - match: \b(?i:nowait|log|seterror)\b scope: keyword.other.tsql - match: (?=\S) - pop: true + pop: 1 cursor-declaration: - meta_content_scope: meta.cursor-declaration.tsql @@ -612,7 +612,7 @@ contexts: scope: keyword.other.tsql set: expect-cursor-select-statement - match: (?=\S) - pop: true + pop: 1 expect-cursor-select-statement: - meta_content_scope: meta.cursor-declaration.tsql @@ -620,7 +620,7 @@ contexts: scope: keyword.other.DML.sql set: after-cursor-select-statement - match: (?=\S) - pop: true + pop: 1 after-cursor-select-statement: - meta_content_scope: meta.cursor-declaration.tsql @@ -628,7 +628,7 @@ contexts: scope: keyword.other.tsql set: after-cursor-select-statement-for - match: (?=\b(?i:open)\b) - pop: true + pop: 1 - include: main #- include: pop-on-top-level-reserved-word #- include: expressions-or-column-name @@ -637,6 +637,6 @@ contexts: - meta_scope: meta.cursor-declaration.tsql - match: (?i)\b(?:READ\s+ONLY|UPDATE(?:\s+OF)?)\b scope: storage.modifier.tsql - pop: true + pop: 1 - match: (?=\S) - pop: true + pop: 1 From 3ee68e043d5e57cc5130d63d4a98b0e68fc448fa Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 3 Oct 2021 21:25:57 +0300 Subject: [PATCH 028/250] [SQL] fix CTEs with no explicit column definition in TSQL --- SQL/TSQL.sublime-syntax | 2 +- SQL/syntax_test_tsql.sql | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index bc6c9a2c94..86ca451192 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -526,7 +526,7 @@ contexts: scope: punctuation.section.group.begin.tsql set: [cte-as, ddl-table-creation-columns] - match: (?=\S) - pop: 1 + set: cte-as cte-as: - match: (?i:\bas\b) diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 5ec08f3430..767379b10f 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -770,6 +770,47 @@ SELECT cte_table.* FROM cte_table -- ^^^^ keyword.other.DML -- ^^^^^^^^^ meta.table-name +;WITH A AS + ( + SELECT + Foo.ID AS [FooID], + Character, + Universe, + COUNT(Bar.*) AS BarCount + FROM + Foo + LEFT JOIN Bar B WITH (NOLOCK) ON B.Something = 1 AND B.Example = Foo.Example AND B.[When] >= @intervalDate_Start AND B.[When] < @intervalDate_End + WHERE + @intervalDate_Start <= Foo.CreationTime AND Foo.CreationTime < @intervalDate_End + GROUP BY + ISNULL(Foo.Example, Foo.ID) + ), + B AS +-- ^ meta.cte-table-name +-- ^^ keyword.operator.assignment.cte + ( + SELECT +-- ^^^^^^ meta.group keyword.other.DML + FooID, + CASE WHEN Character = 'Zoidberg' + THEN + CASE WHEN SUBSTRING(Universe, 1, 3) IN ('140', '170','290','235') + THEN 'Futurama' + ELSE 'Pasturama' + END + ELSE Universe + END AS Universe, + BarCount + FROM + A a + ) + SELECT + * + FROM + B + ORDER BY Universe DESC + + CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)) -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other From 9e5bc1edc1fdec872c715c27d046de17efc066ce Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 3 Oct 2021 21:31:21 +0300 Subject: [PATCH 029/250] [SQL] improve TSQL OPENXML scoping --- SQL/TSQL.sublime-syntax | 7 ++++++- SQL/syntax_test_tsql.sql | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 86ca451192..8425c0eadb 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -502,7 +502,7 @@ contexts: - meta_prepend: true - match: \b(?i:OPENXML)\b scope: meta.table-valued-function-name.sql support.function.tsql - push: begin-method-call-paren + push: [with-column-definition, begin-method-call-paren] - match: \b(?i:(OPENROWSET))\b\s*(\() scope: meta.function-call.tsql captures: @@ -640,3 +640,8 @@ contexts: pop: 1 - match: (?=\S) pop: 1 + + with-column-definition: + - match: \b(?i:with)\b + scope: keyword.other.tsql + set: ddl-table-creation-columns diff --git a/SQL/syntax_test_tsql.sql b/SQL/syntax_test_tsql.sql index 767379b10f..fd1a78058c 100644 --- a/SQL/syntax_test_tsql.sql +++ b/SQL/syntax_test_tsql.sql @@ -1288,9 +1288,23 @@ FROM OPENXML (@XmlDocumentHandle, '/ROOT/Customer',2) -- TODO: apply xpath -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.parens.begin -- ^^^^^^^^^^^^^^^^^^ variable.other.readwrite - WITH (CustomerID varchar(10), -- TODO: scope correctly https://docs.microsoft.com/en-us/sql/t-sql/functions/openxml-transact-sql?view=sql-server-ver15 + WITH (CustomerID varchar(10), +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^ storage.type +-- ^ punctuation.separator.sequence ContactName varchar(20)) +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ - meta.group +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^ storage.type +-- ^ punctuation.section.group.end EXEC sp_xml_removedocument @XmlDocumentHandle +-- <- keyword.control.flow +-- ^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name +-- ^ variable.other.readwrite punctuation.definition.variable --Create an internal representation of the XML document. EXEC sp_xml_preparedocument @idoc OUTPUT, @doc; @@ -1301,8 +1315,17 @@ FROM OPENXML (@idoc, '/ROOT/Customer/Order/OrderDetail',2) WITH (OrderID int '../@OrderID', CustomerID varchar(10) '../@CustomerID', OrderDate datetime '../@OrderDate', +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^^^^^^^^^ meta.column-name +-- ^^^^^^^^ storage.type +-- ^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ punctuation.definition.string.end +-- ^ punctuation.separator.sequence ProdID int '@ProductID', Qty int '@Quantity'); +-- ^ meta.group.table-columns punctuation.section.group.end +-- ^ punctuation.terminator.statement - meta.group ----- SELECT * FROM table_name AS t1 From 09f5a6e904e75e5a41c38b2e453ca03b5e4defba Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 3 Oct 2021 21:39:40 +0300 Subject: [PATCH 030/250] [SQL] support ALGORITHM=... in MySQL when creating views --- SQL/MySQL.sublime-syntax | 12 ++++++++++++ SQL/syntax_test_mysql.sql | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index e08a99becd..b85cb16ad4 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -139,6 +139,11 @@ contexts: push: [table-name, single-identifier-after-whitespace] - match: (?i)\b(?:using)\b scope: keyword.other.mysql + - match: \b((?i:algorithm))\s*(=) + captures: + 1: keyword.other.mysql + 2: keyword.operator.assignment.mysql + push: ddl-target-algorithm - match: (?=\() pop: 1 @@ -177,3 +182,10 @@ contexts: scope: keyword.other.mysql - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) scope: keyword.other.object-comments.sql + + ddl-target-algorithm: + - match: \b(?i:MERGE|TEMPTABLE|UNDEFINED)\b + scope: keyword.other.mysql + pop: true + - match: (?=\S) + pop: true diff --git a/SQL/syntax_test_mysql.sql b/SQL/syntax_test_mysql.sql index db6dd477b8..bd1ce67b8a 100644 --- a/SQL/syntax_test_mysql.sql +++ b/SQL/syntax_test_mysql.sql @@ -251,3 +251,32 @@ CREATE INDEX IX_some_index ON dbo.some_table( -- ^^^^^^^^^^^ meta.group meta.column-name -- ^^^ meta.group keyword.other.order ) + +CREATE ALGORITHM=MERGE VIEW contactPersons( +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^ keyword.other +-- ^ keyword.operator.assignment +-- ^^^^^ keyword.other +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^ meta.group punctuation.section.group.begin + customerName, +-- ^^^^^^^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.separator.sequence + firstName, + lastName, + phone +) AS +-- <- meta.group punctuation.section.group.end +-- ^ keyword.operator.assignment.alias - meta.group +SELECT +-- ^^^ keyword.other.DML + customerName, + contactFirstName, + contactLastName, + phone +FROM customers; +-- ^ keyword.other.DML +-- ^^^^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement From 841225c6b4332cbcedff3e6e8cbe5e0108fb4175 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 3 Oct 2021 22:19:11 +0300 Subject: [PATCH 031/250] [SQL] initial Postgres support --- SQL/PostgresSQL.sublime-syntax | 49 +++++++++ SQL/syntax_test_postgres.sql | 191 +++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 SQL/PostgresSQL.sublime-syntax create mode 100644 SQL/syntax_test_postgres.sql diff --git a/SQL/PostgresSQL.sublime-syntax b/SQL/PostgresSQL.sublime-syntax new file mode 100644 index 0000000000..7483a74f05 --- /dev/null +++ b/SQL/PostgresSQL.sublime-syntax @@ -0,0 +1,49 @@ +%YAML 1.2 +--- +name: PostgresSQL +scope: source.sql.postgresql +version: 2 +extends: Packages/SQL/MySQL.sublime-syntax + +variables: + simple_types: |- + (?xi: + \b + (?:smallint|integer|bigint|real|double\s+precision|smallserial|serial|bigserial| + money| + bytea| + times?|timestamp(?:s|tz)?|date|interval| + int4range|int8range|numrange|tsrange|tstzrange|daterange| + boolean| + point|line|lseg|box|path|polygon|circle| + cidr|inet|macaddr|macaddr8| + tsvector|tsquery| + uuid| + xml|jsonb?|text) + \b + ) + types_with_optional_number: |- + (?xi: + \b + (?:decimal|numeric| + character\s+varying|varchar|character|char| + bit|bit\s+varying) + \b + ) + +contexts: + types: + - meta_append: true + - match: '::' + scope: keyword.operator.cast.postgresql + + expressions: + - meta_prepend: true + - match: \b(?i:ARRAY)\b + scope: keyword.declaration.postgresql + - match: \[ + scope: punctuation.section.brackets.begin.postgresql + - match: \] + scope: punctuation.section.brackets.end.postgresql + - match: ':(?!:)' + scope: keyword.operator.range.postgresql diff --git a/SQL/syntax_test_postgres.sql b/SQL/syntax_test_postgres.sql new file mode 100644 index 0000000000..7c7bc5281c --- /dev/null +++ b/SQL/syntax_test_postgres.sql @@ -0,0 +1,191 @@ +-- SYNTAX TEST "Packages/SQL/PostgresSQL.sublime-syntax" + +CREATE TABLE test1 (a character(4)); +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^^^^^^^ keyword.other.ddl +-- ^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ punctuation.terminator.statement +-- ^ punctuation.section.group.begin +-- ^ meta.column-name +-- ^^^^^^^^^^^^ storage.type +-- ^ constant.numeric +-- ^ punctuation.section.group.end + +INSERT INTO test1 VALUES ('ok'); +SELECT a, char_length(a) FROM test1; +-- ^^^ keyword.other.DML +-- ^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^ meta.function-call +-- ^^^^^^^^^^^ support.function +-- ^ meta.group punctuation.section.parens.begin +-- ^ meta.group meta.column-name +-- ^ meta.group punctuation.section.parens.end +-- ^^^^ keyword.other.DML - meta.group +-- ^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +CREATE TABLE test2 (b varchar(5)); +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^^^^^^^ keyword.other.ddl +-- ^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ punctuation.terminator.statement +-- ^ punctuation.section.group.begin +-- ^ meta.column-name +-- ^^^^^^^^^^ storage.type +-- ^ constant.numeric +-- ^ punctuation.section.group.end +INSERT INTO test2 VALUES ('ok'); +INSERT INTO test2 VALUES ('good '); +INSERT INTO test2 VALUES ('too long'); +#ERROR: value too long for type character varying(5) +INSERT INTO test2 VALUES ('too long'::varchar(5)); -- explicit truncation +-- ^^^^^^^^^^ string.quoted.single +-- ^^ keyword.operator.cast +-- ^^^^^^^^^^ storage.type +SELECT b, char_length(b) FROM test2; + +CREATE TABLE IF NOT EXISTS public.dropzone_details +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^^^^^^^ keyword.other.ddl +-- ^^ keyword.control.flow +-- ^^^ keyword.operator.logical +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^ punctuation.accessor.dot +( +-- <- meta.create meta.group.table-columns punctuation.section.group.begin + id uuid NOT NULL DEFAULT uuid_generate_v4(), +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^ meta.column-name +-- ^^^^ storage.type +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^ meta.function-call support.function +-- ^ meta.function-call meta.group punctuation.section.parens.begin +-- ^ meta.function-call meta.group punctuation.section.parens.end +-- ^ punctuation.separator.sequence + name text COLLATE pg_catalog."default", + doc jsonb, +-- ^^^ meta.column-name +-- ^^^^^ storage.type +-- ^ punctuation.separator.sequence + poc json, +-- ^^^ meta.column-name +-- ^^^^ storage.type +-- ^ punctuation.separator.sequence + size integer, +-- ^^^^ meta.column-name +-- ^^^^^^^ storage.type +-- ^ punctuation.separator.sequence + CONSTRAINT id_name_uix UNIQUE (id, name) +-- ^^^^^^^^^^ storage.modifier +) + +SELECT '\xDEADBEEF'; +SET bytea_output = 'escape'; + +SELECT 'abc \153\154\155 \052\251\124'::bytea; +-- ^^ keyword.operator.cast +-- ^^^^^ storage.type +-- ^ punctuation.terminator.statement + +CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); +-- ^^^ meta.create keyword.other.ddl +-- ^^^^ meta.create keyword.other +-- ^^^^ meta.create meta.toc-list.full-identifier entity.name.function +-- ^^ keyword.operator.assignment.alias +CREATE TABLE person ( + name text, + current_mood mood -- TODO: scope custom types +); +INSERT INTO person VALUES ('Moe', 'happy'); +SELECT * FROM person WHERE current_mood = 'happy'; + +CREATE TABLE test (a BIT(3), b BIT VARYING(5)); +INSERT INTO test VALUES (B'101', B'00'); +INSERT INTO test VALUES (B'10', B'101'); +INSERT INTO test VALUES (B'10'::bit(3), B'101'); + +CREATE TABLE sal_emp ( + name text, + pay_by_quarter integer[], +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^^^^ meta.column-name +-- ^^^^^^^ storage.type +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +-- ^ punctuation.separator.sequence - storage + schedule text[][] +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^ meta.column-name +-- ^^^^ storage.type +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +); + +INSERT INTO sal_emp + VALUES ('Bill', + '{10000, 10000, 10000, 10000}', + '{{"meeting", "lunch"}, {"training", "presentation"}}'); + +INSERT INTO sal_emp + VALUES ('Carol', + '{20000, 25000, 25000, 25000}', + '{{"breakfast", "consulting"}, {"meeting", "lunch"}}'); + +INSERT INTO sal_emp + VALUES ('Bill', + ARRAY[10000, 10000, 10000, 10000], +-- ^^^^^ keyword.declaration +-- ^ punctuation.section.brackets.begin +-- ^^^^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.separator.sequence +-- ^ punctuation.section.brackets.end +-- ^ punctuation.separator.sequence + ARRAY[['meeting', 'lunch'], ['training', 'presentation']]); +-- ^^^^^ keyword.declaration +-- ^^ punctuation.section.brackets.begin +-- ^^^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence - string + +INSERT INTO sal_emp + VALUES ('Carol', + ARRAY[20000, 25000, 25000, 25000], + ARRAY[['breakfast', 'consulting'], ['meeting', 'lunch']]); + +SELECT name FROM sal_emp WHERE pay_by_quarter[1] <> pay_by_quarter[2]; +-- ^^^ keyword.other.DML +-- ^^^^ meta.column-name +-- ^^^^ keyword.other.DML +-- ^^^^^^^ meta.table-name +-- ^^^^^ keyword.other.DML +-- ^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.brackets.begin +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.brackets.end +-- ^^ keyword.operator.comparison +-- ^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.brackets.begin +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.brackets.end +-- ^ punctuation.terminator.statement + +SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; +-- ^^^ keyword.other.DML +-- ^^^^^^^^ meta.column-name +-- ^ punctuation.section.brackets.begin +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ keyword.operator.range +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.brackets.end +-- ^ punctuation.section.brackets.begin +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.brackets.end +-- ^^^^ keyword.other.DML +-- ^^^^^^^ meta.table-name From 666c89ecd79e3a189268ef1e5a24be18be12796f Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 3 Oct 2021 22:50:51 +0300 Subject: [PATCH 032/250] [SQL] initial support for Apache Cassandra --- SQL/Cassandra.sublime-syntax | 69 +++++++++++++ SQL/SQL (basic).sublime-syntax | 5 +- SQL/syntax_test_cassandra.cql | 171 +++++++++++++++++++++++++++++++++ 3 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 SQL/Cassandra.sublime-syntax create mode 100644 SQL/syntax_test_cassandra.cql diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax new file mode 100644 index 0000000000..f35873adbe --- /dev/null +++ b/SQL/Cassandra.sublime-syntax @@ -0,0 +1,69 @@ +%YAML 1.2 +--- +name: CQL +file_extensions: + - cql +scope: source.sql.cql +version: 2 +extends: Packages/SQL/SQL (basic).sublime-syntax + +variables: + simple_types: |- + (?ix:\b(?: + (ASCII|BIGINT|BLOB|BOOLEAN|COUNTER|DATE| + DECIMAL|DOUBLE|DURATION|FLOAT|INET|INT| + SMALLINT|TEXT|TIME|TIMESTAMP|TIMEUUID|TINYINT| + UUID|VARCHAR|VARINT) + )\b) + types_with_optional_number: (?!) + +contexts: + expressions: + - meta_append: true + - match: \h{8}(?:-\h{4}){3}-\h{12} + scope: constant.numeric.uuid.cql + - match: (:)\w+ + scope: variable.other.constant.cql + captures: + 1: punctuation.definition.variable.cql + - match: \b(?i:limit)\b + scope: keyword.other.dml.cql + - match: \{ + scope: punctuation.section.braces.begin.cql + push: inside-dict + - match: \b(?i:with)\b + scope: keyword.other.cql + + dml-statements: + - meta_append: true + - match: \b(?i:allow filtering)\b + scope: keyword.other.dml.cql + + types: + - meta_prepend: true + - match: \b(?i:set|frozen|map|tuple)(<) + scope: storage.type.cql + captures: + 1: punctuation.definition.generic.begin.cql + push: generic-type + + generic-type: + - include: types + - match: \> + scope: storage.type.cql punctuation.definition.generic.end.cql + pop: 1 + + ddl-target: + - meta_prepend: true + - match: \b(?i:keyspace)\b + scope: keyword.other.cql + - match: \b(?i:materialized)\b + scope: keyword.other.cql + + inside-dict: + - match: \} + scope: punctuation.section.braces.end.cql + pop: 1 + - match: ':' + scope: punctuation.separator.mapping.key-value.cql + - include: expressions diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 26e25a60c9..6bcbe43448 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -325,10 +325,11 @@ contexts: ddl-target: - match: |- (?xi) - aggregate|conversion|database|domain|function|group| + \b + (?:aggregate|conversion|database|domain|function|group| (?:(?:fulltext|spatial|unique)\s+)?index| language|operator class|operator|procedure|rule| - schema|sequence|table(?:space)?|trigger|type|user|view + schema|sequence|table(?:space)?|trigger|type|user|view)\b scope: keyword.other.sql - match: (?=\S) pop: 1 diff --git a/SQL/syntax_test_cassandra.cql b/SQL/syntax_test_cassandra.cql new file mode 100644 index 0000000000..b58d5f46fb --- /dev/null +++ b/SQL/syntax_test_cassandra.cql @@ -0,0 +1,171 @@ +-- SYNTAX TEST "Packages/SQL/Cassandra.sublime-syntax" + +CREATE KEYSPACE killrvideo WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1}; +--^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +--^^^^ keyword.other.ddl +-- ^^^^^^^^ keyword.other +-- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^ keyword.other +-- ^ keyword.operator +-- ^ punctuation.section.braces.begin +-- ^^^^^^^ string.quoted.single +-- ^ punctuation.separator.mapping.key-value +-- ^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.separator.mapping.key-value +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.braces.end +-- ^ punctuation.terminator.statement + +select someid, token(someid), something +--^^^^ keyword.other.DML +-- ^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^ meta.function-call support.function +-- ^ meta.function-call meta.group punctuation.section.parens.begin +-- ^^^^^^ meta.function-call meta.group meta.column-name +-- ^ meta.function-call meta.group punctuation.section.parens.end +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ meta.column-name +from something_by_someid +--^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^ meta.table-name +where token(someid) >= token(d821d7d8-8265-402e-9a72-c61ab8473ab6) +--^^^ keyword.other.DML +-- ^^^^^^^^^^^^^ meta.function-call +-- ^^^^^ support.function +-- ^^^^^^^^ meta.group +-- ^ punctuation.section.parens.begin +-- ^^^^^^ meta.column-name +-- ^ punctuation.section.parens.end +-- ^^ keyword.operator.comparison +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^^^^^ support.function +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.parens.begin +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.uuid +-- ^ punctuation.section.parens.end +-- ^ - meta +and token(someid) <= token(cf0acefc-ccff-42a0-8753-65d82e9c9b0f) +limit 2000; +-- <- keyword.other.dml +--^^^ keyword.other.dml +-- ^^^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.terminator.statement + +select count(someid) +from something_by_someid +where something = 'abc' +-- ^^ keyword.other.DML +-- ^^^^^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^^^^^ string.quoted.single +limit 2000 +allow filtering; +-- ^^^^^^^^^^^^ keyword.other.dml +-- ^ punctuation.terminator.statement + +insert into something_by_countrycode (someid, countrycode) values (:someid, :countrycode); +-- ^^^^^^^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^^^^^ keyword.other.DML.II +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^ variable.other.constant +-- ^ punctuation.separator.sequence +-- ^ punctuation.definition.variable +-- ^^^^^^^^^^^ variable.other.constant +-- ^ punctuation.terminator.statement + +CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^^^^^^^ keyword.other.ddl +-- ^^ keyword.control.flow +-- ^^^ keyword.operator.logical +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^ meta.group.table-columns punctuation.section.group.begin + userid uuid, +-- ^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^ meta.column-name +-- ^^^^ storage.type +-- ^ punctuation.separator.sequence + permissions frozen>, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^^^^^^^ storage.type +-- ^ punctuation.definition.generic.begin +-- ^ punctuation.definition.generic.begin +-- ^^ punctuation.definition.generic.end +-- ^ punctuation.separator.sequence + PRIMARY KEY(userid) +-- ^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^ storage.modifier +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.section.group.end +); +-- <- meta.create meta.group.table-columns punctuation.section.group.end + +CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( + userid uuid, + other_id uuid, + test text, + PRIMARY KEY(userid, other_id) +); +CREATE TABLE IF NOT EXISTS date_by_userid ( + userid uuid PRIMARY KEY, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^ meta.column-name +-- ^^^^ storage.type +-- ^^^^^^^^^^^ storage.modifier +-- ^ punctuation.separator.sequence + date timestamp -- TODO: scope date as a column name +-- ^^^^^^^^^ storage.type +); + + +DROP TABLE IF EXISTS userpermissions_by_userid; +--^^^^^^^^^^^^^^^^^^^ meta.drop +--^^^^^^^^ keyword.other.ddl +-- ^^ keyword.control.flow +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +--^^^^ keyword.other.ddl +-- ^^^^^^^^^^^^ keyword.other +-- ^^^^ keyword.other +-- ^^ keyword.control.flow +-- ^^^ keyword.operator.logical +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^ keyword.operator.assignment.alias + SELECT * +-- ^^^^^^ keyword.other.DML +-- ^ variable.language.wildcard.asterisk + FROM foo + WHERE bar IS NOT NULL + PRIMARY KEY (foo_id, bar_id) -- TODO: scope correctly + WITH comment = 'allow querying by relationship more easily'; +-- ^^^^ keyword.other + +CREATE TYPE user_defined_type ( +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +--^^^^ keyword.other.ddl +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^ meta.group punctuation.section.group.begin + type1 timestamp, + type2 text, + type3 text, + type4 text); From 2227515c1c6bf593633cdb8695953c02dcfa6559 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 4 Oct 2021 21:31:53 +0300 Subject: [PATCH 033/250] [SQL] reorganize syntax tests into subfolders --- SQL/Indentation Rules.tmPreferences | 20 +++++- .../syntax_test_indentation_tsql.sql | 65 +++++++++++++++++++ .../syntax}/syntax_test_cassandra.cql | 0 SQL/{ => tests/syntax}/syntax_test_mysql.sql | 0 .../syntax}/syntax_test_postgres.sql | 0 SQL/{ => tests/syntax}/syntax_test_tsql.sql | 0 6 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 SQL/tests/indentation/syntax_test_indentation_tsql.sql rename SQL/{ => tests/syntax}/syntax_test_cassandra.cql (100%) rename SQL/{ => tests/syntax}/syntax_test_mysql.sql (100%) rename SQL/{ => tests/syntax}/syntax_test_postgres.sql (100%) rename SQL/{ => tests/syntax}/syntax_test_tsql.sql (100%) diff --git a/SQL/Indentation Rules.tmPreferences b/SQL/Indentation Rules.tmPreferences index 8bc06e9e1e..941f81f112 100644 --- a/SQL/Indentation Rules.tmPreferences +++ b/SQL/Indentation Rules.tmPreferences @@ -2,13 +2,27 @@ scope - source.sql + source.sql - string - comment settings decreaseIndentPattern - \)(?!=.*\() + (?xi) + \)(?!=.*\() + |^\s*end\b + increaseIndentPattern - ^\s*(create|grant|insert|delete|update)\b|\((?!.*\)) + (?xi) + ^\s* + (?: + (?:create|grant|delete|update|begin)\b + #| select\s*$ + ) + |\((?!.*\)) + + unIndentedLinePattern + (?xi) + ^go$ + diff --git a/SQL/tests/indentation/syntax_test_indentation_tsql.sql b/SQL/tests/indentation/syntax_test_indentation_tsql.sql new file mode 100644 index 0000000000..39629fd155 --- /dev/null +++ b/SQL/tests/indentation/syntax_test_indentation_tsql.sql @@ -0,0 +1,65 @@ +-- SYNTAX TEST reindent "Packages/SQL/TSQL.sublime-syntax" +SELECT * +FROM ( + SELECT * + FROM a + INNER JOIN b ON a.ID = b.ID +) alias +WHERE 1 = 1 +GO + +BEGIN + INSERT INTO a + VALUES (123, 456) +END + +BEGIN + INSERT INTO a + VALUES (123, 456) +GO + INSERT INTO b + VALUES (123, 456) +END + +SELECT +a, +b, +c +FROM foo + +SELECT a +,b +,c +FROM foo + +CREATE TABLE hello ( + -- @@@@@ definition + field1 int, + field2 nvarchar(50) +) + +CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( + -- @@@@@@@@@@@@@ definition + some_column ASC +) + +SET @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) +-- @@@@@@@ reference +-- @@@@@@@ reference + +BEGIN RAISERROR ('File "%s" does not exist', 16, -1, @FromFile) + -- @@@@@@@@@ reference +END + +SELECT COALESCE(a.field1, b.field2, c.field1) AS Blah, ISNULL(d.field1, 'default') as field1 +-- @@@@@@@@ reference +-- @@@@@@ reference + +'no indentation increase when an unclosed open paren is in a string(' +BEGIN + 'no indentation decrease when a close paren with no matching open paren on the same line is in a string)' + null + -- no indentation increase when an unclosed open paren is in a comment ( + --no indentation decrease when a close paren with no matching open paren on the same line is in a comment ) + null +END diff --git a/SQL/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql similarity index 100% rename from SQL/syntax_test_cassandra.cql rename to SQL/tests/syntax/syntax_test_cassandra.cql diff --git a/SQL/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql similarity index 100% rename from SQL/syntax_test_mysql.sql rename to SQL/tests/syntax/syntax_test_mysql.sql diff --git a/SQL/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.sql similarity index 100% rename from SQL/syntax_test_postgres.sql rename to SQL/tests/syntax/syntax_test_postgres.sql diff --git a/SQL/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql similarity index 100% rename from SQL/syntax_test_tsql.sql rename to SQL/tests/syntax/syntax_test_tsql.sql From daca95f8001e27db2aa6cfd9a282c41f3426fb2f Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 4 Oct 2021 21:35:26 +0300 Subject: [PATCH 034/250] [SQL] fix pesky preserveIndent on comments preventing indentation tests from passing --- SQL/Indentation Rules - Comments.tmPreferences | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 SQL/Indentation Rules - Comments.tmPreferences diff --git a/SQL/Indentation Rules - Comments.tmPreferences b/SQL/Indentation Rules - Comments.tmPreferences new file mode 100644 index 0000000000..a002e36995 --- /dev/null +++ b/SQL/Indentation Rules - Comments.tmPreferences @@ -0,0 +1,13 @@ + + + + + scope + source.sql comment + settings + + preserveIndent + + + + From 25369466b46911c610ccf9a8787489374dae2479 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Thu, 7 Oct 2021 23:54:13 +0300 Subject: [PATCH 035/250] [SQL] improve Cassandra syntax test coverage slightly --- SQL/Cassandra.sublime-syntax | 23 ++++- SQL/SQL (basic).sublime-syntax | 1 - SQL/tests/syntax/syntax_test_cassandra.cql | 99 +++++++++++++++++++++- 3 files changed, 118 insertions(+), 5 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index f35873adbe..080ffbf00d 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -16,6 +16,7 @@ variables: UUID|VARCHAR|VARINT) )\b) types_with_optional_number: (?!) + #reserved: (?:;) contexts: expressions: @@ -30,8 +31,12 @@ contexts: scope: keyword.other.dml.cql - match: \{ scope: punctuation.section.braces.begin.cql - push: inside-dict - - match: \b(?i:with)\b + push: inside-dict-or-set + - match: \b((?i:with))\s+(\w+)? + captures: + 1: keyword.other.cql + 2: string.unquoted.cql + - match: \b(?i:primary\s+key)\b scope: keyword.other.cql dml-statements: @@ -60,10 +65,22 @@ contexts: - match: \b(?i:materialized)\b scope: keyword.other.cql - inside-dict: + inside-dict-or-set: - match: \} scope: punctuation.section.braces.end.cql pop: 1 - match: ':' scope: punctuation.separator.mapping.key-value.cql - include: expressions + - match: \w+ + scope: meta.mapping.key.cql string.unquoted.cql + + ddl-create-target: + - meta_prepend: true + - match: \b(?i:with)\b + scope: keyword.other.cql + - match: \b(?i:clustering)\b + scope: keyword.other.cql + + ddl-alter-common: + - meta_prepend: false diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 6bcbe43448..d179f7a4b1 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -342,7 +342,6 @@ contexts: ddl-alter-table: - meta_scope: meta.alter.sql - - match: \s+ - match: \b(?i:add(?:\s+column)?|alter\s+column)\b scope: keyword.other.ddl.sql - include: ddl-alter-common diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index b58d5f46fb..2ed02600c8 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -120,6 +120,19 @@ CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( test text, PRIMARY KEY(userid, other_id) ); +CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( + userid uuid, + other_id uuid, + test text, + PRIMARY KEY ((userid), other_id) +); +CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( + userid uuid, + other_id uuid, + test int, + PRIMARY KEY ((userid, other_id), test) +); + CREATE TABLE IF NOT EXISTS date_by_userid ( userid uuid PRIMARY KEY, -- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns @@ -155,9 +168,20 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS -- ^ variable.language.wildcard.asterisk FROM foo WHERE bar IS NOT NULL - PRIMARY KEY (foo_id, bar_id) -- TODO: scope correctly + PRIMARY KEY (foo_id, bar_id) +-- ^^^^^^^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^ meta.column-name +-- ^ punctuation.section.group.end WITH comment = 'allow querying by relationship more easily'; -- ^^^^ keyword.other +-- ^^^^^^^ string.unquoted +-- ^ keyword.operator +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.terminator.statement CREATE TYPE user_defined_type ( --^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create @@ -169,3 +193,76 @@ CREATE TYPE user_defined_type ( type2 text, type3 text, type4 text); + + +INSERT INTO something_by_someid (someid, somebool, somemap) +VALUES ( + 583395ca-0845-4517-b0f7-97bb0ea86b53, + false, + {77a969b4-378a-4fb0-b531-83404ee3c395:{id:22f7244c-c6d7-4bd7-aeac-a886c4242cd8,sometext:'text here',empty:{}}} + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.uuid + -- ^ punctuation.separator.mapping.key-value + -- ^ punctuation.section.braces.begin + -- ^^ meta.mapping.key string.unquoted + -- ^ punctuation.separator.mapping.key-value + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.uuid + -- ^ punctuation.separator.sequence + -- ^^^^^^^^ meta.mapping.key string.unquoted + -- ^ punctuation.separator.mapping.key-value + -- ^^^^^^^^^^^ string.quoted.single + -- ^ punctuation.separator.sequence + -- ^^^^^ meta.mapping.key string.unquoted + -- ^ punctuation.separator.mapping.key-value + -- ^ punctuation.section.braces.begin + -- ^^^ punctuation.section.braces.end +); + +INSERT INTO something_by_someid (someid, someset) +VALUES (22f7244c-c6d7-4bd7-aeac-a886c4242cd8,{'item1','item2','item3'}); +-- ^ punctuation.section.braces.begin +-- ^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence +-- ^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence +-- ^^^^^^^ string.quoted.single +-- ^ punctuation.section.braces.end +-- ^ meta.group punctuation.section.group.end +-- ^ punctuation.terminator.statement + +CREATE TABLE IF NOT EXISTS someentity_by_somefield ( + entityid uuid, + datecreated timestamp, + somefield int, + anotherfield text +PRIMARY KEY (entityid, datecreated, somefield) +) WITH CLUSTERING ORDER BY (datecreated DESC, somefield ASC); +--^^^^^^^^^^^^^^^^ meta.create +-- ^^^ keyword.other +-- ^^^^^^^^^^ keyword.other +-- ^^^^^^^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^ keyword.other.order +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^ meta.column-name +-- ^^^ keyword.other.order +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement + +ALTER TABLE someentity_by_somefield add usefulfield text; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter +-- ^^^^^^^^ keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^ storage.type +-- ^ punctuation.terminator.statement + +ALTER TABLE someentity_by_somefield + add usefulfield text; +-- ^^^^^^^^^^^^^^^^^^^^ meta.alter +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^ storage.type +-- ^ punctuation.terminator.statement From 91b2f891ebbc73f83cc833066f2ce49dc221d428 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 9 Oct 2021 22:43:50 +0300 Subject: [PATCH 036/250] [SQL] misc TSQL improvements --- SQL/SQL (basic).sublime-syntax | 16 +++++++ SQL/TSQL.sublime-syntax | 7 ++- SQL/tests/syntax/syntax_test_tsql.sql | 66 ++++++++++++++++++++++++--- 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index d179f7a4b1..8546703a3b 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -480,6 +480,11 @@ contexts: set: [after-table-alias, table-alias-name, single-identifier] after-table-alias: + - match: \b(?i:(TABLESAMPLE(?:\s+SYSTEM)?))\s*(\() + captures: + 1: keyword.other.tsql + 2: meta.group.tablesample.tsql punctuation.section.group.begin.tsql + push: tablesample - match: (?=\S) pop: 1 @@ -526,3 +531,14 @@ contexts: - include: wildcard-identifier - match: (?=\S) pop: 1 + + tablesample: + - meta_content_scope: meta.group.tablesample.sql + - match: \b(?i:rows|percent)\b + scope: constant.language.sql + - match: (\))(?:\s*((?i:repeatable))\b)? + captures: + 1: meta.group.tablesample.tsql punctuation.section.group.end.sql + 2: constant.language.sql + pop: true + - include: expressions diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 8425c0eadb..a52ce255f3 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -6,7 +6,7 @@ version: 2 extends: Packages/SQL/SQL (basic).sublime-syntax variables: - string_escape: (?:'') #(?:\\[tnr]) + string_escape: (?:'') simple_identifier: (?:(?:(?:##?)?|@)?\w+) # (one or two hashes OR an ampersand OR nothing) followed by a word additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec|go|bulk|insert|on|when)\b) enclosed_type_begin: (?:\[) @@ -239,7 +239,7 @@ contexts: scope: keyword.other.tsql - match: \b(?i:disk|tape|url)\b scope: keyword.other.tsql - - match: \b(?i:pivot|unpivot)\b + - match: \b(?i:pivot|unpivot|for)\b scope: keyword.other.tsql - match: \b(\w+)(:) captures: @@ -381,6 +381,9 @@ contexts: - meta_prepend: true - match: \b(?i:nocount|ansi_nulls|quoted_identifier)\b scope: constant.language.switch.tsql + - match: \b(?i:identity_insert)\b + scope: constant.language.switch.tsql + push: [table-name, single-identifier] - match: \b(?i:on|off)\b scope: constant.language.boolean.tsql - include: variables diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index fd1a78058c..07da330040 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -947,16 +947,32 @@ WITH (INDEX = [AK_Product_Name]) ON PR.ProductID = PP.ProductID -- TODO: scope i -- Pivot table with one row and five columns SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days, [0], [1], [2], [3], [4] +--^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^ meta.column-name FROM ( SELECT DaysToManufacture, StandardCost FROM Production.Product ) AS SourceTable PIVOT +--^^^ keyword.other ( AVG(StandardCost) - FOR DaysToManufacture IN ([0], [1], [2], [3], [4]) -- TODO: scope FOR correctly -) AS PivotTable; +--^^^^^^^^^^^^^^^^^ meta.function-call +--^^^ support.function.aggregate +-- ^ punctuation.section.parens.begin +-- ^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.parens.end + FOR DaysToManufacture IN ([0], [1], [2], [3], [4]) +--^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^ meta.column-name +-- ^^ keyword.operator.logical +-- ^ punctuation.section.group.begin +-- ^^^ meta.column-name +-- ^ punctuation.separator.sequence +) AS PivotTable; -- TODO: scope this correctly +--^^ keyword.operator.assignment.alias ------------ -- Create the table and insert values as portrayed in the previous example. CREATE TABLE pvt (VendorID INT, Emp1 INT, Emp2 INT, @@ -974,10 +990,19 @@ FROM (SELECT VendorID, Emp1, Emp2, Emp3, Emp4, Emp5 FROM pvt) p UNPIVOT - (Orders FOR Employee IN -- TODO: scope FOR correctly +-- <- keyword.other +--^^^^^ keyword.other + (Orders FOR Employee IN +-- ^^^^^^ meta.column-name +-- ^^^ keyword.other +-- ^^^^^^^^ meta.column-name +-- ^^ keyword.operator.logical (Emp1, Emp2, Emp3, Emp4, Emp5) -)AS unpvt; +) AS unpvt; -- TODO: scope this correctly +-- <- meta.group punctuation.section.group.end +--^^ keyword.operator.assignment.alias GO + ------------- CREATE TABLE dbo.T1 ( column_1 int IDENTITY, column_2 VARCHAR(30)); @@ -988,7 +1013,12 @@ INSERT T1 VALUES ('Row #1'); -- ^^^^^^ keyword.other.DML.II INSERT T1 (column_2) VALUES ('Row #2'); GO -SET IDENTITY_INSERT T1 ON; -- TODO: scope me correctly +SET IDENTITY_INSERT T1 ON; +-- <- keyword.other.DML +-- ^^^^^^^^^^^^^^^ constant.language.switch +-- ^^ meta.table-name +-- ^^ constant.language.boolean +-- ^ punctuation.terminator.statement GO INSERT INTO T1 (column_1,column_2) VALUES (-99, 'Explicit identity value'); @@ -1203,9 +1233,31 @@ SELECT p.BusinessEntityID , p.LastName , pp.PhoneNumber , dbo.some_func(p.BusinessEntityID) -- TODO: scope correctly -FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) -- TODO: scope correctly - LEFT OUTER JOIN Person.PersonPhone AS pp TABLESAMPLE (10 ROWS) +FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) +-- ^ meta.table-alias-name +-- ^^^^^^^^^^^ keyword.other +-- ^^^^^^^^^^^^ meta.group.tablesample +-- ^ punctuation.section.group.begin +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^^^^^^^ constant.language +-- ^ punctuation.section.group.end +-- ^^^^^^^^^^ constant.language +-- ^ meta.group punctuation.section.group.begin +-- ^^^ meta.group meta.number.integer.decimal constant.numeric.value +-- ^ meta.group punctuation.section.group.end + LEFT OUTER JOIN Person.PersonPhone AS pp TABLESAMPLE SYSTEM (10 ROWS) +-- ^^ meta.table-alias-name +-- ^^^^^^^^^^^^^^^^^^ keyword.other +-- ^^^^^^^^^ meta.group.tablesample +-- ^ punctuation.section.group.begin +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^^^^ constant.language +-- ^ punctuation.section.group.end ON pp.BusinessEntityID = p.BusinessEntityID +-- ^^ keyword.operator.join +-- ^^^^^^^^^^^^^^^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^^^^^^^^^^^^^^^^^^ meta.column-name ORDER BY p.BusinessEntityID DESC; -------- From 245c7481c5d12b4abbef5272a4ec8b5f9aa63f37 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 9 Oct 2021 23:10:33 +0300 Subject: [PATCH 037/250] [SQL] fix TSQL function calls where the function name is in square brackets --- SQL/TSQL.sublime-syntax | 16 ++++++++++++++ SQL/tests/syntax/syntax_test_tsql.sql | 31 ++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index a52ce255f3..9e49e38bcd 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -648,3 +648,19 @@ contexts: - match: \b(?i:with)\b scope: keyword.other.tsql set: ddl-table-creation-columns + + user-defined-function-calls: + - meta_append: true + - match: |- + (?x) + (?= + (?:(?:\b\w+|\[[^]]+\])\.)* + (?: \b\w+|\[[^]]+\]) + \s*\( + ) + push: [begin-method-call-paren, function-name, single-identifier] + + function-name: + - meta_content_scope: variable.function.tsql + - match: '' + pop: 1 diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 07da330040..fdce4563ca 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -941,6 +941,18 @@ FROM [Production].[ProductReview] PR WITH (INDEX = IX_ProductReview_ProductID_Name) -- TODO: scope index name correctly INNER JOIN [Production].[Product] PP WITH (INDEX = [AK_Product_Name]) ON PR.ProductID = PP.ProductID -- TODO: scope index name correctly + +SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name +FROM [Production].[ProductReview] PR +WITH (TABLOCK, INDEX(myindex, [anotherindex])) -- TODO: + +SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name +FROM [Production].[ProductReview] PR +WITH (TABLOCK, INDEX(1)) -- TODO: + +SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name +FROM [Production].[ProductReview] PR +WITH (FORCESEEK (MyIndex (col1, col2, col3)) -- TODO: ----------------- @@ -1232,7 +1244,14 @@ SELECT p.BusinessEntityID , p.MiddleName , p.LastName , pp.PhoneNumber , - dbo.some_func(p.BusinessEntityID) -- TODO: scope correctly + dbo.some_func(p.BusinessEntityID), +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^^^^^^^^^^^^^ variable.function +-- ^ punctuation.accessor.dot + [dbo].[some_func](p.BusinessEntityID) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call +-- ^^^^^^^^^^^^^^^^^ variable.function +-- ^ punctuation.accessor.dot FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) -- ^ meta.table-alias-name -- ^^^^^^^^^^^ keyword.other @@ -1494,3 +1513,13 @@ set @test |= 2 -- ^^^^^ variable.other.readwrite -- ^^ keyword.operator.assignment -- ^ meta.number.integer.decimal constant.numeric.value + +--------------- +CREATE PROCEDURE dbo.RetrievePersonAddress + @city_name NVARCHAR(30), + @postal_code NVARCHAR(15) +AS +SELECT * FROM Person.Address +WHERE City = @city_name AND PostalCode = @postal_code +OPTION ( OPTIMIZE FOR (@city_name = 'Seattle', @postal_code UNKNOWN) ); -- TODO: +GO From 696bc38dc8942a53df89ab79041edf72db6d9c5d Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 9 Oct 2021 23:18:29 +0300 Subject: [PATCH 038/250] [SQL] fix TSQL "Optimize for" hints --- SQL/TSQL.sublime-syntax | 24 ++++++++++++++++++++---- SQL/tests/syntax/syntax_test_tsql.sql | 25 ++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 9e49e38bcd..44d0beb0e8 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -299,7 +299,7 @@ contexts: - match: \b(?i:(option))\b\s*(\() captures: 1: keyword.other.DML.tsql - 2: punctuation.section.group.begin.sql + 2: meta.group.sql punctuation.section.group.begin.sql push: inside-with-group - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b scope: keyword.other.sql @@ -436,16 +436,23 @@ contexts: with-paren-or-pop: - match: \( - scope: punctuation.section.group.begin.sql + scope: meta.group.sql punctuation.section.group.begin.sql set: inside-with-group - match: (?=\S) set: maybe-table-alias inside-with-group: - - meta_scope: meta.group.sql + - meta_content_scope: meta.group.sql - match: \) - scope: punctuation.section.group.end.sql + scope: meta.group.sql punctuation.section.group.end.sql pop: 1 + - match: \b(?i:OPTIMIZE\s+FOR\s+UNKNOWN)\b + scope: keyword.other.tsql + - match: \b((?i:OPTIMIZE\s+FOR))\s*(\() + captures: + 1: keyword.other.tsql + 2: meta.group.tsql punctuation.section.group.begin.tsql + push: expressions-or-unknown - match: \w+ scope: constant.language.with.tsql - match: ',' @@ -664,3 +671,12 @@ contexts: - meta_content_scope: variable.function.tsql - match: '' pop: 1 + + expressions-or-unknown: + - meta_content_scope: meta.group.tsql + - match: \b(?i:unknown)\b + scope: keyword.other.tsql + - match: \) + scope: meta.group.tsql punctuation.section.group.end.tsql + pop: 1 + - include: expressions diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index fdce4563ca..f203cbdaf9 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1521,5 +1521,28 @@ CREATE PROCEDURE dbo.RetrievePersonAddress AS SELECT * FROM Person.Address WHERE City = @city_name AND PostalCode = @postal_code -OPTION ( OPTIMIZE FOR (@city_name = 'Seattle', @postal_code UNKNOWN) ); -- TODO: +OPTION ( OPTIMIZE FOR (@city_name = 'Seattle', @postal_code UNKNOWN) ); +-- ^^^ keyword.other.DML +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^ variable.other.readwrite +-- ^ keyword.operator.comparison +-- ^^^^^^^^^ string.quoted.single +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^ variable.other.readwrite +-- ^^^^^^^ keyword.other +-- ^ punctuation.section.group.end +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement GO + +SELECT * FROM Person.Address +WHERE City = @city_name AND PostalCode = @postal_code +OPTION (OPTIMIZE FOR UNKNOWN); +--^^^^ keyword.other.DML - meta.group +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^^^^^^^^ keyword.other +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement From 82f6060fde48b57751f74e03643cbee15936ff3f Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 9 Oct 2021 23:39:18 +0300 Subject: [PATCH 039/250] [SQL] scope TSQL index hints more precisely --- SQL/SQL (basic).sublime-syntax | 15 ++++++---- SQL/TSQL.sublime-syntax | 41 +++++++++++++++++++++++++-- SQL/tests/syntax/syntax_test_tsql.sql | 41 +++++++++++++++++++++++---- 3 files changed, 83 insertions(+), 14 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 8546703a3b..68f76ae302 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -189,15 +189,10 @@ contexts: - match: (?i)\bas\b scope: keyword.operator.assignment.alias.sql push: [column-alias, single-identifier-after-whitespace] - - include: numbers - - match: (?i)\b(?:true|false)\b - scope: constant.language.boolean.sql - - match: (?i:\bnull\b) - scope: constant.language.null.sql - match: \b(?i:case)\b scope: keyword.control.conditional.case.sql push: inside-case-expression - - include: strings + - include: numbers-variables-and-strings - include: operators - include: built-in-aggregate-function-calls - include: built-in-scalar-function-calls @@ -212,6 +207,14 @@ contexts: - match: (?=;) pop: 1 + numbers-variables-and-strings: + - include: numbers + - match: (?i)\b(?:true|false)\b + scope: constant.language.boolean.sql + - match: (?i:\bnull\b) + scope: constant.language.null.sql + - include: strings + inside-case-expression: - meta_scope: meta.statement.conditional.case.sql - match: \b(?i:end)\b diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 44d0beb0e8..0b9fcd0897 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -257,12 +257,9 @@ contexts: expressions: - meta_prepend: true - - match: 0x\h+ - scope: meta.number.integer.hexadecimal.tsql constant.numeric.value.tsql - match: \b(?i:cast)\b scope: support.function.tsql push: cast - - include: variables - include: with - match: \b(?i:output)\b scope: storage.modifier.output.tsql @@ -278,6 +275,12 @@ contexts: scope: keyword.control.conditional.case.sql push: merge-condition + numbers-variables-and-strings: + - meta_prepend: true + - include: variables + - match: 0x\h+ + scope: meta.number.integer.hexadecimal.tsql constant.numeric.value.tsql + dml-statements: - meta_append: true - match: \b(?i:bulk\s+insert)\b @@ -453,6 +456,21 @@ contexts: 1: keyword.other.tsql 2: meta.group.tsql punctuation.section.group.begin.tsql push: expressions-or-unknown + - match: \b((?i:OPTIMIZE\s+FOR))\s*(\() + captures: + 1: keyword.other.tsql + 2: meta.group.tsql punctuation.section.group.begin.tsql + push: expressions-or-unknown + - match: \b((?i:INDEX|FORCESEEK))\s*(\() + captures: + 1: keyword.other.tsql + 2: meta.group.tsql punctuation.section.group.begin.tsql + push: index-names + - match: \b((?i:INDEX))\s*(=) + captures: + 1: keyword.other.tsql + 2: keyword.operator.assignment.tsql + push: [index-name, single-identifier-after-whitespace] - match: \w+ scope: constant.language.with.tsql - match: ',' @@ -680,3 +698,20 @@ contexts: scope: meta.group.tsql punctuation.section.group.end.tsql pop: 1 - include: expressions + + index-names: + - meta_content_scope: meta.group.tsql + - match: ',' + scope: punctuation.separator.sequence.tsql + - match: \) + scope: meta.group.tsql punctuation.section.group.end.tsql + pop: 1 + - include: numbers-variables-and-strings + - include: ddl-table-creation-columns + - match: (?=\S) + push: [index-name, single-identifier] + + index-name: + - meta_content_scope: meta.index-name.tsql + - match: '' + pop: 1 diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index f203cbdaf9..0c01ccf648 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -938,21 +938,52 @@ USE [AdventureWorks] GO SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name FROM [Production].[ProductReview] PR -WITH (INDEX = IX_ProductReview_ProductID_Name) -- TODO: scope index name correctly +WITH (INDEX = IX_ProductReview_ProductID_Name) +-- ^^^^^ keyword.other +-- ^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.index-name INNER JOIN [Production].[Product] PP -WITH (INDEX = [AK_Product_Name]) ON PR.ProductID = PP.ProductID -- TODO: scope index name correctly +WITH (INDEX = [AK_Product_Name]) ON PR.ProductID = PP.ProductID +-- ^^^^^ keyword.other +-- ^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^^^^ meta.index-name +-- ^ punctuation.definition.identifier.begin +-- ^ punctuation.definition.identifier.end SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name FROM [Production].[ProductReview] PR -WITH (TABLOCK, INDEX(myindex, [anotherindex])) -- TODO: +WITH (TABLOCK, INDEX(myindex, [anotherindex])) +-- ^^^^^^^ constant.language.with +-- ^ punctuation.separator.sequence +-- ^^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^ meta.index-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^ meta.index-name +-- ^^ punctuation.section.group.end SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name FROM [Production].[ProductReview] PR -WITH (TABLOCK, INDEX(1)) -- TODO: +WITH (TABLOCK, INDEX(1)) +-- ^^^^^ keyword.other +-- ^^^ meta.group meta.group +-- ^ meta.number.integer.decimal constant.numeric.value SELECT PR.ProductID, PR.ReviewerName, PR.Comments, PP.Name FROM [Production].[ProductReview] PR -WITH (FORCESEEK (MyIndex (col1, col2, col3)) -- TODO: +WITH (FORCESEEK (MyIndex (col1, col2, col3)) +-- ^^^^^^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^ meta.index-name +-- ^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^ punctuation.section.group.begin +-- ^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^ punctuation.section.group.end ----------------- From a527926186b0e0a573701cf7f928c969ea2997ec Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 10 Oct 2021 22:57:39 +0300 Subject: [PATCH 040/250] [SQL] fix T-SQL PIVOT/UNPIVOT without table alias --- SQL/TSQL.sublime-syntax | 12 +++++++++++- SQL/tests/syntax/syntax_test_tsql.sql | 20 ++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 0b9fcd0897..db348e3a35 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -239,7 +239,10 @@ contexts: scope: keyword.other.tsql - match: \b(?i:disk|tape|url)\b scope: keyword.other.tsql - - match: \b(?i:pivot|unpivot|for)\b + - match: \b(?i:pivot|unpivot)\b + scope: keyword.other.tsql + push: [maybe-table-alias, expressions-pop-at-as] + - match: \b(?i:for)\b scope: keyword.other.tsql - match: \b(\w+)(:) captures: @@ -399,6 +402,8 @@ contexts: maybe-table-alias: - meta_prepend: true - include: with + - match: (?=\b(?i:unpivot|pivot)\b) + pop: 1 fail-if-function-call: - meta_prepend: true @@ -715,3 +720,8 @@ contexts: - meta_content_scope: meta.index-name.tsql - match: '' pop: 1 + + expressions-pop-at-as: + - match: (?=(?i:\bas\b)) + pop: 1 + - include: expressions diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 0c01ccf648..71fc1698eb 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1014,8 +1014,22 @@ PIVOT -- ^ punctuation.section.group.begin -- ^^^ meta.column-name -- ^ punctuation.separator.sequence -) AS PivotTable; -- TODO: scope this correctly +) AS PivotTable; --^^ keyword.operator.assignment.alias +-- ^^^^^^^^^^ meta.table-alias-name +-- ^ punctuation.terminator.statement + +SELECT item.ID AS DatePivotID, + MAX(dDate) AS LastUpdateDate +FROM Documents +UNPIVOT (dDate FOR nDate IN (date1, date2, date3, date4)) AS item +-- <- keyword.other +-- ^^^^ keyword.other +-- ^^ keyword.operator.assignment.alias +-- ^^^^ meta.table-alias-name +GROUP BY item.ID +-- ^^^^^ keyword.other.DML + ------------ -- Create the table and insert values as portrayed in the previous example. CREATE TABLE pvt (VendorID INT, Emp1 INT, Emp2 INT, @@ -1041,9 +1055,11 @@ UNPIVOT -- ^^^^^^^^ meta.column-name -- ^^ keyword.operator.logical (Emp1, Emp2, Emp3, Emp4, Emp5) -) AS unpvt; -- TODO: scope this correctly +) AS unpvt; -- <- meta.group punctuation.section.group.end --^^ keyword.operator.assignment.alias +-- ^^^^^ meta.table-alias-name +-- ^ punctuation.terminator.statement GO ------------- From ea4246086cc16d2d74301e09d9d2f88e1183b0a6 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 10 Oct 2021 23:00:44 +0300 Subject: [PATCH 041/250] [SQL] tighten context for clarity --- SQL/SQL (basic).sublime-syntax | 9 ++++++--- SQL/TSQL.sublime-syntax | 10 +++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 68f76ae302..cb5b4d2f71 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -197,9 +197,7 @@ contexts: - include: built-in-aggregate-function-calls - include: built-in-scalar-function-calls - include: user-defined-function-calls - - match: \( - scope: punctuation.section.group.begin.sql - push: inside-group + - include: begin-group - match: \) scope: invalid.illegal.trailing-paren.sql - match: ',' @@ -215,6 +213,11 @@ contexts: scope: constant.language.null.sql - include: strings + begin-group: + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-group + inside-case-expression: - meta_scope: meta.statement.conditional.case.sql - match: \b(?i:end)\b diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index db348e3a35..2138894c67 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -241,7 +241,7 @@ contexts: scope: keyword.other.tsql - match: \b(?i:pivot|unpivot)\b scope: keyword.other.tsql - push: [maybe-table-alias, expressions-pop-at-as] + push: [maybe-table-alias, begin-group-or-pop] - match: \b(?i:for)\b scope: keyword.other.tsql - match: \b(\w+)(:) @@ -721,7 +721,7 @@ contexts: - match: '' pop: 1 - expressions-pop-at-as: - - match: (?=(?i:\bas\b)) - pop: 1 - - include: expressions + begin-group-or-pop: + - include: begin-group + - match: (?=\S) + pop: true From e92279bec11945cf1c95d8f465928d382488b37d Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 12 Oct 2021 22:22:49 +0300 Subject: [PATCH 042/250] [SQL] scope partition keys in CQL, joins don't exist --- SQL/Cassandra.sublime-syntax | 39 ++++++++++++++++++- SQL/tests/syntax/syntax_test_cassandra.cql | 44 ++++++++++++++++++++-- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 080ffbf00d..377a8e6237 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -1,6 +1,6 @@ %YAML 1.2 --- -name: CQL +name: Cassandra Query Language file_extensions: - cql scope: source.sql.cql @@ -84,3 +84,40 @@ contexts: ddl-alter-common: - meta_prepend: false + + inside-ddl-table-creation-columns: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - match: ((?i:\bprimary\s+key))\s*(\() + captures: + 1: keyword.other.cql + 2: meta.group.cql punctuation.section.group.begin.cql + push: partition-key + - match: \b(?i:primary\s+key)\b + scope: storage.modifier.cql + push: partition-key + - include: expressions-or-column-name + + partition-key: + - meta_content_scope: meta.group.partition-key.cql + - match: \) + scope: meta.group.partition-key.cql punctuation.section.group.end.cql + pop: 1 + - match: \( + scope: punctuation.section.group.begin.cql + push: inside-partition-key-group + - match: ',' + scope: punctuation.separator.sequence.cql + set: inside-group + - include: inside-ddl-table-creation-columns + + inside-partition-key-group: + - match: \) + scope: punctuation.section.group.end.cql + pop: 1 + - include: inside-ddl-table-creation-columns + + joins: + - match: \bjoin\b diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 2ed02600c8..a1710b9c82 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -107,10 +107,10 @@ CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( -- ^ punctuation.separator.sequence PRIMARY KEY(userid) -- ^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns --- ^^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^ keyword.other -- ^ meta.group punctuation.section.group.begin --- ^^^^^^ meta.group meta.column-name --- ^ meta.group punctuation.section.group.end +-- ^^^^^^ meta.group.partition-key meta.column-name +-- ^ meta.group.partition-key punctuation.section.group.end ); -- <- meta.create meta.group.table-columns punctuation.section.group.end @@ -119,19 +119,51 @@ CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( other_id uuid, test text, PRIMARY KEY(userid, other_id) +-- ^^^^^^^^^^^ meta.create meta.group.table-columns keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.group.partition-key meta.column-name +-- ^^^^^^^^^^^ - meta.group.partition-key +-- ^ meta.group punctuation.separator.sequence +-- ^^^^^^^^ meta.group.table-columns meta.group meta.column-name +-- ^ punctuation.section.group.end ); +-- <- meta.create meta.group.table-columns punctuation.section.group.end CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( userid uuid, other_id uuid, test text, PRIMARY KEY ((userid), other_id) +-- ^^^^^^^^^^^ meta.create meta.group.table-columns keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^^ meta.group.partition-key +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^^^^^^^^^^ - meta.group.partition-key +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ meta.group.table-columns meta.group meta.column-name +-- ^ punctuation.section.group.end ); +-- <- meta.create meta.group.table-columns punctuation.section.group.end CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( userid uuid, other_id uuid, test int, PRIMARY KEY ((userid, other_id), test) +-- ^^^^^^^^^^^ meta.create meta.group.table-columns keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^^^^^^ meta.group.partition-key +-- ^ punctuation.section.group.begin +-- ^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^^^^^^^ - meta.group.partition-key +-- ^ punctuation.separator.sequence +-- ^^^^ meta.group.table-columns meta.group meta.column-name +-- ^ punctuation.section.group.end ); +-- <- meta.create meta.group.table-columns punctuation.section.group.end CREATE TABLE IF NOT EXISTS date_by_userid ( userid uuid PRIMARY KEY, @@ -266,3 +298,9 @@ ALTER TABLE someentity_by_somefield -- ^^^^^^^^^^^ meta.column-name -- ^^^^ storage.type -- ^ punctuation.terminator.statement + +select * +from test_by_example +join fred -- there are no joins in CQL +-- <- - keyword +--^^ - keyword From 9067ab59eac1cc6cc23edc02968a509f96d83202 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 12 Oct 2021 22:39:58 +0300 Subject: [PATCH 043/250] [SQL] scope constraint names correctly in table definitions --- SQL/SQL (basic).sublime-syntax | 10 +++++++++- SQL/tests/syntax/syntax_test_tsql.sql | 25 ++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index cb5b4d2f71..eed22f3d11 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -402,7 +402,10 @@ contexts: - match: \) scope: punctuation.section.group.end.sql pop: 1 - - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|constraint|default)\b) + - match: (?i:\bconstraint\b) + scope: storage.modifier.sql + push: [constraint-name, single-identifier-after-whitespace] + - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|default)\b) scope: storage.modifier.sql - include: expressions-or-column-name @@ -453,6 +456,11 @@ contexts: - match: '' pop: 1 + constraint-name: + - meta_content_scope: meta.constraint-name.sql + - match: '' + pop: 1 + subquery: - match: \( scope: punctuation.section.group.begin.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 71fc1698eb..1aa0aae336 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1099,8 +1099,14 @@ CREATE TABLE dbo.T1 column_2 varchar(30) -- ^^^^^^^^ meta.column-name -- ^^^^^^^^^^^ storage.type - CONSTRAINT default_name DEFAULT ('my column default'), -- TODO: scope the constraint name correctly + CONSTRAINT default_name DEFAULT ('my column default'), -- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^ meta.constraint-name +-- ^^^^^^^ storage.modifier +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence column_3 rowversion, -- ^^^^^^^^ meta.column-name -- ^^^^^^^^^^ storage.type @@ -1185,6 +1191,17 @@ GO CREATE TABLE [dbo].[be_Categories]( [CategoryID] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [DF_be_Categories_CategoryID] DEFAULT (newid()), -- ^^^^^^^^^^ storage.modifier +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.constraint-name +-- ^^^^^^^ storage.modifier +-- ^ punctuation.section.group.begin +-- ^^^^^ meta.function-call support.function +-- ^ punctuation.section.parens.begin +-- ^ punctuation.section.parens.end +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence [CategoryName] [nvarchar](50) NULL, [Description] [nvarchar](200) NULL, [ParentID] [uniqueidentifier] NULL, @@ -1209,6 +1226,12 @@ GO -------------- CREATE TABLE [Employee]( [EmployeeID] [int] NOT NULL PRIMARY KEY, +-- ^^^^^^^^^^^^ meta.column-name +-- ^^^^^ storage.type +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^^^^^ storage.modifier +-- ^ punctuation.separator.sequence [FirstName] VARCHAR(250) NOT NULL, [LastName] VARCHAR(250) NOT NULL, [DepartmentID] [int] NOT NULL REFERENCES [Department](DepartmentID), -- TODO: scope reference table name correctly From e9ffa2d1b78aa717431c7e782177511d8ad81412 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 12 Oct 2021 23:10:19 +0300 Subject: [PATCH 044/250] [SQL] scope references correctly, scope filegroups in TSQL --- SQL/SQL (basic).sublime-syntax | 5 +++- SQL/TSQL.sublime-syntax | 34 ++++++++++++++++++++------- SQL/tests/syntax/syntax_test_tsql.sql | 29 +++++++++++++++++++++-- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index eed22f3d11..039b0d1171 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -405,7 +405,10 @@ contexts: - match: (?i:\bconstraint\b) scope: storage.modifier.sql push: [constraint-name, single-identifier-after-whitespace] - - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|references|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|default)\b) + - match: (?i:\breferences\b) + scope: storage.modifier.sql + push: [table-name, single-identifier-after-whitespace] + - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|default)\b) scope: storage.modifier.sql - include: expressions-or-column-name diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 2138894c67..e2f2414bbb 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -11,6 +11,11 @@ variables: additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec|go|bulk|insert|on|when)\b) enclosed_type_begin: (?:\[) enclosed_type_end: (?:\]) + identifier_for_lookahead: |- + (?x: + (?:(?:\b\w+|\[[^]]+\])\.)* + (?:\b\w+|\[[^]]+\]) + ) simple_types: |- (?ix:\b(?: @@ -453,7 +458,7 @@ contexts: - meta_content_scope: meta.group.sql - match: \) scope: meta.group.sql punctuation.section.group.end.sql - pop: 1 + set: maybe-filegroup - match: \b(?i:OPTIMIZE\s+FOR\s+UNKNOWN)\b scope: keyword.other.tsql - match: \b((?i:OPTIMIZE\s+FOR))\s*(\() @@ -610,6 +615,18 @@ contexts: - include: dml-statements - include: expressions + ddl-table-creation-columns: + - match: \( + scope: punctuation.section.group.begin.sql + set: [maybe-filegroup, inside-ddl-table-creation-columns] + + maybe-filegroup: + - match: \b(?i:ON)\b(?!\s*{{identifier_for_lookahead}}\s*=) + scope: keyword.other.tsql + set: [filegroup-name, single-identifier-after-whitespace] + - match: (?=\S) + pop: 1 + inside-ddl-table-creation-columns: - meta_prepend: true - match: \b(?i:ROWGUIDCOL|CLUSTERED|NONCLUSTERED)\b @@ -681,13 +698,7 @@ contexts: user-defined-function-calls: - meta_append: true - - match: |- - (?x) - (?= - (?:(?:\b\w+|\[[^]]+\])\.)* - (?: \b\w+|\[[^]]+\]) - \s*\( - ) + - match: (?={{identifier_for_lookahead}}\s*\() push: [begin-method-call-paren, function-name, single-identifier] function-name: @@ -724,4 +735,9 @@ contexts: begin-group-or-pop: - include: begin-group - match: (?=\S) - pop: true + pop: 1 + + filegroup-name: + - meta_content_scope: meta.filegroup-name.tsql + - match: '' + pop: 1 diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 1aa0aae336..4108b0882a 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1206,6 +1206,8 @@ CREATE TABLE [dbo].[be_Categories]( [Description] [nvarchar](200) NULL, [ParentID] [uniqueidentifier] NULL, CONSTRAINT [PK_be_Categories] PRIMARY KEY CLUSTERED +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^^^ meta.constraint-name -- ^^^^^^^^^^^ storage.modifier -- ^^^^^^^^^ storage.modifier ( @@ -1221,7 +1223,19 @@ CREATE TABLE [dbo].[be_Categories]( -- ^^^^^^^^^^^^^^^ constant.language.with -- ^ keyword.operator.assignment -- ^^ constant.language.bool +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^ constant.language.bool +-- ^ punctuation.section.group.end +-- ^^ keyword.other +-- ^^^^^^^^^ meta.filegroup-name ) ON [PRIMARY] +-- <- punctuation.section.group.end +--^^ meta.create keyword.other +-- ^^^^^^^^^ meta.filegroup-name +-- ^ punctuation.definition.identifier.begin +-- ^ punctuation.definition.identifier.end GO -------------- CREATE TABLE [Employee]( @@ -1234,8 +1248,19 @@ CREATE TABLE [Employee]( -- ^ punctuation.separator.sequence [FirstName] VARCHAR(250) NOT NULL, [LastName] VARCHAR(250) NOT NULL, - [DepartmentID] [int] NOT NULL REFERENCES [Department](DepartmentID), -- TODO: scope reference table name correctly -) ON [PRIMARY] -- TODO: scope on primary correctly + [DepartmentID] [int] NOT NULL REFERENCES [Department](DepartmentID), +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence +) ON [PRIMARY] +-- <- punctuation.section.group.end +--^^ meta.create keyword.other +-- ^^^^^^^^^ meta.create meta.filegroup-name GO SELECT * FROM Department D CROSS APPLY From c28363752bc7122cfeb6b113b5bffc0bf335ebee Mon Sep 17 00:00:00 2001 From: Johannes Rappen Date: Tue, 12 Oct 2021 23:05:33 +0200 Subject: [PATCH 045/250] [SQL] fix tmPreferences - remove redundant lines - convert indentation to tabs --- SQL/Indentation Rules - Comments.tmPreferences | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/SQL/Indentation Rules - Comments.tmPreferences b/SQL/Indentation Rules - Comments.tmPreferences index a002e36995..e018720e72 100644 --- a/SQL/Indentation Rules - Comments.tmPreferences +++ b/SQL/Indentation Rules - Comments.tmPreferences @@ -1,13 +1,12 @@ - - scope - source.sql comment - settings - - preserveIndent - - + scope + source.sql comment + settings + + preserveIndent + + From 700f8f8db6c99c368d60d227d4aa43e66d9b428a Mon Sep 17 00:00:00 2001 From: Johannes Rappen Date: Tue, 12 Oct 2021 23:14:26 +0200 Subject: [PATCH 046/250] [SQL] split tests into separate ones for: - symbols - indentation --- .../syntax_test_indentation_tsql.sql | 7 -- .../symbols/syntax_test_indentation_tsql.sql | 66 +++++++++++++++++++ 2 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 SQL/tests/symbols/syntax_test_indentation_tsql.sql diff --git a/SQL/tests/indentation/syntax_test_indentation_tsql.sql b/SQL/tests/indentation/syntax_test_indentation_tsql.sql index 39629fd155..1816cead2a 100644 --- a/SQL/tests/indentation/syntax_test_indentation_tsql.sql +++ b/SQL/tests/indentation/syntax_test_indentation_tsql.sql @@ -33,27 +33,20 @@ SELECT a FROM foo CREATE TABLE hello ( - -- @@@@@ definition field1 int, field2 nvarchar(50) ) CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( - -- @@@@@@@@@@@@@ definition some_column ASC ) SET @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) --- @@@@@@@ reference --- @@@@@@@ reference BEGIN RAISERROR ('File "%s" does not exist', 16, -1, @FromFile) - -- @@@@@@@@@ reference END SELECT COALESCE(a.field1, b.field2, c.field1) AS Blah, ISNULL(d.field1, 'default') as field1 --- @@@@@@@@ reference --- @@@@@@ reference 'no indentation increase when an unclosed open paren is in a string(' BEGIN diff --git a/SQL/tests/symbols/syntax_test_indentation_tsql.sql b/SQL/tests/symbols/syntax_test_indentation_tsql.sql new file mode 100644 index 0000000000..e868e85e80 --- /dev/null +++ b/SQL/tests/symbols/syntax_test_indentation_tsql.sql @@ -0,0 +1,66 @@ +-- SYNTAX TEST "Packages/SQL/TSQL.sublime-syntax" + +SELECT * +FROM ( + SELECT * + FROM a + INNER JOIN b ON a.ID = b.ID +) alias +WHERE 1 = 1 +GO + +BEGIN + INSERT INTO a + VALUES (123, 456) +END + +BEGIN + INSERT INTO a + VALUES (123, 456) +GO + INSERT INTO b + VALUES (123, 456) +END + +SELECT +a, +b, +c +FROM foo + +SELECT a +,b +,c +FROM foo + +CREATE TABLE hello ( + -- @@@@@ definition + field1 int, + field2 nvarchar(50) +) + +CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( + -- @@@@@@@@@@@@@ definition + some_column ASC +) + +SET @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) +-- @@@@@@@ reference +-- @@@@@@@ reference + +BEGIN RAISERROR ('File "%s" does not exist', 16, -1, @FromFile) + -- @@@@@@@@@ reference +END + +SELECT COALESCE(a.field1, b.field2, c.field1) AS Blah, ISNULL(d.field1, 'default') as field1 +-- @@@@@@@@ reference +-- @@@@@@ reference + +'no indentation increase when an unclosed open paren is in a string(' +BEGIN + 'no indentation decrease when a close paren with no matching open paren on the same line is in a string)' + null + -- no indentation increase when an unclosed open paren is in a comment ( + --no indentation decrease when a close paren with no matching open paren on the same line is in a comment ) + null +END From 7224d18de6ed63b17b19fe89c25ec504aee9e81e Mon Sep 17 00:00:00 2001 From: Johannes Rappen Date: Tue, 12 Oct 2021 23:39:50 +0200 Subject: [PATCH 047/250] [SQL] minor syntax file readability improvements --- SQL/MySQL.sublime-syntax | 13 +++-- SQL/SQL (basic).sublime-syntax | 89 ++++++++++++++++++++++++------- SQL/TSQL.sublime-syntax | 96 ++++++++++++++++++++++++++-------- 3 files changed, 154 insertions(+), 44 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index b85cb16ad4..c711710dc0 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -123,20 +123,27 @@ contexts: - meta_prepend: true - match: \b(?i:create\s+or\s+replace)\b scope: keyword.other.ddl.sql - push: [ddl-create-target, create-condition, ddl-target] + push: + - ddl-create-target + - create-condition + - ddl-target dml-statements: - meta_append: true - match: (?i:\binsert(\s+(?:ignore\s+)?into)?\b) scope: keyword.other.DML.sql - push: [table-name, single-identifier-after-whitespace] + push: + - table-name + - single-identifier-after-whitespace - match: (?i)\b(?:limit)\b scope: keyword.other.DML.sql ddl-target-common: - match: \b(?i:on)\b scope: keyword.other.mysql - push: [table-name, single-identifier-after-whitespace] + push: + - table-name + - single-identifier-after-whitespace - match: (?i)\b(?:using)\b scope: keyword.other.mysql - match: \b((?i:algorithm))\s*(=) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 039b0d1171..9385321ee2 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -88,7 +88,9 @@ contexts: single-identifier: - include: pop-on-top-level-reserved-word - match: '' - set: [maybe-identifier-accessor, identifier-part] + set: + - maybe-identifier-accessor + - identifier-part maybe-identifier-accessor: - match: \s*(\.)(?=\s*\*) @@ -136,7 +138,9 @@ contexts: create-condition: - include: dml-condition - match: (?=\S) - set: [identifier-create, single-identifier] + set: + - identifier-create + - single-identifier drop-condition: - include: dml-condition @@ -176,7 +180,10 @@ contexts: - include: wildcard-identifier - include: expressions - match: (?=\S) - push: [possible-operator, column-name, single-identifier] + push: + - possible-operator + - column-name + - single-identifier numbers: - match: \b\d+\.\d+\b @@ -188,7 +195,9 @@ contexts: - include: types - match: (?i)\bas\b scope: keyword.operator.assignment.alias.sql - push: [column-alias, single-identifier-after-whitespace] + push: + - column-alias + - single-identifier-after-whitespace - match: \b(?i:case)\b scope: keyword.control.conditional.case.sql push: inside-case-expression @@ -291,22 +300,36 @@ contexts: ddl-statements: - match: \b(?i:create\s+table)\b scope: keyword.other.ddl.sql - push: [ddl-create-target, ddl-table-creation-columns, create-condition] + push: + - ddl-create-target + - ddl-table-creation-columns + - create-condition - match: \b(?i:create)\b scope: keyword.other.ddl.sql - push: [ddl-create-target, create-condition, ddl-target] + push: + - ddl-create-target + - create-condition + - ddl-target - match: (?i:\bdrop\s+table\b) scope: keyword.other.ddl.sql push: ddl-drop-table - match: \b(?i:drop)\b scope: keyword.other.ddl.sql - push: [ddl-drop-target, drop-condition, ddl-target] + push: + - ddl-drop-target + - drop-condition + - ddl-target - match: \b(?i:alter\s+table)\b scope: keyword.other.ddl.sql - push: [ddl-alter-table, table-name, single-identifier-after-whitespace] + push: + - ddl-alter-table + - table-name + - single-identifier-after-whitespace - match: \b(?i:alter)\b scope: keyword.other.ddl.sql - push: [ddl-alter-target, ddl-target] + push: + - ddl-alter-target + - ddl-target - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) scope: keyword.other.authorization.sql @@ -314,7 +337,9 @@ contexts: - meta_scope: meta.create.sql - match: \b(?i:on)\b scope: keyword.other.sql - push: [table-name, single-identifier-after-whitespace] + push: + - table-name + - single-identifier-after-whitespace - match: (?=\S) pop: 1 @@ -344,7 +369,9 @@ contexts: - meta_scope: meta.drop.sql - include: dml-condition - match: (?=\S) - set: [table-name, single-identifier-after-whitespace] + set: + - table-name + - single-identifier-after-whitespace ddl-alter-table: - meta_scope: meta.alter.sql @@ -381,7 +408,9 @@ contexts: set: dml-update - match: (?i:\b(?:insert\s+into|truncate)\b) scope: keyword.other.DML.sql - push: [table-name, single-identifier-after-whitespace] + push: + - table-name + - single-identifier-after-whitespace - match: (?i:\bset\b) scope: keyword.other.DML.sql push: set @@ -404,21 +433,29 @@ contexts: pop: 1 - match: (?i:\bconstraint\b) scope: storage.modifier.sql - push: [constraint-name, single-identifier-after-whitespace] + push: + - constraint-name + - single-identifier-after-whitespace - match: (?i:\breferences\b) scope: storage.modifier.sql - push: [table-name, single-identifier-after-whitespace] + push: + - table-name + - single-identifier-after-whitespace - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|default)\b) scope: storage.modifier.sql - include: expressions-or-column-name dml-delete: - match: (?=\S) - set: [table-name, single-identifier] + set: + - table-name + - single-identifier dml-update: - match: (?=\S) - set: [table-name, single-identifier] + set: + - table-name + - single-identifier distinct: - match: \b(?i:distinct)\b @@ -427,7 +464,9 @@ contexts: joins: - match: (?i)\b(?:(?:inner|(?:full|left\s+)?outer|cross|left|right)\s+)?join\b scope: keyword.other.DML.sql - push: [join-on, table-name-or-subquery] + push: + - join-on + - table-name-or-subquery column-name: - meta_content_scope: meta.column-name.sql @@ -480,7 +519,10 @@ contexts: table-name-not-function-call: - match: '' - push: [fail-if-function-call, table-name, single-identifier] + push: + - fail-if-function-call + - table-name + - single-identifier fail-if-function-call: - match: \( @@ -494,7 +536,10 @@ contexts: scope: keyword.operator.assignment.alias.sql - include: pop-on-top-level-reserved-word - match: (?=\S) - set: [after-table-alias, table-alias-name, single-identifier] + set: + - after-table-alias + - table-alias-name + - single-identifier after-table-alias: - match: \b(?i:(TABLESAMPLE(?:\s+SYSTEM)?))\s*(\() @@ -528,7 +573,11 @@ contexts: table-valued-function-call: - match: '' - set: [maybe-table-alias, begin-method-call-paren, table-valued-function-name, single-identifier] + set: + - maybe-table-alias + - begin-method-call-paren + - table-valued-function-name + - single-identifier table-valued-function-name: - meta_content_scope: meta.table-valued-function-name.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index e2f2414bbb..0a3f857862 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -79,28 +79,39 @@ contexts: like-string-not-followed-by-escape: - match: \' scope: punctuation.definition.string.begin.sql - set: [like-escape-fail, inside-like-single-quoted-string] + set: + - like-escape-fail + - inside-like-single-quoted-string - match: (?=\S) pop: 1 like-string-followed-by-escape-slash: - match: \' scope: punctuation.definition.string.begin.sql - set: [like-escape-character-slash, like-escape-pop, inside-like-single-quoted-string-slash-escape] + set: + - like-escape-character-slash + - like-escape-pop + - inside-like-single-quoted-string-slash-escape - match: (?=\S) pop: 1 like-string-followed-by-escape-caret: - match: \' scope: punctuation.definition.string.begin.sql - set: [like-escape-character-caret, like-escape-pop, inside-like-single-quoted-string-caret-escape] + set: + - like-escape-character-caret + - like-escape-pop + - inside-like-single-quoted-string-caret-escape - match: (?=\S) pop: 1 like-string-followed-by-unknown-escape: - match: \' scope: punctuation.definition.string.begin.sql - set: [like-escape-character-any, like-escape-pop, inside-like-single-quoted-string] + set: + - like-escape-character-any + - like-escape-pop + - inside-like-single-quoted-string - match: (?=\S) pop: 1 @@ -314,19 +325,33 @@ contexts: push: inside-with-group - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b scope: keyword.other.sql - push: [cursor-name, single-identifier-after-whitespace] + push: + - cursor-name + - single-identifier-after-whitespace - match: \b(?i:merge)\b scope: keyword.other.tsql - push: [maybe-table-alias, table-name, single-identifier-after-whitespace] + push: + - maybe-table-alias + - table-name + - single-identifier-after-whitespace - match: \b(?i:using)\b scope: keyword.other.tsql - push: [table-name-or-subquery, join-on, maybe-table-alias, table-name, single-identifier-after-whitespace] + push: + - table-name-or-subquery + - join-on + - maybe-table-alias + - table-name + - single-identifier-after-whitespace ddl-statements: - meta_prepend: true - match: (?i)\b(?:create(?:\s+or\s+alter)?)\b(?!\s*table\b) scope: keyword.other.ddl.sql - push: [ddl-create-target-expect-as, ddl-create-target, create-condition, ddl-target] + push: + - ddl-create-target-expect-as + - ddl-create-target + - create-condition + - ddl-target ddl-target: - meta_prepend: true @@ -338,7 +363,9 @@ contexts: #- match: \b(?i:proc|procedure|function)\b # scope: keyword.other.sql - match: (?=\S) - set: [ddl-create-target-expect-as, expect-procedure-name] + set: + - ddl-create-target-expect-as + - expect-procedure-name ddl-create-target-expect-as: - match: (?i:\bas\b) @@ -384,7 +411,9 @@ contexts: after-declare: - match: (?=\w+\s+(?i:cursor)\b) - set: [cursor-name, single-identifier] + set: + - cursor-name + - single-identifier - match: (?=\S) pop: 1 @@ -394,7 +423,9 @@ contexts: scope: constant.language.switch.tsql - match: \b(?i:identity_insert)\b scope: constant.language.switch.tsql - push: [table-name, single-identifier] + push: + - table-name + - single-identifier - match: \b(?i:on|off)\b scope: constant.language.boolean.tsql - include: variables @@ -437,10 +468,16 @@ contexts: cte-with: - match: (?i)\bwith\b(?=\s*(?:\[\w+\]|\w+)\s*\() scope: keyword.other.DML.sql - push: [cte-column-list-begin, cte-table-name, single-identifier] + push: + - cte-column-list-begin + - cte-table-name + - single-identifier - match: (?i)\bwith\b #(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) scope: keyword.other.DML.sql - push: [cte-as, cte-table-name, single-identifier] + push: + - cte-as + - cte-table-name + - single-identifier with: - match: (?i)\bwith\b @@ -480,7 +517,9 @@ contexts: captures: 1: keyword.other.tsql 2: keyword.operator.assignment.tsql - push: [index-name, single-identifier-after-whitespace] + push: + - index-name + - single-identifier-after-whitespace - match: \w+ scope: constant.language.with.tsql - match: ',' @@ -540,7 +579,9 @@ contexts: - meta_prepend: true - match: \b(?i:OPENXML)\b scope: meta.table-valued-function-name.sql support.function.tsql - push: [with-column-definition, begin-method-call-paren] + push: + - with-column-definition + - begin-method-call-paren - match: \b(?i:(OPENROWSET))\b\s*(\() scope: meta.function-call.tsql captures: @@ -557,12 +598,16 @@ contexts: expect-procedure-name: - match: '' - set: [procedure-name, single-identifier-after-whitespace] + set: + - procedure-name + - single-identifier-after-whitespace cte-column-list-begin: - match: (?=\() scope: punctuation.section.group.begin.tsql - set: [cte-as, ddl-table-creation-columns] + set: + - cte-as + - ddl-table-creation-columns - match: (?=\S) set: cte-as @@ -618,12 +663,16 @@ contexts: ddl-table-creation-columns: - match: \( scope: punctuation.section.group.begin.sql - set: [maybe-filegroup, inside-ddl-table-creation-columns] + set: + - maybe-filegroup + - inside-ddl-table-creation-columns maybe-filegroup: - match: \b(?i:ON)\b(?!\s*{{identifier_for_lookahead}}\s*=) scope: keyword.other.tsql - set: [filegroup-name, single-identifier-after-whitespace] + set: + - filegroup-name + - single-identifier-after-whitespace - match: (?=\S) pop: 1 @@ -699,7 +748,10 @@ contexts: user-defined-function-calls: - meta_append: true - match: (?={{identifier_for_lookahead}}\s*\() - push: [begin-method-call-paren, function-name, single-identifier] + push: + - begin-method-call-paren + - function-name + - single-identifier function-name: - meta_content_scope: variable.function.tsql @@ -725,7 +777,9 @@ contexts: - include: numbers-variables-and-strings - include: ddl-table-creation-columns - match: (?=\S) - push: [index-name, single-identifier] + push: + - index-name + - single-identifier index-name: - meta_content_scope: meta.index-name.tsql From ff347d197d673d5e01f3b2af6d6ec67616628bae Mon Sep 17 00:00:00 2001 From: Johannes Rappen Date: Tue, 12 Oct 2021 23:46:09 +0200 Subject: [PATCH 048/250] [SQL] rename syntax test file --- ...tax_test_indentation_tsql.sql => syntax_test_symbols_tsql.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename SQL/tests/symbols/{syntax_test_indentation_tsql.sql => syntax_test_symbols_tsql.sql} (100%) diff --git a/SQL/tests/symbols/syntax_test_indentation_tsql.sql b/SQL/tests/symbols/syntax_test_symbols_tsql.sql similarity index 100% rename from SQL/tests/symbols/syntax_test_indentation_tsql.sql rename to SQL/tests/symbols/syntax_test_symbols_tsql.sql From 076427ba176f8f98ce9efa1d728cc20fc70e1d95 Mon Sep 17 00:00:00 2001 From: Johannes Rappen Date: Wed, 13 Oct 2021 02:18:00 +0200 Subject: [PATCH 049/250] [SQL] clean up symbols tests --- .../symbols/syntax_test_symbols_tsql.sql | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/SQL/tests/symbols/syntax_test_symbols_tsql.sql b/SQL/tests/symbols/syntax_test_symbols_tsql.sql index e868e85e80..ad0ec2e548 100644 --- a/SQL/tests/symbols/syntax_test_symbols_tsql.sql +++ b/SQL/tests/symbols/syntax_test_symbols_tsql.sql @@ -1,38 +1,5 @@ -- SYNTAX TEST "Packages/SQL/TSQL.sublime-syntax" -SELECT * -FROM ( - SELECT * - FROM a - INNER JOIN b ON a.ID = b.ID -) alias -WHERE 1 = 1 -GO - -BEGIN - INSERT INTO a - VALUES (123, 456) -END - -BEGIN - INSERT INTO a - VALUES (123, 456) -GO - INSERT INTO b - VALUES (123, 456) -END - -SELECT -a, -b, -c -FROM foo - -SELECT a -,b -,c -FROM foo - CREATE TABLE hello ( -- @@@@@ definition field1 int, @@ -55,12 +22,3 @@ END SELECT COALESCE(a.field1, b.field2, c.field1) AS Blah, ISNULL(d.field1, 'default') as field1 -- @@@@@@@@ reference -- @@@@@@ reference - -'no indentation increase when an unclosed open paren is in a string(' -BEGIN - 'no indentation decrease when a close paren with no matching open paren on the same line is in a string)' - null - -- no indentation increase when an unclosed open paren is in a comment ( - --no indentation decrease when a close paren with no matching open paren on the same line is in a comment ) - null -END From 6e3c84c02e5e3ef458b55429e9811385e35150f1 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 15 Oct 2021 06:52:49 +0300 Subject: [PATCH 050/250] [SQL] Support opening paren directly after TOP with no whitespace between --- SQL/TSQL.sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_tsql.sql | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 0a3f857862..c4b187af66 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -377,7 +377,7 @@ contexts: - include: expressions top: - - match: (?i)\b(top)\b(?:\s+(?:(\()\s*)?(\d+)(?:\s*(\)))?(?:\s+(percent\b))?)? + - match: (?i)\b(top)\b(?:\s*(?:(\()\s*)?(\d+)(?:\s*(\)))?(?:\s+(percent\b))?)? captures: 1: keyword.other.DML.tsql 2: meta.group.tsql punctuation.section.parens.begin.tsql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 4108b0882a..4b16d28325 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -136,6 +136,18 @@ SELECT TOP 1 @Example = 4 FROM [dbo].[TableName] -- ^ constant.numeric -- ^^^^ keyword.other.DML +SELECT TOP(1) @Example = y FROM [dbo].[TableName] +-- ^^^ keyword.other.DML +-- ^^^ keyword.other.DML +-- ^ meta.group punctuation.section.parens.begin +-- ^ meta.group meta.number.integer.decimal constant.numeric.value +-- ^ meta.group punctuation.section.parens.end +-- ^^^^^^^^ variable.other.readwrite +-- ^ keyword.operator +-- ^ meta.column-name +-- ^^^^ keyword.other.DML +-- ^^^^^^^^^^^^^^^^^ meta.table-name + SET @Path = 'X:\nowayout\' --^ keyword.other.DML -- ^^^^^ variable.other.readwrite From adaaf66daf73aa2404947748997f8aacb3481bfa Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 18 Oct 2021 22:46:39 +0300 Subject: [PATCH 051/250] [SQL] improvements to Cassandra syntax --- SQL/Cassandra.sublime-syntax | 46 ++++- SQL/SQL (basic).sublime-syntax | 16 +- SQL/TSQL.sublime-syntax | 5 - SQL/tests/syntax/syntax_test_cassandra.cql | 219 ++++++++++++++++++++- 4 files changed, 274 insertions(+), 12 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 377a8e6237..9079a8078d 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -32,17 +32,37 @@ contexts: - match: \{ scope: punctuation.section.braces.begin.cql push: inside-dict-or-set + - match: \[ + scope: punctuation.section.brackets.begin.cql + push: inside-array - match: \b((?i:with))\s+(\w+)? captures: 1: keyword.other.cql 2: string.unquoted.cql - match: \b(?i:primary\s+key)\b scope: keyword.other.cql + - match: \b(?i:using\s+ttl)\b + scope: keyword.other.cql dml-statements: - - meta_append: true + - meta_prepend: true + - match: (?i:\bselect\s+json\b) + scope: keyword.other.DML.sql - match: \b(?i:allow filtering)\b scope: keyword.other.dml.cql + - match: \b(?i:copy)\b + scope: keyword.other.dml.cql + push: + - copy-from + - begin-group-or-pop + - table-name + - single-identifier-after-whitespace + + statements: + - meta_prepend: true + - include: use-db + - match: \b(?i:source)\b + scope: keyword.other.cql types: - meta_prepend: true @@ -75,6 +95,12 @@ contexts: - match: \w+ scope: meta.mapping.key.cql string.unquoted.cql + inside-array: + - match: \] + scope: punctuation.section.brackets.end.cql + pop: 1 + - include: expressions + ddl-create-target: - meta_prepend: true - match: \b(?i:with)\b @@ -121,3 +147,21 @@ contexts: joins: - match: \bjoin\b + + copy-from: + - match: \b(?i:from)\b + scope: keyword.other.cql + pop: 1 + - match: '' + pop: 1 + + built-in-scalar-function-calls: + - meta_append: true + - match: \b(?:token|uuid|now|toJson|TTL|WRITETIME|KEYS|ENTRIES|FULL)(?=\s*\() + scope: support.function.scalar.cql + push: begin-method-call-paren + + logical-operators: + - meta_append: true + - match: \b(?i:contains(?:\s+key)?)\b + scope: keyword.operator.logical.cql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 9385321ee2..aa244b6f78 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -192,7 +192,6 @@ contexts: scope: meta.number.integer.decimal.sql constant.numeric.value.sql expressions: - - include: types - match: (?i)\bas\b scope: keyword.operator.assignment.alias.sql push: @@ -205,6 +204,7 @@ contexts: - include: operators - include: built-in-aggregate-function-calls - include: built-in-scalar-function-calls + - include: types - include: user-defined-function-calls - include: begin-group - match: \) @@ -227,6 +227,11 @@ contexts: scope: punctuation.section.group.begin.sql push: inside-group + begin-group-or-pop: + - include: begin-group + - match: (?=\S) + pop: 1 + inside-case-expression: - meta_scope: meta.statement.conditional.case.sql - match: \b(?i:end)\b @@ -375,7 +380,7 @@ contexts: ddl-alter-table: - meta_scope: meta.alter.sql - - match: \b(?i:add(?:\s+column)?|alter\s+column)\b + - match: \b(?i:(?:add|drop)(?:\s+column)?|alter\s+column)\b scope: keyword.other.ddl.sql - include: ddl-alter-common - include: expressions-or-column-name @@ -445,6 +450,13 @@ contexts: scope: storage.modifier.sql - include: expressions-or-column-name + use-db: + - match: \b(?i:use)\b + scope: keyword.context.tsql + push: + - database-name + - single-identifier-after-whitespace + dml-delete: - match: (?=\S) set: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index c4b187af66..8f7a378104 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -786,11 +786,6 @@ contexts: - match: '' pop: 1 - begin-group-or-pop: - - include: begin-group - - match: (?=\S) - pop: 1 - filegroup-name: - meta_content_scope: meta.filegroup-name.tsql - match: '' diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index a1710b9c82..cad769229f 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -147,7 +147,10 @@ CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( -- <- meta.create meta.group.table-columns punctuation.section.group.end CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( userid uuid, - other_id uuid, + other_id timeuuid, +-- ^^^^^^^^ meta.column-name +-- ^^^^^^^^ storage.type +-- ^ punctuation.separator.sequence test int, PRIMARY KEY ((userid, other_id), test) -- ^^^^^^^^^^^ meta.create meta.group.table-columns keyword.other @@ -223,9 +226,18 @@ CREATE TYPE user_defined_type ( -- ^ meta.group punctuation.section.group.begin type1 timestamp, type2 text, - type3 text, - type4 text); - + type3 counter, +-- ^^^^^ meta.column-name +-- ^^^^^^^ storage.type + type4 boolean, +-- ^^^^^ meta.column-name +-- ^^^^^^^ storage.type + type5 blob, +-- ^^^^^ meta.column-name +-- ^^^^ storage.type + type6 inet); +-- ^^^^^ meta.column-name +-- ^^^^ storage.type INSERT INTO something_by_someid (someid, somebool, somemap) VALUES ( @@ -299,8 +311,207 @@ ALTER TABLE someentity_by_somefield -- ^^^^ storage.type -- ^ punctuation.terminator.statement +ALTER TABLE someentity_by_somefield + DROP unnecessryfield; +-- ^^^^^^^^^^^^^^^^^^^^ meta.alter +-- ^^^^ keyword.other.ddl +-- ^^^^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.terminator.statement + + select * from test_by_example join fred -- there are no joins in CQL -- <- - keyword --^^ - keyword + +USE killrvideo; +-- <- keyword.context +--^ keyword.context +-- ^^^^^^^^^^ meta.database-name +-- ^ punctuation.terminator.statement + +select uuid(), now(), * +-- ^^^^ meta.function-call support.function.scalar +-- ^ punctuation.separator.sequence +-- ^^^ meta.function-call support.function +-- ^ punctuation.separator.sequence +-- ^ variable.language.wildcard.asterisk +from test_by_example; + +COPY table1 (column1, column2, column3) FROM 'table1data.csv' +-- ^ keyword.other.dml +-- ^^^^^^ meta.table-name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group +-- ^ punctuation.section.group.begin +-- ^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.definition.string.begin +-- ^ punctuation.definition.string.end +WITH HEADER=true; +-- ^ keyword.other +-- ^^^^^^ string.unquoted +-- ^ keyword.operator +-- ^^^^ constant.language.boolean +-- ^ punctuation.terminator.statement + +TRUNCATE table1; +-- ^^^^^ keyword.other.DML +-- ^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +SOURCE './myscript.cql'; +-- ^^^ keyword.other +-- ^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.terminator.statement + +-- https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/cqlCreateIndex.html +CREATE TABLE myschema.users ( + userID uuid, + fname text, + lname text, + email text, + address text, + zip int, + state text, + PRIMARY KEY (userID) + ); + +CREATE INDEX user_state +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other +-- ^^^^^^^^^^ meta.toc-list.full-identifier + ON myschema.users (state); +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement + +CREATE INDEX ON myschema.users (zip); +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^ meta.column-name +-- ^ punctuation.section.group.end + +CREATE INDEX todo_dates ON users (KEYS(todo)); +-- ^^^^^ meta.create meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^ meta.function-call support.function.scalar +-- ^ punctuation.section.parens.begin +-- ^^^^ meta.column-name +-- ^ punctuation.section.parens.end +-- ^ punctuation.section.group.end + +CREATE INDEX entries_idx ON race (ENTRIES(race_wins)); +-- ^^^^ meta.create meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^^^^ meta.function-call support.function.scalar +-- ^ punctuation.section.parens.begin +-- ^^^^^^^^^ meta.column-name +-- ^ punctuation.section.parens.end +-- ^ punctuation.section.group.end + +CREATE INDEX rnumbers_idx ON cycling.race_starts (FULL(rnumbers)); +-- ^^^^^^^^^^^^^^^^^^^ meta.create meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^ meta.function-call support.function.scalar +-- ^ punctuation.section.parens.begin +-- ^^^^^^^^ meta.column-name +-- ^ punctuation.section.parens.end +-- ^ punctuation.section.group.end + +SELECT album, tags +FROM playlists +WHERE tags CONTAINS 'blues'; +-- ^^^^^^^^ keyword.operator.logical + +SELECT * +FROM playlists +WHERE venue CONTAINS KEY '2014-09-22 22:00:00-0700'; +-- ^^^^^^^^^^^^ keyword.operator.logical + +SELECT * +FROM cycling.birthday_list +WHERE blist['age'] = '23'; +-- ^^^^^ meta.column-name +-- ^ punctuation.section.brackets.begin +-- ^^^^^ string.quoted.single +-- ^ punctuation.section.brackets.end +-- ^ keyword.operator.comparison +-- ^^^^ string.quoted.single +-- ^ punctuation.terminator.statement + +SELECT * +FROM cycling.race_starts +WHERE rnumbers = [39,7,14]; +-- ^^^^^^^^ meta.column-name +-- ^ keyword.operator.comparison +-- ^ punctuation.section.brackets.begin +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.separator.sequence +-- ^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.separator.sequence +-- ^^ meta.number.integer.decimal constant.numeric.value +-- ^ punctuation.section.brackets.end +-- ^ punctuation.terminator.statement + +SELECT * +FROM ruling_stewards +WHERE (steward_name, king) = ('Boromir', 'Brego'); +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.separator.sequence +-- ^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.section.group.end +-- ^ keyword.operator.comparison +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^^^^ meta.group string.quoted.single +-- ^ meta.group punctuation.separator.sequence +-- ^^^^^^^ meta.group string.quoted.single +-- ^ meta.group punctuation.section.group.end +-- ^ punctuation.terminator.statement + +SELECT WRITETIME (first_name) +--^^^^ keyword.other.DML +-- ^^^^^^^^^ meta.function-call support.function +FROM users +WHERE last_name = 'Jones'; + +INSERT INTO cycling.calendar (race_id, race_name, race_start_date, race_end_date) +VALUES (200, 'placeholder', '2015-05-27', '2015-05-27') +USING TTL; +-- ^^^^^^ keyword.other +-- ^ punctuation.terminator.statement + +UPDATE cycling.calendar +USING TTL 300 +-- ^^^^^^ keyword.other +-- ^^^ meta.number.integer.decimal constant.numeric.value +SET race_name = 'dummy' +-- <- keyword.other.DML +WHERE race_id = 200 + AND race_start_date = '2015-05-27' + AND race_end_date = '2015-05-27'; + +SELECT TTL(race_name) +-- ^^^ meta.function-call support.function +FROM cycling.calendar +WHERE race_id=200; + +-- https://docs.datastax.com/en/cql-oss/3.x/cql/cql_using/useQueryJSON.html +select json name, checkin_id, timestamp from checkin; +-- ^^^^^^^^ keyword.other.DML + +select name, checkin_id, toJson(timestamp) from checkin; +-- ^^^^^^ meta.function-call support.function From 488ee10780969474cb802d020d0d482e5d4fb3d1 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 23 Oct 2021 22:51:04 +0300 Subject: [PATCH 052/250] Apply suggestions from code review Co-authored-by: deathaxe --- SQL/Cassandra.sublime-syntax | 12 ++++++------ SQL/SQL (basic).sublime-syntax | 33 +++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 9079a8078d..5a66715eda 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -9,12 +9,12 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: simple_types: |- - (?ix:\b(?: - (ASCII|BIGINT|BLOB|BOOLEAN|COUNTER|DATE| - DECIMAL|DOUBLE|DURATION|FLOAT|INET|INT| - SMALLINT|TEXT|TIME|TIMESTAMP|TIMEUUID|TINYINT| - UUID|VARCHAR|VARINT) - )\b) + simple_types: |- + \b(?ix: + ASCII | BIGINT | BLOB | BOOLEAN | COUNTER | DATE | DECIMAL | DOUBLE + | DURATION | FLOAT | INET | INT | SMALLINT | TEXT | TIME | TIMESTAMP + | TIMEUUID | TINYINT | UUID | VARCHAR | VARINT + )\b types_with_optional_number: (?!) #reserved: (?:;) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index aa244b6f78..f64a4b7e8d 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -36,7 +36,7 @@ contexts: block-comments: - meta_include_prototype: false - - match: /\* + - match: /\*+ scope: punctuation.definition.comment.begin.sql push: inside-comment-block @@ -49,10 +49,10 @@ contexts: inside-comment-block: - meta_include_prototype: false - meta_scope: comment.block.sql - - match: \*/ + - match: \*+/ scope: punctuation.definition.comment.end.sql pop: 1 - - match: ^\s*(\*)(?!/) + - match: ^\s*(\*)(?!\**/) captures: 1: punctuation.definition.comment.sql @@ -69,7 +69,7 @@ contexts: single-quoted-string: - meta_include_prototype: false - meta_scope: string.quoted.single.sql - - match: (?:'') + - match: \'\' scope: constant.character.escape.sql - match: \' scope: punctuation.definition.string.end.sql @@ -77,6 +77,7 @@ contexts: - include: string-escape identifier-create: + - meta_include_prototype: false - meta_scope: meta.toc-list.full-identifier.sql entity.name.function.sql - match: '' pop: 1 @@ -86,6 +87,7 @@ contexts: set: single-identifier single-identifier: + - meta_include_prototype: false - include: pop-on-top-level-reserved-word - match: '' set: @@ -148,12 +150,12 @@ contexts: set: single-identifier-after-whitespace dml-condition: - - match: (?i:\b(if)\b) + - match: \b(?i:if)\b scope: keyword.control.flow.sql - include: logical-operators logical-operators: - - match: (?i:\b(and|or|having|exists|between|in|not|is)\b) + - match: \b(?i:and|or|having|exists|between|in|not|is)\b scope: keyword.operator.logical.sql operators: @@ -192,7 +194,7 @@ contexts: scope: meta.number.integer.decimal.sql constant.numeric.value.sql expressions: - - match: (?i)\bas\b + - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql push: - column-alias @@ -216,9 +218,9 @@ contexts: numbers-variables-and-strings: - include: numbers - - match: (?i)\b(?:true|false)\b + - match: \b(?i:true|false)\b scope: constant.language.boolean.sql - - match: (?i:\bnull\b) + - match: \b(?i:null)\b scope: constant.language.null.sql - include: strings @@ -237,7 +239,7 @@ contexts: - match: \b(?i:end)\b scope: keyword.control.conditional.end.sql pop: 1 - - match: \b(?i)(case)\s+(when)\b + - match: \b(?i:(case)\s+(when))\b captures: 1: keyword.control.conditional.case.sql 2: keyword.control.conditional.when.sql @@ -251,13 +253,13 @@ contexts: built-in-aggregate-function-calls: # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - - match: (?i)\b(?:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() + - match: \b(?i:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() scope: support.function.aggregate.sql push: begin-method-call-paren built-in-scalar-function-calls: # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - - match: (?i)\b(?:CURRENT_(?:DATE|TIME(?:STAMP)?|USER)|(?:SESSION|SYSTEM)_USER)\b + - match: \b(?i:CURRENT_(?:DATE|TIME(?:STAMP)?|USER)|(?:SESSION|SYSTEM)_USER)\b scope: support.function.scalar.sql user-defined-function-calls: @@ -315,7 +317,7 @@ contexts: - ddl-create-target - create-condition - ddl-target - - match: (?i:\bdrop\s+table\b) + - match: \b(?i:drop\s+table)\b scope: keyword.other.ddl.sql push: ddl-drop-table - match: \b(?i:drop)\b @@ -335,7 +337,7 @@ contexts: push: - ddl-alter-target - ddl-target - - match: (?i:\b(grant(\swith\sgrant\soption)?|revoke)\b) + - match: \b(?i:grant(?:\swith\sgrant\soption)?|revoke)\b scope: keyword.other.authorization.sql ddl-create-target: @@ -354,6 +356,7 @@ contexts: set: inside-ddl-table-creation-columns ddl-drop-target: + - meta_include_prototype: false - meta_scope: meta.drop.sql - match: '' pop: 1 @@ -530,6 +533,7 @@ contexts: - table-valued-function-call table-name-not-function-call: + - meta_include_prototype: false - match: '' push: - fail-if-function-call @@ -584,6 +588,7 @@ contexts: scope: keyword.operator.assignment.sql table-valued-function-call: + - meta_include_prototype: false - match: '' set: - maybe-table-alias From 73c8870cb95ebbc58746f7e4936f724d35ce8116 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 23 Oct 2021 22:52:16 +0300 Subject: [PATCH 053/250] [SQL] improvements from code review --- SQL/Cassandra.sublime-syntax | 19 ++++++++----------- SQL/MySQL.sublime-syntax | 4 ++-- SQL/SQL (basic).sublime-syntax | 22 +++++++++++++++------- SQL/tests/syntax/syntax_test_cassandra.cql | 10 +++++----- SQL/tests/syntax/syntax_test_mysql.sql | 3 +++ 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 5a66715eda..e2023f3409 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -8,7 +8,6 @@ version: 2 extends: Packages/SQL/SQL (basic).sublime-syntax variables: - simple_types: |- simple_types: |- \b(?ix: ASCII | BIGINT | BLOB | BOOLEAN | COUNTER | DATE | DECIMAL | DOUBLE @@ -16,7 +15,12 @@ variables: | TIMEUUID | TINYINT | UUID | VARCHAR | VARINT )\b types_with_optional_number: (?!) - #reserved: (?:;) + ddl_target: |- + (?xi) + \b(?: + function|index|keyspace|table|type|user + |(?:materialized\s+)?view + )\b contexts: expressions: @@ -40,7 +44,7 @@ contexts: 1: keyword.other.cql 2: string.unquoted.cql - match: \b(?i:primary\s+key)\b - scope: keyword.other.cql + scope: storage.modifier.cql - match: \b(?i:using\s+ttl)\b scope: keyword.other.cql @@ -78,13 +82,6 @@ contexts: scope: storage.type.cql punctuation.definition.generic.end.cql pop: 1 - ddl-target: - - meta_prepend: true - - match: \b(?i:keyspace)\b - scope: keyword.other.cql - - match: \b(?i:materialized)\b - scope: keyword.other.cql - inside-dict-or-set: - match: \} scope: punctuation.section.braces.end.cql @@ -118,7 +115,7 @@ contexts: pop: 1 - match: ((?i:\bprimary\s+key))\s*(\() captures: - 1: keyword.other.cql + 1: storage.modifier.cql 2: meta.group.cql punctuation.section.group.begin.cql push: partition-key - match: \b(?i:primary\s+key)\b diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index c711710dc0..762a134814 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -47,7 +47,7 @@ contexts: inside-double-quoted-string: - meta_include_prototype: false - - meta_scope: string.quoted.double.sql + - meta_scope: meta.string.mysql string.quoted.double.sql - match: '""' scope: constant.character.escape.sql - match: '"' @@ -172,8 +172,8 @@ contexts: scope: keyword.other.DML.sql table-name-or-subquery: - - meta_include_prototype: false - meta_prepend: true + - meta_include_prototype: false - match: (?=#) pop: 1 - include: comments diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index f64a4b7e8d..acd013244f 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -12,6 +12,13 @@ variables: additional_reserved: (?!) simple_types: (?i:\b(?:bit|bool|boolean|datetime|int)\b) types_with_optional_number: (?i:\b(?:n?char|number|n?varchar|varbinary)\b) + ddl_target: |- + (?xi) + \b + (?:aggregate|conversion|database|domain|function|group| + (?:(?:fulltext|spatial|unique)\s+)?index| + language|operator class|operator|procedure|rule| + schema|sequence|table(?:space)?|trigger|type|user|view)\b contexts: prototype: @@ -362,13 +369,7 @@ contexts: pop: 1 ddl-target: - - match: |- - (?xi) - \b - (?:aggregate|conversion|database|domain|function|group| - (?:(?:fulltext|spatial|unique)\s+)?index| - language|operator class|operator|procedure|rule| - schema|sequence|table(?:space)?|trigger|type|user|view)\b + - match: '{{ddl_target}}' scope: keyword.other.sql - match: (?=\S) pop: 1 @@ -484,36 +485,43 @@ contexts: - table-name-or-subquery column-name: + - meta_include_prototype: false - meta_content_scope: meta.column-name.sql - match: '' pop: 1 column-alias: + - meta_include_prototype: false - meta_content_scope: meta.column-alias.sql - match: '' pop: 1 database-name: + - meta_include_prototype: false - meta_content_scope: meta.database-name.sql - match: '' pop: 1 table-name: + - meta_include_prototype: false - meta_content_scope: meta.table-name.sql - match: '' pop: 1 table-alias-name: + - meta_include_prototype: false - meta_content_scope: meta.table-alias-name.sql - match: '' pop: 1 procedure-name: + - meta_include_prototype: false - meta_content_scope: meta.procedure-name.sql - match: '' pop: 1 constraint-name: + - meta_include_prototype: false - meta_content_scope: meta.constraint-name.sql - match: '' pop: 1 diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index cad769229f..700e817098 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -107,7 +107,7 @@ CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( -- ^ punctuation.separator.sequence PRIMARY KEY(userid) -- ^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns --- ^^^^^^^^^^^ keyword.other +-- ^^^^^^^^^^^ storage.modifier -- ^ meta.group punctuation.section.group.begin -- ^^^^^^ meta.group.partition-key meta.column-name -- ^ meta.group.partition-key punctuation.section.group.end @@ -119,7 +119,7 @@ CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( other_id uuid, test text, PRIMARY KEY(userid, other_id) --- ^^^^^^^^^^^ meta.create meta.group.table-columns keyword.other +-- ^^^^^^^^^^^ meta.create meta.group.table-columns storage.modifier -- ^ punctuation.section.group.begin -- ^^^^^^ meta.group.partition-key meta.column-name -- ^^^^^^^^^^^ - meta.group.partition-key @@ -133,7 +133,7 @@ CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( other_id uuid, test text, PRIMARY KEY ((userid), other_id) --- ^^^^^^^^^^^ meta.create meta.group.table-columns keyword.other +-- ^^^^^^^^^^^ meta.create meta.group.table-columns storage.modifier -- ^ punctuation.section.group.begin -- ^^^^^^^^ meta.group.partition-key -- ^ punctuation.section.group.begin @@ -153,7 +153,7 @@ CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( -- ^ punctuation.separator.sequence test int, PRIMARY KEY ((userid, other_id), test) --- ^^^^^^^^^^^ meta.create meta.group.table-columns keyword.other +-- ^^^^^^^^^^^ meta.create meta.group.table-columns storage.modifier -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^^^^^^^^ meta.group.partition-key -- ^ punctuation.section.group.begin @@ -204,7 +204,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS FROM foo WHERE bar IS NOT NULL PRIMARY KEY (foo_id, bar_id) --- ^^^^^^^^^^^ keyword.other +-- ^^^^^^^^^^^ storage.modifier -- ^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^ meta.column-name diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index bd1ce67b8a..3806ddb9e4 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -10,7 +10,10 @@ SELECT 'Foo '' Bar'; -- ^^ constant.character.escape.sql SELECT "My "" Crazy Column Name" FROM my_table; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double +-- ^ punctuation.definition.string.begin -- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end SELECT "My -- Crazy Column Name" FROM my_table; -- ^^ - comment - punctuation From caa1cb738541ed3bc2d9c44310a1ca6c92080570 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 23 Oct 2021 23:01:57 +0300 Subject: [PATCH 054/250] Apply suggestions from code review Co-authored-by: deathaxe --- SQL/SQL (basic).sublime-syntax | 1 + 1 file changed, 1 insertion(+) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index acd013244f..fbca8302ec 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -605,6 +605,7 @@ contexts: - single-identifier table-valued-function-name: + - meta_include_prototype: false - meta_content_scope: meta.table-valued-function-name.sql - match: '' pop: 1 From 6c4ffeabbfc4d5093e5b43dc922d5d4612bd4395 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 23 Oct 2021 22:59:02 +0300 Subject: [PATCH 055/250] [SQL] tweak to Cassandra "select json" scope --- SQL/Cassandra.sublime-syntax | 6 ++++-- SQL/tests/syntax/syntax_test_cassandra.cql | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index e2023f3409..d50f3b8d2d 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -50,8 +50,10 @@ contexts: dml-statements: - meta_prepend: true - - match: (?i:\bselect\s+json\b) - scope: keyword.other.DML.sql + - match: \b(?i:(select)\s+(json))\b + captures: + 1: keyword.other.DML.sql + 2: storage.modifier.cql - match: \b(?i:allow filtering)\b scope: keyword.other.dml.cql - match: \b(?i:copy)\b diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 700e817098..dcab84e667 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -511,7 +511,8 @@ WHERE race_id=200; -- https://docs.datastax.com/en/cql-oss/3.x/cql/cql_using/useQueryJSON.html select json name, checkin_id, timestamp from checkin; --- ^^^^^^^^ keyword.other.DML +-- ^^^ keyword.other.DML +-- ^^^^ storage.modifier select name, checkin_id, toJson(timestamp) from checkin; -- ^^^^^^ meta.function-call support.function From 0c3df74e3b68d605214fd50a5e27cb3e3ab39ef1 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 23 Oct 2021 23:03:20 +0300 Subject: [PATCH 056/250] [SQL] add meta_include_prototype false to name contexts --- SQL/TSQL.sublime-syntax | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 8f7a378104..d36466f9a9 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -754,6 +754,7 @@ contexts: - single-identifier function-name: + - meta_include_prototype: false - meta_content_scope: variable.function.tsql - match: '' pop: 1 @@ -782,11 +783,13 @@ contexts: - single-identifier index-name: + - meta_include_prototype: false - meta_content_scope: meta.index-name.tsql - match: '' pop: 1 filegroup-name: + - meta_include_prototype: false - meta_content_scope: meta.filegroup-name.tsql - match: '' pop: 1 From 843f7083d6f264f4940503deb055f1a58ae75c8b Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 23 Oct 2021 23:08:45 +0300 Subject: [PATCH 057/250] [SQL] make ignore case/word boundary order consistent --- SQL/Cassandra.sublime-syntax | 2 +- SQL/MySQL.sublime-syntax | 16 ++++++++-------- SQL/SQL (basic).sublime-syntax | 20 ++++++++++---------- SQL/TSQL.sublime-syntax | 14 +++++++------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index d50f3b8d2d..8348cf6fe6 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -115,7 +115,7 @@ contexts: - match: \) scope: punctuation.section.group.end.sql pop: 1 - - match: ((?i:\bprimary\s+key))\s*(\() + - match: \b(?i:(primary\s+key))\s*(\() captures: 1: storage.modifier.cql 2: meta.group.cql punctuation.section.group.begin.cql diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 762a134814..38784bf029 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -98,7 +98,7 @@ contexts: types: - meta_append: true - - match: (?i:\bwith(?:out)?\s+time\s+zone\b) + - match: \b(?i:with(?:out)?\s+time\s+zone)\b scope: storage.type.sql inside-number-sign-comment: @@ -109,14 +109,14 @@ contexts: expressions: - meta_prepend: true - - match: (?i)\b(?:CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b + - match: \b(?i:CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b scope: support.function.string.sql - - match: (?i)\b(?:using)\b + - match: \b(?i:using)\b scope: keyword.other.mysql statements: - meta_append: true - - match: (?i:\b(begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b) + - match: \b(?i:begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b scope: keyword.other.LUW.sql ddl-statements: @@ -130,12 +130,12 @@ contexts: dml-statements: - meta_append: true - - match: (?i:\binsert(\s+(?:ignore\s+)?into)?\b) + - match: \b(?i:insert(\s+(?:ignore\s+)?into)?)\b scope: keyword.other.DML.sql push: - table-name - single-identifier-after-whitespace - - match: (?i)\b(?:limit)\b + - match: \b(?i:limit)\b scope: keyword.other.DML.sql ddl-target-common: @@ -144,9 +144,9 @@ contexts: push: - table-name - single-identifier-after-whitespace - - match: (?i)\b(?:using)\b + - match: \b(?i:using)\b scope: keyword.other.mysql - - match: \b((?i:algorithm))\s*(=) + - match: \b(?i:(algorithm))\s*(=) captures: 1: keyword.other.mysql 2: keyword.operator.assignment.mysql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index fbca8302ec..a2e8bcfa04 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -405,25 +405,25 @@ contexts: - include: pop-on-top-level-reserved-word dml-statements: - - match: (?i:\bselect\b) + - match: \b(?i:select)\b scope: keyword.other.DML.sql - - match: (?i:\bunion(?:\s+all)?\b) + - match: \b(?i:union(?:\s+all)?)\b scope: keyword.other.DML.sql - - match: (?i:\b(?:delete(?:\s+from)?)\b) + - match: \b(?i:(?:delete(?:\s+from)?))\b scope: keyword.other.DML.sql set: dml-delete - - match: (?i:\b(?:update)\b) + - match: \b(?i:update)\b scope: keyword.other.DML.sql set: dml-update - - match: (?i:\b(?:insert\s+into|truncate)\b) + - match: \b(?i:(?:insert\s+into|truncate))\b scope: keyword.other.DML.sql push: - table-name - single-identifier-after-whitespace - - match: (?i:\bset\b) + - match: \b(?i:set)\b scope: keyword.other.DML.sql push: set - - match: (?i:\b(?:default\s+)?values\b) + - match: \b(?i:(?:default\s+)?values)\b scope: keyword.other.DML.II.sql - include: distinct - include: joins @@ -440,17 +440,17 @@ contexts: - match: \) scope: punctuation.section.group.end.sql pop: 1 - - match: (?i:\bconstraint\b) + - match: \b(?i:constraint)\b scope: storage.modifier.sql push: - constraint-name - single-identifier-after-whitespace - - match: (?i:\breferences\b) + - match: \b(?i:references)\b scope: storage.modifier.sql push: - table-name - single-identifier-after-whitespace - - match: (?i:\b(((?:foreign|fulltext|primary|unique)\s+)?key|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|default)\b) + - match: \b(?i:(((?:foreign|fulltext|primary|unique)\s+)?key|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|default))\b scope: storage.modifier.sql - include: expressions-or-column-name diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index d36466f9a9..754590f5cc 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -53,7 +53,7 @@ contexts: operators: - meta_append: true - - match: (?i:\blike\b) + - match: \b(?i:like)\b scope: keyword.operator.logical.sql branch_point: like-strings-branch branch: @@ -151,13 +151,13 @@ contexts: scope: keyword.operator.wildcard.sql like-escape-fail: - - match: (?i:\bescape\b) + - match: \b(?i:escape)\b fail: like-strings-branch - match: (?=\S) pop: 1 like-escape-pop: - - match: (?i:\bescape\b) + - match: \b(?i:escape)\b scope: keyword.operator.word.sql pop: 1 - match: (?=\S) @@ -304,7 +304,7 @@ contexts: - meta_append: true - match: \b(?i:bulk\s+insert)\b scope: keyword.other.tsql - - match: (?i:\binsert\b) + - match: \b(?i:insert)\b scope: keyword.other.DML.sql push: [table-name, single-identifier-after-whitespace] - match: \b(?i:into)\b(?!\s*@) @@ -368,7 +368,7 @@ contexts: - expect-procedure-name ddl-create-target-expect-as: - - match: (?i:\bas\b) + - match: \b(?i:as)\b scope: keyword.context.block.sql pop: 1 - match: \b(?i:returns)\b @@ -612,7 +612,7 @@ contexts: set: cte-as cte-as: - - match: (?i:\bas\b) + - match: \b(?i:as)\b scope: keyword.operator.assignment.cte.tsql - include: pop-on-top-level-reserved-word - match: ',' @@ -650,7 +650,7 @@ contexts: scope: keyword.other.tsql - match: \b(?i:then)\b scope: keyword.other.tsql - - match: (?i:\binsert\b)(?=\s*\() + - match: \b(?i:insert)\b(?=\s*\() scope: keyword.other.DML.sql push: values-or-expressions - include: dml-statements From 16e9e12575512848205cdc4f6bd9c601e0ed84c7 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 23 Oct 2021 23:12:32 +0300 Subject: [PATCH 058/250] [SQL] make keyword.other.DML scope lowercase to match all other scopes --- Markdown/syntax_test_markdown.md | 2 +- PHP/tests/syntax_test_php.php | 18 +- Python/syntax_test_python_strings.py | 32 ++-- SQL/Cassandra.sublime-syntax | 2 +- SQL/MySQL.sublime-syntax | 6 +- SQL/SQL (basic).sublime-syntax | 22 +-- SQL/TSQL.sublime-syntax | 22 +-- SQL/tests/syntax/syntax_test_cassandra.cql | 24 +-- SQL/tests/syntax/syntax_test_mysql.sql | 10 +- SQL/tests/syntax/syntax_test_postgres.sql | 14 +- SQL/tests/syntax/syntax_test_tsql.sql | 182 ++++++++++----------- 11 files changed, 167 insertions(+), 167 deletions(-) diff --git a/Markdown/syntax_test_markdown.md b/Markdown/syntax_test_markdown.md index a2cc25873d..0dfc2f2d88 100644 --- a/Markdown/syntax_test_markdown.md +++ b/Markdown/syntax_test_markdown.md @@ -2580,7 +2580,7 @@ okay | ^^^ constant.other.language-name SELECT * |^^^^^^^^ markup.raw.code-fence.sql -|^^^^^ keyword.other.DML.sql +|^^^^^ keyword.other.dml.sql FROM TableName ``` |^^ meta.code-fence.definition.end.sql punctuation.definition.raw.code-fence.end - markup diff --git a/PHP/tests/syntax_test_php.php b/PHP/tests/syntax_test_php.php index 07138d93d4..714086e481 100644 --- a/PHP/tests/syntax_test_php.php +++ b/PHP/tests/syntax_test_php.php @@ -1649,11 +1649,11 @@ function generate2() // Do not highlight plain SQL indicator as SQL $sql = "SELECT"; -// ^^^^^^ - keyword.other.DML +// ^^^^^^ - keyword.other.dml $sql = " SELECT -// ^^^^^^ keyword.other.DML +// ^^^^^^ keyword.other.dml * FROM users WHERE first_name = 'Eric' @@ -1662,7 +1662,7 @@ function generate2() $sql = "SELECT * FROM users WHERE first_name = 'Eric'"; // ^ meta.string.php string.quoted.double.php punctuation.definition.string.begin.php - meta.interpolation - string string // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php meta.interpolation.php source.sql - string.quoted.double.php -// ^ keyword.other.DML +// ^ keyword.other.dml // ^^^^^^ string.quoted.single.sql // ^ meta.string.php string.quoted.double.php punctuation.definition.string.end.php - meta.interpolation - string string @@ -1670,14 +1670,14 @@ function generate2() $sql = "SELECT * FROM users WHERE first_name = 'Eric"; // ^ meta.string.php string.quoted.double.php punctuation.definition.string.begin.php - meta.interpolation - string string // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php meta.interpolation.php source.sql - string.quoted.double.php -// ^ keyword.other.DML +// ^ keyword.other.dml // ^^^^^ string.quoted.single.sql // ^ meta.string.php string.quoted.double.php punctuation.definition.string.end.php - meta.interpolation - string string $sql = " SELECT * FROM users WHERE first_name = 'Eric' //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php meta.interpolation.php source.sql - string.quoted.double.php -// ^ keyword.other.DML +// ^ keyword.other.dml // ^^^^^^ string.quoted.single.sql "; // <- meta.string.php string.quoted.double.php punctuation.definition.string.end.php - meta.interpolation - string string @@ -1691,7 +1691,7 @@ function generate2() $sql = 'SELECT * FROM users WHERE first_name = \'Eric\''; // ^ meta.string.php string.quoted.single.php punctuation.definition.string.begin.php - meta.interpolation - string string // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php meta.interpolation.php source.sql - string.quoted.single.php -// ^ keyword.other.DML +// ^ keyword.other.dml // ^^ constant.character.escape.php // ^^ constant.character.escape.php // ^ meta.string.php string.quoted.single.php punctuation.definition.string.end.php - meta.interpolation - string string @@ -1699,7 +1699,7 @@ function generate2() $sql = ' SELECT * FROM users WHERE first_name = \'Eric\' //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php meta.interpolation.php source.sql - string.quoted.single.php -// ^ keyword.other.DML +// ^ keyword.other.dml // ^^ constant.character.escape.php '; // <- meta.string.php string.quoted.single.php punctuation.definition.string.end.php - meta.interpolation - string string @@ -1889,7 +1889,7 @@ function generate2() // ^^^ entity.name.tag.heredoc SELECT * FROM users WHERE first_name = 'John' LIMIT $limit //^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.sql source.sql -// <- keyword.other.DML +// <- keyword.other.dml // ^ variable.language.wildcard.asterisk // ^^^^^^ string.quoted.single // ^^^^^^ variable.other.php @@ -1906,7 +1906,7 @@ function generate2() // ^^^ entity.name.tag.heredoc SELECT * FROM users WHERE first_name = 'John'\n //^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.sql source.sql -// <- keyword.other.DML +// <- keyword.other.dml // ^ variable.language.wildcard.asterisk // ^^^^^^ string.quoted.single // ^^ - constant.character.escape.php diff --git a/Python/syntax_test_python_strings.py b/Python/syntax_test_python_strings.py index d3e9a3a6b4..7bb8382d83 100644 --- a/Python/syntax_test_python_strings.py +++ b/Python/syntax_test_python_strings.py @@ -30,61 +30,61 @@ # ^^ invalid.deprecated.character.escape.python conn.execute("SELECT * FROM foobar") -# ^ meta.string.python keyword.other.DML.sql +# ^ meta.string.python keyword.other.dml.sql conn.execute('SELECT * FROM foobar') -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql conn.execute(U"SELECT * FROM foobar") -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql conn.execute(U'SELECT * FROM foobar') -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # In this example, the Python string is not raw, so \t is a python escape conn.execute(u"SELECT * FROM foobar WHERE foo = '\t'") -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # ^ constant.character.escape.python conn.execute(u'SELECT * FROM foobar') -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # In this example, the Python string is raw, so the \b should be a SQL escape conn.execute(r"SELECT * FROM foobar WHERE baz = '\b") -# ^ meta.string.python keyword.other.DML.sql +# ^ meta.string.python keyword.other.dml.sql # ^ constant.character.escape.sql # This tests to ensure the Python placeholder will be highlighted even in a raw SQL string conn.execute(r'SELECT * FROM foobar WHERE %s') -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # ^ constant.other.placeholder.python conn.execute(r"SELECT * FROM foobar") -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql conn.execute(r'SELECT * FROM foobar') -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql conn.execute(r"""SELECT * FROM foobar WHERE %s and foo = '\t'""") -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # ^ constant.other.placeholder.python # ^ constant.character.escape.sql # Capital R prevents all syntax embedding conn.execute(R'SELECT * FROM foobar') -# ^ meta.string.python - keyword.other.DML.sql +# ^ meta.string.python - keyword.other.dml.sql conn.execute(R"SELECT * FROM foobar") -# ^ - keyword.other.DML.sql +# ^ - keyword.other.dml.sql conn.execute(R"""SELECT * FROM foobar""") -# ^ - keyword.other.DML.sql +# ^ - keyword.other.dml.sql conn.execute(r'''SELECT * FROM foobar''') -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql conn.execute(u"""SELECT * FROM foobar WHERE %s and foo = '\t'""") -# ^ keyword.other.DML.sql +# ^ keyword.other.dml.sql # ^ constant.other.placeholder.python # ^ constant.character.escape.python diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 8348cf6fe6..046854adc1 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -52,7 +52,7 @@ contexts: - meta_prepend: true - match: \b(?i:(select)\s+(json))\b captures: - 1: keyword.other.DML.sql + 1: keyword.other.dml.sql 2: storage.modifier.cql - match: \b(?i:allow filtering)\b scope: keyword.other.dml.cql diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 38784bf029..1ac2eeb894 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -131,12 +131,12 @@ contexts: dml-statements: - meta_append: true - match: \b(?i:insert(\s+(?:ignore\s+)?into)?)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: - table-name - single-identifier-after-whitespace - match: \b(?i:limit)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql ddl-target-common: - match: \b(?i:on)\b @@ -169,7 +169,7 @@ contexts: joins: - meta_append: true - match: (?i)\b(?:straight_join|natural)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql table-name-or-subquery: - meta_prepend: true diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index a2e8bcfa04..a30bf666d1 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -406,31 +406,31 @@ contexts: dml-statements: - match: \b(?i:select)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql - match: \b(?i:union(?:\s+all)?)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql - match: \b(?i:(?:delete(?:\s+from)?))\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql set: dml-delete - match: \b(?i:update)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql set: dml-update - match: \b(?i:(?:insert\s+into|truncate))\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: - table-name - single-identifier-after-whitespace - match: \b(?i:set)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: set - match: \b(?i:(?:default\s+)?values)\b - scope: keyword.other.DML.II.sql + scope: keyword.other.dml.II.sql - include: distinct - include: joins - match: \b(?i:group\s+by|order\s+by|having|where)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql - match: \b(?i:from)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: table-name-or-subquery - match: (?i)\b(asc|desc)\b scope: keyword.other.order.sql @@ -475,11 +475,11 @@ contexts: distinct: - match: \b(?i:distinct)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql joins: - match: (?i)\b(?:(?:inner|(?:full|left\s+)?outer|cross|left|right)\s+)?join\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: - join-on - table-name-or-subquery diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 754590f5cc..547c4bd66a 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -305,10 +305,10 @@ contexts: - match: \b(?i:bulk\s+insert)\b scope: keyword.other.tsql - match: \b(?i:insert)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: [table-name, single-identifier-after-whitespace] - match: \b(?i:into)\b(?!\s*@) - scope: keyword.other.DML.tsql + scope: keyword.other.dml.tsql push: [table-name, single-identifier-after-whitespace] - match: \b(?i:into)\b scope: keyword.other.tsql @@ -320,7 +320,7 @@ contexts: - include: top - match: \b(?i:(option))\b\s*(\() captures: - 1: keyword.other.DML.tsql + 1: keyword.other.dml.tsql 2: meta.group.sql punctuation.section.group.begin.sql push: inside-with-group - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b @@ -379,11 +379,11 @@ contexts: top: - match: (?i)\b(top)\b(?:\s*(?:(\()\s*)?(\d+)(?:\s*(\)))?(?:\s+(percent\b))?)? captures: - 1: keyword.other.DML.tsql + 1: keyword.other.dml.tsql 2: meta.group.tsql punctuation.section.parens.begin.tsql 3: meta.group.tsql meta.number.integer.decimal.tsql constant.numeric.value.tsql 4: meta.group.tsql punctuation.section.parens.end.tsql - 5: keyword.other.DML.tsql + 5: keyword.other.dml.tsql dml-delete: - meta_prepend: true @@ -467,13 +467,13 @@ contexts: cte-with: - match: (?i)\bwith\b(?=\s*(?:\[\w+\]|\w+)\s*\() - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: - cte-column-list-begin - cte-table-name - single-identifier - match: (?i)\bwith\b #(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: - cte-as - cte-table-name @@ -481,7 +481,7 @@ contexts: with: - match: (?i)\bwith\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: with-paren-or-pop with-paren-or-pop: @@ -572,7 +572,7 @@ contexts: joins: - meta_append: true - match: (?i)\b(?:(?:cross|outer)\s+)?apply\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: table-name-or-subquery table-name-or-subquery: @@ -651,7 +651,7 @@ contexts: - match: \b(?i:then)\b scope: keyword.other.tsql - match: \b(?i:insert)\b(?=\s*\() - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql push: values-or-expressions - include: dml-statements - include: pop-on-top-level-reserved-word @@ -716,7 +716,7 @@ contexts: expect-cursor-select-statement: - meta_content_scope: meta.cursor-declaration.tsql - match: \b(?i:select)\b - scope: keyword.other.DML.sql + scope: keyword.other.dml.sql set: after-cursor-select-statement - match: (?=\S) pop: 1 diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index dcab84e667..a009ae96dc 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -19,7 +19,7 @@ CREATE KEYSPACE killrvideo WITH replication = {'class':'SimpleStrategy', 'replic -- ^ punctuation.terminator.statement select someid, token(someid), something ---^^^^ keyword.other.DML +--^^^^ keyword.other.dml -- ^^^^^^ meta.column-name -- ^ punctuation.separator.sequence -- ^^^^^ meta.function-call support.function @@ -29,10 +29,10 @@ select someid, token(someid), something -- ^ punctuation.separator.sequence -- ^^^^^^^^^ meta.column-name from something_by_someid ---^^ keyword.other.DML +--^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^ meta.table-name where token(someid) >= token(d821d7d8-8265-402e-9a72-c61ab8473ab6) ---^^^ keyword.other.DML +--^^^ keyword.other.dml -- ^^^^^^^^^^^^^ meta.function-call -- ^^^^^ support.function -- ^^^^^^^^ meta.group @@ -57,7 +57,7 @@ limit 2000; select count(someid) from something_by_someid where something = 'abc' --- ^^ keyword.other.DML +-- ^^ keyword.other.dml -- ^^^^^^^^^ meta.column-name -- ^ keyword.operator.comparison -- ^^^^^ string.quoted.single @@ -67,7 +67,7 @@ allow filtering; -- ^ punctuation.terminator.statement insert into something_by_countrycode (someid, countrycode) values (:someid, :countrycode); --- ^^^^^^^^ keyword.other.DML +-- ^^^^^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.group.begin @@ -75,7 +75,7 @@ insert into something_by_countrycode (someid, countrycode) values (:someid, :cou -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^ meta.column-name -- ^ punctuation.section.group.end --- ^^^^^^ keyword.other.DML.II +-- ^^^^^^ keyword.other.dml.II -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^^ variable.other.constant @@ -199,7 +199,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS -- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function -- ^^ keyword.operator.assignment.alias SELECT * --- ^^^^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml -- ^ variable.language.wildcard.asterisk FROM foo WHERE bar IS NOT NULL @@ -283,7 +283,7 @@ PRIMARY KEY (entityid, datecreated, somefield) --^^^^^^^^^^^^^^^^ meta.create -- ^^^ keyword.other -- ^^^^^^^^^^ keyword.other --- ^^^^^^^^ keyword.other.DML +-- ^^^^^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^ meta.column-name @@ -362,7 +362,7 @@ WITH HEADER=true; -- ^ punctuation.terminator.statement TRUNCATE table1; --- ^^^^^ keyword.other.DML +-- ^^^^^ keyword.other.dml -- ^^^^^^ meta.table-name -- ^ punctuation.terminator.statement @@ -483,7 +483,7 @@ WHERE (steward_name, king) = ('Boromir', 'Brego'); -- ^ punctuation.terminator.statement SELECT WRITETIME (first_name) ---^^^^ keyword.other.DML +--^^^^ keyword.other.dml -- ^^^^^^^^^ meta.function-call support.function FROM users WHERE last_name = 'Jones'; @@ -499,7 +499,7 @@ USING TTL 300 -- ^^^^^^ keyword.other -- ^^^ meta.number.integer.decimal constant.numeric.value SET race_name = 'dummy' --- <- keyword.other.DML +-- <- keyword.other.dml WHERE race_id = 200 AND race_start_date = '2015-05-27' AND race_end_date = '2015-05-27'; @@ -511,7 +511,7 @@ WHERE race_id=200; -- https://docs.datastax.com/en/cql-oss/3.x/cql/cql_using/useQueryJSON.html select json name, checkin_id, timestamp from checkin; --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^^^^ storage.modifier select name, checkin_id, toJson(timestamp) from checkin; diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 3806ddb9e4..2417aab95c 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -153,7 +153,7 @@ CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; -- ^ meta.group punctuation.separator.sequence -- ^^^^^^^ meta.group meta.column-name -- ^ meta.group punctuation.section.group.end --- ^^^^^ keyword.other.DML.sql +-- ^^^^^ keyword.other.dml.sql -- ^^ keyword.operator.logical.sql -- ^^^^ constant.language.null.sql @@ -226,14 +226,14 @@ select -- ^^^ keyword.operator.comparison.sql SELECT *, --- ^^^ keyword.other.DML.sql +-- ^^^ keyword.other.dml.sql -- ^ variable.language.wildcard.asterisk.sql f.id AS database_id -- ^^ keyword.operator.assignment.alias.sql -- ^^^^^^^^^^^ meta.column-alias FROM foo WHERE f.a IS NULL --- ^^ keyword.other.DML.sql +-- ^^ keyword.other.dml.sql -- ^^ keyword.operator.logical.sql -- ^^^^ constant.language.null.sql AND f.b IS NOT NULL @@ -274,12 +274,12 @@ CREATE ALGORITHM=MERGE VIEW contactPersons( -- <- meta.group punctuation.section.group.end -- ^ keyword.operator.assignment.alias - meta.group SELECT --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml customerName, contactFirstName, contactLastName, phone FROM customers; --- ^ keyword.other.DML +-- ^ keyword.other.dml -- ^^^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement diff --git a/SQL/tests/syntax/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.sql index 7c7bc5281c..2a68419b3c 100644 --- a/SQL/tests/syntax/syntax_test_postgres.sql +++ b/SQL/tests/syntax/syntax_test_postgres.sql @@ -14,7 +14,7 @@ CREATE TABLE test1 (a character(4)); INSERT INTO test1 VALUES ('ok'); SELECT a, char_length(a) FROM test1; --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^ meta.column-name -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^^^^ meta.function-call @@ -22,7 +22,7 @@ SELECT a, char_length(a) FROM test1; -- ^ meta.group punctuation.section.parens.begin -- ^ meta.group meta.column-name -- ^ meta.group punctuation.section.parens.end --- ^^^^ keyword.other.DML - meta.group +-- ^^^^ keyword.other.dml - meta.group -- ^^^^^ meta.table-name -- ^ punctuation.terminator.statement @@ -160,11 +160,11 @@ INSERT INTO sal_emp ARRAY[['breakfast', 'consulting'], ['meeting', 'lunch']]); SELECT name FROM sal_emp WHERE pay_by_quarter[1] <> pay_by_quarter[2]; --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^^^^ meta.column-name --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml -- ^^^^^^^ meta.table-name --- ^^^^^ keyword.other.DML +-- ^^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.section.brackets.begin -- ^ meta.number.integer.decimal constant.numeric.value @@ -177,7 +177,7 @@ SELECT name FROM sal_emp WHERE pay_by_quarter[1] <> pay_by_quarter[2]; -- ^ punctuation.terminator.statement SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^^^^^^^^ meta.column-name -- ^ punctuation.section.brackets.begin -- ^ meta.number.integer.decimal constant.numeric.value @@ -187,5 +187,5 @@ SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; -- ^ punctuation.section.brackets.begin -- ^ meta.number.integer.decimal constant.numeric.value -- ^ punctuation.section.brackets.end --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml -- ^^^^^^^ meta.table-name diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 4b16d28325..77413b3ab3 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -128,28 +128,28 @@ DECLARE @Example INT = 5 -- ^ constant.numeric SELECT TOP 1 @Example = 4 FROM [dbo].[TableName] --- ^^^ keyword.other.DML --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml +-- ^^^ keyword.other.dml -- ^ constant.numeric -- ^^^^^^^^ variable.other.readwrite -- ^ keyword.operator -- ^ constant.numeric --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml SELECT TOP(1) @Example = y FROM [dbo].[TableName] --- ^^^ keyword.other.DML --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml +-- ^^^ keyword.other.dml -- ^ meta.group punctuation.section.parens.begin -- ^ meta.group meta.number.integer.decimal constant.numeric.value -- ^ meta.group punctuation.section.parens.end -- ^^^^^^^^ variable.other.readwrite -- ^ keyword.operator -- ^ meta.column-name --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^ meta.table-name SET @Path = 'X:\nowayout\' ---^ keyword.other.DML +--^ keyword.other.dml -- ^^^^^ variable.other.readwrite -- ^ keyword.operator -- ^^^^^^^^^^^^^^ string.quoted.single - constant @@ -239,13 +239,13 @@ DECLARE db_cursor CURSOR SCROLL DYNAMIC FOR -- ^^^^^^^ storage.modifier -- ^^^ keyword.other SELECT name --- ^^^^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml -- ^^^^ meta.column-name FROM MASTER.dbo.sysdatabases - -- ^ keyword.other.DML + -- ^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name WHERE name NOT IN ('master','model','msdb','tempdb') - -- ^^ keyword.other.DML + -- ^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^^^^^^^^ string.quoted.single -- ^ punctuation.separator.sequence @@ -304,13 +304,13 @@ DECLARE db_cursor CURSOR FAST_FORWARD READ_ONLY FOR -- ^^^^^^^^^ storage.modifier -- ^^^ keyword.other SELECT name --- ^^^^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml -- ^^^^ meta.column-name FROM MASTER.dbo.sysdatabases - -- ^ keyword.other.DML + -- ^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name WHERE name NOT IN ('master','model','msdb','tempdb') - -- ^^ keyword.other.DML + -- ^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^^^^^^^^ string.quoted.single -- ^ punctuation.separator.sequence @@ -324,7 +324,7 @@ OPEN db_cursor DECLARE @FileExists INT SET NOCOUNT ON ---^ keyword.other.DML +--^ keyword.other.dml -- ^^^^^^^ constant.language.switch -- ^^ constant.language.boolean EXEC master.dbo.xp_fileexist @FromFile, @FileExists OUTPUT @@ -335,7 +335,7 @@ EXEC master.dbo.xp_fileexist @FromFile, @FileExists OUTPUT -- ^^^^^^^^^^^ variable.other.readwrite -- ^^^^^^ storage.modifier.output SET NOCOUNT OFF ---^ keyword.other.DML +--^ keyword.other.dml -- ^^^^^^^ constant.language.switch -- ^^^ constant.language.boolean IF @FileExists = 0 @@ -394,24 +394,24 @@ EndSave: ------------- INSERT INTO my_table (foo, bar) --- ^^^^^^^^ keyword.other.DML +-- ^^^^^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^ - meta.function-call - support -- ^^^^^^^^ meta.table-name VALUES (2, 'two'), --- ^^^ keyword.other.DML.II +-- ^^^ keyword.other.dml.II (3, 'three') INSERT INTO #my_table --- ^^^^^^^^ keyword.other.DML +-- ^^^^^^^^ keyword.other.dml -- ^^^^^^^^^ meta.table-name - meta.function-call - support VALUES (2, 'two'), --- ^^^ keyword.other.DML.II +-- ^^^ keyword.other.dml.II (3, 'three') SELECT foo AS foobar, COUNT(*) AS tally --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^^^ meta.column-name -- ^^ keyword.operator.assignment.alias -- ^^^^^^ meta.column-alias @@ -425,23 +425,23 @@ SELECT foo AS foobar, COUNT(*) AS tally -- ^^ keyword.operator.assignment.alias -- ^^^^^ meta.column-alias FROM bar --- ^ keyword.other.DML +-- ^ keyword.other.dml -- ^^^ meta.table-name WHERE 1 = 1 --- ^^ keyword.other.DML +-- ^^ keyword.other.dml GROUP BY foo --- ^^^^^ keyword.other.DML +-- ^^^^^ keyword.other.dml select * from (select * from some_table) alias_table WITH (NOLOCK) --- ^ keyword.other.DML +-- ^ keyword.other.dml -- ^ punctuation.section.group.begin --- ^^^^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml -- ^ variable.language.wildcard.asterisk -- ^^^^^^^^^^ meta.table-name -- ^ punctuation.section.group.end -- ^^^^^^^^^^^ meta.table-alias-name --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml -- ^ punctuation.section.group.begin -- ^^^^^^ meta.group constant.language.with -- ^ punctuation.section.group.end @@ -449,17 +449,17 @@ where exists(select * from other_table where id = some_table.id) -- ^^^^^^ keyword.operator.logical UPDATE TableAlias --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^^^^^^^^^^ meta.table-name SET column1 = v.column1, --- <- keyword.other.DML ---^ keyword.other.DML +-- <- keyword.other.dml +--^ keyword.other.dml column2 = 'testing123 TODO: assert the = operator is scoped as assignment instead of comparison' -- ^ keyword.operator , col3 = 0xDEADC0DE -- ^^^^^^^^^^ meta.number.integer.hexadecimal constant.numeric.value FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) --- ^ keyword.other.DML +-- ^ keyword.other.dml -- ^^^^^^^^^^^^^ meta.table-name -- ^^^^^^^^^^ meta.table-alias-name -- ^^^^ keyword.other @@ -471,11 +471,11 @@ FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^^^^^^^^^ meta.group constant.language.with -- ^ punctuation.section.group.end INNER JOIN some_view AS v WITH (NOLOCK) ON v.some_id = TableAlias.some_id --- ^^^^^^^ keyword.other.DML +-- ^^^^^^^ keyword.other.dml -- ^^^^^^^^^ meta.table-name -- ^^ keyword.operator.assignment.alias -- ^ meta.table-alias-name --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml -- ^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^ constant.language.with @@ -487,17 +487,17 @@ INNER JOIN some_view AS v WITH (NOLOCK) ON v.some_id = TableAlias.some_id -- ^^^^^^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.accessor.dot WHERE TableAlias.some_id IN ( --- ^^ keyword.other.DML +-- ^^ keyword.other.dml -- ^^ keyword.operator.logical -- ^ meta.group punctuation.section.group.begin SELECT a.another_id_column --- ^^^^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml FROM dbname..table_name_in_default_schema a --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^ meta.group meta.table-alias-name WHERE a.another_id_column IS NOT NULL --- ^^^^^ meta.group keyword.other.DML +-- ^^^^^ meta.group keyword.other.dml -- ^^ keyword.operator.logical -- ^^^ keyword.operator.logical -- ^^^^ constant.language.null @@ -539,7 +539,7 @@ SELECT i.ProductID, p.Name, i.LocationID, i.Quantity -- ^^^^ meta.function-call support.function -- ^^^^ keyword.other -- ^^^^^^^^^^^^ meta.group keyword.other --- ^^^^^^^^ meta.group keyword.other.DML +-- ^^^^^^^^ meta.group keyword.other.dml -- ^^^^ meta.group keyword.other.order -- ^^ keyword.operator.assignment.alias -- ^^^^ meta.column-alias @@ -547,7 +547,7 @@ FROM Production.ProductInventory AS i INNER JOIN Production.Product AS p ON i.ProductID = p.ProductID WHERE i.LocationID BETWEEN 3 AND 4 --- ^^ keyword.other.DML +-- ^^ keyword.other.dml -- ^^^^^^^ keyword.operator.logical -- ^ meta.number.integer.decimal constant.numeric.value -- ^^^ keyword.operator.logical @@ -570,7 +570,7 @@ UPDATE foo SET Value = Bar.Value FROM foo INNER JOIN bar (NOLOCK) ON bar.Title = foo.Title COLLATE DATABASE_DEFAULT AND ISNULL(bar.some_id, 0) = ISNULL(foo.some_id, 0) --- ^^^^^^^ keyword.other.DML +-- ^^^^^^^ keyword.other.dml -- ^^^ meta.table-name -- ^^^^^^ meta.group invalid.deprecated.table-hint-without-with.tsql constant.language.table-hint.tsql -- ^^ keyword.operator.join @@ -591,11 +591,11 @@ INNER JOIN bar (NOLOCK) ON bar.Title = foo.Title COLLATE DATABASE_DEFAULT AND IS SELECT DISTINCT * INTO ##global_temp_table --- ^ keyword.other.DML +-- ^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^ meta.table-name FROM some_long_table_name s LEFT OUTER JOIN another_long_table_name (NOLOCK) a ON s.blah = a.blah AND ISNULL(p.ok, '') = ISNULL(a.ok, '') COLLATE DATABASE_DEFAULT --- ^^^^^^^^^^^^ keyword.other.DML +-- ^^^^^^^^^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^^^^^^ invalid.deprecated.table-hint-without-with.tsql constant.language.table-hint.tsql -- ^ meta.table-alias-name @@ -628,14 +628,14 @@ AS BEGIN -- <- keyword.control.flow.begin SELECT TOP (@Count) * FROM [dbo].[CountryInfoNew] --- ^^^^^^ keyword.other.DML --- ^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml +-- ^^^ keyword.other.dml -- ^ meta.group punctuation.section.group.begin -- ^ meta.group variable.other.readwrite punctuation.definition.variable -- ^^^^^ meta.group variable.other.readwrite -- ^ meta.group punctuation.section.group.end -- ^ variable.language.wildcard.asterisk --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^ punctuation.definition.identifier.begin -- ^ punctuation.definition.identifier.end @@ -677,24 +677,24 @@ select A.A -- ^ punctuation.accessor.dot -- ^ variable.language.wildcard.asterisk into #temp --- ^ keyword.other.DML +-- ^ keyword.other.dml -- ^^^^^ meta.table-name from @A A --- ^ keyword.other.DML +-- ^ keyword.other.dml -- ^^ meta.table-name -- ^ meta.table-alias-name inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN(B.C) DESC) = B.ID ---^^^^^^^^ keyword.other.DML +--^^^^^^^^ keyword.other.dml -- ^ meta.table-name -- ^^ keyword.operator.join -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.group.begin --- ^^^^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml -- ^ keyword.operator.comparison -- ^^^^ meta.column-name WITH Sales_CTE (SalesPersonID, TotalSales, SalesYear) --- ^ keyword.other.DML +-- ^ keyword.other.dml -- ^^^^^^^^^ meta.cte-table-name -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns -- ^ punctuation.section.group.begin @@ -710,7 +710,7 @@ AS ( -- <- meta.group punctuation.section.group.begin SELECT SalesPersonID, SUM(TotalDue) AS TotalSales, YEAR(OrderDate) AS SalesYear --- ^^^^^^ meta.group keyword.other.DML +-- ^^^^^^ meta.group keyword.other.dml FROM Sales.SalesOrderHeader WHERE SalesPersonID IS NOT NULL GROUP BY SalesPersonID, YEAR(OrderDate) @@ -728,14 +728,14 @@ AS ( -- <- meta.group punctuation.section.group.begin SELECT BusinessEntityID, SUM(SalesQuota)AS SalesQuota, YEAR(QuotaDate) AS SalesQuotaYear --- ^^^^^^ meta.group keyword.other.DML +-- ^^^^^^ meta.group keyword.other.dml FROM Sales.SalesPersonQuotaHistory GROUP BY BusinessEntityID, YEAR(QuotaDate) ) -- Define the outer query by referencing columns from both CTEs. SELECT SalesPersonID --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml , SalesYear , FORMAT(TotalSales,'C','en-us') AS TotalSales , SalesQuotaYear @@ -761,25 +761,25 @@ SELECT ManagerID, EmployeeID, Title, EmployeeLevel FROM DirectReports ORDER BY ManagerID OPTION (MAXRECURSION 3) --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^ meta.group punctuation.section.group.begin -- ^^^^^^^^^^^^ meta.group constant.language.with -- ^ meta.group constant.language.with -- ^ meta.group punctuation.section.group.end WITH cte_table AS ( SELECT blah ) --- ^ keyword.other.DML +-- ^ keyword.other.dml -- ^^^^^^^^^ meta.cte-table-name -- ^^ keyword.operator.assignment.cte -- ^ meta.group punctuation.section.group.begin --- ^^^^^^ meta.group keyword.other.DML +-- ^^^^^^ meta.group keyword.other.dml -- ^^^^ meta.group meta.column-name -- ^ meta.group punctuation.section.group.end SELECT cte_table.* FROM cte_table --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^^^^^^^^^^ meta.column-name -- ^ variable.language.wildcard.asterisk --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml -- ^^^^^^^^^ meta.table-name ;WITH A AS @@ -802,7 +802,7 @@ SELECT cte_table.* FROM cte_table -- ^^ keyword.operator.assignment.cte ( SELECT --- ^^^^^^ meta.group keyword.other.DML +-- ^^^^^^ meta.group keyword.other.dml FooID, CASE WHEN Character = 'Zoidberg' THEN @@ -852,12 +852,12 @@ AS -- <- keyword.context.block ;WITH CTE AS (SELECT @input1 AS Input1) UPDATE Blah SET X = CTE.Input1 FROM CTE JOIN X ON X.Nonsense = 12.6 -- <- punctuation.terminator.statement ---^^^ keyword.other.DML +--^^^ keyword.other.dml -- ^^^ meta.cte-table-name -- ^^ keyword.operator.assignment.cte --- ^^^^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml -- ^^^^ meta.table-name --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^^^^ meta.number.float.decimal constant.numeric.value IF OBJECT_ID('tempdb..import') IS NOT NULL @@ -1040,7 +1040,7 @@ UNPIVOT (dDate FOR nDate IN (date1, date2, date3, date4)) AS item -- ^^ keyword.operator.assignment.alias -- ^^^^ meta.table-alias-name GROUP BY item.ID --- ^^^^^ keyword.other.DML +-- ^^^^^ keyword.other.dml ------------ -- Create the table and insert values as portrayed in the previous example. @@ -1079,13 +1079,13 @@ GO CREATE TABLE dbo.T1 ( column_1 int IDENTITY, column_2 VARCHAR(30)); GO INSERT T1 VALUES ('Row #1'); ---^^^^ keyword.other.DML +--^^^^ keyword.other.dml -- ^^ meta.table-name --- ^^^^^^ keyword.other.DML.II +-- ^^^^^^ keyword.other.dml.II INSERT T1 (column_2) VALUES ('Row #2'); GO SET IDENTITY_INSERT T1 ON; --- <- keyword.other.DML +-- <- keyword.other.dml -- ^^^^^^^^^^^^^^^ constant.language.switch -- ^^ meta.table-name -- ^^ constant.language.boolean @@ -1125,9 +1125,9 @@ CREATE TABLE dbo.T1 column_4 varchar(40) NULL ); INSERT INTO T1 DEFAULT VALUES; --- ^^^^^^^^ keyword.other.DML +-- ^^^^^^^^ keyword.other.dml -- ^^ meta.table-name --- ^^^^^^^^^^^^^^ keyword.other.DML.II +-- ^^^^^^^^^^^^^^ keyword.other.dml.II -- ^ punctuation.terminator.statement @@ -1149,8 +1149,8 @@ WHEN MATCHED -- ^^^^^^^^^ keyword.control.conditional.case THEN UPDATE SET -- ^^^^ keyword.other --- ^^^^^^ keyword.other.DML --- ^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml +-- ^^^ keyword.other.dml t.category_name = s.category_name, -- ^^^^^^^^^^^^^^^ meta.column-name -- ^ keyword.operator @@ -1165,7 +1165,7 @@ WHEN NOT MATCHED BY TARGET -- ^^^^^^^^^ keyword.other THEN INSERT (category_id, category_name, amount) -- ^^^^ keyword.other --- ^^^^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^ meta.column-name @@ -1175,7 +1175,7 @@ WHEN NOT MATCHED BY TARGET -- ^^^^^^ meta.column-name -- ^ punctuation.section.group.end VALUES (s.category_id, s.category_name, s.amount) --- ^^^^^^ keyword.other.DML.II +-- ^^^^^^ keyword.other.dml.II -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.separator.sequence @@ -1188,7 +1188,7 @@ WHEN NOT MATCHED BY SOURCE -- ^^^^^^^^^ keyword.other THEN DELETE; -- ^^^^ keyword.other --- ^^^^^^ keyword.other.DML +-- ^^^^^^ keyword.other.dml -- ^ punctuation.terminator.statement -------------- @@ -1227,7 +1227,7 @@ CREATE TABLE [dbo].[be_Categories]( -- ^^^^^^^^^^^^ meta.column-name -- ^^^ keyword.other.order ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml -- ^^^^^^^^^ constant.language.with -- ^ keyword.operator.assignment -- ^^^ constant.language.bool @@ -1276,7 +1276,7 @@ CREATE TABLE [Employee]( GO SELECT * FROM Department D CROSS APPLY ---^^^^^^^^^ keyword.other.DML +--^^^^^^^^^ keyword.other.dml ( SELECT * FROM Employee E WHERE E.DepartmentID = D.DepartmentID @@ -1284,7 +1284,7 @@ CROSS APPLY GO SELECT * FROM Department D OUTER APPLY --- ^^^^^^^^ keyword.other.DML +-- ^^^^^^^^ keyword.other.dml ( SELECT * FROM Employee E WHERE E.DepartmentID = D.DepartmentID @@ -1396,8 +1396,8 @@ DECLARE @MyTableVar table( NewVacationHours INT, ModifiedDate datetime); UPDATE TOP (10) HumanResources.Employee --- ^^^ keyword.other.DML --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml +-- ^^^ keyword.other.dml -- ^^^^ meta.group -- ^ punctuation.section.parens.begin -- ^^ meta.number.integer.decimal constant.numeric.value @@ -1428,9 +1428,9 @@ GO --Note that ModifiedDate reflects the value generated by an --AFTER UPDATE trigger. SELECT TOP 10 percent BusinessEntityID, VacationHours, ModifiedDate --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^^ meta.number.integer.decimal constant.numeric.value --- ^^^^^^^ keyword.other.DML +-- ^^^^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^ meta.column-name FROM HumanResources.Employee; GO @@ -1459,7 +1459,7 @@ EXEC sp_xml_preparedocument @XmlDocumentHandle OUTPUT, @XmlDocument -- Execute a SELECT statement using OPENXML rowset provider. SELECT * FROM OPENXML (@XmlDocumentHandle, '/ROOT/Customer',2) -- TODO: apply xpath highlighting to the string ---^^ keyword.other.DML +--^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call -- ^ - meta.function-call -- ^^^^^^^ meta.table-valued-function-name support.function @@ -1519,7 +1519,7 @@ FROM table_name AS t1 SELECT a.* FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', --- ^^^^ keyword.other.DML +-- ^^^^ keyword.other.dml -- ^^^^^^^^^^ meta.function-call meta.table-valued-function-name support.function 'C:\SAMPLES\Northwind.mdb'; -- ^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single @@ -1571,7 +1571,7 @@ CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( --^ - meta.group WITH cols ---^^ keyword.other.DML +--^^ keyword.other.dml -- ^^^^ meta.cte-table-name AS -- <- keyword.operator.assignment.cte @@ -1586,37 +1586,37 @@ FROM cols ORDER BY sequence set @test += 2 ---^ keyword.other.DML +--^ keyword.other.dml -- ^^^^^ variable.other.readwrite -- ^^ keyword.operator.assignment -- ^ meta.number.integer.decimal constant.numeric.value set @test -= 2 ---^ keyword.other.DML +--^ keyword.other.dml -- ^^^^^ variable.other.readwrite -- ^^ keyword.operator.assignment -- ^ meta.number.integer.decimal constant.numeric.value set @test *= 2 ---^ keyword.other.DML +--^ keyword.other.dml -- ^^^^^ variable.other.readwrite -- ^^ keyword.operator.assignment -- ^ meta.number.integer.decimal constant.numeric.value set @test /= 2 ---^ keyword.other.DML +--^ keyword.other.dml -- ^^^^^ variable.other.readwrite -- ^^ keyword.operator.assignment -- ^ meta.number.integer.decimal constant.numeric.value set @test %= 2 ---^ keyword.other.DML +--^ keyword.other.dml -- ^^^^^ variable.other.readwrite -- ^^ keyword.operator.assignment -- ^ meta.number.integer.decimal constant.numeric.value set @test ^= 2 ---^ keyword.other.DML +--^ keyword.other.dml -- ^^^^^ variable.other.readwrite -- ^^ keyword.operator.assignment -- ^ meta.number.integer.decimal constant.numeric.value set @test |= 2 ---^ keyword.other.DML +--^ keyword.other.dml -- ^^^^^ variable.other.readwrite -- ^^ keyword.operator.assignment -- ^ meta.number.integer.decimal constant.numeric.value @@ -1629,7 +1629,7 @@ AS SELECT * FROM Person.Address WHERE City = @city_name AND PostalCode = @postal_code OPTION ( OPTIMIZE FOR (@city_name = 'Seattle', @postal_code UNKNOWN) ); --- ^^^ keyword.other.DML +-- ^^^ keyword.other.dml -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^^ keyword.other -- ^ punctuation.section.group.begin @@ -1647,7 +1647,7 @@ GO SELECT * FROM Person.Address WHERE City = @city_name AND PostalCode = @postal_code OPTION (OPTIMIZE FOR UNKNOWN); ---^^^^ keyword.other.DML - meta.group +--^^^^ keyword.other.dml - meta.group -- ^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^^^^^^^^^^ keyword.other From 545ddcb50d50022a3a08e3dfde0a88379cf532e0 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 25 Oct 2021 22:17:17 +0300 Subject: [PATCH 059/250] [SQL] Update Python MySQL syntax tests --- Python/syntax_test_python_strings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/syntax_test_python_strings.py b/Python/syntax_test_python_strings.py index 7bb8382d83..11718af5e3 100644 --- a/Python/syntax_test_python_strings.py +++ b/Python/syntax_test_python_strings.py @@ -198,7 +198,7 @@ EXISTS( select 1) ELSE NULL - ) as result + END) as result """ query = \ @@ -213,7 +213,7 @@ EXISTS( select 1) ELSE NULL - ) as result + END) as result """ query = \ @@ -227,7 +227,7 @@ EXISTS( select 1) ELSE NULL - ) as result + END) as result ''' sql = 'SELECT * FROM foo -- bar baz' From a305dc7f7e55f9bb3e76982f1d90dd8216016da0 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 12 Nov 2021 20:51:45 +0200 Subject: [PATCH 060/250] [SQL] Support MySQL temporary table creation --- SQL/SQL (basic).sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_mysql.sql | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index a30bf666d1..29d5cad64b 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -312,7 +312,7 @@ contexts: - include: dml-statements ddl-statements: - - match: \b(?i:create\s+table)\b + - match: \b(?i:create\s+(?:temporary\s+)?table)\b scope: keyword.other.ddl.sql push: - ddl-create-target diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 2417aab95c..6a6c6abe89 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -283,3 +283,10 @@ FROM customers; -- ^ keyword.other.dml -- ^^^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement + +CREATE TEMPORARY TABLE IF NOT EXISTS foo ( +-- ^^^^^^^^^^^^^^^^^^^ meta.create keyword.other.ddl +-- ^^^ meta.toc-list.full-identifier entity.name.function + bar NVARCHAR(400), + baz INT +); From 8940b18f08c690f1d95864cd20cbc9c33b8902df Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 12 Nov 2021 21:53:27 +0200 Subject: [PATCH 061/250] [SQL] Improve Postgres syntax support --- SQL/Cassandra.sublime-syntax | 2 +- SQL/PostgresSQL.sublime-syntax | 61 +++++++++++++ SQL/SQL (basic).sublime-syntax | 39 ++++++-- SQL/TSQL.sublime-syntax | 5 -- SQL/tests/syntax/syntax_test_postgres.sql | 103 ++++++++++++++++++++++ 5 files changed, 195 insertions(+), 15 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 046854adc1..82776ce7b8 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -54,7 +54,7 @@ contexts: captures: 1: keyword.other.dml.sql 2: storage.modifier.cql - - match: \b(?i:allow filtering)\b + - match: \b(?i:allow\s+filtering)\b scope: keyword.other.dml.cql - match: \b(?i:copy)\b scope: keyword.other.dml.cql diff --git a/SQL/PostgresSQL.sublime-syntax b/SQL/PostgresSQL.sublime-syntax index 7483a74f05..bc9f890d56 100644 --- a/SQL/PostgresSQL.sublime-syntax +++ b/SQL/PostgresSQL.sublime-syntax @@ -39,6 +39,7 @@ contexts: expressions: - meta_prepend: true + - match: \b(?i:as\s+\$\$) - match: \b(?i:ARRAY)\b scope: keyword.declaration.postgresql - match: \[ @@ -47,3 +48,63 @@ contexts: scope: punctuation.section.brackets.end.postgresql - match: ':(?!:)' scope: keyword.operator.range.postgresql + - match: \b(?i:returns)\b + scope: keyword.other.postgresql + - match: \b(?i:return)\b + scope: keyword.control.flow.return.postgresql + + ddl-target: + - meta_prepend: true + - match: \b(?i:extension|domain)\b + scope: keyword.other.postgresql + + ddl-create-target: + - meta_prepend: true + - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b + scope: keyword.other.postgresql + + operators: + - meta_prepend: true + - include: regex-operators + + regex-operators: + # https://www.postgresql.org/docs/7.4/functions-matching.html#FUNCTIONS-POSIX-REGEXP + - match: '!?~\*?' + scope: keyword.operator.comparison.postgresql + push: expect-regex + + inside-ddl-table-creation-columns: + - meta_prepend: true + - match: \b(?i:unique)\b + scope: keyword.other.postgresql + + expect-regex: + - match: \' + scope: punctuation.definition.string.begin.sql + embed: single-quoted-regex + embed_scope: source.regexp + escape: \' + escape_captures: + 0: meta.string.regexp.postgresql punctuation.definition.string.end.sql + pop: 1 + - match: (?=\S) + pop: 1 + + single-quoted-regex: + - meta_scope: meta.string.regexp.postgresql + - include: scope:source.regexp + + statements: + - meta_prepend: true + - include: declarations + + after-declare: + - match: '' + set: + - declaration-variable-name + - single-identifier + + declaration-variable-name: + - meta_scope: variable.other.postgresql + - match: '' + pop: true diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 29d5cad64b..f000ad3634 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -15,7 +15,7 @@ variables: ddl_target: |- (?xi) \b - (?:aggregate|conversion|database|domain|function|group| + (?:aggregate|constraint|conversion|database|domain|function|group| (?:(?:fulltext|spatial|unique)\s+)?index| language|operator class|operator|procedure|rule| schema|sequence|table(?:space)?|trigger|type|user|view)\b @@ -154,7 +154,9 @@ contexts: drop-condition: - include: dml-condition - match: (?=\S) - set: single-identifier-after-whitespace + set: + - ddl-target-on + - single-identifier-after-whitespace dml-condition: - match: \b(?i:if)\b @@ -349,6 +351,9 @@ contexts: ddl-create-target: - meta_scope: meta.create.sql + - include: ddl-target-on + + ddl-target-on: - match: \b(?i:on)\b scope: keyword.other.sql push: @@ -384,8 +389,7 @@ contexts: ddl-alter-table: - meta_scope: meta.alter.sql - - match: \b(?i:(?:add|drop)(?:\s+column)?|alter\s+column)\b - scope: keyword.other.ddl.sql + - include: ddl-alter-column - include: ddl-alter-common - include: expressions-or-column-name @@ -396,14 +400,22 @@ contexts: pop: 1 ddl-alter-common: - - match: (?i:\s*\b(add)\s+(constraint|(?:fulltext|spatial)\s+(index|key)|index)) - scope: meta.add.sql - captures: - 1: keyword.other.add.sql - 2: keyword.other.sql + - match: \b(?i:add\s+constraint)\b + scope: meta.add.sql keyword.other.sql + push: + - constraint-name + - single-identifier-after-whitespace + - match: \b(?i:add\s+(?:(?:fulltext|spatial)\s+(index|key)|index))\b + scope: meta.add.sql keyword.other.sql - include: types - include: pop-on-top-level-reserved-word + ddl-alter-column: + - match: \b(?i:(?:add|drop|alter)\s+column)\b + scope: keyword.other.ddl.sql + - match: \b(?i:(?:add|drop|alter))\b(?!\s+{{ddl_target}}) + scope: keyword.other.ddl.sql + dml-statements: - match: \b(?i:select)\b scope: keyword.other.dml.sql @@ -634,3 +646,12 @@ contexts: 2: constant.language.sql pop: true - include: expressions + + declarations: + - match: \b(?i:declare)\b + scope: keyword.declaration.variable.tsql + push: after-declare + + after-declare: + - match: '' + pop: 1 diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 547c4bd66a..eedd8e9c60 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -269,11 +269,6 @@ contexts: - match: (?i)\b(?:begin|commit|rollback|save)\s+tran(saction)?\b scope: keyword.context.tsql - declarations: - - match: \b(?i:declare)\b - scope: keyword.declaration.variable.tsql - push: after-declare - expressions: - meta_prepend: true - match: \b(?i:cast)\b diff --git a/SQL/tests/syntax/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.sql index 2a68419b3c..4b27830453 100644 --- a/SQL/tests/syntax/syntax_test_postgres.sql +++ b/SQL/tests/syntax/syntax_test_postgres.sql @@ -83,6 +83,13 @@ CREATE TABLE IF NOT EXISTS public.dropzone_details -- ^ punctuation.separator.sequence CONSTRAINT id_name_uix UNIQUE (id, name) -- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^ meta.constraint-name +-- ^^^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^ meta.column-name +-- ^ punctuation.separator.sequence +-- ^^^^ meta.column-name +-- ^ punctuation.section.group.end ) SELECT '\xDEADBEEF'; @@ -189,3 +196,99 @@ SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; -- ^ punctuation.section.brackets.end -- ^^^^ keyword.other.dml -- ^^^^^^^ meta.table-name + +CREATE EXTENSION hstore SCHEMA addons; -- TODO: scope schema correctly +-- ^^^ meta.create keyword.other.ddl +-- ^^^^^^^^^ meta.create keyword.other +-- ^^^^^^ meta.create meta.toc-list.full-identifier entity.name.function + +CREATE TABLE example_table ( + first_name VARCHAR(100) + CONSTRAINT check_first_name +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^ meta.constraint-name + ( first_name ~* '^[a-z]+$') +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^ meta.column-name +-- ^^ keyword.operator.comparison +-- ^^^^^^^^^^ meta.string.regexp +-- ^^^^^^^^ source.regexp +-- ^ punctuation.definition.string.begin +-- ^ punctuation.definition.string.end +-- ^ punctuation.section.group.end - meta.string +); + +ALTER TABLE mytable ADD CONSTRAINT verif_code CHECK (code IN ('A', 'AG', 'AL', 'AS', 'B', 'C', 'D', 'DA')); -- TODO: scope CHECK correctly +-- ^^^^^^^^ keyword.other.ddl +-- ^^^^^^^ meta.table-name +-- ^^^^^^^^^^^^^^ keyword.other +-- ^^^^^^^^^^ meta.constraint-name + + +CREATE TABLE test1 ( + name varchar(500) NOT NULL PRIMARY KEY, + description varchar NOT NULL DEFAULT '', + authors varchar[], +); + +CREATE TABLE test2 ( + test1name varchar(500) NOT NULL REFERENCES test1(name) ON DELETE CASCADE ON UPDATE CASCADE, +-- ^^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^^ storage.type +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^ meta.column-name +-- ^ punctuation.section.group.end +-- ^^^^^^^^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^^ storage.modifier +-- ^ punctuation.separator.sequence + PRIMARY KEY(test1name) +); + +ALTER TABLE test2 ADD something varchar[]; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter +-- ^^^^^^^^ keyword.other.ddl +-- ^^^^^ meta.table-name +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^ meta.column-name +-- ^^^^^^^ storage.type +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +-- ^ punctuation.terminator.statement + + +CREATE TRIGGER blah AFTER INSERT OR UPDATE +-- ^^^ keyword.other.ddl +-- ^^^^^^^ keyword.other +-- ^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^^^^^^^^^^ keyword.other + ON some_table FOR EACH ROW EXECUTE PROCEDURE some_procedure(); -- TODO: +-- ^^ keyword.other +-- ^^^^^^^^^^ meta.table-name + + +CREATE FUNCTION highlight_result_array(vals varchar[], something tsquery, something_else boolean) RETURNS varchar[] AS $$ +DECLARE +-- ^^^^ keyword.declaration.variable + output varchar[]; +-- ^^^^^^ variable.other +BEGIN +-- ^^ keyword.other.LUW + FOR I IN array_lower(vals, 1)..array_upper(vals, 1) LOOP + output[I] := compute_result(vals[I], something, something_else); + END LOOP; + RETURN output; +-- ^^^^^^ keyword.control.flow.return +END; +$$ LANGUAGE plpgsql STABLE; + +DROP TRIGGER blah ON some_table; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop +-- ^ keyword.other.ddl +-- ^^^^^^^ keyword.other +-- ^^ keyword.other +-- ^^^^^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement From ae583143b49e698019716e92449816b14ed028a1 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 13 Nov 2021 20:03:48 +0200 Subject: [PATCH 062/250] [SQL] move ddl-create-target-expect-as to base syntax --- SQL/PostgresSQL.sublime-syntax | 7 +++--- SQL/SQL (basic).sublime-syntax | 27 ++++++++++++++++++---- SQL/TSQL.sublime-syntax | 9 -------- SQL/tests/syntax/syntax_test_cassandra.cql | 2 +- SQL/tests/syntax/syntax_test_mysql.sql | 2 +- SQL/tests/syntax/syntax_test_postgres.sql | 2 +- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/SQL/PostgresSQL.sublime-syntax b/SQL/PostgresSQL.sublime-syntax index bc9f890d56..89271c1336 100644 --- a/SQL/PostgresSQL.sublime-syntax +++ b/SQL/PostgresSQL.sublime-syntax @@ -39,7 +39,6 @@ contexts: expressions: - meta_prepend: true - - match: \b(?i:as\s+\$\$) - match: \b(?i:ARRAY)\b scope: keyword.declaration.postgresql - match: \[ @@ -48,8 +47,6 @@ contexts: scope: punctuation.section.brackets.end.postgresql - match: ':(?!:)' scope: keyword.operator.range.postgresql - - match: \b(?i:returns)\b - scope: keyword.other.postgresql - match: \b(?i:return)\b scope: keyword.control.flow.return.postgresql @@ -108,3 +105,7 @@ contexts: - meta_scope: variable.other.postgresql - match: '' pop: true + + ddl-statements: + - meta_prepend: true + - match: \$\$ diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index f000ad3634..5b1eadb723 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -187,6 +187,12 @@ contexts: 2: punctuation.separator.sequence.sql 3: constant.numeric.sql + expect-type: + - include: types + # TODO: support custom type identifiers + - match: (?=\S) + pop: 1 + expressions-or-column-name: - include: wildcard-identifier - include: expressions @@ -323,6 +329,7 @@ contexts: - match: \b(?i:create)\b scope: keyword.other.ddl.sql push: + - ddl-create-target-expect-as - ddl-create-target - create-condition - ddl-target @@ -353,6 +360,16 @@ contexts: - meta_scope: meta.create.sql - include: ddl-target-on + ddl-create-target-expect-as: + - match: \b(?i:as)\b + scope: keyword.context.block.sql + pop: 1 + - match: \b(?i:returns)\b + scope: keyword.other.sql + push: expect-type + - include: pop-on-top-level-reserved-word + - include: expressions + ddl-target-on: - match: \b(?i:on)\b scope: keyword.other.sql @@ -468,7 +485,7 @@ contexts: use-db: - match: \b(?i:use)\b - scope: keyword.context.tsql + scope: keyword.context.sql push: - database-name - single-identifier-after-whitespace @@ -580,8 +597,8 @@ contexts: after-table-alias: - match: \b(?i:(TABLESAMPLE(?:\s+SYSTEM)?))\s*(\() captures: - 1: keyword.other.tsql - 2: meta.group.tablesample.tsql punctuation.section.group.begin.tsql + 1: keyword.other.sql + 2: meta.group.tablesample.sql punctuation.section.group.begin.sql push: tablesample - match: (?=\S) pop: 1 @@ -642,14 +659,14 @@ contexts: scope: constant.language.sql - match: (\))(?:\s*((?i:repeatable))\b)? captures: - 1: meta.group.tablesample.tsql punctuation.section.group.end.sql + 1: meta.group.tablesample.sql punctuation.section.group.end.sql 2: constant.language.sql pop: true - include: expressions declarations: - match: \b(?i:declare)\b - scope: keyword.declaration.variable.tsql + scope: keyword.declaration.variable.sql push: after-declare after-declare: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index eedd8e9c60..7dac60ae05 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -362,15 +362,6 @@ contexts: - ddl-create-target-expect-as - expect-procedure-name - ddl-create-target-expect-as: - - match: \b(?i:as)\b - scope: keyword.context.block.sql - pop: 1 - - match: \b(?i:returns)\b - scope: keyword.other.tsql - - include: pop-on-top-level-reserved-word - - include: expressions - top: - match: (?i)\b(top)\b(?:\s*(?:(\()\s*)?(\d+)(?:\s*(\)))?(?:\s+(percent\b))?)? captures: diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index a009ae96dc..8de1f1ff8a 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -197,7 +197,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical -- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function --- ^^ keyword.operator.assignment.alias +-- ^^ keyword.context.block SELECT * -- ^^^^^^ keyword.other.dml -- ^ variable.language.wildcard.asterisk diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 6a6c6abe89..ae8ec1c409 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -272,7 +272,7 @@ CREATE ALGORITHM=MERGE VIEW contactPersons( phone ) AS -- <- meta.group punctuation.section.group.end --- ^ keyword.operator.assignment.alias - meta.group +-- ^ keyword.context.block - meta.group SELECT -- ^^^ keyword.other.dml customerName, diff --git a/SQL/tests/syntax/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.sql index 4b27830453..452e966c8c 100644 --- a/SQL/tests/syntax/syntax_test_postgres.sql +++ b/SQL/tests/syntax/syntax_test_postgres.sql @@ -104,7 +104,7 @@ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); -- ^^^ meta.create keyword.other.ddl -- ^^^^ meta.create keyword.other -- ^^^^ meta.create meta.toc-list.full-identifier entity.name.function --- ^^ keyword.operator.assignment.alias +-- ^^ keyword.context.block CREATE TABLE person ( name text, current_mood mood -- TODO: scope custom types From a4754f4da3183c82c9bad34fdcdde101bc16779b Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 13 Nov 2021 20:15:08 +0200 Subject: [PATCH 063/250] [SQL] scope columns in a table creation context specifically --- SQL/SQL (basic).sublime-syntax | 26 ++++++++++++++++++++++- SQL/TSQL.sublime-syntax | 10 --------- SQL/tests/syntax/syntax_test_postgres.sql | 10 ++++----- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 5b1eadb723..35a7e2051f 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -481,7 +481,13 @@ contexts: - single-identifier-after-whitespace - match: \b(?i:(((?:foreign|fulltext|primary|unique)\s+)?key|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|default))\b scope: storage.modifier.sql - - include: expressions-or-column-name + - include: collate + - include: expressions + - match: (?=\S) + push: + - expect-type + - column-name-declaration + - single-identifier use-db: - match: \b(?i:use)\b @@ -519,6 +525,12 @@ contexts: - match: '' pop: 1 + column-name-declaration: + - meta_include_prototype: false + - meta_content_scope: meta.column-name.sql variable.other.member.declaration.sql + - match: '' + pop: 1 + column-alias: - meta_include_prototype: false - meta_content_scope: meta.column-alias.sql @@ -672,3 +684,15 @@ contexts: after-declare: - match: '' pop: 1 + + collate: + - match: \b(?i:collate)\b + scope: keyword.other.sql + push: collation + + collation: + - match: \w+ + scope: support.constant.sql + pop: 1 + - match: (?=\S) + pop: 1 diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 7dac60ae05..5e830496a8 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -282,9 +282,6 @@ contexts: - match: \b(?i:cursor)\b scope: support.type.tsql set: cursor-declaration - - match: \b(?i:collate)\b - scope: keyword.other.tsql - push: collation - match: \b(?i:when\s+(?:not\s+)?matched)\b scope: keyword.control.conditional.case.sql push: merge-condition @@ -548,13 +545,6 @@ contexts: scope: keyword.operator.assignment.tsql - include: expressions-or-column-name - collation: - - match: \w+ - scope: support.constant.tsql - pop: 1 - - match: (?=\S) - pop: 1 - joins: - meta_append: true - match: (?i)\b(?:(?:cross|outer)\s+)?apply\b diff --git a/SQL/tests/syntax/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.sql index 452e966c8c..29b515c329 100644 --- a/SQL/tests/syntax/syntax_test_postgres.sql +++ b/SQL/tests/syntax/syntax_test_postgres.sql @@ -7,7 +7,7 @@ CREATE TABLE test1 (a character(4)); -- ^^^^^^^^^^^^^^^^ meta.group.table-columns -- ^ punctuation.terminator.statement -- ^ punctuation.section.group.begin --- ^ meta.column-name +-- ^ meta.column-name variable.other.member.declaration -- ^^^^^^^^^^^^ storage.type -- ^ constant.numeric -- ^ punctuation.section.group.end @@ -15,12 +15,12 @@ CREATE TABLE test1 (a character(4)); INSERT INTO test1 VALUES ('ok'); SELECT a, char_length(a) FROM test1; -- ^^^ keyword.other.dml --- ^ meta.column-name +-- ^ meta.column-name - variable.other.member.declaration -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^^^^ meta.function-call -- ^^^^^^^^^^^ support.function -- ^ meta.group punctuation.section.parens.begin --- ^ meta.group meta.column-name +-- ^ meta.group meta.column-name - variable.other.member.declaration -- ^ meta.group punctuation.section.parens.end -- ^^^^ keyword.other.dml - meta.group -- ^^^^^ meta.table-name @@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS public.dropzone_details -- ^ punctuation.separator.sequence name text COLLATE pg_catalog."default", doc jsonb, --- ^^^ meta.column-name +-- ^^^ meta.column-name variable.other.member.declaration -- ^^^^^ storage.type -- ^ punctuation.separator.sequence poc json, @@ -86,7 +86,7 @@ CREATE TABLE IF NOT EXISTS public.dropzone_details -- ^^^^^^^^^^^ meta.constraint-name -- ^^^^^^ keyword.other -- ^ punctuation.section.group.begin --- ^^ meta.column-name +-- ^^ meta.column-name - variable.other.member.declaration -- ^ punctuation.separator.sequence -- ^^^^ meta.column-name -- ^ punctuation.section.group.end From bdd4b7e88391464114572b666ea1ed84145d349b Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 13 Nov 2021 21:06:23 +0200 Subject: [PATCH 064/250] [SQL] (WIP) refactor to support scoping of types only in a type context --- SQL/Cassandra.sublime-syntax | 20 ++++---- SQL/MySQL.sublime-syntax | 23 +++++++-- SQL/PostgresSQL.sublime-syntax | 8 ++-- SQL/SQL (basic).sublime-syntax | 55 ++++++++++++++++++---- SQL/TSQL.sublime-syntax | 20 ++++++-- SQL/tests/syntax/syntax_test_cassandra.cql | 3 +- SQL/tests/syntax/syntax_test_mysql.sql | 6 ++- SQL/tests/syntax/syntax_test_postgres.sql | 7 ++- SQL/tests/syntax/syntax_test_tsql.sql | 6 +-- 9 files changed, 111 insertions(+), 37 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 82776ce7b8..f5ea80dfb1 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -70,16 +70,17 @@ contexts: - match: \b(?i:source)\b scope: keyword.other.cql - types: + built-in-type: - meta_prepend: true - match: \b(?i:set|frozen|map|tuple)(<) scope: storage.type.cql captures: 1: punctuation.definition.generic.begin.cql - push: generic-type + set: + - end-generic-type + - built-in-type - generic-type: - - include: types + end-generic-type: - match: \> scope: storage.type.cql punctuation.definition.generic.end.cql pop: 1 @@ -122,8 +123,9 @@ contexts: push: partition-key - match: \b(?i:primary\s+key)\b scope: storage.modifier.cql - push: partition-key - - include: expressions-or-column-name + #push: partition-key + - include: expressions + - include: ddl-creation-column partition-key: - meta_content_scope: meta.group.partition-key.cql @@ -136,13 +138,15 @@ contexts: - match: ',' scope: punctuation.separator.sequence.cql set: inside-group - - include: inside-ddl-table-creation-columns + - include: column-references inside-partition-key-group: - match: \) scope: punctuation.section.group.end.cql pop: 1 - - include: inside-ddl-table-creation-columns + - match: ',' + scope: punctuation.separator.sequence.cql + - include: column-references joins: - match: \bjoin\b diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 1ac2eeb894..92e51bf91c 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -10,8 +10,8 @@ variables: (?xi: \b (?:bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|integer| - line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext| - unsigned) + line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext + ) \b ) types_with_optional_number: |- @@ -96,10 +96,14 @@ contexts: - match: \|\| scope: keyword.operator.concatenation.sql - types: - - meta_append: true + after-type: + - meta_prepend: true + - match: \b(?i:unsigned)\b + scope: storage.modifier.mysql + pop: 1 - match: \b(?i:with(?:out)?\s+time\s+zone)\b scope: storage.type.sql + pop: 1 inside-number-sign-comment: - meta_include_prototype: false @@ -182,6 +186,10 @@ contexts: - meta_prepend: true - match: \b(?i:change\s+column)\b scope: keyword.other.ddl.sql + push: + - new-column-name + - column-name + - single-identifier-after-whitespace inside-ddl-table-creation-columns: - meta_prepend: true @@ -196,3 +204,10 @@ contexts: pop: true - match: (?=\S) pop: true + + new-column-name: + - match: (?=\S) + set: + - expect-type + - column-name-declaration + - single-identifier diff --git a/SQL/PostgresSQL.sublime-syntax b/SQL/PostgresSQL.sublime-syntax index 89271c1336..055a5f6493 100644 --- a/SQL/PostgresSQL.sublime-syntax +++ b/SQL/PostgresSQL.sublime-syntax @@ -32,11 +32,6 @@ variables: ) contexts: - types: - - meta_append: true - - match: '::' - scope: keyword.operator.cast.postgresql - expressions: - meta_prepend: true - match: \b(?i:ARRAY)\b @@ -62,6 +57,9 @@ contexts: operators: - meta_prepend: true + - match: '::' + scope: keyword.operator.cast.postgresql + push: expect-type - include: regex-operators regex-operators: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 35a7e2051f..760ab50de0 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -174,9 +174,10 @@ contexts: scope: keyword.operator.arithmetic.sql - include: logical-operators - types: + built-in-type: - match: '{{simple_types}}' scope: storage.type.sql + pop: 1 - match: |- (?xi) {{types_with_optional_number}} @@ -186,16 +187,27 @@ contexts: 1: constant.numeric.sql 2: punctuation.separator.sequence.sql 3: constant.numeric.sql + pop: 1 expect-type: - - include: types - # TODO: support custom type identifiers + - include: built-in-type + # TODO: support custom type identifiers wrapped in square brackets etc. in TSQL syntax just like built-in types + - match: '{{simple_identifier}}' + scope: support.type.sql + pop: 1 + - match: (?=\S) + pop: 1 + + after-type: - match: (?=\S) pop: 1 expressions-or-column-name: - include: wildcard-identifier - include: expressions + - include: column-references + + column-references: - match: (?=\S) push: - possible-operator @@ -219,9 +231,10 @@ contexts: push: inside-case-expression - include: numbers-variables-and-strings - include: operators + - include: collate - include: built-in-aggregate-function-calls - include: built-in-scalar-function-calls - - include: types + #- include: types - include: user-defined-function-calls - include: begin-group - match: \) @@ -367,8 +380,11 @@ contexts: - match: \b(?i:returns)\b scope: keyword.other.sql push: expect-type - - include: pop-on-top-level-reserved-word + - match: (@){{simple_identifier}} + scope: variable.parameter.sql + push: expect-type - include: expressions + - include: pop-on-top-level-reserved-word ddl-target-on: - match: \b(?i:on)\b @@ -424,14 +440,32 @@ contexts: - single-identifier-after-whitespace - match: \b(?i:add\s+(?:(?:fulltext|spatial)\s+(index|key)|index))\b scope: meta.add.sql keyword.other.sql - - include: types + #- include: types - include: pop-on-top-level-reserved-word ddl-alter-column: - - match: \b(?i:(?:add|drop|alter)\s+column)\b + - match: \b(?i:(?:add|alter)\s+column)\b + scope: keyword.other.ddl.sql + push: + - expect-type + - column-name-declaration + - single-identifier-after-whitespace + - match: \b(?i:(?:add|alter))\b(?!\s+{{ddl_target}}) scope: keyword.other.ddl.sql - - match: \b(?i:(?:add|drop|alter))\b(?!\s+{{ddl_target}}) + push: + - expect-type + - column-name-declaration + - single-identifier-after-whitespace + - match: \b(?i:drop\s+column)\b scope: keyword.other.ddl.sql + push: + - column-name + - single-identifier-after-whitespace + - match: \b(?i:drop)\b(?!\s+{{ddl_target}}) + scope: keyword.other.ddl.sql + push: + - column-name + - single-identifier-after-whitespace dml-statements: - match: \b(?i:select)\b @@ -481,10 +515,13 @@ contexts: - single-identifier-after-whitespace - match: \b(?i:(((?:foreign|fulltext|primary|unique)\s+)?key|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|default))\b scope: storage.modifier.sql - - include: collate - include: expressions + - include: ddl-creation-column + + ddl-creation-column: - match: (?=\S) push: + - after-type - expect-type - column-name-declaration - single-identifier diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 5e830496a8..06cb5b490e 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -196,7 +196,7 @@ contexts: - match: (?=\S) fail: like-strings-branch - types: + built-in-type: - meta_prepend: true - match: |- (?xi) @@ -204,6 +204,7 @@ contexts: {{simple_types}} {{enclosed_type_end}} scope: storage.type.sql + pop: 1 - match: |- (?xi) {{enclosed_type_begin}} @@ -216,12 +217,14 @@ contexts: 2: constant.language.max.sql 3: punctuation.separator.sequence.sql 4: constant.numeric.sql + pop: 1 - match: |- (?xi) (?:{{enclosed_type_begin}}|\b) table (?:{{enclosed_type_end}}|\b) scope: storage.type.sql + pop: 1 statements: - meta_append: true @@ -397,9 +400,20 @@ contexts: set: - cursor-name - single-identifier + - match: '(@){{simple_identifier}}' + scope: variable.other.readwrite.declaration.tsql + captures: + 1: punctuation.definition.variable.tsql + set: expect-type - match: (?=\S) pop: 1 + expect-type: + - meta_prepend: true + - match: \b(?i:as)\b + scope: keyword.other.tsql + set: computed-column-definition + set: - meta_prepend: true - match: \b(?i:nocount|ansi_nulls|quoted_identifier)\b @@ -543,6 +557,7 @@ contexts: pop: 1 - match: \b(?i:as)\b scope: keyword.operator.assignment.tsql + push: expect-type - include: expressions-or-column-name joins: @@ -656,9 +671,6 @@ contexts: - meta_prepend: true - match: \b(?i:ROWGUIDCOL|CLUSTERED|NONCLUSTERED)\b scope: storage.modifier.tsql - - match: \b(?i:AS)\b - scope: keyword.other.tsql - push: computed-column-definition computed-column-definition: - meta_content_scope: meta.computed-column-definition.tsql diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 8de1f1ff8a..d5339ba81d 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -175,7 +175,8 @@ CREATE TABLE IF NOT EXISTS date_by_userid ( -- ^^^^ storage.type -- ^^^^^^^^^^^ storage.modifier -- ^ punctuation.separator.sequence - date timestamp -- TODO: scope date as a column name + date timestamp +-- ^^^^ meta.column-name -- ^^^^^^^^^ storage.type ); diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index ae8ec1c409..10f0f54abf 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -62,10 +62,10 @@ create table IF NOT EXISTS `testing123` ( -- ^^ keyword.control.flow -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, -- TODO: is unsigned a modifier or part of the type? + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, -- ^^^^ meta.column-name -- ^^^^^^^ storage.type --- ^^^^^^^^ storage.type +-- ^^^^^^^^ storage.modifier -- ^^^ keyword.operator.logical -- ^^^^ constant.language.null -- ^^^^^^^^^^^^^^ keyword.other @@ -176,6 +176,8 @@ ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); -- ^^^^^^^^^^^^^ meta.alter keyword.other.ddl +-- ^^^^^^^^ meta.column-name +-- ^^^^^^^^ meta.column-name variable.other.member.declaration -- ^^^^ storage.type.sql DROP TABLE IF EXISTS testing123; diff --git a/SQL/tests/syntax/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.sql index 29b515c329..4e9bf9deb9 100644 --- a/SQL/tests/syntax/syntax_test_postgres.sql +++ b/SQL/tests/syntax/syntax_test_postgres.sql @@ -107,7 +107,12 @@ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); -- ^^ keyword.context.block CREATE TABLE person ( name text, - current_mood mood -- TODO: scope custom types +-- ^^^^ meta.column-name variable.other.member.declaration +-- ^^^^ storage.type +-- ^ punctuation.separator.sequence + current_mood mood +-- ^^^^^^^^^^^^ meta.column-name variable.other.member.declaration +-- ^^^^ support.type ); INSERT INTO person VALUES ('Moe', 'happy'); SELECT * FROM person WHERE current_mood = 'happy'; diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 77413b3ab3..7706c838a4 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -620,7 +620,7 @@ CREATE OR ALTER PROC CreateOrAlterDemo @Count SMALLINT ,@Other INT OUTPUT -- <- punctuation.separator.sequence ---^^^^^ variable.other.readwrite +--^^^^^ variable.parameter -- ^^^ storage.type -- ^^^^^^ storage.modifier.output AS @@ -656,7 +656,7 @@ ALTER PROC CreateOrAlterDemo @Count SMALLINT ,@Other INT OUTPUT -- <- punctuation.separator.sequence ---^^^^^ variable.other.readwrite +--^^^^^ variable.parameter -- ^^^ storage.type -- ^^^^^^ storage.modifier.output AS @@ -1569,7 +1569,7 @@ CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( ) -- <- meta.group punctuation.section.group.end --^ - meta.group - +; WITH cols --^^ keyword.other.dml -- ^^^^ meta.cte-table-name From e246202ac9ec462e08c1f7f22d0375ae440f3af9 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 13 Nov 2021 21:19:18 +0200 Subject: [PATCH 065/250] [SQL] Correctly scope types for variable declarations in Postgres syntax --- SQL/PostgresSQL.sublime-syntax | 1 + SQL/tests/syntax/syntax_test_postgres.sql | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/SQL/PostgresSQL.sublime-syntax b/SQL/PostgresSQL.sublime-syntax index 055a5f6493..7ee5401ddc 100644 --- a/SQL/PostgresSQL.sublime-syntax +++ b/SQL/PostgresSQL.sublime-syntax @@ -96,6 +96,7 @@ contexts: after-declare: - match: '' set: + - expect-type - declaration-variable-name - single-identifier diff --git a/SQL/tests/syntax/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.sql index 4e9bf9deb9..78b3282f00 100644 --- a/SQL/tests/syntax/syntax_test_postgres.sql +++ b/SQL/tests/syntax/syntax_test_postgres.sql @@ -280,6 +280,10 @@ DECLARE -- ^^^^ keyword.declaration.variable output varchar[]; -- ^^^^^^ variable.other +-- ^^^^^^^ storage.type +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end +-- ^ punctuation.terminator.statement BEGIN -- ^^ keyword.other.LUW FOR I IN array_lower(vals, 1)..array_upper(vals, 1) LOOP From ee8a3f57974d1076ba420c1247134e005d24b526 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 14 Nov 2021 21:53:33 +0200 Subject: [PATCH 066/250] [SQL] fix Cassandra and TSQL syntax tests after context-specific type awareness changes --- SQL/Cassandra.sublime-syntax | 9 +++++++++ SQL/TSQL.sublime-syntax | 19 ++++++++++++++++++- SQL/tests/syntax/syntax_test_cassandra.cql | 3 +++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index f5ea80dfb1..9d3466ce72 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -108,6 +108,15 @@ contexts: - match: \b(?i:clustering)\b scope: keyword.other.cql + ddl-statements: + - meta_prepend: true + - match: \b(?i:create\s+type)\b + scope: keyword.other.ddl.sql + push: + - ddl-create-target + - ddl-table-creation-columns + - create-condition + ddl-alter-common: - meta_prepend: false diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 06cb5b490e..0744e743f3 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -381,10 +381,27 @@ contexts: built-in-scalar-function-calls: - meta_append: true - - match: (?i)\b(?:CONVERT|GETDATE)(?=\s*\() + - match: (?i)\b(CONVERT)\s*(\() + scope: meta.function-call.sql + captures: + 1: support.function.scalar.sql + 2: meta.group.sql punctuation.section.parens.begin.sql + push: + - method-call-convert + - expect-type + - match: (?i)\b(?:GETDATE)(?=\s*\() scope: support.function.scalar.sql push: begin-method-call-paren + method-call-convert: + - meta_content_scope: meta.function-call.sql meta.group.sql + - match: \) + scope: meta.function-call.sql meta.group.sql punctuation.section.parens.end.sql + pop: 1 + - match: ',' + scope: punctuation.separator.argument.sql + - include: expressions-or-column-name + label-name: - meta_content_scope: meta.label-name.sql - match: '' diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index d5339ba81d..ba039e17a2 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -226,6 +226,9 @@ CREATE TYPE user_defined_type ( -- ^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function -- ^ meta.group punctuation.section.group.begin type1 timestamp, +-- ^^^^^ meta.column-name variable.other.member.declaration +-- ^^^^^^^^^ storage.type +-- ^ punctuation.separator.sequence type2 text, type3 counter, -- ^^^^^ meta.column-name From 22a867788c0c2a3f9a057ae731209d0fdcc8504c Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 30 Nov 2021 22:06:21 +0200 Subject: [PATCH 067/250] [SQL] support included columns in TSQL indexes --- SQL/TSQL.sublime-syntax | 2 ++ SQL/tests/syntax/syntax_test_tsql.sql | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 0744e743f3..a2fcffe674 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -288,6 +288,8 @@ contexts: - match: \b(?i:when\s+(?:not\s+)?matched)\b scope: keyword.control.conditional.case.sql push: merge-condition + - match: \b(?i:include)\b + scope: keyword.other.sql numbers-variables-and-strings: - meta_prepend: true diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 7706c838a4..46b4386126 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1653,3 +1653,19 @@ OPTION (OPTIMIZE FOR UNKNOWN); -- ^^^^^^^^^^^^^^^^^^^^ keyword.other -- ^ punctuation.section.group.end -- ^ punctuation.terminator.statement + + +CREATE NONCLUSTERED INDEX IX_Address_PostalCode +ON Person.Address (PostalCode) +-- <- keyword.other +-- ^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end +INCLUDE (AddressLine1, AddressLine2, City, StateProvinceID) +-- ^^^^ keyword.other - meta.function-call - support.function +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.column-name +-- ^ punctuation.separator.sequence +WHERE CountryCode = 'FR' + From 5350f073539f9c5fb9552b515d1e887c2cd95825 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 30 Nov 2021 22:15:14 +0200 Subject: [PATCH 068/250] [SQL] fix Ruby syntax tests --- Ruby/Embeddings/SQL (for Ruby).sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ruby/Embeddings/SQL (for Ruby).sublime-syntax b/Ruby/Embeddings/SQL (for Ruby).sublime-syntax index dac679e014..a81d06ecc2 100644 --- a/Ruby/Embeddings/SQL (for Ruby).sublime-syntax +++ b/Ruby/Embeddings/SQL (for Ruby).sublime-syntax @@ -1,7 +1,7 @@ %YAML 1.2 --- scope: source.sql.embedded.ruby -# version: 2 +version: 2 hidden: true extends: Packages/SQL/SQL.sublime-syntax From 9f565752c23f48a769b792584f39de555f54bdc2 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 7 Dec 2021 22:15:07 +0200 Subject: [PATCH 069/250] [SQL] resolve Postgres TODO comments from syntax test file --- SQL/PostgresSQL.sublime-syntax | 15 +++++++++++++++ SQL/SQL (basic).sublime-syntax | 6 ++++++ SQL/tests/syntax/syntax_test_postgres.sql | 14 +++++++++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/SQL/PostgresSQL.sublime-syntax b/SQL/PostgresSQL.sublime-syntax index 7ee5401ddc..aed8b1510a 100644 --- a/SQL/PostgresSQL.sublime-syntax +++ b/SQL/PostgresSQL.sublime-syntax @@ -55,6 +55,11 @@ contexts: - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b scope: keyword.other.postgresql + ddl-alter-common: + - meta_prepend: true + - match: \b(?i:check)\b + scope: keyword.other.postgresql + operators: - meta_prepend: true - match: '::' @@ -108,3 +113,13 @@ contexts: ddl-statements: - meta_prepend: true - match: \$\$ + + ddl-create-target-expect-as: + - meta_prepend: true + - match: \b(?i:FOR\s+EACH\s+ROW\s+EXECUTE\s+PROCEDURE)\b + scope: keyword.other.postgresql + - match: \b(?i:schema)\b + scope: storage.modifier.postgresql + push: + - schema-name + - single-identifier-after-whitespace diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 760ab50de0..4508072083 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -604,6 +604,12 @@ contexts: - match: '' pop: 1 + schema-name: + - meta_include_prototype: false + - meta_content_scope: meta.schema-name.sql + - match: '' + pop: 1 + subquery: - match: \( scope: punctuation.section.group.begin.sql diff --git a/SQL/tests/syntax/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.sql index 78b3282f00..931c66ad40 100644 --- a/SQL/tests/syntax/syntax_test_postgres.sql +++ b/SQL/tests/syntax/syntax_test_postgres.sql @@ -202,10 +202,13 @@ SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; -- ^^^^ keyword.other.dml -- ^^^^^^^ meta.table-name -CREATE EXTENSION hstore SCHEMA addons; -- TODO: scope schema correctly +CREATE EXTENSION hstore SCHEMA addons; -- ^^^ meta.create keyword.other.ddl -- ^^^^^^^^^ meta.create keyword.other -- ^^^^^^ meta.create meta.toc-list.full-identifier entity.name.function +-- ^^^^^^ storage.modifier +-- ^^^^^^ meta.schema-name +-- ^ punctuation.terminator.statement CREATE TABLE example_table ( first_name VARCHAR(100) @@ -223,11 +226,14 @@ CREATE TABLE example_table ( -- ^ punctuation.section.group.end - meta.string ); -ALTER TABLE mytable ADD CONSTRAINT verif_code CHECK (code IN ('A', 'AG', 'AL', 'AS', 'B', 'C', 'D', 'DA')); -- TODO: scope CHECK correctly +ALTER TABLE mytable ADD CONSTRAINT verif_code CHECK (code IN ('A', 'AG', 'AL', 'AS', 'B', 'C', 'D', 'DA')); -- ^^^^^^^^ keyword.other.ddl -- ^^^^^^^ meta.table-name -- ^^^^^^^^^^^^^^ keyword.other -- ^^^^^^^^^^ meta.constraint-name +-- ^^^^^ keyword.other +-- ^ punctuation.section.group.begin +-- ^^^^ meta.column-name CREATE TABLE test1 ( @@ -270,9 +276,11 @@ CREATE TRIGGER blah AFTER INSERT OR UPDATE -- ^^^^^^^ keyword.other -- ^^^^ meta.toc-list.full-identifier entity.name.function -- ^^^^^^^^^^^^^^^^^^^^^^ keyword.other - ON some_table FOR EACH ROW EXECUTE PROCEDURE some_procedure(); -- TODO: + ON some_table FOR EACH ROW EXECUTE PROCEDURE some_procedure(); -- ^^ keyword.other -- ^^^^^^^^^^ meta.table-name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ keyword.other +-- ^^^^^^^^^^^^^^ meta.function-call support.function CREATE FUNCTION highlight_result_array(vals varchar[], something tsquery, something_else boolean) RETURNS varchar[] AS $$ From 3c4eeaf191a3e66b0a204c3df360e4951357363c Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 17 Dec 2021 20:27:49 +0200 Subject: [PATCH 070/250] [SQL] only scope a leading asterisk in documentation block comments --- SQL/SQL (basic).sublime-syntax | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 4508072083..e67aaa719a 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -43,7 +43,10 @@ contexts: block-comments: - meta_include_prototype: false - - match: /\*+ + - match: /\*\*+ + scope: punctuation.definition.comment.begin.sql + push: inside-comment-docblock + - match: /\* scope: punctuation.definition.comment.begin.sql push: inside-comment-block @@ -53,9 +56,9 @@ contexts: - match: \n pop: 1 - inside-comment-block: + inside-comment-docblock: - meta_include_prototype: false - - meta_scope: comment.block.sql + - meta_scope: comment.block.documentation.sql - match: \*+/ scope: punctuation.definition.comment.end.sql pop: 1 @@ -63,6 +66,13 @@ contexts: captures: 1: punctuation.definition.comment.sql + inside-comment-block: + - meta_include_prototype: false + - meta_scope: comment.block.sql + - match: \*+/ + scope: punctuation.definition.comment.end.sql + pop: 1 + string-escape: - meta_include_prototype: false - match: '{{string_escape}}' From fdcbe5e239f2bfc2921c9c0fa773d23da7e536d2 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 18 Dec 2021 14:44:40 +0100 Subject: [PATCH 071/250] [SQL] Enable variable interpolations This commit turns SQL.sublime-syntax into an inherited syntax of MySQL.sublime-syntax in order to properly support variable interpolation in Ruby HEREDOCs. The Ruby package contains a SQL (for Ruby).sublime-syntax, which inherits from SQL.sublime-syntax in order to inject variable interpolation via `prototype`. This mechanism does only work if SQL.sublime-syntax inherits from the desired dialect as well. --- SQL/SQL.sublime-syntax | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/SQL/SQL.sublime-syntax b/SQL/SQL.sublime-syntax index def12e3bf9..8a9c5e51f9 100644 --- a/SQL/SQL.sublime-syntax +++ b/SQL/SQL.sublime-syntax @@ -4,6 +4,8 @@ name: SQL scope: source.sql version: 2 +extends: Packages/SQL/MySQL.sublime-syntax + file_extensions: - sql - ddl @@ -13,8 +15,3 @@ first_line_match: |- (?xi: ^ \s* -- .*? -\*- .*? \bsql\b .*? -\*- # editorconfig ) - -contexts: - main: - - include: scope:source.sql.mysql - apply_prototype: true From 7e72cf5c088d23272ce8e197183d47941f39c504 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 11 Feb 2022 06:27:08 +0200 Subject: [PATCH 072/250] [SQL] improve block comment handling --- SQL/SQL (basic).sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_cassandra.cql | 9 +++++++++ SQL/tests/syntax/syntax_test_mysql.sql | 4 ++-- SQL/tests/syntax/syntax_test_tsql.sql | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index e67aaa719a..c8e111401c 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -43,7 +43,7 @@ contexts: block-comments: - meta_include_prototype: false - - match: /\*\*+ + - match: /\*(?:\*(?!/))+ scope: punctuation.definition.comment.begin.sql push: inside-comment-docblock - match: /\* diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index ba039e17a2..1d9297b8d1 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -520,3 +520,12 @@ select json name, checkin_id, timestamp from checkin; select name, checkin_id, toJson(timestamp) from checkin; -- ^^^^^^ meta.function-call support.function + +update blah.table +--^^^^ keyword.other.dml +-- ^^^^^^^^^^ meta.table-name +set x = 4 +--^ keyword.other.dml +-- ^ meta.column-name +-- ^ keyword.operator +-- ^ meta.number.integer.decimal constant.numeric.value diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 10f0f54abf..12bfb40558 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -1,4 +1,4 @@ --- SYNTAX TEST "Packages/SQL/SQL.sublime-syntax" +-- SYNTAX TEST "Packages/SQL/MySQL.sublime-syntax" SELECT 'Foo Bar'; -- ^^^^^^^^^ string.quoted.single @@ -224,7 +224,7 @@ multiline comment select - <=> + <=> -- ^^^ keyword.operator.comparison.sql SELECT *, diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 46b4386126..fec22e7eac 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1669,3 +1669,22 @@ INCLUDE (AddressLine1, AddressLine2, City, StateProvinceID) -- ^ punctuation.separator.sequence WHERE CountryCode = 'FR' + /**/ +--^^^^ comment.block - comment.block.documentation +--^^ punctuation.definition.comment.begin +-- ^^ punctuation.definition.comment.end + + /***/ +--^^^ comment.block.documentation punctuation.definition.comment.begin +-- ^^ comment.block.documentation punctuation.definition.comment.end + + /****/ +--^^^^ comment.block.documentation punctuation.definition.comment.begin +-- ^^ comment.block.documentation punctuation.definition.comment.end + + /*** + *** +-- ^ comment.block.documentation punctuation.definition.comment + ^^ - punctuation + ***/ +-- ^^^^ comment.block.documentation punctuation.definition.comment.end From 454877f214965299f6a8d92e2b4966fe8a8898bd Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 12 Feb 2022 22:21:35 +0200 Subject: [PATCH 073/250] [SQL] fixes after merge from master branch --- Rails/SQL (Rails).sublime-syntax | 1 + 1 file changed, 1 insertion(+) diff --git a/Rails/SQL (Rails).sublime-syntax b/Rails/SQL (Rails).sublime-syntax index 5a10f58090..5a49301d62 100644 --- a/Rails/SQL (Rails).sublime-syntax +++ b/Rails/SQL (Rails).sublime-syntax @@ -2,6 +2,7 @@ --- name: SQL (Rails) scope: source.sql.rails +version: 2 extends: Packages/SQL/SQL.sublime-syntax From 67f8cb542dbb8d5a3182cc18aa6af7c113cfd2eb Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 13 Feb 2022 22:32:53 +0200 Subject: [PATCH 074/250] Apply suggestions from code review Co-authored-by: deathaxe --- SQL/Cassandra.sublime-syntax | 13 ++++++------- SQL/SQL (basic).sublime-syntax | 22 ++++++++++++---------- SQL/TSQL.sublime-syntax | 33 ++++++++++++++++++--------------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 9d3466ce72..b6ee20f46a 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -9,17 +9,16 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: simple_types: |- - \b(?ix: + \b(?xi: ASCII | BIGINT | BLOB | BOOLEAN | COUNTER | DATE | DECIMAL | DOUBLE | DURATION | FLOAT | INET | INT | SMALLINT | TEXT | TIME | TIMESTAMP | TIMEUUID | TINYINT | UUID | VARCHAR | VARINT )\b types_with_optional_number: (?!) ddl_target: |- - (?xi) - \b(?: - function|index|keyspace|table|type|user - |(?:materialized\s+)?view + \b(?xi: + function | index | keyspace | table | type | user + | (?:materialized\s+)?view )\b contexts: @@ -90,7 +89,7 @@ contexts: scope: punctuation.section.braces.end.cql pop: 1 - match: ':' - scope: punctuation.separator.mapping.key-value.cql + scope: punctuation.separator.key-value.cql - include: expressions - match: \w+ scope: meta.mapping.key.cql string.unquoted.cql @@ -128,7 +127,7 @@ contexts: - match: \b(?i:(primary\s+key))\s*(\() captures: 1: storage.modifier.cql - 2: meta.group.cql punctuation.section.group.begin.cql + 2: meta.group.partition-key.cql punctuation.section.group.begin.cql push: partition-key - match: \b(?i:primary\s+key)\b scope: storage.modifier.cql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index c8e111401c..40487a6f33 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -8,17 +8,17 @@ version: 2 variables: string_escape: (?:\\.) simple_identifier: (?:\w+) - reserved: (?i:;|\b(?:from|order|group|select|where|inner|outer|left|right|join|on|set|union|insert|delete|update|truncate|create|alter|drop|return)\b) + reserved: (?:;|\b(?i:from|order|group|select|where|inner|outer|left|right|join|on|set|union|insert|delete|update|truncate|create|alter|drop|return)\b) additional_reserved: (?!) simple_types: (?i:\b(?:bit|bool|boolean|datetime|int)\b) types_with_optional_number: (?i:\b(?:n?char|number|n?varchar|varbinary)\b) ddl_target: |- - (?xi) - \b - (?:aggregate|constraint|conversion|database|domain|function|group| - (?:(?:fulltext|spatial|unique)\s+)?index| - language|operator class|operator|procedure|rule| - schema|sequence|table(?:space)?|trigger|type|user|view)\b + \b(?xi: + aggregate | constraint | conversion | database | domain | function | group + | (?:(?:fulltext | spatial | unique)\s+)?index | language | operator class + | operator | procedure | rule | schema | sequence | table(?:space)? + | trigger | type | user | view + )\b contexts: prototype: @@ -268,7 +268,9 @@ contexts: push: inside-group begin-group-or-pop: - - include: begin-group + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-group - match: (?=\S) pop: 1 @@ -309,7 +311,7 @@ contexts: - meta_include_prototype: false - meta_scope: meta.function-call.sql - match: \( - scope: meta.group.sql punctuation.section.parens.begin.sql + scope: meta.group.sql punctuation.section.group.begin.sql set: inside-method-call - match: (?=\S) pop: 1 @@ -317,7 +319,7 @@ contexts: inside-method-call: - meta_content_scope: meta.function-call.sql meta.group.sql - match: \) - scope: meta.function-call.sql meta.group.sql punctuation.section.parens.end.sql + scope: meta.function-call.sql meta.group.sql punctuation.section.group.end.sql pop: 1 - match: ',' scope: punctuation.separator.argument.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index a2fcffe674..62d6bc7ec2 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -8,7 +8,7 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') simple_identifier: (?:(?:(?:##?)?|@)?\w+) # (one or two hashes OR an ampersand OR nothing) followed by a word - additional_reserved: (?i:\b(?:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec|go|bulk|insert|on|when)\b) + additional_reserved: \b(?i:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec|go|bulk|insert|on|when)\b enclosed_type_begin: (?:\[) enclosed_type_end: (?:\]) identifier_for_lookahead: |- @@ -18,16 +18,16 @@ variables: ) simple_types: |- - (?ix:\b(?: - (?:bigint|bit|float|int|real|smallint|tinyint) - | (?:date|datetime|datetime2|datetimeoffset|smalldatetime|time) - | (?:geometry|hierarchyid|image|n?text|rowversion|sql_variant|sysname|uniqueidentifier|xml) - )\b) + \b(?xi: + (?: bigint | bit | float | int | real | smallint | tinyint ) + | (?: date | datetime | datetime2 | datetimeoffset | smalldatetime | time ) + | (?: geometry | hierarchyid | image | n?text | rowversion | sql_variant | sysname | uniqueidentifier | xml ) + )\b types_with_optional_number: |- - (?ix:\b(?: - (?:n?char|n?varchar|binary|varbinary) - | (?:decimal|money|numeric) - )\b) + \b(?xi: + (?: n?char | n?varchar | binary | varbinary ) + | (?: decimal | money | numeric ) + )\b contexts: identifier-part: @@ -387,7 +387,7 @@ contexts: scope: meta.function-call.sql captures: 1: support.function.scalar.sql - 2: meta.group.sql punctuation.section.parens.begin.sql + 2: meta.group.sql punctuation.section.group.begin.sql push: - method-call-convert - expect-type @@ -398,13 +398,14 @@ contexts: method-call-convert: - meta_content_scope: meta.function-call.sql meta.group.sql - match: \) - scope: meta.function-call.sql meta.group.sql punctuation.section.parens.end.sql + scope: meta.function-call.sql meta.group.sql punctuation.section.group.end.sql pop: 1 - match: ',' scope: punctuation.separator.argument.sql - include: expressions-or-column-name label-name: + - meta_include_prototype: false - meta_content_scope: meta.label-name.sql - match: '' pop: 1 @@ -564,7 +565,7 @@ contexts: cast: - meta_scope: meta.function-call.sql - match: \( - scope: meta.group.sql punctuation.section.parens.begin.sql + scope: meta.group.sql punctuation.section.group.begin.sql set: inside-cast-method-call - match: (?=\S) pop: 1 @@ -572,7 +573,7 @@ contexts: inside-cast-method-call: - meta_content_scope: meta.function-call.sql meta.group.sql - match: \) - scope: meta.function-call.sql meta.group.sql punctuation.section.parens.end.sql + scope: meta.function-call.sql meta.group.sql punctuation.section.group.end.sql pop: 1 - match: \b(?i:as)\b scope: keyword.operator.assignment.tsql @@ -607,6 +608,7 @@ contexts: pop: 1 expect-procedure-name: + - meta_include_prototype: false - match: '' set: - procedure-name @@ -631,6 +633,7 @@ contexts: - include: expressions cte-table-name: + - meta_include_prototype: false - meta_content_scope: meta.cte-table-name.sql - match: '' pop: 1 @@ -651,7 +654,7 @@ contexts: - match: ';' scope: punctuation.separator.sequence.tsql - match: \) - scope: meta.function-call.tsql meta.group.tsql punctuation.section.parens.end.sql + scope: meta.function-call.tsql meta.group.tsql punctuation.section.group.end.sql set: maybe-table-alias - include: inside-method-call From bc9e021b6d4ef9f64101d283a389040d73841cfd Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 14 Feb 2022 22:26:18 +0200 Subject: [PATCH 075/250] [SQL] fixes --- SQL/Cassandra.sublime-syntax | 5 +- SQL/MySQL.sublime-syntax | 5 +- SQL/SQL (basic).sublime-syntax | 94 +++++++++------------- SQL/TSQL.sublime-syntax | 66 ++++++--------- SQL/tests/syntax/syntax_test_cassandra.cql | 36 ++++----- SQL/tests/syntax/syntax_test_mysql.sql | 4 +- SQL/tests/syntax/syntax_test_postgres.sql | 8 +- SQL/tests/syntax/syntax_test_tsql.sql | 52 +++++++----- 8 files changed, 121 insertions(+), 149 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index b6ee20f46a..8a95545cee 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -18,7 +18,7 @@ variables: ddl_target: |- \b(?xi: function | index | keyspace | table | type | user - | (?:materialized\s+)?view + | (?:materialized\s+)?view )\b contexts: @@ -163,8 +163,7 @@ contexts: - match: \b(?i:from)\b scope: keyword.other.cql pop: 1 - - match: '' - pop: 1 + - include: else-pop built-in-scalar-function-calls: - meta_append: true diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 92e51bf91c..39af8b8609 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -201,9 +201,8 @@ contexts: ddl-target-algorithm: - match: \b(?i:MERGE|TEMPTABLE|UNDEFINED)\b scope: keyword.other.mysql - pop: true - - match: (?=\S) - pop: true + pop: 1 + - include: else-pop new-column-name: - match: (?=\S) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 40487a6f33..354d1c0a89 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -24,6 +24,14 @@ contexts: prototype: - include: comments + else-pop: + - match: (?=\S) + pop: 1 + + immediately-pop: + - match: '' + pop: 1 + main: - include: statements - match: ';' @@ -96,8 +104,7 @@ contexts: identifier-create: - meta_include_prototype: false - meta_scope: meta.toc-list.full-identifier.sql entity.name.function.sql - - match: '' - pop: 1 + - include: immediately-pop single-identifier-after-whitespace: - match: \s* @@ -120,8 +127,7 @@ contexts: captures: 1: punctuation.accessor.dot.sql set: single-identifier-after-whitespace - - match: '' - pop: 1 + - include: immediately-pop identifier-part: - include: simple-identifier-part @@ -201,16 +207,13 @@ contexts: expect-type: - include: built-in-type - # TODO: support custom type identifiers wrapped in square brackets etc. in TSQL syntax just like built-in types - match: '{{simple_identifier}}' scope: support.type.sql pop: 1 - - match: (?=\S) - pop: 1 + - include: else-pop after-type: - - match: (?=\S) - pop: 1 + - include: else-pop expressions-or-column-name: - include: wildcard-identifier @@ -271,8 +274,7 @@ contexts: - match: \( scope: punctuation.section.group.begin.sql set: inside-group - - match: (?=\S) - pop: 1 + - include: else-pop inside-case-expression: - meta_scope: meta.statement.conditional.case.sql @@ -311,15 +313,14 @@ contexts: - meta_include_prototype: false - meta_scope: meta.function-call.sql - match: \( - scope: meta.group.sql punctuation.section.group.begin.sql + scope: meta.group.sql punctuation.section.arguments.begin.sql set: inside-method-call - - match: (?=\S) - pop: 1 + - include: else-pop inside-method-call: - meta_content_scope: meta.function-call.sql meta.group.sql - match: \) - scope: meta.function-call.sql meta.group.sql punctuation.section.group.end.sql + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql pop: 1 - match: ',' scope: punctuation.separator.argument.sql @@ -404,8 +405,7 @@ contexts: push: - table-name - single-identifier-after-whitespace - - match: (?=\S) - pop: 1 + - include: else-pop ddl-table-creation-columns: - match: \( @@ -415,14 +415,12 @@ contexts: ddl-drop-target: - meta_include_prototype: false - meta_scope: meta.drop.sql - - match: '' - pop: 1 + - include: immediately-pop ddl-target: - match: '{{ddl_target}}' scope: keyword.other.sql - - match: (?=\S) - pop: 1 + - include: else-pop ddl-drop-table: - meta_scope: meta.drop.sql @@ -441,8 +439,7 @@ contexts: ddl-alter-target: - meta_scope: meta.alter.sql - include: ddl-alter-common - - match: (?=\S) - pop: 1 + - include: else-pop ddl-alter-common: - match: \b(?i:add\s+constraint)\b @@ -571,56 +568,47 @@ contexts: column-name: - meta_include_prototype: false - meta_content_scope: meta.column-name.sql - - match: '' - pop: 1 + - include: immediately-pop column-name-declaration: - meta_include_prototype: false - meta_content_scope: meta.column-name.sql variable.other.member.declaration.sql - - match: '' - pop: 1 + - include: immediately-pop column-alias: - meta_include_prototype: false - meta_content_scope: meta.column-alias.sql - - match: '' - pop: 1 + - include: immediately-pop database-name: - meta_include_prototype: false - meta_content_scope: meta.database-name.sql - - match: '' - pop: 1 + - include: immediately-pop table-name: - meta_include_prototype: false - meta_content_scope: meta.table-name.sql - - match: '' - pop: 1 + - include: immediately-pop table-alias-name: - meta_include_prototype: false - meta_content_scope: meta.table-alias-name.sql - - match: '' - pop: 1 + - include: immediately-pop procedure-name: - meta_include_prototype: false - meta_content_scope: meta.procedure-name.sql - - match: '' - pop: 1 + - include: immediately-pop constraint-name: - meta_include_prototype: false - meta_content_scope: meta.constraint-name.sql - - match: '' - pop: 1 + - include: immediately-pop schema-name: - meta_include_prototype: false - meta_content_scope: meta.schema-name.sql - - match: '' - pop: 1 + - include: immediately-pop subquery: - match: \( @@ -667,19 +655,16 @@ contexts: 1: keyword.other.sql 2: meta.group.tablesample.sql punctuation.section.group.begin.sql push: tablesample - - match: (?=\S) - pop: 1 + - include: else-pop join-on: - match: (?i)\bon\b scope: keyword.operator.join.sql pop: 1 - - match: (?=\S) - pop: 1 + - include: else-pop set: - - match: (?=\S) - pop: 1 + - include: else-pop pop-on-top-level-reserved-word: - match: (?={{reserved}}|{{additional_reserved}}) @@ -703,13 +688,11 @@ contexts: table-valued-function-name: - meta_include_prototype: false - meta_content_scope: meta.table-valued-function-name.sql - - match: '' - pop: 1 + - include: immediately-pop possible-operator: - include: operators - - match: (?=\S) - pop: 1 + - include: else-pop wildcard-identifier: - match: \* @@ -717,8 +700,7 @@ contexts: possible-wildcard: - include: wildcard-identifier - - match: (?=\S) - pop: 1 + - include: else-pop tablesample: - meta_content_scope: meta.group.tablesample.sql @@ -737,8 +719,7 @@ contexts: push: after-declare after-declare: - - match: '' - pop: 1 + - include: immediately-pop collate: - match: \b(?i:collate)\b @@ -749,5 +730,4 @@ contexts: - match: \w+ scope: support.constant.sql pop: 1 - - match: (?=\S) - pop: 1 + - include: else-pop diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 62d6bc7ec2..94955d86c6 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -82,8 +82,7 @@ contexts: set: - like-escape-fail - inside-like-single-quoted-string - - match: (?=\S) - pop: 1 + - include: else-pop like-string-followed-by-escape-slash: - match: \' @@ -92,8 +91,7 @@ contexts: - like-escape-character-slash - like-escape-pop - inside-like-single-quoted-string-slash-escape - - match: (?=\S) - pop: 1 + - include: else-pop like-string-followed-by-escape-caret: - match: \' @@ -102,8 +100,7 @@ contexts: - like-escape-character-caret - like-escape-pop - inside-like-single-quoted-string-caret-escape - - match: (?=\S) - pop: 1 + - include: else-pop like-string-followed-by-unknown-escape: - match: \' @@ -112,8 +109,7 @@ contexts: - like-escape-character-any - like-escape-pop - inside-like-single-quoted-string - - match: (?=\S) - pop: 1 + - include: else-pop inside-like-single-quoted-string-slash-escape: - meta_include_prototype: false @@ -153,15 +149,13 @@ contexts: like-escape-fail: - match: \b(?i:escape)\b fail: like-strings-branch - - match: (?=\S) - pop: 1 + - include: else-pop like-escape-pop: - match: \b(?i:escape)\b scope: keyword.operator.word.sql pop: 1 - - match: (?=\S) - pop: 1 + - include: else-pop like-escape-character-any: - match: (\')([^'])(\') @@ -171,8 +165,7 @@ contexts: 2: constant.character.escape.sql 3: punctuation.definition.string.end.sql pop: 1 - - match: (?=\S) - pop: 1 + - include: else-pop like-escape-character-caret: - match: (\')(\^)(\') @@ -387,7 +380,7 @@ contexts: scope: meta.function-call.sql captures: 1: support.function.scalar.sql - 2: meta.group.sql punctuation.section.group.begin.sql + 2: meta.group.sql punctuation.section.arguments.begin.sql push: - method-call-convert - expect-type @@ -398,7 +391,7 @@ contexts: method-call-convert: - meta_content_scope: meta.function-call.sql meta.group.sql - match: \) - scope: meta.function-call.sql meta.group.sql punctuation.section.group.end.sql + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql pop: 1 - match: ',' scope: punctuation.separator.argument.sql @@ -425,8 +418,7 @@ contexts: captures: 1: punctuation.definition.variable.tsql set: expect-type - - match: (?=\S) - pop: 1 + - include: else-pop expect-type: - meta_prepend: true @@ -449,8 +441,7 @@ contexts: - match: '[-+/*%^|]=' scope: keyword.operator.assignment.tsql - include: operators - - match: (?=\S) - pop: 1 + - include: else-pop maybe-table-alias: - meta_prepend: true @@ -565,15 +556,14 @@ contexts: cast: - meta_scope: meta.function-call.sql - match: \( - scope: meta.group.sql punctuation.section.group.begin.sql + scope: meta.group.sql punctuation.section.arguments.begin.sql set: inside-cast-method-call - - match: (?=\S) - pop: 1 + - include: else-pop inside-cast-method-call: - meta_content_scope: meta.function-call.sql meta.group.sql - match: \) - scope: meta.function-call.sql meta.group.sql punctuation.section.group.end.sql + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql pop: 1 - match: \b(?i:as)\b scope: keyword.operator.assignment.tsql @@ -597,15 +587,14 @@ contexts: scope: meta.function-call.tsql captures: 1: meta.table-valued-function-name.sql support.function.tsql - 2: punctuation.section.group.begin.tsql + 2: punctuation.section.arguments.begin.tsql set: inside-openrowset-call exec: - include: assignment-operator - include: pop-on-top-level-reserved-word - include: expressions - - match: (?=\S) - pop: 1 + - include: else-pop expect-procedure-name: - meta_include_prototype: false @@ -635,8 +624,7 @@ contexts: cte-table-name: - meta_include_prototype: false - meta_content_scope: meta.cte-table-name.sql - - match: '' - pop: 1 + - include: immediately-pop for-xml: - match: \b(?i:raw|auto|elements|root|path)\b @@ -646,15 +634,14 @@ contexts: - match: (?=\)) pop: 1 - include: expressions - - match: (?=\S) - pop: 1 + - include: else-pop inside-openrowset-call: - meta_content_scope: meta.group.sql - match: ';' scope: punctuation.separator.sequence.tsql - match: \) - scope: meta.function-call.tsql meta.group.tsql punctuation.section.group.end.sql + scope: meta.function-call.tsql meta.group.tsql punctuation.section.arguments.end.sql set: maybe-table-alias - include: inside-method-call @@ -686,8 +673,7 @@ contexts: set: - filegroup-name - single-identifier-after-whitespace - - match: (?=\S) - pop: 1 + - include: else-pop inside-ddl-table-creation-columns: - meta_prepend: true @@ -710,8 +696,7 @@ contexts: raiserror-options: - match: \b(?i:nowait|log|seterror)\b scope: keyword.other.tsql - - match: (?=\S) - pop: 1 + - include: else-pop cursor-declaration: - meta_content_scope: meta.cursor-declaration.tsql @@ -720,16 +705,14 @@ contexts: - match: \b(?i:for)\b scope: keyword.other.tsql set: expect-cursor-select-statement - - match: (?=\S) - pop: 1 + - include: else-pop expect-cursor-select-statement: - meta_content_scope: meta.cursor-declaration.tsql - match: \b(?i:select)\b scope: keyword.other.dml.sql set: after-cursor-select-statement - - match: (?=\S) - pop: 1 + - include: else-pop after-cursor-select-statement: - meta_content_scope: meta.cursor-declaration.tsql @@ -747,8 +730,7 @@ contexts: - match: (?i)\b(?:READ\s+ONLY|UPDATE(?:\s+OF)?)\b scope: storage.modifier.tsql pop: 1 - - match: (?=\S) - pop: 1 + - include: else-pop with-column-definition: - match: \b(?i:with)\b diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 1d9297b8d1..10d57f1036 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -9,11 +9,11 @@ CREATE KEYSPACE killrvideo WITH replication = {'class':'SimpleStrategy', 'replic -- ^ keyword.operator -- ^ punctuation.section.braces.begin -- ^^^^^^^ string.quoted.single --- ^ punctuation.separator.mapping.key-value +-- ^ punctuation.separator.key-value -- ^^^^^^^^^^^^^^^^ string.quoted.single -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^^^^^^^^^^ string.quoted.single --- ^ punctuation.separator.mapping.key-value +-- ^ punctuation.separator.key-value -- ^ meta.number.integer.decimal constant.numeric.value -- ^ punctuation.section.braces.end -- ^ punctuation.terminator.statement @@ -23,9 +23,9 @@ select someid, token(someid), something -- ^^^^^^ meta.column-name -- ^ punctuation.separator.sequence -- ^^^^^ meta.function-call support.function --- ^ meta.function-call meta.group punctuation.section.parens.begin +-- ^ meta.function-call meta.group punctuation.section.arguments.begin -- ^^^^^^ meta.function-call meta.group meta.column-name --- ^ meta.function-call meta.group punctuation.section.parens.end +-- ^ meta.function-call meta.group punctuation.section.arguments.end -- ^ punctuation.separator.sequence -- ^^^^^^^^^ meta.column-name from something_by_someid @@ -36,16 +36,16 @@ where token(someid) >= token(d821d7d8-8265-402e-9a72-c61ab8473ab6) -- ^^^^^^^^^^^^^ meta.function-call -- ^^^^^ support.function -- ^^^^^^^^ meta.group --- ^ punctuation.section.parens.begin +-- ^ punctuation.section.arguments.begin -- ^^^^^^ meta.column-name --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.end -- ^^ keyword.operator.comparison -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call -- ^^^^^ support.function -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group --- ^ punctuation.section.parens.begin +-- ^ punctuation.section.arguments.begin -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.uuid --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.end -- ^ - meta and token(someid) <= token(cf0acefc-ccff-42a0-8753-65d82e9c9b0f) limit 2000; @@ -249,18 +249,18 @@ VALUES ( false, {77a969b4-378a-4fb0-b531-83404ee3c395:{id:22f7244c-c6d7-4bd7-aeac-a886c4242cd8,sometext:'text here',empty:{}}} -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.uuid - -- ^ punctuation.separator.mapping.key-value + -- ^ punctuation.separator.key-value -- ^ punctuation.section.braces.begin -- ^^ meta.mapping.key string.unquoted - -- ^ punctuation.separator.mapping.key-value + -- ^ punctuation.separator.key-value -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.uuid -- ^ punctuation.separator.sequence -- ^^^^^^^^ meta.mapping.key string.unquoted - -- ^ punctuation.separator.mapping.key-value + -- ^ punctuation.separator.key-value -- ^^^^^^^^^^^ string.quoted.single -- ^ punctuation.separator.sequence -- ^^^^^ meta.mapping.key string.unquoted - -- ^ punctuation.separator.mapping.key-value + -- ^ punctuation.separator.key-value -- ^ punctuation.section.braces.begin -- ^^^ punctuation.section.braces.end ); @@ -412,27 +412,27 @@ CREATE INDEX todo_dates ON users (KEYS(todo)); -- ^^^^^ meta.create meta.table-name -- ^ punctuation.section.group.begin -- ^^^^ meta.function-call support.function.scalar --- ^ punctuation.section.parens.begin +-- ^ punctuation.section.arguments.begin -- ^^^^ meta.column-name --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.end -- ^ punctuation.section.group.end CREATE INDEX entries_idx ON race (ENTRIES(race_wins)); -- ^^^^ meta.create meta.table-name -- ^ punctuation.section.group.begin -- ^^^^^^^ meta.function-call support.function.scalar --- ^ punctuation.section.parens.begin +-- ^ punctuation.section.arguments.begin -- ^^^^^^^^^ meta.column-name --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.end -- ^ punctuation.section.group.end CREATE INDEX rnumbers_idx ON cycling.race_starts (FULL(rnumbers)); -- ^^^^^^^^^^^^^^^^^^^ meta.create meta.table-name -- ^ punctuation.section.group.begin -- ^^^^ meta.function-call support.function.scalar --- ^ punctuation.section.parens.begin +-- ^ punctuation.section.arguments.begin -- ^^^^^^^^ meta.column-name --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.end -- ^ punctuation.section.group.end SELECT album, tags diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 12bfb40558..cfc34827a4 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -108,8 +108,8 @@ create table fancy_table ( -- ^^^^^^^^^^^^^^^^^ storage.type.sql -- ^^^^^^^ storage.modifier -- ^^^ meta.function-call support.function --- ^ punctuation.section.parens.begin --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.begin +-- ^ punctuation.section.arguments.end -- ^ punctuation.separator.sequence mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, -- TODO: seems like :: is a postgresql cast operator -- ^^^^^^^^^^^^^^^^^^^ storage.type.sql diff --git a/SQL/tests/syntax/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.sql index 931c66ad40..9af692a980 100644 --- a/SQL/tests/syntax/syntax_test_postgres.sql +++ b/SQL/tests/syntax/syntax_test_postgres.sql @@ -19,9 +19,9 @@ SELECT a, char_length(a) FROM test1; -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^^^^ meta.function-call -- ^^^^^^^^^^^ support.function --- ^ meta.group punctuation.section.parens.begin +-- ^ meta.group punctuation.section.arguments.begin -- ^ meta.group meta.column-name - variable.other.member.declaration --- ^ meta.group punctuation.section.parens.end +-- ^ meta.group punctuation.section.arguments.end -- ^^^^ keyword.other.dml - meta.group -- ^^^^^ meta.table-name -- ^ punctuation.terminator.statement @@ -65,8 +65,8 @@ CREATE TABLE IF NOT EXISTS public.dropzone_details -- ^^^^ constant.language.null -- ^^^^^^^ storage.modifier -- ^^^^^^^^^^^^^^^^ meta.function-call support.function --- ^ meta.function-call meta.group punctuation.section.parens.begin --- ^ meta.function-call meta.group punctuation.section.parens.end +-- ^ meta.function-call meta.group punctuation.section.arguments.begin +-- ^ meta.function-call meta.group punctuation.section.arguments.end -- ^ punctuation.separator.sequence name text COLLATE pg_catalog."default", doc jsonb, diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index fec22e7eac..7eac426a08 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -220,15 +220,15 @@ SET @path = 'C:\Backup\' SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) -- ^ keyword.operator -- ^^^^^^^ meta.function-call support.function.scalar --- ^ meta.function-call meta.group punctuation.section.parens.begin +-- ^ meta.function-call meta.group punctuation.section.arguments.begin -- ^^^^^^^^^^^ storage.type -- ^ punctuation.separator -- ^^^^^^^ support.function.scalar --- ^ punctuation.section.parens.begin --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.begin +-- ^ punctuation.section.arguments.end -- ^ punctuation.separator.argument -- ^^^ meta.number.integer.decimal constant.numeric.value --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.end -- ^ - meta.function-call - meta.group DECLARE db_cursor CURSOR SCROLL DYNAMIC FOR @@ -397,8 +397,12 @@ INSERT INTO my_table (foo, bar) -- ^^^^^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^ - meta.function-call - support -- ^^^^^^^^ meta.table-name +-- ^ punctuation.section.group.begin +-- ^ punctuation.section.group.end VALUES (2, 'two'), -- ^^^ keyword.other.dml.II +-- ^ punctuation.section.group.begin +-- ^ punctuation.section.group.end (3, 'three') INSERT INTO #my_table @@ -419,9 +423,9 @@ SELECT foo AS foobar, COUNT(*) AS tally -- ^^^^^^^^ meta.function-call -- ^^^^^ support.function.aggregate -- ^^^ meta.group --- ^ punctuation.section.parens.begin +-- ^ punctuation.section.arguments.begin -- ^ variable.language.wildcard.asterisk --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.end -- ^^ keyword.operator.assignment.alias -- ^^^^^ meta.column-alias FROM bar @@ -560,11 +564,11 @@ PRINT 'Record with ID ' + CAST(@RecordID AS VARCHAR(10)) + ' has been updated.' -- ^ keyword.operator.arithmetic -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call -- ^^^^ support.function --- ^ punctuation.section.parens.begin +-- ^ punctuation.section.arguments.begin -- ^^^^^^^^^ variable.other.readwrite -- ^^ keyword.operator.assignment -- ^^^^^^^^^^^ storage.type --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.end UPDATE foo SET Value = Bar.Value @@ -1016,9 +1020,9 @@ PIVOT AVG(StandardCost) --^^^^^^^^^^^^^^^^^ meta.function-call --^^^ support.function.aggregate --- ^ punctuation.section.parens.begin +-- ^ punctuation.section.arguments.begin -- ^^^^^^^^^^^^ meta.column-name --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.end FOR DaysToManufacture IN ([0], [1], [2], [3], [4]) --^^^ keyword.other -- ^^^^^^^^^^^^^^^^^ meta.column-name @@ -1210,8 +1214,8 @@ CREATE TABLE [dbo].[be_Categories]( -- ^^^^^^^ storage.modifier -- ^ punctuation.section.group.begin -- ^^^^^ meta.function-call support.function --- ^ punctuation.section.parens.begin --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.begin +-- ^ punctuation.section.arguments.end -- ^ punctuation.section.group.end -- ^ punctuation.separator.sequence [CategoryName] [nvarchar](50) NULL, @@ -1316,9 +1320,9 @@ CROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) AS func_call_resu -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-valued-function-name -- ^^^^^^^^^^^^^^^^ meta.group --- ^ punctuation.section.parens.begin +-- ^ punctuation.section.arguments.begin -- ^^^^^^^^^^^^^^ meta.column-name --- ^ punctuation.section.parens.end +-- ^ punctuation.section.arguments.end -- ^^ keyword.operator.assignment.alias - meta.function-call -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-alias-name GO @@ -1326,25 +1330,29 @@ GO SELECT * FROM Department D OUTER APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID, 123, 'testing123') -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call meta.table-valued-function-name --- ^ meta.function-call meta.group punctuation.section.parens.begin +-- ^ meta.function-call meta.group punctuation.section.arguments.begin -- ^^^^^^^^^^^^^^ meta.function-call meta.group meta.column-name -- ^ meta.function-call meta.group punctuation.separator.argument -- ^^^ meta.function-call meta.group meta.number.integer.decimal constant.numeric.value -- ^ meta.function-call meta.group punctuation.separator.argument -- ^^^^^^^^^^^^ meta.function-call meta.group string.quoted.single --- ^ meta.function-call meta.group punctuation.section.parens.end +-- ^ meta.function-call meta.group punctuation.section.arguments.end GO SELECT DB_NAME(r.database_id) AS [Database], st.[text] AS [Query] FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.plan_handle) st -- ^^^^^^^^^^^^^^^^^^^^ meta.function-call meta.table-valued-function-name --- ^ meta.function-call meta.group punctuation.section.parens.begin +-- ^ meta.function-call meta.group punctuation.section.arguments.begin -- ^^^^^^^^^^^^^ meta.function-call meta.group meta.column-name --- ^ meta.function-call meta.group punctuation.section.parens.end +-- ^ meta.function-call meta.group punctuation.section.arguments.end -- ^^ meta.table-alias-name WHERE r.session_Id > 50 -- Consider spids for users only, no system spids. AND r.session_Id NOT IN (@@SPID) -- Don't include request from current spid. +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^ support.variable.global +-- ^^ punctuation.definition.variable +-- ^ meta.group punctuation.section.group.end SELECT p.BusinessEntityID , p.FirstName , @@ -1464,7 +1472,7 @@ FROM OPENXML (@XmlDocumentHandle, '/ROOT/Customer',2) -- TODO: apply xpath -- ^ - meta.function-call -- ^^^^^^^ meta.table-valued-function-name support.function -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group --- ^ punctuation.section.parens.begin +-- ^ punctuation.section.arguments.begin -- ^^^^^^^^^^^^^^^^^^ variable.other.readwrite WITH (CustomerID varchar(10), -- ^^^^ keyword.other @@ -1521,17 +1529,20 @@ SELECT a.* FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', -- ^^^^ keyword.other.dml -- ^^^^^^^^^^ meta.function-call meta.table-valued-function-name support.function +-- ^ punctuation.section.arguments.begin 'C:\SAMPLES\Northwind.mdb'; -- ^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single -- ^ punctuation.separator.sequence 'admin'; 'password', Customers) AS a; --- ^ meta.function-call meta.group punctuation.section.parens.end +-- ^ meta.function-call meta.group punctuation.section.arguments.end -- ^^ keyword.operator.assignment.alias - meta.group - meta.function-call -- ^ meta.table-alias-name DECLARE @Data NVARCHAR(MAX) +-- ^ punctuation.section.group.begin +-- ^ punctuation.section.group.end SELECT @Data = ( SELECT [CustomerID] as "@CustomerID", [CustomerName], @@ -1547,6 +1558,7 @@ SELECT @Data = ( WHERE CustomerID < 3 FOR XML PATH('Customer'), ROOT('Customers') -- ^^^^^^^ keyword.other -- ^^^^ keyword.other +-- ^ punctuation.section.group.begin -- ^ punctuation.separator.sequence -- ^^^^ keyword.other ) From 2ef35ee196e712af569abdaef6fc690c186a0413 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 6 Mar 2022 16:16:41 +0100 Subject: [PATCH 076/250] [SQL] Update Embedded PHP SQL syntaxes --- PHP/Embeddings/SQL (for PHP Interpolation).sublime-syntax | 8 ++++++++ PHP/Embeddings/SQL (for PHP).sublime-syntax | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/PHP/Embeddings/SQL (for PHP Interpolation).sublime-syntax b/PHP/Embeddings/SQL (for PHP Interpolation).sublime-syntax index 471cbc6eb4..7d4bbf5ed8 100644 --- a/PHP/Embeddings/SQL (for PHP Interpolation).sublime-syntax +++ b/PHP/Embeddings/SQL (for PHP Interpolation).sublime-syntax @@ -1,6 +1,7 @@ %YAML 1.2 --- scope: source.sql.interpolated.php +version: 2 hidden: true extends: Packages/SQL/SQL.sublime-syntax @@ -9,3 +10,10 @@ contexts: prototype: - meta_prepend: true - include: Packages/PHP/PHP Source.sublime-syntax#interpolation + + main: + - meta_prepend: true + # prevent stray bracket highlighting + - match: \) + scope: punctuation.section.arguments.end.sql + diff --git a/PHP/Embeddings/SQL (for PHP).sublime-syntax b/PHP/Embeddings/SQL (for PHP).sublime-syntax index 361f780251..d3df586ab7 100644 --- a/PHP/Embeddings/SQL (for PHP).sublime-syntax +++ b/PHP/Embeddings/SQL (for PHP).sublime-syntax @@ -1,6 +1,7 @@ %YAML 1.2 --- scope: source.sql.embedded.php +version: 2 hidden: true extends: Packages/SQL/SQL.sublime-syntax @@ -11,6 +12,12 @@ contexts: - include: php-single-quoted-strings - include: php-string-single-quoted-escapes + main: + - meta_prepend: true + # prevent stray bracket highlighting + - match: \) + scope: punctuation.section.arguments.end.sql + php-string-single-quoted-escapes: - match: \\[\\'] scope: constant.character.escape.php From 5e130b9d0274048b07b1d4ff6f5b63cc82ae70e3 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 6 Mar 2022 22:17:12 +0200 Subject: [PATCH 077/250] [SQL] improve TSQL foreign key and temporal table support --- SQL/SQL (basic).sublime-syntax | 32 ++++-- SQL/TSQL.sublime-syntax | 49 +++++++- SQL/tests/syntax/syntax_test_mysql.sql | 2 +- SQL/tests/syntax/syntax_test_tsql.sql | 150 +++++++++++++++++++++++++ 4 files changed, 224 insertions(+), 9 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 354d1c0a89..ed8f27b5a0 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -445,6 +445,7 @@ contexts: - match: \b(?i:add\s+constraint)\b scope: meta.add.sql keyword.other.sql push: + - after-constraint-pop - constraint-name - single-identifier-after-whitespace - match: \b(?i:add\s+(?:(?:fulltext|spatial)\s+(index|key)|index))\b @@ -517,13 +518,7 @@ contexts: push: - constraint-name - single-identifier-after-whitespace - - match: \b(?i:references)\b - scope: storage.modifier.sql - push: - - table-name - - single-identifier-after-whitespace - - match: \b(?i:(((?:foreign|fulltext|primary|unique)\s+)?key|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|check|default))\b - scope: storage.modifier.sql + - include: after-constraint - include: expressions - include: ddl-creation-column @@ -731,3 +726,26 @@ contexts: scope: support.constant.sql pop: 1 - include: else-pop + + after-constraint: + - match: \b(?i:check)\b + scope: keyword.other.sql + - match: \b(?i:(((?:foreign|fulltext|primary|unique)\s+)?key|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|default))\b + scope: storage.modifier.sql + push: maybe-column-reference + - match: \b(?i:references)\b + scope: storage.modifier.sql + push: + - maybe-column-reference + - table-name + - single-identifier-after-whitespace + + after-constraint-pop: + - include: after-constraint + - include: else-pop + + maybe-column-reference: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-ddl-table-creation-columns + - include: else-pop diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 94955d86c6..067d93ddea 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -61,6 +61,8 @@ contexts: - like-string-followed-by-escape-slash - like-string-followed-by-escape-caret - like-string-followed-by-unknown-escape + - match: '%' + scope: keyword.operator.arithmetic.tsql variables: - match: (@)\w+ @@ -343,6 +345,10 @@ contexts: - create-condition - ddl-target + ddl-create-target-expect-as: + - meta_prepend: true + - include: with + ddl-target: - meta_prepend: true - match: \b(?i:proc|unique|clustered|nonclustered)\b @@ -528,6 +534,19 @@ contexts: push: - index-name - single-identifier-after-whitespace + - match: \b((?i:SYSTEM_VERSIONING))\s*(=) + captures: + 1: keyword.other.tsql + 2: keyword.operator.assignment.tsql + push: + - maybe-nested-with-group + - match: \b((?i:HISTORY_TABLE))\s*(=) + captures: + 1: keyword.other.tsql + 2: keyword.operator.assignment.tsql + push: + - table-name + - single-identifier-after-whitespace - match: \w+ scope: constant.language.with.tsql - match: ',' @@ -537,15 +556,34 @@ contexts: push: with-assignment with-assignment: + - include: with-bool-assignment + - include: expressions-pop-at-comma + + with-bool-assignment: - match: \b(?i:ON|OFF)\b scope: constant.language.bool.tsql - - include: expressions-pop-at-comma expressions-pop-at-comma: - match: (?=[,)]) pop: 1 - include: expressions + maybe-nested-with-group: + - include: with-bool-assignment + - match: \( + scope: meta.group.sql punctuation.section.group.begin.sql + set: inside-with-group + - include: else-pop + + after-type: + - meta_prepend: true + - match: \b(?i:GENERATED\s+ALWAYS\s+AS\s+ROW\s+(?:START|END)(?:\s+HIDDEN)?)\b + scope: keyword.other.tsql + - match: \b(?i:ENCRYPTED\s+WITH)\b + scope: storage.modifier.tsql + set: with-paren-or-pop + - include: collate + maybe-identifier-accessor: - meta_prepend: true - match: \s*(\.{2,}) @@ -664,6 +702,7 @@ contexts: - match: \( scope: punctuation.section.group.begin.sql set: + - maybe-with-table-options - maybe-filegroup - inside-ddl-table-creation-columns @@ -675,15 +714,23 @@ contexts: - single-identifier-after-whitespace - include: else-pop + maybe-with-table-options: + - include: with + - include: else-pop + inside-ddl-table-creation-columns: - meta_prepend: true - match: \b(?i:ROWGUIDCOL|CLUSTERED|NONCLUSTERED)\b scope: storage.modifier.tsql + - match: \b(?i:period\s+for\s+system_time)\b + scope: storage.modifier.tsql computed-column-definition: - meta_content_scope: meta.computed-column-definition.tsql - match: (?=,) pop: 1 + - match: (?=\b(?i:constraint)\b) + pop: 1 - include: expressions-or-column-name raiserror-args: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index cfc34827a4..100b441222 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -126,7 +126,7 @@ create table fancy_table ( UNIQUE (foreign_id), CONSTRAINT fancy_table_valid1 CHECK (id <> foreign_id) -- ^^^^^^^^^^ storage.modifier.sql --- ^^^^^ storage.modifier.sql +-- ^^^^^ keyword.other -- ^^^^^^^^^^^^^^^^^^ meta.group meta.group -- ^^ meta.column-name -- ^^ keyword.operator.comparison diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 7eac426a08..32d00bcac9 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1254,6 +1254,57 @@ CREATE TABLE [dbo].[be_Categories]( -- ^ punctuation.definition.identifier.end GO -------------- +CREATE TABLE [dbo].[table_with_constraint_following_derived_column]( + [SomeID] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [DF_be_Categories_CategoryID] DEFAULT (newid()), + [Data] [nvarchar](MAX) NOT NULL, + [DerivedColumn1] AS CAST(JSON_VALUE([Data], '$.info.address.PostCode') AS NVARCHAR(1000)) +-- ^^^^^^^^^^^^^^^^ meta.column-name variable.other.member.declaration +-- ^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.computed-column-definition meta.function-call +-- ^^^^ support.function +-- ^ punctuation.section.arguments.begin +-- ^^^^^^^^^^ support.function +-- ^ punctuation.section.arguments.begin +-- ^^^^^^ meta.group meta.function-call meta.group meta.column-name +-- ^ meta.group meta.function-call meta.group punctuation.separator.argument +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +-- ^ punctuation.section.arguments.end +-- ^^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^ storage.type +-- ^ punctuation.section.arguments.end + CONSTRAINT [PK_be_Categories] PRIMARY KEY CLUSTERED +-- ^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^^^^^^^^^^ meta.constraint-name +-- ^^^^^^^^^^^ storage.modifier +-- ^^^^^^^^^ storage.modifier + ( + [CategoryID] ASC +-- ^^^^^^^^^^^^ meta.column-name +-- ^^^ keyword.other.order + ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +-- ^^^^ keyword.other.dml +-- ^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^^ constant.language.bool +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^ constant.language.bool +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^ constant.language.bool +-- ^ punctuation.section.group.end +-- ^^ keyword.other +-- ^^^^^^^^^ meta.filegroup-name +) ON [PRIMARY] +-- <- punctuation.section.group.end +--^^ meta.create keyword.other +-- ^^^^^^^^^ meta.filegroup-name +-- ^ punctuation.definition.identifier.begin +-- ^ punctuation.definition.identifier.end +GO +-------------- CREATE TABLE [Employee]( [EmployeeID] [int] NOT NULL PRIMARY KEY, -- ^^^^^^^^^^^^ meta.column-name @@ -1700,3 +1751,102 @@ WHERE CountryCode = 'FR' ^^ - punctuation ***/ -- ^^^^ comment.block.documentation punctuation.definition.comment.end + +SELECT FLOOR(hours / 24) as days, hours%24 as hours +-- ^ keyword.operator.arithmetic +FROM timings + +-- Temporal table +CREATE TABLE Department +( + DepartmentNumber CHAR(10) NOT NULL PRIMARY KEY CLUSTERED, + DepartmentName VARCHAR(50) NOT NULL, + ManagerID INT NULL, + ParentDepartmentNumber CHAR(10) NULL, + SysStartTime DATETIME2 GENERATED ALWAYS AS ROW START HIDDEN NOT NULL, +-- ^^^^^^^^^^^^ meta.column-name variable.other.member.declaration +-- ^^^^^^^^^ storage.type +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ keyword.other +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^ punctuation.separator.sequence + SysEndTime DATETIME2 GENERATED ALWAYS AS ROW END HIDDEN NOT NULL, +-- ^^^^^^^^^^ meta.column-name variable.other.member.declaration +-- ^^^^^^^^^ storage.type +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ keyword.other +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null +-- ^ punctuation.separator.sequence + PERIOD FOR SYSTEM_TIME (SysStartTime, SysEndTime) +-- ^^^^^^^^^^^^^^^^^^^^^^ storage.modifier +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.column-name - variable.other.member.declaration +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^ meta.column-name - variable.other.member.declaration +-- ^ punctuation.section.group.end +) +WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.Department_History, DATA_CONSISTENCY_CHECK = ON)); +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +--^^ keyword.other.dml +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^^^^^ keyword.other +-- ^ keyword.operator.assignment +-- ^^ constant.language.bool +-- ^ punctuation.section.group.begin +-- ^^^^^^^^^^^^^ keyword.other +-- ^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^^^^^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^ constant.language.bool +-- ^ punctuation.section.group.end +-- ^ punctuation.section.group.end +-- ^ punctuation.terminator.statement + +CREATE TABLE Customers ( + CustName NVARCHAR(60) + ENCRYPTED WITH ( +-- ^^^^^^^^^^^^^^ storage.modifier + COLUMN_ENCRYPTION_KEY = MyCEK, +-- ^^^^^^^^^^^^^^^^^^^^^ constant.language.with + ENCRYPTION_TYPE = RANDOMIZED, +-- ^^^^^^^^^^^^^^^ constant.language.with + ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256' +-- ^^^^^^^^^ constant.language.with +-- ^ keyword.operator.assignment +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single + ), +-- ^ punctuation.section.group.end +-- ^ punctuation.separator.sequence + SSN VARCHAR(11) COLLATE Latin1_General_BIN2 +-- ^^^ meta.create meta.group.table-columns meta.column-name variable.other.member.declaration +-- ^^^^^^^^^^^ storage.type +-- ^^^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^^ support.constant + ENCRYPTED WITH ( +-- ^^^^^^^^^^^^^^ storage.modifier + COLUMN_ENCRYPTION_KEY = MyCEK, + ENCRYPTION_TYPE = DETERMINISTIC , + ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256' + ), + Age INT NULL +); + +ALTER TABLE inventory +ADD CONSTRAINT fk_inv_product_id +--^^^^^^^^^^^^ meta.alter meta.add keyword.other +-- ^^^^^^^^^^^^^^^^^ meta.alter meta.constraint-name + FOREIGN KEY (product_id) +-- ^^^^^^^^^^^ meta.alter storage.modifier +-- ^ meta.alter meta.group.table-columns punctuation.section.group.begin +-- ^^^^^^^^^^ meta.column-name + REFERENCES products (product_id) +-- ^^^^^^^^^^ meta.alter storage.modifier +-- ^^^^^^^^ meta.alter meta.table-name +-- ^ meta.alter meta.group.table-columns punctuation.section.group.begin +-- ^^^^^^^^^^ meta.column-name +-- ^ punctuation.section.group.end + ON DELETE CASCADE; +-- ^^^^^^^^^^^^^^^^^ meta.alter storage.modifier +-- ^ punctuation.terminator.statement From ee39f29a65eb39cd797b026a3b26734991798a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aziz=20K=C3=B6ksal?= Date: Tue, 12 Apr 2022 23:37:13 +0200 Subject: [PATCH 078/250] [SQL] Rename PostgresSQL to PostgreSQL * The official site rarely refers to is as "PostgresSQL". * The name "PostgreSQL" has way more results in search engines. * The Wikipedia page never uses "PostgresSQL". --- SQL/{PostgresSQL.sublime-syntax => PostgreSQL.sublime-syntax} | 2 +- SQL/tests/syntax/syntax_test_postgres.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename SQL/{PostgresSQL.sublime-syntax => PostgreSQL.sublime-syntax} (99%) diff --git a/SQL/PostgresSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax similarity index 99% rename from SQL/PostgresSQL.sublime-syntax rename to SQL/PostgreSQL.sublime-syntax index aed8b1510a..1e48754d50 100644 --- a/SQL/PostgresSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -1,6 +1,6 @@ %YAML 1.2 --- -name: PostgresSQL +name: PostgreSQL scope: source.sql.postgresql version: 2 extends: Packages/SQL/MySQL.sublime-syntax diff --git a/SQL/tests/syntax/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.sql index 9af692a980..9c05aedb2d 100644 --- a/SQL/tests/syntax/syntax_test_postgres.sql +++ b/SQL/tests/syntax/syntax_test_postgres.sql @@ -1,4 +1,4 @@ --- SYNTAX TEST "Packages/SQL/PostgresSQL.sublime-syntax" +-- SYNTAX TEST "Packages/SQL/PostgreSQL.sublime-syntax" CREATE TABLE test1 (a character(4)); -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create From c6d4ccc91ef29be7c460ebb8456e78f1c31f162b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aziz=20K=C3=B6ksal?= Date: Wed, 20 Apr 2022 23:01:55 +0200 Subject: [PATCH 079/250] [SQL] Added Postgres `.psql` file extension and renamed the test. --- SQL/PostgreSQL.sublime-syntax | 3 +++ .../{syntax_test_postgres.sql => syntax_test_postgres.psql} | 0 2 files changed, 3 insertions(+) rename SQL/tests/syntax/{syntax_test_postgres.sql => syntax_test_postgres.psql} (100%) diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 1e48754d50..e45f4c9bce 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -5,6 +5,9 @@ scope: source.sql.postgresql version: 2 extends: Packages/SQL/MySQL.sublime-syntax +file_extensions: + - psql + variables: simple_types: |- (?xi: diff --git a/SQL/tests/syntax/syntax_test_postgres.sql b/SQL/tests/syntax/syntax_test_postgres.psql similarity index 100% rename from SQL/tests/syntax/syntax_test_postgres.sql rename to SQL/tests/syntax/syntax_test_postgres.psql From c7ada36bef8ce8567d433fb3b4a4ad7ffccf807a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aziz=20K=C3=B6ksal?= Date: Wed, 20 Apr 2022 23:22:44 +0200 Subject: [PATCH 080/250] [SQL] Change `postgresql` scope suffix to `psql`. --- SQL/PostgreSQL.sublime-syntax | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index e45f4c9bce..e4bcbbc633 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -1,7 +1,7 @@ %YAML 1.2 --- name: PostgreSQL -scope: source.sql.postgresql +scope: source.sql.psql version: 2 extends: Packages/SQL/MySQL.sublime-syntax @@ -38,48 +38,48 @@ contexts: expressions: - meta_prepend: true - match: \b(?i:ARRAY)\b - scope: keyword.declaration.postgresql + scope: keyword.declaration.psql - match: \[ - scope: punctuation.section.brackets.begin.postgresql + scope: punctuation.section.brackets.begin.psql - match: \] - scope: punctuation.section.brackets.end.postgresql + scope: punctuation.section.brackets.end.psql - match: ':(?!:)' - scope: keyword.operator.range.postgresql + scope: keyword.operator.range.psql - match: \b(?i:return)\b - scope: keyword.control.flow.return.postgresql + scope: keyword.control.flow.return.psql ddl-target: - meta_prepend: true - match: \b(?i:extension|domain)\b - scope: keyword.other.postgresql + scope: keyword.other.psql ddl-create-target: - meta_prepend: true - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b - scope: keyword.other.postgresql + scope: keyword.other.psql ddl-alter-common: - meta_prepend: true - match: \b(?i:check)\b - scope: keyword.other.postgresql + scope: keyword.other.psql operators: - meta_prepend: true - match: '::' - scope: keyword.operator.cast.postgresql + scope: keyword.operator.cast.psql push: expect-type - include: regex-operators regex-operators: # https://www.postgresql.org/docs/7.4/functions-matching.html#FUNCTIONS-POSIX-REGEXP - match: '!?~\*?' - scope: keyword.operator.comparison.postgresql + scope: keyword.operator.comparison.psql push: expect-regex inside-ddl-table-creation-columns: - meta_prepend: true - match: \b(?i:unique)\b - scope: keyword.other.postgresql + scope: keyword.other.psql expect-regex: - match: \' @@ -88,13 +88,13 @@ contexts: embed_scope: source.regexp escape: \' escape_captures: - 0: meta.string.regexp.postgresql punctuation.definition.string.end.sql + 0: meta.string.regexp.psql punctuation.definition.string.end.sql pop: 1 - match: (?=\S) pop: 1 single-quoted-regex: - - meta_scope: meta.string.regexp.postgresql + - meta_scope: meta.string.regexp.psql - include: scope:source.regexp statements: @@ -109,7 +109,7 @@ contexts: - single-identifier declaration-variable-name: - - meta_scope: variable.other.postgresql + - meta_scope: variable.other.psql - match: '' pop: true @@ -120,9 +120,9 @@ contexts: ddl-create-target-expect-as: - meta_prepend: true - match: \b(?i:FOR\s+EACH\s+ROW\s+EXECUTE\s+PROCEDURE)\b - scope: keyword.other.postgresql + scope: keyword.other.psql - match: \b(?i:schema)\b - scope: storage.modifier.postgresql + scope: storage.modifier.psql push: - schema-name - single-identifier-after-whitespace From ad5e59f044be8e631e28834be31771ef09e6fca4 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 22 Apr 2022 01:42:24 +0300 Subject: [PATCH 081/250] [SQL] fix syntax tests --- SQL/SQL (basic).sublime-syntax | 2 +- SQL/TSQL.sublime-syntax | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index ed8f27b5a0..7ef58edc37 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -487,7 +487,7 @@ contexts: set: dml-delete - match: \b(?i:update)\b scope: keyword.other.dml.sql - set: dml-update + push: dml-update - match: \b(?i:(?:insert\s+into|truncate))\b scope: keyword.other.dml.sql push: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 067d93ddea..c48e897757 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -334,6 +334,8 @@ contexts: - maybe-table-alias - table-name - single-identifier-after-whitespace + - match: \b(?i:set)\b + scope: keyword.other.dml.tsql ddl-statements: - meta_prepend: true @@ -691,7 +693,6 @@ contexts: - match: \b(?i:insert)\b(?=\s*\() scope: keyword.other.dml.sql push: values-or-expressions - - include: dml-statements - include: pop-on-top-level-reserved-word values-or-expressions: From acfbeeb666084167a3d5d402532b65baf6b07c4d Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 18 May 2022 00:13:33 +0300 Subject: [PATCH 082/250] [SQL] rename entity.name.function to entity.name.struct for table definitions --- SQL/Cassandra.sublime-syntax | 14 ++++++++++++- SQL/Indexed Symbol List.tmPreferences | 13 ++++++++++++ SQL/SQL (basic).sublime-syntax | 16 +++++++++++++-- SQL/TSQL.sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_cassandra.cql | 8 ++++---- SQL/tests/syntax/syntax_test_mysql.sql | 24 +++++++++++----------- SQL/tests/syntax/syntax_test_postgres.psql | 12 +++++------ SQL/tests/syntax/syntax_test_tsql.sql | 6 +++--- 8 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 SQL/Indexed Symbol List.tmPreferences diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 8a95545cee..f4ce7dea02 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -114,11 +114,23 @@ contexts: push: - ddl-create-target - ddl-table-creation-columns - - create-condition + - create-type-condition ddl-alter-common: - meta_prepend: false + create-type-condition: + - include: dml-condition + - match: (?=\S) + set: + - type-identifier-create + - single-identifier + + type-identifier-create: + - meta_include_prototype: false + - meta_scope: meta.toc-list.full-identifier.sql entity.name.type.cql + - include: immediately-pop + inside-ddl-table-creation-columns: - meta_scope: meta.group.table-columns.sql - match: \) diff --git a/SQL/Indexed Symbol List.tmPreferences b/SQL/Indexed Symbol List.tmPreferences new file mode 100644 index 0000000000..a3e5d97a3f --- /dev/null +++ b/SQL/Indexed Symbol List.tmPreferences @@ -0,0 +1,13 @@ + + + + + scope + source.sql entity.name.struct + settings + + showInIndexedSymbolList + 1 + + + diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 7ef58edc37..8ac3af1533 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -103,7 +103,12 @@ contexts: identifier-create: - meta_include_prototype: false - - meta_scope: meta.toc-list.full-identifier.sql entity.name.function.sql + - meta_scope: meta.toc-list.full-identifier.sql entity.name.other.sql + - include: immediately-pop + + table-identifier-create: + - meta_include_prototype: false + - meta_scope: meta.toc-list.full-identifier.sql entity.name.struct.sql - include: immediately-pop single-identifier-after-whitespace: @@ -167,6 +172,13 @@ contexts: - identifier-create - single-identifier + create-table-condition: + - include: dml-condition + - match: (?=\S) + set: + - table-identifier-create + - single-identifier + drop-condition: - include: dml-condition - match: (?=\S) @@ -351,7 +363,7 @@ contexts: push: - ddl-create-target - ddl-table-creation-columns - - create-condition + - create-table-condition - match: \b(?i:create)\b scope: keyword.other.ddl.sql push: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index c48e897757..479168b3c9 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -344,7 +344,7 @@ contexts: push: - ddl-create-target-expect-as - ddl-create-target - - create-condition + - create-table-condition - ddl-target ddl-create-target-expect-as: diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 10d57f1036..9b4ea1a1fa 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -4,7 +4,7 @@ CREATE KEYSPACE killrvideo WITH replication = {'class':'SimpleStrategy', 'replic --^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create --^^^^ keyword.other.ddl -- ^^^^^^^^ keyword.other --- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.other -- ^^^^ keyword.other -- ^ keyword.operator -- ^ punctuation.section.braces.begin @@ -90,7 +90,7 @@ CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( -- ^^ keyword.control.flow -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical --- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.struct -- ^ meta.group.table-columns punctuation.section.group.begin userid uuid, -- ^^^^^^^^^^^^^ meta.create meta.group.table-columns @@ -197,7 +197,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS -- ^^ keyword.control.flow -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical --- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.other -- ^^ keyword.context.block SELECT * -- ^^^^^^ keyword.other.dml @@ -223,7 +223,7 @@ CREATE TYPE user_defined_type ( --^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create --^^^^ keyword.other.ddl -- ^^^^ keyword.other --- ^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.type -- ^ meta.group punctuation.section.group.begin type1 timestamp, -- ^^^^^ meta.column-name variable.other.member.declaration diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 100b441222..70698642eb 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -26,36 +26,36 @@ SELECT "My /* Crazy Column Name" FROM my_table; -- <- meta.create keyword.other.ddl --^^^^^ keyword.other.ddl -- ^^^^^ keyword.other --- ^^^ entity.name.function --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - entity.name.function +-- ^^^ entity.name.struct +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - entity.name create table some_schema.test2( id serial ); --^^^^ meta.create keyword.other.ddl -- ^^^^^ meta.create keyword.other --- ^^^^^^^^^^^^^^^^^ entity.name.function +-- ^^^^^^^^^^^^^^^^^ entity.name.struct -- ^ punctuation.accessor.dot --- ^^^^^^^^^^^^^^ - entity.name.function +-- ^^^^^^^^^^^^^^ - entity.name create table some_schema . test2 ( id serial ); --^^^^ meta.create keyword.other.ddl -- ^^^^^ meta.create keyword.other -- ^^^^^^^^^^^^^^^^^^^ entity.name -- ^ punctuation.accessor.dot --- ^^^^^^^^^^^^^^^ - entity.name.function +-- ^^^^^^^^^^^^^^^ - entity.name create table "testing123" (id integer); --^^^^ meta.create keyword.other.ddl -- ^^^^^ meta.create keyword.other -- ^ punctuation.definition.identifier.begin --- ^^^^^^^^^^ entity.name.function +-- ^^^^^^^^^^ entity.name.struct -- ^ punctuation.definition.identifier.end create table `dbo`."testing123" (id integer); --^^^^ meta.create keyword.other.ddl -- ^^^^^ meta.create keyword.other --- ^^^^^^^^^^^^^^^^^^ entity.name.function +-- ^^^^^^^^^^^^^^^^^^ entity.name.struct -- ^ punctuation.accessor.dot --- ^^^^^^^^^^^^^^^ - entity.name.function +-- ^^^^^^^^^^^^^^^ - entity.name create table IF NOT EXISTS `testing123` ( -- ^^^^^^^^^^^^^^^^^^^^^^^^ - meta.toc-list @@ -162,7 +162,7 @@ create fulltext index if not exists `myindex` ON mytable; -- ^^ keyword.control.flow -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical --- ^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^ meta.toc-list.full-identifier entity.name.other -- ^^ keyword.other -- ^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement @@ -248,7 +248,7 @@ CREATE INDEX IX_some_index ON dbo.some_table( -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other --- ^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^ meta.toc-list.full-identifier -- ^^ keyword.other -- ^^^^^^^^^^^^^^ meta.table-name -- ^ meta.group punctuation.section.group.begin @@ -264,7 +264,7 @@ CREATE ALGORITHM=MERGE VIEW contactPersons( -- ^ keyword.operator.assignment -- ^^^^^ keyword.other -- ^^^^ keyword.other --- ^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.other -- ^ meta.group punctuation.section.group.begin customerName, -- ^^^^^^^^^^^^ meta.group meta.column-name @@ -288,7 +288,7 @@ FROM customers; CREATE TEMPORARY TABLE IF NOT EXISTS foo ( -- ^^^^^^^^^^^^^^^^^^^ meta.create keyword.other.ddl --- ^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^ meta.toc-list.full-identifier entity.name.struct bar NVARCHAR(400), baz INT ); diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index 9c05aedb2d..2ac08fa352 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -3,7 +3,7 @@ CREATE TABLE test1 (a character(4)); -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create -- ^^^^^^^^^ keyword.other.ddl --- ^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^ meta.toc-list.full-identifier entity.name.struct -- ^^^^^^^^^^^^^^^^ meta.group.table-columns -- ^ punctuation.terminator.statement -- ^ punctuation.section.group.begin @@ -29,7 +29,7 @@ SELECT a, char_length(a) FROM test1; CREATE TABLE test2 (b varchar(5)); -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create -- ^^^^^^^^^ keyword.other.ddl --- ^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^ meta.toc-list.full-identifier entity.name.struct -- ^^^^^^^^^^^^^^ meta.group.table-columns -- ^ punctuation.terminator.statement -- ^ punctuation.section.group.begin @@ -53,7 +53,7 @@ CREATE TABLE IF NOT EXISTS public.dropzone_details -- ^^ keyword.control.flow -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.struct -- ^ punctuation.accessor.dot ( -- <- meta.create meta.group.table-columns punctuation.section.group.begin @@ -103,7 +103,7 @@ SELECT 'abc \153\154\155 \052\251\124'::bytea; CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); -- ^^^ meta.create keyword.other.ddl -- ^^^^ meta.create keyword.other --- ^^^^ meta.create meta.toc-list.full-identifier entity.name.function +-- ^^^^ meta.create meta.toc-list.full-identifier entity.name -- ^^ keyword.context.block CREATE TABLE person ( name text, @@ -205,7 +205,7 @@ SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; CREATE EXTENSION hstore SCHEMA addons; -- ^^^ meta.create keyword.other.ddl -- ^^^^^^^^^ meta.create keyword.other --- ^^^^^^ meta.create meta.toc-list.full-identifier entity.name.function +-- ^^^^^^ meta.create meta.toc-list.full-identifier entity.name.other -- ^^^^^^ storage.modifier -- ^^^^^^ meta.schema-name -- ^ punctuation.terminator.statement @@ -274,7 +274,7 @@ ALTER TABLE test2 ADD something varchar[]; CREATE TRIGGER blah AFTER INSERT OR UPDATE -- ^^^ keyword.other.ddl -- ^^^^^^^ keyword.other --- ^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^ meta.toc-list.full-identifier entity.name.other -- ^^^^^^^^^^^^^^^^^^^^^^ keyword.other ON some_table FOR EACH ROW EXECUTE PROCEDURE some_procedure(); -- ^^ keyword.other diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 32d00bcac9..3a315e6eda 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -620,7 +620,7 @@ GO CREATE OR ALTER PROC CreateOrAlterDemo -- ^^^^^^^^^^^^ meta.create keyword.other.ddl -- ^^^^ meta.create keyword.other --- ^^^^^^^^^^^^^^^^^ meta.create meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^^^^^ meta.create meta.toc-list.full-identifier entity.name.struct @Count SMALLINT ,@Other INT OUTPUT -- <- punctuation.separator.sequence @@ -830,7 +830,7 @@ SELECT cte_table.* FROM cte_table CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)) -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other --- ^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^ meta.toc-list.full-identifier entity.name.struct -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns -- ^ punctuation.section.group.begin -- ^^ meta.column-name @@ -1622,7 +1622,7 @@ CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( -- ^^^^^^ keyword.other -- ^^^^^^^^^^^^ keyword.other -- ^^^^^ keyword.other --- ^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.function +-- ^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.struct -- ^^ keyword.other -- ^^^^^^^^^^^^^^ meta.table-name -- ^ meta.group punctuation.section.group.begin From 511206aa11972b5adf41bbc4945ed7a69f5429c8 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 21 May 2022 15:37:07 +0200 Subject: [PATCH 083/250] [PHP] Fix interpolation --- .../SQL (for PHP Interpolated).sublime-syntax | 6 +++++- PHP/Embeddings/SQL (for PHP).sublime-syntax | 2 +- PHP/PHP Source.sublime-syntax | 18 ++++++++++++++++++ PHP/tests/syntax_test_php.php | 4 ++++ SQL/SQL (basic).sublime-syntax | 1 + 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax b/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax index e5a41d3848..a38a89d321 100644 --- a/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax +++ b/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax @@ -15,5 +15,9 @@ contexts: - meta_prepend: true # prevent stray bracket highlighting - match: \) - scope: punctuation.section.arguments.end.sql + scope: punctuation.section.group.end.sql + single-identifier: + - meta_prepend: true + - meta_include_prototype: false + - include: Packages/PHP/PHP Source.sublime-syntax#interpolation diff --git a/PHP/Embeddings/SQL (for PHP).sublime-syntax b/PHP/Embeddings/SQL (for PHP).sublime-syntax index d3df586ab7..4cfcf3467c 100644 --- a/PHP/Embeddings/SQL (for PHP).sublime-syntax +++ b/PHP/Embeddings/SQL (for PHP).sublime-syntax @@ -16,7 +16,7 @@ contexts: - meta_prepend: true # prevent stray bracket highlighting - match: \) - scope: punctuation.section.arguments.end.sql + scope: punctuation.section.group.end.sql php-string-single-quoted-escapes: - match: \\[\\'] diff --git a/PHP/PHP Source.sublime-syntax b/PHP/PHP Source.sublime-syntax index c76f591520..d28e66c146 100644 --- a/PHP/PHP Source.sublime-syntax +++ b/PHP/PHP Source.sublime-syntax @@ -1742,6 +1742,24 @@ contexts: - match: (?=\${{identifier_start}}) push: interpolation-literal-variable + interpolation: + # PHP variable/expressions interpolated into foreign + # source code without clearing any string scopes. + # + # Prevents: "c:\{$foo}" + - match: \\\{ + # Handles: "foo{$bar}baz" + - match: \{(?=\$) + scope: punctuation.section.interpolation.begin.php + set: interpolation-braced-expression + # Handles: "foo${bar}baz" + - match: \$\{ + scope: punctuation.definition.variable.begin.php + set: interpolation-braced-variable + # Handles: $foo, $foo[0], $foo[$bar], $foo->bar + - match: (?=\${{identifier_start}}) + set: interpolation-literal-variable + interpolation-braced-expression: - meta_include_prototype: false - meta_scope: meta.interpolation.php diff --git a/PHP/tests/syntax_test_php.php b/PHP/tests/syntax_test_php.php index 76b1742b3e..f2f425310f 100644 --- a/PHP/tests/syntax_test_php.php +++ b/PHP/tests/syntax_test_php.php @@ -4494,6 +4494,7 @@ function testTypeCasts() SELECT * FROM users WHERE first_name = 'Eric' //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php - string.quoted.double.php // ^ keyword.other.dml +// ^^^^^ keyword.other.dml.sql // ^^^^^^ string.quoted.single.sql "; // <- meta.string.php string.quoted.double.php punctuation.definition.string.end.php - meta.interpolation - string string @@ -4520,11 +4521,14 @@ function testTypeCasts() // ^ keyword.operator.concatenation.php // ^ string.quoted.double.php punctuation.definition.string.begin.php // ^^^^^^ variable.other.php +// ^^^^^ keyword.other.dml.sql +// ^ punctuation.section.group.begin.sql // ^ string.quoted.double.php punctuation.definition.string.end.php // ^ keyword.operator.concatenation.php // ^^^^^ variable.other.php // ^ keyword.operator.concatenation.php // ^ string.quoted.double.php punctuation.definition.string.begin.php +// ^ punctuation.section.group.end.sql - string // ^ string.quoted.double.php punctuation.definition.string.end.php // ^ punctuation.terminator.statement.php // ^ keyword.operator.concatenation.php diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 8ac3af1533..0eeb31d458 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -139,6 +139,7 @@ contexts: - include: single-quoted-identifier-part - include: double-quoted-identifier-part - include: backtick-quoted-identifier-part + - include: else-pop simple-identifier-part: - match: '{{simple_identifier}}' From f586ddcd080d324a2391a1bb2fb73e0a9710f047 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 7 Jun 2022 20:03:43 +0200 Subject: [PATCH 084/250] Remove unnecessary directives Those don't have any effect. --- SQL/SQL (basic).sublime-syntax | 4 ---- 1 file changed, 4 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 0eeb31d458..0c799084ad 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -39,18 +39,15 @@ contexts: - include: expressions-or-column-name comments: - - meta_include_prototype: false - include: double-dash-comments - include: block-comments double-dash-comments: - - meta_include_prototype: false - match: '--' scope: punctuation.definition.comment.sql push: inside-double-dash-comment block-comments: - - meta_include_prototype: false - match: /\*(?:\*(?!/))+ scope: punctuation.definition.comment.begin.sql push: inside-comment-docblock @@ -82,7 +79,6 @@ contexts: pop: 1 string-escape: - - meta_include_prototype: false - match: '{{string_escape}}' scope: constant.character.escape.sql From 7d7fe0330c20d67a03a432b39f8897dbf2af6895 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 7 Jun 2022 20:06:15 +0200 Subject: [PATCH 085/250] Reorg string-escapes 1. renames context to plural as it doesn't pop 2. move after strings context --- SQL/SQL (basic).sublime-syntax | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 0c799084ad..8ef3e47a8e 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -78,10 +78,6 @@ contexts: scope: punctuation.definition.comment.end.sql pop: 1 - string-escape: - - match: '{{string_escape}}' - scope: constant.character.escape.sql - strings: - match: \' scope: punctuation.definition.string.begin.sql @@ -95,7 +91,11 @@ contexts: - match: \' scope: punctuation.definition.string.end.sql pop: 1 - - include: string-escape + - include: string-escapes + + string-escapes: + - match: '{{string_escape}}' + scope: constant.character.escape.sql identifier-create: - meta_include_prototype: false From 29320a9806b967216bf43754b6f5226ad6f14dab Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 7 Jun 2022 20:13:55 +0200 Subject: [PATCH 086/250] Add meta.string Required for variable interpolation by inheriting syntaxes. --- SQL/SQL (basic).sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 8ef3e47a8e..3611d6acf9 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -85,7 +85,7 @@ contexts: single-quoted-string: - meta_include_prototype: false - - meta_scope: string.quoted.single.sql + - meta_scope: meta.string.sql string.quoted.single.sql - match: \'\' scope: constant.character.escape.sql - match: \' From ef8716b69eb2a4e5ae5196035146220793d04bca Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 7 Jun 2022 20:16:59 +0200 Subject: [PATCH 087/250] Reorganize number/consant/string literals 1. Rename `numbers-variables-and-strings` to `literals-and-variables`. 2. Create a context for each literal type. 3. Organize all literal contexts next to each other. --- SQL/SQL (basic).sublime-syntax | 59 ++++++++++++++++++---------------- SQL/TSQL.sublime-syntax | 4 +-- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 3611d6acf9..df610e1c21 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -78,25 +78,6 @@ contexts: scope: punctuation.definition.comment.end.sql pop: 1 - strings: - - match: \' - scope: punctuation.definition.string.begin.sql - push: single-quoted-string - - single-quoted-string: - - meta_include_prototype: false - - meta_scope: meta.string.sql string.quoted.single.sql - - match: \'\' - scope: constant.character.escape.sql - - match: \' - scope: punctuation.definition.string.end.sql - pop: 1 - - include: string-escapes - - string-escapes: - - match: '{{string_escape}}' - scope: constant.character.escape.sql - identifier-create: - meta_include_prototype: false - meta_scope: meta.toc-list.full-identifier.sql entity.name.other.sql @@ -236,12 +217,6 @@ contexts: - column-name - single-identifier - numbers: - - match: \b\d+\.\d+\b - scope: meta.number.float.decimal.sql constant.numeric.value.sql - - match: \b\d+\b - scope: meta.number.integer.decimal.sql constant.numeric.value.sql - expressions: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql @@ -251,7 +226,7 @@ contexts: - match: \b(?i:case)\b scope: keyword.control.conditional.case.sql push: inside-case-expression - - include: numbers-variables-and-strings + - include: literals-and-variables - include: operators - include: collate - include: built-in-aggregate-function-calls @@ -266,13 +241,41 @@ contexts: - match: (?=;) pop: 1 - numbers-variables-and-strings: + literals-and-variables: + - include: constants - include: numbers + - include: strings + + constants: - match: \b(?i:true|false)\b scope: constant.language.boolean.sql - match: \b(?i:null)\b scope: constant.language.null.sql - - include: strings + + numbers: + - match: \b\d+\.\d+\b + scope: meta.number.float.decimal.sql constant.numeric.value.sql + - match: \b\d+\b + scope: meta.number.integer.decimal.sql constant.numeric.value.sql + + strings: + - match: \' + scope: punctuation.definition.string.begin.sql + push: single-quoted-string + + single-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.quoted.single.sql + - match: \'\' + scope: constant.character.escape.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-escapes + + string-escapes: + - match: '{{string_escape}}' + scope: constant.character.escape.sql begin-group: - match: \( diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 479168b3c9..ebffcf00e4 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -286,7 +286,7 @@ contexts: - match: \b(?i:include)\b scope: keyword.other.sql - numbers-variables-and-strings: + literals-and-variables: - meta_prepend: true - include: variables - match: 0x\h+ @@ -815,7 +815,7 @@ contexts: - match: \) scope: meta.group.tsql punctuation.section.group.end.tsql pop: 1 - - include: numbers-variables-and-strings + - include: literals-and-variables - include: ddl-table-creation-columns - match: (?=\S) push: From b4e0456964169d10445a8d5c556f8e5a8d33a49a Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 7 Jun 2022 20:23:49 +0200 Subject: [PATCH 088/250] Add scope for decimal point --- SQL/SQL (basic).sublime-syntax | 4 +++- SQL/tests/syntax/syntax_test_tsql.sql | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index df610e1c21..397e9e0a4b 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -253,8 +253,10 @@ contexts: scope: constant.language.null.sql numbers: - - match: \b\d+\.\d+\b + - match: \b\d+(\.)\d+\b scope: meta.number.float.decimal.sql constant.numeric.value.sql + captures: + 1: punctuation.separator.decimal.sql - match: \b\d+\b scope: meta.number.integer.decimal.sql constant.numeric.value.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 3a315e6eda..8458bd1dbc 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -863,6 +863,7 @@ AS -- ^^^^ meta.table-name -- ^^^ keyword.other.dml -- ^^^^ meta.number.float.decimal constant.numeric.value +-- ^ punctuation.separator.decimal IF OBJECT_ID('tempdb..import') IS NOT NULL DROP TABLE tempdb..import From 301bddf7b4553d6235b9074d1c277132fcde7672 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 7 Jun 2022 20:31:36 +0200 Subject: [PATCH 089/250] TSQL: Scope hexadecimal base ... and move pattern to `numbers` context. --- SQL/TSQL.sublime-syntax | 10 ++++++++-- SQL/tests/syntax/syntax_test_tsql.sql | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index ebffcf00e4..f7655ffe2a 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -289,8 +289,14 @@ contexts: literals-and-variables: - meta_prepend: true - include: variables - - match: 0x\h+ - scope: meta.number.integer.hexadecimal.tsql constant.numeric.value.tsql + + numbers: + - meta_prepend: true + - match: (0x)(\h+) + scope: meta.number.integer.hexadecimal.tsql + captures: + 1: constant.numeric.base.tsql + 2: constant.numeric.value.tsql dml-statements: - meta_append: true diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 8458bd1dbc..dadfff8ed9 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -461,7 +461,9 @@ SET column1 = v.column1, column2 = 'testing123 TODO: assert the = operator is scoped as assignment instead of comparison' -- ^ keyword.operator , col3 = 0xDEADC0DE --- ^^^^^^^^^^ meta.number.integer.hexadecimal constant.numeric.value +-- ^^^^^^^^^^ meta.number.integer.hexadecimal +-- ^^ constant.numeric.base +-- ^^^^^^^^ constant.numeric.value FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^ keyword.other.dml -- ^^^^^^^^^^^^^ meta.table-name From e8eee030844bad77334cc83109b27a06fccb1b49 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 7 Jun 2022 20:29:07 +0200 Subject: [PATCH 090/250] Reorganize inside-... contexts inside-... contexts should directly follow their begin- counter parts, especially if there's only one or two. --- SQL/SQL (basic).sublime-syntax | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 397e9e0a4b..9988b760a8 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -290,6 +290,13 @@ contexts: set: inside-group - include: else-pop + inside-group: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: main + inside-case-expression: - meta_scope: meta.statement.conditional.case.sql - match: \b(?i:end)\b @@ -341,20 +348,6 @@ contexts: - include: distinct - include: expressions-or-column-name - inside-group: - - meta_scope: meta.group.sql - - match: \) - scope: punctuation.section.group.end.sql - pop: 1 - - include: main - - inside-subquery-allow-table-alias: - - meta_scope: meta.group.sql - - match: \) - scope: punctuation.section.group.end.sql - set: maybe-table-alias - - include: main - statements: - include: ddl-statements - include: dml-statements @@ -624,6 +617,13 @@ contexts: scope: punctuation.section.group.begin.sql set: inside-subquery-allow-table-alias + inside-subquery-allow-table-alias: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + set: maybe-table-alias + - include: main + table-name-or-subquery: - include: pop-on-top-level-reserved-word - include: subquery From 4ca8ec561da91ec01431fc90485d4b373672a632 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 10 Jun 2022 17:59:08 +0200 Subject: [PATCH 091/250] Rename inside-single-quoted-string context --- SQL/SQL (basic).sublime-syntax | 4 ++-- SQL/TSQL.sublime-syntax | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 9988b760a8..8f8135a066 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -263,9 +263,9 @@ contexts: strings: - match: \' scope: punctuation.definition.string.begin.sql - push: single-quoted-string + push: inside-single-quoted-string - single-quoted-string: + inside-single-quoted-string: - meta_include_prototype: false - meta_scope: meta.string.sql string.quoted.single.sql - match: \'\' diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index f7655ffe2a..56e9f3a842 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -49,7 +49,7 @@ contexts: - meta_append: true - match: N' scope: punctuation.definition.string.begin.sql - push: single-quoted-string + push: inside-single-quoted-string operators: - meta_append: true From 9f10f81d0e7daf6c19b4775815116e9ea8ae638b Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 10 Jun 2022 18:03:13 +0200 Subject: [PATCH 092/250] Reorganize groups contexts --- SQL/Cassandra.sublime-syntax | 2 +- SQL/SQL (basic).sublime-syntax | 41 ++++++++++++++++++---------------- SQL/TSQL.sublime-syntax | 8 +++---- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index f4ce7dea02..3fd8d37844 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -59,7 +59,7 @@ contexts: scope: keyword.other.dml.cql push: - copy-from - - begin-group-or-pop + - maybe-group - table-name - single-identifier-after-whitespace diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 8f8135a066..53c0ddc538 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -233,7 +233,7 @@ contexts: - include: built-in-scalar-function-calls #- include: types - include: user-defined-function-calls - - include: begin-group + - include: groups - match: \) scope: invalid.illegal.trailing-paren.sql - match: ',' @@ -241,6 +241,27 @@ contexts: - match: (?=;) pop: 1 + maybe-group: + - include: group + - include: else-pop + + group: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-group + + groups: + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-group + + inside-group: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: main + literals-and-variables: - include: constants - include: numbers @@ -279,24 +300,6 @@ contexts: - match: '{{string_escape}}' scope: constant.character.escape.sql - begin-group: - - match: \( - scope: punctuation.section.group.begin.sql - push: inside-group - - begin-group-or-pop: - - match: \( - scope: punctuation.section.group.begin.sql - set: inside-group - - include: else-pop - - inside-group: - - meta_scope: meta.group.sql - - match: \) - scope: punctuation.section.group.end.sql - pop: 1 - - include: main - inside-case-expression: - meta_scope: meta.statement.conditional.case.sql - match: \b(?i:end)\b diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 56e9f3a842..6c85ffbb6e 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -255,7 +255,7 @@ contexts: scope: keyword.other.tsql - match: \b(?i:pivot|unpivot)\b scope: keyword.other.tsql - push: [maybe-table-alias, begin-group-or-pop] + push: [maybe-table-alias, maybe-group] - match: \b(?i:for)\b scope: keyword.other.tsql - match: \b(\w+)(:) @@ -469,11 +469,9 @@ contexts: after-table-alias: - meta_prepend: true - - include: with + - include: groups # column-alias-list - include: table-hint-without-with - - match: \( - scope: punctuation.section.group.begin.tsql - push: inside-group # column-alias-list + - include: with table-hint-without-with: - match: |- From 27a6a5f9352bdd45e47c0600179af558c9e10f40 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 10 Jun 2022 18:14:28 +0200 Subject: [PATCH 093/250] Reorganize function-call contexts --- SQL/Cassandra.sublime-syntax | 12 +++--- SQL/SQL (basic).sublime-syntax | 79 ++++++++++++++++++---------------- SQL/TSQL.sublime-syntax | 52 +++++++++++----------- 3 files changed, 73 insertions(+), 70 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 3fd8d37844..987c486b79 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -47,6 +47,12 @@ contexts: - match: \b(?i:using\s+ttl)\b scope: keyword.other.cql + built-in-scalar-function-calls: + - meta_append: true + - match: \b(?:token|uuid|now|toJson|TTL|WRITETIME|KEYS|ENTRIES|FULL)(?=\s*\() + scope: support.function.scalar.cql + push: function-call-arguments + dml-statements: - meta_prepend: true - match: \b(?i:(select)\s+(json))\b @@ -177,12 +183,6 @@ contexts: pop: 1 - include: else-pop - built-in-scalar-function-calls: - - meta_append: true - - match: \b(?:token|uuid|now|toJson|TTL|WRITETIME|KEYS|ENTRIES|FULL)(?=\s*\() - scope: support.function.scalar.cql - push: begin-method-call-paren - logical-operators: - meta_append: true - match: \b(?i:contains(?:\s+key)?)\b diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 53c0ddc538..b776d263a1 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -229,10 +229,8 @@ contexts: - include: literals-and-variables - include: operators - include: collate - - include: built-in-aggregate-function-calls - - include: built-in-scalar-function-calls + - include: function-calls #- include: types - - include: user-defined-function-calls - include: groups - match: \) scope: invalid.illegal.trailing-paren.sql @@ -241,6 +239,45 @@ contexts: - match: (?=;) pop: 1 + function-calls: + - include: built-in-aggregate-function-calls + - include: built-in-scalar-function-calls + - include: user-defined-function-calls + + built-in-aggregate-function-calls: + # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + - match: \b(?i:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() + scope: support.function.aggregate.sql + push: function-call-arguments + + built-in-scalar-function-calls: + # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + - match: \b(?i:CURRENT_(?:DATE|TIME(?:STAMP)?|USER)|(?:SESSION|SYSTEM)_USER)\b + scope: support.function.scalar.sql + + user-defined-function-calls: + - match: \b\w+(?=\s*\() + scope: support.function.sql + push: function-call-arguments + + function-call-arguments: + - meta_include_prototype: false + - meta_scope: meta.function-call.sql + - match: \( + scope: meta.group.sql punctuation.section.arguments.begin.sql + set: inside-function-call-arguments + - include: else-pop + + inside-function-call-arguments: + - meta_content_scope: meta.function-call.sql meta.group.sql + - match: \) + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql + pop: 1 + - match: ',' + scope: punctuation.separator.argument.sql + - include: distinct + - include: expressions-or-column-name + maybe-group: - include: group - include: else-pop @@ -317,40 +354,6 @@ contexts: scope: keyword.control.conditional.else.sql - include: expressions-or-column-name - built-in-aggregate-function-calls: - # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - - match: \b(?i:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() - scope: support.function.aggregate.sql - push: begin-method-call-paren - - built-in-scalar-function-calls: - # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - - match: \b(?i:CURRENT_(?:DATE|TIME(?:STAMP)?|USER)|(?:SESSION|SYSTEM)_USER)\b - scope: support.function.scalar.sql - - user-defined-function-calls: - - match: \b\w+(?=\s*\() - scope: support.function.sql - push: begin-method-call-paren - - begin-method-call-paren: - - meta_include_prototype: false - - meta_scope: meta.function-call.sql - - match: \( - scope: meta.group.sql punctuation.section.arguments.begin.sql - set: inside-method-call - - include: else-pop - - inside-method-call: - - meta_content_scope: meta.function-call.sql meta.group.sql - - match: \) - scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql - pop: 1 - - match: ',' - scope: punctuation.separator.argument.sql - - include: distinct - - include: expressions-or-column-name - statements: - include: ddl-statements - include: dml-statements @@ -693,7 +696,7 @@ contexts: - match: '' set: - maybe-table-alias - - begin-method-call-paren + - function-call-arguments - table-valued-function-name - single-identifier diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 6c85ffbb6e..a4b313f44a 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -286,6 +286,29 @@ contexts: - match: \b(?i:include)\b scope: keyword.other.sql + built-in-scalar-function-calls: + - meta_append: true + - match: \b((?i:CONVERT))\s*(\() + scope: meta.function-call.sql + captures: + 1: support.function.scalar.sql + 2: meta.group.sql punctuation.section.arguments.begin.sql + push: + - inside-convert-arguments + - expect-type + - match: \b(?i:GETDATE)(?=\s*\() + scope: support.function.scalar.sql + push: function-call-arguments + + inside-convert-arguments: + - meta_content_scope: meta.function-call.sql meta.group.sql + - match: \) + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql + pop: 1 + - match: ',' + scope: punctuation.separator.argument.sql + - include: expressions-or-column-name + literals-and-variables: - meta_prepend: true - include: variables @@ -388,29 +411,6 @@ contexts: - meta_prepend: true - include: top - built-in-scalar-function-calls: - - meta_append: true - - match: (?i)\b(CONVERT)\s*(\() - scope: meta.function-call.sql - captures: - 1: support.function.scalar.sql - 2: meta.group.sql punctuation.section.arguments.begin.sql - push: - - method-call-convert - - expect-type - - match: (?i)\b(?:GETDATE)(?=\s*\() - scope: support.function.scalar.sql - push: begin-method-call-paren - - method-call-convert: - - meta_content_scope: meta.function-call.sql meta.group.sql - - match: \) - scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql - pop: 1 - - match: ',' - scope: punctuation.separator.argument.sql - - include: expressions-or-column-name - label-name: - meta_include_prototype: false - meta_content_scope: meta.label-name.sql @@ -626,7 +626,7 @@ contexts: scope: meta.table-valued-function-name.sql support.function.tsql push: - with-column-definition - - begin-method-call-paren + - function-call-arguments - match: \b(?i:(OPENROWSET))\b\s*(\() scope: meta.function-call.tsql captures: @@ -687,7 +687,7 @@ contexts: - match: \) scope: meta.function-call.tsql meta.group.tsql punctuation.section.arguments.end.sql set: maybe-table-alias - - include: inside-method-call + - include: inside-function-call-arguments merge-condition: - match: \b(?i:\s+by\s+(?:source|target))\b @@ -793,7 +793,7 @@ contexts: - meta_append: true - match: (?={{identifier_for_lookahead}}\s*\() push: - - begin-method-call-paren + - function-call-arguments - function-name - single-identifier From db1faa03eef674634766c63befd774a0b5398a97 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 10 Jun 2022 18:17:31 +0200 Subject: [PATCH 094/250] Reorganize case expression contexts --- SQL/SQL (basic).sublime-syntax | 43 ++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index b776d263a1..23164bfc88 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -223,9 +223,7 @@ contexts: push: - column-alias - single-identifier-after-whitespace - - match: \b(?i:case)\b - scope: keyword.control.conditional.case.sql - push: inside-case-expression + - include: case-expressions - include: literals-and-variables - include: operators - include: collate @@ -239,6 +237,28 @@ contexts: - match: (?=;) pop: 1 + case-expressions: + - match: \b(?i:case)\b + scope: keyword.control.conditional.case.sql + push: inside-case-expression + + inside-case-expression: + - meta_scope: meta.statement.conditional.case.sql + - match: \b(?i:end)\b + scope: keyword.control.conditional.end.sql + pop: 1 + - match: \b(?i:(case)\s+(when))\b + captures: + 1: keyword.control.conditional.case.sql + 2: keyword.control.conditional.when.sql + - match: \b(?i:when)\b + scope: keyword.control.conditional.when.sql + - match: \b(?i:then)\b + scope: keyword.control.conditional.then.sql + - match: \b(?i:else)\b + scope: keyword.control.conditional.else.sql + - include: expressions-or-column-name + function-calls: - include: built-in-aggregate-function-calls - include: built-in-scalar-function-calls @@ -337,23 +357,6 @@ contexts: - match: '{{string_escape}}' scope: constant.character.escape.sql - inside-case-expression: - - meta_scope: meta.statement.conditional.case.sql - - match: \b(?i:end)\b - scope: keyword.control.conditional.end.sql - pop: 1 - - match: \b(?i:(case)\s+(when))\b - captures: - 1: keyword.control.conditional.case.sql - 2: keyword.control.conditional.when.sql - - match: \b(?i:when)\b - scope: keyword.control.conditional.when.sql - - match: \b(?i:then)\b - scope: keyword.control.conditional.then.sql - - match: \b(?i:else)\b - scope: keyword.control.conditional.else.sql - - include: expressions-or-column-name - statements: - include: ddl-statements - include: dml-statements From e2de5801e070dc24f1e678e5650203eff3affd1d Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 10 Jun 2022 18:18:36 +0200 Subject: [PATCH 095/250] Reorganize alias expression contexts --- SQL/SQL (basic).sublime-syntax | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 23164bfc88..b581b09f90 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -218,11 +218,7 @@ contexts: - single-identifier expressions: - - match: \b(?i:as)\b - scope: keyword.operator.assignment.alias.sql - push: - - column-alias - - single-identifier-after-whitespace + - include: alias-expressions - include: case-expressions - include: literals-and-variables - include: operators @@ -237,6 +233,13 @@ contexts: - match: (?=;) pop: 1 + alias-expressions: + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + push: + - column-alias + - single-identifier-after-whitespace + case-expressions: - match: \b(?i:case)\b scope: keyword.control.conditional.case.sql From 3f8253114b95f9575a6196936e32ecc7291e64c5 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 10 Jun 2022 18:24:32 +0200 Subject: [PATCH 096/250] Reorganize collate expression contexts --- SQL/SQL (basic).sublime-syntax | 24 ++++++++++++------------ SQL/TSQL.sublime-syntax | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index b581b09f90..482f35504c 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -220,9 +220,9 @@ contexts: expressions: - include: alias-expressions - include: case-expressions + - include: collate-expressions - include: literals-and-variables - include: operators - - include: collate - include: function-calls #- include: types - include: groups @@ -262,6 +262,17 @@ contexts: scope: keyword.control.conditional.else.sql - include: expressions-or-column-name + collate-expressions: + - match: \b(?i:collate)\b + scope: keyword.other.sql + push: inside-collate-expression + + inside-collate-expression: + - match: \w+ + scope: support.constant.sql + pop: 1 + - include: else-pop + function-calls: - include: built-in-aggregate-function-calls - include: built-in-scalar-function-calls @@ -742,17 +753,6 @@ contexts: after-declare: - include: immediately-pop - collate: - - match: \b(?i:collate)\b - scope: keyword.other.sql - push: collation - - collation: - - match: \w+ - scope: support.constant.sql - pop: 1 - - include: else-pop - after-constraint: - match: \b(?i:check)\b scope: keyword.other.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index a4b313f44a..4058708f90 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -588,7 +588,7 @@ contexts: - match: \b(?i:ENCRYPTED\s+WITH)\b scope: storage.modifier.tsql set: with-paren-or-pop - - include: collate + - include: collate-expressions maybe-identifier-accessor: - meta_prepend: true From 998f7a1841129ae3158bed1d6fd5ab26e705994c Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 10 Jun 2022 19:03:40 +0200 Subject: [PATCH 097/250] Tweak case insenstive alterantion --- SQL/SQL (basic).sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 482f35504c..6361ad2c35 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -535,7 +535,7 @@ contexts: - match: \b(?i:from)\b scope: keyword.other.dml.sql push: table-name-or-subquery - - match: (?i)\b(asc|desc)\b + - match: \b(?i:asc|desc)\b scope: keyword.other.order.sql inside-ddl-table-creation-columns: From b941956b183a56e95121f1038b4e0f91a8e4ea63 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 10 Jun 2022 19:08:31 +0200 Subject: [PATCH 098/250] Reuse else-pop and immediately-pop --- SQL/PostgreSQL.sublime-syntax | 7 +++---- SQL/TSQL.sublime-syntax | 16 ++++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index e4bcbbc633..e09ace5ea8 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -90,8 +90,7 @@ contexts: escape_captures: 0: meta.string.regexp.psql punctuation.definition.string.end.sql pop: 1 - - match: (?=\S) - pop: 1 + - include: else-pop single-quoted-regex: - meta_scope: meta.string.regexp.psql @@ -109,9 +108,9 @@ contexts: - single-identifier declaration-variable-name: + - meta_include_prototype: false - meta_scope: variable.other.psql - - match: '' - pop: true + - include: immediately-pop ddl-statements: - meta_prepend: true diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 4058708f90..6be8203838 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -414,13 +414,12 @@ contexts: label-name: - meta_include_prototype: false - meta_content_scope: meta.label-name.sql - - match: '' - pop: 1 + - include: immediately-pop cursor-name: + - meta_include_prototype: false - meta_content_scope: meta.cursor-name.sql - - match: '' - pop: 1 + - include: immediately-pop after-declare: - match: (?=\w+\s+(?i:cursor)\b) @@ -800,8 +799,7 @@ contexts: function-name: - meta_include_prototype: false - meta_content_scope: variable.function.tsql - - match: '' - pop: 1 + - include: immediately-pop expressions-or-unknown: - meta_content_scope: meta.group.tsql @@ -829,11 +827,9 @@ contexts: index-name: - meta_include_prototype: false - meta_content_scope: meta.index-name.tsql - - match: '' - pop: 1 + - include: immediately-pop filegroup-name: - meta_include_prototype: false - meta_content_scope: meta.filegroup-name.tsql - - match: '' - pop: 1 + - include: immediately-pop From a3b4290a4ac706d31349d1d0b140e0351a07fc39 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 10 Jun 2022 20:00:55 +0200 Subject: [PATCH 099/250] Tweak declarations --- SQL/PostgreSQL.sublime-syntax | 4 ++-- SQL/SQL (basic).sublime-syntax | 4 ++-- SQL/TSQL.sublime-syntax | 11 +++++------ SQL/tests/syntax/syntax_test_postgres.psql | 8 ++++++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index e09ace5ea8..e3724f3e62 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -100,8 +100,8 @@ contexts: - meta_prepend: true - include: declarations - after-declare: - - match: '' + inside-declaration: + - match: (?=\S) set: - expect-type - declaration-variable-name diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 6361ad2c35..5493afc42f 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -748,9 +748,9 @@ contexts: declarations: - match: \b(?i:declare)\b scope: keyword.declaration.variable.sql - push: after-declare + push: inside-declaration - after-declare: + inside-declaration: - include: immediately-pop after-constraint: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 6be8203838..080d38d93d 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -421,12 +421,11 @@ contexts: - meta_content_scope: meta.cursor-name.sql - include: immediately-pop - after-declare: - - match: (?=\w+\s+(?i:cursor)\b) - set: - - cursor-name - - single-identifier - - match: '(@){{simple_identifier}}' + inside-declaration: + - match: \w+(?=\s+(?i:cursor)\b) + scope: meta.cursor-name.sql + pop: 1 + - match: (@){{simple_identifier}} scope: variable.other.readwrite.declaration.tsql captures: 1: punctuation.definition.variable.tsql diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index 2ac08fa352..ff436caf78 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -287,8 +287,11 @@ CREATE FUNCTION highlight_result_array(vals varchar[], something tsquery, someth DECLARE -- ^^^^ keyword.declaration.variable output varchar[]; +-- ^ - variable -- ^^^^^^ variable.other +-- ^ - variable - storage -- ^^^^^^^ storage.type +-- ^^ - storage -- ^ punctuation.section.brackets.begin -- ^ punctuation.section.brackets.end -- ^ punctuation.terminator.statement @@ -302,6 +305,11 @@ BEGIN END; $$ LANGUAGE plpgsql STABLE; +DECLARE var varchar[]; +-- ^ - variable +-- ^^^ variable.other.psql +-- ^ - variable - storage + DROP TRIGGER blah ON some_table; -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop -- ^ keyword.other.ddl From 86ac1c4064d379b34c8b9ec99265b8977a336ddb Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 12 Jun 2022 10:00:36 +0200 Subject: [PATCH 100/250] Refactor wildcard identifiers --- SQL/SQL (basic).sublime-syntax | 23 ++++++++++------------- SQL/TSQL.sublime-syntax | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 5493afc42f..4de7935829 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -101,14 +101,15 @@ contexts: - identifier-part maybe-identifier-accessor: - - match: \s*(\.)(?=\s*\*) + - match: \s*(\.)\s*(\*) captures: 1: punctuation.accessor.dot.sql - set: possible-wildcard - - match: \s*(\.) + 2: variable.language.wildcard.asterisk.sql + pop: 1 + - match: \s*(\.)\s* captures: 1: punctuation.accessor.dot.sql - set: single-identifier-after-whitespace + set: single-identifier - include: immediately-pop identifier-part: @@ -143,6 +144,10 @@ contexts: 3: punctuation.definition.identifier.end.sql pop: 1 + wildcard-identifiers: + - match: \* + scope: variable.language.wildcard.asterisk.sql + create-condition: - include: dml-condition - match: (?=\S) @@ -206,7 +211,7 @@ contexts: - include: else-pop expressions-or-column-name: - - include: wildcard-identifier + - include: wildcard-identifiers - include: expressions - include: column-references @@ -726,14 +731,6 @@ contexts: - include: operators - include: else-pop - wildcard-identifier: - - match: \* - scope: variable.language.wildcard.asterisk.sql - - possible-wildcard: - - include: wildcard-identifier - - include: else-pop - tablesample: - meta_content_scope: meta.group.tablesample.sql - match: \b(?i:rows|percent)\b diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 080d38d93d..bf5792c627 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -590,10 +590,10 @@ contexts: maybe-identifier-accessor: - meta_prepend: true - - match: \s*(\.{2,}) + - match: \s*(\.{2,})\s* captures: 1: punctuation.accessor.dot.sql - set: single-identifier-after-whitespace + set: single-identifier cast: - meta_scope: meta.function-call.sql From 6d68d539690061d29ad73cf4f4cee6f0ae33c329 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 12 Jun 2022 11:35:10 +0200 Subject: [PATCH 101/250] Use more efficient lookahead to skip whitespace Allow comments in between. --- SQL/SQL (basic).sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 4de7935829..ff777d6cc4 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -89,7 +89,7 @@ contexts: - include: immediately-pop single-identifier-after-whitespace: - - match: \s* + - match: (?=\S) set: single-identifier single-identifier: From 6f32bbe08a26debdf1939540e58815205d15f247 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 12 Jun 2022 11:10:34 +0200 Subject: [PATCH 102/250] Refactor `cast` as builtin function-call CAST and CONVERT are both listed as related functions in TSQL specs. --- SQL/TSQL.sublime-syntax | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index bf5792c627..cf310d581b 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -269,9 +269,6 @@ contexts: expressions: - meta_prepend: true - - match: \b(?i:cast)\b - scope: support.function.tsql - push: cast - include: with - match: \b(?i:output)\b scope: storage.modifier.output.tsql @@ -288,6 +285,9 @@ contexts: built-in-scalar-function-calls: - meta_append: true + - match: \b(?i:CAST)\b + scope: support.function.tsql + push: cast-arguments - match: \b((?i:CONVERT))\s*(\() scope: meta.function-call.sql captures: @@ -300,6 +300,23 @@ contexts: scope: support.function.scalar.sql push: function-call-arguments + cast-arguments: + - meta_scope: meta.function-call.sql + - match: \( + scope: meta.group.sql punctuation.section.arguments.begin.sql + set: inside-cast-arguments + - include: else-pop + + inside-cast-arguments: + - meta_content_scope: meta.function-call.sql meta.group.sql + - match: \) + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql + pop: 1 + - match: \b(?i:as)\b + scope: keyword.operator.assignment.tsql + push: expect-type + - include: expressions-or-column-name + inside-convert-arguments: - meta_content_scope: meta.function-call.sql meta.group.sql - match: \) @@ -595,23 +612,6 @@ contexts: 1: punctuation.accessor.dot.sql set: single-identifier - cast: - - meta_scope: meta.function-call.sql - - match: \( - scope: meta.group.sql punctuation.section.arguments.begin.sql - set: inside-cast-method-call - - include: else-pop - - inside-cast-method-call: - - meta_content_scope: meta.function-call.sql meta.group.sql - - match: \) - scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql - pop: 1 - - match: \b(?i:as)\b - scope: keyword.operator.assignment.tsql - push: expect-type - - include: expressions-or-column-name - joins: - meta_append: true - match: (?i)\b(?:(?:cross|outer)\s+)?apply\b From e0c8b41cf81b7949cfd553187b167963364b1fe1 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Mon, 13 Jun 2022 19:55:38 +0200 Subject: [PATCH 103/250] Reorganize TSQL table creation --- SQL/TSQL.sublime-syntax | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index cf310d581b..92d0ea2a90 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -709,6 +709,13 @@ contexts: - maybe-filegroup - inside-ddl-table-creation-columns + inside-ddl-table-creation-columns: + - meta_prepend: true + - match: \b(?i:ROWGUIDCOL|CLUSTERED|NONCLUSTERED)\b + scope: storage.modifier.tsql + - match: \b(?i:period\s+for\s+system_time)\b + scope: storage.modifier.tsql + maybe-filegroup: - match: \b(?i:ON)\b(?!\s*{{identifier_for_lookahead}}\s*=) scope: keyword.other.tsql @@ -717,17 +724,15 @@ contexts: - single-identifier-after-whitespace - include: else-pop + filegroup-name: + - meta_include_prototype: false + - meta_content_scope: meta.filegroup-name.tsql + - include: immediately-pop + maybe-with-table-options: - include: with - include: else-pop - inside-ddl-table-creation-columns: - - meta_prepend: true - - match: \b(?i:ROWGUIDCOL|CLUSTERED|NONCLUSTERED)\b - scope: storage.modifier.tsql - - match: \b(?i:period\s+for\s+system_time)\b - scope: storage.modifier.tsql - computed-column-definition: - meta_content_scope: meta.computed-column-definition.tsql - match: (?=,) @@ -827,8 +832,3 @@ contexts: - meta_include_prototype: false - meta_content_scope: meta.index-name.tsql - include: immediately-pop - - filegroup-name: - - meta_include_prototype: false - - meta_content_scope: meta.filegroup-name.tsql - - include: immediately-pop From 02123eb7b13c5b337a950b75acd469d31b60e406 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Mon, 13 Jun 2022 19:59:05 +0200 Subject: [PATCH 104/250] Remove unnecessary word boundary checks --- SQL/TSQL.sublime-syntax | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 92d0ea2a90..b913250724 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -356,7 +356,7 @@ contexts: scope: keyword.other.tsql push: for-xml - include: top - - match: \b(?i:(option))\b\s*(\() + - match: \b(?i:(option))\s*(\() captures: 1: keyword.other.dml.tsql 2: meta.group.sql punctuation.section.group.begin.sql @@ -625,7 +625,7 @@ contexts: push: - with-column-definition - function-call-arguments - - match: \b(?i:(OPENROWSET))\b\s*(\() + - match: \b(?i:(OPENROWSET))\s*(\() scope: meta.function-call.tsql captures: 1: meta.table-valued-function-name.sql support.function.tsql From c25d4dd691d66f2aa47c880107aeb5a0443da63f Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Wed, 15 Jun 2022 19:09:30 +0200 Subject: [PATCH 105/250] Reorg prototypes --- SQL/SQL (basic).sublime-syntax | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index ff777d6cc4..c73f498d48 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -24,14 +24,6 @@ contexts: prototype: - include: comments - else-pop: - - match: (?=\S) - pop: 1 - - immediately-pop: - - match: '' - pop: 1 - main: - include: statements - match: ';' @@ -772,3 +764,13 @@ contexts: scope: punctuation.section.group.begin.sql set: inside-ddl-table-creation-columns - include: else-pop + +###[ PROTOTYPES ]############################################################## + + else-pop: + - match: (?=\S) + pop: 1 + + immediately-pop: + - match: '' + pop: 1 From f6965b92a5818c716cf98e3e16fc46090b71bed3 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Wed, 15 Jun 2022 19:10:42 +0200 Subject: [PATCH 106/250] Reorg comments --- SQL/MySQL.sublime-syntax | 2 ++ SQL/SQL (basic).sublime-syntax | 2 ++ 2 files changed, 4 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 39af8b8609..08c1bf20d8 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -26,6 +26,8 @@ contexts: - meta_append: true - include: regexps +###[ COMMENTS ]################################################################ + comments: - meta_append: true - match: '#' diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index c73f498d48..f85231898f 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -30,6 +30,8 @@ contexts: scope: punctuation.terminator.statement.sql - include: expressions-or-column-name +###[ COMMENTS ]################################################################ + comments: - include: double-dash-comments - include: block-comments From ad6c269357c603708e95e558392f3197ed19f914 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Wed, 15 Jun 2022 19:13:18 +0200 Subject: [PATCH 107/250] Reorg identifiers --- SQL/SQL (basic).sublime-syntax | 252 +++++++++++++++++---------------- 1 file changed, 128 insertions(+), 124 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index f85231898f..e0e9efc4a6 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -72,89 +72,13 @@ contexts: scope: punctuation.definition.comment.end.sql pop: 1 - identifier-create: - - meta_include_prototype: false - - meta_scope: meta.toc-list.full-identifier.sql entity.name.other.sql - - include: immediately-pop - - table-identifier-create: - - meta_include_prototype: false - - meta_scope: meta.toc-list.full-identifier.sql entity.name.struct.sql - - include: immediately-pop - - single-identifier-after-whitespace: - - match: (?=\S) - set: single-identifier - - single-identifier: - - meta_include_prototype: false - - include: pop-on-top-level-reserved-word - - match: '' - set: - - maybe-identifier-accessor - - identifier-part - - maybe-identifier-accessor: - - match: \s*(\.)\s*(\*) - captures: - 1: punctuation.accessor.dot.sql - 2: variable.language.wildcard.asterisk.sql - pop: 1 - - match: \s*(\.)\s* - captures: - 1: punctuation.accessor.dot.sql - set: single-identifier - - include: immediately-pop - - identifier-part: - - include: simple-identifier-part - - include: single-quoted-identifier-part - - include: double-quoted-identifier-part - - include: backtick-quoted-identifier-part - - include: else-pop - - simple-identifier-part: - - match: '{{simple_identifier}}' - pop: 1 - - single-quoted-identifier-part: - - match: (')([^']+)(') - captures: - 1: punctuation.definition.identifier.begin.sql - 3: punctuation.definition.identifier.end.sql - pop: 1 - - double-quoted-identifier-part: - - match: (")([^"]+)(") - captures: - 1: punctuation.definition.identifier.begin.sql - 3: punctuation.definition.identifier.end.sql - pop: 1 - - backtick-quoted-identifier-part: - - match: (`)([^`]+)(`) - captures: - 1: punctuation.definition.identifier.begin.sql - 3: punctuation.definition.identifier.end.sql - pop: 1 - - wildcard-identifiers: - - match: \* - scope: variable.language.wildcard.asterisk.sql - create-condition: - include: dml-condition - - match: (?=\S) - set: - - identifier-create - - single-identifier + - include: expect-other-creation-name create-table-condition: - include: dml-condition - - match: (?=\S) - set: - - table-identifier-create - - single-identifier + - include: expect-table-creation-name drop-condition: - include: dml-condition @@ -236,7 +160,7 @@ contexts: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql push: - - column-alias + - column-alias-name - single-identifier-after-whitespace case-expressions: @@ -589,51 +513,6 @@ contexts: - join-on - table-name-or-subquery - column-name: - - meta_include_prototype: false - - meta_content_scope: meta.column-name.sql - - include: immediately-pop - - column-name-declaration: - - meta_include_prototype: false - - meta_content_scope: meta.column-name.sql variable.other.member.declaration.sql - - include: immediately-pop - - column-alias: - - meta_include_prototype: false - - meta_content_scope: meta.column-alias.sql - - include: immediately-pop - - database-name: - - meta_include_prototype: false - - meta_content_scope: meta.database-name.sql - - include: immediately-pop - - table-name: - - meta_include_prototype: false - - meta_content_scope: meta.table-name.sql - - include: immediately-pop - - table-alias-name: - - meta_include_prototype: false - - meta_content_scope: meta.table-alias-name.sql - - include: immediately-pop - - procedure-name: - - meta_include_prototype: false - - meta_content_scope: meta.procedure-name.sql - - include: immediately-pop - - constraint-name: - - meta_include_prototype: false - - meta_content_scope: meta.constraint-name.sql - - include: immediately-pop - - schema-name: - - meta_include_prototype: false - - meta_content_scope: meta.schema-name.sql - - include: immediately-pop - subquery: - match: \( scope: punctuation.section.group.begin.sql @@ -767,6 +646,131 @@ contexts: set: inside-ddl-table-creation-columns - include: else-pop +###[ IDENTIFIERS ]############################################################# + + column-name: + - meta_include_prototype: false + - meta_content_scope: meta.column-name.sql + - include: immediately-pop + + column-name-declaration: + - meta_include_prototype: false + - meta_content_scope: meta.column-name.sql variable.other.member.declaration.sql + - include: immediately-pop + + column-alias-name: + - meta_include_prototype: false + - meta_content_scope: meta.column-alias.sql + - include: immediately-pop + + database-name: + - meta_include_prototype: false + - meta_content_scope: meta.database-name.sql + - include: immediately-pop + + procedure-name: + - meta_include_prototype: false + - meta_content_scope: meta.procedure-name.sql + - include: immediately-pop + + constraint-name: + - meta_include_prototype: false + - meta_content_scope: meta.constraint-name.sql + - include: immediately-pop + + schema-name: + - meta_include_prototype: false + - meta_content_scope: meta.schema-name.sql + - include: immediately-pop + + expect-table-creation-name: + - match: (?=\S) + set: [table-creation-name, single-identifier] + + table-creation-name: + - meta_include_prototype: false + - meta_scope: meta.toc-list.full-identifier.sql entity.name.struct.sql + - include: immediately-pop + + table-name: + - meta_include_prototype: false + - meta_content_scope: meta.table-name.sql + - include: immediately-pop + + table-alias-name: + - meta_include_prototype: false + - meta_content_scope: meta.table-alias-name.sql + - include: immediately-pop + + expect-other-creation-name: + - match: (?=\S) + set: [other-creation-name, single-identifier] + + other-creation-name: + - meta_include_prototype: false + - meta_scope: meta.toc-list.full-identifier.sql entity.name.other.sql + - include: immediately-pop + + single-identifier-after-whitespace: + - match: (?=\S) + set: single-identifier + + single-identifier: + - meta_include_prototype: false + - include: pop-on-top-level-reserved-word + - match: '' + set: + - maybe-identifier-accessor + - identifier-part + + maybe-identifier-accessor: + - match: \s*(\.)\s*(\*) + captures: + 1: punctuation.accessor.dot.sql + 2: variable.language.wildcard.asterisk.sql + pop: 1 + - match: \s*(\.)\s* + captures: + 1: punctuation.accessor.dot.sql + set: single-identifier + - include: immediately-pop + + identifier-part: + - include: simple-identifier-part + - include: single-quoted-identifier-part + - include: double-quoted-identifier-part + - include: backtick-quoted-identifier-part + - include: else-pop + + simple-identifier-part: + - match: '{{simple_identifier}}' + pop: 1 + + single-quoted-identifier-part: + - match: (')([^']+)(') + captures: + 1: punctuation.definition.identifier.begin.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + + double-quoted-identifier-part: + - match: (")([^"]+)(") + captures: + 1: punctuation.definition.identifier.begin.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + + backtick-quoted-identifier-part: + - match: (`)([^`]+)(`) + captures: + 1: punctuation.definition.identifier.begin.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + + wildcard-identifiers: + - match: \* + scope: variable.language.wildcard.asterisk.sql + ###[ PROTOTYPES ]############################################################## else-pop: From c6e3dcd4cd7f47ffe3791bd47482ec6d6555cac9 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Wed, 15 Jun 2022 19:30:53 +0200 Subject: [PATCH 108/250] Refactor/fix identifier boundaries Old implementation caused whitespace in front of identifiers being included into identifier scope. That's fixed by this commit. --- SQL/Cassandra.sublime-syntax | 11 +- SQL/MySQL.sublime-syntax | 21 +--- SQL/PostgreSQL.sublime-syntax | 4 +- SQL/SQL (basic).sublime-syntax | 113 ++++++++--------- SQL/TSQL.sublime-syntax | 168 ++++++++++++++------------ SQL/tests/syntax/syntax_test_tsql.sql | 49 +++++++- 6 files changed, 203 insertions(+), 163 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 987c486b79..e069f20d2f 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -66,8 +66,7 @@ contexts: push: - copy-from - maybe-group - - table-name - - single-identifier-after-whitespace + - expect-table-name statements: - meta_prepend: true @@ -129,10 +128,10 @@ contexts: - include: dml-condition - match: (?=\S) set: - - type-identifier-create + - type-creation-name - single-identifier - type-identifier-create: + type-creation-name: - meta_include_prototype: false - meta_scope: meta.toc-list.full-identifier.sql entity.name.type.cql - include: immediately-pop @@ -164,7 +163,7 @@ contexts: - match: ',' scope: punctuation.separator.sequence.cql set: inside-group - - include: column-references + - include: expect-column-names inside-partition-key-group: - match: \) @@ -172,7 +171,7 @@ contexts: pop: 1 - match: ',' scope: punctuation.separator.sequence.cql - - include: column-references + - include: expect-column-names joins: - match: \bjoin\b diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 08c1bf20d8..9f30aed988 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -138,18 +138,14 @@ contexts: - meta_append: true - match: \b(?i:insert(\s+(?:ignore\s+)?into)?)\b scope: keyword.other.dml.sql - push: - - table-name - - single-identifier-after-whitespace + push: expect-table-name - match: \b(?i:limit)\b scope: keyword.other.dml.sql ddl-target-common: - match: \b(?i:on)\b scope: keyword.other.mysql - push: - - table-name - - single-identifier-after-whitespace + push: expect-table-name - match: \b(?i:using)\b scope: keyword.other.mysql - match: \b(?i:(algorithm))\s*(=) @@ -189,9 +185,9 @@ contexts: - match: \b(?i:change\s+column)\b scope: keyword.other.ddl.sql push: - - new-column-name - - column-name - - single-identifier-after-whitespace + - expect-type + - expect-column-name-declaration + - expect-column-name inside-ddl-table-creation-columns: - meta_prepend: true @@ -205,10 +201,3 @@ contexts: scope: keyword.other.mysql pop: 1 - include: else-pop - - new-column-name: - - match: (?=\S) - set: - - expect-type - - column-name-declaration - - single-identifier diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index e3724f3e62..197043fe8a 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -122,6 +122,4 @@ contexts: scope: keyword.other.psql - match: \b(?i:schema)\b scope: storage.modifier.psql - push: - - schema-name - - single-identifier-after-whitespace + push: expect-schema-name diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index e0e9efc4a6..ac0b493e67 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -85,7 +85,7 @@ contexts: - match: (?=\S) set: - ddl-target-on - - single-identifier-after-whitespace + - single-identifier dml-condition: - match: \b(?i:if)\b @@ -131,14 +131,7 @@ contexts: expressions-or-column-name: - include: wildcard-identifiers - include: expressions - - include: column-references - - column-references: - - match: (?=\S) - push: - - possible-operator - - column-name - - single-identifier + - include: expect-column-names expressions: - include: alias-expressions @@ -159,9 +152,7 @@ contexts: alias-expressions: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql - push: - - column-alias-name - - single-identifier-after-whitespace + push: expect-column-alias-name case-expressions: - match: \b(?i:case)\b @@ -325,8 +316,7 @@ contexts: scope: keyword.other.ddl.sql push: - ddl-alter-table - - table-name - - single-identifier-after-whitespace + - expect-table-name - match: \b(?i:alter)\b scope: keyword.other.ddl.sql push: @@ -355,9 +345,7 @@ contexts: ddl-target-on: - match: \b(?i:on)\b scope: keyword.other.sql - push: - - table-name - - single-identifier-after-whitespace + push: expect-table-name - include: else-pop ddl-table-creation-columns: @@ -378,10 +366,7 @@ contexts: ddl-drop-table: - meta_scope: meta.drop.sql - include: dml-condition - - match: (?=\S) - set: - - table-name - - single-identifier-after-whitespace + - include: expect-table-name ddl-alter-table: - meta_scope: meta.alter.sql @@ -399,8 +384,7 @@ contexts: scope: meta.add.sql keyword.other.sql push: - after-constraint-pop - - constraint-name - - single-identifier-after-whitespace + - expect-constraint-name - match: \b(?i:add\s+(?:(?:fulltext|spatial)\s+(index|key)|index))\b scope: meta.add.sql keyword.other.sql #- include: types @@ -411,24 +395,18 @@ contexts: scope: keyword.other.ddl.sql push: - expect-type - - column-name-declaration - - single-identifier-after-whitespace + - expect-column-name-declaration - match: \b(?i:(?:add|alter))\b(?!\s+{{ddl_target}}) scope: keyword.other.ddl.sql push: - expect-type - - column-name-declaration - - single-identifier-after-whitespace + - expect-column-name-declaration - match: \b(?i:drop\s+column)\b scope: keyword.other.ddl.sql - push: - - column-name - - single-identifier-after-whitespace + push: expect-column-name - match: \b(?i:drop)\b(?!\s+{{ddl_target}}) scope: keyword.other.ddl.sql - push: - - column-name - - single-identifier-after-whitespace + push: expect-column-name dml-statements: - match: \b(?i:select)\b @@ -443,9 +421,7 @@ contexts: push: dml-update - match: \b(?i:(?:insert\s+into|truncate))\b scope: keyword.other.dml.sql - push: - - table-name - - single-identifier-after-whitespace + push: expect-table-name - match: \b(?i:set)\b scope: keyword.other.dml.sql push: set @@ -468,9 +444,7 @@ contexts: pop: 1 - match: \b(?i:constraint)\b scope: storage.modifier.sql - push: - - constraint-name - - single-identifier-after-whitespace + push: expect-constraint-name - include: after-constraint - include: expressions - include: ddl-creation-column @@ -486,21 +460,13 @@ contexts: use-db: - match: \b(?i:use)\b scope: keyword.context.sql - push: - - database-name - - single-identifier-after-whitespace + push: expect-database-name dml-delete: - - match: (?=\S) - set: - - table-name - - single-identifier + - include: expect-table-name dml-update: - - match: (?=\S) - set: - - table-name - - single-identifier + - include: expect-table-name distinct: - match: \b(?i:distinct)\b @@ -633,8 +599,7 @@ contexts: scope: storage.modifier.sql push: - maybe-column-reference - - table-name - - single-identifier-after-whitespace + - expect-table-name after-constraint-pop: - include: after-constraint @@ -648,36 +613,68 @@ contexts: ###[ IDENTIFIERS ]############################################################# + expect-column-names: + - match: (?=\S) + push: [possible-operator, column-name, single-identifier] + + expect-column-name: + - match: (?=\S) + set: [column-name, single-identifier] + column-name: - meta_include_prototype: false - meta_content_scope: meta.column-name.sql - include: immediately-pop + expect-column-name-declaration: + - match: (?=\S) + set: [column-name-declaration, single-identifier] + column-name-declaration: - meta_include_prototype: false - meta_content_scope: meta.column-name.sql variable.other.member.declaration.sql - include: immediately-pop + expect-column-alias-name: + - match: (?=\S) + set: [column-alias-name, single-identifier] + column-alias-name: - meta_include_prototype: false - meta_content_scope: meta.column-alias.sql - include: immediately-pop + expect-database-name: + - match: (?=\S) + set: [database-name, single-identifier] + database-name: - meta_include_prototype: false - meta_content_scope: meta.database-name.sql - include: immediately-pop + expect-procedure-name: + - match: (?=\S) + set: [procedure-name, single-identifier] + procedure-name: - meta_include_prototype: false - meta_content_scope: meta.procedure-name.sql - include: immediately-pop + expect-constraint-name: + - match: (?=\S) + set: [constraint-name, single-identifier] + constraint-name: - meta_include_prototype: false - meta_content_scope: meta.constraint-name.sql - include: immediately-pop + expect-schema-name: + - match: (?=\S) + set: [schema-name, single-identifier] + schema-name: - meta_include_prototype: false - meta_content_scope: meta.schema-name.sql @@ -692,11 +689,19 @@ contexts: - meta_scope: meta.toc-list.full-identifier.sql entity.name.struct.sql - include: immediately-pop + expect-table-name: + - match: (?=\S) + set: [table-name, single-identifier] + table-name: - meta_include_prototype: false - meta_content_scope: meta.table-name.sql - include: immediately-pop + expect-table-alias-name: + - match: (?=\S) + set: [table-alias-name, single-identifier] + table-alias-name: - meta_include_prototype: false - meta_content_scope: meta.table-alias-name.sql @@ -711,10 +716,6 @@ contexts: - meta_scope: meta.toc-list.full-identifier.sql entity.name.other.sql - include: immediately-pop - single-identifier-after-whitespace: - - match: (?=\S) - set: single-identifier - single-identifier: - meta_include_prototype: false - include: pop-on-top-level-reserved-word diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index b913250724..207abad710 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -30,21 +30,6 @@ variables: )\b contexts: - identifier-part: - - meta_prepend: true - - match: \b(?i:inserted|deleted)(\.) - scope: constant.language.table.tsql - captures: - 1: punctuation.accessor.dot.tsql - - include: square-bracketed-identifier-part - - square-bracketed-identifier-part: - - match: (\[)([^]]+)(\]) - captures: - 1: punctuation.definition.identifier.begin.sql - 3: punctuation.definition.identifier.end.sql - pop: 1 - strings: - meta_append: true - match: N' @@ -234,7 +219,7 @@ contexts: scope: keyword.control.flow.tsql - match: \b(?i:goto)\b scope: keyword.control.flow.tsql - push: [label-name, single-identifier-after-whitespace] + push: expect-label-name - match: \b(?i:exec)\b scope: keyword.control.flow.tsql push: [expect-procedure-name, exec] @@ -246,7 +231,7 @@ contexts: scope: keyword.other.tsql - match: \b(?i:use)\b scope: keyword.context.tsql - push: [database-name, single-identifier-after-whitespace] + push: expect-database-name - match: \b(?i:backup(?:\s+database)?)\b # https://docs.microsoft.com/en-us/sql/t-sql/statements/backup-transact-sql?view=sql-server-ver15 scope: keyword.other.tsql - match: \b(?i:to)\b @@ -344,10 +329,10 @@ contexts: scope: keyword.other.tsql - match: \b(?i:insert)\b scope: keyword.other.dml.sql - push: [table-name, single-identifier-after-whitespace] + push: expect-table-name - match: \b(?i:into)\b(?!\s*@) scope: keyword.other.dml.tsql - push: [table-name, single-identifier-after-whitespace] + push: expect-table-name - match: \b(?i:into)\b scope: keyword.other.tsql - match: \b(?i:off)\b @@ -363,23 +348,19 @@ contexts: push: inside-with-group - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b scope: keyword.other.sql - push: - - cursor-name - - single-identifier-after-whitespace + push: expect-cursor-name - match: \b(?i:merge)\b scope: keyword.other.tsql push: - maybe-table-alias - - table-name - - single-identifier-after-whitespace + - expect-table-name - match: \b(?i:using)\b scope: keyword.other.tsql push: - table-name-or-subquery - join-on - maybe-table-alias - - table-name - - single-identifier-after-whitespace + - expect-table-name - match: \b(?i:set)\b scope: keyword.other.dml.tsql @@ -428,16 +409,6 @@ contexts: - meta_prepend: true - include: top - label-name: - - meta_include_prototype: false - - meta_content_scope: meta.label-name.sql - - include: immediately-pop - - cursor-name: - - meta_include_prototype: false - - meta_content_scope: meta.cursor-name.sql - - include: immediately-pop - inside-declaration: - match: \w+(?=\s+(?i:cursor)\b) scope: meta.cursor-name.sql @@ -461,9 +432,7 @@ contexts: scope: constant.language.switch.tsql - match: \b(?i:identity_insert)\b scope: constant.language.switch.tsql - push: - - table-name - - single-identifier + push: expect-table-name - match: \b(?i:on|off)\b scope: constant.language.boolean.tsql - include: variables @@ -505,14 +474,12 @@ contexts: scope: keyword.other.dml.sql push: - cte-column-list-begin - - cte-table-name - - single-identifier + - expect-cte-table-name - match: (?i)\bwith\b #(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) scope: keyword.other.dml.sql push: - cte-as - - cte-table-name - - single-identifier + - expect-cte-table-name with: - match: (?i)\bwith\b @@ -552,9 +519,7 @@ contexts: captures: 1: keyword.other.tsql 2: keyword.operator.assignment.tsql - push: - - index-name - - single-identifier-after-whitespace + push: expect-index-name - match: \b((?i:SYSTEM_VERSIONING))\s*(=) captures: 1: keyword.other.tsql @@ -565,9 +530,7 @@ contexts: captures: 1: keyword.other.tsql 2: keyword.operator.assignment.tsql - push: - - table-name - - single-identifier-after-whitespace + push: expect-table-name - match: \w+ scope: constant.language.with.tsql - match: ',' @@ -605,13 +568,6 @@ contexts: set: with-paren-or-pop - include: collate-expressions - maybe-identifier-accessor: - - meta_prepend: true - - match: \s*(\.{2,})\s* - captures: - 1: punctuation.accessor.dot.sql - set: single-identifier - joins: - meta_append: true - match: (?i)\b(?:(?:cross|outer)\s+)?apply\b @@ -638,13 +594,6 @@ contexts: - include: expressions - include: else-pop - expect-procedure-name: - - meta_include_prototype: false - - match: '' - set: - - procedure-name - - single-identifier-after-whitespace - cte-column-list-begin: - match: (?=\() scope: punctuation.section.group.begin.tsql @@ -660,14 +609,11 @@ contexts: - include: pop-on-top-level-reserved-word - match: ',' scope: punctuation.separator.sequence.cte.tsql - set: [cte-column-list-begin, cte-table-name, single-identifier-after-whitespace] + set: + - cte-column-list-begin + - expect-cte-table-name - include: expressions - cte-table-name: - - meta_include_prototype: false - - meta_content_scope: meta.cte-table-name.sql - - include: immediately-pop - for-xml: - match: \b(?i:raw|auto|elements|root|path)\b scope: keyword.other.tsql @@ -719,16 +665,9 @@ contexts: maybe-filegroup: - match: \b(?i:ON)\b(?!\s*{{identifier_for_lookahead}}\s*=) scope: keyword.other.tsql - set: - - filegroup-name - - single-identifier-after-whitespace + set: expect-filegroup-name - include: else-pop - filegroup-name: - - meta_include_prototype: false - - meta_content_scope: meta.filegroup-name.tsql - - include: immediately-pop - maybe-with-table-options: - include: with - include: else-pop @@ -823,12 +762,81 @@ contexts: pop: 1 - include: literals-and-variables - include: ddl-table-creation-columns + - include: expect-index-names + +###[ IDENTIFIERS ]############################################################# + + expect-cte-table-name: - match: (?=\S) - push: - - index-name - - single-identifier + set: [cte-table-name, single-identifier] + + cte-table-name: + - meta_include_prototype: false + - meta_content_scope: meta.cte-table-name.sql + - include: immediately-pop + + expect-cursor-name: + - match: (?=\S) + set: [cursor-name, single-identifier] + + cursor-name: + - meta_include_prototype: false + - meta_content_scope: meta.cursor-name.sql + - include: immediately-pop + + expect-filegroup-name: + - match: (?=\S) + set: [filegroup-name, single-identifier] + + filegroup-name: + - meta_include_prototype: false + - meta_content_scope: meta.filegroup-name.tsql + - include: immediately-pop + + expect-index-names: + - match: (?=\S) + push: [index-name, single-identifier] + + expect-index-name: + - match: (?=\S) + set: [index-name, single-identifier] index-name: - meta_include_prototype: false - meta_content_scope: meta.index-name.tsql - include: immediately-pop + + expect-label-name: + - match: (?=\S) + set: [label-name, single-identifier] + + label-name: + - meta_include_prototype: false + - meta_content_scope: meta.label-name.sql + - include: immediately-pop + + maybe-identifier-accessor: + - meta_prepend: true + - match: \s*(\.{2,})\s* + captures: + 1: punctuation.accessor.dot.sql + set: single-identifier + + identifier-part: + - meta_prepend: true + - match: \b(?i:inserted|deleted)(\.) + scope: constant.language.table.tsql + captures: + 1: punctuation.accessor.dot.tsql + - include: square-bracketed-identifier-part + + square-bracketed-identifier-part: + - match: (\[)([^]]+)(\]) + captures: + 1: punctuation.definition.identifier.begin.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + + inside-simple-identifier-part: + - meta_prepend: true + - include: variables diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index dadfff8ed9..5a71e85d90 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -329,7 +329,9 @@ SET NOCOUNT ON -- ^^ constant.language.boolean EXEC master.dbo.xp_fileexist @FromFile, @FileExists OUTPUT -- ^ keyword.control.flow +-- ^ - meta.procedure-name -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name +-- ^ - meta.procedure-name -- ^^^^^^^^^ variable.other.readwrite -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^ variable.other.readwrite @@ -373,7 +375,9 @@ EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'every 10 @schedule_uid=N'564354f8-4985-7408-80b7-afdc2bb92d3c' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback -- ^^^^ keyword.control.flow +-- ^ - meta.label-name -- ^^^^^^^^^^^^^^^^ meta.label-name +-- ^ - meta.label-name EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' -- ^ keyword.control.flow -- ^^^^^^^^^^^ variable.other.readwrite @@ -466,8 +470,11 @@ SET column1 = v.column1, -- ^^^^^^^^ constant.numeric.value FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^ keyword.other.dml +-- ^ - meta.table-name -- ^^^^^^^^^^^^^ meta.table-name +-- ^ - meta.table-name - meta.table-alias-name -- ^^^^^^^^^^ meta.table-alias-name +-- ^ - meta.table-alias-name -- ^^^^ keyword.other -- ^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ - meta.group @@ -478,20 +485,28 @@ FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^ punctuation.section.group.end INNER JOIN some_view AS v WITH (NOLOCK) ON v.some_id = TableAlias.some_id -- ^^^^^^^ keyword.other.dml +-- ^ - meta.table-name -- ^^^^^^^^^ meta.table-name +-- ^ - meta.table-name -- ^^ keyword.operator.assignment.alias +-- ^ - meta.table-alias-name -- ^ meta.table-alias-name +-- ^ - meta.table-alias-name -- ^^^^ keyword.other.dml -- ^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^ constant.language.with -- ^ punctuation.section.group.end -- ^^ keyword.operator.join +-- ^ - meta.column-name -- ^^^^^^^^^ meta.column-name -- ^ punctuation.accessor.dot +-- ^ - meta.column-name -- ^ keyword.operator.comparison +-- ^ - meta.column-name -- ^^^^^^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.accessor.dot +-- ^ - meta.column-name WHERE TableAlias.some_id IN ( -- ^^ keyword.other.dml -- ^^ keyword.operator.logical @@ -500,10 +515,16 @@ WHERE TableAlias.some_id IN ( -- ^^^^^^ keyword.other.dml FROM dbname..table_name_in_default_schema a -- ^^^^ keyword.other.dml +-- ^ - meta.table-name -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name --- ^ meta.group meta.table-alias-name +-- ^ - meta.table-name - meta.table-alias-name +-- ^ meta.table-alias-name +-- ^ - meta.table-alias-name WHERE a.another_id_column IS NOT NULL --- ^^^^^ meta.group keyword.other.dml +-- ^^^^^ keyword.other.dml +-- ^ - meta.column-name - keyword +-- ^^^^^^^^^^^^^^^^^^^ meta.column-name +-- ^ - meta.column-name - keyword -- ^^ keyword.operator.logical -- ^^^ keyword.operator.logical -- ^^^^ constant.language.null @@ -1120,14 +1141,18 @@ CREATE TABLE dbo.T1 -- ^^^^^^^^^^^ storage.type CONSTRAINT default_name DEFAULT ('my column default'), -- ^^^^^^^^^^ storage.modifier +-- ^ - meta.constraint-name -- ^^^^^^^^^^^^ meta.constraint-name +-- ^ - meta.constraint-name -- ^^^^^^^ storage.modifier -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^^^^^^^^^ string.quoted.single -- ^ punctuation.section.group.end -- ^ punctuation.separator.sequence column_3 rowversion, +-- ^ - meta.column-name -- ^^^^^^^^ meta.column-name +-- ^ - meta.column-name -- ^^^^^^^^^^ storage.type column_4 varchar(40) NULL ); @@ -1140,12 +1165,18 @@ INSERT INTO T1 DEFAULT VALUES; MERGE sales.category t -- ^^ keyword.other +-- ^ - meta.table-name -- ^^^^^^^^^^^^^^ meta.table-name +-- ^ - meta.table-name - meta.table-alias-name -- ^ meta.table-alias-name +-- ^ - meta.table-alias-name USING sales.category_staging s -- ^^^^^ keyword.other +-- ^ - meta.table-name -- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^ - meta.table-name - meta.table-alias-name -- ^ meta.table-alias-name +-- ^ - meta.table-alias-name ON (s.category_id = t.category_id) -- <- keyword.operator.join -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group @@ -1543,11 +1574,25 @@ FROM OPENXML (@XmlDocumentHandle, '/ROOT/Customer',2) -- TODO: apply xpath -- ^ punctuation.section.group.end EXEC sp_xml_removedocument @XmlDocumentHandle -- <- keyword.control.flow +-- ^ - meta.procedure-name -- ^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name +-- ^ - meta.procedure-name -- ^ variable.other.readwrite punctuation.definition.variable +-- ^^^^^^^^^^^^^^^^^ variable.other.readwrite - punctuation --Create an internal representation of the XML document. EXEC sp_xml_preparedocument @idoc OUTPUT, @doc; +-- <- keyword.control.flow +-- ^ - meta.procedure-name +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name +-- ^ - meta.procedure-name +-- ^ variable.other.readwrite punctuation.definition.variable +-- ^^^^ variable.other.readwrite.sql +-- ^ - variable +-- ^^^^^^ storage.modifier.output.tsql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ variable.other.readwrite.sql +-- ^ punctuation.terminator.statement.sql -- SELECT stmt using OPENXML rowset provider SELECT * From db7dad485753ae0e3187982dda6d72edeb2031d4 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Thu, 16 Jun 2022 20:07:07 +0200 Subject: [PATCH 109/250] Add support for interpolated identifiers This commit refactors `identifier` related contexts by setting dedicated `inside-...identifier-part` contexts on stack, which may be extended by variable interpolation patterns. PHP makes use of it, currently. --- PHP/tests/syntax_test_php.php | 54 +++++++----- SQL/SQL (basic).sublime-syntax | 116 ++++++++++++++++++++------ SQL/TSQL.sublime-syntax | 33 ++++++-- SQL/tests/syntax/syntax_test_tsql.sql | 9 +- 4 files changed, 160 insertions(+), 52 deletions(-) diff --git a/PHP/tests/syntax_test_php.php b/PHP/tests/syntax_test_php.php index f2f425310f..9e911d95b2 100644 --- a/PHP/tests/syntax_test_php.php +++ b/PHP/tests/syntax_test_php.php @@ -4499,20 +4499,34 @@ function testTypeCasts() "; // <- meta.string.php string.quoted.double.php punctuation.definition.string.end.php - meta.interpolation - string string -$sql = "SELECT " . $col . "FROM $table WHERE ( first_name =" . $name . ")" ; . "GROUP BY" ; +$sql = "SELECT `$col` FROM 'my$table--name'"; +// ^^^^^^ meta.column-name.sql +// ^ punctuation.definition.identifier.begin.sql +// ^^^^ meta.interpolation.php variable.other.php +// ^ punctuation.definition.identifier.end.sql +// ^^^^ keyword.other.dml.sql +// ^^^^^^^^^^^^^^^^ meta.table-name.sql +// ^ punctuation.definition.identifier.begin.sql +// ^^^^^^ meta.interpolation.php variable.other.php +// ^ punctuation.definition.identifier.end.sql + +$sql = "SELECT " . $col . "FROM $table WHERE ( first_$name =" . $name . ")" ; . "GROUP BY" ; // ^ meta.string.php - meta.interpolation // ^^^^^^^ meta.string.php source.sql.embedded.php // ^ meta.string.php - meta.interpolation // ^^^^^^^^^^ - meta.string // ^ meta.string.php - meta.interpolation -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php -// ^ meta.string.php - meta.interpolation -// ^^^^^^^^^^^ - meta.string -// ^ meta.string.php - meta.interpolation -// ^ meta.string.php source.sql.embedded.php -// ^ meta.string.php - meta.interpolation -// ^^^^^ - meta.string -// ^^^^^^^^^^ meta.string.php string.quoted.double.php - meta.interpolation +// ^^^^^ meta.string.php source.sql.embedded.php - meta.interpolation +// ^^^^^^ meta.string.php source.sql.embedded.php meta.table-name.sql meta.interpolation.php +// ^^^^^^^^^^^^^^^ meta.string.php source.sql.embedded.php - meta.interpolation +// ^^^^^ meta.string.php source.sql.embedded.php meta.interpolation.php +// ^ meta.string.php - meta.interpolation +// ^^^^^^^^^^^ - meta.string +// ^ meta.string.php - meta.interpolation +// ^ meta.string.php source.sql.embedded.php +// ^ meta.string.php - meta.interpolation +// ^^^^^ - meta.string +// ^^^^^^^^^^ meta.string.php string.quoted.double.php - meta.interpolation // ^ string.quoted.double.php punctuation.definition.string.begin.php // ^^^^^^ keyword.other.dml.sql // ^ string.quoted.double.php punctuation.definition.string.end.php @@ -4523,16 +4537,18 @@ function testTypeCasts() // ^^^^^^ variable.other.php // ^^^^^ keyword.other.dml.sql // ^ punctuation.section.group.begin.sql -// ^ string.quoted.double.php punctuation.definition.string.end.php -// ^ keyword.operator.concatenation.php -// ^^^^^ variable.other.php -// ^ keyword.operator.concatenation.php -// ^ string.quoted.double.php punctuation.definition.string.begin.php -// ^ punctuation.section.group.end.sql - string -// ^ string.quoted.double.php punctuation.definition.string.end.php -// ^ punctuation.terminator.statement.php -// ^ keyword.operator.concatenation.php -// ^ punctuation.terminator.statement.php +// ^^^^^^ meta.column-name.sql - variable +// ^^^^^ meta.column-name.sql variable.other.php +// ^ keyword.operator.comparison.sql +// ^ string.quoted.double.php punctuation.definition.string.end.php +// ^ keyword.operator.concatenation.php +// ^^^^^ variable.other.php +// ^ keyword.operator.concatenation.php +// ^ string.quoted.double.php punctuation.definition.string.begin.php +// ^ string.quoted.double.php punctuation.definition.string.end.php +// ^ punctuation.terminator.statement.php +// ^ keyword.operator.concatenation.php +// ^ punctuation.terminator.statement.php $sql = "DROP TABLE foo"; // ^ meta.string.php string.quoted.double.php punctuation.definition.string.begin.php diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index ac0b493e67..42cdfcb055 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -8,6 +8,7 @@ version: 2 variables: string_escape: (?:\\.) simple_identifier: (?:\w+) + simple_identifier_break: (?!\w) reserved: (?:;|\b(?i:from|order|group|select|where|inner|outer|left|right|join|on|set|union|insert|delete|update|truncate|create|alter|drop|return)\b) additional_reserved: (?!) simple_types: (?i:\b(?:bit|bool|boolean|datetime|int)\b) @@ -103,6 +104,12 @@ contexts: scope: keyword.operator.arithmetic.sql - include: logical-operators + expect-type: + - meta_include_prototype: false + - include: comments + - include: built-in-type + - include: expect-user-type + built-in-type: - match: '{{simple_types}}' scope: storage.type.sql @@ -118,12 +125,15 @@ contexts: 3: constant.numeric.sql pop: 1 - expect-type: - - include: built-in-type - - match: '{{simple_identifier}}' - scope: support.type.sql + expect-user-type: + - match: (?=\S) + set: inside-user-type + + inside-user-type: + # note: may contain foreign variable interpolation + - meta_scope: support.type.sql + - match: '{{simple_identifier_break}}' pop: 1 - - include: else-pop after-type: - include: else-pop @@ -509,6 +519,7 @@ contexts: - single-identifier fail-if-function-call: + - meta_include_prototype: false - match: \( fail: table-or-table-function # basically we are using branch points to avoid a complicated lookahead (which can be overridden by syntaxes extending this one) for an identifier followed by an open paren - match: (?=\S) @@ -618,6 +629,9 @@ contexts: push: [possible-operator, column-name, single-identifier] expect-column-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [column-name, single-identifier] @@ -627,6 +641,9 @@ contexts: - include: immediately-pop expect-column-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [column-name-declaration, single-identifier] @@ -636,6 +653,9 @@ contexts: - include: immediately-pop expect-column-alias-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [column-alias-name, single-identifier] @@ -645,6 +665,9 @@ contexts: - include: immediately-pop expect-database-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [database-name, single-identifier] @@ -654,6 +677,9 @@ contexts: - include: immediately-pop expect-procedure-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [procedure-name, single-identifier] @@ -663,6 +689,9 @@ contexts: - include: immediately-pop expect-constraint-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [constraint-name, single-identifier] @@ -672,6 +701,9 @@ contexts: - include: immediately-pop expect-schema-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [schema-name, single-identifier] @@ -681,6 +713,9 @@ contexts: - include: immediately-pop expect-table-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [table-creation-name, single-identifier] @@ -690,6 +725,9 @@ contexts: - include: immediately-pop expect-table-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [table-name, single-identifier] @@ -699,6 +737,9 @@ contexts: - include: immediately-pop expect-table-alias-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [table-alias-name, single-identifier] @@ -708,6 +749,9 @@ contexts: - include: immediately-pop expect-other-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [other-creation-name, single-identifier] @@ -725,47 +769,65 @@ contexts: - identifier-part maybe-identifier-accessor: + - meta_include_prototype: false - match: \s*(\.)\s*(\*) captures: 1: punctuation.accessor.dot.sql 2: variable.language.wildcard.asterisk.sql pop: 1 - - match: \s*(\.)\s* + - match: \s*(\.) captures: 1: punctuation.accessor.dot.sql set: single-identifier - include: immediately-pop identifier-part: - - include: simple-identifier-part - - include: single-quoted-identifier-part - - include: double-quoted-identifier-part + - meta_include_prototype: false - include: backtick-quoted-identifier-part - - include: else-pop + - include: double-quoted-identifier-part + - include: single-quoted-identifier-part + - include: simple-identifier-part - simple-identifier-part: - - match: '{{simple_identifier}}' + backtick-quoted-identifier-part: + - match: \` + scope: punctuation.definition.identifier.begin.sql + set: inside-backtick-quoted-identifier-part + + inside-backtick-quoted-identifier-part: + # note: may contain foreign variable interpolation + - match: \` + scope: punctuation.definition.identifier.end.sql pop: 1 - single-quoted-identifier-part: - - match: (')([^']+)(') - captures: - 1: punctuation.definition.identifier.begin.sql - 3: punctuation.definition.identifier.end.sql + double-quoted-identifier-part: + - match: \" + scope: punctuation.definition.identifier.begin.sql + set: inside-double-quoted-identifier-part + + inside-double-quoted-identifier-part: + # note: may contain foreign variable interpolation + - match: \" + scope: punctuation.definition.identifier.end.sql pop: 1 - double-quoted-identifier-part: - - match: (")([^"]+)(") - captures: - 1: punctuation.definition.identifier.begin.sql - 3: punctuation.definition.identifier.end.sql + single-quoted-identifier-part: + - match: \' + scope: punctuation.definition.identifier.begin.sql + set: inside-single-quoted-identifier-part + + inside-single-quoted-identifier-part: + # note: may contain foreign variable interpolation + - match: \' + scope: punctuation.definition.identifier.end.sql pop: 1 - backtick-quoted-identifier-part: - - match: (`)([^`]+)(`) - captures: - 1: punctuation.definition.identifier.begin.sql - 3: punctuation.definition.identifier.end.sql + simple-identifier-part: + - match: (?=\S) + set: inside-simple-identifier-part + + inside-simple-identifier-part: + # note: may contain foreign variable interpolation + - match: '{{simple_identifier_break}}' pop: 1 wildcard-identifiers: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 207abad710..5a8c88e917 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -7,7 +7,7 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') - simple_identifier: (?:(?:(?:##?)?|@)?\w+) # (one or two hashes OR an ampersand OR nothing) followed by a word + simple_identifier_break: (?![\w#@]) additional_reserved: \b(?i:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec|go|bulk|insert|on|when)\b enclosed_type_begin: (?:\[) enclosed_type_end: (?:\]) @@ -426,6 +426,10 @@ contexts: scope: keyword.other.tsql set: computed-column-definition + inside-user-type: + - meta_prepend: true + - include: variables + set: - meta_prepend: true - match: \b(?i:nocount|ansi_nulls|quoted_identifier)\b @@ -767,6 +771,9 @@ contexts: ###[ IDENTIFIERS ]############################################################# expect-cte-table-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [cte-table-name, single-identifier] @@ -776,6 +783,9 @@ contexts: - include: immediately-pop expect-cursor-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [cursor-name, single-identifier] @@ -785,6 +795,9 @@ contexts: - include: immediately-pop expect-filegroup-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [filegroup-name, single-identifier] @@ -798,6 +811,9 @@ contexts: push: [index-name, single-identifier] expect-index-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [index-name, single-identifier] @@ -807,6 +823,9 @@ contexts: - include: immediately-pop expect-label-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments - match: (?=\S) set: [label-name, single-identifier] @@ -831,10 +850,14 @@ contexts: - include: square-bracketed-identifier-part square-bracketed-identifier-part: - - match: (\[)([^]]+)(\]) - captures: - 1: punctuation.definition.identifier.begin.sql - 3: punctuation.definition.identifier.end.sql + - match: \[ + scope: punctuation.definition.identifier.begin.sql + set: inside-square-bracketed-identifier-part + + inside-square-bracketed-identifier-part: + # note: may contain foreign variable interpolation + - match: \] + scope: punctuation.definition.identifier.end.sql pop: 1 inside-simple-identifier-part: diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 5a71e85d90..cc0d94c122 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -708,7 +708,7 @@ into #temp -- ^^^^^ meta.table-name from @A A -- ^ keyword.other.dml --- ^^ meta.table-name +-- ^^ meta.table-name.sql variable.other.readwrite.sql -- ^ meta.table-alias-name inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN(B.C) DESC) = B.ID --^^^^^^^^ keyword.other.dml @@ -1400,6 +1400,13 @@ RETURN ) GO +CREATE FUNCTION foo() RETURNS @MyType +-- ^^^^^^^ support.type.sql variable.other.readwrite.sql + +CREATE FUNCTION foo() RETURNS My@TypeName +-- ^^ support.type.sql - variable +-- ^^^^^^^^^ support.type.sql variable.other.readwrite.sql + SELECT * FROM Department D CROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) AS func_call_results_table -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call From 472603b92b57fc98a50c67fa1dce0c15d9226d20 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 17 Jun 2022 21:32:57 +0200 Subject: [PATCH 110/250] Reorganize reserved word bailout --- SQL/SQL (basic).sublime-syntax | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 42cdfcb055..3957d9654d 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -553,12 +553,6 @@ contexts: set: - include: else-pop - pop-on-top-level-reserved-word: - - match: (?={{reserved}}|{{additional_reserved}}) - pop: 1 - - match: (?=\)) - pop: 1 - assignment-operator: - match: '=' scope: keyword.operator.assignment.sql @@ -843,3 +837,9 @@ contexts: immediately-pop: - match: '' pop: 1 + + pop-on-top-level-reserved-word: + - match: (?={{reserved}}|{{additional_reserved}}) + pop: 1 + - match: (?=\)) + pop: 1 From e73d6836d6bf09e23be7aa3b50bd4d5c2c5eb167 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 17 Jun 2022 21:35:10 +0200 Subject: [PATCH 111/250] Refactor table-name-or-subquery - move `join-on` and `set` upwards before `table-name-or-subquery` - reuse `group` context - a branch is like a push, so `table-valued-function-call` should have never popped `table-name-or-subquery` before. No idea why it worked anyway without a final `pop: 2`. `table-name-or-subquery` is now popped off stack before evaluating branches, so any normal `pop: 1` causes to continue with the next parent context of `table-name-or-subquery`. Note: The limitation of `push` only in branches has been fixed 409x dev builds, so `table-name-not-function-call` can safely be set away from. - remove `pop-on-top-level-reserved-word` from `maybe-table-alias` and leave handling fallback up to `single-identifer` ... It may require some more round trips for incomplete code scenarios, but saves some if code is complete and valid. --- SQL/SQL (basic).sublime-syntax | 73 ++++++++++++--------------- SQL/TSQL.sublime-syntax | 8 +-- SQL/tests/syntax/syntax_test_tsql.sql | 5 ++ 3 files changed, 40 insertions(+), 46 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 3957d9654d..83cb08ef0a 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -489,22 +489,22 @@ contexts: - join-on - table-name-or-subquery - subquery: - - match: \( - scope: punctuation.section.group.begin.sql - set: inside-subquery-allow-table-alias + join-on: + - match: (?i)\bon\b + scope: keyword.operator.join.sql + pop: 1 + - include: else-pop - inside-subquery-allow-table-alias: - - meta_scope: meta.group.sql - - match: \) - scope: punctuation.section.group.end.sql - set: maybe-table-alias - - include: main + set: + - include: else-pop table-name-or-subquery: - - include: pop-on-top-level-reserved-word - - include: subquery + - match: (?=\() + set: + - maybe-table-alias + - group - match: (?=\S) + pop: 1 # pop `table-name-or-subquery` before evaluating branches branch_point: table-or-table-function branch: - table-name-not-function-call @@ -513,23 +513,35 @@ contexts: table-name-not-function-call: - meta_include_prototype: false - match: '' - push: - - fail-if-function-call + set: + - table-name-fail-if-function-cal - table-name - single-identifier - fail-if-function-call: + table-name-fail-if-function-cal: - meta_include_prototype: false - - match: \( - fail: table-or-table-function # basically we are using branch points to avoid a complicated lookahead (which can be overridden by syntaxes extending this one) for an identifier followed by an open paren + - match: (?=\() + fail: table-or-table-function - match: (?=\S) set: maybe-table-alias - pop: 3 # one to pop 'fail-if-function-call', one to pop 'table-name-not-function-call' where we were forced to push to avoid the branch instantly succeeding, one because we are doing a set and ST gets confused without it?! it should set away from 'table-name-or-subquery' + + table-valued-function-call: + - meta_include_prototype: false + - match: '' + set: + - maybe-table-alias + - function-call-arguments + - table-valued-function-name + - single-identifier + + table-valued-function-name: + - meta_include_prototype: false + - meta_content_scope: meta.table-valued-function-name.sql + - include: immediately-pop maybe-table-alias: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql - - include: pop-on-top-level-reserved-word - match: (?=\S) set: - after-table-alias @@ -544,33 +556,10 @@ contexts: push: tablesample - include: else-pop - join-on: - - match: (?i)\bon\b - scope: keyword.operator.join.sql - pop: 1 - - include: else-pop - - set: - - include: else-pop - assignment-operator: - match: '=' scope: keyword.operator.assignment.sql - table-valued-function-call: - - meta_include_prototype: false - - match: '' - set: - - maybe-table-alias - - function-call-arguments - - table-valued-function-name - - single-identifier - - table-valued-function-name: - - meta_include_prototype: false - - meta_content_scope: meta.table-valued-function-name.sql - - include: immediately-pop - possible-operator: - include: operators - include: else-pop diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 5a8c88e917..2639842d9e 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -445,16 +445,16 @@ contexts: - include: operators - include: else-pop + table-name-fail-if-function-cal: + - meta_prepend: true + - include: table-hint-without-with + maybe-table-alias: - meta_prepend: true - include: with - match: (?=\b(?i:unpivot|pivot)\b) pop: 1 - fail-if-function-call: - - meta_prepend: true - - include: table-hint-without-with - after-table-alias: - meta_prepend: true - include: groups # column-alias-list diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index cc0d94c122..cd4179117b 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1486,6 +1486,11 @@ FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) -- ^^^^^^^^^^^^^^^^^^ meta.column-name ORDER BY p.BusinessEntityID DESC; +-- Test incomplete table alias assignment +JOIN table AS WHERE +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^ keyword.other.dml.sql + -------- USE AdventureWorks2012; From a6087e196d7fa323ec164b93f60746e75cbc88d5 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 19 Jun 2022 20:36:18 +0200 Subject: [PATCH 112/250] More expressive identifier patterns --- SQL/Cassandra.sublime-syntax | 2 +- SQL/SQL (basic).sublime-syntax | 4 ++-- SQL/TSQL.sublime-syntax | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index e069f20d2f..b2f23e3a2b 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -26,7 +26,7 @@ contexts: - meta_append: true - match: \h{8}(?:-\h{4}){3}-\h{12} scope: constant.numeric.uuid.cql - - match: (:)\w+ + - match: (:){{simple_identifier}} scope: variable.other.constant.cql captures: 1: punctuation.definition.variable.cql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 83cb08ef0a..567ce82333 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -192,7 +192,7 @@ contexts: push: inside-collate-expression inside-collate-expression: - - match: \w+ + - match: '{{simple_identifier}}' scope: support.constant.sql pop: 1 - include: else-pop @@ -214,7 +214,7 @@ contexts: scope: support.function.scalar.sql user-defined-function-calls: - - match: \b\w+(?=\s*\() + - match: \b{{simple_identifier}}(?=\s*\() scope: support.function.sql push: function-call-arguments diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 2639842d9e..9d8c8f0a7a 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -410,7 +410,7 @@ contexts: - include: top inside-declaration: - - match: \w+(?=\s+(?i:cursor)\b) + - match: '{{simple_identifier}}(?=\s+(?i:cursor)\b)' scope: meta.cursor-name.sql pop: 1 - match: (@){{simple_identifier}} @@ -535,7 +535,7 @@ contexts: 1: keyword.other.tsql 2: keyword.operator.assignment.tsql push: expect-table-name - - match: \w+ + - match: '{{simple_identifier}}' scope: constant.language.with.tsql - match: ',' scope: punctuation.separator.sequence.tsql From 7f1185933a38e440a1a12a4b9f879458ab09d2b6 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Mon, 20 Jun 2022 20:43:05 +0200 Subject: [PATCH 113/250] Simplify cte column list contexts --- SQL/TSQL.sublime-syntax | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 9d8c8f0a7a..efc528cf25 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -477,7 +477,8 @@ contexts: - match: (?i)\bwith\b(?=\s*(?:\[\w+\]|\w+)\s*\() scope: keyword.other.dml.sql push: - - cte-column-list-begin + - cte-as + - cte-column-list - expect-cte-table-name - match: (?i)\bwith\b #(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) scope: keyword.other.dml.sql @@ -598,14 +599,9 @@ contexts: - include: expressions - include: else-pop - cte-column-list-begin: - - match: (?=\() - scope: punctuation.section.group.begin.tsql - set: - - cte-as - - ddl-table-creation-columns - - match: (?=\S) - set: cte-as + cte-column-list: + - include: ddl-table-creation-columns + - include: else-pop cte-as: - match: \b(?i:as)\b @@ -613,8 +609,8 @@ contexts: - include: pop-on-top-level-reserved-word - match: ',' scope: punctuation.separator.sequence.cte.tsql - set: - - cte-column-list-begin + push: + - cte-column-list - expect-cte-table-name - include: expressions From b0a5c051cad068b9c2ff3f57145f0e6226fcb426 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Thu, 23 Jun 2022 19:42:10 +0200 Subject: [PATCH 114/250] Reorganize operators --- SQL/Cassandra.sublime-syntax | 2 + SQL/MySQL.sublime-syntax | 12 +++-- SQL/PostgreSQL.sublime-syntax | 54 +++++++++++----------- SQL/SQL (basic).sublime-syntax | 50 ++++++++++++-------- SQL/TSQL.sublime-syntax | 30 ++++++------ SQL/tests/syntax/syntax_test_postgres.psql | 1 - 6 files changed, 81 insertions(+), 68 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index b2f23e3a2b..fa21bf978c 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -182,6 +182,8 @@ contexts: pop: 1 - include: else-pop +###[ OPERATORS ]############################################################### + logical-operators: - meta_append: true - match: \b(?i:contains(?:\s+key)?)\b diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 9f30aed988..41b18b530c 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -93,11 +93,6 @@ contexts: - match: \\/ scope: constant.character.escape.slash.sql - operators: - - meta_append: true - - match: \|\| - scope: keyword.operator.concatenation.sql - after-type: - meta_prepend: true - match: \b(?i:unsigned)\b @@ -201,3 +196,10 @@ contexts: scope: keyword.other.mysql pop: 1 - include: else-pop + +###[ OPERATORS ]############################################################### + + operators: + - meta_append: true + - match: \|\| + scope: keyword.operator.concatenation.sql diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 197043fe8a..02abca2ad5 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -63,39 +63,11 @@ contexts: - match: \b(?i:check)\b scope: keyword.other.psql - operators: - - meta_prepend: true - - match: '::' - scope: keyword.operator.cast.psql - push: expect-type - - include: regex-operators - - regex-operators: - # https://www.postgresql.org/docs/7.4/functions-matching.html#FUNCTIONS-POSIX-REGEXP - - match: '!?~\*?' - scope: keyword.operator.comparison.psql - push: expect-regex - inside-ddl-table-creation-columns: - meta_prepend: true - match: \b(?i:unique)\b scope: keyword.other.psql - expect-regex: - - match: \' - scope: punctuation.definition.string.begin.sql - embed: single-quoted-regex - embed_scope: source.regexp - escape: \' - escape_captures: - 0: meta.string.regexp.psql punctuation.definition.string.end.sql - pop: 1 - - include: else-pop - - single-quoted-regex: - - meta_scope: meta.string.regexp.psql - - include: scope:source.regexp - statements: - meta_prepend: true - include: declarations @@ -123,3 +95,29 @@ contexts: - match: \b(?i:schema)\b scope: storage.modifier.psql push: expect-schema-name + +###[ OPERATORS ]############################################################### + + operators: + - meta_prepend: true + - match: '::' + scope: keyword.operator.cast.psql + push: expect-type + - include: regex-operators + + regex-operators: + # https://www.postgresql.org/docs/7.4/functions-matching.html#FUNCTIONS-POSIX-REGEXP + - match: '!?~\*?' + scope: keyword.operator.comparison.psql + push: expect-regexp + + expect-regexp: + - match: \' + scope: meta.string.regexp.psql punctuation.definition.string.begin.sql + embed: scope:source.regexp + embed_scope: meta.string.regexp.psql + escape: \' + escape_captures: + 0: meta.string.regexp.psql punctuation.definition.string.end.sql + pop: 1 + - include: else-pop diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 567ce82333..628576ff5b 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -93,17 +93,6 @@ contexts: scope: keyword.control.flow.sql - include: logical-operators - logical-operators: - - match: \b(?i:and|or|having|exists|between|in|not|is)\b - scope: keyword.operator.logical.sql - - operators: - - match: '<=>|[!<>]?=|<>|<|>' - scope: keyword.operator.comparison.sql - - match: '[-+/*]' - scope: keyword.operator.arithmetic.sql - - include: logical-operators - expect-type: - meta_include_prototype: false - include: comments @@ -556,14 +545,6 @@ contexts: push: tablesample - include: else-pop - assignment-operator: - - match: '=' - scope: keyword.operator.assignment.sql - - possible-operator: - - include: operators - - include: else-pop - tablesample: - meta_content_scope: meta.group.tablesample.sql - match: \b(?i:rows|percent)\b @@ -609,7 +590,7 @@ contexts: expect-column-names: - match: (?=\S) - push: [possible-operator, column-name, single-identifier] + push: [maybe-operator, column-name, single-identifier] expect-column-name: # prevent prototypes from inheriting syntaxes @@ -817,6 +798,35 @@ contexts: - match: \* scope: variable.language.wildcard.asterisk.sql +###[ OPERATORS ]############################################################### + + maybe-operator: + - match: '<=>|[!<>]?=|<>|<|>' + scope: keyword.operator.comparison.sql + pop: 1 + - match: '[-+/*]' + scope: keyword.operator.arithmetic.sql + pop: 1 + - match: \b(?i:and|or|having|exists|between|in|not|is)\b + scope: keyword.operator.logical.sql + pop: 1 + - include: else-pop + + operators: + - match: '<=>|[!<>]?=|<>|<|>' + scope: keyword.operator.comparison.sql + - match: '[-+/*]' + scope: keyword.operator.arithmetic.sql + - include: logical-operators + + assignment-operators: + - match: '=' + scope: keyword.operator.assignment.sql + + logical-operators: + - match: \b(?i:and|or|having|exists|between|in|not|is)\b + scope: keyword.operator.logical.sql + ###[ PROTOTYPES ]############################################################## else-pop: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index efc528cf25..b7711f5753 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -36,19 +36,6 @@ contexts: scope: punctuation.definition.string.begin.sql push: inside-single-quoted-string - operators: - - meta_append: true - - match: \b(?i:like)\b - scope: keyword.operator.logical.sql - branch_point: like-strings-branch - branch: - - like-string-not-followed-by-escape - - like-string-followed-by-escape-slash - - like-string-followed-by-escape-caret - - like-string-followed-by-unknown-escape - - match: '%' - scope: keyword.operator.arithmetic.tsql - variables: - match: (@)\w+ scope: variable.other.readwrite.sql @@ -594,8 +581,8 @@ contexts: set: inside-openrowset-call exec: - - include: assignment-operator - include: pop-on-top-level-reserved-word + - include: assignment-operators - include: expressions - include: else-pop @@ -859,3 +846,18 @@ contexts: inside-simple-identifier-part: - meta_prepend: true - include: variables + +###[ OPERATORS ]############################################################### + + operators: + - meta_append: true + - match: \b(?i:like)\b + scope: keyword.operator.logical.sql + branch_point: like-strings-branch + branch: + - like-string-not-followed-by-escape + - like-string-followed-by-escape-slash + - like-string-followed-by-escape-caret + - like-string-followed-by-unknown-escape + - match: '%' + scope: keyword.operator.arithmetic.tsql diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index ff436caf78..f6c9f980bc 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -220,7 +220,6 @@ CREATE TABLE example_table ( -- ^^^^^^^^^^ meta.column-name -- ^^ keyword.operator.comparison -- ^^^^^^^^^^ meta.string.regexp --- ^^^^^^^^ source.regexp -- ^ punctuation.definition.string.begin -- ^ punctuation.definition.string.end -- ^ punctuation.section.group.end - meta.string From f6f10ef801dd4a367023b929645f07e01460ba56 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Thu, 23 Jun 2022 19:56:23 +0200 Subject: [PATCH 115/250] Reorganize literals (constants, numbers, strings, variables) --- SQL/Cassandra.sublime-syntax | 23 +++++-- SQL/MySQL.sublime-syntax | 118 ++++++++++++++++++--------------- SQL/SQL (basic).sublime-syntax | 78 +++++++++++----------- SQL/TSQL.sublime-syntax | 68 ++++++++++--------- 4 files changed, 159 insertions(+), 128 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index fa21bf978c..2a91013d62 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -24,12 +24,6 @@ variables: contexts: expressions: - meta_append: true - - match: \h{8}(?:-\h{4}){3}-\h{12} - scope: constant.numeric.uuid.cql - - match: (:){{simple_identifier}} - scope: variable.other.constant.cql - captures: - 1: punctuation.definition.variable.cql - match: \b(?i:limit)\b scope: keyword.other.dml.cql - match: \{ @@ -182,6 +176,23 @@ contexts: pop: 1 - include: else-pop +###[ LITERALS ]################################################################ + + literals-and-variables: + - meta_prepend: true + - include: variables + + numbers: + - meta_prepend: true + - match: \h{8}(?:-\h{4}){3}-\h{12} + scope: constant.numeric.uuid.cql + + variables: + - match: (:){{simple_identifier}} + scope: variable.other.constant.cql + captures: + 1: punctuation.definition.variable.cql + ###[ OPERATORS ]############################################################### logical-operators: diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 41b18b530c..bc62640e20 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -40,59 +40,6 @@ contexts: scope: punctuation.definition.comment.sql push: inside-double-dash-comment - strings: - - meta_append: true - - match: '"' - scope: punctuation.definition.string.begin.sql - push: inside-double-quoted-string - - include: begin-interpolation - - inside-double-quoted-string: - - meta_include_prototype: false - - meta_scope: meta.string.mysql string.quoted.double.sql - - match: '""' - scope: constant.character.escape.sql - - match: '"' - scope: punctuation.definition.string.end.sql - pop: 1 - - include: string-interpolation - - begin-interpolation: - - match: '%\{' - scope: punctuation.definition.string.begin.sql - push: inside-interpolation - - inside-interpolation: - - meta_include_prototype: false - - meta_scope: string.other.quoted.brackets.sql - - match: '\}' - scope: punctuation.definition.string.end.sql - pop: 1 - - include: string-interpolation - - string-interpolation: - - meta_include_prototype: false - - match: '(#\{)([^\}]*)(\})' - scope: string.interpolated.sql - captures: - 1: punctuation.definition.string.begin.sql - 3: punctuation.definition.string.end.sql - - regexps: - - match: /(?=\S.*/) - scope: punctuation.definition.string.begin.sql - push: inside-regexp - - inside-regexp: - - meta_include_prototype: false - - meta_scope: string.regexp.sql - - match: / - scope: punctuation.definition.string.end.sql - pop: 1 - - include: string-interpolation - - match: \\/ - scope: constant.character.escape.slash.sql - after-type: - meta_prepend: true - match: \b(?i:unsigned)\b @@ -197,9 +144,74 @@ contexts: pop: 1 - include: else-pop +###[ LITERALS ]################################################################ + + regexps: + - match: /(?=\S.*/) + scope: punctuation.definition.string.begin.sql + push: inside-regexp + + inside-regexp: + - meta_include_prototype: false + - meta_scope: meta.string.regexp.sql string.regexp.sql + - match: / + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-interpolations + - match: \\/ + scope: constant.character.escape.slash.sql + + strings: + - meta_append: true + - include: double-quoted-strings + - include: interpolations + + double-quoted-strings: + - match: \" + scope: punctuation.definition.string.begin.sql + push: inside-double-quoted-string + + inside-double-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.quoted.double.sql + - match: \"\" + scope: constant.character.escape.sql + - match: \" + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-interpolations + + interpolations: + - match: \%\{ + scope: punctuation.definition.string.begin.sql + push: inside-interpolation + + inside-interpolation: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.other.quoted.brackets.sql + - match: \} + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-interpolations + + string-interpolations: + - meta_include_prototype: false + - match: (#\{)([^\}]*)(\}) + scope: meta.interpolation.sql + captures: + 1: punctuation.section.interpolation.begin.sql + 3: punctuation.section.interpolation.end.sql + push: clear-scope-imediately-pop + ###[ OPERATORS ]############################################################### operators: - meta_append: true - match: \|\| scope: keyword.operator.concatenation.sql + +###[ PROTOTYPES ]############################################################## + + clear-scope-imediately-pop: + - clear_scopes: 1 + - include: immediately-pop diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 628576ff5b..45676fc09b 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -246,44 +246,6 @@ contexts: pop: 1 - include: main - literals-and-variables: - - include: constants - - include: numbers - - include: strings - - constants: - - match: \b(?i:true|false)\b - scope: constant.language.boolean.sql - - match: \b(?i:null)\b - scope: constant.language.null.sql - - numbers: - - match: \b\d+(\.)\d+\b - scope: meta.number.float.decimal.sql constant.numeric.value.sql - captures: - 1: punctuation.separator.decimal.sql - - match: \b\d+\b - scope: meta.number.integer.decimal.sql constant.numeric.value.sql - - strings: - - match: \' - scope: punctuation.definition.string.begin.sql - push: inside-single-quoted-string - - inside-single-quoted-string: - - meta_include_prototype: false - - meta_scope: meta.string.sql string.quoted.single.sql - - match: \'\' - scope: constant.character.escape.sql - - match: \' - scope: punctuation.definition.string.end.sql - pop: 1 - - include: string-escapes - - string-escapes: - - match: '{{string_escape}}' - scope: constant.character.escape.sql - statements: - include: ddl-statements - include: dml-statements @@ -798,6 +760,46 @@ contexts: - match: \* scope: variable.language.wildcard.asterisk.sql +###[ LITERALS ]################################################################ + + literals-and-variables: + - include: constants + - include: numbers + - include: strings + + constants: + - match: \b(?i:true|false)\b + scope: constant.language.boolean.sql + - match: \b(?i:null)\b + scope: constant.language.null.sql + + numbers: + - match: \b\d+(\.)\d+\b + scope: meta.number.float.decimal.sql constant.numeric.value.sql + captures: + 1: punctuation.separator.decimal.sql + - match: \b\d+\b + scope: meta.number.integer.decimal.sql constant.numeric.value.sql + + strings: + - match: \' + scope: punctuation.definition.string.begin.sql + push: inside-single-quoted-string + + inside-single-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.quoted.single.sql + - match: \'\' + scope: constant.character.escape.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-escapes + + string-escapes: + - match: '{{string_escape}}' + scope: constant.character.escape.sql + ###[ OPERATORS ]############################################################### maybe-operator: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index b7711f5753..05e50eb3c3 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -30,25 +30,6 @@ variables: )\b contexts: - strings: - - meta_append: true - - match: N' - scope: punctuation.definition.string.begin.sql - push: inside-single-quoted-string - - variables: - - match: (@)\w+ - scope: variable.other.readwrite.sql - captures: - 1: punctuation.definition.variable.sql - - match: |- - (?xi)(@@) - (?:cursor_rows|connections|cpu_busy|datefirst|dbts|error|fetch_status|identity|idle|io_busy|langid|language|lock_timeout| - max_connections|max_precision|nestlevel|options|packet_errors|pack_received|pack_sent|procid|remserver|rowcount| - servername|servicename|spid|textsize|timeticks|total_errors|total_read|total_write|trancount|version)\b - scope: support.variable.global.sql - captures: - 1: punctuation.definition.variable.sql like-string-not-followed-by-escape: - match: \' @@ -298,18 +279,6 @@ contexts: scope: punctuation.separator.argument.sql - include: expressions-or-column-name - literals-and-variables: - - meta_prepend: true - - include: variables - - numbers: - - meta_prepend: true - - match: (0x)(\h+) - scope: meta.number.integer.hexadecimal.tsql - captures: - 1: constant.numeric.base.tsql - 2: constant.numeric.value.tsql - dml-statements: - meta_append: true - match: \b(?i:bulk\s+insert)\b @@ -847,6 +816,43 @@ contexts: - meta_prepend: true - include: variables +###[ LITERALS ]################################################################ + + literals-and-variables: + - meta_prepend: true + - include: variables + + numbers: + - meta_prepend: true + - match: (0x)(\h+) + scope: meta.number.integer.hexadecimal.tsql + captures: + 1: constant.numeric.base.tsql + 2: constant.numeric.value.tsql + + strings: + - meta_append: true + - match: N' + scope: punctuation.definition.string.begin.sql + push: inside-single-quoted-string + + variables: + - match: (@){{simple_identifier}} + scope: variable.other.readwrite.sql + captures: + 1: punctuation.definition.variable.sql + - match: |- + (?xi)(@@) + (?: cursor_rows | connections | cpu_busy | datefirst | dbts | error + | fetch_status | identity | idle | io_busy | langid | language + | lock_timeout | max_connections | max_precision | nestlevel | options + | packet_errors | pack_received | pack_sent | procid | remserver + | rowcount | servername | servicename | spid | textsize | timeticks + | total_errors | total_read | total_write | trancount | version )\b + scope: support.variable.global.sql + captures: + 1: punctuation.definition.variable.sql + ###[ OPERATORS ]############################################################### operators: From 23708c7b3a9adde54b2dd44242d78858ed2f96f2 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Thu, 23 Jun 2022 20:16:50 +0200 Subject: [PATCH 116/250] Reorganize LIKE expressions It doesn't look like `LIKE "something"` is supported within `SET something` statements. Thus a dedicated like-expressions context is created to organize them. --- SQL/TSQL.sublime-syntax | 249 +++++++++++++++++++++------------------- 1 file changed, 128 insertions(+), 121 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 05e50eb3c3..eabc27a010 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -31,119 +31,6 @@ variables: contexts: - like-string-not-followed-by-escape: - - match: \' - scope: punctuation.definition.string.begin.sql - set: - - like-escape-fail - - inside-like-single-quoted-string - - include: else-pop - - like-string-followed-by-escape-slash: - - match: \' - scope: punctuation.definition.string.begin.sql - set: - - like-escape-character-slash - - like-escape-pop - - inside-like-single-quoted-string-slash-escape - - include: else-pop - - like-string-followed-by-escape-caret: - - match: \' - scope: punctuation.definition.string.begin.sql - set: - - like-escape-character-caret - - like-escape-pop - - inside-like-single-quoted-string-caret-escape - - include: else-pop - - like-string-followed-by-unknown-escape: - - match: \' - scope: punctuation.definition.string.begin.sql - set: - - like-escape-character-any - - like-escape-pop - - inside-like-single-quoted-string - - include: else-pop - - inside-like-single-quoted-string-slash-escape: - - meta_include_prototype: false - - meta_scope: meta.string.like.sql string.quoted.single.sql - - match: \\. - scope: constant.character.escape.sql - - include: inside-like-single-quoted-string - - inside-like-single-quoted-string-caret-escape: - - meta_include_prototype: false - - meta_scope: meta.string.like.sql string.quoted.single.sql - - match: \^. - scope: constant.character.escape.sql - - include: inside-like-single-quoted-string - - inside-like-single-quoted-string: - - meta_include_prototype: false - - meta_scope: meta.string.like.sql string.quoted.single.sql - - match: \' - scope: punctuation.definition.string.end.sql - pop: 1 - - match: |- - (?x) - (\[)(\^)? - (?:.|[^]'-]+?) - (?:(-)[^]'-]*)? - (\]) - scope: meta.set.like.sql - captures: - 1: keyword.control.set.begin.sql - 2: keyword.control.set.negation.sql - 3: constant.other.range.sql - 4: keyword.control.set.end.sql - - match: '[%_]' - scope: keyword.operator.wildcard.sql - - like-escape-fail: - - match: \b(?i:escape)\b - fail: like-strings-branch - - include: else-pop - - like-escape-pop: - - match: \b(?i:escape)\b - scope: keyword.operator.word.sql - pop: 1 - - include: else-pop - - like-escape-character-any: - - match: (\')([^'])(\') - scope: meta.string.escape.sql string.quoted.single.sql - captures: - 1: punctuation.definition.string.begin.sql - 2: constant.character.escape.sql - 3: punctuation.definition.string.end.sql - pop: 1 - - include: else-pop - - like-escape-character-caret: - - match: (\')(\^)(\') - scope: meta.string.escape.sql string.quoted.single.sql - captures: - 1: punctuation.definition.string.begin.sql - 2: constant.character.escape.sql - 3: punctuation.definition.string.end.sql - pop: 1 - - match: (?=\S) - fail: like-strings-branch - - like-escape-character-slash: - - match: (\')(\\)(\') - scope: meta.string.escape.sql string.quoted.single.sql - captures: - 1: punctuation.definition.string.begin.sql - 2: constant.character.escape.sql - 3: punctuation.definition.string.end.sql - pop: 1 - - match: (?=\S) - fail: like-strings-branch - built-in-type: - meta_prepend: true - match: |- @@ -223,6 +110,7 @@ contexts: expressions: - meta_prepend: true - include: with + - include: like-expressions - match: \b(?i:output)\b scope: storage.modifier.output.tsql - match: \b(?i:over|partition\s+by)\b @@ -720,6 +608,133 @@ contexts: - include: ddl-table-creation-columns - include: expect-index-names +###[ LIKE EXPRESSIONS ]######################################################## + + like-expressions: + - match: \b(?i:like)\b + scope: keyword.operator.logical.sql + branch_point: like-expressions + branch: + - like-string-not-followed-by-escape + - like-string-followed-by-escape-slash + - like-string-followed-by-escape-caret + - like-string-followed-by-unknown-escape + + like-string-not-followed-by-escape: + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-fail + - inside-like-single-quoted-string + - include: else-pop + + like-string-followed-by-escape-slash: + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-slash + - like-escape + - inside-like-single-quoted-string-slash-escape + - include: else-pop + + like-string-followed-by-escape-caret: + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-caret + - like-escape + - inside-like-single-quoted-string-caret-escape + - include: else-pop + + like-string-followed-by-unknown-escape: + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-any + - like-escape + - inside-like-single-quoted-string + - include: else-pop + + inside-like-single-quoted-string-slash-escape: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \\. + scope: constant.character.escape.sql + - include: inside-like-single-quoted-string + + inside-like-single-quoted-string-caret-escape: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \^. + scope: constant.character.escape.sql + - include: inside-like-single-quoted-string + + inside-like-single-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - match: |- + (?x) + (\[)(\^)? + (?:.|[^]'-]+?) + (?:(-)[^]'-]*)? + (\]) + scope: meta.set.like.sql + captures: + 1: keyword.control.set.begin.sql + 2: keyword.control.set.negation.sql + 3: constant.other.range.sql + 4: keyword.control.set.end.sql + - match: '[%_]' + scope: keyword.operator.wildcard.sql + + like-else-fail: + - match: (?=\S) + fail: like-expressions + + like-escape-fail: + - match: \b(?i:escape)\b + fail: like-expressions + - include: else-pop + + like-escape: + - match: \b(?i:escape)\b + scope: keyword.operator.word.sql + pop: 1 + - include: else-pop + + like-escape-character-any: + - match: (\')([^'])(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: else-pop + + like-escape-character-caret: + - match: (\')(\^)(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: like-else-fail + + like-escape-character-slash: + - match: (\')(\\)(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: like-else-fail + ###[ IDENTIFIERS ]############################################################# expect-cte-table-name: @@ -857,13 +872,5 @@ contexts: operators: - meta_append: true - - match: \b(?i:like)\b - scope: keyword.operator.logical.sql - branch_point: like-strings-branch - branch: - - like-string-not-followed-by-escape - - like-string-followed-by-escape-slash - - like-string-followed-by-escape-caret - - like-string-followed-by-unknown-escape - match: '%' scope: keyword.operator.arithmetic.tsql From bc14941b8c41fe096eb18e252dfc957601e641ce Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 26 Jun 2022 17:18:49 +0200 Subject: [PATCH 117/250] Reorganize types --- SQL/Cassandra.sublime-syntax | 32 ++++----- SQL/MySQL.sublime-syntax | 20 +++--- SQL/SQL (basic).sublime-syntax | 70 ++++++++++---------- SQL/TSQL.sublime-syntax | 116 +++++++++++++++++---------------- 4 files changed, 123 insertions(+), 115 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 2a91013d62..7806015a02 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -68,21 +68,6 @@ contexts: - match: \b(?i:source)\b scope: keyword.other.cql - built-in-type: - - meta_prepend: true - - match: \b(?i:set|frozen|map|tuple)(<) - scope: storage.type.cql - captures: - 1: punctuation.definition.generic.begin.cql - set: - - end-generic-type - - built-in-type - - end-generic-type: - - match: \> - scope: storage.type.cql punctuation.definition.generic.end.cql - pop: 1 - inside-dict-or-set: - match: \} scope: punctuation.section.braces.end.cql @@ -176,6 +161,23 @@ contexts: pop: 1 - include: else-pop +###[ TYPES ]################################################################### + + built-in-type: + - meta_prepend: true + - match: \b(?i:set|frozen|map|tuple)(<) + scope: storage.type.cql + captures: + 1: punctuation.definition.generic.begin.cql + set: + - end-generic-type + - built-in-type + + end-generic-type: + - match: \> + scope: storage.type.cql punctuation.definition.generic.end.cql + pop: 1 + ###[ LITERALS ]################################################################ literals-and-variables: diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index bc62640e20..2d919b7c98 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -40,15 +40,6 @@ contexts: scope: punctuation.definition.comment.sql push: inside-double-dash-comment - after-type: - - meta_prepend: true - - match: \b(?i:unsigned)\b - scope: storage.modifier.mysql - pop: 1 - - match: \b(?i:with(?:out)?\s+time\s+zone)\b - scope: storage.type.sql - pop: 1 - inside-number-sign-comment: - meta_include_prototype: false - meta_scope: comment.line.number-sign.sql @@ -144,6 +135,17 @@ contexts: pop: 1 - include: else-pop +###[ TYPES ]################################################################### + + after-type: + - meta_prepend: true + - match: \b(?i:unsigned)\b + scope: storage.modifier.mysql + pop: 1 + - match: \b(?i:with(?:out)?\s+time\s+zone)\b + scope: storage.type.sql + pop: 1 + ###[ LITERALS ]################################################################ regexps: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 45676fc09b..ea97c80f33 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -93,40 +93,6 @@ contexts: scope: keyword.control.flow.sql - include: logical-operators - expect-type: - - meta_include_prototype: false - - include: comments - - include: built-in-type - - include: expect-user-type - - built-in-type: - - match: '{{simple_types}}' - scope: storage.type.sql - pop: 1 - - match: |- - (?xi) - {{types_with_optional_number}} - (?:\s*\((\d+)(?:\s*(,)\s*(\d+))?\))? - scope: storage.type.sql - captures: - 1: constant.numeric.sql - 2: punctuation.separator.sequence.sql - 3: constant.numeric.sql - pop: 1 - - expect-user-type: - - match: (?=\S) - set: inside-user-type - - inside-user-type: - # note: may contain foreign variable interpolation - - meta_scope: support.type.sql - - match: '{{simple_identifier_break}}' - pop: 1 - - after-type: - - include: else-pop - expressions-or-column-name: - include: wildcard-identifiers - include: expressions @@ -548,6 +514,42 @@ contexts: set: inside-ddl-table-creation-columns - include: else-pop +###[ TYPES ]################################################################### + + expect-type: + - meta_include_prototype: false + - include: comments + - include: built-in-type + - include: expect-user-type + + built-in-type: + - match: '{{simple_types}}' + scope: storage.type.sql + pop: 1 + - match: |- + (?xi) + {{types_with_optional_number}} + (?:\s*\((\d+)(?:\s*(,)\s*(\d+))?\))? + scope: storage.type.sql + captures: + 1: constant.numeric.sql + 2: punctuation.separator.sequence.sql + 3: constant.numeric.sql + pop: 1 + + expect-user-type: + - match: (?=\S) + set: inside-user-type + + inside-user-type: + # note: may contain foreign variable interpolation + - meta_scope: support.type.sql + - match: '{{simple_identifier_break}}' + pop: 1 + + after-type: + - include: else-pop + ###[ IDENTIFIERS ]############################################################# expect-column-names: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index eabc27a010..d906e75a67 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -31,36 +31,6 @@ variables: contexts: - built-in-type: - - meta_prepend: true - - match: |- - (?xi) - {{enclosed_type_begin}} - {{simple_types}} - {{enclosed_type_end}} - scope: storage.type.sql - pop: 1 - - match: |- - (?xi) - {{enclosed_type_begin}} - {{types_with_optional_number}} - {{enclosed_type_end}} - (?:\s*\(\s*(?:(\d+)|(MAX))\s*(?:(,)\s*(\d+))?\))? - scope: storage.type.sql - captures: - 1: constant.numeric.sql - 2: constant.language.max.sql - 3: punctuation.separator.sequence.sql - 4: constant.numeric.sql - pop: 1 - - match: |- - (?xi) - (?:{{enclosed_type_begin}}|\b) - table - (?:{{enclosed_type_end}}|\b) - scope: storage.type.sql - pop: 1 - statements: - meta_append: true - include: declarations @@ -264,16 +234,6 @@ contexts: set: expect-type - include: else-pop - expect-type: - - meta_prepend: true - - match: \b(?i:as)\b - scope: keyword.other.tsql - set: computed-column-definition - - inside-user-type: - - meta_prepend: true - - include: variables - set: - meta_prepend: true - match: \b(?i:nocount|ansi_nulls|quoted_identifier)\b @@ -408,15 +368,6 @@ contexts: set: inside-with-group - include: else-pop - after-type: - - meta_prepend: true - - match: \b(?i:GENERATED\s+ALWAYS\s+AS\s+ROW\s+(?:START|END)(?:\s+HIDDEN)?)\b - scope: keyword.other.tsql - - match: \b(?i:ENCRYPTED\s+WITH)\b - scope: storage.modifier.tsql - set: with-paren-or-pop - - include: collate-expressions - joins: - meta_append: true - match: (?i)\b(?:(?:cross|outer)\s+)?apply\b @@ -516,14 +467,6 @@ contexts: - include: with - include: else-pop - computed-column-definition: - - meta_content_scope: meta.computed-column-definition.tsql - - match: (?=,) - pop: 1 - - match: (?=\b(?i:constraint)\b) - pop: 1 - - include: expressions-or-column-name - raiserror-args: - match: \b(?i:with)\b scope: keyword.other.tsql @@ -735,6 +678,65 @@ contexts: pop: 1 - include: like-else-fail +###[ TYPES ]################################################################### + + expect-type: + - meta_prepend: true + - match: \b(?i:as)\b + scope: keyword.other.tsql + set: computed-column-definition + + computed-column-definition: + - meta_content_scope: meta.computed-column-definition.tsql + - match: (?=,) + pop: 1 + - match: (?=\b(?i:constraint)\b) + pop: 1 + - include: expressions-or-column-name + + built-in-type: + - meta_prepend: true + - match: |- + (?xi) + {{enclosed_type_begin}} + {{simple_types}} + {{enclosed_type_end}} + scope: storage.type.sql + pop: 1 + - match: |- + (?xi) + {{enclosed_type_begin}} + {{types_with_optional_number}} + {{enclosed_type_end}} + (?:\s*\(\s*(?:(\d+)|(MAX))\s*(?:(,)\s*(\d+))?\))? + scope: storage.type.sql + captures: + 1: constant.numeric.sql + 2: constant.language.max.sql + 3: punctuation.separator.sequence.sql + 4: constant.numeric.sql + pop: 1 + - match: |- + (?xi) + (?:{{enclosed_type_begin}}|\b) + table + (?:{{enclosed_type_end}}|\b) + scope: storage.type.sql + pop: 1 + + inside-user-type: + - meta_prepend: true + - include: variables + + after-type: + - meta_prepend: true + - match: \b(?i:GENERATED\s+ALWAYS\s+AS\s+ROW\s+(?:START|END)(?:\s+HIDDEN)?)\b + scope: keyword.other.tsql + - match: \b(?i:ENCRYPTED\s+WITH)\b + scope: storage.modifier.tsql + set: with-paren-or-pop + - include: collate-expressions + ###[ IDENTIFIERS ]############################################################# expect-cte-table-name: From 1471890f3bf8f239666559570d884391e6bcf35e Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 26 Jun 2022 17:34:16 +0200 Subject: [PATCH 118/250] Add expressions separator --- SQL/Cassandra.sublime-syntax | 3 +++ SQL/MySQL.sublime-syntax | 16 +++++++++------- SQL/PostgreSQL.sublime-syntax | 4 ++++ SQL/SQL (basic).sublime-syntax | 2 ++ SQL/TSQL.sublime-syntax | 2 ++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 7806015a02..323fca371f 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -22,6 +22,9 @@ variables: )\b contexts: + +###[ EXPRESSIONS ]############################################################# + expressions: - meta_append: true - match: \b(?i:limit)\b diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 2d919b7c98..3e3173205c 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -46,13 +46,6 @@ contexts: - match: \n pop: 1 - expressions: - - meta_prepend: true - - match: \b(?i:CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b - scope: support.function.string.sql - - match: \b(?i:using)\b - scope: keyword.other.mysql - statements: - meta_append: true - match: \b(?i:begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b @@ -135,6 +128,15 @@ contexts: pop: 1 - include: else-pop +###[ EXPRESSIONS ]############################################################# + + expressions: + - meta_prepend: true + - match: \b(?i:CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b + scope: support.function.string.sql + - match: \b(?i:using)\b + scope: keyword.other.mysql + ###[ TYPES ]################################################################### after-type: diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 02abca2ad5..624e94edd8 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -35,6 +35,10 @@ variables: ) contexts: + + +###[ EXPRESSIONS ]############################################################# + expressions: - meta_prepend: true - match: \b(?i:ARRAY)\b diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index ea97c80f33..b9a18c915e 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -93,6 +93,8 @@ contexts: scope: keyword.control.flow.sql - include: logical-operators +###[ EXPRESSIONS ]############################################################# + expressions-or-column-name: - include: wildcard-identifiers - include: expressions diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index d906e75a67..c6d5022fc0 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -77,6 +77,8 @@ contexts: - match: (?i)\b(?:begin|commit|rollback|save)\s+tran(saction)?\b scope: keyword.context.tsql +###[ EXPRESSIONS ]############################################################# + expressions: - meta_prepend: true - include: with From bc056c9af19c4d469e5c9bfba3e2b2b8d7b04148 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 26 Jun 2022 17:37:35 +0200 Subject: [PATCH 119/250] Reorganize statement contexts Moves statement related contexts around --- SQL/Cassandra.sublime-syntax | 170 +++++++------- SQL/MySQL.sublime-syntax | 98 ++++---- SQL/PostgreSQL.sublime-syntax | 80 ++++--- SQL/SQL (basic).sublime-syntax | 379 ++++++++++++++++--------------- SQL/TSQL.sublime-syntax | 393 +++++++++++++++++---------------- 5 files changed, 578 insertions(+), 542 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 323fca371f..9eb391434f 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -23,76 +23,7 @@ variables: contexts: -###[ EXPRESSIONS ]############################################################# - - expressions: - - meta_append: true - - match: \b(?i:limit)\b - scope: keyword.other.dml.cql - - match: \{ - scope: punctuation.section.braces.begin.cql - push: inside-dict-or-set - - match: \[ - scope: punctuation.section.brackets.begin.cql - push: inside-array - - match: \b((?i:with))\s+(\w+)? - captures: - 1: keyword.other.cql - 2: string.unquoted.cql - - match: \b(?i:primary\s+key)\b - scope: storage.modifier.cql - - match: \b(?i:using\s+ttl)\b - scope: keyword.other.cql - - built-in-scalar-function-calls: - - meta_append: true - - match: \b(?:token|uuid|now|toJson|TTL|WRITETIME|KEYS|ENTRIES|FULL)(?=\s*\() - scope: support.function.scalar.cql - push: function-call-arguments - - dml-statements: - - meta_prepend: true - - match: \b(?i:(select)\s+(json))\b - captures: - 1: keyword.other.dml.sql - 2: storage.modifier.cql - - match: \b(?i:allow\s+filtering)\b - scope: keyword.other.dml.cql - - match: \b(?i:copy)\b - scope: keyword.other.dml.cql - push: - - copy-from - - maybe-group - - expect-table-name - - statements: - - meta_prepend: true - - include: use-db - - match: \b(?i:source)\b - scope: keyword.other.cql - - inside-dict-or-set: - - match: \} - scope: punctuation.section.braces.end.cql - pop: 1 - - match: ':' - scope: punctuation.separator.key-value.cql - - include: expressions - - match: \w+ - scope: meta.mapping.key.cql string.unquoted.cql - - inside-array: - - match: \] - scope: punctuation.section.brackets.end.cql - pop: 1 - - include: expressions - - ddl-create-target: - - meta_prepend: true - - match: \b(?i:with)\b - scope: keyword.other.cql - - match: \b(?i:clustering)\b - scope: keyword.other.cql +###[ DDL STATEMENTS ]########################################################## ddl-statements: - meta_prepend: true @@ -101,17 +32,25 @@ contexts: push: - ddl-create-target - ddl-table-creation-columns - - create-type-condition + - ddl-create-type-condition ddl-alter-common: - meta_prepend: false - create-type-condition: + ddl-create-target: + - meta_prepend: true + - match: \b(?i:with)\b + scope: keyword.other.cql + - match: \b(?i:clustering)\b + scope: keyword.other.cql + + ddl-create-type-condition: - include: dml-condition + - include: expect-type-creation-name + + expect-type-creation-name: - match: (?=\S) - set: - - type-creation-name - - single-identifier + set: [type-creation-name, single-identifier] type-creation-name: - meta_include_prototype: false @@ -127,14 +66,13 @@ contexts: captures: 1: storage.modifier.cql 2: meta.group.partition-key.cql punctuation.section.group.begin.cql - push: partition-key + push: inside-partition-key - match: \b(?i:primary\s+key)\b scope: storage.modifier.cql - #push: partition-key - include: expressions - include: ddl-creation-column - partition-key: + inside-partition-key: - meta_content_scope: meta.group.partition-key.cql - match: \) scope: meta.group.partition-key.cql punctuation.section.group.end.cql @@ -155,15 +93,85 @@ contexts: scope: punctuation.separator.sequence.cql - include: expect-column-names - joins: - - match: \bjoin\b +###[ DML STATEMENTS ]########################################################## + + dml-statements: + - meta_prepend: true + - match: \b(?i:(select)\s+(json))\b + captures: + 1: keyword.other.dml.sql + 2: storage.modifier.cql + - match: \b(?i:allow\s+filtering)\b + scope: keyword.other.dml.cql + - match: \b(?i:copy)\b + scope: keyword.other.dml.cql + push: + - dml-copy-from + - maybe-group + - expect-table-name - copy-from: + dml-copy-from: - match: \b(?i:from)\b scope: keyword.other.cql pop: 1 - include: else-pop + joins: + - match: \bjoin\b + +###[ OTHER STATEMENTS ]######################################################## + + other-statements: + - meta_prepend: true + - match: \b(?i:use)\b + scope: keyword.context.sql + push: expect-database-name + - match: \b(?i:source)\b + scope: keyword.other.cql + +###[ EXPRESSIONS ]############################################################# + + expressions: + - meta_append: true + - match: \b(?i:limit)\b + scope: keyword.other.dml.cql + - match: \{ + scope: punctuation.section.braces.begin.cql + push: inside-dict-or-set + - match: \[ + scope: punctuation.section.brackets.begin.cql + push: inside-array + - match: \b((?i:with))\s+(\w+)? + captures: + 1: keyword.other.cql + 2: string.unquoted.cql + - match: \b(?i:primary\s+key)\b + scope: storage.modifier.cql + - match: \b(?i:using\s+ttl)\b + scope: keyword.other.cql + + built-in-scalar-function-calls: + - meta_append: true + - match: \b(?:token|uuid|now|toJson|TTL|WRITETIME|KEYS|ENTRIES|FULL)(?=\s*\() + scope: support.function.scalar.cql + push: function-call-arguments + + inside-array: + - match: \] + scope: punctuation.section.brackets.end.cql + pop: 1 + - include: expressions + + inside-dict-or-set: + - match: \} + scope: punctuation.section.braces.end.cql + pop: 1 + - match: ':' + scope: punctuation.separator.key-value.cql + - include: expressions + - match: \w+ + scope: meta.mapping.key.cql string.unquoted.cql + ###[ TYPES ]################################################################### built-in-type: diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 3e3173205c..80403858dd 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -22,7 +22,7 @@ variables: ) contexts: - main: + sql: - meta_append: true - include: regexps @@ -46,10 +46,7 @@ contexts: - match: \n pop: 1 - statements: - - meta_append: true - - match: \b(?i:begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b - scope: keyword.other.LUW.sql +###[ DDL STATEMENTS ]########################################################## ddl-statements: - meta_prepend: true @@ -60,13 +57,26 @@ contexts: - create-condition - ddl-target - dml-statements: - - meta_append: true - - match: \b(?i:insert(\s+(?:ignore\s+)?into)?)\b - scope: keyword.other.dml.sql - push: expect-table-name - - match: \b(?i:limit)\b - scope: keyword.other.dml.sql + ddl-alter-table: + - meta_prepend: true + - match: \b(?i:change\s+column)\b + scope: keyword.other.ddl.sql + push: + - expect-type + - expect-column-name-declaration + - expect-column-name + + ddl-target: + - meta_prepend: true + - include: ddl-target-common + + ddl-create-target: + - meta_prepend: true + - include: ddl-target-common + + create-condition: + - meta_prepend: true + - include: ddl-target-common ddl-target-common: - match: \b(?i:on)\b @@ -82,51 +92,40 @@ contexts: - match: (?=\() pop: 1 - create-condition: - - meta_prepend: true - - include: ddl-target-common + ddl-target-algorithm: + - match: \b(?i:MERGE|TEMPTABLE|UNDEFINED)\b + scope: keyword.other.mysql + pop: 1 + - include: else-pop - ddl-target: + inside-ddl-table-creation-columns: - meta_prepend: true - - include: ddl-target-common + - match: \b(?i:auto_increment)\b + scope: keyword.other.mysql + - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) + scope: keyword.other.object-comments.sql - ddl-create-target: - - meta_prepend: true - - include: ddl-target-common +###[ DML STATEMENTS ]########################################################## + + dml-statements: + - meta_append: true + - match: \b(?i:insert(\s+(?:ignore\s+)?into)?)\b + scope: keyword.other.dml.sql + push: expect-table-name + - match: \b(?i:limit)\b + scope: keyword.other.dml.sql joins: - meta_append: true - match: (?i)\b(?:straight_join|natural)\b scope: keyword.other.dml.sql - table-name-or-subquery: - - meta_prepend: true - - meta_include_prototype: false - - match: (?=#) - pop: 1 - - include: comments +###[ OTHER STATEMENTS ]######################################################## - ddl-alter-table: + other-statements: - meta_prepend: true - - match: \b(?i:change\s+column)\b - scope: keyword.other.ddl.sql - push: - - expect-type - - expect-column-name-declaration - - expect-column-name - - inside-ddl-table-creation-columns: - - meta_prepend: true - - match: \b(?i:auto_increment)\b - scope: keyword.other.mysql - - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) - scope: keyword.other.object-comments.sql - - ddl-target-algorithm: - - match: \b(?i:MERGE|TEMPTABLE|UNDEFINED)\b - scope: keyword.other.mysql - pop: 1 - - include: else-pop + - match: \b(?i:begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b + scope: keyword.other.LUW.sql ###[ EXPRESSIONS ]############################################################# @@ -137,6 +136,13 @@ contexts: - match: \b(?i:using)\b scope: keyword.other.mysql + table-name-or-subquery: + - meta_prepend: true + - meta_include_prototype: false + - match: (?=#) + pop: 1 + - include: comments + ###[ TYPES ]################################################################### after-type: diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 624e94edd8..37ef139514 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -36,45 +36,16 @@ variables: contexts: - -###[ EXPRESSIONS ]############################################################# - - expressions: - - meta_prepend: true - - match: \b(?i:ARRAY)\b - scope: keyword.declaration.psql - - match: \[ - scope: punctuation.section.brackets.begin.psql - - match: \] - scope: punctuation.section.brackets.end.psql - - match: ':(?!:)' - scope: keyword.operator.range.psql - - match: \b(?i:return)\b - scope: keyword.control.flow.return.psql - - ddl-target: - - meta_prepend: true - - match: \b(?i:extension|domain)\b - scope: keyword.other.psql - - ddl-create-target: - - meta_prepend: true - - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b - scope: keyword.other.psql - - ddl-alter-common: + sql: - meta_prepend: true - - match: \b(?i:check)\b - scope: keyword.other.psql + - include: declarations - inside-ddl-table-creation-columns: - - meta_prepend: true - - match: \b(?i:unique)\b - scope: keyword.other.psql +###[ DECLARATIONS ]############################################################ - statements: - - meta_prepend: true - - include: declarations + declarations: + - match: \b(?i:declare)\b + scope: keyword.declaration.variable.sql + push: inside-declaration inside-declaration: - match: (?=\S) @@ -88,10 +59,22 @@ contexts: - meta_scope: variable.other.psql - include: immediately-pop +###[ DDL STATEMENTS ]########################################################## + ddl-statements: - meta_prepend: true - match: \$\$ + ddl-alter-common: + - meta_prepend: true + - match: \b(?i:check)\b + scope: keyword.other.psql + + ddl-create-target: + - meta_prepend: true + - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b + scope: keyword.other.psql + ddl-create-target-expect-as: - meta_prepend: true - match: \b(?i:FOR\s+EACH\s+ROW\s+EXECUTE\s+PROCEDURE)\b @@ -100,6 +83,31 @@ contexts: scope: storage.modifier.psql push: expect-schema-name + ddl-target: + - meta_prepend: true + - match: \b(?i:extension|domain)\b + scope: keyword.other.psql + + inside-ddl-table-creation-columns: + - meta_prepend: true + - match: \b(?i:unique)\b + scope: keyword.other.psql + +###[ EXPRESSIONS ]############################################################# + + expressions: + - meta_prepend: true + - match: \b(?i:ARRAY)\b + scope: keyword.declaration.psql + - match: \[ + scope: punctuation.section.brackets.begin.psql + - match: \] + scope: punctuation.section.brackets.end.psql + - match: ':(?!:)' + scope: keyword.operator.range.psql + - match: \b(?i:return)\b + scope: keyword.control.flow.return.psql + ###[ OPERATORS ]############################################################### operators: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index b9a18c915e..338da8a148 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -26,11 +26,19 @@ contexts: - include: comments main: + - include: sql + + sql: - include: statements - match: ';' scope: punctuation.terminator.statement.sql - include: expressions-or-column-name + statements: + - include: ddl-statements + - include: dml-statements + - include: other-statements + ###[ COMMENTS ]################################################################ comments: @@ -73,150 +81,7 @@ contexts: scope: punctuation.definition.comment.end.sql pop: 1 - create-condition: - - include: dml-condition - - include: expect-other-creation-name - - create-table-condition: - - include: dml-condition - - include: expect-table-creation-name - - drop-condition: - - include: dml-condition - - match: (?=\S) - set: - - ddl-target-on - - single-identifier - - dml-condition: - - match: \b(?i:if)\b - scope: keyword.control.flow.sql - - include: logical-operators - -###[ EXPRESSIONS ]############################################################# - - expressions-or-column-name: - - include: wildcard-identifiers - - include: expressions - - include: expect-column-names - - expressions: - - include: alias-expressions - - include: case-expressions - - include: collate-expressions - - include: literals-and-variables - - include: operators - - include: function-calls - #- include: types - - include: groups - - match: \) - scope: invalid.illegal.trailing-paren.sql - - match: ',' - scope: punctuation.separator.sequence.sql - - match: (?=;) - pop: 1 - - alias-expressions: - - match: \b(?i:as)\b - scope: keyword.operator.assignment.alias.sql - push: expect-column-alias-name - - case-expressions: - - match: \b(?i:case)\b - scope: keyword.control.conditional.case.sql - push: inside-case-expression - - inside-case-expression: - - meta_scope: meta.statement.conditional.case.sql - - match: \b(?i:end)\b - scope: keyword.control.conditional.end.sql - pop: 1 - - match: \b(?i:(case)\s+(when))\b - captures: - 1: keyword.control.conditional.case.sql - 2: keyword.control.conditional.when.sql - - match: \b(?i:when)\b - scope: keyword.control.conditional.when.sql - - match: \b(?i:then)\b - scope: keyword.control.conditional.then.sql - - match: \b(?i:else)\b - scope: keyword.control.conditional.else.sql - - include: expressions-or-column-name - - collate-expressions: - - match: \b(?i:collate)\b - scope: keyword.other.sql - push: inside-collate-expression - - inside-collate-expression: - - match: '{{simple_identifier}}' - scope: support.constant.sql - pop: 1 - - include: else-pop - - function-calls: - - include: built-in-aggregate-function-calls - - include: built-in-scalar-function-calls - - include: user-defined-function-calls - - built-in-aggregate-function-calls: - # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - - match: \b(?i:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() - scope: support.function.aggregate.sql - push: function-call-arguments - - built-in-scalar-function-calls: - # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - - match: \b(?i:CURRENT_(?:DATE|TIME(?:STAMP)?|USER)|(?:SESSION|SYSTEM)_USER)\b - scope: support.function.scalar.sql - - user-defined-function-calls: - - match: \b{{simple_identifier}}(?=\s*\() - scope: support.function.sql - push: function-call-arguments - - function-call-arguments: - - meta_include_prototype: false - - meta_scope: meta.function-call.sql - - match: \( - scope: meta.group.sql punctuation.section.arguments.begin.sql - set: inside-function-call-arguments - - include: else-pop - - inside-function-call-arguments: - - meta_content_scope: meta.function-call.sql meta.group.sql - - match: \) - scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql - pop: 1 - - match: ',' - scope: punctuation.separator.argument.sql - - include: distinct - - include: expressions-or-column-name - - maybe-group: - - include: group - - include: else-pop - - group: - - match: \( - scope: punctuation.section.group.begin.sql - set: inside-group - - groups: - - match: \( - scope: punctuation.section.group.begin.sql - push: inside-group - - inside-group: - - meta_scope: meta.group.sql - - match: \) - scope: punctuation.section.group.end.sql - pop: 1 - - include: main - - statements: - - include: ddl-statements - - include: dml-statements +###[ DDL STATEMENTS ]########################################################## ddl-statements: - match: \b(?i:create\s+(?:temporary\s+)?table)\b @@ -230,7 +95,7 @@ contexts: push: - ddl-create-target-expect-as - ddl-create-target - - create-condition + - create-other-condition - ddl-target - match: \b(?i:drop\s+table)\b scope: keyword.other.ddl.sql @@ -251,8 +116,31 @@ contexts: push: - ddl-alter-target - ddl-target - - match: \b(?i:grant(?:\swith\sgrant\soption)?|revoke)\b - scope: keyword.other.authorization.sql + + ddl-table-creation-columns: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-ddl-table-creation-columns + + inside-ddl-table-creation-columns: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - match: \b(?i:constraint)\b + scope: storage.modifier.sql + push: expect-constraint-name + - include: after-constraint + - include: expressions + - include: ddl-creation-column + + ddl-creation-column: + - match: (?=\S) + push: + - after-type + - expect-type + - column-name-declaration + - single-identifier ddl-create-target: - meta_scope: meta.create.sql @@ -277,11 +165,6 @@ contexts: push: expect-table-name - include: else-pop - ddl-table-creation-columns: - - match: \( - scope: punctuation.section.group.begin.sql - set: inside-ddl-table-creation-columns - ddl-drop-target: - meta_include_prototype: false - meta_scope: meta.drop.sql @@ -337,6 +220,23 @@ contexts: scope: keyword.other.ddl.sql push: expect-column-name + create-other-condition: + - include: dml-condition + - include: expect-other-creation-name + + create-table-condition: + - include: dml-condition + - include: expect-table-creation-name + + drop-condition: + - include: dml-condition + - match: (?=\S) + set: + - ddl-target-on + - single-identifier + +###[ DML STATEMENTS ]########################################################## + dml-statements: - match: \b(?i:select)\b scope: keyword.other.dml.sql @@ -366,31 +266,6 @@ contexts: - match: \b(?i:asc|desc)\b scope: keyword.other.order.sql - inside-ddl-table-creation-columns: - - meta_scope: meta.group.table-columns.sql - - match: \) - scope: punctuation.section.group.end.sql - pop: 1 - - match: \b(?i:constraint)\b - scope: storage.modifier.sql - push: expect-constraint-name - - include: after-constraint - - include: expressions - - include: ddl-creation-column - - ddl-creation-column: - - match: (?=\S) - push: - - after-type - - expect-type - - column-name-declaration - - single-identifier - - use-db: - - match: \b(?i:use)\b - scope: keyword.context.sql - push: expect-database-name - dml-delete: - include: expect-table-name @@ -414,6 +289,138 @@ contexts: pop: 1 - include: else-pop + dml-condition: + - match: \b(?i:if)\b + scope: keyword.control.flow.sql + - include: logical-operators + +###[ OTHER STATEMENTS ]######################################################## + + other-statements: + - match: \b(?i:grant(?:\s+with\s+grant\s+option)?|revoke)\b + scope: keyword.other.authorization.sql + +###[ EXPRESSIONS ]############################################################# + + expressions-or-column-name: + - include: wildcard-identifiers + - include: expressions + - include: expect-column-names + + expressions: + - include: alias-expressions + - include: case-expressions + - include: collate-expressions + - include: literals-and-variables + - include: operators + - include: function-calls + #- include: types + - include: groups + - match: \) + scope: invalid.illegal.trailing-paren.sql + - match: ',' + scope: punctuation.separator.sequence.sql + - match: (?=;) + pop: 1 + + alias-expressions: + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + push: expect-column-alias-name + + case-expressions: + - match: \b(?i:case)\b + scope: keyword.control.conditional.case.sql + push: inside-case-expression + + inside-case-expression: + - meta_scope: meta.statement.conditional.case.sql + - match: \b(?i:end)\b + scope: keyword.control.conditional.end.sql + pop: 1 + - match: \b(?i:(case)\s+(when))\b + captures: + 1: keyword.control.conditional.case.sql + 2: keyword.control.conditional.when.sql + - match: \b(?i:when)\b + scope: keyword.control.conditional.when.sql + - match: \b(?i:then)\b + scope: keyword.control.conditional.then.sql + - match: \b(?i:else)\b + scope: keyword.control.conditional.else.sql + - include: expressions-or-column-name + + collate-expressions: + - match: \b(?i:collate)\b + scope: keyword.other.sql + push: inside-collate-expression + + inside-collate-expression: + - match: '{{simple_identifier}}' + scope: support.constant.sql + pop: 1 + - include: else-pop + + function-calls: + - include: built-in-aggregate-function-calls + - include: built-in-scalar-function-calls + - include: user-defined-function-calls + + built-in-aggregate-function-calls: + # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + - match: \b(?i:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() + scope: support.function.aggregate.sql + push: function-call-arguments + + built-in-scalar-function-calls: + # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + - match: \b(?i:CURRENT_(?:DATE|TIME(?:STAMP)?|USER)|(?:SESSION|SYSTEM)_USER)\b + scope: support.function.scalar.sql + + user-defined-function-calls: + - match: \b{{simple_identifier}}(?=\s*\() + scope: support.function.sql + push: function-call-arguments + + function-call-arguments: + - meta_include_prototype: false + - meta_scope: meta.function-call.sql + - match: \( + scope: meta.group.sql punctuation.section.arguments.begin.sql + set: inside-function-call-arguments + - include: else-pop + + inside-function-call-arguments: + - meta_content_scope: meta.function-call.sql meta.group.sql + - match: \) + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql + pop: 1 + - match: ',' + scope: punctuation.separator.argument.sql + - include: distinct + - include: expressions-or-column-name + + maybe-group: + - include: group + - include: else-pop + + group: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-group + + groups: + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-group + + inside-group: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: main + set: - include: else-pop @@ -472,28 +479,20 @@ contexts: captures: 1: keyword.other.sql 2: meta.group.tablesample.sql punctuation.section.group.begin.sql - push: tablesample + push: inside-tablesample-group - include: else-pop - tablesample: + inside-tablesample-group: - meta_content_scope: meta.group.tablesample.sql - - match: \b(?i:rows|percent)\b - scope: constant.language.sql - match: (\))(?:\s*((?i:repeatable))\b)? captures: 1: meta.group.tablesample.sql punctuation.section.group.end.sql 2: constant.language.sql - pop: true + pop: 1 + - match: \b(?i:rows|percent)\b + scope: constant.language.sql - include: expressions - declarations: - - match: \b(?i:declare)\b - scope: keyword.declaration.variable.sql - push: inside-declaration - - inside-declaration: - - include: immediately-pop - after-constraint: - match: \b(?i:check)\b scope: keyword.other.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index c6d5022fc0..4f737f45a9 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -31,10 +31,153 @@ variables: contexts: - statements: - - meta_append: true + sql: + - meta_prepend: true - include: declarations - - include: transaction-statements + +###[ DECLARATIONS ]############################################################ + + declarations: + - match: \b(?i:declare)\b + scope: keyword.declaration.variable.sql + push: inside-declaration + + inside-declaration: + - match: '{{simple_identifier}}(?=\s+(?i:cursor)\b)' + scope: meta.cursor-name.sql + pop: 1 + - match: (@){{simple_identifier}} + scope: variable.other.readwrite.declaration.tsql + captures: + 1: punctuation.definition.variable.tsql + set: expect-type + - include: else-pop + +###[ DDL STATEMENTS ]########################################################## + + ddl-statements: + - meta_prepend: true + - match: (?i)\b(?:create(?:\s+or\s+alter)?)\b(?!\s*table\b) + scope: keyword.other.ddl.sql + push: + - ddl-create-target-expect-as + - ddl-create-target + - create-table-condition + - ddl-target + + ddl-alter-target: + - meta_prepend: true + #- match: \b(?i:proc|procedure|function)\b + # scope: keyword.other.sql + - match: (?=\S) + set: + - ddl-create-target-expect-as + - expect-procedure-name + + ddl-create-target-expect-as: + - meta_prepend: true + - include: with + + ddl-target: + - meta_prepend: true + - match: \b(?i:proc|unique|clustered|nonclustered)\b + scope: keyword.other.ddl.sql + + ddl-table-creation-columns: + - match: \( + scope: punctuation.section.group.begin.sql + set: + - maybe-with-table-options + - maybe-filegroup + - inside-ddl-table-creation-columns + + inside-ddl-table-creation-columns: + - meta_prepend: true + - match: \b(?i:ROWGUIDCOL|CLUSTERED|NONCLUSTERED)\b + scope: storage.modifier.tsql + - match: \b(?i:period\s+for\s+system_time)\b + scope: storage.modifier.tsql + +###[ DML STATEMENTS ]########################################################## + + dml-statements: + - meta_append: true + - match: \b(?i:bulk\s+insert)\b + scope: keyword.other.tsql + - match: \b(?i:insert)\b + scope: keyword.other.dml.sql + push: expect-table-name + - match: \b(?i:into)\b(?!\s*@) + scope: keyword.other.dml.tsql + push: expect-table-name + - match: \b(?i:into)\b + scope: keyword.other.tsql + - match: \b(?i:off)\b + scope: keyword.other.tsql + - match: \b(?i:for\s+xml)\b + scope: keyword.other.tsql + push: for-xml + - match: \b(?i:(option))\s*(\() + captures: + 1: keyword.other.dml.tsql + 2: meta.group.sql punctuation.section.group.begin.sql + push: inside-with-group + - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b + scope: keyword.other.sql + push: expect-cursor-name + - match: \b(?i:merge)\b + scope: keyword.other.tsql + push: + - maybe-table-alias + - expect-table-name + - match: \b(?i:using)\b + scope: keyword.other.tsql + push: + - table-name-or-subquery + - join-on + - maybe-table-alias + - expect-table-name + - match: \b(?i:set)\b + scope: keyword.other.dml.tsql + - include: top + + dml-delete: + - meta_prepend: true + - include: top + + dml-update: + - meta_prepend: true + - include: top + + top: + - match: (?i)\b(top)\b(?:\s*(?:(\()\s*)?(\d+)(?:\s*(\)))?(?:\s+(percent\b))?)? + captures: + 1: keyword.other.dml.tsql + 2: meta.group.tsql punctuation.section.parens.begin.tsql + 3: meta.group.tsql meta.number.integer.decimal.tsql constant.numeric.value.tsql + 4: meta.group.tsql punctuation.section.parens.end.tsql + 5: keyword.other.dml.tsql + + for-xml: + - match: \b(?i:raw|auto|elements|root|path)\b + scope: keyword.other.tsql + - match: \b(?:XSINIL|XMLSCHEMA)\b # case sensitive?! TODO: need to check + scope: keyword.other.tsql + - match: (?=\)) + pop: 1 + - include: expressions + - include: else-pop + + joins: + - meta_append: true + - match: (?i)\b(?:(?:cross|outer)\s+)?apply\b + scope: keyword.other.dml.sql + push: table-name-or-subquery + +###[ OTHER STATEMENTS ]######################################################## + + other-statements: + - meta_prepend: true - include: cte-with - match: (?=\b(?i:raiserror)\b) push: raiserror-args @@ -72,11 +215,39 @@ contexts: captures: 1: entity.name.label.tsql 2: punctuation.definition.label.tsql - - transaction-statements: - match: (?i)\b(?:begin|commit|rollback|save)\s+tran(saction)?\b scope: keyword.context.tsql +###[ CTE WITH STATEMENTS ]##################################################### + + cte-with: + - match: \b(?i:with)\b(?=\s*(?:\[\w+\]|\w+)\s*\() + scope: keyword.other.dml.sql + push: + - cte-as + - cte-column-list + - expect-cte-table-name + - match: \b(?i:with)\b #(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) + scope: keyword.other.dml.sql + push: + - cte-as + - expect-cte-table-name + + cte-as: + - match: \b(?i:as)\b + scope: keyword.operator.assignment.cte.tsql + - include: pop-on-top-level-reserved-word + - match: ',' + scope: punctuation.separator.sequence.cte.tsql + push: + - cte-column-list + - expect-cte-table-name + - include: expressions + + cte-column-list: + - include: ddl-table-creation-columns + - include: else-pop + ###[ EXPRESSIONS ]############################################################# expressions: @@ -139,103 +310,6 @@ contexts: scope: punctuation.separator.argument.sql - include: expressions-or-column-name - dml-statements: - - meta_append: true - - match: \b(?i:bulk\s+insert)\b - scope: keyword.other.tsql - - match: \b(?i:insert)\b - scope: keyword.other.dml.sql - push: expect-table-name - - match: \b(?i:into)\b(?!\s*@) - scope: keyword.other.dml.tsql - push: expect-table-name - - match: \b(?i:into)\b - scope: keyword.other.tsql - - match: \b(?i:off)\b - scope: keyword.other.tsql - - match: \b(?i:for\s+xml)\b - scope: keyword.other.tsql - push: for-xml - - include: top - - match: \b(?i:(option))\s*(\() - captures: - 1: keyword.other.dml.tsql - 2: meta.group.sql punctuation.section.group.begin.sql - push: inside-with-group - - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b - scope: keyword.other.sql - push: expect-cursor-name - - match: \b(?i:merge)\b - scope: keyword.other.tsql - push: - - maybe-table-alias - - expect-table-name - - match: \b(?i:using)\b - scope: keyword.other.tsql - push: - - table-name-or-subquery - - join-on - - maybe-table-alias - - expect-table-name - - match: \b(?i:set)\b - scope: keyword.other.dml.tsql - - ddl-statements: - - meta_prepend: true - - match: (?i)\b(?:create(?:\s+or\s+alter)?)\b(?!\s*table\b) - scope: keyword.other.ddl.sql - push: - - ddl-create-target-expect-as - - ddl-create-target - - create-table-condition - - ddl-target - - ddl-create-target-expect-as: - - meta_prepend: true - - include: with - - ddl-target: - - meta_prepend: true - - match: \b(?i:proc|unique|clustered|nonclustered)\b - scope: keyword.other.ddl.sql - - ddl-alter-target: - - meta_prepend: true - #- match: \b(?i:proc|procedure|function)\b - # scope: keyword.other.sql - - match: (?=\S) - set: - - ddl-create-target-expect-as - - expect-procedure-name - - top: - - match: (?i)\b(top)\b(?:\s*(?:(\()\s*)?(\d+)(?:\s*(\)))?(?:\s+(percent\b))?)? - captures: - 1: keyword.other.dml.tsql - 2: meta.group.tsql punctuation.section.parens.begin.tsql - 3: meta.group.tsql meta.number.integer.decimal.tsql constant.numeric.value.tsql - 4: meta.group.tsql punctuation.section.parens.end.tsql - 5: keyword.other.dml.tsql - - dml-delete: - - meta_prepend: true - - include: top - - dml-update: - - meta_prepend: true - - include: top - - inside-declaration: - - match: '{{simple_identifier}}(?=\s+(?i:cursor)\b)' - scope: meta.cursor-name.sql - pop: 1 - - match: (@){{simple_identifier}} - scope: variable.other.readwrite.declaration.tsql - captures: - 1: punctuation.definition.variable.tsql - set: expect-type - - include: else-pop - set: - meta_prepend: true - match: \b(?i:nocount|ansi_nulls|quoted_identifier)\b @@ -251,6 +325,29 @@ contexts: - include: operators - include: else-pop + table-name-or-subquery: + - meta_prepend: true + - match: \b(?i:OPENXML)\b + scope: meta.table-valued-function-name.sql support.function.tsql + push: + - with-column-definition + - function-call-arguments + - match: \b(?i:(OPENROWSET))\s*(\() + scope: meta.function-call.tsql + captures: + 1: meta.table-valued-function-name.sql support.function.tsql + 2: punctuation.section.arguments.begin.tsql + set: inside-openrowset-call + + inside-openrowset-call: + - meta_content_scope: meta.group.sql + - match: \) + scope: meta.function-call.tsql meta.group.tsql punctuation.section.arguments.end.sql + set: maybe-table-alias + - match: ';' + scope: punctuation.separator.sequence.tsql + - include: inside-function-call-arguments + table-name-fail-if-function-cal: - meta_prepend: true - include: table-hint-without-with @@ -279,18 +376,9 @@ contexts: 2: constant.language.table-hint.tsql 3: punctuation.section.group.end.tsql - cte-with: - - match: (?i)\bwith\b(?=\s*(?:\[\w+\]|\w+)\s*\() - scope: keyword.other.dml.sql - push: - - cte-as - - cte-column-list - - expect-cte-table-name - - match: (?i)\bwith\b #(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) - scope: keyword.other.dml.sql - push: - - cte-as - - expect-cte-table-name + maybe-with-table-options: + - include: with + - include: else-pop with: - match: (?i)\bwith\b @@ -370,66 +458,12 @@ contexts: set: inside-with-group - include: else-pop - joins: - - meta_append: true - - match: (?i)\b(?:(?:cross|outer)\s+)?apply\b - scope: keyword.other.dml.sql - push: table-name-or-subquery - - table-name-or-subquery: - - meta_prepend: true - - match: \b(?i:OPENXML)\b - scope: meta.table-valued-function-name.sql support.function.tsql - push: - - with-column-definition - - function-call-arguments - - match: \b(?i:(OPENROWSET))\s*(\() - scope: meta.function-call.tsql - captures: - 1: meta.table-valued-function-name.sql support.function.tsql - 2: punctuation.section.arguments.begin.tsql - set: inside-openrowset-call - exec: - include: pop-on-top-level-reserved-word - include: assignment-operators - include: expressions - include: else-pop - cte-column-list: - - include: ddl-table-creation-columns - - include: else-pop - - cte-as: - - match: \b(?i:as)\b - scope: keyword.operator.assignment.cte.tsql - - include: pop-on-top-level-reserved-word - - match: ',' - scope: punctuation.separator.sequence.cte.tsql - push: - - cte-column-list - - expect-cte-table-name - - include: expressions - - for-xml: - - match: \b(?i:raw|auto|elements|root|path)\b - scope: keyword.other.tsql - - match: \b(?:XSINIL|XMLSCHEMA)\b # case sensitive?! TODO: need to check - scope: keyword.other.tsql - - match: (?=\)) - pop: 1 - - include: expressions - - include: else-pop - - inside-openrowset-call: - - meta_content_scope: meta.group.sql - - match: ';' - scope: punctuation.separator.sequence.tsql - - match: \) - scope: meta.function-call.tsql meta.group.tsql punctuation.section.arguments.end.sql - set: maybe-table-alias - - include: inside-function-call-arguments - merge-condition: - match: \b(?i:\s+by\s+(?:source|target))\b scope: keyword.other.tsql @@ -444,31 +478,12 @@ contexts: - include: dml-statements - include: expressions - ddl-table-creation-columns: - - match: \( - scope: punctuation.section.group.begin.sql - set: - - maybe-with-table-options - - maybe-filegroup - - inside-ddl-table-creation-columns - - inside-ddl-table-creation-columns: - - meta_prepend: true - - match: \b(?i:ROWGUIDCOL|CLUSTERED|NONCLUSTERED)\b - scope: storage.modifier.tsql - - match: \b(?i:period\s+for\s+system_time)\b - scope: storage.modifier.tsql - maybe-filegroup: - match: \b(?i:ON)\b(?!\s*{{identifier_for_lookahead}}\s*=) scope: keyword.other.tsql set: expect-filegroup-name - include: else-pop - maybe-with-table-options: - - include: with - - include: else-pop - raiserror-args: - match: \b(?i:with)\b scope: keyword.other.tsql @@ -544,11 +559,11 @@ contexts: index-names: - meta_content_scope: meta.group.tsql - - match: ',' - scope: punctuation.separator.sequence.tsql - match: \) scope: meta.group.tsql punctuation.section.group.end.tsql pop: 1 + - match: ',' + scope: punctuation.separator.sequence.tsql - include: literals-and-variables - include: ddl-table-creation-columns - include: expect-index-names From b23344ceeed123921090aa3397070756f1426c96 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 26 Jun 2022 19:29:30 +0200 Subject: [PATCH 120/250] Less restrictive whitespace --- SQL/SQL (basic).sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 338da8a148..65a540b704 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -496,7 +496,7 @@ contexts: after-constraint: - match: \b(?i:check)\b scope: keyword.other.sql - - match: \b(?i:(((?:foreign|fulltext|primary|unique)\s+)?key|on\sdelete(\s+cascade)?|on\supdate(\s+cascade)?|default))\b + - match: \b(?i:(((?:foreign|fulltext|primary|unique)\s+)?key|on\s+delete(\s+cascade)?|on\s+update(\s+cascade)?|default))\b scope: storage.modifier.sql push: maybe-column-reference - match: \b(?i:references)\b From 4c84c207be28306c2badc0be6f60fbb8f08543db Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 26 Jun 2022 21:27:32 +0200 Subject: [PATCH 121/250] Fix cursor expressions --- SQL/TSQL.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 4f737f45a9..35f042095c 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -260,7 +260,7 @@ contexts: scope: keyword.other.sql - match: \b(?i:cursor)\b scope: support.type.tsql - set: cursor-declaration + push: cursor-declaration - match: \b(?i:when\s+(?:not\s+)?matched)\b scope: keyword.control.conditional.case.sql push: merge-condition From ed8cb471d2e1a00d718159ad76c8a44c0d2233ec Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 1 Jul 2022 17:31:48 +0200 Subject: [PATCH 122/250] Refactor column modifiers --- SQL/SQL (basic).sublime-syntax | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 65a540b704..d1c706f21d 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -130,7 +130,7 @@ contexts: - match: \b(?i:constraint)\b scope: storage.modifier.sql push: expect-constraint-name - - include: after-constraint + - include: column-modifiers - include: expressions - include: ddl-creation-column @@ -195,7 +195,7 @@ contexts: - match: \b(?i:add\s+constraint)\b scope: meta.add.sql keyword.other.sql push: - - after-constraint-pop + - maybe-column-modifier - expect-constraint-name - match: \b(?i:add\s+(?:(?:fulltext|spatial)\s+(index|key)|index))\b scope: meta.add.sql keyword.other.sql @@ -424,6 +424,8 @@ contexts: set: - include: else-pop +###[ TABLE NAMES ]############################################################# + table-name-or-subquery: - match: (?=\() set: @@ -493,10 +495,21 @@ contexts: scope: constant.language.sql - include: expressions - after-constraint: +###[ COLUMN MODIFIERS ]######################################################## + + maybe-column-modifier: + - include: column-modifiers + - include: else-pop + + column-modifiers: - match: \b(?i:check)\b scope: keyword.other.sql - - match: \b(?i:(((?:foreign|fulltext|primary|unique)\s+)?key|on\s+delete(\s+cascade)?|on\s+update(\s+cascade)?|default))\b + - match: |- + \b(?xi: + (?: (?: foreign | fulltext | primary | unique ) \s+ )? key + | on \s+ (?: delete | update ) (?: \s+ cascade )? + | default + )\b scope: storage.modifier.sql push: maybe-column-reference - match: \b(?i:references)\b @@ -505,10 +518,6 @@ contexts: - maybe-column-reference - expect-table-name - after-constraint-pop: - - include: after-constraint - - include: else-pop - maybe-column-reference: - match: \( scope: punctuation.section.group.begin.sql From 5597b02d44a0103d4d8797df08038d15a9e24b84 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 1 Jul 2022 17:51:19 +0200 Subject: [PATCH 123/250] Add meta scopes to arrays, dicts/sets --- SQL/Cassandra.sublime-syntax | 22 +++++++++++++++------- SQL/tests/syntax/syntax_test_cassandra.cql | 7 +++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 9eb391434f..75de003464 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -133,14 +133,10 @@ contexts: expressions: - meta_append: true + - include: arrays + - include: dicts-or-sets - match: \b(?i:limit)\b scope: keyword.other.dml.cql - - match: \{ - scope: punctuation.section.braces.begin.cql - push: inside-dict-or-set - - match: \[ - scope: punctuation.section.brackets.begin.cql - push: inside-array - match: \b((?i:with))\s+(\w+)? captures: 1: keyword.other.cql @@ -156,20 +152,32 @@ contexts: scope: support.function.scalar.cql push: function-call-arguments + arrays: + - match: \[ + scope: punctuation.section.brackets.begin.cql + push: inside-array + inside-array: + - meta_scope: meta.brackets.cql - match: \] scope: punctuation.section.brackets.end.cql pop: 1 - include: expressions + dicts-or-sets: + - match: \{ + scope: punctuation.section.braces.begin.cql + push: inside-dict-or-set + inside-dict-or-set: + - meta_scope: meta.braces.cql - match: \} scope: punctuation.section.braces.end.cql pop: 1 - match: ':' scope: punctuation.separator.key-value.cql - include: expressions - - match: \w+ + - match: '{{simple_identifier}}' scope: meta.mapping.key.cql string.unquoted.cql ###[ TYPES ]################################################################### diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 9b4ea1a1fa..a5ebfba1ac 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -248,6 +248,10 @@ VALUES ( 583395ca-0845-4517-b0f7-97bb0ea86b53, false, {77a969b4-378a-4fb0-b531-83404ee3c395:{id:22f7244c-c6d7-4bd7-aeac-a886c4242cd8,sometext:'text here',empty:{}}} + -- <- meta.braces.cql punctuation.section.braces.begin.cql + --^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.braces.cql - meta.braces meta.braces + -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.braces.cql meta.braces.cql + -- ^ meta.braces.cql - meta.braces meta.braces -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.uuid -- ^ punctuation.separator.key-value -- ^ punctuation.section.braces.begin @@ -267,6 +271,7 @@ VALUES ( INSERT INTO something_by_someid (someid, someset) VALUES (22f7244c-c6d7-4bd7-aeac-a886c4242cd8,{'item1','item2','item3'}); +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.braces.cql -- ^ punctuation.section.braces.begin -- ^^^^^^^ string.quoted.single -- ^ punctuation.separator.sequence @@ -449,6 +454,7 @@ SELECT * FROM cycling.birthday_list WHERE blist['age'] = '23'; -- ^^^^^ meta.column-name +-- ^^^^^^^ meta.brackets.cql -- ^ punctuation.section.brackets.begin -- ^^^^^ string.quoted.single -- ^ punctuation.section.brackets.end @@ -461,6 +467,7 @@ FROM cycling.race_starts WHERE rnumbers = [39,7,14]; -- ^^^^^^^^ meta.column-name -- ^ keyword.operator.comparison +-- ^^^^^^^^^ meta.brackets.cql -- ^ punctuation.section.brackets.begin -- ^^ meta.number.integer.decimal constant.numeric.value -- ^ punctuation.separator.sequence From 9c56e2e48ce90c4436d2b7b19084436aed82f9dd Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 2 Jul 2022 18:53:48 +0200 Subject: [PATCH 124/250] Fix Cassandra collection types --- SQL/Cassandra.sublime-syntax | 28 ++++++++++++++++------ SQL/tests/syntax/syntax_test_cassandra.cql | 28 +++++++++++++++++++++- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 75de003464..4d7e8980a2 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -184,18 +184,32 @@ contexts: built-in-type: - meta_prepend: true - - match: \b(?i:set|frozen|map|tuple)(<) + # https://cassandra.apache.org/doc/latest/cassandra/cql/types.html#collections + - match: \b(?i:frozen|list|map|set|tuple)\b scope: storage.type.cql - captures: - 1: punctuation.definition.generic.begin.cql + set: maybe-generic + + maybe-generic: + - match: < + scope: punctuation.definition.generic.begin.cql set: - - end-generic-type - - built-in-type + - inside-generic + - expect-generic-type + - include: else-pop - end-generic-type: + inside-generic: + - meta_scope: meta.generic.cql - match: \> - scope: storage.type.cql punctuation.definition.generic.end.cql + scope: punctuation.definition.generic.end.cql + pop: 1 + - match: ',' + scope: punctuation.separator.sequence.cql + push: expect-generic-type + + expect-generic-type: + - match: (?=[,>]) pop: 1 + - include: expect-type ###[ LITERALS ]################################################################ diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index a5ebfba1ac..997b3ef70f 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -100,11 +100,37 @@ CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( permissions frozen>, -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns -- ^^^^^^^^^^^ meta.column-name --- ^^^^^^^^^^^^^^^^^ storage.type +-- ^^^^^^ - meta.generic +-- ^^^^ meta.generic.cql - meta.generic meta.generic +-- ^^^^^^ meta.generic.cql meta.generic.cql - meta.generic meta.generic meta.generic +-- ^ meta.generic.cql - meta.generic meta.generic +-- ^ - meta.generic +-- ^^^^^^ storage.type -- ^ punctuation.definition.generic.begin +-- ^^^ storage.type -- ^ punctuation.definition.generic.begin +-- ^^^^ storage.type -- ^^ punctuation.definition.generic.end -- ^ punctuation.separator.sequence + storage tuple>>, +-- ^^^^^ - meta.generic +-- ^^^^ meta.generic.cql - meta.generic meta.generic +-- ^^^^^^^^^^ meta.generic.cql meta.generic.cql - meta.generic meta.generic meta.generic +-- ^^^^^^^^^ meta.generic.cql meta.generic.cql meta.generic.cql +-- ^ meta.generic.cql meta.generic.cql - meta.generic meta.generic meta.generic +-- ^ meta.generic.cql - meta.generic meta.generic +-- ^ - meta.generic +-- ^^^^^ storage.type.cql +-- ^ punctuation.definition.generic.begin.cql +-- ^^^ storage.type.cql +-- ^ punctuation.definition.generic.begin.cql +-- ^^^^ storage.type.sql +-- ^ punctuation.separator.sequence.cql +-- ^^^ storage.type.cql +-- ^ punctuation.definition.generic.begin.cql +-- ^^^^^^^ support.type.sql +-- ^^^ punctuation.definition.generic.end.cql +-- ^ punctuation.separator.sequence.sql PRIMARY KEY(userid) -- ^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns -- ^^^^^^^^^^^ storage.modifier From 9d539e14da8f369d4cebd35d46d3dedf14258281 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 2 Jul 2022 18:58:35 +0200 Subject: [PATCH 125/250] Update main keys order --- SQL/Cassandra.sublime-syntax | 7 +++++-- SQL/MySQL.sublime-syntax | 1 + SQL/PostgreSQL.sublime-syntax | 1 + SQL/SQL (basic).sublime-syntax | 2 +- SQL/TSQL.sublime-syntax | 1 + 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 4d7e8980a2..243751df7b 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -1,12 +1,15 @@ %YAML 1.2 --- +# https://cassandra.apache.org/doc/latest/cassandra/cql name: Cassandra Query Language -file_extensions: - - cql scope: source.sql.cql version: 2 + extends: Packages/SQL/SQL (basic).sublime-syntax +file_extensions: + - cql + variables: simple_types: |- \b(?xi: diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 80403858dd..c9e45e61b6 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -3,6 +3,7 @@ name: MySQL scope: source.sql.mysql version: 2 + extends: Packages/SQL/SQL (basic).sublime-syntax variables: diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 37ef139514..863de0f6b2 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -3,6 +3,7 @@ name: PostgreSQL scope: source.sql.psql version: 2 + extends: Packages/SQL/MySQL.sublime-syntax file_extensions: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index d1c706f21d..ccd212da55 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -2,8 +2,8 @@ --- name: SQL (Basic) scope: source.sql.basic -hidden: true version: 2 +hidden: true variables: string_escape: (?:\\.) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 35f042095c..13389f1279 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -3,6 +3,7 @@ name: T-SQL scope: source.sql.tsql version: 2 + extends: Packages/SQL/SQL (basic).sublime-syntax variables: From ae27fa1cf9de92d98dca8d9f2ac60a27a9a29525 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Mon, 4 Jul 2022 19:52:15 +0200 Subject: [PATCH 126/250] Tweak casing --- SQL/MySQL.sublime-syntax | 2 +- SQL/SQL (basic).sublime-syntax | 4 ++-- SQL/TSQL.sublime-syntax | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index c9e45e61b6..2ebc234bff 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -118,7 +118,7 @@ contexts: joins: - meta_append: true - - match: (?i)\b(?:straight_join|natural)\b + - match: \b(?i:straight_join|natural)\b scope: keyword.other.dml.sql ###[ OTHER STATEMENTS ]######################################################## diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index ccd212da55..382a2aed10 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -277,14 +277,14 @@ contexts: scope: keyword.other.dml.sql joins: - - match: (?i)\b(?:(?:inner|(?:full|left\s+)?outer|cross|left|right)\s+)?join\b + - match: \b(?i:(?:(?:inner|(?:full|left\s+)?outer|cross|left|right)\s+)?join)\b scope: keyword.other.dml.sql push: - join-on - table-name-or-subquery join-on: - - match: (?i)\bon\b + - match: \b(?i:on)\b scope: keyword.operator.join.sql pop: 1 - include: else-pop diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 13389f1279..60469aed4d 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -466,7 +466,7 @@ contexts: - include: else-pop merge-condition: - - match: \b(?i:\s+by\s+(?:source|target))\b + - match: \b(?i:by\s+(?:source|target))\b scope: keyword.other.tsql - match: \b(?i:then)\b scope: keyword.other.tsql @@ -499,7 +499,7 @@ contexts: cursor-declaration: - meta_content_scope: meta.cursor-declaration.tsql - - match: (?i)\b(?:FORWARD_ONLY|SCROLL|STATIC|KEYSET|DYNAMIC|FAST_FORWARD|READ_ONLY|SCROLL_LOCKS|OPTIMISTIC|TYPE_WARNING)\b + - match: \b(?i:FORWARD_ONLY|SCROLL|STATIC|KEYSET|DYNAMIC|FAST_FORWARD|READ_ONLY|SCROLL_LOCKS|OPTIMISTIC|TYPE_WARNING)\b scope: storage.modifier.tsql - match: \b(?i:for)\b scope: keyword.other.tsql @@ -526,7 +526,7 @@ contexts: after-cursor-select-statement-for: - meta_scope: meta.cursor-declaration.tsql - - match: (?i)\b(?:READ\s+ONLY|UPDATE(?:\s+OF)?)\b + - match: \b(?i:READ\s+ONLY|UPDATE(?:\s+OF)?)\b scope: storage.modifier.tsql pop: 1 - include: else-pop From 49d6ad863a1dc6343bde5f9fe1d0fca4897da32e Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 5 Jul 2022 17:55:07 +0200 Subject: [PATCH 127/250] Refactor TABLESAMPLE contexts Replace capture groups by contexts with simple patterns. --- SQL/SQL (basic).sublime-syntax | 34 ++++++++++++++++++++++------------ SQL/TSQL.sublime-syntax | 8 ++++---- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 382a2aed10..33d88e5b5a 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -472,29 +472,39 @@ contexts: scope: keyword.operator.assignment.alias.sql - match: (?=\S) set: - - after-table-alias + - maybe-table-sample - table-alias-name - single-identifier - after-table-alias: - - match: \b(?i:(TABLESAMPLE(?:\s+SYSTEM)?))\s*(\() - captures: - 1: keyword.other.sql - 2: meta.group.tablesample.sql punctuation.section.group.begin.sql - push: inside-tablesample-group + maybe-table-sample: + - match: \b(?i:tablesample(?:\s+system)?)\b + scope: keyword.other.sql + push: + - after-tablesample-group + - maybe-table-sample-group + - include: else-pop + + maybe-table-sample-group: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-tablesample-group - include: else-pop inside-tablesample-group: - - meta_content_scope: meta.group.tablesample.sql - - match: (\))(?:\s*((?i:repeatable))\b)? - captures: - 1: meta.group.tablesample.sql punctuation.section.group.end.sql - 2: constant.language.sql + - meta_scope: meta.group.tablesample.sql + - match: \) + scope: punctuation.section.group.end.sql pop: 1 - match: \b(?i:rows|percent)\b scope: constant.language.sql - include: expressions + after-tablesample-group: + - match: \b(?i:repeatable)\b + scope: constant.language.sql + pop: 1 + - include: else-pop + ###[ COLUMN MODIFIERS ]######################################################## maybe-column-modifier: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 60469aed4d..dc2c326ad9 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -351,7 +351,7 @@ contexts: table-name-fail-if-function-cal: - meta_prepend: true - - include: table-hint-without-with + - include: table-hints-without-with maybe-table-alias: - meta_prepend: true @@ -359,13 +359,13 @@ contexts: - match: (?=\b(?i:unpivot|pivot)\b) pop: 1 - after-table-alias: + maybe-table-sample: - meta_prepend: true - include: groups # column-alias-list - - include: table-hint-without-with + - include: table-hints-without-with - include: with - table-hint-without-with: + table-hints-without-with: - match: |- (?xi) (\()\s* From 26a1ea5ce36233ad9f3506b4ce2d73ffe990ccfc Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 5 Jul 2022 18:14:18 +0200 Subject: [PATCH 128/250] Lowercase keyword scopes --- SQL/MySQL.sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_postgres.psql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 2ebc234bff..045e226184 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -126,7 +126,7 @@ contexts: other-statements: - meta_prepend: true - match: \b(?i:begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b - scope: keyword.other.LUW.sql + scope: keyword.other.luw.sql ###[ EXPRESSIONS ]############################################################# diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index f6c9f980bc..79bee07b14 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -295,7 +295,7 @@ DECLARE -- ^ punctuation.section.brackets.end -- ^ punctuation.terminator.statement BEGIN --- ^^ keyword.other.LUW +-- ^^ keyword.other.luw FOR I IN array_lower(vals, 1)..array_upper(vals, 1) LOOP output[I] := compute_result(vals[I], something, something_else); END LOOP; From 0607a8b9346c14a3c70a499c4444347b39552092 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 5 Jul 2022 18:21:26 +0200 Subject: [PATCH 129/250] Remove duplicate pattern --- SQL/TSQL.sublime-syntax | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index dc2c326ad9..ad18e3438a 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -405,11 +405,6 @@ contexts: 1: keyword.other.tsql 2: meta.group.tsql punctuation.section.group.begin.tsql push: expressions-or-unknown - - match: \b((?i:OPTIMIZE\s+FOR))\s*(\() - captures: - 1: keyword.other.tsql - 2: meta.group.tsql punctuation.section.group.begin.tsql - push: expressions-or-unknown - match: \b((?i:INDEX|FORCESEEK))\s*(\() captures: 1: keyword.other.tsql From e4e0bc21f2264816d0fc48b8107c346214b3e120 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 5 Jul 2022 18:27:55 +0200 Subject: [PATCH 130/250] Add reusable comma and semicolon context --- SQL/SQL (basic).sublime-syntax | 17 +++++++++++------ SQL/TSQL.sublime-syntax | 8 +++----- SQL/tests/syntax/syntax_test_tsql.sql | 8 ++++---- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 33d88e5b5a..1f10f91940 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -30,8 +30,7 @@ contexts: sql: - include: statements - - match: ';' - scope: punctuation.terminator.statement.sql + - include: statement-terminators - include: expressions-or-column-name statements: @@ -314,12 +313,10 @@ contexts: - include: literals-and-variables - include: operators - include: function-calls - #- include: types + - include: comma-separators - include: groups - match: \) scope: invalid.illegal.trailing-paren.sql - - match: ',' - scope: punctuation.separator.sequence.sql - match: (?=;) pop: 1 @@ -396,7 +393,7 @@ contexts: scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql pop: 1 - match: ',' - scope: punctuation.separator.argument.sql + scope: punctuation.separator.arguments.sql - include: distinct - include: expressions-or-column-name @@ -851,6 +848,14 @@ contexts: - match: \b(?i:and|or|having|exists|between|in|not|is)\b scope: keyword.operator.logical.sql + comma-separators: + - match: ',' + scope: punctuation.separator.sequence.sql + + statement-terminators: + - match: ';' + scope: punctuation.terminator.statement.sql + ###[ PROTOTYPES ]############################################################## else-pop: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index ad18e3438a..20f07c8d69 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -308,7 +308,7 @@ contexts: scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql pop: 1 - match: ',' - scope: punctuation.separator.argument.sql + scope: punctuation.separator.arguments.sql - include: expressions-or-column-name set: @@ -428,11 +428,10 @@ contexts: push: expect-table-name - match: '{{simple_identifier}}' scope: constant.language.with.tsql - - match: ',' - scope: punctuation.separator.sequence.tsql - match: '=' scope: keyword.operator.assignment.tsql push: with-assignment + - include: comma-separators with-assignment: - include: with-bool-assignment @@ -558,8 +557,7 @@ contexts: - match: \) scope: meta.group.tsql punctuation.section.group.end.tsql pop: 1 - - match: ',' - scope: punctuation.separator.sequence.tsql + - include: comma-separators - include: literals-and-variables - include: ddl-table-creation-columns - include: expect-index-names diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index cd4179117b..ec7b02c9a2 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -226,7 +226,7 @@ SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) -- ^^^^^^^ support.function.scalar -- ^ punctuation.section.arguments.begin -- ^ punctuation.section.arguments.end --- ^ punctuation.separator.argument +-- ^ punctuation.separator.arguments -- ^^^ meta.number.integer.decimal constant.numeric.value -- ^ punctuation.section.arguments.end -- ^ - meta.function-call - meta.group @@ -1300,7 +1300,7 @@ CREATE TABLE [dbo].[table_with_constraint_following_derived_column]( -- ^^^^^^^^^^ support.function -- ^ punctuation.section.arguments.begin -- ^^^^^^ meta.group meta.function-call meta.group meta.column-name --- ^ meta.group meta.function-call meta.group punctuation.separator.argument +-- ^ meta.group meta.function-call meta.group punctuation.separator.arguments -- ^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single -- ^ punctuation.section.arguments.end -- ^^ keyword.operator.assignment @@ -1424,9 +1424,9 @@ OUTER APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID, 123, 'testing123' -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call meta.table-valued-function-name -- ^ meta.function-call meta.group punctuation.section.arguments.begin -- ^^^^^^^^^^^^^^ meta.function-call meta.group meta.column-name --- ^ meta.function-call meta.group punctuation.separator.argument +-- ^ meta.function-call meta.group punctuation.separator.arguments -- ^^^ meta.function-call meta.group meta.number.integer.decimal constant.numeric.value --- ^ meta.function-call meta.group punctuation.separator.argument +-- ^ meta.function-call meta.group punctuation.separator.arguments -- ^^^^^^^^^^^^ meta.function-call meta.group string.quoted.single -- ^ meta.function-call meta.group punctuation.section.arguments.end GO From 45a616daf33d38b3bfbee4234fe30c0c0e0fd2bc Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 5 Jul 2022 19:00:48 +0200 Subject: [PATCH 131/250] Reorganize T-SQL "with" expressions - also moves some other expressions related contexts --- SQL/TSQL.sublime-syntax | 279 ++++++++++++++++++++-------------------- 1 file changed, 139 insertions(+), 140 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 20f07c8d69..8f9815c8e5 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -77,7 +77,7 @@ contexts: ddl-create-target-expect-as: - meta_prepend: true - - include: with + - include: with-table-options ddl-target: - meta_prepend: true @@ -118,11 +118,9 @@ contexts: - match: \b(?i:for\s+xml)\b scope: keyword.other.tsql push: for-xml - - match: \b(?i:(option))\s*(\() - captures: - 1: keyword.other.dml.tsql - 2: meta.group.sql punctuation.section.group.begin.sql - push: inside-with-group + - match: \b(?i:option)\b + scope: keyword.other.dml.tsql + push: maybe-with-group - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b scope: keyword.other.sql push: expect-cursor-name @@ -191,7 +189,7 @@ contexts: push: expect-label-name - match: \b(?i:exec)\b scope: keyword.control.flow.tsql - push: [expect-procedure-name, exec] + push: [expect-procedure-name, exec-args] - match: \b(?i:begin)\b scope: keyword.control.flow.begin.tsql - match: \b(?i:end)\b @@ -219,6 +217,24 @@ contexts: - match: (?i)\b(?:begin|commit|rollback|save)\s+tran(saction)?\b scope: keyword.context.tsql + exec-args: + - include: pop-on-top-level-reserved-word + - include: assignment-operators + - include: expressions + - include: else-pop + + raiserror-args: + - match: \b(?i:with)\b + scope: keyword.other.tsql + set: raiserror-options + - include: pop-on-top-level-reserved-word + - include: expressions + + raiserror-options: + - match: \b(?i:nowait|log|seterror)\b + scope: keyword.other.tsql + - include: else-pop + ###[ CTE WITH STATEMENTS ]##################################################### cte-with: @@ -253,7 +269,7 @@ contexts: expressions: - meta_prepend: true - - include: with + - include: with-table-options - include: like-expressions - match: \b(?i:output)\b scope: storage.modifier.output.tsql @@ -311,6 +327,65 @@ contexts: scope: punctuation.separator.arguments.sql - include: expressions-or-column-name + user-defined-function-calls: + - meta_append: true + - match: (?={{identifier_for_lookahead}}\s*\() + push: + - function-call-arguments + - function-name + - single-identifier + + function-name: + - meta_include_prototype: false + - meta_content_scope: variable.function.tsql + - include: immediately-pop + + cursor-declaration: + - meta_content_scope: meta.cursor-declaration.tsql + - match: \b(?i:FORWARD_ONLY|SCROLL|STATIC|KEYSET|DYNAMIC|FAST_FORWARD|READ_ONLY|SCROLL_LOCKS|OPTIMISTIC|TYPE_WARNING)\b + scope: storage.modifier.tsql + - match: \b(?i:for)\b + scope: keyword.other.tsql + set: expect-cursor-select-statement + - include: else-pop + + expect-cursor-select-statement: + - meta_content_scope: meta.cursor-declaration.tsql + - match: \b(?i:select)\b + scope: keyword.other.dml.sql + set: after-cursor-select-statement + - include: else-pop + + after-cursor-select-statement: + - meta_content_scope: meta.cursor-declaration.tsql + - match: \b(?i:for)\b + scope: keyword.other.tsql + set: after-cursor-select-statement-for + - match: (?=\b(?i:open)\b) + pop: 1 + - include: main + + after-cursor-select-statement-for: + - meta_scope: meta.cursor-declaration.tsql + - match: \b(?i:READ\s+ONLY|UPDATE(?:\s+OF)?)\b + scope: storage.modifier.tsql + pop: 1 + - include: else-pop + + merge-condition: + - match: \b(?i:by\s+(?:source|target))\b + scope: keyword.other.tsql + - match: \b(?i:then)\b + scope: keyword.other.tsql + - match: \b(?i:insert)\b(?=\s*\() + scope: keyword.other.dml.sql + push: values-or-expressions + - include: pop-on-top-level-reserved-word + + values-or-expressions: + - include: dml-statements + - include: expressions + set: - meta_prepend: true - match: \b(?i:nocount|ansi_nulls|quoted_identifier)\b @@ -331,7 +406,7 @@ contexts: - match: \b(?i:OPENXML)\b scope: meta.table-valued-function-name.sql support.function.tsql push: - - with-column-definition + - maybe-with-column-definition - function-call-arguments - match: \b(?i:(OPENROWSET))\s*(\() scope: meta.function-call.tsql @@ -355,7 +430,7 @@ contexts: maybe-table-alias: - meta_prepend: true - - include: with + - include: with-table-options - match: (?=\b(?i:unpivot|pivot)\b) pop: 1 @@ -363,7 +438,7 @@ contexts: - meta_prepend: true - include: groups # column-alias-list - include: table-hints-without-with - - include: with + - include: with-table-options table-hints-without-with: - match: |- @@ -377,26 +452,38 @@ contexts: 2: constant.language.table-hint.tsql 3: punctuation.section.group.end.tsql +###[ WITH EXPRESSIONS ]######################################################## + + maybe-with-column-definition: + - match: \b(?i:with)\b + scope: keyword.other.tsql + set: ddl-table-creation-columns + - include: else-pop + maybe-with-table-options: - - include: with + - include: with-table-options - include: else-pop - with: - - match: (?i)\bwith\b + with-table-options: + - match: \b(?i:with)\b scope: keyword.other.dml.sql - push: with-paren-or-pop + push: + - maybe-table-alias + - maybe-with-group + + maybe-with-group: + - include: with-group + - include: else-pop - with-paren-or-pop: + with-group: - match: \( - scope: meta.group.sql punctuation.section.group.begin.sql + scope: punctuation.section.group.begin.sql set: inside-with-group - - match: (?=\S) - set: maybe-table-alias inside-with-group: - - meta_content_scope: meta.group.sql + - meta_scope: meta.group.sql - match: \) - scope: meta.group.sql punctuation.section.group.end.sql + scope: punctuation.section.group.end.sql set: maybe-filegroup - match: \b(?i:OPTIMIZE\s+FOR\s+UNKNOWN)\b scope: keyword.other.tsql @@ -404,12 +491,12 @@ contexts: captures: 1: keyword.other.tsql 2: meta.group.tsql punctuation.section.group.begin.tsql - push: expressions-or-unknown + push: inside-optimize-for-group - match: \b((?i:INDEX|FORCESEEK))\s*(\() captures: 1: keyword.other.tsql 2: meta.group.tsql punctuation.section.group.begin.tsql - push: index-names + push: inside-index-names-group - match: \b((?i:INDEX))\s*(=) captures: 1: keyword.other.tsql @@ -419,8 +506,7 @@ contexts: captures: 1: keyword.other.tsql 2: keyword.operator.assignment.tsql - push: - - maybe-nested-with-group + push: with-group-assignment - match: \b((?i:HISTORY_TABLE))\s*(=) captures: 1: keyword.other.tsql @@ -430,137 +516,48 @@ contexts: scope: constant.language.with.tsql - match: '=' scope: keyword.operator.assignment.tsql - push: with-assignment + push: with-other-assignment - include: comma-separators - with-assignment: - - include: with-bool-assignment - - include: expressions-pop-at-comma - - with-bool-assignment: - - match: \b(?i:ON|OFF)\b - scope: constant.language.bool.tsql - - expressions-pop-at-comma: - - match: (?=[,)]) - pop: 1 - - include: expressions - - maybe-nested-with-group: - - include: with-bool-assignment - - match: \( - scope: meta.group.sql punctuation.section.group.begin.sql - set: inside-with-group - - include: else-pop - - exec: - - include: pop-on-top-level-reserved-word - - include: assignment-operators - - include: expressions - - include: else-pop - - merge-condition: - - match: \b(?i:by\s+(?:source|target))\b - scope: keyword.other.tsql - - match: \b(?i:then)\b - scope: keyword.other.tsql - - match: \b(?i:insert)\b(?=\s*\() - scope: keyword.other.dml.sql - push: values-or-expressions - - include: pop-on-top-level-reserved-word - - values-or-expressions: - - include: dml-statements - - include: expressions - maybe-filegroup: - match: \b(?i:ON)\b(?!\s*{{identifier_for_lookahead}}\s*=) scope: keyword.other.tsql set: expect-filegroup-name - include: else-pop - raiserror-args: - - match: \b(?i:with)\b - scope: keyword.other.tsql - set: raiserror-options - - include: pop-on-top-level-reserved-word - - include: expressions - - raiserror-options: - - match: \b(?i:nowait|log|seterror)\b - scope: keyword.other.tsql - - include: else-pop - - cursor-declaration: - - meta_content_scope: meta.cursor-declaration.tsql - - match: \b(?i:FORWARD_ONLY|SCROLL|STATIC|KEYSET|DYNAMIC|FAST_FORWARD|READ_ONLY|SCROLL_LOCKS|OPTIMISTIC|TYPE_WARNING)\b - scope: storage.modifier.tsql - - match: \b(?i:for)\b - scope: keyword.other.tsql - set: expect-cursor-select-statement - - include: else-pop - - expect-cursor-select-statement: - - meta_content_scope: meta.cursor-declaration.tsql - - match: \b(?i:select)\b - scope: keyword.other.dml.sql - set: after-cursor-select-statement - - include: else-pop - - after-cursor-select-statement: - - meta_content_scope: meta.cursor-declaration.tsql - - match: \b(?i:for)\b - scope: keyword.other.tsql - set: after-cursor-select-statement-for - - match: (?=\b(?i:open)\b) - pop: 1 - - include: main - #- include: pop-on-top-level-reserved-word - #- include: expressions-or-column-name - - after-cursor-select-statement-for: - - meta_scope: meta.cursor-declaration.tsql - - match: \b(?i:READ\s+ONLY|UPDATE(?:\s+OF)?)\b - scope: storage.modifier.tsql - pop: 1 - - include: else-pop - - with-column-definition: - - match: \b(?i:with)\b - scope: keyword.other.tsql - set: ddl-table-creation-columns - - user-defined-function-calls: - - meta_append: true - - match: (?={{identifier_for_lookahead}}\s*\() - push: - - function-call-arguments - - function-name - - single-identifier - - function-name: - - meta_include_prototype: false - - meta_content_scope: variable.function.tsql - - include: immediately-pop - - expressions-or-unknown: + inside-index-names-group: - meta_content_scope: meta.group.tsql - - match: \b(?i:unknown)\b - scope: keyword.other.tsql - match: \) scope: meta.group.tsql punctuation.section.group.end.tsql pop: 1 - - include: expressions + - include: comma-separators + - include: literals-and-variables + - include: ddl-table-creation-columns + - include: expect-index-names - index-names: + inside-optimize-for-group: - meta_content_scope: meta.group.tsql - match: \) scope: meta.group.tsql punctuation.section.group.end.tsql pop: 1 - - include: comma-separators - - include: literals-and-variables - - include: ddl-table-creation-columns - - include: expect-index-names + - match: \b(?i:unknown)\b + scope: keyword.other.tsql + - include: expressions + + with-group-assignment: + - include: with-group + - include: with-booleans + - include: else-pop + + with-other-assignment: + - match: (?=[,)]) + pop: 1 + - include: with-booleans + - include: expressions + + with-booleans: + - match: \b(?i:ON|OFF)\b + scope: constant.language.bool.tsql ###[ LIKE EXPRESSIONS ]######################################################## @@ -745,7 +742,9 @@ contexts: scope: keyword.other.tsql - match: \b(?i:ENCRYPTED\s+WITH)\b scope: storage.modifier.tsql - set: with-paren-or-pop + set: + - maybe-table-alias + - maybe-with-group - include: collate-expressions ###[ IDENTIFIERS ]############################################################# From 0711ff9bf6a20be5ee6afffd5a96f54482378ddb Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 5 Jul 2022 19:14:11 +0200 Subject: [PATCH 132/250] Reorganize T-SQL table-names-or-subquery Just move the whole set of contexts to logical position of SQL (basic). --- SQL/TSQL.sublime-syntax | 116 ++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 57 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 8f9815c8e5..d499e31b19 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -401,65 +401,8 @@ contexts: - include: operators - include: else-pop - table-name-or-subquery: - - meta_prepend: true - - match: \b(?i:OPENXML)\b - scope: meta.table-valued-function-name.sql support.function.tsql - push: - - maybe-with-column-definition - - function-call-arguments - - match: \b(?i:(OPENROWSET))\s*(\() - scope: meta.function-call.tsql - captures: - 1: meta.table-valued-function-name.sql support.function.tsql - 2: punctuation.section.arguments.begin.tsql - set: inside-openrowset-call - - inside-openrowset-call: - - meta_content_scope: meta.group.sql - - match: \) - scope: meta.function-call.tsql meta.group.tsql punctuation.section.arguments.end.sql - set: maybe-table-alias - - match: ';' - scope: punctuation.separator.sequence.tsql - - include: inside-function-call-arguments - - table-name-fail-if-function-cal: - - meta_prepend: true - - include: table-hints-without-with - - maybe-table-alias: - - meta_prepend: true - - include: with-table-options - - match: (?=\b(?i:unpivot|pivot)\b) - pop: 1 - - maybe-table-sample: - - meta_prepend: true - - include: groups # column-alias-list - - include: table-hints-without-with - - include: with-table-options - - table-hints-without-with: - - match: |- - (?xi) - (\()\s* - (NOLOCK|READUNCOMMITTED|UPDLOCK|REPEATABLEREAD|SERIALIZABLE|READCOMMITTED|TABLOCK|TABLOCKX|PAGLOCK|ROWLOCK|NOWAIT|READPAST|XLOCK|SNAPSHOT|NOEXPAND) - \s*(\)) - scope: meta.group.tsql invalid.deprecated.table-hint-without-with.tsql # https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-ver15#arguments - captures: - 1: punctuation.section.group.begin.tsql - 2: constant.language.table-hint.tsql - 3: punctuation.section.group.end.tsql - ###[ WITH EXPRESSIONS ]######################################################## - maybe-with-column-definition: - - match: \b(?i:with)\b - scope: keyword.other.tsql - set: ddl-table-creation-columns - - include: else-pop - maybe-with-table-options: - include: with-table-options - include: else-pop @@ -686,6 +629,65 @@ contexts: pop: 1 - include: like-else-fail +###[ TABLE NAMES ]############################################################# + + table-name-or-subquery: + - meta_prepend: true + - match: \b(?i:OPENXML)\b + scope: meta.table-valued-function-name.sql support.function.tsql + push: + - maybe-with-column-definition + - function-call-arguments + - match: \b(?i:(OPENROWSET))\s*(\() + scope: meta.function-call.tsql + captures: + 1: meta.table-valued-function-name.sql support.function.tsql + 2: punctuation.section.arguments.begin.tsql + set: inside-openrowset-call + + inside-openrowset-call: + - meta_content_scope: meta.group.sql + - match: \) + scope: meta.function-call.tsql meta.group.tsql punctuation.section.arguments.end.sql + set: maybe-table-alias + - match: ';' + scope: punctuation.separator.sequence.tsql + - include: inside-function-call-arguments + + table-name-fail-if-function-cal: + - meta_prepend: true + - include: table-hints-without-with + + maybe-table-alias: + - meta_prepend: true + - include: with-table-options + - match: (?=\b(?i:unpivot|pivot)\b) + pop: 1 + + maybe-table-sample: + - meta_prepend: true + - include: groups # column-alias-list + - include: table-hints-without-with + - include: with-table-options + + table-hints-without-with: + - match: |- + (?xi) + (\()\s* + (NOLOCK|READUNCOMMITTED|UPDLOCK|REPEATABLEREAD|SERIALIZABLE|READCOMMITTED|TABLOCK|TABLOCKX|PAGLOCK|ROWLOCK|NOWAIT|READPAST|XLOCK|SNAPSHOT|NOEXPAND) + \s*(\)) + scope: meta.group.tsql invalid.deprecated.table-hint-without-with.tsql # https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-ver15#arguments + captures: + 1: punctuation.section.group.begin.tsql + 2: constant.language.table-hint.tsql + 3: punctuation.section.group.end.tsql + + maybe-with-column-definition: + - match: \b(?i:with)\b + scope: keyword.other.tsql + set: ddl-table-creation-columns + - include: else-pop + ###[ TYPES ]################################################################### expect-type: From 7ee61549c6b9bb39f294ecbd65543e29d45cd05c Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 5 Jul 2022 20:12:18 +0200 Subject: [PATCH 133/250] Tweak T-SQL cursor declaration --- SQL/TSQL.sublime-syntax | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index d499e31b19..90dd0ab539 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -277,7 +277,7 @@ contexts: scope: keyword.other.sql - match: \b(?i:cursor)\b scope: support.type.tsql - push: cursor-declaration + push: inside-cursor-declaration - match: \b(?i:when\s+(?:not\s+)?matched)\b scope: keyword.control.conditional.case.sql push: merge-condition @@ -340,32 +340,34 @@ contexts: - meta_content_scope: variable.function.tsql - include: immediately-pop - cursor-declaration: + inside-cursor-declaration: - meta_content_scope: meta.cursor-declaration.tsql - - match: \b(?i:FORWARD_ONLY|SCROLL|STATIC|KEYSET|DYNAMIC|FAST_FORWARD|READ_ONLY|SCROLL_LOCKS|OPTIMISTIC|TYPE_WARNING)\b + - match: |- + \b(?xi: DYNAMIC | FAST_FORWARD | FORWARD_ONLY | KEYSET | OPTIMISTIC + | READ_ONLY | SCROLL | SCROLL_LOCKS | STATIC | TYPE_WARNING )\b scope: storage.modifier.tsql - match: \b(?i:for)\b scope: keyword.other.tsql - set: expect-cursor-select-statement + set: cursor-select-statement - include: else-pop - expect-cursor-select-statement: + cursor-select-statement: - meta_content_scope: meta.cursor-declaration.tsql - match: \b(?i:select)\b scope: keyword.other.dml.sql - set: after-cursor-select-statement + set: inside-cursor-select-statement - include: else-pop - after-cursor-select-statement: + inside-cursor-select-statement: - meta_content_scope: meta.cursor-declaration.tsql - match: \b(?i:for)\b scope: keyword.other.tsql - set: after-cursor-select-statement-for + set: after-cursor-select-statement - match: (?=\b(?i:open)\b) pop: 1 - - include: main + - include: sql - after-cursor-select-statement-for: + after-cursor-select-statement: - meta_scope: meta.cursor-declaration.tsql - match: \b(?i:READ\s+ONLY|UPDATE(?:\s+OF)?)\b scope: storage.modifier.tsql From 543c1eb81257d34cff25ca9e88eed230db8b8ba3 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 5 Jul 2022 21:01:40 +0200 Subject: [PATCH 134/250] Refactor variables 1. adjust code style 2. move word boundary checks to the `match` rules --- SQL/MySQL.sublime-syntax | 18 ++++++---------- SQL/PostgreSQL.sublime-syntax | 35 ++++++++++++------------------- SQL/SQL (basic).sublime-syntax | 38 +++++++++++++++++++--------------- SQL/TSQL.sublime-syntax | 38 ++++++++++++++++++++-------------- 4 files changed, 62 insertions(+), 67 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 045e226184..27575ff2a4 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -8,19 +8,13 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: simple_types: |- - (?xi: - \b - (?:bigint|bigserial|bit|bool|boolean|box|bytea|cidr|circle|date|datetime|double\s+precision|enum|inet|integer| - line|longtext|lseg|macaddr|money|ntext|oid|path|point|polygon|real|serial|smallint|sysdate|sysname|text|tinytext - ) - \b - ) + (?xi: bigint | bigserial | bit | bool | boolean | box | bytea | cidr | circle + | date | datetime | double\s+precision | enum | inet | integer | line + | longtext | lseg | macaddr | money | ntext | oid | path | point | polygon + | real | serial | smallint | sysdate | sysname | text | tinytext ) types_with_optional_number: |- - (?xi: - \b - (?:bit\s+varying|character\s+(?:varying)?|tinyint|var\schar|float|int|interval|numeric|decimal|times?|timestamp(?:s|tz)?) - \b - ) + (?xi: bit\s+varying | character\s+(?:varying)? | tinyint | var\s+char | float + | int | interval | numeric | decimal | times? | timestamp(?:s | tz)? ) contexts: sql: diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 863de0f6b2..15902fdba3 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -11,29 +11,20 @@ file_extensions: variables: simple_types: |- - (?xi: - \b - (?:smallint|integer|bigint|real|double\s+precision|smallserial|serial|bigserial| - money| - bytea| - times?|timestamp(?:s|tz)?|date|interval| - int4range|int8range|numrange|tsrange|tstzrange|daterange| - boolean| - point|line|lseg|box|path|polygon|circle| - cidr|inet|macaddr|macaddr8| - tsvector|tsquery| - uuid| - xml|jsonb?|text) - \b - ) + (?xi: smallint | integer | bigint | real | double\s+precision + | smallserial | serial | bigserial + | money + | bytea + | boolean + | times? | timestamp(?:s | tz)? | date | interval + | int4range | int8range | numrange | tsrange | tstzrange | daterange + | point | line | lseg | box | path | polygon | circle + | cidr | inet | macaddr | macaddr8 + | tsvector | tsquery + | uuid + | text | xml | jsonb? ) types_with_optional_number: |- - (?xi: - \b - (?:decimal|numeric| - character\s+varying|varchar|character|char| - bit|bit\s+varying) - \b - ) + (?xi: (?: bit | character ) (?:\s+varying)? | char | decimal | numeric | varchar ) contexts: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 1f10f91940..71164809ea 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -9,17 +9,23 @@ variables: string_escape: (?:\\.) simple_identifier: (?:\w+) simple_identifier_break: (?!\w) - reserved: (?:;|\b(?i:from|order|group|select|where|inner|outer|left|right|join|on|set|union|insert|delete|update|truncate|create|alter|drop|return)\b) + + reserved: |- + (?xi: alter | create | delete | drop | from | group | inner | insert + | join | left | on | order | outer | return | right | select | set + | truncate | union | update | where ) additional_reserved: (?!) - simple_types: (?i:\b(?:bit|bool|boolean|datetime|int)\b) - types_with_optional_number: (?i:\b(?:n?char|number|n?varchar|varbinary)\b) + ddl_target: |- - \b(?xi: - aggregate | constraint | conversion | database | domain | function | group - | (?:(?:fulltext | spatial | unique)\s+)?index | language | operator class - | operator | procedure | rule | schema | sequence | table(?:space)? - | trigger | type | user | view - )\b + (?xi: aggregate | constraint | conversion | database | domain | function + | group | (?: (?: fulltext | spatial | unique ) \s+ )?index | language + | operator\s+class | operator | procedure | rule | schema | sequence + | table(?:space)? | trigger | type | user | view ) + + simple_types: |- + (?xi: bit | bool | boolean | datetime | int ) + types_with_optional_number: |- + (?xi: number | n?(?:var)?char | varbinary ) contexts: prototype: @@ -170,7 +176,7 @@ contexts: - include: immediately-pop ddl-target: - - match: '{{ddl_target}}' + - match: \b{{ddl_target}}\b scope: keyword.other.sql - include: else-pop @@ -207,7 +213,7 @@ contexts: push: - expect-type - expect-column-name-declaration - - match: \b(?i:(?:add|alter))\b(?!\s+{{ddl_target}}) + - match: \b(?i:(?:add|alter))\b(?!\s+{{ddl_target}}\b) scope: keyword.other.ddl.sql push: - expect-type @@ -215,7 +221,7 @@ contexts: - match: \b(?i:drop\s+column)\b scope: keyword.other.ddl.sql push: expect-column-name - - match: \b(?i:drop)\b(?!\s+{{ddl_target}}) + - match: \b(?i:drop)\b(?!\s+{{ddl_target}}\b) scope: keyword.other.ddl.sql push: expect-column-name @@ -540,12 +546,12 @@ contexts: - include: expect-user-type built-in-type: - - match: '{{simple_types}}' + - match: \b{{simple_types}}\b scope: storage.type.sql pop: 1 - match: |- (?xi) - {{types_with_optional_number}} + \b{{types_with_optional_number}}\b (?:\s*\((\d+)(?:\s*(,)\s*(\d+))?\))? scope: storage.type.sql captures: @@ -867,7 +873,5 @@ contexts: pop: 1 pop-on-top-level-reserved-word: - - match: (?={{reserved}}|{{additional_reserved}}) - pop: 1 - - match: (?=\)) + - match: (?=[;)]|\b(?:{{reserved}}|{{additional_reserved}})\b) pop: 1 diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 90dd0ab539..c26df5a9cd 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -9,26 +9,29 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: string_escape: (?:'') simple_identifier_break: (?![\w#@]) - additional_reserved: \b(?i:if|while|declare|with|for|begin|end|else|print|use|raiserror|merge|backup|exec|go|bulk|insert|on|when)\b - enclosed_type_begin: (?:\[) - enclosed_type_end: (?:\]) + + additional_reserved: |- + (?xi: backup | begin | bulk | declare | else | end | exec | for | go | if + | insert | merge | on | print | raiserror | use | when | while | with ) + identifier_for_lookahead: |- (?x: (?:(?:\b\w+|\[[^]]+\])\.)* (?:\b\w+|\[[^]]+\]) ) + # types + + enclosed_type_begin: \[ + enclosed_type_end: \] + simple_types: |- - \b(?xi: - (?: bigint | bit | float | int | real | smallint | tinyint ) - | (?: date | datetime | datetime2 | datetimeoffset | smalldatetime | time ) - | (?: geometry | hierarchyid | image | n?text | rowversion | sql_variant | sysname | uniqueidentifier | xml ) - )\b + (?xi: bigint | bit | float | int | real | smallint | tinyint + | date | datetime | datetime2 | datetimeoffset | smalldatetime | time + | geometry | hierarchyid | image | n?text | rowversion | sql_variant + | sysname | uniqueidentifier | xml ) types_with_optional_number: |- - \b(?xi: - (?: n?char | n?varchar | binary | varbinary ) - | (?: decimal | money | numeric ) - )\b + (?xi: n?char | n?varchar | binary | varbinary | decimal | money | numeric ) contexts: @@ -673,12 +676,15 @@ contexts: - include: with-table-options table-hints-without-with: + # https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-ver15#arguments - match: |- (?xi) - (\()\s* - (NOLOCK|READUNCOMMITTED|UPDLOCK|REPEATABLEREAD|SERIALIZABLE|READCOMMITTED|TABLOCK|TABLOCKX|PAGLOCK|ROWLOCK|NOWAIT|READPAST|XLOCK|SNAPSHOT|NOEXPAND) - \s*(\)) - scope: meta.group.tsql invalid.deprecated.table-hint-without-with.tsql # https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-ver15#arguments + (\() \s* + ( NOLOCK | READUNCOMMITTED | UPDLOCK | REPEATABLEREAD | SERIALIZABLE + | READCOMMITTED | TABLOCK | TABLOCKX | PAGLOCK | ROWLOCK | NOWAIT + | READPAST | XLOCK | SNAPSHOT | NOEXPAND ) + \s* (\)) + scope: meta.group.tsql invalid.deprecated.table-hint-without-with.tsql captures: 1: punctuation.section.group.begin.tsql 2: constant.language.table-hint.tsql From e6ee23ffd653c9f13afbb48d872f550658d472e1 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 5 Jul 2022 21:19:41 +0200 Subject: [PATCH 135/250] Convert all case-insensitive patterns to lower-case Remove mixed cased patterns. --- SQL/PostgreSQL.sublime-syntax | 2 +- SQL/TSQL.sublime-syntax | 42 +++++++++++++++++------------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 15902fdba3..af3254b509 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -69,7 +69,7 @@ contexts: ddl-create-target-expect-as: - meta_prepend: true - - match: \b(?i:FOR\s+EACH\s+ROW\s+EXECUTE\s+PROCEDURE)\b + - match: \b(?i:for\s+each\s+row\s+execute\s+procedure)\b scope: keyword.other.psql - match: \b(?i:schema)\b scope: storage.modifier.psql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index c26df5a9cd..44eb523fc4 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -97,7 +97,7 @@ contexts: inside-ddl-table-creation-columns: - meta_prepend: true - - match: \b(?i:ROWGUIDCOL|CLUSTERED|NONCLUSTERED)\b + - match: \b(?i:rowguidcol|clustered|nonclustered)\b scope: storage.modifier.tsql - match: \b(?i:period\s+for\s+system_time)\b scope: storage.modifier.tsql @@ -289,10 +289,10 @@ contexts: built-in-scalar-function-calls: - meta_append: true - - match: \b(?i:CAST)\b + - match: \b(?i:cast)\b scope: support.function.tsql push: cast-arguments - - match: \b((?i:CONVERT))\s*(\() + - match: \b((?i:convert))\s*(\() scope: meta.function-call.sql captures: 1: support.function.scalar.sql @@ -300,7 +300,7 @@ contexts: push: - inside-convert-arguments - expect-type - - match: \b(?i:GETDATE)(?=\s*\() + - match: \b(?i:getdate)(?=\s*\() scope: support.function.scalar.sql push: function-call-arguments @@ -372,7 +372,7 @@ contexts: after-cursor-select-statement: - meta_scope: meta.cursor-declaration.tsql - - match: \b(?i:READ\s+ONLY|UPDATE(?:\s+OF)?)\b + - match: \b(?i:read\s+only|update(?:\s+of)?)\b scope: storage.modifier.tsql pop: 1 - include: else-pop @@ -433,29 +433,29 @@ contexts: - match: \) scope: punctuation.section.group.end.sql set: maybe-filegroup - - match: \b(?i:OPTIMIZE\s+FOR\s+UNKNOWN)\b + - match: \b(?i:optimize\s+for\s+unknown)\b scope: keyword.other.tsql - - match: \b((?i:OPTIMIZE\s+FOR))\s*(\() + - match: \b((?i:optimize\s+for))\s*(\() captures: 1: keyword.other.tsql 2: meta.group.tsql punctuation.section.group.begin.tsql push: inside-optimize-for-group - - match: \b((?i:INDEX|FORCESEEK))\s*(\() + - match: \b((?i:index|forceseek))\s*(\() captures: 1: keyword.other.tsql 2: meta.group.tsql punctuation.section.group.begin.tsql push: inside-index-names-group - - match: \b((?i:INDEX))\s*(=) + - match: \b((?i:index))\s*(=) captures: 1: keyword.other.tsql 2: keyword.operator.assignment.tsql push: expect-index-name - - match: \b((?i:SYSTEM_VERSIONING))\s*(=) + - match: \b((?i:system_versioning))\s*(=) captures: 1: keyword.other.tsql 2: keyword.operator.assignment.tsql push: with-group-assignment - - match: \b((?i:HISTORY_TABLE))\s*(=) + - match: \b((?i:history_table))\s*(=) captures: 1: keyword.other.tsql 2: keyword.operator.assignment.tsql @@ -468,7 +468,7 @@ contexts: - include: comma-separators maybe-filegroup: - - match: \b(?i:ON)\b(?!\s*{{identifier_for_lookahead}}\s*=) + - match: \b(?i:on)\b(?!\s*{{identifier_for_lookahead}}\s*=) scope: keyword.other.tsql set: expect-filegroup-name - include: else-pop @@ -504,7 +504,7 @@ contexts: - include: expressions with-booleans: - - match: \b(?i:ON|OFF)\b + - match: \b(?i:on|off)\b scope: constant.language.bool.tsql ###[ LIKE EXPRESSIONS ]######################################################## @@ -638,12 +638,12 @@ contexts: table-name-or-subquery: - meta_prepend: true - - match: \b(?i:OPENXML)\b + - match: \b(?i:openxml)\b scope: meta.table-valued-function-name.sql support.function.tsql push: - maybe-with-column-definition - function-call-arguments - - match: \b(?i:(OPENROWSET))\s*(\() + - match: \b(?i:(openrowset))\s*(\() scope: meta.function-call.tsql captures: 1: meta.table-valued-function-name.sql support.function.tsql @@ -680,9 +680,9 @@ contexts: - match: |- (?xi) (\() \s* - ( NOLOCK | READUNCOMMITTED | UPDLOCK | REPEATABLEREAD | SERIALIZABLE - | READCOMMITTED | TABLOCK | TABLOCKX | PAGLOCK | ROWLOCK | NOWAIT - | READPAST | XLOCK | SNAPSHOT | NOEXPAND ) + ( nolock | readuncommitted | updlock | repeatableread | serializable + | readcommitted | tablock | tablockx | paglock | rowlock | nowait + | readpast | xlock | snapshot | noexpand ) \s* (\)) scope: meta.group.tsql invalid.deprecated.table-hint-without-with.tsql captures: @@ -726,7 +726,7 @@ contexts: {{enclosed_type_begin}} {{types_with_optional_number}} {{enclosed_type_end}} - (?:\s*\(\s*(?:(\d+)|(MAX))\s*(?:(,)\s*(\d+))?\))? + (?:\s*\(\s*(?:(\d+)|(max))\s*(?:(,)\s*(\d+))?\))? scope: storage.type.sql captures: 1: constant.numeric.sql @@ -748,9 +748,9 @@ contexts: after-type: - meta_prepend: true - - match: \b(?i:GENERATED\s+ALWAYS\s+AS\s+ROW\s+(?:START|END)(?:\s+HIDDEN)?)\b + - match: \b(?i:generated\s+always\s+as\s+row\s+(?:start|end)(?:\s+hidden)?)\b scope: keyword.other.tsql - - match: \b(?i:ENCRYPTED\s+WITH)\b + - match: \b(?i:encrypted\s+with)\b scope: storage.modifier.tsql set: - maybe-table-alias From 6d913dc04ec7fbdf0b23f51c12b06fee1d619d79 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 5 Jul 2022 21:24:03 +0200 Subject: [PATCH 136/250] Fix T-SQL "alter" statement Current implementation skipped `ddl-alter-common` by prepending (?=\S) --- SQL/SQL (basic).sublime-syntax | 1 - SQL/TSQL.sublime-syntax | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 71164809ea..97e262a3bd 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -204,7 +204,6 @@ contexts: - expect-constraint-name - match: \b(?i:add\s+(?:(?:fulltext|spatial)\s+(index|key)|index))\b scope: meta.add.sql keyword.other.sql - #- include: types - include: pop-on-top-level-reserved-word ddl-alter-column: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 44eb523fc4..1aa21a6187 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -70,9 +70,8 @@ contexts: - ddl-target ddl-alter-target: - - meta_prepend: true - #- match: \b(?i:proc|procedure|function)\b - # scope: keyword.other.sql + - meta_scope: meta.alter.sql + - include: ddl-alter-common - match: (?=\S) set: - ddl-create-target-expect-as From 9e4dbf32ac572c4ab8d96d36b9fbfaf095842272 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Wed, 6 Jul 2022 17:14:28 +0200 Subject: [PATCH 137/250] Rename expressions-or-column-names to plural Indicate non-popping behavior --- SQL/SQL (basic).sublime-syntax | 10 +++++----- SQL/TSQL.sublime-syntax | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 97e262a3bd..d627e4f23c 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -37,7 +37,7 @@ contexts: sql: - include: statements - include: statement-terminators - - include: expressions-or-column-name + - include: expressions-or-column-names statements: - include: ddl-statements @@ -189,7 +189,7 @@ contexts: - meta_scope: meta.alter.sql - include: ddl-alter-column - include: ddl-alter-common - - include: expressions-or-column-name + - include: expressions-or-column-names ddl-alter-target: - meta_scope: meta.alter.sql @@ -306,7 +306,7 @@ contexts: ###[ EXPRESSIONS ]############################################################# - expressions-or-column-name: + expressions-or-column-names: - include: wildcard-identifiers - include: expressions - include: expect-column-names @@ -350,7 +350,7 @@ contexts: scope: keyword.control.conditional.then.sql - match: \b(?i:else)\b scope: keyword.control.conditional.else.sql - - include: expressions-or-column-name + - include: expressions-or-column-names collate-expressions: - match: \b(?i:collate)\b @@ -400,7 +400,7 @@ contexts: - match: ',' scope: punctuation.separator.arguments.sql - include: distinct - - include: expressions-or-column-name + - include: expressions-or-column-names maybe-group: - include: group diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 1aa21a6187..51c8cbd5f3 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -318,7 +318,7 @@ contexts: - match: \b(?i:as)\b scope: keyword.operator.assignment.tsql push: expect-type - - include: expressions-or-column-name + - include: expressions-or-column-names inside-convert-arguments: - meta_content_scope: meta.function-call.sql meta.group.sql @@ -327,7 +327,7 @@ contexts: pop: 1 - match: ',' scope: punctuation.separator.arguments.sql - - include: expressions-or-column-name + - include: expressions-or-column-names user-defined-function-calls: - meta_append: true @@ -709,7 +709,7 @@ contexts: pop: 1 - match: (?=\b(?i:constraint)\b) pop: 1 - - include: expressions-or-column-name + - include: expressions-or-column-names built-in-type: - meta_prepend: true From 0ed3589b7312aca04dcee73ca3f14e63b1473ae2 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Wed, 6 Jul 2022 17:20:46 +0200 Subject: [PATCH 138/250] Fix last computed column in group Missing `)` in bailout caused closing parentheses to be highlighted illegal. --- SQL/TSQL.sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_tsql.sql | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 51c8cbd5f3..3020103d6f 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -705,7 +705,7 @@ contexts: computed-column-definition: - meta_content_scope: meta.computed-column-definition.tsql - - match: (?=,) + - match: (?=[,)]) pop: 1 - match: (?=\b(?i:constraint)\b) pop: 1 diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index ec7b02c9a2..4e3b211f29 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1128,6 +1128,7 @@ GO CREATE TABLE dbo.T1 ( +-- <- meta.group.table-columns punctuation.section.group.begin column_1 AS 'Computed column ' + column_2, -- ^^^^^^^^ meta.column-name -- ^^ keyword.other @@ -1154,8 +1155,24 @@ CREATE TABLE dbo.T1 -- ^^^^^^^^ meta.column-name -- ^ - meta.column-name -- ^^^^^^^^^^ storage.type - column_4 varchar(40) NULL + column_4 varchar(40) NULL, +-- ^ - meta.column-name +-- ^^^^^^^^ meta.column-name +-- ^ - meta.column-name +-- ^^^^^^^^^^^ storage.type +-- ^^^^ constant.language.null +-- ^ punctuation.separator.sequence + column_5 as 'last computed' + column_2 +-- ^ - meta.column-name +-- ^^^^^^^^ meta.column-name +-- ^^^ - meta.column-name - meta.computed-column-definition +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.computed-column-definition +-- ^^ keyword.other.tsql +-- ^^^^^^^^^^^^^^^ string.quoted.single +-- ^ keyword.operator.arithmetic +-- ^^^^^^^^ meta.column-name.sql ); +-- <- meta.group.table-columns punctuation.section.group.end INSERT INTO T1 DEFAULT VALUES; -- ^^^^^^^^ keyword.other.dml -- ^^ meta.table-name From a58db1df21b5dae84b61e8ed0e1ad2db4ff69d2c Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Wed, 6 Jul 2022 17:30:36 +0200 Subject: [PATCH 139/250] Fix on/off boolean scopes and create reusable contexts --- SQL/TSQL.sublime-syntax | 22 ++++++++++++---------- SQL/tests/syntax/syntax_test_tsql.sql | 16 ++++++++-------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 3020103d6f..eb8147c02a 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -397,11 +397,9 @@ contexts: - match: \b(?i:identity_insert)\b scope: constant.language.switch.tsql push: expect-table-name - - match: \b(?i:on|off)\b - scope: constant.language.boolean.tsql + - include: onoff-constants - include: variables - - match: '[-+/*%^|]=' - scope: keyword.operator.assignment.tsql + - include: augmented-assignment-operators - include: operators - include: else-pop @@ -493,19 +491,15 @@ contexts: with-group-assignment: - include: with-group - - include: with-booleans + - include: onoff-constants - include: else-pop with-other-assignment: - match: (?=[,)]) pop: 1 - - include: with-booleans + - include: onoff-constants - include: expressions - with-booleans: - - match: \b(?i:on|off)\b - scope: constant.language.bool.tsql - ###[ LIKE EXPRESSIONS ]######################################################## like-expressions: @@ -858,6 +852,10 @@ contexts: - meta_prepend: true - include: variables + onoff-constants: + - match: \b(?i:on|off)\b + scope: constant.language.boolean.tsql + numbers: - meta_prepend: true - match: (0x)(\h+) @@ -895,3 +893,7 @@ contexts: - meta_append: true - match: '%' scope: keyword.operator.arithmetic.tsql + + augmented-assignment-operators: + - match: '[-+/*%^|]=' + scope: keyword.operator.assignment.tsql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 4e3b211f29..46455b2105 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1285,15 +1285,15 @@ CREATE TABLE [dbo].[be_Categories]( -- ^^^^ keyword.other.dml -- ^^^^^^^^^ constant.language.with -- ^ keyword.operator.assignment --- ^^^ constant.language.bool +-- ^^^ constant.language.boolean -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^^^^^ constant.language.with -- ^ keyword.operator.assignment --- ^^ constant.language.bool +-- ^^ constant.language.boolean -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^^^^^^ constant.language.with -- ^ keyword.operator.assignment --- ^^ constant.language.bool +-- ^^ constant.language.boolean -- ^ punctuation.section.group.end -- ^^ keyword.other -- ^^^^^^^^^ meta.filegroup-name @@ -1336,15 +1336,15 @@ CREATE TABLE [dbo].[table_with_constraint_following_derived_column]( -- ^^^^ keyword.other.dml -- ^^^^^^^^^ constant.language.with -- ^ keyword.operator.assignment --- ^^^ constant.language.bool +-- ^^^ constant.language.boolean -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^^^^^ constant.language.with -- ^ keyword.operator.assignment --- ^^ constant.language.bool +-- ^^ constant.language.boolean -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^^^^^^ constant.language.with -- ^ keyword.operator.assignment --- ^^ constant.language.bool +-- ^^ constant.language.boolean -- ^ punctuation.section.group.end -- ^^ keyword.other -- ^^^^^^^^^ meta.filegroup-name @@ -1868,7 +1868,7 @@ WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.Department_History, DATA_CONSI -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^^^^^^^ keyword.other -- ^ keyword.operator.assignment --- ^^ constant.language.bool +-- ^^ constant.language.boolean -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^^^ keyword.other -- ^ keyword.operator.assignment @@ -1876,7 +1876,7 @@ WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.Department_History, DATA_CONSI -- ^ punctuation.separator.sequence -- ^^^^^^^^^^^^^^^^^^^^^^ constant.language.with -- ^ keyword.operator.assignment --- ^^ constant.language.bool +-- ^^ constant.language.boolean -- ^ punctuation.section.group.end -- ^ punctuation.section.group.end -- ^ punctuation.terminator.statement From 3e58cb82b6f723c40dd61aa1ed3e64b2e94a05f6 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Thu, 7 Jul 2022 23:41:35 +0300 Subject: [PATCH 140/250] [SQL] Small context name typo fix --- SQL/SQL (basic).sublime-syntax | 4 ++-- SQL/TSQL.sublime-syntax | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index d627e4f23c..79b2d36ee5 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -444,11 +444,11 @@ contexts: - meta_include_prototype: false - match: '' set: - - table-name-fail-if-function-cal + - table-name-fail-if-function-call - table-name - single-identifier - table-name-fail-if-function-cal: + table-name-fail-if-function-call: - meta_include_prototype: false - match: (?=\() fail: table-or-table-function diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index eb8147c02a..ca61ffb71b 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -652,7 +652,7 @@ contexts: scope: punctuation.separator.sequence.tsql - include: inside-function-call-arguments - table-name-fail-if-function-cal: + table-name-fail-if-function-call: - meta_prepend: true - include: table-hints-without-with From 079980296ed0056502b01c7c460c920f5299fd9e Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 8 Jul 2022 18:47:39 +0200 Subject: [PATCH 141/250] Refactor column declaration lists Inspired by a missing bailout in `ddl-table-creation-columns` context this commit separates it into `column-declaration-list` and a `column-reference-list` in order to 1. properly scope column definitions and references different 2. fix/prevent possible syntax highlighting issues caused by the overridden context in T-SQL. Column references don't appear to support type information or file-groups following the reference list. As a `column-modifiers` section exists already, it is re-used to organize all column related contexts. Related contexts are moved to the relative position in all dialects. --- SQL/Cassandra.sublime-syntax | 34 +++++------ SQL/MySQL.sublime-syntax | 16 +++--- SQL/PostgreSQL.sublime-syntax | 12 ++-- SQL/SQL (basic).sublime-syntax | 78 +++++++++++++++----------- SQL/TSQL.sublime-syntax | 44 +++++++-------- SQL/tests/syntax/syntax_test_mysql.sql | 4 ++ 6 files changed, 105 insertions(+), 83 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 243751df7b..be129c83f4 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -34,7 +34,7 @@ contexts: scope: keyword.other.ddl.sql push: - ddl-create-target - - ddl-table-creation-columns + - maybe-column-declaration-list - ddl-create-type-condition ddl-alter-common: @@ -60,21 +60,6 @@ contexts: - meta_scope: meta.toc-list.full-identifier.sql entity.name.type.cql - include: immediately-pop - inside-ddl-table-creation-columns: - - meta_scope: meta.group.table-columns.sql - - match: \) - scope: punctuation.section.group.end.sql - pop: 1 - - match: \b(?i:(primary\s+key))\s*(\() - captures: - 1: storage.modifier.cql - 2: meta.group.partition-key.cql punctuation.section.group.begin.cql - push: inside-partition-key - - match: \b(?i:primary\s+key)\b - scope: storage.modifier.cql - - include: expressions - - include: ddl-creation-column - inside-partition-key: - meta_content_scope: meta.group.partition-key.cql - match: \) @@ -183,6 +168,23 @@ contexts: - match: '{{simple_identifier}}' scope: meta.mapping.key.cql string.unquoted.cql +###[ COLUMN DECLARATIONS ]##################################################### + + inside-column-declaration-list: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - match: \b(?i:(primary\s+key))\s*(\() + captures: + 1: storage.modifier.cql + 2: meta.group.partition-key.cql punctuation.section.group.begin.cql + push: inside-partition-key + - match: \b(?i:primary\s+key)\b + scope: storage.modifier.cql + - include: expressions + - include: column-declaration + ###[ TYPES ]################################################################### built-in-type: diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 27575ff2a4..15520eb7d9 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -93,13 +93,6 @@ contexts: pop: 1 - include: else-pop - inside-ddl-table-creation-columns: - - meta_prepend: true - - match: \b(?i:auto_increment)\b - scope: keyword.other.mysql - - match: (?i:\s*\b(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)\s+) - scope: keyword.other.object-comments.sql - ###[ DML STATEMENTS ]########################################################## dml-statements: @@ -138,6 +131,15 @@ contexts: pop: 1 - include: comments +###[ COLUMN DECLARATIONS ]##################################################### + + inside-column-declaration-list: + - meta_prepend: true + - match: \b(?i:auto_increment)\b + scope: keyword.other.mysql + - match: \b(?i:(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)) + scope: keyword.other.object-comments.sql + ###[ TYPES ]################################################################### after-type: diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index af3254b509..2097bfa73f 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -80,11 +80,6 @@ contexts: - match: \b(?i:extension|domain)\b scope: keyword.other.psql - inside-ddl-table-creation-columns: - - meta_prepend: true - - match: \b(?i:unique)\b - scope: keyword.other.psql - ###[ EXPRESSIONS ]############################################################# expressions: @@ -100,6 +95,13 @@ contexts: - match: \b(?i:return)\b scope: keyword.control.flow.return.psql +###[ COLUMN DECLARATIONS ]##################################################### + + inside-column-declaration-list: + - meta_prepend: true + - match: \b(?i:unique)\b + scope: keyword.other.psql + ###[ OPERATORS ]############################################################### operators: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 79b2d36ee5..dab76682be 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -93,7 +93,7 @@ contexts: scope: keyword.other.ddl.sql push: - ddl-create-target - - ddl-table-creation-columns + - maybe-column-declaration-list - create-table-condition - match: \b(?i:create)\b scope: keyword.other.ddl.sql @@ -122,31 +122,6 @@ contexts: - ddl-alter-target - ddl-target - ddl-table-creation-columns: - - match: \( - scope: punctuation.section.group.begin.sql - set: inside-ddl-table-creation-columns - - inside-ddl-table-creation-columns: - - meta_scope: meta.group.table-columns.sql - - match: \) - scope: punctuation.section.group.end.sql - pop: 1 - - match: \b(?i:constraint)\b - scope: storage.modifier.sql - push: expect-constraint-name - - include: column-modifiers - - include: expressions - - include: ddl-creation-column - - ddl-creation-column: - - match: (?=\S) - push: - - after-type - - expect-type - - column-name-declaration - - single-identifier - ddl-create-target: - meta_scope: meta.create.sql - include: ddl-target-on @@ -507,7 +482,36 @@ contexts: pop: 1 - include: else-pop -###[ COLUMN MODIFIERS ]######################################################## +###[ COLUMN DECLARATIONS ]##################################################### + + maybe-column-declaration-list: + - include: column-declaration-list + - include: else-pop + + column-declaration-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-column-declaration-list + + inside-column-declaration-list: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - match: \b(?i:constraint)\b + scope: storage.modifier.sql + push: expect-constraint-name + - include: column-modifiers + - include: expressions + - include: column-declaration + + column-declaration: + - match: (?=\S) + push: + - after-type + - expect-type + - column-name-declaration + - single-identifier maybe-column-modifier: - include: column-modifiers @@ -523,18 +527,28 @@ contexts: | default )\b scope: storage.modifier.sql - push: maybe-column-reference + push: maybe-column-reference-list - match: \b(?i:references)\b scope: storage.modifier.sql push: - - maybe-column-reference + - maybe-column-reference-list - expect-table-name - maybe-column-reference: + maybe-column-reference-list: + - include: column-reference-list + - include: else-pop + + column-reference-list: - match: \( scope: punctuation.section.group.begin.sql - set: inside-ddl-table-creation-columns - - include: else-pop + set: inside-column-reference-list + + inside-column-reference-list: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: expressions-or-column-names ###[ TYPES ]################################################################### diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index ca61ffb71b..e14c38ac2b 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -86,21 +86,6 @@ contexts: - match: \b(?i:proc|unique|clustered|nonclustered)\b scope: keyword.other.ddl.sql - ddl-table-creation-columns: - - match: \( - scope: punctuation.section.group.begin.sql - set: - - maybe-with-table-options - - maybe-filegroup - - inside-ddl-table-creation-columns - - inside-ddl-table-creation-columns: - - meta_prepend: true - - match: \b(?i:rowguidcol|clustered|nonclustered)\b - scope: storage.modifier.tsql - - match: \b(?i:period\s+for\s+system_time)\b - scope: storage.modifier.tsql - ###[ DML STATEMENTS ]########################################################## dml-statements: @@ -244,7 +229,7 @@ contexts: scope: keyword.other.dml.sql push: - cte-as - - cte-column-list + - maybe-column-reference-list - expect-cte-table-name - match: \b(?i:with)\b #(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) scope: keyword.other.dml.sql @@ -259,14 +244,10 @@ contexts: - match: ',' scope: punctuation.separator.sequence.cte.tsql push: - - cte-column-list + - maybe-column-reference-list - expect-cte-table-name - include: expressions - cte-column-list: - - include: ddl-table-creation-columns - - include: else-pop - ###[ EXPRESSIONS ]############################################################# expressions: @@ -476,8 +457,8 @@ contexts: scope: meta.group.tsql punctuation.section.group.end.tsql pop: 1 - include: comma-separators + - include: column-reference-list - include: literals-and-variables - - include: ddl-table-creation-columns - include: expect-index-names inside-optimize-for-group: @@ -686,9 +667,26 @@ contexts: maybe-with-column-definition: - match: \b(?i:with)\b scope: keyword.other.tsql - set: ddl-table-creation-columns + set: maybe-column-declaration-list - include: else-pop +###[ COLUMN DECLARATIONS ]##################################################### + + maybe-column-declaration-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: + - maybe-with-table-options + - maybe-filegroup + - inside-column-declaration-list + + inside-column-declaration-list: + - meta_prepend: true + - match: \b(?i:rowguidcol|clustered|nonclustered)\b + scope: storage.modifier.tsql + - match: \b(?i:period\s+for\s+system_time)\b + scope: storage.modifier.tsql + ###[ TYPES ]################################################################### expect-type: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 70698642eb..e655c2f9cb 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -21,8 +21,12 @@ SELECT "My -- Crazy Column Name" FROM my_table; SELECT "My /* Crazy Column Name" FROM my_table; -- ^^ - comment - punctuation +CREATE TABLE foo +-- ^^^^^^^^^ keyword.other.ddl +-- ^^^ entity.name.struct ;CREATE TABLE foo (id INTEGER PRIMARY KEY); +-- <- punctuation.terminator.statement.sql -- <- meta.create keyword.other.ddl --^^^^^ keyword.other.ddl -- ^^^^^ keyword.other From 10e4c1e06cce91a5b8f6c11306d99af12032d8bf Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 8 Jul 2022 20:37:30 +0200 Subject: [PATCH 142/250] Avoid including `main`. Even probably unlikely with SQL, the `main` context may be overridden by an inheriting syntax in order to prepend stuff like shebang or frontmatter. Thus it should never be included in the middle of the syntax. --- SQL/SQL (basic).sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index dab76682be..9e9d890b92 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -396,7 +396,7 @@ contexts: - match: \) scope: punctuation.section.group.end.sql pop: 1 - - include: main + - include: sql set: - include: else-pop From f8c096db8dc240cd95654564b511e75b515418e8 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 9 Jul 2022 11:43:17 +0200 Subject: [PATCH 143/250] T-SQL: Add missing keywords source: https://docs.microsoft.com/en-us/sql/t-sql/language-elements/control-of-flow?view=sql-server-ver16 Note: RETURN seems not supported by Casandra and is therefore removed from `reserved_words in SQL (basic). RETURN is defined in MySQL, thus not needed in PostresSQL, which is inherit from MySQL. --- SQL/MySQL.sublime-syntax | 11 ++- SQL/PostgreSQL.sublime-syntax | 4 +- SQL/SQL (basic).sublime-syntax | 8 +- SQL/TSQL.sublime-syntax | 72 +++++++++++----- SQL/tests/syntax/syntax_test_cassandra.cql | 6 +- SQL/tests/syntax/syntax_test_mysql.sql | 13 ++- SQL/tests/syntax/syntax_test_postgres.psql | 2 +- SQL/tests/syntax/syntax_test_tsql.sql | 95 +++++++++++++++++++--- 8 files changed, 162 insertions(+), 49 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 15520eb7d9..ef308c58af 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -7,6 +7,9 @@ version: 2 extends: Packages/SQL/SQL (basic).sublime-syntax variables: + additional_reserved: |- + (?xi: begin | end | return ) + simple_types: |- (?xi: bigint | bigserial | bit | bool | boolean | box | bytea | cidr | circle | date | datetime | double\s+precision | enum | inet | integer | line @@ -88,7 +91,7 @@ contexts: pop: 1 ddl-target-algorithm: - - match: \b(?i:MERGE|TEMPTABLE|UNDEFINED)\b + - match: \b(?i:merge|temptable|undefined)\b scope: keyword.other.mysql pop: 1 - include: else-pop @@ -114,12 +117,16 @@ contexts: - meta_prepend: true - match: \b(?i:begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b scope: keyword.other.luw.sql + - match: \b(?i:end)\b + scope: keyword.control.flow.end.sql + - match: \b(?i:return)\b + scope: keyword.control.flow.return.sql ###[ EXPRESSIONS ]############################################################# expressions: - meta_prepend: true - - match: \b(?i:CONCATENATE|CONVERT|LOWER|SUBSTRING|TRANSLATE|TRIM|UPPER)\b + - match: \b(?i:concatenate|convert|lower|substring|translate|trim|upper)\b scope: support.function.string.sql - match: \b(?i:using)\b scope: keyword.other.mysql diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 2097bfa73f..d7664f8435 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -84,7 +84,7 @@ contexts: expressions: - meta_prepend: true - - match: \b(?i:ARRAY)\b + - match: \b(?i:array)\b scope: keyword.declaration.psql - match: \[ scope: punctuation.section.brackets.begin.psql @@ -92,8 +92,6 @@ contexts: scope: punctuation.section.brackets.end.psql - match: ':(?!:)' scope: keyword.operator.range.psql - - match: \b(?i:return)\b - scope: keyword.control.flow.return.psql ###[ COLUMN DECLARATIONS ]##################################################### diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 9e9d890b92..c768290acf 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -11,9 +11,9 @@ variables: simple_identifier_break: (?!\w) reserved: |- - (?xi: alter | create | delete | drop | from | group | inner | insert - | join | left | on | order | outer | return | right | select | set - | truncate | union | update | where ) + (?xi: alter | create | delete | drop | from | group | inner | insert | join + | left | on | order | outer | right | select | set | truncate | union + | update | where ) additional_reserved: (?!) ddl_target: |- @@ -270,7 +270,7 @@ contexts: dml-condition: - match: \b(?i:if)\b - scope: keyword.control.flow.sql + scope: keyword.control.conditional.if.sql - include: logical-operators ###[ OTHER STATEMENTS ]######################################################## diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index e14c38ac2b..1c2361573c 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -11,8 +11,9 @@ variables: simple_identifier_break: (?![\w#@]) additional_reserved: |- - (?xi: backup | begin | bulk | declare | else | end | exec | for | go | if - | insert | merge | on | print | raiserror | use | when | while | with ) + (?xi: backup | begin | break | bulk | continue | declare | else | end + | exec(?:ute)? | for | go | if | insert | merge | on | print | raiserror + | return | throw | use | waitfor | when | while | with ) identifier_for_lookahead: |- (?x: @@ -164,28 +165,51 @@ contexts: other-statements: - meta_prepend: true + # context keywords - include: cte-with - - match: (?=\b(?i:raiserror)\b) - push: raiserror-args - - match: \b(?i:go)\b - scope: keyword.control.flow.tsql - - match: \b(?i:if|else|return|while)\b - scope: keyword.control.flow.tsql - - match: \b(?i:goto)\b - scope: keyword.control.flow.tsql - push: expect-label-name - - match: \b(?i:exec)\b - scope: keyword.control.flow.tsql - push: [expect-procedure-name, exec-args] + - match: \b(?i:(?:begin|commit|rollback|save)\s+tran(?:saction)?)\b + scope: keyword.context.tsql + - match: \b(?i:use)\b + scope: keyword.context.tsql + push: expect-database-name + # control flow keywords + - match: \b(?i:if)\b + scope: keyword.control.conditional.if.tsql + - match: \b(?i:else)\b + scope: keyword.control.conditional.else.tsql + - match: \b(?i:begin|end)\s+(?i:try|catch)\b + scope: keyword.control.exception.tsql + - match: \b(?i:while)\b + scope: keyword.control.loop.tsql - match: \b(?i:begin)\b scope: keyword.control.flow.begin.tsql + - match: \b(?i:break)\b + scope: keyword.control.flow.break.tsql + - match: \b(?i:continue)\b + scope: keyword.control.flow.continue.tsql - match: \b(?i:end)\b scope: keyword.control.flow.end.tsql + - match: \b(?i:exec(?:ute)?)\b + scope: keyword.control.flow.execute.tsql + push: [expect-procedure-name, execute-args] + - match: \b(?i:go)\b + scope: keyword.control.flow.go.tsql + - match: \b(?i:goto)\b + scope: keyword.control.flow.goto.tsql + push: expect-label-name + - match: \b(?i:return)\b + scope: keyword.control.flow.return.tsql + - match: \b(?i:throw)\b + scope: keyword.control.flow.throw.tsql + - match: \b(?i:waitfor)\b + scope: keyword.control.flow.waitfor.tsql + push: waitfor-args + # builtin funtions - match: \b(?i:print)\b - scope: keyword.other.tsql - - match: \b(?i:use)\b - scope: keyword.context.tsql - push: expect-database-name + scope: support.function.tsql + - match: (?=\b(?i:raiserror)\b) + push: raiserror-args + # other keywords - match: \b(?i:backup(?:\s+database)?)\b # https://docs.microsoft.com/en-us/sql/t-sql/statements/backup-transact-sql?view=sql-server-ver15 scope: keyword.other.tsql - match: \b(?i:to)\b @@ -201,10 +225,8 @@ contexts: captures: 1: entity.name.label.tsql 2: punctuation.definition.label.tsql - - match: (?i)\b(?:begin|commit|rollback|save)\s+tran(saction)?\b - scope: keyword.context.tsql - exec-args: + execute-args: - include: pop-on-top-level-reserved-word - include: assignment-operators - include: expressions @@ -222,6 +244,12 @@ contexts: scope: keyword.other.tsql - include: else-pop + waitfor-args: + - match: \b(?i:delay|time)\b + scope: storage.type.tsql + pop: 1 + - include: else-pop + ###[ CTE WITH STATEMENTS ]##################################################### cte-with: @@ -283,6 +311,8 @@ contexts: - match: \b(?i:getdate)(?=\s*\() scope: support.function.scalar.sql push: function-call-arguments + - match: \b(?i:user)\b + scope: support.function.scalar.sql cast-arguments: - meta_scope: meta.function-call.sql diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 997b3ef70f..b5190e8451 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -87,7 +87,7 @@ insert into something_by_countrycode (someid, countrycode) values (:someid, :cou CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create -- ^^^^^^^^^ keyword.other.ddl --- ^^ keyword.control.flow +-- ^^ keyword.control.conditional.if -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical -- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.struct @@ -210,7 +210,7 @@ CREATE TABLE IF NOT EXISTS date_by_userid ( DROP TABLE IF EXISTS userpermissions_by_userid; --^^^^^^^^^^^^^^^^^^^ meta.drop --^^^^^^^^ keyword.other.ddl --- ^^ keyword.control.flow +-- ^^ keyword.control.conditional.if -- ^^^^^^ keyword.operator.logical -- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement @@ -220,7 +220,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS --^^^^ keyword.other.ddl -- ^^^^^^^^^^^^ keyword.other -- ^^^^ keyword.other --- ^^ keyword.control.flow +-- ^^ keyword.control.conditional.if -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical -- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.other diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index e655c2f9cb..e8978c78fe 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -63,7 +63,7 @@ create table `dbo`."testing123" (id integer); create table IF NOT EXISTS `testing123` ( -- ^^^^^^^^^^^^^^^^^^^^^^^^ - meta.toc-list --- ^^ keyword.control.flow +-- ^^ keyword.control.conditional.if -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical `id` int(10) unsigned NOT NULL AUTO_INCREMENT, @@ -163,7 +163,7 @@ CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; create fulltext index if not exists `myindex` ON mytable; -- ^^^^^^^^^^^^^^ keyword.other.sql --- ^^ keyword.control.flow +-- ^^ keyword.control.conditional.if -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical -- ^^^^^^^^^ meta.toc-list.full-identifier entity.name.other @@ -187,7 +187,7 @@ ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); DROP TABLE IF EXISTS testing123; -- <- meta.drop.sql keyword.other.ddl.sql -- ^^^^^^^ meta.drop keyword.other.ddl --- ^^ meta.drop keyword.control.flow +-- ^^ meta.drop keyword.control.conditional.if -- ^^^^^^ keyword.operator.logical.sql -- ^^^^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement @@ -296,3 +296,10 @@ CREATE TEMPORARY TABLE IF NOT EXISTS foo ( bar NVARCHAR(400), baz INT ); + +CREATE FUNCTION myFunction(id INT) RETURNS TABLE +BEGIN + RETURN SELECT * FROM board; +-- ^^^^^^ keyword.control.flow.return +END +-- <- keyword.control.flow.end diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index 79bee07b14..005474879b 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -50,7 +50,7 @@ SELECT b, char_length(b) FROM test2; CREATE TABLE IF NOT EXISTS public.dropzone_details -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create -- ^^^^^^^^^ keyword.other.ddl --- ^^ keyword.control.flow +-- ^^ keyword.control.conditional.if -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.struct diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 46455b2105..1b9aba592a 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -268,7 +268,7 @@ FETCH NEXT FROM db_cursor INTO @name -- ^^^^^ variable.other.readwrite WHILE @@FETCH_STATUS = 0 --- ^^ keyword.control.flow +-- ^^ keyword.control.loop -- ^^^^^^^^^^^^^^ support.variable.global -- ^^ support.variable.global -- ^ keyword.operator.comparison @@ -328,7 +328,7 @@ SET NOCOUNT ON -- ^^^^^^^ constant.language.switch -- ^^ constant.language.boolean EXEC master.dbo.xp_fileexist @FromFile, @FileExists OUTPUT --- ^ keyword.control.flow +-- ^ keyword.control.flow.execute -- ^ - meta.procedure-name -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name -- ^ - meta.procedure-name @@ -344,7 +344,7 @@ IF @FileExists = 0 BEGIN RAISERROR ('File "%s" does not exist', 16, -1, @FromFile) RETURN -1 - -- ^^^ keyword.control.flow + -- ^^^ keyword.control.flow.return -- ^ keyword.operator.arithmetic -- ^ meta.number.integer.decimal constant.numeric.value END @@ -374,17 +374,19 @@ EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'every 10 @active_end_time=235959, @schedule_uid=N'564354f8-4985-7408-80b7-afdc2bb92d3c' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback --- ^^^^ keyword.control.flow +-- <- keyword.control.conditional +-- ^^^^ keyword.control.flow.goto -- ^ - meta.label-name -- ^^^^^^^^^^^^^^^^ meta.label-name -- ^ - meta.label-name EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' --- ^ keyword.control.flow +-- ^ keyword.control.flow.execute -- ^^^^^^^^^^^ variable.other.readwrite -- ^ keyword.operator.assignment -- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback COMMIT TRANSACTION +-- <- keyword.context -- ^^^^^^^^^^^^^^^ keyword.context GOTO EndSave QuitWithRollback: @@ -582,7 +584,7 @@ WHERE i.LocationID BETWEEN 3 AND 4 ORDER BY i.LocationID; PRINT 'Record with ID ' + CAST(@RecordID AS VARCHAR(10)) + ' has been updated.' --- ^^ keyword.other +-- ^^ support.function.tsql -- ^^^^^^^^^^^^^^^^^ string.quoted.single -- ^ keyword.operator.arithmetic -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call @@ -673,7 +675,7 @@ BEGIN END -- <- keyword.control.flow.end GO --- <- keyword.control.flow +-- <- keyword.control.flow.go --------------- ALTER PROC CreateOrAlterDemo @@ -865,7 +867,7 @@ CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)) -- ^ constant.numeric -- ^ punctuation.section.group.end GO --- <- keyword.control.flow +-- <- keyword.control.flow.go CREATE TABLE foo ([int] [int] PRIMARY KEY, [test'hello¬world'@"me"] [varchar] (5)); -- ^^^^^ storage.type -- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.column-name @@ -920,7 +922,7 @@ WITH ( ) -- <- punctuation.section.group.end IF @@ERROR != 0 --- <- keyword.control.flow +-- <- keyword.control.conditional -- ^^^^^^^ support.variable.global -- ^^ keyword.operator.comparison UPDATE tempdb..continue_script SET proceed = 0 @@ -1410,7 +1412,7 @@ RETURNS TABLE AS -- <- keyword.context.block RETURN --- ^^^ keyword.control.flow +-- ^^^ keyword.control.flow.return ( SELECT * FROM Employee E WHERE E.DepartmentID = @DeptID @@ -1602,7 +1604,7 @@ FROM OPENXML (@XmlDocumentHandle, '/ROOT/Customer',2) -- TODO: apply xpath -- ^^^^^^^^^^^ storage.type -- ^ punctuation.section.group.end EXEC sp_xml_removedocument @XmlDocumentHandle --- <- keyword.control.flow +-- <- keyword.control.flow.execute -- ^ - meta.procedure-name -- ^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name -- ^ - meta.procedure-name @@ -1611,7 +1613,7 @@ EXEC sp_xml_removedocument @XmlDocumentHandle --Create an internal representation of the XML document. EXEC sp_xml_preparedocument @idoc OUTPUT, @doc; --- <- keyword.control.flow +-- <- keyword.control.flow.execute -- ^ - meta.procedure-name -- ^^^^^^^^^^^^^^^^^^^^^^ meta.procedure-name -- ^ - meta.procedure-name @@ -1927,3 +1929,72 @@ ADD CONSTRAINT fk_inv_product_id ON DELETE CASCADE; -- ^^^^^^^^^^^^^^^^^ meta.alter storage.modifier -- ^ punctuation.terminator.statement + +BEGIN TRY +-- <- keyword.control.exception +-- ^^^^^^ keyword.control.exception + -- Generate divide-by-zero error. + SELECT 1/0; +END TRY +-- <- keyword.control.exception +-- ^^^^ keyword.control.exception +BEGIN CATCH +-- <- keyword.control.exception +-- ^^^^^^^^ keyword.control.exception + -- Execute error retrieval routine. + EXECUTE usp_GetErrorInfo; +END CATCH; +-- <- keyword.control.exception +-- ^^^^^^ keyword.control.exception + +BEGIN +-- <- keyword.control.flow.begin + WAITFOR DELAY '02:00'; +-- ^^^^^^^ keyword.control.flow.waitfor +-- ^^^^^ storage.type +-- ^^^^^^^ meta.string string.quoted.single +-- ^ punctuation.terminator.statement + EXECUTE sp_helpdb; +-- ^^^^^^^ keyword.control.flow.execute +-- ^^^^^^^^^ meta.procedure-name +END; + +BEGIN +-- <- keyword.control.flow.begin + WAITFOR TIME '22:20'; +-- ^^^^^^^ keyword.control.flow.waitfor +-- ^^^^ storage.type +-- ^^^^^^^ meta.string string.quoted.single +-- ^ punctuation.terminator.statement + EXECUTE sp_helpdb; +-- ^^^^^^^ keyword.control.flow.execute +-- ^^^^^^^^^ meta.procedure-name +END; + +IF DATENAME(weekday, GETDATE()) IN (N'Saturday', N'Sunday') +-- <- keyword.control.conditional +-- ^^^^^^^^ meta.function-call support.function +-- ^^^^^^^^^^^^^^^^^^^^ meta.function-call meta.group +-- ^^ keyword.operator.logical +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group + SELECT 'Weekend'; +-- ^^^^^^ keyword.other.dml +ELSE +-- <- keyword.control.conditional + SELECT 'Weekday'; +-- ^^^^^^ keyword.other.dml + +WHILE TRUE +-- <- keyword.control.loop + BREAK +-- ^^^^^ keyword.control.flow.break + CONTINUE +-- ^^^^^^^^ keyword.control.flow.continue +END +-- <- keyword.control.flow.end + + CURRENT_USER SESSION_USER SYSTEM_USER USER +-- ^^^^^^^^^^^^ support.function.scalar.sql +-- ^^^^^^^^^^^^ support.function.scalar.sql +-- ^^^^^^^^^^^ support.function.scalar.sql +-- ^^^^ support.function.scalar.sql From 7006e54769dbfb35cd4bd254a2369f2435bd1e96 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 10 Jul 2022 12:30:00 +0200 Subject: [PATCH 144/250] Sort identifier contexts alphabetically --- SQL/SQL (basic).sublime-syntax | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index c768290acf..4237df83aa 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -623,6 +623,18 @@ contexts: - match: (?=\S) set: [column-alias-name, single-identifier] + expect-constraint-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [constraint-name, single-identifier] + + constraint-name: + - meta_include_prototype: false + - meta_content_scope: meta.constraint-name.sql + - include: immediately-pop + column-alias-name: - meta_include_prototype: false - meta_content_scope: meta.column-alias.sql @@ -652,18 +664,6 @@ contexts: - meta_content_scope: meta.procedure-name.sql - include: immediately-pop - expect-constraint-name: - # prevent prototypes from inheriting syntaxes - - meta_include_prototype: false - - include: comments - - match: (?=\S) - set: [constraint-name, single-identifier] - - constraint-name: - - meta_include_prototype: false - - meta_content_scope: meta.constraint-name.sql - - include: immediately-pop - expect-schema-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false From 3ea6eb07c4fd877bd6fd9201ef94978461d62151 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 10 Jul 2022 15:37:53 +0200 Subject: [PATCH 145/250] Cassandra: Reorganize partition key contexts Moves `inside-partition-key` context to COLUMN DECLARATIONS section, because `inside-column-declaration-list` is the only context which uses it. --- SQL/Cassandra.sublime-syntax | 42 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index be129c83f4..a26cb9814c 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -60,27 +60,6 @@ contexts: - meta_scope: meta.toc-list.full-identifier.sql entity.name.type.cql - include: immediately-pop - inside-partition-key: - - meta_content_scope: meta.group.partition-key.cql - - match: \) - scope: meta.group.partition-key.cql punctuation.section.group.end.cql - pop: 1 - - match: \( - scope: punctuation.section.group.begin.cql - push: inside-partition-key-group - - match: ',' - scope: punctuation.separator.sequence.cql - set: inside-group - - include: expect-column-names - - inside-partition-key-group: - - match: \) - scope: punctuation.section.group.end.cql - pop: 1 - - match: ',' - scope: punctuation.separator.sequence.cql - - include: expect-column-names - ###[ DML STATEMENTS ]########################################################## dml-statements: @@ -185,6 +164,27 @@ contexts: - include: expressions - include: column-declaration + inside-partition-key: + - meta_content_scope: meta.group.partition-key.cql + - match: \) + scope: meta.group.partition-key.cql punctuation.section.group.end.cql + pop: 1 + - match: \( + scope: punctuation.section.group.begin.cql + push: inside-partition-key-group + - match: ',' + scope: punctuation.separator.sequence.cql + set: inside-group + - include: expect-column-names + + inside-partition-key-group: + - match: \) + scope: punctuation.section.group.end.cql + pop: 1 + - match: ',' + scope: punctuation.separator.sequence.cql + - include: expect-column-names + ###[ TYPES ]################################################################### built-in-type: From 5369bbbf14fac0593d00e6946607668db8172005 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 10 Jul 2022 11:02:14 +0200 Subject: [PATCH 146/250] Refactor ddl statements This commit designs ddl statement context structure to more closely following syntax sql architecture. Each ddl statement starts just with its CREATE/DROP/ALTER keyword, to avoid capture groups and introduce a `...-target` context which is used to implement dedicated code paths for each target as needed. Goal is to increase flexibility in adding new statements of different structure and to reduce risk of conflicts between dialects. Removes `meta.toc-list` to avoid mix of single-/multi-scopes in identifiers. Indexing is handled via `entity.name` and tmPreferences. --- SQL/Cassandra.sublime-syntax | 61 ++-- SQL/Indexed Symbol List.tmPreferences | 1 - SQL/MySQL.sublime-syntax | 55 +-- SQL/PostgreSQL.sublime-syntax | 160 ++++++++- SQL/SQL (basic).sublime-syntax | 400 +++++++++++++++------ SQL/Symbol List.tmPreferences | 12 + SQL/TSQL.sublime-syntax | 38 +- SQL/tests/syntax/syntax_test_cassandra.cql | 34 +- SQL/tests/syntax/syntax_test_mysql.sql | 73 ++-- SQL/tests/syntax/syntax_test_postgres.psql | 141 +++++++- SQL/tests/syntax/syntax_test_tsql.sql | 72 +++- 11 files changed, 791 insertions(+), 256 deletions(-) create mode 100644 SQL/Symbol List.tmPreferences diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index a26cb9814c..a10f43142f 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -11,6 +11,12 @@ file_extensions: - cql variables: + + ddl_target_procedure: |- + (?xi: function ) + ddl_target_other: |- + (?xi: keyspace | type | user | (?: materialized \s+ )? view ) + simple_types: |- \b(?xi: ASCII | BIGINT | BLOB | BOOLEAN | COUNTER | DATE | DECIMAL | DOUBLE @@ -18,47 +24,35 @@ variables: | TIMEUUID | TINYINT | UUID | VARCHAR | VARINT )\b types_with_optional_number: (?!) - ddl_target: |- - \b(?xi: - function | index | keyspace | table | type | user - | (?:materialized\s+)?view - )\b contexts: -###[ DDL STATEMENTS ]########################################################## +###[ DDL CREATE STATEMENTS ]################################################### - ddl-statements: + ddl-create-target: - meta_prepend: true - - match: \b(?i:create\s+type)\b + - include: ddl-create-type + + ddl-create-type: + - match: \b(?i:type)\b scope: keyword.other.ddl.sql push: - - ddl-create-target + - ddl-target-on - maybe-column-declaration-list + - expect-type-creation-name - ddl-create-type-condition - ddl-alter-common: - - meta_prepend: false + ddl-create-type-condition: + - include: ddl-condition + +###[ DDL STATEMENT PROTOTYPES ]################################################ - ddl-create-target: + ddl-target-on: - meta_prepend: true - - match: \b(?i:with)\b - scope: keyword.other.cql - match: \b(?i:clustering)\b scope: keyword.other.cql - - ddl-create-type-condition: - - include: dml-condition - - include: expect-type-creation-name - - expect-type-creation-name: - - match: (?=\S) - set: [type-creation-name, single-identifier] - - type-creation-name: - - meta_include_prototype: false - - meta_scope: meta.toc-list.full-identifier.sql entity.name.type.cql - - include: immediately-pop + - match: \b(?i:with)\b + scope: keyword.other.cql ###[ DML STATEMENTS ]########################################################## @@ -185,6 +179,19 @@ contexts: scope: punctuation.separator.sequence.cql - include: expect-column-names +###[ IDENTIFIERS ]############################################################# + + expect-type-creation-name: + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [type-creation-name, single-identifier] + + type-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.type.cql + - include: immediately-pop + ###[ TYPES ]################################################################### built-in-type: diff --git a/SQL/Indexed Symbol List.tmPreferences b/SQL/Indexed Symbol List.tmPreferences index a3e5d97a3f..f2fe506f31 100644 --- a/SQL/Indexed Symbol List.tmPreferences +++ b/SQL/Indexed Symbol List.tmPreferences @@ -1,5 +1,4 @@ - scope diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index ef308c58af..3128ae48ca 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -44,55 +44,56 @@ contexts: - match: \n pop: 1 -###[ DDL STATEMENTS ]########################################################## +###[ DDL CREATE STATEMENTS ]################################################### - ddl-statements: + ddl-create-statements: - meta_prepend: true - match: \b(?i:create\s+or\s+replace)\b scope: keyword.other.ddl.sql push: + - ddl-create-meta - ddl-create-target - - create-condition - - ddl-target - ddl-alter-table: + ddl-create-target: - meta_prepend: true - - match: \b(?i:change\s+column)\b + - include: ddl-target-algorithm + # index modifiers + - match: \b(?i:unique|fulltext|spatial)\b scope: keyword.other.ddl.sql - push: - - expect-type - - expect-column-name-declaration - - expect-column-name - ddl-target: + ddl-drop-target: - meta_prepend: true - - include: ddl-target-common + - include: ddl-target-algorithm - ddl-create-target: +###[ DDL ALTER STATEMENTS ]#################################################### + + ddl-alter-target: - meta_prepend: true - - include: ddl-target-common + - include: ddl-target-algorithm - create-condition: + ddl-alter-columns: - meta_prepend: true - - include: ddl-target-common + - match: \b(?i:(change)\s+(column))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + push: + - expect-type + - expect-column-name-declaration + - expect-column-name - ddl-target-common: - - match: \b(?i:on)\b - scope: keyword.other.mysql - push: expect-table-name - - match: \b(?i:using)\b - scope: keyword.other.mysql +###[ DDL STATEMENT PROTOTYPES ]################################################ + + ddl-target-algorithm: - match: \b(?i:(algorithm))\s*(=) captures: 1: keyword.other.mysql 2: keyword.operator.assignment.mysql - push: ddl-target-algorithm - - match: (?=\() - pop: 1 + push: ddl-target-algorithm-value - ddl-target-algorithm: + ddl-target-algorithm-value: - match: \b(?i:merge|temptable|undefined)\b - scope: keyword.other.mysql + scope: constant.language.sql pop: 1 - include: else-pop diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index d7664f8435..cb0802fd2f 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -32,11 +32,15 @@ contexts: - meta_prepend: true - include: declarations + statements: + - meta_prepend: true + - match: \$\$ + ###[ DECLARATIONS ]############################################################ declarations: - match: \b(?i:declare)\b - scope: keyword.declaration.variable.sql + scope: keyword.declaration.variable.psql push: inside-declaration inside-declaration: @@ -51,33 +55,101 @@ contexts: - meta_scope: variable.other.psql - include: immediately-pop -###[ DDL STATEMENTS ]########################################################## +###[ DDL CREATE STATEMENTS ]################################################### - ddl-statements: + ddl-create-target: - meta_prepend: true - - match: \$\$ + - include: ddl-create-extension + + ddl-create-extension: + # https://www.postgresql.org/docs/current/sql-createextension.html + - match: \b(?i:extension|domain)\b + scope: keyword.other.ddl.psql + set: + - ddl-target-as + - expect-extension-name-declaration + - ddl-create-extension-condition + + ddl-create-extension-condition: + - include: ddl-condition + +###[ DDL DROP STATEMENTS ]##################################################### + + ddl-drop-target: + - meta_prepend: true + # https://www.postgresql.org/docs/current/sql-dropextension.html + - match: \b(?i:extension|domain)\b + scope: keyword.other.ddl.psql + set: + - ddl-target-as + - ddl-drop-extension-name-list + - ddl-drop-extension-name + + ddl-drop-extension-name-list: + - match: ',' + scope: punctuation.separator.sequence.psql + push: expect-extension-name + - include: else-pop + + ddl-drop-extension-name: + - meta_include_prototype: false + - include: comments + - include: dml-condition + - include: expect-extension-name + +###[ DDL ALTER STATEMENTS ]#################################################### + + ddl-alter-target: + - meta_prepend: true + # https://www.postgresql.org/docs/current/sql-alterextension.html + - match: \b(?i:extension|domain)\b + scope: keyword.other.ddl.psql + set: + - ddl-alter-extension-args + - ddl-alter-extension-name + + ddl-alter-extension-name: + - meta_include_prototype: false + - include: expect-extension-name + + ddl-alter-extension-args: + - match: \b(?i:add|drop)\b + scope: keyword.other.ddl.sql + push: expect-member-name + - match: \b(?i:(set)\s+(schema))\b + captures: + 1: keyword.other.ddl.psql + 2: storage.modifier.psql + push: expect-schema-name + - match: \b(?i:(update)\s+(to))\b + captures: + 1: keyword.other.ddl.psql + 2: keyword.other.ddl.psql + - include: numbers + - include: else-pop ddl-alter-common: - meta_prepend: true - match: \b(?i:check)\b scope: keyword.other.psql - ddl-create-target: - - meta_prepend: true - - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b - scope: keyword.other.psql +###[ DDL STATEMENT PROTOTYPES ]################################################ - ddl-create-target-expect-as: + ddl-target-as: - meta_prepend: true - match: \b(?i:for\s+each\s+row\s+execute\s+procedure)\b scope: keyword.other.psql + - match: \b(?i:with)\b + scope: keyword.other.psql - match: \b(?i:schema)\b scope: storage.modifier.psql push: expect-schema-name + - match: \b(?i:version|cascade|restrict)\b + scope: storage.modifier.psql - ddl-target: + ddl-target-on: - meta_prepend: true - - match: \b(?i:extension|domain)\b + - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b scope: keyword.other.psql ###[ EXPRESSIONS ]############################################################# @@ -100,6 +172,68 @@ contexts: - match: \b(?i:unique)\b scope: keyword.other.psql +###[ IDENTIFIERS ]############################################################# + + expect-extension-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [extension-name, single-identifier] + + extension-name: + - meta_include_prototype: false + - meta_content_scope: meta.extension-name.psql + - include: immediately-pop + + expect-extension-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [extension-name-declaration, single-identifier] + + extension-name-declaration: + - meta_include_prototype: false + - meta_content_scope: entity.name.namespace.psql + - include: immediately-pop + + expect-member-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [member-name, single-identifier] + + member-name: + - meta_include_prototype: false + - meta_content_scope: meta.member-name.psql + - include: immediately-pop + + expect-member-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [member-name-declaration, single-identifier] + + member-name-declaration: + - meta_include_prototype: false + - meta_content_scope: entity.name.member.psql + - include: immediately-pop + + expect-schema-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [schema-name, single-identifier] + + schema-name: + - meta_include_prototype: false + - meta_content_scope: meta.schema-name.psql + - include: immediately-pop + ###[ OPERATORS ]############################################################### operators: @@ -117,11 +251,11 @@ contexts: expect-regexp: - match: \' - scope: meta.string.regexp.psql punctuation.definition.string.begin.sql + scope: meta.string.regexp.psql punctuation.definition.string.begin.psql embed: scope:source.regexp embed_scope: meta.string.regexp.psql escape: \' escape_captures: - 0: meta.string.regexp.psql punctuation.definition.string.end.sql + 0: meta.string.regexp.psql punctuation.definition.string.end.psql pop: 1 - include: else-pop diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 4237df83aa..f0f9fc7fd0 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -16,11 +16,22 @@ variables: | update | where ) additional_reserved: (?!) + # TODO: not all are supported by all dialects! ddl_target: |- - (?xi: aggregate | constraint | conversion | database | domain | function - | group | (?: (?: fulltext | spatial | unique ) \s+ )?index | language - | operator\s+class | operator | procedure | rule | schema | sequence - | table(?:space)? | trigger | type | user | view ) + (?xi: {{ddl_target_other}} | {{ddl_target_procedure}} + | (?: {{ddl_target_index_modifier}} \s+ )? index + | (?: {{ddl_target_table_modifier}} \s+ )? table ) + ddl_target_procedure: |- + (?xi: procedure | function ) + ddl_target_other: |- + (?xi: aggregate | constraint | conversion | database | domain | group + | language | operator\s+class | operator | rule | schema | sequence + | tablespace | trigger | type | user | view ) + + ddl_target_index_modifier: |- + (?xi: fulltext | spatial | unique ) + ddl_target_table_modifier: |- + (?xi: temp(?:orary)? ) simple_types: |- (?xi: bit | bool | boolean | datetime | int ) @@ -44,6 +55,11 @@ contexts: - include: dml-statements - include: other-statements + ddl-statements: + - include: ddl-create-statements + - include: ddl-drop-statements + - include: ddl-alter-statements + ###[ COMMENTS ]################################################################ comments: @@ -86,133 +102,275 @@ contexts: scope: punctuation.definition.comment.end.sql pop: 1 -###[ DDL STATEMENTS ]########################################################## +###[ DDL CREATE STATEMENTS ]################################################### - ddl-statements: - - match: \b(?i:create\s+(?:temporary\s+)?table)\b - scope: keyword.other.ddl.sql - push: - - ddl-create-target - - maybe-column-declaration-list - - create-table-condition + ddl-create-statements: - match: \b(?i:create)\b scope: keyword.other.ddl.sql push: - - ddl-create-target-expect-as + - ddl-create-meta - ddl-create-target - - create-other-condition - - ddl-target - - match: \b(?i:drop\s+table)\b + + ddl-create-meta: + - meta_include_prototype: false + - meta_scope: meta.create.sql + - include: immediately-pop + + ddl-create-target: + - include: ddl-create-index + - include: ddl-create-table + - include: ddl-create-procedure + - include: ddl-create-other + - include: else-pop + + ddl-create-index: + - match: \b(?xi:(?:({{ddl_target_index_modifier}})\s+)?(index))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - ddl-target-as + - ddl-target-on + - expect-index-creation-name + - ddl-create-index-condition + + ddl-create-index-condition: + - include: ddl-condition + + ddl-create-procedure: + - match: \b{{ddl_target_procedure}}\b scope: keyword.other.ddl.sql - push: ddl-drop-table + set: + - ddl-target-as + - expect-procedure-creation-name + - ddl-create-procedure-condition + + ddl-create-procedure-condition: + - include: ddl-condition + + ddl-create-table: + - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - ddl-target-on + - maybe-column-declaration-list + - expect-table-creation-name + - ddl-create-table-condition + + ddl-create-table-condition: + - include: ddl-condition + + ddl-create-other: + - match: \b{{ddl_target_other}}\b + scope: keyword.other.ddl.sql + set: + - ddl-target-as + - ddl-target-on + - expect-other-creation-name + - ddl-create-other-condition + + ddl-create-other-condition: + - include: ddl-condition + +###[ DDL DROP STATEMENTS ]##################################################### + + ddl-drop-statements: - match: \b(?i:drop)\b scope: keyword.other.ddl.sql push: + - ddl-drop-meta - ddl-drop-target - - drop-condition - - ddl-target - - match: \b(?i:alter\s+table)\b + + ddl-drop-meta: + - meta_include_prototype: false + - meta_scope: meta.drop.sql + - include: immediately-pop + + ddl-drop-target: + - include: ddl-drop-index + - include: ddl-drop-table + - include: ddl-drop-procedure + - include: ddl-drop-other + - include: else-pop + + ddl-drop-index: + - match: \b(?i:index)\b scope: keyword.other.ddl.sql - push: - - ddl-alter-table + set: + - expect-index-name + - ddl-drop-index-condition + + ddl-drop-index-condition: + - include: ddl-condition + + ddl-drop-procedure: + - match: \b{{ddl_target_procedure}}\b + scope: keyword.other.ddl.sql + set: + - expect-procedure-name + - ddl-drop-procedure-condition + + ddl-drop-procedure-condition: + - include: ddl-condition + + ddl-drop-table: + - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: - expect-table-name - - match: \b(?i:alter)\b + - ddl-drop-table-condition + + ddl-drop-table-condition: + - include: ddl-condition + + ddl-drop-other: + - match: \b{{ddl_target_other}}\b scope: keyword.other.ddl.sql - push: - - ddl-alter-target - - ddl-target + set: + - ddl-target-on + - expect-other-name + - ddl-drop-other-condition - ddl-create-target: - - meta_scope: meta.create.sql - - include: ddl-target-on + ddl-drop-other-condition: + - include: ddl-condition - ddl-create-target-expect-as: - - match: \b(?i:as)\b - scope: keyword.context.block.sql - pop: 1 - - match: \b(?i:returns)\b - scope: keyword.other.sql - push: expect-type - - match: (@){{simple_identifier}} - scope: variable.parameter.sql - push: expect-type - - include: expressions - - include: pop-on-top-level-reserved-word +###[ DDL ALTER STATEMENTS ]#################################################### - ddl-target-on: - - match: \b(?i:on)\b - scope: keyword.other.sql - push: expect-table-name - - include: else-pop + ddl-alter-statements: + - match: \b(?i:alter)\b + scope: keyword.other.ddl.sql + push: + - ddl-alter-meta + - ddl-alter-target - ddl-drop-target: + ddl-alter-meta: - meta_include_prototype: false - - meta_scope: meta.drop.sql + - meta_scope: meta.alter.sql - include: immediately-pop - ddl-target: - - match: \b{{ddl_target}}\b - scope: keyword.other.sql + ddl-alter-target: + - include: ddl-alter-index + - include: ddl-alter-table + - include: ddl-alter-procedure + - include: ddl-alter-other - include: else-pop - ddl-drop-table: - - meta_scope: meta.drop.sql - - include: dml-condition - - include: expect-table-name + ddl-alter-index: + - match: \b(?:({{ddl_target_index_modifier}})\s+)?(index)\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - ddl-alter-other-args + - expect-index-name + - ddl-alter-index-condition + + ddl-alter-index-condition: + - include: ddl-condition + + ddl-alter-procedure: + - match: \b{{ddl_target_procedure}}\b + scope: keyword.other.ddl.sql + set: + - ddl-target-as + - expect-procedure-name + - ddl-alter-procedure-condition + + ddl-alter-procedure-condition: + - include: ddl-condition ddl-alter-table: - - meta_scope: meta.alter.sql - - include: ddl-alter-column + - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - ddl-alter-table-args + - expect-table-name + - ddl-alter-table-condition + + ddl-alter-table-condition: + - include: ddl-condition + + ddl-alter-table-args: + - include: ddl-alter-columns - include: ddl-alter-common + - include: pop-on-top-level-reserved-word - include: expressions-or-column-names - ddl-alter-target: - - meta_scope: meta.alter.sql + ddl-alter-other: + - match: \b{{ddl_target_other}}\b + scope: keyword.other.ddl.sql + set: + - ddl-alter-other-args + - expect-other-name + - ddl-alter-other-condition + + ddl-alter-other-condition: + - include: ddl-condition + + ddl-alter-other-args: - include: ddl-alter-common - include: else-pop - ddl-alter-common: - - match: \b(?i:add\s+constraint)\b - scope: meta.add.sql keyword.other.sql - push: - - maybe-column-modifier - - expect-constraint-name - - match: \b(?i:add\s+(?:(?:fulltext|spatial)\s+(index|key)|index))\b - scope: meta.add.sql keyword.other.sql - - include: pop-on-top-level-reserved-word - - ddl-alter-column: - - match: \b(?i:(?:add|alter)\s+column)\b - scope: keyword.other.ddl.sql - push: - - expect-type - - expect-column-name-declaration - - match: \b(?i:(?:add|alter))\b(?!\s+{{ddl_target}}\b) - scope: keyword.other.ddl.sql + ddl-alter-columns: + - match: \b(?i:(add|alter)(?:\s+(column)|(?!\s+{{ddl_target}})))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql push: - expect-type - expect-column-name-declaration - - match: \b(?i:drop\s+column)\b - scope: keyword.other.ddl.sql - push: expect-column-name - - match: \b(?i:drop)\b(?!\s+{{ddl_target}}\b) + - match: \b(?i:(drop)(?:\s+(column)|(?!\s+{{ddl_target}})))\b scope: keyword.other.ddl.sql push: expect-column-name - create-other-condition: - - include: dml-condition - - include: expect-other-creation-name + ddl-alter-common: + - match: \b(?i:(add)\s+(constraint))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + push: + - maybe-column-modifier + - expect-constraint-name + - match: \b(?i:(add)\s+(?:({{ddl_target_index_modifier}})\s+)?(index))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + 3: keyword.other.ddl.sql + - match: \b(?i:(add)\s+(primary|foreign)\s+(key))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + 3: keyword.other.ddl.sql - create-table-condition: - - include: dml-condition - - include: expect-table-creation-name +###[ DDL STATEMENT PROTOTYPES ]################################################ - drop-condition: - - include: dml-condition - - match: (?=\S) - set: - - ddl-target-on - - single-identifier + ddl-condition: + - match: \b(?i:if)\b + scope: keyword.control.conditional.if.sql + - include: logical-operators + - include: else-pop + + ddl-target-as: + - match: \b(?i:as)\b + scope: keyword.context.block.sql + pop: 1 + - match: \b(?i:returns)\b + scope: keyword.other.sql + push: expect-type + - include: expressions + - include: pop-on-top-level-reserved-word + + ddl-target-on: + - match: \b(?i:on)\b + scope: keyword.other.sql + push: expect-table-name + - include: else-pop ###[ DML STATEMENTS ]########################################################## @@ -652,28 +810,52 @@ contexts: - meta_content_scope: meta.database-name.sql - include: immediately-pop - expect-procedure-name: + expect-index-creation-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false - include: comments - match: (?=\S) - set: [procedure-name, single-identifier] + set: [index-creation-name, single-identifier] - procedure-name: + index-creation-name: - meta_include_prototype: false - - meta_content_scope: meta.procedure-name.sql + - meta_scope: entity.name.struct.index.sql + - include: immediately-pop + + expect-index-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [index-name, single-identifier] + + index-name: + - meta_include_prototype: false + - meta_scope: meta.index-name.sql - include: immediately-pop - expect-schema-name: + expect-procedure-creation-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false - include: comments - match: (?=\S) - set: [schema-name, single-identifier] + set: [procedure-creation-name, single-identifier] - schema-name: + procedure-creation-name: - meta_include_prototype: false - - meta_content_scope: meta.schema-name.sql + - meta_content_scope: entity.name.function.sql + - include: immediately-pop + + expect-procedure-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [procedure-name, single-identifier] + + procedure-name: + - meta_include_prototype: false + - meta_content_scope: meta.procedure-name.sql - include: immediately-pop expect-table-creation-name: @@ -685,7 +867,7 @@ contexts: table-creation-name: - meta_include_prototype: false - - meta_scope: meta.toc-list.full-identifier.sql entity.name.struct.sql + - meta_scope: entity.name.struct.table.sql - include: immediately-pop expect-table-name: @@ -721,7 +903,19 @@ contexts: other-creation-name: - meta_include_prototype: false - - meta_scope: meta.toc-list.full-identifier.sql entity.name.other.sql + - meta_scope: entity.name.struct.other.sql + - include: immediately-pop + + expect-other-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [other-name, single-identifier] + + other-name: + - meta_include_prototype: false + - meta_scope: meta.other-name.sql - include: immediately-pop single-identifier: diff --git a/SQL/Symbol List.tmPreferences b/SQL/Symbol List.tmPreferences new file mode 100644 index 0000000000..79be334003 --- /dev/null +++ b/SQL/Symbol List.tmPreferences @@ -0,0 +1,12 @@ + + + + scope + source.sql entity.name.struct + settings + + showInSymbolList + 1 + + + diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 1c2361573c..0a76522f19 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -21,6 +21,9 @@ variables: (?:\b\w+|\[[^]]+\]) ) + ddl_target_procedure: |- + (?xi: proc(?:edure)? | func(?:tion)? ) + # types enclosed_type_begin: \[ @@ -58,34 +61,29 @@ contexts: set: expect-type - include: else-pop -###[ DDL STATEMENTS ]########################################################## +###[ DDL CREATE STATEMENTS ]################################################### - ddl-statements: - - meta_prepend: true - - match: (?i)\b(?:create(?:\s+or\s+alter)?)\b(?!\s*table\b) + ddl-create-statements: + - match: \b(?i:create(?:\s+or\s+alter)?)\b scope: keyword.other.ddl.sql push: - - ddl-create-target-expect-as + - ddl-create-meta - ddl-create-target - - create-table-condition - - ddl-target - - ddl-alter-target: - - meta_scope: meta.alter.sql - - include: ddl-alter-common - - match: (?=\S) - set: - - ddl-create-target-expect-as - - expect-procedure-name - ddl-create-target-expect-as: + ddl-create-target: - meta_prepend: true - - include: with-table-options + # modifiers + - match: \b(?i:unique|clustered|nonclustered)\b + scope: keyword.other.ddl.sql + +###[ DDL STATEMENT PROTOTYPES ]################################################ - ddl-target: + ddl-target-as: - meta_prepend: true - - match: \b(?i:proc|unique|clustered|nonclustered)\b - scope: keyword.other.ddl.sql + - include: with-table-options + - match: (@){{simple_identifier}} + scope: variable.parameter.sql + push: expect-type ###[ DML STATEMENTS ]########################################################## diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index b5190e8451..41a16a67f0 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -4,7 +4,7 @@ CREATE KEYSPACE killrvideo WITH replication = {'class':'SimpleStrategy', 'replic --^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create --^^^^ keyword.other.ddl -- ^^^^^^^^ keyword.other --- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.other +-- ^^^^^^^^^^ entity.name.struct.other -- ^^^^ keyword.other -- ^ keyword.operator -- ^ punctuation.section.braces.begin @@ -86,11 +86,12 @@ insert into something_by_countrycode (someid, countrycode) values (:someid, :cou CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create --- ^^^^^^^^^ keyword.other.ddl +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl -- ^^ keyword.control.conditional.if -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical --- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.struct +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.struct -- ^ meta.group.table-columns punctuation.section.group.begin userid uuid, -- ^^^^^^^^^^^^^ meta.create meta.group.table-columns @@ -208,22 +209,25 @@ CREATE TABLE IF NOT EXISTS date_by_userid ( DROP TABLE IF EXISTS userpermissions_by_userid; ---^^^^^^^^^^^^^^^^^^^ meta.drop ---^^^^^^^^ keyword.other.ddl +-- <- meta.drop.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop.sql +-- ^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl -- ^^ keyword.control.conditional.if -- ^^^^^^ keyword.operator.logical -- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- <- meta.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql --^^^^ keyword.other.ddl --- ^^^^^^^^^^^^ keyword.other --- ^^^^ keyword.other +-- ^^^^^^^^^^^^ keyword.other.ddl +-- ^^^^ keyword.other.ddl -- ^^ keyword.control.conditional.if -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical --- ^^^^^^^^^^ meta.toc-list.full-identifier entity.name.other +-- ^^^^^^^^^^ entity.name.struct.other -- ^^ keyword.context.block SELECT * -- ^^^^^^ keyword.other.dml @@ -249,7 +253,7 @@ CREATE TYPE user_defined_type ( --^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create --^^^^ keyword.other.ddl -- ^^^^ keyword.other --- ^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.type +-- ^^^^^^^^^^^^^^^^^ entity.name.type -- ^ meta.group punctuation.section.group.begin type1 timestamp, -- ^^^^^ meta.column-name variable.other.member.declaration @@ -330,8 +334,10 @@ PRIMARY KEY (entityid, datecreated, somefield) -- ^ punctuation.terminator.statement ALTER TABLE someentity_by_somefield add usefulfield text; --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter --- ^^^^^^^^ keyword.other.ddl +-- <- meta.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^^^ keyword.other.ddl -- ^^^^^^^^^^^ meta.column-name @@ -419,9 +425,11 @@ CREATE TABLE myschema.users ( ); CREATE INDEX user_state +-- <- meta.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^ meta.create.sql -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other --- ^^^^^^^^^^ meta.toc-list.full-identifier +-- ^^^^^^^^^^ entity.name.struct.index.sql ON myschema.users (state); -- ^^ keyword.other -- ^^^^^^^^^^^^^^ meta.table-name diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index e8978c78fe..aa143554a5 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -22,8 +22,13 @@ SELECT "My /* Crazy Column Name" FROM my_table; -- ^^ - comment - punctuation CREATE TABLE foo --- ^^^^^^^^^ keyword.other.ddl --- ^^^ entity.name.struct +-- <- meta.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl +-- ^ - keyword +-- ^^^^^ keyword.other.ddl +-- ^ - keyword +-- ^^^ entity.name.struct.table.sql ;CREATE TABLE foo (id INTEGER PRIMARY KEY); -- <- punctuation.terminator.statement.sql @@ -138,18 +143,27 @@ create table fancy_table ( ); CREATE INDEX ON fancy_table(mytime); --- ^^^^^ keyword.other.sql +-- <- meta.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^^^ keyword.other.ddl -- ^^ keyword.other -- ^^^^^^^^^^^ meta.table-name CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); --- ^^^^^ keyword.other.sql +-- <- meta.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl -- ^^ keyword.other -- ^^^^^^^^^^^ meta.table-name -- ^^^^^ keyword.other CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; --- ^^^^^^^^^^^^ keyword.other.sql +-- <- meta.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl +-- ^^^^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl -- ^^ meta.create keyword.other -- ^^^^^^^^^^^ meta.table-name -- ^ meta.group punctuation.section.group.begin @@ -162,32 +176,42 @@ CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; -- ^^^^ constant.language.null.sql create fulltext index if not exists `myindex` ON mytable; --- ^^^^^^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl -- ^^ keyword.control.conditional.if -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical --- ^^^^^^^^^ meta.toc-list.full-identifier entity.name.other +-- ^^^^^^^^^ entity.name.struct.index -- ^^ keyword.other -- ^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; --- ^^^^^^^^ meta.alter keyword.other.ddl --- ^^^ keyword.other.ddl.sql --- ^^^^^^ keyword.other.ddl.sql +-- <- meta.alter.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- ^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^^ keyword.other.ddl +-- ^^^^^^ keyword.other.ddl -- ^^^^^^^^ meta.column-name -- ^^^^^^^^ storage.type.sql ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); --- ^^^^^^^^^^^^^ meta.alter keyword.other.ddl +-- <- meta.alter.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- ^^^^^^ keyword.other.ddl +-- ^^^^^^ keyword.other.ddl -- ^^^^^^^^ meta.column-name -- ^^^^^^^^ meta.column-name variable.other.member.declaration -- ^^^^ storage.type.sql DROP TABLE IF EXISTS testing123; --- <- meta.drop.sql keyword.other.ddl.sql --- ^^^^^^^ meta.drop keyword.other.ddl --- ^^ meta.drop keyword.control.conditional.if +-- <- meta.drop.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop.sql +-- ^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.control.conditional.if.sql -- ^^^^^^ keyword.operator.logical.sql -- ^^^^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement @@ -251,8 +275,8 @@ WHERE f.a IS NULL CREATE INDEX IX_some_index ON dbo.some_table( -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create -- ^^^ keyword.other.ddl --- ^^^^^ keyword.other --- ^^^^^^^^^^^^^ meta.toc-list.full-identifier +-- ^^^^^ keyword.other.ddl +-- ^^^^^^^^^^^^^ entity.name.struct.index -- ^^ keyword.other -- ^^^^^^^^^^^^^^ meta.table-name -- ^ meta.group punctuation.section.group.begin @@ -266,9 +290,9 @@ CREATE ALGORITHM=MERGE VIEW contactPersons( -- ^^^ keyword.other.ddl -- ^^^^^^^^^ keyword.other -- ^ keyword.operator.assignment --- ^^^^^ keyword.other --- ^^^^ keyword.other --- ^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.other +-- ^^^^^ constant.language +-- ^^^^ keyword.other.ddl +-- ^^^^^^^^^^^^^^ entity.name.struct.other -- ^ meta.group punctuation.section.group.begin customerName, -- ^^^^^^^^^^^^ meta.group meta.column-name @@ -291,8 +315,15 @@ FROM customers; -- ^ punctuation.terminator.statement CREATE TEMPORARY TABLE IF NOT EXISTS foo ( --- ^^^^^^^^^^^^^^^^^^^ meta.create keyword.other.ddl --- ^^^ meta.toc-list.full-identifier entity.name.struct +-- <- meta.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^ entity.name.struct.table bar NVARCHAR(400), baz INT ); diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index 005474879b..9f92703ca5 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -1,9 +1,11 @@ -- SYNTAX TEST "Packages/SQL/PostgreSQL.sublime-syntax" CREATE TABLE test1 (a character(4)); +-- <- meta.create.sql keyword.other.ddl -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create --- ^^^^^^^^^ keyword.other.ddl --- ^^^^^ meta.toc-list.full-identifier entity.name.struct +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^^^^ entity.name.struct.table -- ^^^^^^^^^^^^^^^^ meta.group.table-columns -- ^ punctuation.terminator.statement -- ^ punctuation.section.group.begin @@ -28,8 +30,9 @@ SELECT a, char_length(a) FROM test1; CREATE TABLE test2 (b varchar(5)); -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create --- ^^^^^^^^^ keyword.other.ddl --- ^^^^^ meta.toc-list.full-identifier entity.name.struct +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^^^^ entity.name.struct -- ^^^^^^^^^^^^^^ meta.group.table-columns -- ^ punctuation.terminator.statement -- ^ punctuation.section.group.begin @@ -49,11 +52,12 @@ SELECT b, char_length(b) FROM test2; CREATE TABLE IF NOT EXISTS public.dropzone_details -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create --- ^^^^^^^^^ keyword.other.ddl +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl -- ^^ keyword.control.conditional.if -- ^^^ keyword.operator.logical -- ^^^^^^ keyword.operator.logical --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.struct +-- ^^^^^^^^^^^^^^^^^^^^^^^ entity.name.struct -- ^ punctuation.accessor.dot ( -- <- meta.create meta.group.table-columns punctuation.section.group.begin @@ -103,7 +107,7 @@ SELECT 'abc \153\154\155 \052\251\124'::bytea; CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); -- ^^^ meta.create keyword.other.ddl -- ^^^^ meta.create keyword.other --- ^^^^ meta.create meta.toc-list.full-identifier entity.name +-- ^^^^ meta.create entity.name -- ^^ keyword.context.block CREATE TABLE person ( name text, @@ -202,14 +206,117 @@ SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; -- ^^^^ keyword.other.dml -- ^^^^^^^ meta.table-name + +-- ----------------- +-- CREATE EXTENSION +-- https://www.postgresql.org/docs/current/sql-createextension.html +-- ----------------- + CREATE EXTENSION hstore SCHEMA addons; --- ^^^ meta.create keyword.other.ddl --- ^^^^^^^^^ meta.create keyword.other --- ^^^^^^ meta.create meta.toc-list.full-identifier entity.name.other +-- <- meta.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^ keyword.other.ddl +-- ^^^^^^ entity.name.namespace.psql -- ^^^^^^ storage.modifier -- ^^^^^^ meta.schema-name -- ^ punctuation.terminator.statement +CREATE EXTENSION IF NOT EXISTS extension_name WITH SCHEMA schema_name VERSION 1.0 CASCADE; +-- <- meta.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^ entity.name.namespace.psql +-- ^^^^ keyword.other.psql +-- ^^^^^^ storage.modifier.psql +-- ^^^^^^^^^^^ meta.schema-name.psql +-- ^^^^^^^ storage.modifier.psql +-- ^^^ meta.number.float.decimal.sql constant.numeric.value.sql +-- ^^^^^^^ storage.modifier.psql +-- ^ punctuation.terminator.statement.sql + +-- ----------------- +-- DROP EXTENSION +-- https://www.postgresql.org/docs/current/sql-dropextension.html +-- ----------------- + +DROP EXTENSION name CASCADE; +-- <- meta.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop.sql +-- ^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^^^ meta.extension-name.psql +-- ^^^^^^^ storage.modifier.psql +-- ^ punctuation.terminator.statement.sql + +DROP EXTENSION IF EXISTS name, second RESTRICT; +-- <- meta.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop.sql +-- ^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^ meta.extension-name.psql +-- ^ punctuation.separator.sequence.psql +-- ^^^^^^ meta.extension-name.psql +-- ^^^^^^^^ storage.modifier.psql +-- ^ punctuation.terminator.statement.sql + +-- ----------------- +-- ALTER EXTENSION +-- https://www.postgresql.org/docs/current/sql-alterextension.html +-- ----------------- + +ALTER EXTENSION extension_name UPDATE TO 1.2; +-- <- meta.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^^^^^^^^^^^^^ meta.extension-name.psql +-- ^^^^^^ keyword.other.ddl.psql +-- ^^ keyword.other.ddl.psql +-- ^^^ meta.number.float.decimal.sql constant.numeric.value.sql +-- ^ punctuation.terminator.statement.sql + +ALTER EXTENSION extension_name SET SCHEMA new_schema; +-- <- meta.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^^^^^^^^^^^^^ meta.extension-name.psql +-- ^^^ keyword.other.ddl.psql +-- ^^^^^^ storage.modifier.psql +-- ^^^^^^^^^^ meta.schema-name.psql +-- + +ALTER EXTENSION extension_name ADD member_object; +-- <- meta.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^^^^^^^^^^^^^ meta.extension-name.psql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.member-name.psql +-- ^ punctuation.terminator.statement.sql + +ALTER EXTENSION extension_name DROP member_object; +-- <- meta.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.psql +-- ^^^^^^^^^^^^^^ meta.extension-name.psql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.member-name.psql + +-- ----------------- +-- CREATE TABLE +-- https://www.postgresql.org/docs/current/ddl-basics.html +-- ----------------- + CREATE TABLE example_table ( first_name VARCHAR(100) CONSTRAINT check_first_name @@ -226,9 +333,13 @@ CREATE TABLE example_table ( ); ALTER TABLE mytable ADD CONSTRAINT verif_code CHECK (code IN ('A', 'AG', 'AL', 'AS', 'B', 'C', 'D', 'DA')); --- ^^^^^^^^ keyword.other.ddl +-- <- meta.alter.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- ^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl -- ^^^^^^^ meta.table-name --- ^^^^^^^^^^^^^^ keyword.other +-- ^^^ keyword.other.ddl +-- ^^^^^^^^^^ keyword.other.ddl -- ^^^^^^^^^^ meta.constraint-name -- ^^^^^ keyword.other -- ^ punctuation.section.group.begin @@ -259,8 +370,10 @@ CREATE TABLE test2 ( ); ALTER TABLE test2 ADD something varchar[]; +-- <- meta.alter.sql keyword.other.ddl -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter --- ^^^^^^^^ keyword.other.ddl +-- ^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl -- ^^^^^ meta.table-name -- ^^^ keyword.other.ddl -- ^^^^^^^^^ meta.column-name @@ -273,7 +386,7 @@ ALTER TABLE test2 ADD something varchar[]; CREATE TRIGGER blah AFTER INSERT OR UPDATE -- ^^^ keyword.other.ddl -- ^^^^^^^ keyword.other --- ^^^^ meta.toc-list.full-identifier entity.name.other +-- ^^^^ entity.name.struct.other -- ^^^^^^^^^^^^^^^^^^^^^^ keyword.other ON some_table FOR EACH ROW EXECUTE PROCEDURE some_procedure(); -- ^^ keyword.other diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 1b9aba592a..f9e53b08e1 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -539,26 +539,46 @@ AND (v.column2 IS NULL OR ISNULL(TableAlias.column1, 0) != v.column1) -- ^^ keyword.operator.comparison drop table foobar --- ^^^^^^^ meta.drop keyword.other.ddl +-- <- meta.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^ meta.drop +-- ^ keyword.other.ddl +-- ^ - keyword +-- ^^^^^ keyword.other -- ^^^^^^ meta.table-name alter table foo --- ^^^^^^^^ meta.alter keyword.other.ddl +-- <- meta.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^ keyword.other.ddl.sql +-- ^ - keyword -- ^^^ meta.alter meta.table-name add bar uniqueidentifier ---^ meta.alter keyword.other.ddl --- ^^^ meta.alter meta.column-name --- ^^^^^^^^^^^^^^^^ meta.alter storage.type +--^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +--^ keyword.other.ddl.sql +-- ^^^ meta.column-name +-- ^^^^^^^^^^^^^^^^ storage.type alter table foo ---^^^^^^^^^ meta.alter keyword.other.ddl - meta.alter meta.alter --- ^^^ meta.alter meta.table-name +-- <- meta.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^ meta.table-name alter column bar uniqueidentifier not null ---^^^^^^^^^^ meta.alter keyword.other.ddl --- ^^^ meta.alter meta.column-name --- ^^^^^^^^^^^^^^^^ meta.alter storage.type --- ^^^ meta.alter keyword.operator.logical --- ^^^^ meta.alter constant.language.null +-- <- meta.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^ meta.column-name +-- ^^^^^^^^^^^^^^^^ storage.type +-- ^^^ keyword.operator.logical +-- ^^^^ constant.language.null USE AdventureWorks2012; GO @@ -645,7 +665,7 @@ GO CREATE OR ALTER PROC CreateOrAlterDemo -- ^^^^^^^^^^^^ meta.create keyword.other.ddl -- ^^^^ meta.create keyword.other --- ^^^^^^^^^^^^^^^^^ meta.create meta.toc-list.full-identifier entity.name.struct +-- ^^^^^^^^^^^^^^^^^ meta.create.sql entity.name.function.sql @Count SMALLINT ,@Other INT OUTPUT -- <- punctuation.separator.sequence @@ -855,7 +875,7 @@ SELECT cte_table.* FROM cte_table CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)) -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other --- ^^^ meta.toc-list.full-identifier entity.name.struct +-- ^^^ entity.name.struct -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns -- ^ punctuation.section.group.begin -- ^^ meta.column-name @@ -1420,9 +1440,23 @@ RETURN GO CREATE FUNCTION foo() RETURNS @MyType +-- <- meta.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^ entity.name.function.sql +-- ^^ meta.group.sql +-- ^^^^^^^ keyword.other.sql -- ^^^^^^^ support.type.sql variable.other.readwrite.sql CREATE FUNCTION foo() RETURNS My@TypeName +-- <- meta.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^ entity.name.function.sql +-- ^^ meta.group.sql +-- ^^^^^^^ keyword.other.sql -- ^^ support.type.sql - variable -- ^^^^^^^^^ support.type.sql variable.other.readwrite.sql @@ -1701,7 +1735,7 @@ CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( -- ^^^^^^ keyword.other -- ^^^^^^^^^^^^ keyword.other -- ^^^^^ keyword.other --- ^^^^^^^^^^^^^ meta.toc-list.full-identifier entity.name.struct +-- ^^^^^^^^^^^^^ entity.name.struct -- ^^ keyword.other -- ^^^^^^^^^^^^^^ meta.table-name -- ^ meta.group punctuation.section.group.begin @@ -1914,8 +1948,12 @@ CREATE TABLE Customers ( ALTER TABLE inventory ADD CONSTRAINT fk_inv_product_id ---^^^^^^^^^^^^ meta.alter meta.add keyword.other --- ^^^^^^^^^^^^^^^^^ meta.alter meta.constraint-name +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +--^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^^^^^^^^^^ meta.constraint-name FOREIGN KEY (product_id) -- ^^^^^^^^^^^ meta.alter storage.modifier -- ^ meta.alter meta.group.table-columns punctuation.section.group.begin From 969fcd160f8880c6860664eb3e9d9a88ff7f0550 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 10 Jul 2022 17:41:29 +0200 Subject: [PATCH 147/250] P-SQL: Improve CREATE INDEX statements --- SQL/PostgreSQL.sublime-syntax | 13 +++- SQL/tests/syntax/syntax_test_postgres.psql | 72 ++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index cb0802fd2f..a3b8cda535 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -73,6 +73,12 @@ contexts: ddl-create-extension-condition: - include: ddl-condition + ddl-create-index-condition: + # https://www.postgresql.org/docs/current/sql-createindex.html + - meta_prepend: true + - match: \b(?i:concurrently)\b + scope: keyword.other.ddl.psql + ###[ DDL DROP STATEMENTS ]##################################################### ddl-drop-target: @@ -148,9 +154,14 @@ contexts: scope: storage.modifier.psql ddl-target-on: - - meta_prepend: true - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b scope: keyword.other.psql + - match: \b(?i:(on)(?:\s+(only))?)\b + captures: + 1: keyword.other.sql + 2: keyword.other.psql + push: expect-table-name + - include: else-pop ###[ EXPRESSIONS ]############################################################# diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index 9f92703ca5..8fa2ed4fb6 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -312,6 +312,78 @@ ALTER EXTENSION extension_name DROP member_object; -- ^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^^^^ meta.member-name.psql + +-- ----------------- +-- CREATE INDEX +-- https://www.postgresql.org/docs/current/sql-createindex.html +-- +-- CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] name ] ON [ ONLY ] table_name [ USING method ] +-- ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass [ ( opclass_parameter = value [, ... ] ) ] ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] ) +-- [ INCLUDE ( column_name [, ...] ) ] +-- [ WITH ( storage_parameter [= value] [, ... ] ) ] +-- [ TABLESPACE tablespace_name ] +-- [ WHERE predicate ] +-- ----------------- + +CREATE INDEX index_name +-- <- meta.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql + +CREATE INDEX index_name USING method_name +-- <- meta.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql +-- ^^^^^ keyword.other.mysql + +CREATE UNIQUE INDEX IF NOT EXISTS index_name ON table_name +-- <- meta.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql +-- ^^ keyword.other.sql +-- ^^^^^^^^^^ meta.table-name.sql + +CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS index_name ON ONLY table_name +-- <- meta.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ keyword.other.ddl.psql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql +-- ^^ keyword.other.sql +-- ^^^^ keyword.other.psql +-- ^^^^^^^^^^ meta.table-name.sql + +CREATE UNIQUE INDEX CONCURRENTLY IF EXISTS index_name ON ONLY table_name USING method_name +-- <- meta.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ keyword.other.ddl.psql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql +-- ^^ keyword.other.sql +-- ^^^^ keyword.other.psql +-- ^^^^^^^^^^ meta.table-name.sql +-- ^^^^^ keyword.other.mysql + + -- ----------------- -- CREATE TABLE -- https://www.postgresql.org/docs/current/ddl-basics.html From 4278b9916ea9e2450d1e624cf6f053a4fa7700c4 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Mon, 11 Jul 2022 18:25:54 +0200 Subject: [PATCH 148/250] Cassandra rename type scope --- SQL/Cassandra.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index a10f43142f..b827a78d47 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -35,7 +35,7 @@ contexts: ddl-create-type: - match: \b(?i:type)\b - scope: keyword.other.ddl.sql + scope: keyword.other.ddl.cql push: - ddl-target-on - maybe-column-declaration-list From 257cba7e98b2948ca19031c2a1c567632e385943 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 16 Jul 2022 10:49:56 +0200 Subject: [PATCH 149/250] Remove `ddl-` from context names There are so many statements which don't fit into ddl- vs. dml- scheme (see T-SQL) and many of them need dedicated code paths to get highlighted accurately. Hence a naming scheme like `-statements` seems enought. --- SQL/Cassandra.sublime-syntax | 17 +-- SQL/MySQL.sublime-syntax | 28 ++-- SQL/PostgreSQL.sublime-syntax | 62 +++++---- SQL/SQL (basic).sublime-syntax | 232 +++++++++++++++++---------------- SQL/TSQL.sublime-syntax | 16 +-- 5 files changed, 181 insertions(+), 174 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index b827a78d47..04c75bb27b 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -29,25 +29,26 @@ contexts: ###[ DDL CREATE STATEMENTS ]################################################### - ddl-create-target: + create-target: - meta_prepend: true - - include: ddl-create-type + - include: create-type - ddl-create-type: + create-type: - match: \b(?i:type)\b scope: keyword.other.ddl.cql push: - - ddl-target-on + - target-on - maybe-column-declaration-list - expect-type-creation-name - - ddl-create-type-condition + - create-type-condition - ddl-create-type-condition: - - include: ddl-condition + create-type-condition: + - meta_include_prototype: false + - include: maybe-condition ###[ DDL STATEMENT PROTOTYPES ]################################################ - ddl-target-on: + target-on: - meta_prepend: true - match: \b(?i:clustering)\b scope: keyword.other.cql diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 3128ae48ca..55865c5022 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -46,32 +46,34 @@ contexts: ###[ DDL CREATE STATEMENTS ]################################################### - ddl-create-statements: + create-statements: - meta_prepend: true - match: \b(?i:create\s+or\s+replace)\b scope: keyword.other.ddl.sql push: - - ddl-create-meta - - ddl-create-target + - create-meta + - create-target - ddl-create-target: + create-target: - meta_prepend: true - - include: ddl-target-algorithm + - include: target-algorithm # index modifiers - match: \b(?i:unique|fulltext|spatial)\b scope: keyword.other.ddl.sql - ddl-drop-target: +###[ DDL DROP STATEMENTS ]##################################################### + + drop-target: - meta_prepend: true - - include: ddl-target-algorithm + - include: target-algorithm ###[ DDL ALTER STATEMENTS ]#################################################### - ddl-alter-target: + alter-target: - meta_prepend: true - - include: ddl-target-algorithm + - include: target-algorithm - ddl-alter-columns: + alter-columns: - meta_prepend: true - match: \b(?i:(change)\s+(column))\b captures: @@ -84,14 +86,14 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ - ddl-target-algorithm: + target-algorithm: - match: \b(?i:(algorithm))\s*(=) captures: 1: keyword.other.mysql 2: keyword.operator.assignment.mysql - push: ddl-target-algorithm-value + push: target-algorithm-value - ddl-target-algorithm-value: + target-algorithm-value: - match: \b(?i:merge|temptable|undefined)\b scope: constant.language.sql pop: 1 diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index a3b8cda535..04e4c0b4c5 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -30,15 +30,15 @@ contexts: sql: - meta_prepend: true - - include: declarations + - include: declare-statements statements: - meta_prepend: true - match: \$\$ -###[ DECLARATIONS ]############################################################ +###[ DECLARE STATEMENTS ]###################################################### - declarations: + declare-statements: - match: \b(?i:declare)\b scope: keyword.declaration.variable.psql push: inside-declaration @@ -57,23 +57,24 @@ contexts: ###[ DDL CREATE STATEMENTS ]################################################### - ddl-create-target: + create-target: - meta_prepend: true - - include: ddl-create-extension + - include: create-extension - ddl-create-extension: + create-extension: # https://www.postgresql.org/docs/current/sql-createextension.html - match: \b(?i:extension|domain)\b scope: keyword.other.ddl.psql set: - - ddl-target-as + - target-as - expect-extension-name-declaration - - ddl-create-extension-condition + - create-extension-condition - ddl-create-extension-condition: - - include: ddl-condition + create-extension-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-create-index-condition: + create-index-condition: # https://www.postgresql.org/docs/current/sql-createindex.html - meta_prepend: true - match: \b(?i:concurrently)\b @@ -81,44 +82,39 @@ contexts: ###[ DDL DROP STATEMENTS ]##################################################### - ddl-drop-target: + drop-target: - meta_prepend: true # https://www.postgresql.org/docs/current/sql-dropextension.html - match: \b(?i:extension|domain)\b scope: keyword.other.ddl.psql set: - - ddl-target-as - - ddl-drop-extension-name-list - - ddl-drop-extension-name + - target-as + - drop-extension-name-list + - expect-extension-name + - drop-extension-condition + + drop-extension-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-drop-extension-name-list: + drop-extension-name-list: - match: ',' scope: punctuation.separator.sequence.psql push: expect-extension-name - include: else-pop - ddl-drop-extension-name: - - meta_include_prototype: false - - include: comments - - include: dml-condition - - include: expect-extension-name - ###[ DDL ALTER STATEMENTS ]#################################################### - ddl-alter-target: + alter-target: - meta_prepend: true # https://www.postgresql.org/docs/current/sql-alterextension.html - match: \b(?i:extension|domain)\b scope: keyword.other.ddl.psql set: - - ddl-alter-extension-args - - ddl-alter-extension-name - - ddl-alter-extension-name: - - meta_include_prototype: false - - include: expect-extension-name + - alter-extension-args + - expect-extension-name - ddl-alter-extension-args: + alter-extension-args: - match: \b(?i:add|drop)\b scope: keyword.other.ddl.sql push: expect-member-name @@ -134,14 +130,14 @@ contexts: - include: numbers - include: else-pop - ddl-alter-common: + alter-common: - meta_prepend: true - match: \b(?i:check)\b scope: keyword.other.psql ###[ DDL STATEMENT PROTOTYPES ]################################################ - ddl-target-as: + target-as: - meta_prepend: true - match: \b(?i:for\s+each\s+row\s+execute\s+procedure)\b scope: keyword.other.psql @@ -153,7 +149,7 @@ contexts: - match: \b(?i:version|cascade|restrict)\b scope: storage.modifier.psql - ddl-target-on: + target-on: - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b scope: keyword.other.psql - match: \b(?i:(on)(?:\s+(only))?)\b diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index f0f9fc7fd0..8b9cf1b837 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -51,15 +51,12 @@ contexts: - include: expressions-or-column-names statements: - - include: ddl-statements + - include: create-statements + - include: drop-statements + - include: alter-statements - include: dml-statements - include: other-statements - ddl-statements: - - include: ddl-create-statements - - include: ddl-drop-statements - - include: ddl-alter-statements - ###[ COMMENTS ]################################################################ comments: @@ -104,220 +101,232 @@ contexts: ###[ DDL CREATE STATEMENTS ]################################################### - ddl-create-statements: + create-statements: - match: \b(?i:create)\b scope: keyword.other.ddl.sql push: - - ddl-create-meta - - ddl-create-target + - create-meta + - create-target - ddl-create-meta: + create-meta: - meta_include_prototype: false - meta_scope: meta.create.sql - include: immediately-pop - ddl-create-target: - - include: ddl-create-index - - include: ddl-create-table - - include: ddl-create-procedure - - include: ddl-create-other + create-target: + - include: create-index + - include: create-table + - include: create-procedure + - include: create-other - include: else-pop - ddl-create-index: + create-index: - match: \b(?xi:(?:({{ddl_target_index_modifier}})\s+)?(index))\b captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql set: - - ddl-target-as - - ddl-target-on + - target-as + - target-on - expect-index-creation-name - - ddl-create-index-condition + - create-index-condition - ddl-create-index-condition: - - include: ddl-condition + create-index-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-create-procedure: + create-procedure: - match: \b{{ddl_target_procedure}}\b scope: keyword.other.ddl.sql set: - - ddl-target-as + - target-as - expect-procedure-creation-name - - ddl-create-procedure-condition + - create-procedure-condition - ddl-create-procedure-condition: - - include: ddl-condition + create-procedure-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-create-table: + create-table: - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql set: - - ddl-target-on + - target-on - maybe-column-declaration-list - expect-table-creation-name - - ddl-create-table-condition + - create-table-condition - ddl-create-table-condition: - - include: ddl-condition + create-table-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-create-other: + create-other: - match: \b{{ddl_target_other}}\b scope: keyword.other.ddl.sql set: - - ddl-target-as - - ddl-target-on + - target-as + - target-on - expect-other-creation-name - - ddl-create-other-condition + - create-other-condition - ddl-create-other-condition: - - include: ddl-condition + create-other-condition: + - meta_include_prototype: false + - include: maybe-condition ###[ DDL DROP STATEMENTS ]##################################################### - ddl-drop-statements: + drop-statements: - match: \b(?i:drop)\b scope: keyword.other.ddl.sql push: - - ddl-drop-meta - - ddl-drop-target + - drop-meta + - drop-target - ddl-drop-meta: + drop-meta: - meta_include_prototype: false - meta_scope: meta.drop.sql - include: immediately-pop - ddl-drop-target: - - include: ddl-drop-index - - include: ddl-drop-table - - include: ddl-drop-procedure - - include: ddl-drop-other + drop-target: + - include: drop-index + - include: drop-table + - include: drop-procedure + - include: drop-other - include: else-pop - ddl-drop-index: + drop-index: - match: \b(?i:index)\b scope: keyword.other.ddl.sql set: - expect-index-name - - ddl-drop-index-condition + - drop-index-condition - ddl-drop-index-condition: - - include: ddl-condition + drop-index-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-drop-procedure: + drop-procedure: - match: \b{{ddl_target_procedure}}\b scope: keyword.other.ddl.sql set: - expect-procedure-name - - ddl-drop-procedure-condition + - drop-procedure-condition - ddl-drop-procedure-condition: - - include: ddl-condition + drop-procedure-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-drop-table: + drop-table: - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql set: - expect-table-name - - ddl-drop-table-condition + - drop-table-condition - ddl-drop-table-condition: - - include: ddl-condition + drop-table-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-drop-other: + drop-other: - match: \b{{ddl_target_other}}\b scope: keyword.other.ddl.sql set: - - ddl-target-on + - target-on - expect-other-name - - ddl-drop-other-condition + - drop-other-condition - ddl-drop-other-condition: - - include: ddl-condition + drop-other-condition: + - meta_include_prototype: false + - include: maybe-condition ###[ DDL ALTER STATEMENTS ]#################################################### - ddl-alter-statements: + alter-statements: - match: \b(?i:alter)\b scope: keyword.other.ddl.sql push: - - ddl-alter-meta - - ddl-alter-target + - alter-meta + - alter-target - ddl-alter-meta: + alter-meta: - meta_include_prototype: false - meta_scope: meta.alter.sql - include: immediately-pop - ddl-alter-target: - - include: ddl-alter-index - - include: ddl-alter-table - - include: ddl-alter-procedure - - include: ddl-alter-other + alter-target: + - include: alter-index + - include: alter-table + - include: alter-procedure + - include: alter-other - include: else-pop - ddl-alter-index: + alter-index: - match: \b(?:({{ddl_target_index_modifier}})\s+)?(index)\b captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql set: - - ddl-alter-other-args + - alter-other-args - expect-index-name - - ddl-alter-index-condition + - alter-index-condition - ddl-alter-index-condition: - - include: ddl-condition + alter-index-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-alter-procedure: + alter-procedure: - match: \b{{ddl_target_procedure}}\b scope: keyword.other.ddl.sql set: - - ddl-target-as + - target-as - expect-procedure-name - - ddl-alter-procedure-condition + - alter-procedure-condition - ddl-alter-procedure-condition: - - include: ddl-condition + alter-procedure-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-alter-table: + alter-table: - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql set: - - ddl-alter-table-args + - alter-table-args - expect-table-name - - ddl-alter-table-condition + - alter-table-condition - ddl-alter-table-condition: - - include: ddl-condition + alter-table-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-alter-table-args: - - include: ddl-alter-columns - - include: ddl-alter-common + alter-table-args: + - include: alter-columns + - include: alter-common - include: pop-on-top-level-reserved-word - include: expressions-or-column-names - ddl-alter-other: + alter-other: - match: \b{{ddl_target_other}}\b scope: keyword.other.ddl.sql set: - - ddl-alter-other-args + - alter-other-args - expect-other-name - - ddl-alter-other-condition + - alter-other-condition - ddl-alter-other-condition: - - include: ddl-condition + alter-other-condition: + - meta_include_prototype: false + - include: maybe-condition - ddl-alter-other-args: - - include: ddl-alter-common + alter-other-args: + - include: alter-common - include: else-pop - ddl-alter-columns: + alter-columns: - match: \b(?i:(add|alter)(?:\s+(column)|(?!\s+{{ddl_target}})))\b captures: 1: keyword.other.ddl.sql @@ -329,7 +338,7 @@ contexts: scope: keyword.other.ddl.sql push: expect-column-name - ddl-alter-common: + alter-common: - match: \b(?i:(add)\s+(constraint))\b captures: 1: keyword.other.ddl.sql @@ -350,13 +359,7 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ - ddl-condition: - - match: \b(?i:if)\b - scope: keyword.control.conditional.if.sql - - include: logical-operators - - include: else-pop - - ddl-target-as: + target-as: - match: \b(?i:as)\b scope: keyword.context.block.sql pop: 1 @@ -366,7 +369,7 @@ contexts: - include: expressions - include: pop-on-top-level-reserved-word - ddl-target-on: + target-on: - match: \b(?i:on)\b scope: keyword.other.sql push: expect-table-name @@ -426,11 +429,6 @@ contexts: pop: 1 - include: else-pop - dml-condition: - - match: \b(?i:if)\b - scope: keyword.control.conditional.if.sql - - include: logical-operators - ###[ OTHER STATEMENTS ]######################################################## other-statements: @@ -1034,6 +1032,16 @@ contexts: ###[ OPERATORS ]############################################################### + maybe-condition: + - meta_include_prototype: false + - include: conditions + - include: else-pop + + conditions: + - match: \b(?i:if)\b + scope: keyword.control.conditional.if.sql + - include: logical-operators + maybe-operator: - match: '<=>|[!<>]?=|<>|<|>' scope: keyword.operator.comparison.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 0a76522f19..4c4c127c63 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -41,11 +41,11 @@ contexts: sql: - meta_prepend: true - - include: declarations + - include: declare-statements -###[ DECLARATIONS ]############################################################ +###[ DECLARE STATEMENTS ]###################################################### - declarations: + declare-statements: - match: \b(?i:declare)\b scope: keyword.declaration.variable.sql push: inside-declaration @@ -63,14 +63,14 @@ contexts: ###[ DDL CREATE STATEMENTS ]################################################### - ddl-create-statements: + create-statements: - match: \b(?i:create(?:\s+or\s+alter)?)\b scope: keyword.other.ddl.sql push: - - ddl-create-meta - - ddl-create-target + - create-meta + - create-target - ddl-create-target: + create-target: - meta_prepend: true # modifiers - match: \b(?i:unique|clustered|nonclustered)\b @@ -78,7 +78,7 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ - ddl-target-as: + target-as: - meta_prepend: true - include: with-table-options - match: (@){{simple_identifier}} From 9476e36fb08df2260b70099a6793b3542273e3b0 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 16 Jul 2022 10:56:00 +0200 Subject: [PATCH 150/250] Rename `target-as` to `target-options` --- SQL/PostgreSQL.sublime-syntax | 6 +++--- SQL/SQL (basic).sublime-syntax | 10 +++++----- SQL/TSQL.sublime-syntax | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 04e4c0b4c5..378f779c74 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -66,7 +66,7 @@ contexts: - match: \b(?i:extension|domain)\b scope: keyword.other.ddl.psql set: - - target-as + - target-options - expect-extension-name-declaration - create-extension-condition @@ -88,7 +88,7 @@ contexts: - match: \b(?i:extension|domain)\b scope: keyword.other.ddl.psql set: - - target-as + - target-options - drop-extension-name-list - expect-extension-name - drop-extension-condition @@ -137,7 +137,7 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ - target-as: + target-options: - meta_prepend: true - match: \b(?i:for\s+each\s+row\s+execute\s+procedure)\b scope: keyword.other.psql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 8b9cf1b837..bc8a2fed6f 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -126,7 +126,7 @@ contexts: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql set: - - target-as + - target-options - target-on - expect-index-creation-name - create-index-condition @@ -139,7 +139,7 @@ contexts: - match: \b{{ddl_target_procedure}}\b scope: keyword.other.ddl.sql set: - - target-as + - target-options - expect-procedure-creation-name - create-procedure-condition @@ -166,7 +166,7 @@ contexts: - match: \b{{ddl_target_other}}\b scope: keyword.other.ddl.sql set: - - target-as + - target-options - target-on - expect-other-creation-name - create-other-condition @@ -282,7 +282,7 @@ contexts: - match: \b{{ddl_target_procedure}}\b scope: keyword.other.ddl.sql set: - - target-as + - target-options - expect-procedure-name - alter-procedure-condition @@ -359,7 +359,7 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ - target-as: + target-options: - match: \b(?i:as)\b scope: keyword.context.block.sql pop: 1 diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 4c4c127c63..61bfba46bc 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -78,7 +78,7 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ - target-as: + target-options: - meta_prepend: true - include: with-table-options - match: (@){{simple_identifier}} From ad140af18b677fdb1971cd096da75a7ef05e7f94 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 16 Jul 2022 11:44:09 +0200 Subject: [PATCH 151/250] Rename statement meta scopes --- SQL/SQL (basic).sublime-syntax | 6 +- SQL/tests/syntax/syntax_test_cassandra.cql | 56 +++++++-------- SQL/tests/syntax/syntax_test_mysql.sql | 56 +++++++-------- SQL/tests/syntax/syntax_test_postgres.psql | 84 +++++++++++----------- SQL/tests/syntax/syntax_test_tsql.sql | 68 +++++++++--------- 5 files changed, 135 insertions(+), 135 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index bc8a2fed6f..123031e826 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -110,7 +110,7 @@ contexts: create-meta: - meta_include_prototype: false - - meta_scope: meta.create.sql + - meta_scope: meta.statement.create.sql - include: immediately-pop create-target: @@ -186,7 +186,7 @@ contexts: drop-meta: - meta_include_prototype: false - - meta_scope: meta.drop.sql + - meta_scope: meta.statement.drop.sql - include: immediately-pop drop-target: @@ -254,7 +254,7 @@ contexts: alter-meta: - meta_include_prototype: false - - meta_scope: meta.alter.sql + - meta_scope: meta.statement.alter.sql - include: immediately-pop alter-target: diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 41a16a67f0..69baed4789 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -1,7 +1,7 @@ -- SYNTAX TEST "Packages/SQL/Cassandra.sublime-syntax" CREATE KEYSPACE killrvideo WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1}; ---^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +--^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create --^^^^ keyword.other.ddl -- ^^^^^^^^ keyword.other -- ^^^^^^^^^^ entity.name.struct.other @@ -85,7 +85,7 @@ insert into something_by_countrycode (someid, countrycode) values (:someid, :cou -- ^ punctuation.terminator.statement CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^ keyword.control.conditional.if @@ -94,12 +94,12 @@ CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( -- ^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.struct -- ^ meta.group.table-columns punctuation.section.group.begin userid uuid, --- ^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns -- ^^^^^^ meta.column-name -- ^^^^ storage.type -- ^ punctuation.separator.sequence permissions frozen>, --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns -- ^^^^^^^^^^^ meta.column-name -- ^^^^^^ - meta.generic -- ^^^^ meta.generic.cql - meta.generic meta.generic @@ -133,20 +133,20 @@ CREATE TABLE IF NOT EXISTS userpermissions_by_userid ( -- ^^^ punctuation.definition.generic.end.cql -- ^ punctuation.separator.sequence.sql PRIMARY KEY(userid) --- ^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns -- ^^^^^^^^^^^ storage.modifier -- ^ meta.group punctuation.section.group.begin -- ^^^^^^ meta.group.partition-key meta.column-name -- ^ meta.group.partition-key punctuation.section.group.end ); --- <- meta.create meta.group.table-columns punctuation.section.group.end +-- <- meta.statement.create meta.group.table-columns punctuation.section.group.end CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( userid uuid, other_id uuid, test text, PRIMARY KEY(userid, other_id) --- ^^^^^^^^^^^ meta.create meta.group.table-columns storage.modifier +-- ^^^^^^^^^^^ meta.statement.create meta.group.table-columns storage.modifier -- ^ punctuation.section.group.begin -- ^^^^^^ meta.group.partition-key meta.column-name -- ^^^^^^^^^^^ - meta.group.partition-key @@ -154,13 +154,13 @@ CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( -- ^^^^^^^^ meta.group.table-columns meta.group meta.column-name -- ^ punctuation.section.group.end ); --- <- meta.create meta.group.table-columns punctuation.section.group.end +-- <- meta.statement.create meta.group.table-columns punctuation.section.group.end CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( userid uuid, other_id uuid, test text, PRIMARY KEY ((userid), other_id) --- ^^^^^^^^^^^ meta.create meta.group.table-columns storage.modifier +-- ^^^^^^^^^^^ meta.statement.create meta.group.table-columns storage.modifier -- ^ punctuation.section.group.begin -- ^^^^^^^^ meta.group.partition-key -- ^ punctuation.section.group.begin @@ -171,7 +171,7 @@ CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( -- ^^^^^^^^ meta.group.table-columns meta.group meta.column-name -- ^ punctuation.section.group.end ); --- <- meta.create meta.group.table-columns punctuation.section.group.end +-- <- meta.statement.create meta.group.table-columns punctuation.section.group.end CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( userid uuid, other_id timeuuid, @@ -180,7 +180,7 @@ CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( -- ^ punctuation.separator.sequence test int, PRIMARY KEY ((userid, other_id), test) --- ^^^^^^^^^^^ meta.create meta.group.table-columns storage.modifier +-- ^^^^^^^^^^^ meta.statement.create meta.group.table-columns storage.modifier -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^^^^^^^^ meta.group.partition-key -- ^ punctuation.section.group.begin @@ -193,11 +193,11 @@ CREATE TABLE IF NOT EXISTS test_by_userid_otherid ( -- ^^^^ meta.group.table-columns meta.group meta.column-name -- ^ punctuation.section.group.end ); --- <- meta.create meta.group.table-columns punctuation.section.group.end +-- <- meta.statement.create meta.group.table-columns punctuation.section.group.end CREATE TABLE IF NOT EXISTS date_by_userid ( userid uuid PRIMARY KEY, --- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns -- ^^^^^^ meta.column-name -- ^^^^ storage.type -- ^^^^^^^^^^^ storage.modifier @@ -209,8 +209,8 @@ CREATE TABLE IF NOT EXISTS date_by_userid ( DROP TABLE IF EXISTS userpermissions_by_userid; --- <- meta.drop.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop.sql +-- <- meta.statement.drop.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql -- ^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^ keyword.control.conditional.if @@ -219,8 +219,8 @@ DROP TABLE IF EXISTS userpermissions_by_userid; -- ^ punctuation.terminator.statement CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS --- <- meta.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql --^^^^ keyword.other.ddl -- ^^^^^^^^^^^^ keyword.other.ddl -- ^^^^ keyword.other.ddl @@ -250,7 +250,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS -- ^ punctuation.terminator.statement CREATE TYPE user_defined_type ( ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create --^^^^ keyword.other.ddl -- ^^^^ keyword.other -- ^^^^^^^^^^^^^^^^^ entity.name.type @@ -319,7 +319,7 @@ CREATE TABLE IF NOT EXISTS someentity_by_somefield ( anotherfield text PRIMARY KEY (entityid, datecreated, somefield) ) WITH CLUSTERING ORDER BY (datecreated DESC, somefield ASC); ---^^^^^^^^^^^^^^^^ meta.create +--^^^^^^^^^^^^^^^^ meta.statement.create -- ^^^ keyword.other -- ^^^^^^^^^^ keyword.other -- ^^^^^^^^ keyword.other.dml @@ -334,8 +334,8 @@ PRIMARY KEY (entityid, datecreated, somefield) -- ^ punctuation.terminator.statement ALTER TABLE someentity_by_somefield add usefulfield text; --- <- meta.alter.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql -- ^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name @@ -346,7 +346,7 @@ ALTER TABLE someentity_by_somefield add usefulfield text; ALTER TABLE someentity_by_somefield add usefulfield text; --- ^^^^^^^^^^^^^^^^^^^^ meta.alter +-- ^^^^^^^^^^^^^^^^^^^^ meta.statement.alter -- ^^^ keyword.other.ddl -- ^^^^^^^^^^^ meta.column-name -- ^^^^ storage.type @@ -354,7 +354,7 @@ ALTER TABLE someentity_by_somefield ALTER TABLE someentity_by_somefield DROP unnecessryfield; --- ^^^^^^^^^^^^^^^^^^^^ meta.alter +-- ^^^^^^^^^^^^^^^^^^^^ meta.statement.alter -- ^^^^ keyword.other.ddl -- ^^^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.terminator.statement @@ -425,8 +425,8 @@ CREATE TABLE myschema.users ( ); CREATE INDEX user_state --- <- meta.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other -- ^^^^^^^^^^ entity.name.struct.index.sql @@ -448,7 +448,7 @@ CREATE INDEX ON myschema.users (zip); -- ^ punctuation.section.group.end CREATE INDEX todo_dates ON users (KEYS(todo)); --- ^^^^^ meta.create meta.table-name +-- ^^^^^ meta.statement.create meta.table-name -- ^ punctuation.section.group.begin -- ^^^^ meta.function-call support.function.scalar -- ^ punctuation.section.arguments.begin @@ -457,7 +457,7 @@ CREATE INDEX todo_dates ON users (KEYS(todo)); -- ^ punctuation.section.group.end CREATE INDEX entries_idx ON race (ENTRIES(race_wins)); --- ^^^^ meta.create meta.table-name +-- ^^^^ meta.statement.create meta.table-name -- ^ punctuation.section.group.begin -- ^^^^^^^ meta.function-call support.function.scalar -- ^ punctuation.section.arguments.begin @@ -466,7 +466,7 @@ CREATE INDEX entries_idx ON race (ENTRIES(race_wins)); -- ^ punctuation.section.group.end CREATE INDEX rnumbers_idx ON cycling.race_starts (FULL(rnumbers)); --- ^^^^^^^^^^^^^^^^^^^ meta.create meta.table-name +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.table-name -- ^ punctuation.section.group.begin -- ^^^^ meta.function-call support.function.scalar -- ^ punctuation.section.arguments.begin diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index aa143554a5..abae336e10 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -22,8 +22,8 @@ SELECT "My /* Crazy Column Name" FROM my_table; -- ^^ - comment - punctuation CREATE TABLE foo --- <- meta.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl -- ^ - keyword -- ^^^^^ keyword.other.ddl @@ -32,36 +32,36 @@ CREATE TABLE foo ;CREATE TABLE foo (id INTEGER PRIMARY KEY); -- <- punctuation.terminator.statement.sql - -- <- meta.create keyword.other.ddl + -- <- meta.statement.create keyword.other.ddl --^^^^^ keyword.other.ddl -- ^^^^^ keyword.other -- ^^^ entity.name.struct -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - entity.name create table some_schema.test2( id serial ); ---^^^^ meta.create keyword.other.ddl --- ^^^^^ meta.create keyword.other +--^^^^ meta.statement.create keyword.other.ddl +-- ^^^^^ meta.statement.create keyword.other -- ^^^^^^^^^^^^^^^^^ entity.name.struct -- ^ punctuation.accessor.dot -- ^^^^^^^^^^^^^^ - entity.name create table some_schema . test2 ( id serial ); ---^^^^ meta.create keyword.other.ddl --- ^^^^^ meta.create keyword.other +--^^^^ meta.statement.create keyword.other.ddl +-- ^^^^^ meta.statement.create keyword.other -- ^^^^^^^^^^^^^^^^^^^ entity.name -- ^ punctuation.accessor.dot -- ^^^^^^^^^^^^^^^ - entity.name create table "testing123" (id integer); ---^^^^ meta.create keyword.other.ddl --- ^^^^^ meta.create keyword.other +--^^^^ meta.statement.create keyword.other.ddl +-- ^^^^^ meta.statement.create keyword.other -- ^ punctuation.definition.identifier.begin -- ^^^^^^^^^^ entity.name.struct -- ^ punctuation.definition.identifier.end create table `dbo`."testing123" (id integer); ---^^^^ meta.create keyword.other.ddl --- ^^^^^ meta.create keyword.other +--^^^^ meta.statement.create keyword.other.ddl +-- ^^^^^ meta.statement.create keyword.other -- ^^^^^^^^^^^^^^^^^^ entity.name.struct -- ^ punctuation.accessor.dot -- ^^^^^^^^^^^^^^^ - entity.name @@ -143,15 +143,15 @@ create table fancy_table ( ); CREATE INDEX ON fancy_table(mytime); --- <- meta.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^^^ keyword.other.ddl -- ^^ keyword.other -- ^^^^^^^^^^^ meta.table-name CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); --- <- meta.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^ keyword.other @@ -159,12 +159,12 @@ CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); -- ^^^^^ keyword.other CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; --- <- meta.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl -- ^^^^^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl --- ^^ meta.create keyword.other +-- ^^ meta.statement.create keyword.other -- ^^^^^^^^^^^ meta.table-name -- ^ meta.group punctuation.section.group.begin -- ^^^^^^^^^^^^ meta.group meta.column-name @@ -187,8 +187,8 @@ create fulltext index if not exists `myindex` ON mytable; -- ^ punctuation.terminator.statement ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; --- <- meta.alter.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^^^^^^^^^^^^^ meta.table-name.sql @@ -198,8 +198,8 @@ ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; -- ^^^^^^^^ storage.type.sql ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); --- <- meta.alter.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^^^^^ keyword.other.ddl -- ^^^^^^ keyword.other.ddl -- ^^^^^^^^ meta.column-name @@ -207,8 +207,8 @@ ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); -- ^^^^ storage.type.sql DROP TABLE IF EXISTS testing123; --- <- meta.drop.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop.sql +-- <- meta.statement.drop.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql -- ^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^ keyword.control.conditional.if.sql @@ -273,7 +273,7 @@ WHERE f.a IS NULL -- ^^^^ constant.language.null.sql CREATE INDEX IX_some_index ON dbo.some_table( --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^^^^^^^^^^^^ entity.name.struct.index @@ -286,7 +286,7 @@ CREATE INDEX IX_some_index ON dbo.some_table( ) CREATE ALGORITHM=MERGE VIEW contactPersons( --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create -- ^^^ keyword.other.ddl -- ^^^^^^^^^ keyword.other -- ^ keyword.operator.assignment @@ -315,8 +315,8 @@ FROM customers; -- ^ punctuation.terminator.statement CREATE TEMPORARY TABLE IF NOT EXISTS foo ( --- <- meta.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl -- ^^^^^^^^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index 8fa2ed4fb6..505c5861dd 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -1,8 +1,8 @@ -- SYNTAX TEST "Packages/SQL/PostgreSQL.sublime-syntax" CREATE TABLE test1 (a character(4)); --- <- meta.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^^^^ entity.name.struct.table @@ -29,7 +29,7 @@ SELECT a, char_length(a) FROM test1; -- ^ punctuation.terminator.statement CREATE TABLE test2 (b varchar(5)); --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^^^^ entity.name.struct @@ -51,7 +51,7 @@ INSERT INTO test2 VALUES ('too long'::varchar(5)); -- explicit truncation SELECT b, char_length(b) FROM test2; CREATE TABLE IF NOT EXISTS public.dropzone_details --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^ keyword.control.conditional.if @@ -60,9 +60,9 @@ CREATE TABLE IF NOT EXISTS public.dropzone_details -- ^^^^^^^^^^^^^^^^^^^^^^^ entity.name.struct -- ^ punctuation.accessor.dot ( --- <- meta.create meta.group.table-columns punctuation.section.group.begin +-- <- meta.statement.create meta.group.table-columns punctuation.section.group.begin id uuid NOT NULL DEFAULT uuid_generate_v4(), --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns -- ^^ meta.column-name -- ^^^^ storage.type -- ^^^ keyword.operator.logical @@ -105,9 +105,9 @@ SELECT 'abc \153\154\155 \052\251\124'::bytea; -- ^ punctuation.terminator.statement CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); --- ^^^ meta.create keyword.other.ddl --- ^^^^ meta.create keyword.other --- ^^^^ meta.create entity.name +-- ^^^ meta.statement.create keyword.other.ddl +-- ^^^^ meta.statement.create keyword.other +-- ^^^^ meta.statement.create entity.name -- ^^ keyword.context.block CREATE TABLE person ( name text, @@ -129,14 +129,14 @@ INSERT INTO test VALUES (B'10'::bit(3), B'101'); CREATE TABLE sal_emp ( name text, pay_by_quarter integer[], --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns -- ^^^^^^^^^^^^^^ meta.column-name -- ^^^^^^^ storage.type -- ^ punctuation.section.brackets.begin -- ^ punctuation.section.brackets.end -- ^ punctuation.separator.sequence - storage schedule text[][] --- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns -- ^^^^^^^^ meta.column-name -- ^^^^ storage.type -- ^ punctuation.section.brackets.begin @@ -213,8 +213,8 @@ SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; -- ----------------- CREATE EXTENSION hstore SCHEMA addons; --- <- meta.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl -- ^^^^^^^^^ keyword.other.ddl -- ^^^^^^ entity.name.namespace.psql @@ -223,8 +223,8 @@ CREATE EXTENSION hstore SCHEMA addons; -- ^ punctuation.terminator.statement CREATE EXTENSION IF NOT EXISTS extension_name WITH SCHEMA schema_name VERSION 1.0 CASCADE; --- <- meta.create.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl.sql -- ^^^^^^^^^ keyword.other.ddl.psql -- ^^ keyword.control.conditional.if.sql @@ -245,8 +245,8 @@ CREATE EXTENSION IF NOT EXISTS extension_name WITH SCHEMA schema_name VERSION 1. -- ----------------- DROP EXTENSION name CASCADE; --- <- meta.drop.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop.sql +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql -- ^ keyword.other.ddl.sql -- ^^^^^^^^^ keyword.other.ddl.psql -- ^^^^ meta.extension-name.psql @@ -254,8 +254,8 @@ DROP EXTENSION name CASCADE; -- ^ punctuation.terminator.statement.sql DROP EXTENSION IF EXISTS name, second RESTRICT; --- <- meta.drop.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop.sql +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql -- ^ keyword.other.ddl.sql -- ^^^^^^^^^ keyword.other.ddl.psql -- ^^ keyword.control.conditional.if.sql @@ -272,8 +272,8 @@ DROP EXTENSION IF EXISTS name, second RESTRICT; -- ----------------- ALTER EXTENSION extension_name UPDATE TO 1.2; --- <- meta.alter.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^^^ keyword.other.ddl.psql -- ^^^^^^^^^^^^^^ meta.extension-name.psql @@ -283,8 +283,8 @@ ALTER EXTENSION extension_name UPDATE TO 1.2; -- ^ punctuation.terminator.statement.sql ALTER EXTENSION extension_name SET SCHEMA new_schema; --- <- meta.alter.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^^^ keyword.other.ddl.psql -- ^^^^^^^^^^^^^^ meta.extension-name.psql @@ -294,8 +294,8 @@ ALTER EXTENSION extension_name SET SCHEMA new_schema; -- ALTER EXTENSION extension_name ADD member_object; --- <- meta.alter.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^^^ keyword.other.ddl.psql -- ^^^^^^^^^^^^^^ meta.extension-name.psql @@ -304,8 +304,8 @@ ALTER EXTENSION extension_name ADD member_object; -- ^ punctuation.terminator.statement.sql ALTER EXTENSION extension_name DROP member_object; --- <- meta.alter.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^^^ keyword.other.ddl.psql -- ^^^^^^^^^^^^^^ meta.extension-name.psql @@ -326,23 +326,23 @@ ALTER EXTENSION extension_name DROP member_object; -- ----------------- CREATE INDEX index_name --- <- meta.create.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl.sql -- ^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^ entity.name.struct.index.sql CREATE INDEX index_name USING method_name --- <- meta.create.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl.sql -- ^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^ entity.name.struct.index.sql -- ^^^^^ keyword.other.mysql CREATE UNIQUE INDEX IF NOT EXISTS index_name ON table_name --- <- meta.create.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl.sql -- ^^^^^^ keyword.other.ddl.sql -- ^^^^^ keyword.other.ddl.sql @@ -354,8 +354,8 @@ CREATE UNIQUE INDEX IF NOT EXISTS index_name ON table_name -- ^^^^^^^^^^ meta.table-name.sql CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS index_name ON ONLY table_name --- <- meta.create.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl.sql -- ^^^^^^ keyword.other.ddl.sql -- ^^^^^ keyword.other.ddl.sql @@ -369,8 +369,8 @@ CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS index_name ON ONLY table_name -- ^^^^^^^^^^ meta.table-name.sql CREATE UNIQUE INDEX CONCURRENTLY IF EXISTS index_name ON ONLY table_name USING method_name --- <- meta.create.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl.sql -- ^^^^^^ keyword.other.ddl.sql -- ^^^^^ keyword.other.ddl.sql @@ -405,8 +405,8 @@ CREATE TABLE example_table ( ); ALTER TABLE mytable ADD CONSTRAINT verif_code CHECK (code IN ('A', 'AG', 'AL', 'AS', 'B', 'C', 'D', 'DA')); --- <- meta.alter.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^^^^^^ meta.table-name @@ -442,8 +442,8 @@ CREATE TABLE test2 ( ); ALTER TABLE test2 ADD something varchar[]; --- <- meta.alter.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter +-- <- meta.statement.alter.sql keyword.other.ddl +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter -- ^^ keyword.other.ddl -- ^^^^^ keyword.other.ddl -- ^^^^^ meta.table-name @@ -495,7 +495,7 @@ DECLARE var varchar[]; -- ^ - variable - storage DROP TRIGGER blah ON some_table; --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.drop +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop -- ^ keyword.other.ddl -- ^^^^^^^ keyword.other -- ^^ keyword.other diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index f9e53b08e1..6ef54983fb 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -539,38 +539,38 @@ AND (v.column2 IS NULL OR ISNULL(TableAlias.column1, 0) != v.column1) -- ^^ keyword.operator.comparison drop table foobar --- <- meta.drop.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^ meta.drop +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^ meta.statement.drop -- ^ keyword.other.ddl -- ^ - keyword -- ^^^^^ keyword.other -- ^^^^^^ meta.table-name alter table foo --- <- meta.alter.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql -- ^ - keyword -- ^^^^^ keyword.other.ddl.sql -- ^ - keyword --- ^^^ meta.alter meta.table-name +-- ^^^ meta.statement.alter meta.table-name add bar uniqueidentifier ---^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +--^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql --^ keyword.other.ddl.sql -- ^^^ meta.column-name -- ^^^^^^^^^^^^^^^^ storage.type alter table foo --- <- meta.alter.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql -- ^ - keyword -- ^^^^^ keyword.other.ddl.sql -- ^ - keyword -- ^^^ meta.table-name alter column bar uniqueidentifier not null --- <- meta.alter.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql -- ^ - keyword -- ^^^^^^ keyword.other.ddl.sql @@ -663,9 +663,9 @@ USE MSSQLTipsDemo GO CREATE OR ALTER PROC CreateOrAlterDemo --- ^^^^^^^^^^^^ meta.create keyword.other.ddl --- ^^^^ meta.create keyword.other --- ^^^^^^^^^^^^^^^^^ meta.create.sql entity.name.function.sql +-- ^^^^^^^^^^^^ meta.statement.create keyword.other.ddl +-- ^^^^ meta.statement.create keyword.other +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql entity.name.function.sql @Count SMALLINT ,@Other INT OUTPUT -- <- punctuation.separator.sequence @@ -699,8 +699,8 @@ GO --------------- ALTER PROC CreateOrAlterDemo --- ^^ meta.alter keyword.other.ddl --- ^^^^ meta.alter keyword.other.ddl +-- ^^ meta.statement.alter keyword.other.ddl +-- ^^^^ meta.statement.alter keyword.other.ddl -- ^^^^^^^^^^^^^^^^^ meta.procedure-name @Count SMALLINT ,@Other INT OUTPUT @@ -876,7 +876,7 @@ CREATE TABLE foo (id [int] PRIMARY KEY, [test me] [varchar] (5)) -- ^^^ keyword.other.ddl -- ^^^^^ keyword.other -- ^^^ entity.name.struct --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create meta.group.table-columns +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create meta.group.table-columns -- ^ punctuation.section.group.begin -- ^^ meta.column-name -- ^^^^^ storage.type @@ -1321,7 +1321,7 @@ CREATE TABLE [dbo].[be_Categories]( -- ^^^^^^^^^ meta.filegroup-name ) ON [PRIMARY] -- <- punctuation.section.group.end ---^^ meta.create keyword.other +--^^ meta.statement.create keyword.other -- ^^^^^^^^^ meta.filegroup-name -- ^ punctuation.definition.identifier.begin -- ^ punctuation.definition.identifier.end @@ -1372,7 +1372,7 @@ CREATE TABLE [dbo].[table_with_constraint_following_derived_column]( -- ^^^^^^^^^ meta.filegroup-name ) ON [PRIMARY] -- <- punctuation.section.group.end ---^^ meta.create keyword.other +--^^ meta.statement.create keyword.other -- ^^^^^^^^^ meta.filegroup-name -- ^ punctuation.definition.identifier.begin -- ^ punctuation.definition.identifier.end @@ -1399,8 +1399,8 @@ CREATE TABLE [Employee]( -- ^ punctuation.separator.sequence ) ON [PRIMARY] -- <- punctuation.section.group.end ---^^ meta.create keyword.other --- ^^^^^^^^^ meta.create meta.filegroup-name +--^^ meta.statement.create keyword.other +-- ^^^^^^^^^ meta.statement.create meta.filegroup-name GO SELECT * FROM Department D CROSS APPLY @@ -1440,8 +1440,8 @@ RETURN GO CREATE FUNCTION foo() RETURNS @MyType --- <- meta.create.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl.sql -- ^^^^^^^^ keyword.other.ddl.sql -- ^^^ entity.name.function.sql @@ -1450,8 +1450,8 @@ CREATE FUNCTION foo() RETURNS @MyType -- ^^^^^^^ support.type.sql variable.other.readwrite.sql CREATE FUNCTION foo() RETURNS My@TypeName --- <- meta.create.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create.sql +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^ keyword.other.ddl.sql -- ^^^^^^^^ keyword.other.ddl.sql -- ^^^ entity.name.function.sql @@ -1730,7 +1730,7 @@ SELECT @Data = ( ------------------- CREATE UNIQUE NONCLUSTERED INDEX IX_some_index ON dbo.some_table( --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create -- ^^^ keyword.other.ddl -- ^^^^^^ keyword.other -- ^^^^^^^^^^^^ keyword.other @@ -1899,7 +1899,7 @@ CREATE TABLE Department -- ^ punctuation.section.group.end ) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.Department_History, DATA_CONSISTENCY_CHECK = ON)); ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.create +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create --^^ keyword.other.dml -- ^ punctuation.section.group.begin -- ^^^^^^^^^^^^^^^^^ keyword.other @@ -1933,7 +1933,7 @@ CREATE TABLE Customers ( -- ^ punctuation.section.group.end -- ^ punctuation.separator.sequence SSN VARCHAR(11) COLLATE Latin1_General_BIN2 --- ^^^ meta.create meta.group.table-columns meta.column-name variable.other.member.declaration +-- ^^^ meta.statement.create meta.group.table-columns meta.column-name variable.other.member.declaration -- ^^^^^^^^^^^ storage.type -- ^^^^^^^ keyword.other -- ^^^^^^^^^^^^^^^^^^^ support.constant @@ -1948,24 +1948,24 @@ CREATE TABLE Customers ( ALTER TABLE inventory ADD CONSTRAINT fk_inv_product_id ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.alter.sql +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql --^ keyword.other.ddl.sql -- ^ - keyword -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^ - keyword -- ^^^^^^^^^^^^^^^^^ meta.constraint-name FOREIGN KEY (product_id) --- ^^^^^^^^^^^ meta.alter storage.modifier --- ^ meta.alter meta.group.table-columns punctuation.section.group.begin +-- ^^^^^^^^^^^ meta.statement.alter storage.modifier +-- ^ meta.statement.alter meta.group.table-columns punctuation.section.group.begin -- ^^^^^^^^^^ meta.column-name REFERENCES products (product_id) --- ^^^^^^^^^^ meta.alter storage.modifier --- ^^^^^^^^ meta.alter meta.table-name --- ^ meta.alter meta.group.table-columns punctuation.section.group.begin +-- ^^^^^^^^^^ meta.statement.alter storage.modifier +-- ^^^^^^^^ meta.statement.alter meta.table-name +-- ^ meta.statement.alter meta.group.table-columns punctuation.section.group.begin -- ^^^^^^^^^^ meta.column-name -- ^ punctuation.section.group.end ON DELETE CASCADE; --- ^^^^^^^^^^^^^^^^^ meta.alter storage.modifier +-- ^^^^^^^^^^^^^^^^^ meta.statement.alter storage.modifier -- ^ punctuation.terminator.statement BEGIN TRY From bb5d3e936d3e7418802b5a7f4388dd18253c1d21 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 12:34:16 +0200 Subject: [PATCH 152/250] T-SQL: Remove duplicate index-name contexts --- SQL/SQL (basic).sublime-syntax | 4 ++++ SQL/TSQL.sublime-syntax | 16 ---------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 123031e826..ab21091bb7 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -820,6 +820,10 @@ contexts: - meta_scope: entity.name.struct.index.sql - include: immediately-pop + expect-index-names: + - match: (?=\S) + push: [index-name, single-identifier] + expect-index-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 61bfba46bc..1f0d9d0136 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -814,22 +814,6 @@ contexts: - meta_content_scope: meta.filegroup-name.tsql - include: immediately-pop - expect-index-names: - - match: (?=\S) - push: [index-name, single-identifier] - - expect-index-name: - # prevent prototypes from inheriting syntaxes - - meta_include_prototype: false - - include: comments - - match: (?=\S) - set: [index-name, single-identifier] - - index-name: - - meta_include_prototype: false - - meta_content_scope: meta.index-name.tsql - - include: immediately-pop - expect-label-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false From 7f7daf6ff799ddc5922fc493c679d8cbe6fbb7c8 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 12 Jul 2022 20:31:00 +0200 Subject: [PATCH 153/250] MySQL: Add CREATE/ALTER/DROP USER statements --- SQL/MySQL.sublime-syntax | 178 +++++++++++- SQL/tests/syntax/syntax_test_mysql.sql | 361 +++++++++++++++++++++++++ 2 files changed, 538 insertions(+), 1 deletion(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 55865c5022..7ccb8fc99a 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -56,22 +56,67 @@ contexts: create-target: - meta_prepend: true - - include: target-algorithm # index modifiers - match: \b(?i:unique|fulltext|spatial)\b scope: keyword.other.ddl.sql + - include: target-algorithm + - include: create-user + + create-user: + # https://mariadb.com/kb/en/create-user + - match: \b(?i:user)\b + scope: keyword.other.ddl.sql + set: + - user-options + - create-user-name-list + - user-identification + - expect-user-name-declaration + - create-user-condition + + create-user-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-user-name-list: + - match: ',' + scope: punctuation.separator.sequence.sql + push: + - user-identification + - expect-user-name-declaration + - include: else-pop ###[ DDL DROP STATEMENTS ]##################################################### drop-target: - meta_prepend: true - include: target-algorithm + - include: drop-user + + drop-user: + # https://mariadb.com/kb/en/drop-user + - match: \b(?i:user)\b + scope: keyword.other.ddl.sql + set: + - drop-user-name-list + - expect-user-name + - drop-user-condition + + drop-user-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-user-name-list: + - match: ',' + scope: punctuation.separator.sequence.sql + push: expect-user-name + - include: else-pop ###[ DDL ALTER STATEMENTS ]#################################################### alter-target: - meta_prepend: true - include: target-algorithm + - include: alter-user alter-columns: - meta_prepend: true @@ -84,6 +129,29 @@ contexts: - expect-column-name-declaration - expect-column-name + alter-user: + # https://mariadb.com/kb/en/alter-user + - match: \b(?i:user)\b + scope: keyword.other.ddl.sql + set: + - user-options + - alter-user-name-list + - user-identification + - expect-user-name + - alter-user-condition + + alter-user-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-user-name-list: + - match: ',' + scope: punctuation.separator.sequence.sql + push: + - user-identification + - expect-user-name + - include: else-pop + ###[ DDL STATEMENT PROTOTYPES ]################################################ target-algorithm: @@ -150,6 +218,88 @@ contexts: - match: \b(?i:(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)) scope: keyword.other.object-comments.sql +###[ USER MANAGEMENT EXPRESSIONS ]############################################# + + user-identification: + - match: \b(?i:identified|by)\b + scope: keyword.other.ddl.sql + - match: \b(?i:password)\b + scope: storage.modifier.sql + - match: \b(?i:via)\b + scope: keyword.other.ddl.sql + set: + - user-auth-list + - user-auth-args + - expect-other-name + - include: strings + - include: else-pop + + user-auth-list: + - match: ',' + scope: punctuation.separator.sequence.sql + push: + - user-auth-args + - expect-other-name + - include: else-pop + + user-auth-args: + - match: (?=,|\b(?i:require|with|account)\b) + pop: 1 + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + - match: \b(?i:using)\b + scope: keyword.other.ddl.sql + - match: \b(?i:password) + scope: support.function.sql + push: function-call-arguments + - include: strings + - include: pop-on-top-level-reserved-word + + user-options: + - meta_scope: meta.user.sql + - include: user-account-options + - include: user-password-options + - include: user-resource-options + - include: user-tls-options + - include: numbers + - include: strings + - include: pop-on-top-level-reserved-word + + user-account-options: + - match: \b(?i:account)\b + scope: keyword.other.ddl.sql + - match: \b(?i:unlock|lock)\b + scope: constant.language.sql + + user-password-options: + - match: \b(?i:(password)\s+(expire))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + - match: \b(?i:day)\b + scope: keyword.other.unit.sql + - match: \b(?i:default|never|interval)\b + scope: constant.language.sql + + user-resource-options: + - match: \b(?i:with)\b + scope: keyword.other.ddl.sql + - match: |- + \b(?xi: max_queries_per_hour | max_updates_per_hour + | max_connections_per_hour | max_user_connections + | max_statement_time )\b + scope: constant.language.sql + + user-tls-options: + - match: \b(?i:require)\b + scope: keyword.other.ddl.sql + - match: \b(?i:and)\b + scope: keyword.operator.logical.sql + - match: \b(?i:ssl|x509|cipher|issuer|subject)\b + scope: constant.language.sql + - match: \b(?i:none)\b + scope: constant.language.null.sql + ###[ TYPES ]################################################################### after-type: @@ -161,6 +311,32 @@ contexts: scope: storage.type.sql pop: 1 +###[ IDENTIFIERS ]############################################################# + + expect-user-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [user-name, single-identifier] + + user-name: + - meta_include_prototype: false + - meta_content_scope: meta.user-name.sql + - include: immediately-pop + + expect-user-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [user-name-declaration, single-identifier] + + user-name-declaration: + - meta_include_prototype: false + - meta_content_scope: entity.name.user.sql + - include: immediately-pop + ###[ LITERALS ]################################################################ regexps: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index abae336e10..5f0ee1a5f8 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -1,5 +1,366 @@ -- SYNTAX TEST "Packages/SQL/MySQL.sublime-syntax" +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- https://mariadb.com/kb/en/account-management-sql-commands +-- ---------------------------------------------------------------------------- + +CREATE USER IF NOT EXISTS +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql + user1, +-- <- meta.statement.create.sql +-- ^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^ entity.name.user.sql +-- ^ punctuation.separator.sequence.sql + + user2 IDENTIFIED BY 'password', +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^ entity.name.user.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + user3 IDENTIFIED BY PASSWORD 'password_hash', +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^ entity.name.user.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + user4 IDENTIFIED VIA +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^ entity.name.user.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql + + auth_plugin1, +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin2 AS 'auth_string', +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin3 USING 'auth_string', +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin4 AS PASSWORD('password') +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^^^^^^^^^^^^^^^ meta.function-call.sql +-- ^^^^^^^^ support.function.sql +-- ^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.arguments.end.sql + + REQUIRE NONE +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^ constant.language.null.sql + + REQUIRE SSL AND CIPHER 'ciphername' X509 AND SUBJECT 'subject' +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ constant.language.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^^^^ constant.language.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^ constant.language.sql +-- ^^^^^^^^^ meta.string.sql string.quoted.single.sql + + WITH MAX_QUERIES_PER_HOUR 5 +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_UPDATES_PER_HOUR 5 +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_CONNECTIONS_PER_HOUR 5 +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_USER_CONNECTIONS 5 +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_STATEMENT_TIME 5 +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + ACCOUNT LOCK +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^ constant.language.sql + + ACCOUNT UNLOCK +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ constant.language.sql + + PASSWORD EXPIRE DEFAULT +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ constant.language.sql + + PASSWORD EXPIRE NEVER +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql + + PASSWORD EXPIRE INTERVAL 5 DAY +-- <- meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^ keyword.other.unit.sql + +-- ---------------------------------------------------------------------------- + +ALTER USER IF EXISTS +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql + user1, +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^ meta.user-name.sql +-- ^ punctuation.separator.sequence.sql + + user2 IDENTIFIED BY 'password', +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^ meta.user-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + user3 IDENTIFIED BY PASSWORD 'password_hash', +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^ meta.user-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + user4 IDENTIFIED VIA +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^ meta.user-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql + + auth_plugin1, +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin2 AS 'auth_string', +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin3 USING 'auth_string', +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + auth_plugin4 AS PASSWORD('password') +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^ meta.other-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^^^^^^^^^^^^^^^ meta.function-call.sql +-- ^^^^^^^^ support.function.sql +-- ^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.arguments.end.sql + + REQUIRE NONE +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^ constant.language.null.sql + + REQUIRE SSL AND CIPHER 'ciphername' X509 AND SUBJECT 'subject' +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ constant.language.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^^^^ constant.language.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^ constant.language.sql +-- ^^^^^^^^^ meta.string.sql string.quoted.single.sql + + WITH MAX_QUERIES_PER_HOUR 5 +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_UPDATES_PER_HOUR 5 +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_CONNECTIONS_PER_HOUR 5 +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_USER_CONNECTIONS 5 +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + WITH MAX_STATEMENT_TIME 5 +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + + ACCOUNT LOCK +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^ constant.language.sql + + ACCOUNT UNLOCK +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ constant.language.sql + + PASSWORD EXPIRE DEFAULT +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ constant.language.sql + + PASSWORD EXPIRE NEVER +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql + + PASSWORD EXPIRE INTERVAL 5 DAY +-- <- meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ constant.language.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^ keyword.other.unit.sql + +-- ---------------------------------------------------------------------------- + +DROP USER bob ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^ meta.statement.drop.sql +-- ^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^ meta.user-name.sql +-- ^ punctuation.terminator.statement.sql + +DROP USER IF EXISTS bob, clara ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^ meta.user-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.user-name.sql +-- ^ punctuation.terminator.statement.sql + + +-- ---------------------------------------------------------------------------- +-- Legacy Tests +-- ---------------------------------------------------------------------------- + SELECT 'Foo Bar'; -- ^^^^^^^^^ string.quoted.single -- ^ punctuation.definition.string.begin From a03ac2f649a27c07c3f3468500b19cfb9feed881 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Thu, 14 Jul 2022 19:23:50 +0200 Subject: [PATCH 154/250] MySQL: Add GRANT statements --- SQL/MySQL.sublime-syntax | 135 +++++++++++++++++++--- SQL/tests/syntax/syntax_test_mysql.sql | 149 +++++++++++++++++++++++++ 2 files changed, 270 insertions(+), 14 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 7ccb8fc99a..3643823f1a 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -8,7 +8,7 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: additional_reserved: |- - (?xi: begin | end | return ) + (?xi: begin | end | return | grant ) simple_types: |- (?xi: bigint | bigserial | bit | bool | boolean | box | bytea | cidr | circle @@ -24,6 +24,10 @@ contexts: - meta_append: true - include: regexps + statements: + - meta_prepend: true + - include: grant-statements + ###[ COMMENTS ]################################################################ comments: @@ -67,7 +71,7 @@ contexts: - match: \b(?i:user)\b scope: keyword.other.ddl.sql set: - - user-options + - create-user-args - create-user-name-list - user-identification - expect-user-name-declaration @@ -85,6 +89,10 @@ contexts: - expect-user-name-declaration - include: else-pop + create-user-args: + - meta_scope: meta.user.sql + - include: user-options + ###[ DDL DROP STATEMENTS ]##################################################### drop-target: @@ -134,8 +142,8 @@ contexts: - match: \b(?i:user)\b scope: keyword.other.ddl.sql set: - - user-options - - alter-user-name-list + - alter-user-args + - expect-user-identification-list - user-identification - expect-user-name - alter-user-condition @@ -144,13 +152,9 @@ contexts: - meta_include_prototype: false - include: maybe-condition - alter-user-name-list: - - match: ',' - scope: punctuation.separator.sequence.sql - push: - - user-identification - - expect-user-name - - include: else-pop + alter-user-args: + - meta_scope: meta.user.sql + - include: user-options ###[ DDL STATEMENT PROTOTYPES ]################################################ @@ -182,10 +186,77 @@ contexts: - match: \b(?i:straight_join|natural)\b scope: keyword.other.dml.sql +###[ GRANT STATEMENTS ]######################################################## + + grant-statements: + # https://mariadb.com/kb/en/grant + - match: \b(?i:grant)\b + scope: keyword.other.ddl.sql + push: + - grant-meta + - grant-options + - grant-to-user + - grant-target + + grant-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.grant.sql + - include: immediately-pop + + grant-target: + # grant proxy on name to user + - match: \b(?i:proxy)\b + scope: keyword.other.ddl.sql + set: grant-on-user + # grant role name to + - match: (?=\S+\s+(?i:to)\b) + set: expect-user-name + # grant operation on + - match: (?=\S) + set: grant-operations + + grant-operations: + - match: \b(?i:on)\b + scope: keyword.other.ddl.sql + set: grant-on-type + - match: (?=[;)]|\b(?i:grant|to|with)\b) + pop: 1 + - include: comma-separators + - include: user-privilidges + + grant-on-type: + # object type + - match: \b(?i:table|function|procedure|package)\b + scope: storage.type.sql + # wildcard privilidge level + - match: (\*)(?:(\.)(\*))? + scope: meta.other-name.sql + captures: + 1: variable.language.wildcard.asterisk.sql + 2: punctuation.accessor.dot.sql + 3: variable.language.wildcard.asterisk.sql + pop: 1 + # named privilidge level: database, table or method + - include: expect-other-name + + grant-on-user: + - match: \b(?i:on)\b + scope: keyword.other.ddl.sql + - include: expect-user-name + + grant-to-user: + - match: \b(?i:to)\b + scope: keyword.other.ddl.sql + - include: expect-user-identification-list + + grant-options: + - include: user-grant-privilidges + - include: user-resource-options + - include: else-pop + ###[ OTHER STATEMENTS ]######################################################## other-statements: - - meta_prepend: true - match: \b(?i:begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b scope: keyword.other.luw.sql - match: \b(?i:end)\b @@ -220,6 +291,24 @@ contexts: ###[ USER MANAGEMENT EXPRESSIONS ]############################################# + expect-user-identification-list: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: + - user-identification-list + - user-identification + - expect-user-name + + user-identification-list: + - match: ',' + scope: punctuation.separator.sequence.sql + push: + - user-identification + - expect-user-name + - include: else-pop + user-identification: - match: \b(?i:identified|by)\b scope: keyword.other.ddl.sql @@ -235,15 +324,22 @@ contexts: - include: else-pop user-auth-list: + # used by CREATE/ALTER user - match: ',' scope: punctuation.separator.sequence.sql push: - user-auth-args - expect-other-name + # used by GRANT statements + - match: \b(?i:or)\b + scope: keyword.operator.logical.sql + push: + - user-auth-args + - expect-other-name - include: else-pop user-auth-args: - - match: (?=,|\b(?i:require|with|account)\b) + - match: (?=,|\b(?i:account|on|or|require|with)\b) pop: 1 - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql @@ -256,7 +352,6 @@ contexts: - include: pop-on-top-level-reserved-word user-options: - - meta_scope: meta.user.sql - include: user-account-options - include: user-password-options - include: user-resource-options @@ -300,6 +395,18 @@ contexts: - match: \b(?i:none)\b scope: constant.language.null.sql + user-privilidges: + - include: user-all-privilidges + - include: user-grant-privilidges + + user-all-privilidges: + - match: \b(?i:all\s+privileges)\b + scope: constant.language.sql + + user-grant-privilidges: + - match: \b(?i:(?:grant|admin)\s+option)\b + scope: constant.language.sql + ###[ TYPES ]################################################################### after-type: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 5f0ee1a5f8..9e5fa87401 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -356,6 +356,155 @@ DROP USER IF EXISTS bob, clara ; -- ^^^^^ meta.user-name.sql -- ^ punctuation.terminator.statement.sql +-- ---------------------------------------------------------------------------- + +GRANT +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^ meta.statement.grant.sql keyword.other.ddl.sql +-- ^ meta.statement.grant.sql - keyword + +GRANT DROP TABLE, ALTER COLUMN +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^ punctuation.separator.sequence.sql + +GRANT ALTER COLUMN ON * +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^ meta.other-name.sql variable.language.wildcard.asterisk.sql + +GRANT ALTER TABLE ON *.* +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^^ meta.other-name.sql +-- ^ variable.language.wildcard.asterisk.sql +-- ^ punctuation.accessor.dot.sql +-- ^ variable.language.wildcard.asterisk.sql + +GRANT ALTER INDEX ON db_name.* +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^ meta.other-name.sql +-- ^ punctuation.accessor.dot.sql +-- ^ variable.language.wildcard.asterisk.sql + +GRANT ALTER COLUMN ON db_name.table_name +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^ meta.other-name.sql +-- ^ punctuation.accessor.dot.sql + +GRANT ALTER COLUMN ON table_name +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.other-name.sql + +GRANT CREATE INDEX ON TABLE * TO user1 IDENTIFIED BY 'password' ; +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ storage.type.sql +-- ^ meta.other-name.sql variable.language.wildcard.asterisk.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ meta.user-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.terminator.statement.sql + +GRANT CREATE INDEX ON PROCEDURE *.* TO user1 IDENTIFIED BY PASSWORD 'password_hash' ; +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^ storage.type.sql +-- ^^^ meta.other-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ meta.user-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.terminator.statement.sql + +GRANT CREATE INDEX ON PACKAGE *.* TO user1 IDENTIFIED VIA auth1 or auth2 ; +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ meta.other-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ meta.user-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ meta.other-name.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^^ meta.other-name.sql +-- ^ punctuation.terminator.statement.sql + +GRANT PROXY +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql + ON username +-- <- meta.statement.grant.sql +-- ^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.user-name.sql + TO user1 IDENTIFIED BY 'password', +-- <- meta.statement.grant.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ meta.user-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + user2 IDENTIFIED VIA auth USING PASSWORD('passord') +-- <- meta.statement.grant.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^^^^ meta.user-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ meta.other-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.function-call.sql +-- ^^^^^^^^ support.function.sql +-- ^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.arguments.end.sql + WITH GRANT OPTION ; +-- <- meta.statement.grant.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^ punctuation.terminator.statement.sql + +GRANT rolename TO role, user IDENTIFIED BY 'password' WITH ADMIN OPTION ; +-- <- meta.statement.grant.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.user-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^ meta.user-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.user-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^ punctuation.terminator.statement.sql -- ---------------------------------------------------------------------------- -- Legacy Tests From d2dd9620945f4463af2e36a270ec87bad82d7098 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 15 Jul 2022 19:02:27 +0200 Subject: [PATCH 155/250] MySQL: Fix account names Accounts may consist of `user@host` with `%` being a wildcard host name. --- SQL/MySQL.sublime-syntax | 46 +++++++++++++- SQL/tests/syntax/syntax_test_mysql.sql | 88 +++++++++++++++----------- 2 files changed, 94 insertions(+), 40 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 3643823f1a..64cd416337 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -425,7 +425,7 @@ contexts: - meta_include_prototype: false - include: comments - match: (?=\S) - set: [user-name, single-identifier] + set: [user-name, user-identifier] user-name: - meta_include_prototype: false @@ -437,13 +437,55 @@ contexts: - meta_include_prototype: false - include: comments - match: (?=\S) - set: [user-name-declaration, single-identifier] + set: [user-name-declaration, user-identifier] user-name-declaration: - meta_include_prototype: false - meta_content_scope: entity.name.user.sql - include: immediately-pop + user-identifier: + # https://mariadb.com/kb/en/grant/#account-names + - meta_include_prototype: false + - include: pop-on-top-level-reserved-word + - match: '' + set: + - identifier-host-accessor + - identifier-part + + identifier-host-accessor: + - meta_include_prototype: false + - match: \s*(@) + captures: + 1: punctuation.accessor.at.sql + set: identifier-host-part + - include: immediately-pop + + identifier-host-part: + - meta_include_prototype: false + - match: \% + scope: variable.language.wildcard.percent.sql + pop: 1 + - match: (')(%)(') + captures: + 1: punctuation.definition.identifier.begin.sql + 2: variable.language.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - match: (")(%)(") + captures: + 1: punctuation.definition.identifier.begin.sql + 2: variable.language.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - match: (`)(%)(`) + captures: + 1: punctuation.definition.identifier.begin.sql + 2: variable.language.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - include: identifier-part + ###[ LITERALS ]################################################################ regexps: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 9e5fa87401..fbb20a4e36 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -20,24 +20,32 @@ CREATE USER IF NOT EXISTS -- ^^^^^ entity.name.user.sql -- ^ punctuation.separator.sequence.sql - user2 IDENTIFIED BY 'password', + user2@localhost IDENTIFIED BY 'password', -- <- meta.statement.create.sql meta.user.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql --- ^^^^^ entity.name.user.sql --- ^^^^^^^^^^ keyword.other.ddl.sql --- ^^ keyword.other.ddl.sql --- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql --- ^ punctuation.separator.sequence.sql - - user3 IDENTIFIED BY PASSWORD 'password_hash', +-- ^^^^^^^^^^^^^^^ entity.name.user.sql +-- ^ punctuation.accessor.at.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql + + 'user3@'@'%' IDENTIFIED BY PASSWORD 'password_hash', -- <- meta.statement.create.sql meta.user.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql --- ^^^^^ entity.name.user.sql --- ^^^^^^^^^^ keyword.other.ddl.sql --- ^^ keyword.other.ddl.sql --- ^^^^^^^^ storage.modifier.sql --- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql --- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^ entity.name.user.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ - punctuation +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.accessor.at.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ variable.language.wildcard.percent.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql user4 IDENTIFIED VIA -- <- meta.statement.create.sql meta.user.sql @@ -336,25 +344,27 @@ ALTER USER IF EXISTS -- ---------------------------------------------------------------------------- -DROP USER bob ; +DROP USER bob@'%' ; -- <- meta.statement.drop.sql keyword.other.ddl.sql --- ^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^^^^^^^^^^^^ meta.statement.drop.sql -- ^ keyword.other.ddl.sql -- ^^^^ keyword.other.ddl.sql --- ^^^ meta.user-name.sql --- ^ punctuation.terminator.statement.sql +-- ^^^^^^^ meta.user-name.sql +-- ^ punctuation.accessor.at.sql +-- ^ punctuation.terminator.statement.sql -DROP USER IF EXISTS bob, clara ; +DROP USER IF EXISTS bob, clara@localhost ; -- <- meta.statement.drop.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql -- ^ keyword.other.ddl.sql -- ^^^^ keyword.other.ddl.sql -- ^^ keyword.control.conditional.if.sql -- ^^^^^^ keyword.operator.logical.sql -- ^^^ meta.user-name.sql -- ^ punctuation.separator.sequence.sql --- ^^^^^ meta.user-name.sql --- ^ punctuation.terminator.statement.sql +-- ^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^ punctuation.accessor.at.sql +-- ^ punctuation.terminator.statement.sql -- ---------------------------------------------------------------------------- @@ -405,7 +415,7 @@ GRANT ALTER COLUMN ON table_name -- ^^ keyword.other.ddl.sql -- ^^^^^^^^^^ meta.other-name.sql -GRANT CREATE INDEX ON TABLE * TO user1 IDENTIFIED BY 'password' ; +GRANT CREATE INDEX ON TABLE * TO user1@% IDENTIFIED BY 'password' ; -- <- meta.statement.grant.sql keyword.other.ddl.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql -- ^^ keyword.other.ddl.sql @@ -413,11 +423,13 @@ GRANT CREATE INDEX ON TABLE * TO user1 IDENTIFIED BY 'password' ; -- ^^^^^ storage.type.sql -- ^ meta.other-name.sql variable.language.wildcard.asterisk.sql -- ^^ keyword.other.ddl.sql --- ^^^^^ meta.user-name.sql --- ^^^^^^^^^^ keyword.other.ddl.sql --- ^^ keyword.other.ddl.sql --- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql --- ^ punctuation.terminator.statement.sql +-- ^^^^^^^ meta.user-name.sql +-- ^ punctuation.accessor.at.sql +-- ^ variable.language.wildcard.percent.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.terminator.statement.sql GRANT CREATE INDEX ON PROCEDURE *.* TO user1 IDENTIFIED BY PASSWORD 'password_hash' ; -- <- meta.statement.grant.sql keyword.other.ddl.sql @@ -434,21 +446,21 @@ GRANT CREATE INDEX ON PROCEDURE *.* TO user1 IDENTIFIED BY PASSWORD 'password_ha -- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql -- ^ punctuation.terminator.statement.sql -GRANT CREATE INDEX ON PACKAGE *.* TO user1 IDENTIFIED VIA auth1 or auth2 ; +GRANT CREATE INDEX ON PACKAGE *.* TO "user1" IDENTIFIED VIA auth1 or auth2 ; -- <- meta.statement.grant.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql -- ^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^ storage.type.sql -- ^^^ meta.other-name.sql -- ^^ keyword.other.ddl.sql --- ^^^^^ meta.user-name.sql --- ^^^^^^^^^^ keyword.other.ddl.sql --- ^^^ keyword.other.ddl.sql --- ^^^^^ meta.other-name.sql --- ^^ keyword.operator.logical.sql --- ^^^^^ meta.other-name.sql --- ^ punctuation.terminator.statement.sql +-- ^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ meta.other-name.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^^ meta.other-name.sql +-- ^ punctuation.terminator.statement.sql GRANT PROXY -- <- meta.statement.grant.sql keyword.other.ddl.sql From cb17a7133cf4070d65332cbb9c409ef9f9a26055 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 15 Jul 2022 19:19:31 +0200 Subject: [PATCH 156/250] MySQL: Add RENAME USER statements --- SQL/MySQL.sublime-syntax | 46 +++++++++++++++++++++----- SQL/tests/syntax/syntax_test_mysql.sql | 32 ++++++++++++++++++ 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 64cd416337..fffe0c75fd 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -8,7 +8,7 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: additional_reserved: |- - (?xi: begin | end | return | grant ) + (?xi: begin | end | return | grant | rename ) simple_types: |- (?xi: bigint | bigserial | bit | bool | boolean | box | bytea | cidr | circle @@ -27,6 +27,7 @@ contexts: statements: - meta_prepend: true - include: grant-statements + - include: rename-statements ###[ COMMENTS ]################################################################ @@ -105,7 +106,7 @@ contexts: - match: \b(?i:user)\b scope: keyword.other.ddl.sql set: - - drop-user-name-list + - user-name-list - expect-user-name - drop-user-condition @@ -113,12 +114,6 @@ contexts: - meta_include_prototype: false - include: maybe-condition - drop-user-name-list: - - match: ',' - scope: punctuation.separator.sequence.sql - push: expect-user-name - - include: else-pop - ###[ DDL ALTER STATEMENTS ]#################################################### alter-target: @@ -254,6 +249,35 @@ contexts: - include: user-resource-options - include: else-pop +###[ RENAME STATEMENTS ]####################################################### + + rename-statements: + # https://mariadb.com/kb/en/rename-user + - match: \b(?i:rename)\b + scope: keyword.other.ddl.sql + push: + - rename-meta + - rename-targets + + rename-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.rename.sql + - include: immediately-pop + + rename-targets: + - match: \b(?i:user)\b + scope: keyword.other.ddl.sql + set: + - rename-user + - expect-user-name + - include: else-pop + + rename-user: + - match: \b(?i:to)\b + scope: keyword.other.ddl.sql + push: expect-user-name + - include: user-name-list + ###[ OTHER STATEMENTS ]######################################################## other-statements: @@ -323,6 +347,12 @@ contexts: - include: strings - include: else-pop + user-name-list: + - match: ',' + scope: punctuation.separator.sequence.sql + push: expect-user-name + - include: else-pop + user-auth-list: # used by CREATE/ALTER user - match: ',' diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index fbb20a4e36..10a4c9d42d 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -518,6 +518,38 @@ GRANT rolename TO role, user IDENTIFIED BY 'password' WITH ADMIN OPTION ; -- ^^^^^^^^^^^^ constant.language.sql -- ^ punctuation.terminator.statement.sql +-- ---------------------------------------------------------------------------- + +RENAME +-- <- meta.statement.rename.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.rename.sql +-- ^^^ keyword.other.ddl.sql +-- ^ - keyword + +RENAME USER +-- <- meta.statement.rename.sql keyword.other.ddl.sql +-- ^^^^^^^^^ meta.statement.rename.sql +-- ^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ keyword.other.ddl.sql +-- ^ - keyword + +RENAME USER 'donald' TO 'duck'@'localhost', 'mickey' TO 'mouse'@'localhost'; +-- <- meta.statement.rename.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.rename.sql +-- ^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^ meta.user-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.user-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^ punctuation.terminator.statement.sql + -- ---------------------------------------------------------------------------- -- Legacy Tests -- ---------------------------------------------------------------------------- From da874e922fb22a97f74884beb9719c1b497b1722 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 15 Jul 2022 19:42:30 +0200 Subject: [PATCH 157/250] MySQL: Add REVOKE statements --- SQL/MySQL.sublime-syntax | 78 +++++++++++++++++++------- SQL/SQL (basic).sublime-syntax | 5 ++ SQL/tests/syntax/syntax_test_mysql.sql | 67 ++++++++++++++++++++++ 3 files changed, 129 insertions(+), 21 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index fffe0c75fd..3f7092363e 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -8,7 +8,7 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: additional_reserved: |- - (?xi: begin | end | return | grant | rename ) + (?xi: begin | end | return | grant | rename | revoke ) simple_types: |- (?xi: bigint | bigserial | bit | bool | boolean | box | bytea | cidr | circle @@ -28,6 +28,7 @@ contexts: - meta_prepend: true - include: grant-statements - include: rename-statements + - include: revoke-statements ###[ COMMENTS ]################################################################ @@ -211,29 +212,12 @@ contexts: set: grant-operations grant-operations: - - match: \b(?i:on)\b - scope: keyword.other.ddl.sql - set: grant-on-type - match: (?=[;)]|\b(?i:grant|to|with)\b) pop: 1 + - include: on-privilidge-level - include: comma-separators - include: user-privilidges - grant-on-type: - # object type - - match: \b(?i:table|function|procedure|package)\b - scope: storage.type.sql - # wildcard privilidge level - - match: (\*)(?:(\.)(\*))? - scope: meta.other-name.sql - captures: - 1: variable.language.wildcard.asterisk.sql - 2: punctuation.accessor.dot.sql - 3: variable.language.wildcard.asterisk.sql - pop: 1 - # named privilidge level: database, table or method - - include: expect-other-name - grant-on-user: - match: \b(?i:on)\b scope: keyword.other.ddl.sql @@ -257,14 +241,14 @@ contexts: scope: keyword.other.ddl.sql push: - rename-meta - - rename-targets + - rename-target rename-meta: - meta_include_prototype: false - meta_scope: meta.statement.rename.sql - include: immediately-pop - rename-targets: + rename-target: - match: \b(?i:user)\b scope: keyword.other.ddl.sql set: @@ -278,6 +262,37 @@ contexts: push: expect-user-name - include: user-name-list +###[ REVOKE STATEMENTS ]####################################################### + + revoke-statements: + # https://mariadb.com/kb/en/revoke + - match: \b(?i:revoke)\b + scope: keyword.other.ddl.sql + push: + - revoke-meta + - revoke-options + - revoke-privilidges + + revoke-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.revoke.sql + - include: immediately-pop + + revoke-privilidges: + - match: (?=[;)]|\b(?i:for|from)\b) + pop: 1 + - include: on-privilidge-level + - include: comma-separators + - include: user-privilidges + + revoke-options: + - match: \b(?i:for|from)\b + scope: keyword.other.ddl.sql + push: + - user-name-list + - expect-user-name + - include: else-pop + ###[ OTHER STATEMENTS ]######################################################## other-statements: @@ -426,6 +441,7 @@ contexts: scope: constant.language.null.sql user-privilidges: + - include: column-reference-lists - include: user-all-privilidges - include: user-grant-privilidges @@ -437,6 +453,26 @@ contexts: - match: \b(?i:(?:grant|admin)\s+option)\b scope: constant.language.sql + on-privilidge-level: + - match: \b(?i:on)\b + scope: keyword.other.ddl.sql + set: privilidge-level + + privilidge-level: + # object type + - match: \b(?i:table|function|procedure|package)\b + scope: storage.type.sql + # wildcard privilidge level + - match: (\*)(?:(\.)(\*))? + scope: meta.other-name.sql + captures: + 1: variable.language.wildcard.asterisk.sql + 2: punctuation.accessor.dot.sql + 3: variable.language.wildcard.asterisk.sql + pop: 1 + # named privilidge level: database, table or method + - include: expect-other-name + ###[ TYPES ]################################################################### after-type: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index ab21091bb7..aaed123711 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -699,6 +699,11 @@ contexts: scope: punctuation.section.group.begin.sql set: inside-column-reference-list + column-reference-lists: + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-column-reference-list + inside-column-reference-list: - meta_scope: meta.group.table-columns.sql - match: \) diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 10a4c9d42d..cde1ffd21a 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -550,6 +550,73 @@ RENAME USER 'donald' TO 'duck'@'localhost', 'mickey' TO 'mouse'@'localhost'; -- ^^^^^^^^^^^^^^^^^^^ meta.user-name.sql -- ^ punctuation.terminator.statement.sql +-- ---------------------------------------------------------------------------- + +REVOKE ; +-- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.revoke.sql +-- ^^^ keyword.other.ddl.sql +-- ^ punctuation.terminator.statement.sql + +REVOKE ALTER COLUMN (`col1`, `names`) ; +-- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +REVOKE ALL PRIVILEGES, GRANT OPTION FROM user@'%', user2 ; +-- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^ constant.language.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.user-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.user-name.sql +-- ^ punctuation.terminator.statement.sql + +REVOKE SUPER ON *.* FROM 'alexander'@'localhost'; +-- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^ meta.other-name.sql +-- ^ variable.language.wildcard.asterisk.sql +-- ^ punctuation.accessor.dot.sql +-- ^ variable.language.wildcard.asterisk.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^ punctuation.terminator.statement.sql + +REVOKE ADMIN OPTION FOR role FROM grantee, grantee2 ; +-- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ meta.user-name.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.user-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.user-name.sql +-- ^ punctuation.terminator.statement.sql + +REVOKE role1, role2 FROM grantee, grantee2 ; +-- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.user-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.user-name.sql +-- ^ punctuation.terminator.statement.sql + -- ---------------------------------------------------------------------------- -- Legacy Tests -- ---------------------------------------------------------------------------- From df5be4c892f6157b5475dd16282095750d40aca0 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 16 Jul 2022 13:38:58 +0200 Subject: [PATCH 158/250] MySQL: Add SET PASSWORD statements --- SQL/MySQL.sublime-syntax | 30 ++++++++++++ SQL/SQL (basic).sublime-syntax | 24 +++++++--- SQL/TSQL.sublime-syntax | 27 ++++++----- SQL/tests/syntax/syntax_test_mysql.sql | 66 ++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 19 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 3f7092363e..9fa9449da4 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -182,6 +182,30 @@ contexts: - match: \b(?i:straight_join|natural)\b scope: keyword.other.dml.sql +###[ DML SET STATEMENTS ]###################################################### + + set-target: + - meta_prepend: true + - include: set-password + + set-password: + # https://mariadb.com/kb/en/set-password + - match: \b(?i:password)\b + scope: keyword.other.dml.sql + set: + - set-other-assignment + - maybe-for-user + + set-other-assignment: + - match: = + scope: keyword.operator.assignment.sql + set: set-other-value + - include: else-pop + + set-other-value: + - include: expressions + - include: pop-on-top-level-reserved-word + ###[ GRANT STATEMENTS ]######################################################## grant-statements: @@ -330,6 +354,12 @@ contexts: ###[ USER MANAGEMENT EXPRESSIONS ]############################################# + maybe-for-user: + - match: \b(?i:for)\b + scope: keyword.other.dml.sql + set: expect-user-name + - include: else-pop + expect-user-identification-list: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index aaed123711..c93528131f 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -391,9 +391,7 @@ contexts: - match: \b(?i:(?:insert\s+into|truncate))\b scope: keyword.other.dml.sql push: expect-table-name - - match: \b(?i:set)\b - scope: keyword.other.dml.sql - push: set + - include: set-statements - match: \b(?i:(?:default\s+)?values)\b scope: keyword.other.dml.II.sql - include: distinct @@ -429,6 +427,23 @@ contexts: pop: 1 - include: else-pop +###[ DML SET STATEMENTS ]###################################################### + + set-statements: + - match: \b(?i:set)\b + scope: keyword.other.dml.sql + push: + - set-meta + - set-target + + set-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.set.sql + - include: immediately-pop + + set-target: + - include: else-pop + ###[ OTHER STATEMENTS ]######################################################## other-statements: @@ -554,9 +569,6 @@ contexts: pop: 1 - include: sql - set: - - include: else-pop - ###[ TABLE NAMES ]############################################################# table-name-or-subquery: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 1f0d9d0136..0af7d49dd4 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -159,6 +159,20 @@ contexts: scope: keyword.other.dml.sql push: table-name-or-subquery +###[ DML SET STATEMENTS ]###################################################### + + set-target: + - meta_prepend: true + - match: \b(?i:nocount|ansi_nulls|quoted_identifier)\b + scope: constant.language.switch.tsql + - match: \b(?i:identity_insert)\b + scope: constant.language.switch.tsql + push: expect-table-name + - include: onoff-constants + - include: variables + - include: augmented-assignment-operators + - include: operators + ###[ OTHER STATEMENTS ]######################################################## other-statements: @@ -399,19 +413,6 @@ contexts: - include: dml-statements - include: expressions - set: - - meta_prepend: true - - match: \b(?i:nocount|ansi_nulls|quoted_identifier)\b - scope: constant.language.switch.tsql - - match: \b(?i:identity_insert)\b - scope: constant.language.switch.tsql - push: expect-table-name - - include: onoff-constants - - include: variables - - include: augmented-assignment-operators - - include: operators - - include: else-pop - ###[ WITH EXPRESSIONS ]######################################################## maybe-with-table-options: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index cde1ffd21a..6f1c67b680 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -617,6 +617,72 @@ REVOKE role1, role2 FROM grantee, grantee2 ; -- ^^^^^^^^ meta.user-name.sql -- ^ punctuation.terminator.statement.sql +-- ---------------------------------------------------------------------------- + +SET +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^ meta.statement.set.sql - keyword + +SET PASSWORD = +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^ meta.statement.set.sql +-- ^ - keyword +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ - keyword +-- ^ keyword.operator.assignment.sql + +SET PASSWORD FOR user1@localhost = +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^ - keyword +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^ punctuation.accessor.at.sql +-- ^ keyword.operator.assignment.sql + +SET PASSWORD = PASSWORD('some password') +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^^ meta.function-call - meta.group +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql meta.group.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^ support.function.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.arguments.end.sql + +SET PASSWORD = OLD_PASSWORD('some password'); +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^^^^^^ meta.function-call - meta.group +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql meta.group.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^ support.function.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.arguments.end.sql +-- ^ punctuation.terminator.statement.sql + +SET PASSWORD for `user@`@'%' = 'encrypted password'; +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^ meta.user-name.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.accessor.at.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ variable.language.wildcard.percent.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.terminator.statement.sql + -- ---------------------------------------------------------------------------- -- Legacy Tests -- ---------------------------------------------------------------------------- From dae0ec0a6474db2791843ec39e853ce00ed21ba6 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 16 Jul 2022 18:07:47 +0200 Subject: [PATCH 159/250] MySQL: Add CREATE ROLE statements --- SQL/MySQL.sublime-syntax | 44 ++++++++++++++++++++ SQL/SQL (basic).sublime-syntax | 9 ++++- SQL/tests/syntax/syntax_test_mysql.sql | 56 ++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 9fa9449da4..cfd6dcf02b 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -66,8 +66,26 @@ contexts: - match: \b(?i:unique|fulltext|spatial)\b scope: keyword.other.ddl.sql - include: target-algorithm + - include: create-role - include: create-user + create-role: + # https://mariadb.com/kb/en/create-role + - match: \b(?i:role)\b + scope: keyword.other.ddl.sql + set: + - create-role-args + - expect-user-name-declaration + - create-role-condition + + create-role-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-role-args: + - meta_scope: meta.user.sql + - include: maybe-with-admin-user + create-user: # https://mariadb.com/kb/en/create-user - match: \b(?i:user)\b @@ -336,6 +354,16 @@ contexts: - match: \b(?i:using)\b scope: keyword.other.mysql + built-in-user-function-calls: + - match: \b(?i:(?:current|session|system)_(?:role|user))\b + scope: support.function.scalar.sql + push: function-call-arguments + + built-in-user-function-call: + - match: \b(?i:(?:current|session|system)_(?:role|user))\b + scope: support.function.scalar.sql + set: function-call-arguments + table-name-or-subquery: - meta_prepend: true - meta_include_prototype: false @@ -354,6 +382,21 @@ contexts: ###[ USER MANAGEMENT EXPRESSIONS ]############################################# + maybe-with-admin-user: + - meta_scope: meta.user.sql + - match: \b(?i:with)\b + scope: keyword.other.ddl.sql + set: + - expect-user-name + - maybe-admin + - include: else-pop + + maybe-admin: + - match: \b(?i:admin)\b + scope: keyword.other.ddl.sql + pop: 1 + - include: else-pop + maybe-for-user: - match: \b(?i:for)\b scope: keyword.other.dml.sql @@ -520,6 +563,7 @@ contexts: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false - include: comments + - include: built-in-user-function-call - match: (?=\S) set: [user-name, user-identifier] diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index c93528131f..5bb76bf7ca 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -512,6 +512,7 @@ contexts: function-calls: - include: built-in-aggregate-function-calls - include: built-in-scalar-function-calls + - include: built-in-user-function-calls - include: user-defined-function-calls built-in-aggregate-function-calls: @@ -522,8 +523,14 @@ contexts: built-in-scalar-function-calls: # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - - match: \b(?i:CURRENT_(?:DATE|TIME(?:STAMP)?|USER)|(?:SESSION|SYSTEM)_USER)\b + - match: \b(?i:current_(?:date|time(?:stamp)?))\b scope: support.function.scalar.sql + push: function-call-arguments + + built-in-user-function-calls: + - match: \b(?i:(?:current|session|system)_user)\b + scope: support.function.scalar.sql + push: function-call-arguments user-defined-function-calls: - match: \b{{simple_identifier}}(?=\s*\() diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 6f1c67b680..283827448a 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -5,6 +5,62 @@ -- https://mariadb.com/kb/en/account-management-sql-commands -- ---------------------------------------------------------------------------- +CREATE ROLE role +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.user +-- ^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ keyword.other.ddl.sql +-- ^ - keyword - entity +-- ^^^^ entity.name.user.sql +-- ^ - entity + +CREATE ROLE IF NOT EXISTS role +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^ keyword.control.conditional.if.sql +-- ^ - keyword +-- ^^^ keyword.operator.logical.sql +-- ^ - keyword +-- ^^^^^^ keyword.operator.logical.sql +-- ^ - keyword - entity +-- ^^^^ entity.name.user.sql +-- ^ - entity + +CREATE OR REPLACE ROLE IF NOT EXISTS role +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql +-- ^^^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^ entity.name.user.sql + +CREATE OR REPLACE ROLE with WITH ADMIN lorinda@localhost +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^ punctuation.accessor.at.sql + +CREATE ROLE role WITH ADMIN CURRENT_ROLE +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ support.function.scalar.sql + CREATE USER IF NOT EXISTS -- <- meta.statement.create.sql keyword.other.ddl.sql -- ^^^^ meta.statement.create.sql From d7ab07f21ed6cfd87adb7b8d922c69bfb3ab2648 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 16 Jul 2022 18:14:16 +0200 Subject: [PATCH 160/250] MySQL: Add DROP ROLE statements --- SQL/MySQL.sublime-syntax | 9 ++++-- SQL/tests/syntax/syntax_test_mysql.sql | 42 ++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index cfd6dcf02b..1537dc7a46 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -121,11 +121,12 @@ contexts: - include: drop-user drop-user: + # https://mariadb.com/kb/en/drop-role # https://mariadb.com/kb/en/drop-user - - match: \b(?i:user)\b + - match: \b(?i:role|user)\b scope: keyword.other.ddl.sql set: - - user-name-list + - drop-user-args - expect-user-name - drop-user-condition @@ -133,6 +134,10 @@ contexts: - meta_include_prototype: false - include: maybe-condition + drop-user-args: + - meta_scope: meta.user.sql + - include: user-name-list + ###[ DDL ALTER STATEMENTS ]#################################################### alter-target: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 283827448a..3dd0836309 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -400,9 +400,46 @@ ALTER USER IF EXISTS -- ---------------------------------------------------------------------------- +DROP +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword + +DROP ROLE role ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^ meta.statement.drop.sql meta.user.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ meta.user-name.sql +-- ^ punctuation.terminator.statement.sql + +DROP ROLE IF EXISTS role1, role2, role3; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.user.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^ keyword.control.conditional.if.sql +-- ^ - keyword +-- ^^^^^^ keyword.operator.logical.sql +-- ^ - keyword +-- ^^^^^ meta.user-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.user-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.user-name.sql +-- ^ punctuation.terminator.statement.sql + DROP USER bob@'%' ; -- <- meta.statement.drop.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^^^^ meta.statement.drop.sql meta.user.sql -- ^ keyword.other.ddl.sql -- ^^^^ keyword.other.ddl.sql -- ^^^^^^^ meta.user-name.sql @@ -411,7 +448,8 @@ DROP USER bob@'%' ; DROP USER IF EXISTS bob, clara@localhost ; -- <- meta.statement.drop.sql keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.user.sql -- ^ keyword.other.ddl.sql -- ^^^^ keyword.other.ddl.sql -- ^^ keyword.control.conditional.if.sql From 1d21f0672e7c637c71f46e6dd3e1834388b72a3d Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 16 Jul 2022 18:22:10 +0200 Subject: [PATCH 161/250] MySQL: Add SET ROLE statements --- SQL/MySQL.sublime-syntax | 18 +++++++++++ SQL/tests/syntax/syntax_test_mysql.sql | 44 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 1537dc7a46..7537a92ccb 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -210,6 +210,7 @@ contexts: set-target: - meta_prepend: true - include: set-password + - include: set-role set-password: # https://mariadb.com/kb/en/set-password @@ -219,6 +220,23 @@ contexts: - set-other-assignment - maybe-for-user + set-role: + # https://mariadb.com/kb/en/set-role + # https://mariadb.com/kb/en/set-default-role + - match: \b(?i:(?:(default)\s+)?(role))\b + captures: + 1: keyword.other.dml.sql + 2: keyword.other.dml.sql + set: + - maybe-for-user + - set-role-name + + set-role-name: + - match: \b(?i:none)\b + scope: constant.language.null.sql + pop: 1 + - include: expect-user-name + set-other-assignment: - match: = scope: keyword.operator.assignment.sql diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 3dd0836309..7672e37e91 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -777,6 +777,50 @@ SET PASSWORD for `user@`@'%' = 'encrypted password'; -- ^^^^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql -- ^ punctuation.terminator.statement.sql +SET ROLE NONE +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^ meta.statement.set.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ constant.language.null.sql + +SET ROLE role +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^ meta.statement.set.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ meta.user-name.sql + +SET DEFAULT ROLE NONE +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ constant.language.null.sql + +SET DEFAULT ROLE role +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ meta.user-name.sql + +SET DEFAULT ROLE NONE FOR user@host +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ constant.language.null.sql +-- ^^^ keyword.other.dml.sql +-- ^^^^^^^^^ meta.user-name.sql + +SET DEFAULT ROLE role FOR user@host +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ meta.user-name.sql +-- ^^^ keyword.other.dml.sql +-- ^^^^^^^^^ meta.user-name.sql + -- ---------------------------------------------------------------------------- -- Legacy Tests -- ---------------------------------------------------------------------------- From d32498632deb4ae31aa9e359a5f31ea45143967f Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 16 Jul 2022 18:44:15 +0200 Subject: [PATCH 162/250] MySQL: Add SHOW ROLE statements --- SQL/MySQL.sublime-syntax | 27 ++++++++++++++++- SQL/tests/syntax/syntax_test_mysql.sql | 41 ++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 7537a92ccb..d6c4cd5496 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -8,7 +8,7 @@ extends: Packages/SQL/SQL (basic).sublime-syntax variables: additional_reserved: |- - (?xi: begin | end | return | grant | rename | revoke ) + (?xi: begin | end | return | grant | rename | revoke | show ) simple_types: |- (?xi: bigint | bigserial | bit | bool | boolean | box | bytea | cidr | circle @@ -29,6 +29,7 @@ contexts: - include: grant-statements - include: rename-statements - include: revoke-statements + - include: show-statements ###[ COMMENTS ]################################################################ @@ -358,6 +359,30 @@ contexts: - expect-user-name - include: else-pop +###[ SHOW STATEMENTS ]######################################################### + + show-statements: + - match: \b(?i:show)\b + scope: keyword.other.dml.sql + push: + - show-meta + - show-target + + show-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.show.sql + - include: immediately-pop + + show-target: + # https://mariadb.com/kb/en/show-grants + - include: show-grants + - include: else-pop + + show-grants: + - match: \b(?i:grants)\b + scope: keyword.other.dml.sql + set: maybe-for-user + ###[ OTHER STATEMENTS ]######################################################## other-statements: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 7672e37e91..4032d17f95 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -821,6 +821,47 @@ SET DEFAULT ROLE role FOR user@host -- ^^^ keyword.other.dml.sql -- ^^^^^^^^^ meta.user-name.sql +-- ---------------------------------------------------------------------------- + +SHOW GRANTS +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^^^^ keyword.other.dml.sql +-- ^ - keyword + +SHOW GRANTS FOR user@host +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^^^^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^ keyword.other.dml.sql +-- ^^^^^^^^^ meta.user-name.sql + +SHOW GRANTS FOR role +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^^^^ keyword.other.dml.sql +-- ^ - keyword +-- ^^^ keyword.other.dml.sql +-- ^^^^ meta.user-name.sql + +SHOW GRANTS FOR CURRENT_USER; +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql + +SHOW GRANTS FOR CURRENT_USER(); +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^^ meta.function-call.sql meta.group.sql + -- ---------------------------------------------------------------------------- -- Legacy Tests -- ---------------------------------------------------------------------------- From 5707b4fe1a79f0c8b1ea3b02e0f9702fb97dea78 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 16 Jul 2022 18:53:55 +0200 Subject: [PATCH 163/250] MySQL: Add SHOW CREATE USER statements --- SQL/MySQL.sublime-syntax | 11 ++++++++++- SQL/tests/syntax/syntax_test_mysql.sql | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index d6c4cd5496..dfcdedb4b4 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -374,11 +374,20 @@ contexts: - include: immediately-pop show-target: - # https://mariadb.com/kb/en/show-grants + - include: show-create-user - include: show-grants - include: else-pop + show-create-user: + # https://mariadb.com/kb/en/show-create-user + - match: \b(?i:(create)\s+(user))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: expect-user-name + show-grants: + # https://mariadb.com/kb/en/show-grants - match: \b(?i:grants)\b scope: keyword.other.dml.sql set: maybe-for-user diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 4032d17f95..04e85a20f0 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -823,6 +823,14 @@ SET DEFAULT ROLE role FOR user@host -- ---------------------------------------------------------------------------- +SHOW CREATE USER user_name +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ meta.user-name.sql + SHOW GRANTS -- <- meta.statement.show.sql keyword.other.dml.sql -- ^^^^^^^^^ meta.statement.show.sql From 6f9e8cb1eb054cd3c1357a4ae7befd1b8cefd194 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 08:55:08 +0200 Subject: [PATCH 164/250] MySQL: Refactor algorithm assignments --- SQL/MySQL.sublime-syntax | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index dfcdedb4b4..385072b1ea 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -66,7 +66,7 @@ contexts: # index modifiers - match: \b(?i:unique|fulltext|spatial)\b scope: keyword.other.ddl.sql - - include: target-algorithm + - include: algorithms - include: create-role - include: create-user @@ -118,7 +118,7 @@ contexts: drop-target: - meta_prepend: true - - include: target-algorithm + - include: algorithms - include: drop-user drop-user: @@ -143,7 +143,7 @@ contexts: alter-target: - meta_prepend: true - - include: target-algorithm + - include: algorithms - include: alter-user alter-columns: @@ -176,21 +176,6 @@ contexts: - meta_scope: meta.user.sql - include: user-options -###[ DDL STATEMENT PROTOTYPES ]################################################ - - target-algorithm: - - match: \b(?i:(algorithm))\s*(=) - captures: - 1: keyword.other.mysql - 2: keyword.operator.assignment.mysql - push: target-algorithm-value - - target-algorithm-value: - - match: \b(?i:merge|temptable|undefined)\b - scope: constant.language.sql - pop: 1 - - include: else-pop - ###[ DML STATEMENTS ]########################################################## dml-statements: @@ -428,6 +413,25 @@ contexts: pop: 1 - include: comments +###[ ALGORITHM EXPRESSIONS ]################################################### + + algorithms: + - match: \b(?i:algorithm)\b + scope: keyword.other.mysql + push: algorithm-assignment + + algorithm-assignment: + - match: = + scope: keyword.operator.assignment.sql + set: algorithm-value + - include: else-pop + + algorithm-value: + - match: \b(?i:merge|temptable|undefined)\b + scope: constant.language.sql + pop: 1 + - include: else-pop + ###[ COLUMN DECLARATIONS ]##################################################### inside-column-declaration-list: From 90096a51d45d4d3bae69dd0e56ecb5d87fed1aba Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 16 Jul 2022 19:07:46 +0200 Subject: [PATCH 165/250] MySQL: Reorganize test categories Prepare for DDL tests. User/Role related account management statements are a sub-group of data definition language. --- SQL/tests/syntax/syntax_test_mysql.sql | 83 +++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 04e85a20f0..e814fa463a 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -1,8 +1,14 @@ -- SYNTAX TEST "Packages/SQL/MySQL.sublime-syntax" -- ---------------------------------------------------------------------------- --- Account Management SQL Commands --- https://mariadb.com/kb/en/account-management-sql-commands +-- Data Definition Statements +-- https://mariadb.com/kb/en/data-definition +-- ---------------------------------------------------------------------------- + + +-- ---------------------------------------------------------------------------- +-- Create Role Statements +-- https://mariadb.com/kb/en/create-role -- ---------------------------------------------------------------------------- CREATE ROLE role @@ -61,6 +67,12 @@ CREATE ROLE role WITH ADMIN CURRENT_ROLE -- ^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^^^ support.function.scalar.sql + +-- ---------------------------------------------------------------------------- +-- Create User Statements +-- https://mariadb.com/kb/en/create-user +-- ---------------------------------------------------------------------------- + CREATE USER IF NOT EXISTS -- <- meta.statement.create.sql keyword.other.ddl.sql -- ^^^^ meta.statement.create.sql @@ -233,6 +245,10 @@ CREATE USER IF NOT EXISTS -- ^ meta.number.integer.decimal.sql constant.numeric.value.sql -- ^^^ keyword.other.unit.sql + +-- ---------------------------------------------------------------------------- +-- Alter User Statements +-- https://mariadb.com/kb/en/alter-user -- ---------------------------------------------------------------------------- ALTER USER IF EXISTS @@ -398,6 +414,10 @@ ALTER USER IF EXISTS -- ^ meta.number.integer.decimal.sql constant.numeric.value.sql -- ^^^ keyword.other.unit.sql + +-- ---------------------------------------------------------------------------- +-- Drop Statements +-- https://mariadb.com/kb/en/drop -- ---------------------------------------------------------------------------- DROP @@ -406,6 +426,12 @@ DROP -- ^ keyword.other.ddl.sql -- ^ - keyword + +-- ---------------------------------------------------------------------------- +-- Drop Role Statements +-- https://mariadb.com/kb/en/drop-role +-- ---------------------------------------------------------------------------- + DROP ROLE role ; -- <- meta.statement.drop.sql keyword.other.ddl.sql -- ^^ meta.statement.drop.sql - meta.user @@ -436,6 +462,12 @@ DROP ROLE IF EXISTS role1, role2, role3; -- ^^^^^ meta.user-name.sql -- ^ punctuation.terminator.statement.sql + +-- ---------------------------------------------------------------------------- +-- Drop User Statements +-- https://mariadb.com/kb/en/drop-user +-- ---------------------------------------------------------------------------- + DROP USER bob@'%' ; -- <- meta.statement.drop.sql keyword.other.ddl.sql -- ^^ meta.statement.drop.sql - meta.user @@ -460,6 +492,12 @@ DROP USER IF EXISTS bob, clara@localhost ; -- ^ punctuation.accessor.at.sql -- ^ punctuation.terminator.statement.sql + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Grant Statements +-- https://mariadb.com/kb/en/grant -- ---------------------------------------------------------------------------- GRANT @@ -612,6 +650,12 @@ GRANT rolename TO role, user IDENTIFIED BY 'password' WITH ADMIN OPTION ; -- ^^^^^^^^^^^^ constant.language.sql -- ^ punctuation.terminator.statement.sql + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Rename User Statements +-- https://mariadb.com/kb/en/rename-user -- ---------------------------------------------------------------------------- RENAME @@ -644,6 +688,12 @@ RENAME USER 'donald' TO 'duck'@'localhost', 'mickey' TO 'mouse'@'localhost'; -- ^^^^^^^^^^^^^^^^^^^ meta.user-name.sql -- ^ punctuation.terminator.statement.sql + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Revoke Statements +-- https://mariadb.com/kb/en/revoke -- ---------------------------------------------------------------------------- REVOKE ; @@ -711,6 +761,12 @@ REVOKE role1, role2 FROM grantee, grantee2 ; -- ^^^^^^^^ meta.user-name.sql -- ^ punctuation.terminator.statement.sql + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Set Password Statements +-- https://mariadb.com/kb/en/set-password -- ---------------------------------------------------------------------------- SET @@ -777,6 +833,14 @@ SET PASSWORD for `user@`@'%' = 'encrypted password'; -- ^^^^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql -- ^ punctuation.terminator.statement.sql + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Set Role Statements +-- https://mariadb.com/kb/en/set-role +-- ---------------------------------------------------------------------------- + SET ROLE NONE -- <- meta.statement.set.sql keyword.other.dml.sql -- ^^^^^^^^^^ meta.statement.set.sql @@ -821,6 +885,12 @@ SET DEFAULT ROLE role FOR user@host -- ^^^ keyword.other.dml.sql -- ^^^^^^^^^ meta.user-name.sql + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Show Create User Statements +-- https://mariadb.com/kb/en/show-create-user -- ---------------------------------------------------------------------------- SHOW CREATE USER user_name @@ -831,6 +901,14 @@ SHOW CREATE USER user_name -- ^^^^ keyword.other.ddl.sql -- ^^^^^^^^^ meta.user-name.sql + +-- ---------------------------------------------------------------------------- +-- Account Management SQL Commands +-- ------------------------------- +-- Show Grants Statements +-- https://mariadb.com/kb/en/show-grants +-- ---------------------------------------------------------------------------- + SHOW GRANTS -- <- meta.statement.show.sql keyword.other.dml.sql -- ^^^^^^^^^ meta.statement.show.sql @@ -870,6 +948,7 @@ SHOW GRANTS FOR CURRENT_USER(); -- ^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql -- ^^ meta.function-call.sql meta.group.sql + -- ---------------------------------------------------------------------------- -- Legacy Tests -- ---------------------------------------------------------------------------- From d9e2f22c16a472213a90ee46473cdb74d7784fc2 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 09:35:18 +0200 Subject: [PATCH 166/250] MySQL: Reorganize column declaration expressions --- SQL/MySQL.sublime-syntax | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 385072b1ea..baf2c65b74 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -432,15 +432,6 @@ contexts: pop: 1 - include: else-pop -###[ COLUMN DECLARATIONS ]##################################################### - - inside-column-declaration-list: - - meta_prepend: true - - match: \b(?i:auto_increment)\b - scope: keyword.other.mysql - - match: \b(?i:(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)) - scope: keyword.other.object-comments.sql - ###[ USER MANAGEMENT EXPRESSIONS ]############################################# maybe-with-admin-user: @@ -607,6 +598,15 @@ contexts: # named privilidge level: database, table or method - include: expect-other-name +###[ COLUMN DECLARATIONS ]##################################################### + + inside-column-declaration-list: + - meta_prepend: true + - match: \b(?i:auto_increment)\b + scope: keyword.other.mysql + - match: \b(?i:(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)) + scope: keyword.other.object-comments.sql + ###[ TYPES ]################################################################### after-type: From 5e3e28ac7cb67d477debdf1db7cc1ae07594405c Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 09:55:39 +0200 Subject: [PATCH 167/250] MySQL: Add CREATE DATABASE/SCHEMA statements --- SQL/MySQL.sublime-syntax | 25 ++++++ SQL/SQL (basic).sublime-syntax | 12 +++ SQL/tests/syntax/syntax_test_mysql.sql | 103 +++++++++++++++++++++++++ 3 files changed, 140 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index baf2c65b74..b86806b579 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -67,9 +67,34 @@ contexts: - match: \b(?i:unique|fulltext|spatial)\b scope: keyword.other.ddl.sql - include: algorithms + - include: create-database - include: create-role - include: create-user + create-database: + # https://mariadb.com/kb/en/create-database + - match: \b(?i:database|schema)\b + scope: keyword.other.ddl.sql + set: + - create-database-args + - expect-database-creation-name + - create-database-condition + + create-database-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-database-args: + - meta_scope: meta.database.sql + - match: \b(?i:comment)\b + scope: keyword.other.ddl.sql + - match: \b(?i:(?:default\s+)?(?:character\s+set|collate))\b + scope: variable.parameter.database.sql + - match: = + scope: keyword.operator.assignment.sql + - include: strings + - include: else-pop + create-role: # https://mariadb.com/kb/en/create-role - match: \b(?i:role)\b diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 5bb76bf7ca..f77bd9c619 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -820,6 +820,18 @@ contexts: - meta_content_scope: meta.column-alias.sql - include: immediately-pop + expect-database-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [database-creation-name, single-identifier] + + database-creation-name: + - meta_include_prototype: false + - meta_content_scope: entity.name.struct.database.sql + - include: immediately-pop + expect-database-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index e814fa463a..153bdff2b6 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -5,6 +5,109 @@ -- https://mariadb.com/kb/en/data-definition -- ---------------------------------------------------------------------------- +-- ---------------------------------------------------------------------------- +-- Create Database Statements +-- https://mariadb.com/kb/en/create-database +-- +-- CREATE [OR REPLACE] {DATABASE | SCHEMA} [IF NOT EXISTS] db_name +-- [create_specification] ... +-- +-- create_specification: +-- [DEFAULT] CHARACTER SET [=] charset_name +-- | [DEFAULT] COLLATE [=] collation_name +-- | COMMENT [=] 'comment' +-- ---------------------------------------------------------------------------- + +CREATE DATABASE db_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ entity.name.struct.database.sql + +CREATE DATABASE IF NOT EXISTS db_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ entity.name.struct.database.sql + +CREATE OR REPLACE DATABASE db_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ entity.name.struct.database.sql + +CREATE SCHEMA schema_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ entity.name.struct.database.sql + +CREATE SCHEMA IF NOT EXISTS schema_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^ entity.name.struct.database.sql + +CREATE OR REPLACE SCHEMA schema_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.database +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ entity.name.struct.database.sql + + CHARACTER SET = 'utf-8' +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^ meta.string.sql string.quoted.single.sql + + DEFAULT CHARACTER SET = 'utf-16' +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^ meta.string.sql string.quoted.single.sql + + COLLATE = 'collation' +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + COMMENT = 'My new database' +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + COMMENT 'My new database' +-- <- meta.statement.create.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + -- ---------------------------------------------------------------------------- -- Create Role Statements From 59641a21fa57d725d6c618569e80b82aee6026aa Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 10:05:12 +0200 Subject: [PATCH 168/250] MySQL: Add ALTER DATABASE/SCHEMA statements --- SQL/MySQL.sublime-syntax | 23 ++++++++ SQL/tests/syntax/syntax_test_mysql.sql | 73 ++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index b86806b579..c78b215b75 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -169,6 +169,7 @@ contexts: alter-target: - meta_prepend: true - include: algorithms + - include: alter-database - include: alter-user alter-columns: @@ -182,6 +183,28 @@ contexts: - expect-column-name-declaration - expect-column-name + alter-database: + # https://mariadb.com/kb/en/alter-database + - match: \b(?i:database|schema)\b + scope: keyword.other.ddl.sql + set: + - alter-database-args + - expect-database-name + - alter-database-condition + + alter-database-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-database-args: + - meta_scope: meta.database.sql + - match: \b(?i:(upgrade)(?:\s+(data\s+directory\s+name))?)\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + pop: 1 + - include: create-database-args + alter-user: # https://mariadb.com/kb/en/alter-user - match: \b(?i:user)\b diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 153bdff2b6..ca3b42c77a 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -349,6 +349,79 @@ CREATE USER IF NOT EXISTS -- ^^^ keyword.other.unit.sql +-- ---------------------------------------------------------------------------- +-- Alter Database Statements +-- https://mariadb.com/kb/en/alter-database +-- ---------------------------------------------------------------------------- + +ALTER DATABASE db_name +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.database-name.sql + + +ALTER DATABASE db_name UPGRADE DATA DIRECTORY NA +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^ - meta.statement.alter +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.database-name.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^ - keyword + +ALTER DATABASE db_name UPGRADE DATA DIRECTORY NAME +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.database-name.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^^^^^^^^^^^^ keyword.other.ddl.sql + +ALTER SCHEMA schema_name +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ meta.database-name.sql + + CHARACTER SET = 'utf-8' +-- <- meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^ meta.string.sql string.quoted.single.sql + + DEFAULT CHARACTER SET = 'utf-16' +-- <- meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^ meta.string.sql string.quoted.single.sql + + COLLATE = 'collation' +-- <- meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^^^^^^ variable.parameter.database.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + COMMENT = 'My new database' +-- <- meta.statement.alter.sql meta.database.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + -- ---------------------------------------------------------------------------- -- Alter User Statements -- https://mariadb.com/kb/en/alter-user From dd8a9bde606b19f7afe35dfaae9f53c54f591528 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 10:24:10 +0200 Subject: [PATCH 169/250] MySQL: Add DROP DATABASE/SCHEMA statements --- SQL/MySQL.sublime-syntax | 19 +++++++++++++ SQL/tests/syntax/syntax_test_mysql.sql | 39 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index c78b215b75..d7fbb4f72b 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -144,8 +144,27 @@ contexts: drop-target: - meta_prepend: true - include: algorithms + - include: drop-database - include: drop-user + drop-database: + # https://mariadb.com/kb/en/drop-database + - match: \b(?i:database|schema)\b + scope: keyword.other.ddl.sql + set: + - drop-database-args + - expect-database-name + - drop-database-condition + + drop-database-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-database-args: + - meta_include_prototype: false + - meta_scope: meta.database.sql + - include: immediately-pop + drop-user: # https://mariadb.com/kb/en/drop-role # https://mariadb.com/kb/en/drop-user diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index ca3b42c77a..d8a7edb961 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -603,6 +603,45 @@ DROP -- ^ - keyword +-- ---------------------------------------------------------------------------- +-- Drop Database Statements +-- https://mariadb.com/kb/en/drop-database +-- ---------------------------------------------------------------------------- + +DROP DATABASE db_name ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql +-- ^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.database.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^ meta.database-name.sql +-- ^ punctuation.terminator.statement.sql + +DROP DATABASE IF EXISTS db_name ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.database.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ meta.database-name.sql +-- ^ punctuation.terminator.statement.sql + +DROP SCHEMA schema_name ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.statement.drop.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^^^^^^^ meta.database.sql meta.database-name.sql +-- ^ punctuation.terminator.statement.sql + -- ---------------------------------------------------------------------------- -- Drop Role Statements -- https://mariadb.com/kb/en/drop-role From 4268bb6e3b78e61ef498e8b7676c288258227006 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 12:29:37 +0200 Subject: [PATCH 170/250] MySQL: Add CREATE EVENT statements --- SQL/MySQL.sublime-syntax | 85 +++++++++++++ SQL/SQL (basic).sublime-syntax | 24 ++++ SQL/tests/syntax/syntax_test_mysql.sql | 161 +++++++++++++++++++++++++ 3 files changed, 270 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index d7fbb4f72b..b1a4a33b21 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -19,6 +19,10 @@ variables: (?xi: bit\s+varying | character\s+(?:varying)? | tinyint | var\s+char | float | int | interval | numeric | decimal | times? | timestamp(?:s | tz)? ) + time_unit: |- + (?xi: year | quarter | month | day | hour | minute | week | second | year_month + | day_hour | day_minute | day_second | hour_minute | hour_second | minute_second ) + contexts: sql: - meta_append: true @@ -68,6 +72,7 @@ contexts: scope: keyword.other.ddl.sql - include: algorithms - include: create-database + - include: create-event - include: create-role - include: create-user @@ -95,6 +100,25 @@ contexts: - include: strings - include: else-pop + create-event: + # https://mariadb.com/kb/en/create-event + - include: event-definers + - match: \b(?i:event)\b + scope: keyword.other.ddl.sql + set: + - create-event-args + - expect-event-creation-name + - create-event-condition + + create-event-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-event-args: + - meta_scope: meta.event.sql + - include: event-options + - include: pop-on-top-level-reserved-word + create-role: # https://mariadb.com/kb/en/create-role - match: \b(?i:role)\b @@ -499,6 +523,57 @@ contexts: pop: 1 - include: else-pop +###[ EVENT EXPRESSIONS ]####################################################### + + event-definers: + - match: \b(?i:definer)\b + scope: variable.parameter.definer.sql + push: maybe-user-assignment + + event-options: + - match: \b(?i:do)\b + scope: keyword.other.ddl.sql + pop: 1 + - match: \b(?i:comment)\b + scope: keyword.other.ddl.sql + - include: event-schedule-args + - include: event-enable-args + - include: event-completion-args + + event-completion-args: + - match: \b(?i:(on)\s+(completion))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + - match: \b(?i:preserve)\b + scope: constant.language.sql + + event-enable-args: + - match: \b(?i:(on)\s+(slave))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + - match: \b(?i:enable|disable)\b + scope: keyword.other.ddl.sql + + event-schedule-args: + - match: \b(?i:(on)\s+(schedule))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + - match: \b(?i:starts|ends)\b + scope: keyword.other.ddl.sql + - match: \+ + scope: keyword.operator.arithmetic.sql + - match: \b(?i:at)\b + scope: keyword.other.ddl.sql + - match: \b(?i:every)\b + scope: keyword.other.ddl.sql + - match: \b(?i:interval)\b + scope: storage.type.interval.sql + - include: time-units + - include: expressions + ###[ USER MANAGEMENT EXPRESSIONS ]############################################# maybe-with-admin-user: @@ -522,6 +597,12 @@ contexts: set: expect-user-name - include: else-pop + maybe-user-assignment: + - match: = + scope: keyword.operator.assignment.sql + set: expect-user-name + - include: else-pop + expect-user-identification-list: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false @@ -756,6 +837,10 @@ contexts: ###[ LITERALS ]################################################################ + time-units: + - match: '{{time_unit}}' + scope: keyword.other.unit.sql + regexps: - match: /(?=\S.*/) scope: punctuation.definition.string.begin.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index f77bd9c619..ea5f7ad126 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -844,6 +844,30 @@ contexts: - meta_content_scope: meta.database-name.sql - include: immediately-pop + expect-event-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [event-creation-name, single-identifier] + + event-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.event.sql + - include: immediately-pop + + expect-event-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [event-name, single-identifier] + + event-name: + - meta_include_prototype: false + - meta_scope: meta.event-name.sql + - include: immediately-pop + expect-index-creation-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index d8a7edb961..481091d24e 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -109,6 +109,167 @@ CREATE OR REPLACE SCHEMA schema_name -- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ---------------------------------------------------------------------------- +-- Create Event Statements +-- https://mariadb.com/kb/en/create-event +-- +-- CREATE [OR REPLACE] +-- [DEFINER = { user | CURRENT_USER | role | CURRENT_ROLE }] +-- EVENT +-- [IF NOT EXISTS] +-- event_name +-- ON SCHEDULE schedule +-- [ON COMPLETION [NOT] PRESERVE] +-- [ENABLE | DISABLE | DISABLE ON SLAVE] +-- [COMMENT 'comment'] +-- DO sql_statement; +-- +-- schedule: +-- AT timestamp [+ INTERVAL interval] ... +-- | EVERY interval +-- [STARTS timestamp [+ INTERVAL interval] ...] +-- [ENDS timestamp [+ INTERVAL interval] ...] +-- +-- interval: +-- quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE | +-- WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE | +-- DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND} +-- ---------------------------------------------------------------------------- + +CREATE EVENT event_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.event +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.event.sql + +CREATE DEFINER = user@host EVENT event_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.event +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.definer.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^ meta.user-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.event.sql + +CREATE EVENT IF NOT EXISTS event_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.event +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ entity.name.event.sql + +CREATE EVENT event_name + ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR + INTERVAL 3 MINUTE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^ keyword.other.unit.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^^ keyword.other.unit.sql + +CREATE EVENT event_name + ON SCHEDULE EVERY 1 MONTH +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql + + STARTS CURRENT_TIMESTAMP + INTERVAL 1 MONTH +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql + + ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH + INTERVAL 1 WEEK +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^ keyword.other.unit.sql + + ON COMPLETION PRESERVE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ constant.language.sql + + ON COMPLETION NOT PRESERVE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^ constant.language.sql + + ENABLE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^^^ keyword.other.ddl.sql + + DISABLE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^^^^ keyword.other.ddl.sql + + DISABLE ON SLAVE +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql + + COMMENT 'my comment' +-- <- meta.statement.create.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + DO UPDATE myschema.mytable SET mycol = mycol + 1; +-- <- meta.statement.create.sql meta.event.sql +-- ^^^ meta.statement.create.sql meta.event.sql +-- ^ - meta.statement +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^^ keyword.other.dml.sql +-- ^^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^ meta.column-name.sql +-- ^ keyword.operator.arithmetic.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.terminator.statement.sql + + -- ---------------------------------------------------------------------------- -- Create Role Statements -- https://mariadb.com/kb/en/create-role From 866e570df59caaf3f586740fba09a761d76580a9 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 13:45:53 +0200 Subject: [PATCH 171/250] MySQL: Add ALTER EVENT statements --- SQL/MySQL.sublime-syntax | 20 ++++ SQL/tests/syntax/syntax_test_mysql.sql | 148 +++++++++++++++++++++++++ 2 files changed, 168 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index b1a4a33b21..647d0ced64 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -213,6 +213,7 @@ contexts: - meta_prepend: true - include: algorithms - include: alter-database + - include: alter-event - include: alter-user alter-columns: @@ -248,6 +249,25 @@ contexts: pop: 1 - include: create-database-args + alter-event: + # https://mariadb.com/kb/en/alter-event + - include: event-definers + - match: \b(?i:event)\b + scope: keyword.other.ddl.sql + set: + - alter-event-args + - expect-event-name + - alter-event-condition + + alter-event-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-event-args: + - meta_scope: meta.event.sql + - include: event-options + - include: pop-on-top-level-reserved-word + alter-user: # https://mariadb.com/kb/en/alter-user - match: \b(?i:user)\b diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 481091d24e..086041f8f8 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -582,6 +582,154 @@ ALTER SCHEMA schema_name -- ^ keyword.operator.assignment.sql -- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ---------------------------------------------------------------------------- +-- Alter Event Statements +-- https://mariadb.com/kb/en/alter-event +-- +-- ALTER +-- [DEFINER = { user | CURRENT_USER }] +-- EVENT event_name +-- [ON SCHEDULE schedule] +-- [ON COMPLETION [NOT] PRESERVE] +-- [RENAME TO new_event_name] +-- [ENABLE | DISABLE | DISABLE ON SLAVE] +-- [COMMENT 'comment'] +-- [DO sql_statement] +-- ---------------------------------------------------------------------------- + +ALTER EVENT event_name +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql - meta.event +-- ^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.event-name.sql + +ALTER DEFINER = user@host EVENT event_name +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql - meta.event +-- ^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.definer.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^ meta.user-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.event-name.sql + +ALTER EVENT IF NOT EXISTS event_name +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^ meta.statement.alter.sql - meta.event +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.event-name.sql + +ALTER EVENT event_name + ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR + INTERVAL 3 MINUTE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^ keyword.other.unit.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^^ keyword.other.unit.sql + +ALTER EVENT event_name + ON SCHEDULE EVERY 1 MONTH +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql + + STARTS CURRENT_TIMESTAMP + INTERVAL 1 MONTH +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql + + ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH + INTERVAL 1 WEEK +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ keyword.other.unit.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^ keyword.other.unit.sql + + ON COMPLETION PRESERVE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ constant.language.sql + + ON COMPLETION NOT PRESERVE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^ constant.language.sql + + ENABLE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^^^ keyword.other.ddl.sql + + DISABLE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^^^^ keyword.other.ddl.sql + + DISABLE ON SLAVE +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql + + COMMENT 'my comment' +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + + DO UPDATE myschema.mytable SET mycol = mycol + 1; +-- <- meta.statement.alter.sql meta.event.sql +-- ^^^ meta.statement.alter.sql meta.event.sql +-- ^ - meta.statement +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^^ keyword.other.dml.sql +-- ^^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^ meta.column-name.sql +-- ^ keyword.operator.arithmetic.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.terminator.statement.sql + -- ---------------------------------------------------------------------------- -- Alter User Statements From 3b0229730a2917bf3027823b1f16a7ba4e756060 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 14:55:40 +0200 Subject: [PATCH 172/250] MySQL: Add DROP EVENT statements --- SQL/MySQL.sublime-syntax | 19 ++++++++++++++ SQL/tests/syntax/syntax_test_mysql.sql | 35 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 647d0ced64..39970d5da7 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -169,6 +169,7 @@ contexts: - meta_prepend: true - include: algorithms - include: drop-database + - include: drop-event - include: drop-user drop-database: @@ -189,6 +190,24 @@ contexts: - meta_scope: meta.database.sql - include: immediately-pop + drop-event: + # https://mariadb.com/kb/en/drop-event + - match: \b(?i:event)\b + scope: keyword.other.ddl.sql + set: + - drop-event-args + - expect-event-name + - drop-event-condition + + drop-event-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-event-args: + - meta_include_prototype: false + - meta_scope: meta.event.sql + - include: immediately-pop + drop-user: # https://mariadb.com/kb/en/drop-role # https://mariadb.com/kb/en/drop-user diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 086041f8f8..dd995af4bc 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -951,6 +951,41 @@ DROP SCHEMA schema_name ; -- ^^^^^^^^^^^ meta.database.sql meta.database-name.sql -- ^ punctuation.terminator.statement.sql + +-- ---------------------------------------------------------------------------- +-- Drop Event Statements +-- https://mariadb.com/kb/en/drop-event +-- ---------------------------------------------------------------------------- + +DROP EVENT event ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^^ meta.statement.drop.sql meta.event.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^ keyword.other.ddl.sql +-- ^ - keyword - meta.event-name +-- ^^^^^ meta.event-name.sql +-- ^ - meta.event-name +-- ^ punctuation.terminator.statement.sql + +DROP EVENT IF EXISTS event ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.event.sql +-- ^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^^^^ keyword.other.ddl.sql +-- ^ - keyword +-- ^^ keyword.control.conditional.if.sql +-- ^ - keyword +-- ^^^^^^ keyword.operator.logical.sql +-- ^ - keyword - meta.event-name +-- ^^^^^ meta.event-name.sql +-- ^ - meta.event-name +-- ^ punctuation.terminator.statement.sql + + -- ---------------------------------------------------------------------------- -- Drop Role Statements -- https://mariadb.com/kb/en/drop-role From 3dce64337af7b8baf6db2d52214d1a3dc813ed6f Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 15:01:24 +0200 Subject: [PATCH 173/250] MySQL: Add SHOW CREATE EVENT statements --- SQL/MySQL.sublime-syntax | 9 +++++++++ SQL/tests/syntax/syntax_test_mysql.sql | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 39970d5da7..a02c7f65bc 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -489,10 +489,19 @@ contexts: - include: immediately-pop show-target: + - include: show-create-event - include: show-create-user - include: show-grants - include: else-pop + show-create-event: + # https://mariadb.com/kb/en/show-create-event + - match: \b(?i:(create)\s+(event))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: expect-event-name + show-create-user: # https://mariadb.com/kb/en/show-create-user - match: \b(?i:(create)\s+(user))\b diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index dd995af4bc..39b937aac5 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -1445,6 +1445,20 @@ SET DEFAULT ROLE role FOR user@host -- ^^^^^^^^^ meta.user-name.sql +-- ---------------------------------------------------------------------------- +-- Show Create Event Statements +-- https://mariadb.com/kb/en/show-create-event +-- ---------------------------------------------------------------------------- + +SHOW CREATE EVENT db_name.event_name +-- <- meta.statement.show.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql +-- ^ keyword.other.dml.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^ meta.event-name.sql + + -- ---------------------------------------------------------------------------- -- Account Management SQL Commands -- ------------------------------- From e9341b03c80049608873efd039f2aac53a1bdd1b Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 15:08:10 +0200 Subject: [PATCH 174/250] MySQL: Refactor SHOW statements --- SQL/MySQL.sublime-syntax | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index a02c7f65bc..a113aa5bc9 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -489,27 +489,38 @@ contexts: - include: immediately-pop show-target: + - include: show-create + - include: show-grants + - include: else-pop + + show-create: + - match: \b(?i:create)\b + scope: keyword.other.ddl.sql + set: show-create-target + + show-create-target: - include: show-create-event - include: show-create-user - - include: show-grants + - include: show-create-other - include: else-pop show-create-event: # https://mariadb.com/kb/en/show-create-event - - match: \b(?i:(create)\s+(event))\b - captures: - 1: keyword.other.ddl.sql - 2: keyword.other.ddl.sql + - match: \b(?i:event)\b + scope: keyword.other.ddl.sql set: expect-event-name show-create-user: # https://mariadb.com/kb/en/show-create-user - - match: \b(?i:(create)\s+(user))\b - captures: - 1: keyword.other.ddl.sql - 2: keyword.other.ddl.sql + - match: \b(?i:user)\b + scope: keyword.other.ddl.sql set: expect-user-name + show-create-other: + - match: '{{simple_identifier}}' + scope: keyword.other.ddl.sql + set: expect-other-name + show-grants: # https://mariadb.com/kb/en/show-grants - match: \b(?i:grants)\b From a13c93d6ce375eecd8c42f9b7099452753f80714 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 16:45:53 +0200 Subject: [PATCH 175/250] MySQL: Add CREATE FUNCTION/PROCEDURE statements Looks pretty much different from what exists in T-SQL and SQL (basic). As MySQL seems to follow SQL-99 syntax more closely, implementation in SQL (basic) is adjusted. Rename contexts from `procedure` to `function` as it is the more common name used across syntaxes. --- SQL/Cassandra.sublime-syntax | 2 +- SQL/MySQL.sublime-syntax | 24 ++++ SQL/PostgreSQL.sublime-syntax | 9 ++ SQL/SQL (basic).sublime-syntax | 147 ++++++++++++++------- SQL/TSQL.sublime-syntax | 22 +++- SQL/tests/syntax/syntax_test_mysql.sql | 169 +++++++++++++++++++++++++ SQL/tests/syntax/syntax_test_tsql.sql | 4 +- 7 files changed, 325 insertions(+), 52 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 04c75bb27b..6cbea16923 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -12,7 +12,7 @@ file_extensions: variables: - ddl_target_procedure: |- + ddl_target_function: |- (?xi: function ) ddl_target_other: |- (?xi: keyspace | type | user | (?: materialized \s+ )? view ) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index a113aa5bc9..e0d900835f 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -10,6 +10,9 @@ variables: additional_reserved: |- (?xi: begin | end | return | grant | rename | revoke | show ) + function_parameter_modifier: |- + (?xi: in\s*out | in | out ) + simple_types: |- (?xi: bigint | bigserial | bit | bool | boolean | box | bytea | cidr | circle | date | datetime | double\s+precision | enum | inet | integer | line @@ -633,6 +636,27 @@ contexts: - include: time-units - include: expressions +###[ FUNCTION EXPRESSIONS ]#################################################### + + expect-function-characteristics: + # https://mariadb.com/kb/en/create-function + - meta_prepend: true + - match: \b(?i:return)\b + scope: keyword.control.flow.return.sql + pop: 1 + - match: \b(?i:comment)\b + scope: keyword.other.ddl.sql + - match: \b(?i:not)\b + scope: keyword.operator.logical.sql + - match: \b(?i:deterministic)\b + scope: storage.modifier.sql + - match: \b(?i:(?:contains|no)\s+sql|(?:reads|modifies)\s+sql\s+data)\b + scope: storage.modifier.sql + - match: \b(?i:sql\s+security)\b + scope: storage.modifier.sql + - match: \b(?i:definer|invoker)\b + scope: constant.language.user.sql + ###[ USER MANAGEMENT EXPRESSIONS ]############################################# maybe-with-admin-user: diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 378f779c74..6478e804d0 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -172,6 +172,15 @@ contexts: - match: ':(?!:)' scope: keyword.operator.range.psql +###[ FUNCTION EXPRESSIONS ]#################################################### + + expect-function-characteristics: + # https://mariadb.com/kb/en/create-function + - meta_prepend: true + - match: \b(?i:as)\b + scope: keyword.other.ddl.sql + pop: 1 + ###[ COLUMN DECLARATIONS ]##################################################### inside-column-declaration-list: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index ea5f7ad126..857b544944 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -18,21 +18,27 @@ variables: # TODO: not all are supported by all dialects! ddl_target: |- - (?xi: {{ddl_target_other}} | {{ddl_target_procedure}} + (?xi: {{ddl_target_other}} + | (?: {{ddl_target_function_modifier}} \s+ )? {{ddl_target_function}} | (?: {{ddl_target_index_modifier}} \s+ )? index | (?: {{ddl_target_table_modifier}} \s+ )? table ) - ddl_target_procedure: |- + ddl_target_function: |- (?xi: procedure | function ) ddl_target_other: |- (?xi: aggregate | constraint | conversion | database | domain | group | language | operator\s+class | operator | rule | schema | sequence | tablespace | trigger | type | user | view ) + ddl_target_function_modifier: |- + (?xi: aggregate ) ddl_target_index_modifier: |- (?xi: fulltext | spatial | unique ) ddl_target_table_modifier: |- (?xi: temp(?:orary)? ) + function_parameter_modifier: |- + (?xi: inout | in | out ) + simple_types: |- (?xi: bit | bool | boolean | datetime | int ) types_with_optional_number: |- @@ -114,12 +120,27 @@ contexts: - include: immediately-pop create-target: + - include: create-function - include: create-index - include: create-table - - include: create-procedure - include: create-other - include: else-pop + create-function: + - match: \b(?:({{ddl_target_function_modifier}})\s+)?({{ddl_target_function}})\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - expect-function-characteristics + - expect-function-parameters + - expect-function-creation-name + - create-function-condition + + create-function-condition: + - meta_include_prototype: false + - include: maybe-condition + create-index: - match: \b(?xi:(?:({{ddl_target_index_modifier}})\s+)?(index))\b captures: @@ -135,18 +156,6 @@ contexts: - meta_include_prototype: false - include: maybe-condition - create-procedure: - - match: \b{{ddl_target_procedure}}\b - scope: keyword.other.ddl.sql - set: - - target-options - - expect-procedure-creation-name - - create-procedure-condition - - create-procedure-condition: - - meta_include_prototype: false - - include: maybe-condition - create-table: - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b captures: @@ -190,31 +199,31 @@ contexts: - include: immediately-pop drop-target: + - include: drop-function - include: drop-index - include: drop-table - - include: drop-procedure - include: drop-other - include: else-pop - drop-index: - - match: \b(?i:index)\b + drop-function: + - match: \b{{ddl_target_function}}\b scope: keyword.other.ddl.sql set: - - expect-index-name - - drop-index-condition + - expect-function-name + - drop-function-condition - drop-index-condition: + drop-function-condition: - meta_include_prototype: false - include: maybe-condition - drop-procedure: - - match: \b{{ddl_target_procedure}}\b + drop-index: + - match: \b(?i:index)\b scope: keyword.other.ddl.sql set: - - expect-procedure-name - - drop-procedure-condition + - expect-index-name + - drop-index-condition - drop-procedure-condition: + drop-index-condition: - meta_include_prototype: false - include: maybe-condition @@ -258,12 +267,27 @@ contexts: - include: immediately-pop alter-target: + - include: alter-function - include: alter-index - include: alter-table - - include: alter-procedure - include: alter-other - include: else-pop + alter-function: + - match: \b(?:({{ddl_target_function_modifier}})\s+)?({{ddl_target_function}})\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - expect-function-characteristics + - expect-function-parameters + - expect-function-name + - alter-function-condition + + alter-function-condition: + - meta_include_prototype: false + - include: maybe-condition + alter-index: - match: \b(?:({{ddl_target_index_modifier}})\s+)?(index)\b captures: @@ -278,18 +302,6 @@ contexts: - meta_include_prototype: false - include: maybe-condition - alter-procedure: - - match: \b{{ddl_target_procedure}}\b - scope: keyword.other.ddl.sql - set: - - target-options - - expect-procedure-name - - alter-procedure-condition - - alter-procedure-condition: - - meta_include_prototype: false - - include: maybe-condition - alter-table: - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b captures: @@ -363,9 +375,6 @@ contexts: - match: \b(?i:as)\b scope: keyword.context.block.sql pop: 1 - - match: \b(?i:returns)\b - scope: keyword.other.sql - push: expect-type - include: expressions - include: pop-on-top-level-reserved-word @@ -576,6 +585,56 @@ contexts: pop: 1 - include: sql +###[ FUNCTION EXPRESSIONS ]#################################################### + + expect-function-parameters: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-function-parameters + - include: else-pop + + inside-function-parameters: + - clear_scopes: 1 + - meta_scope: meta.function.parameters.sql meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: comma-separators + - match: (?=\S) + push: + - expect-type + - expect-parameter-name + - maybe-parameter-modifier + + expect-parameter-name: + - match: '{{simple_identifier}}' + scope: variable.parameter.sql + pop: 1 + - include: else-pop + + maybe-parameter-modifier: + - match: \b{{function_parameter_modifier}}\b + scope: storage.modifier.sql + pop: 1 + - include: else-pop + + expect-function-characteristics: + - meta_scope: meta.function.sql + - match: \b(?i:language)\b + scope: storage.modifier.sql + push: expect-function-language-name + - match: \b(?i:returns)\b + scope: keyword.other.ddl.sql + push: expect-type + - include: expressions + - include: pop-on-top-level-reserved-word + + expect-function-language-name: + - match: '{{simple_identifier}}' + scope: constant.other.language.sql + pop: 1 + - include: else-pop + ###[ TABLE NAMES ]############################################################# table-name-or-subquery: @@ -896,7 +955,7 @@ contexts: - meta_scope: meta.index-name.sql - include: immediately-pop - expect-procedure-creation-name: + expect-function-creation-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false - include: comments @@ -908,7 +967,7 @@ contexts: - meta_content_scope: entity.name.function.sql - include: immediately-pop - expect-procedure-name: + expect-function-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false - include: comments diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 0af7d49dd4..9132848072 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -21,7 +21,7 @@ variables: (?:\b\w+|\[[^]]+\]) ) - ddl_target_procedure: |- + ddl_target_function: |- (?xi: proc(?:edure)? | func(?:tion)? ) # types @@ -76,14 +76,15 @@ contexts: - match: \b(?i:unique|clustered|nonclustered)\b scope: keyword.other.ddl.sql + expect-function-characteristics: + - meta_prepend: true + - include: target-options + ###[ DDL STATEMENT PROTOTYPES ]################################################ target-options: - meta_prepend: true - include: with-table-options - - match: (@){{simple_identifier}} - scope: variable.parameter.sql - push: expect-type ###[ DML STATEMENTS ]########################################################## @@ -203,7 +204,7 @@ contexts: scope: keyword.control.flow.end.tsql - match: \b(?i:exec(?:ute)?)\b scope: keyword.control.flow.execute.tsql - push: [expect-procedure-name, execute-args] + push: [expect-function-name, execute-args] - match: \b(?i:go)\b scope: keyword.control.flow.go.tsql - match: \b(?i:goto)\b @@ -413,6 +414,17 @@ contexts: - include: dml-statements - include: expressions +###[ FUNCTION EXPRESSIONS ]#################################################### + + expect-function-parameters: + - match: (@){{simple_identifier}} + scope: variable.parameter.tsql + captures: + 1: punctuation.definition.variable.tsql + push: expect-type + - include: comma-separators + - include: else-pop + ###[ WITH EXPRESSIONS ]######################################################## maybe-with-table-options: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 39b937aac5..9b3a431342 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -270,6 +270,175 @@ CREATE EVENT event_name -- ^ punctuation.terminator.statement.sql +-- ---------------------------------------------------------------------------- +-- Create Function Statements +-- https://mariadb.com/kb/en/create-function +-- +-- CREATE [OR REPLACE] +-- [DEFINER = {user | CURRENT_USER | role | CURRENT_ROLE }] +-- [AGGREGATE] FUNCTION [IF NOT EXISTS] func_name ([func_parameter[,...]]) +-- RETURNS type +-- [characteristic ...] +-- RETURN func_body +-- +-- func_parameter: +-- [ IN | OUT | INOUT | IN OUT ] param_name type +-- +-- type: +-- Any valid MariaDB data type +-- +-- characteristic: +-- LANGUAGE SQL +-- | [NOT] DETERMINISTIC +-- | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA } +-- | SQL SECURITY { DEFINER | INVOKER } +-- | COMMENT 'string' +-- +-- func_body: +-- Valid SQL procedure statement +-- ---------------------------------------------------------------------------- + +CREATE DEFINER = CURRENT_ROLE AGGREGATE FUNCTION foo +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.function +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.definer.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^ entity.name.function.sql + +CREATE FUNCTION func_name(IN param_name number, IN OUT out varchar) RETURN +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.function +-- ^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.parameters.sql meta.group.sql +-- ^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ entity.name.function.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ storage.modifier.sql +-- ^^^^^^^^^^ variable.parameter.sql +-- ^^^^^^ support.type.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ storage.modifier.sql +-- ^^^ variable.parameter.sql +-- ^^^^^^^ support.type.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^^ keyword.control.flow.return.sql +-- + +CREATE AGGREGATE FUNCTION +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.function +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql + + func_name() +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^^^^^^^ meta.function.sql entity.name.function.sql +-- ^ meta.function.parameters.sql meta.group.sql punctuation.section.group.begin.sql +-- ^ meta.function.parameters.sql meta.group.sql punctuation.section.group.end.sql + + RETURNS varchar(200) +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ support.type.sql +-- ^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.section.group.end.sql + + LANGUAGE SQL +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^ constant.other.language.sql + + NOT DETERMINISTIC +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^ storage.modifier.sql + + CONTAINS SQL +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^ storage.modifier.sql + + NO SQL +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^ storage.modifier.sql + + READS SQL DATA +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^ storage.modifier.sql + + MODIFIES SQL DATA +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^ storage.modifier.sql + + SQL SECURITY DEFINER +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^ constant.language.user.sql + SQL SECURITY INVOKER +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^ constant.language.user.sql + + COMMENT 'string' +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.string.sql string.quoted.single.sql + + RETURN +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^ - meta.statement - meta.function + + +-- ---------------------------------------------------------------------------- +-- Create Procedure Statements +-- https://mariadb.com/kb/en/create-function +-- +-- CREATE +-- [OR REPLACE] +-- [DEFINER = { user | CURRENT_USER | role | CURRENT_ROLE }] +-- PROCEDURE sp_name ([proc_parameter[,...]]) +-- [characteristic ...] routine_body +-- +-- proc_parameter: +-- [ IN | OUT | INOUT ] param_name type +-- +-- type: +-- Any valid MariaDB data type +-- +-- characteristic: +-- LANGUAGE SQL +-- | [NOT] DETERMINISTIC +-- | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA } +-- | SQL SECURITY { DEFINER | INVOKER } +-- | COMMENT 'string' +-- +-- routine_body: +-- Valid SQL procedure statement +-- ---------------------------------------------------------------------------- + + -- ---------------------------------------------------------------------------- -- Create Role Statements -- https://mariadb.com/kb/en/create-role diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 6ef54983fb..b9bad3c8cc 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1446,7 +1446,7 @@ CREATE FUNCTION foo() RETURNS @MyType -- ^^^^^^^^ keyword.other.ddl.sql -- ^^^ entity.name.function.sql -- ^^ meta.group.sql --- ^^^^^^^ keyword.other.sql +-- ^^^^^^^ keyword.other.ddl.sql -- ^^^^^^^ support.type.sql variable.other.readwrite.sql CREATE FUNCTION foo() RETURNS My@TypeName @@ -1456,7 +1456,7 @@ CREATE FUNCTION foo() RETURNS My@TypeName -- ^^^^^^^^ keyword.other.ddl.sql -- ^^^ entity.name.function.sql -- ^^ meta.group.sql --- ^^^^^^^ keyword.other.sql +-- ^^^^^^^ keyword.other.ddl.sql -- ^^ support.type.sql - variable -- ^^^^^^^^^ support.type.sql variable.other.readwrite.sql From ae8b1cee670b2be6bec4b87ed85b2b4fdccfd48a Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 17 Jul 2022 18:30:09 +0200 Subject: [PATCH 176/250] MySQL: Reorganize DEFINER expressions Move to global `create/alter-target` as they are not dedicated to events. --- SQL/MySQL.sublime-syntax | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index e0d900835f..37cb566c3f 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -74,6 +74,7 @@ contexts: - match: \b(?i:unique|fulltext|spatial)\b scope: keyword.other.ddl.sql - include: algorithms + - include: definers - include: create-database - include: create-event - include: create-role @@ -105,7 +106,6 @@ contexts: create-event: # https://mariadb.com/kb/en/create-event - - include: event-definers - match: \b(?i:event)\b scope: keyword.other.ddl.sql set: @@ -234,6 +234,7 @@ contexts: alter-target: - meta_prepend: true - include: algorithms + - include: definers - include: alter-database - include: alter-event - include: alter-user @@ -273,7 +274,6 @@ contexts: alter-event: # https://mariadb.com/kb/en/alter-event - - include: event-definers - match: \b(?i:event)\b scope: keyword.other.ddl.sql set: @@ -585,13 +585,13 @@ contexts: pop: 1 - include: else-pop -###[ EVENT EXPRESSIONS ]####################################################### - - event-definers: + definers: - match: \b(?i:definer)\b scope: variable.parameter.definer.sql push: maybe-user-assignment +###[ EVENT EXPRESSIONS ]####################################################### + event-options: - match: \b(?i:do)\b scope: keyword.other.ddl.sql From ff5f685b3103d0a22ed6d1279b2e5dcf80cec16a Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Mon, 18 Jul 2022 17:59:12 +0200 Subject: [PATCH 177/250] MySQL: Fix typo --- SQL/MySQL.sublime-syntax | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 37cb566c3f..5287f02b5b 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -400,7 +400,7 @@ contexts: pop: 1 - include: on-privilidge-level - include: comma-separators - - include: user-privilidges + - include: user-privileges grant-on-user: - match: \b(?i:on)\b @@ -413,7 +413,7 @@ contexts: - include: expect-user-identification-list grant-options: - - include: user-grant-privilidges + - include: user-grant-privileges - include: user-resource-options - include: else-pop @@ -455,19 +455,19 @@ contexts: push: - revoke-meta - revoke-options - - revoke-privilidges + - revoke-privileges revoke-meta: - meta_include_prototype: false - meta_scope: meta.statement.revoke.sql - include: immediately-pop - revoke-privilidges: + revoke-privileges: - match: (?=[;)]|\b(?i:for|from)\b) pop: 1 - include: on-privilidge-level - include: comma-separators - - include: user-privilidges + - include: user-privileges revoke-options: - match: \b(?i:for|from)\b @@ -796,16 +796,16 @@ contexts: - match: \b(?i:none)\b scope: constant.language.null.sql - user-privilidges: + user-privileges: - include: column-reference-lists - - include: user-all-privilidges - - include: user-grant-privilidges + - include: user-all-privileges + - include: user-grant-privileges - user-all-privilidges: + user-all-privileges: - match: \b(?i:all\s+privileges)\b scope: constant.language.sql - user-grant-privilidges: + user-grant-privileges: - match: \b(?i:(?:grant|admin)\s+option)\b scope: constant.language.sql From b6960a67d97e3e09ee08549b9b8c2f5d573f7790 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Thu, 21 Jul 2022 20:50:15 +0200 Subject: [PATCH 178/250] NySQL: Reorganize comments --- SQL/MySQL.sublime-syntax | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 5287f02b5b..c4b9b969c5 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -42,16 +42,18 @@ contexts: comments: - meta_append: true - - match: '#' - scope: punctuation.definition.comment.sql - push: inside-number-sign-comment + - include: number-sign-comments double-dash-comments: - - meta_include_prototype: false - match: '--(?=\s)' scope: punctuation.definition.comment.sql push: inside-double-dash-comment + number-sign-comments: + - match: '#' + scope: punctuation.definition.comment.sql + push: inside-number-sign-comment + inside-number-sign-comment: - meta_include_prototype: false - meta_scope: comment.line.number-sign.sql From 9e4e60cf075285ada2fbc3cb67030a052c33d97f Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Mon, 18 Jul 2022 18:06:47 +0200 Subject: [PATCH 179/250] MySQL: Reuse `interval` in user creations --- SQL/MySQL.sublime-syntax | 13 ++++++++----- SQL/tests/syntax/syntax_test_mysql.sql | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index c4b9b969c5..486e8b231a 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -633,8 +633,7 @@ contexts: scope: keyword.other.ddl.sql - match: \b(?i:every)\b scope: keyword.other.ddl.sql - - match: \b(?i:interval)\b - scope: storage.type.interval.sql + - include: intervals - include: time-units - include: expressions @@ -774,10 +773,10 @@ contexts: captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql - - match: \b(?i:day)\b - scope: keyword.other.unit.sql - - match: \b(?i:default|never|interval)\b + - match: \b(?i:default|never)\b scope: constant.language.sql + - include: intervals + - include: time-units user-resource-options: - match: \b(?i:with)\b @@ -842,6 +841,10 @@ contexts: ###[ TYPES ]################################################################### + intervals: + - match: \b(?i:interval)\b + scope: storage.type.interval.sql + after-type: - meta_prepend: true - match: \b(?i:unsigned)\b diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 9b3a431342..981253294a 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -674,7 +674,7 @@ CREATE USER IF NOT EXISTS -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.user.sql -- ^^^^^^^^ keyword.other.ddl.sql -- ^^^^^^ keyword.other.ddl.sql --- ^^^^^^^^ constant.language.sql +-- ^^^^^^^^ storage.type.interval.sql -- ^ meta.number.integer.decimal.sql constant.numeric.value.sql -- ^^^ keyword.other.unit.sql @@ -1064,7 +1064,7 @@ ALTER USER IF EXISTS -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql -- ^^^^^^^^ keyword.other.ddl.sql -- ^^^^^^ keyword.other.ddl.sql --- ^^^^^^^^ constant.language.sql +-- ^^^^^^^^ storage.type.interval.sql -- ^ meta.number.integer.decimal.sql constant.numeric.value.sql -- ^^^ keyword.other.unit.sql From 59c0d87862204f77db2344511939985d4348c2a3 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Mon, 18 Jul 2022 18:17:53 +0200 Subject: [PATCH 180/250] MySQL: Add some BNF comments --- SQL/tests/syntax/syntax_test_mysql.sql | 199 +++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 981253294a..2dd7301a0d 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -442,6 +442,10 @@ CREATE AGGREGATE FUNCTION -- ---------------------------------------------------------------------------- -- Create Role Statements -- https://mariadb.com/kb/en/create-role +-- +-- CREATE [OR REPLACE] ROLE [IF NOT EXISTS] role +-- [WITH ADMIN +-- {CURRENT_USER | CURRENT_ROLE | user | role}] -- ---------------------------------------------------------------------------- CREATE ROLE role @@ -504,6 +508,49 @@ CREATE ROLE role WITH ADMIN CURRENT_ROLE -- ---------------------------------------------------------------------------- -- Create User Statements -- https://mariadb.com/kb/en/create-user +-- +-- CREATE [OR REPLACE] USER [IF NOT EXISTS] +-- user_specification [,user_specification ...] +-- [REQUIRE {NONE | tls_option [[AND] tls_option ...] }] +-- [WITH resource_option [resource_option ...] ] +-- [lock_option] [password_option] +-- +-- user_specification: +-- username [authentication_option] +-- +-- authentication_option: +-- IDENTIFIED BY 'password' +-- | IDENTIFIED BY PASSWORD 'password_hash' +-- | IDENTIFIED {VIA|WITH} authentication_rule [OR authentication_rule ...] +-- +-- authentication_rule: +-- authentication_plugin +-- | authentication_plugin {USING|AS} 'authentication_string' +-- | authentication_plugin {USING|AS} PASSWORD('password') +-- +-- tls_option: +-- SSL +-- | X509 +-- | CIPHER 'cipher' +-- | ISSUER 'issuer' +-- | SUBJECT 'subject' +-- +-- resource_option: +-- MAX_QUERIES_PER_HOUR count +-- | MAX_UPDATES_PER_HOUR count +-- | MAX_CONNECTIONS_PER_HOUR count +-- | MAX_USER_CONNECTIONS count +-- | MAX_STATEMENT_TIME time +-- +-- password_option: +-- PASSWORD EXPIRE +-- | PASSWORD EXPIRE DEFAULT +-- | PASSWORD EXPIRE NEVER +-- | PASSWORD EXPIRE INTERVAL N DAY +-- +-- lock_option: +-- ACCOUNT LOCK +-- | ACCOUNT UNLOCK -- ---------------------------------------------------------------------------- CREATE USER IF NOT EXISTS @@ -682,6 +729,16 @@ CREATE USER IF NOT EXISTS -- ---------------------------------------------------------------------------- -- Alter Database Statements -- https://mariadb.com/kb/en/alter-database +-- +-- ALTER {DATABASE | SCHEMA} [db_name] +-- alter_specification ... +-- ALTER {DATABASE | SCHEMA} db_name +-- UPGRADE DATA DIRECTORY NAME +-- +-- alter_specification: +-- [DEFAULT] CHARACTER SET [=] charset_name +-- | [DEFAULT] COLLATE [=] collation_name +-- | COMMENT [=] 'comment' -- ---------------------------------------------------------------------------- ALTER DATABASE db_name @@ -903,6 +960,49 @@ ALTER EVENT event_name -- ---------------------------------------------------------------------------- -- Alter User Statements -- https://mariadb.com/kb/en/alter-user +-- +-- ALTER USER [IF EXISTS] +-- user_specification [,user_specification] ... +-- [REQUIRE {NONE | tls_option [[AND] tls_option] ...}] +-- [WITH resource_option [resource_option] ...] +-- [lock_option] [password_option] +-- +-- user_specification: +-- username [authentication_option] +-- +-- authentication_option: +-- IDENTIFIED BY 'password' +-- | IDENTIFIED BY PASSWORD 'password_hash' +-- | IDENTIFIED {VIA|WITH} authentication_rule [OR authentication_rule] ... +-- +-- authentication_rule: +-- authentication_plugin +-- | authentication_plugin {USING|AS} 'authentication_string' +-- | authentication_plugin {USING|AS} PASSWORD('password') +-- +-- tls_option +-- SSL +-- | X509 +-- | CIPHER 'cipher' +-- | ISSUER 'issuer' +-- | SUBJECT 'subject' +-- +-- resource_option +-- MAX_QUERIES_PER_HOUR count +-- | MAX_UPDATES_PER_HOUR count +-- | MAX_CONNECTIONS_PER_HOUR count +-- | MAX_USER_CONNECTIONS count +-- | MAX_STATEMENT_TIME time +-- +-- password_option: +-- PASSWORD EXPIRE +-- | PASSWORD EXPIRE DEFAULT +-- | PASSWORD EXPIRE NEVER +-- | PASSWORD EXPIRE INTERVAL N DAY +-- +-- lock_option: +-- ACCOUNT LOCK +-- | ACCOUNT UNLOCK -- ---------------------------------------------------------------------------- ALTER USER IF EXISTS @@ -1084,6 +1184,8 @@ DROP -- ---------------------------------------------------------------------------- -- Drop Database Statements -- https://mariadb.com/kb/en/drop-database +-- +-- DROP {DATABASE | SCHEMA} [IF EXISTS] db_name -- ---------------------------------------------------------------------------- DROP DATABASE db_name ; @@ -1124,6 +1226,8 @@ DROP SCHEMA schema_name ; -- ---------------------------------------------------------------------------- -- Drop Event Statements -- https://mariadb.com/kb/en/drop-event +-- +-- DROP EVENT [IF EXISTS] event_name -- ---------------------------------------------------------------------------- DROP EVENT event ; @@ -1158,6 +1262,8 @@ DROP EVENT IF EXISTS event ; -- ---------------------------------------------------------------------------- -- Drop Role Statements -- https://mariadb.com/kb/en/drop-role +-- +-- DROP ROLE [IF EXISTS] role_name [,role_name ...] -- ---------------------------------------------------------------------------- DROP ROLE role ; @@ -1194,6 +1300,8 @@ DROP ROLE IF EXISTS role1, role2, role3; -- ---------------------------------------------------------------------------- -- Drop User Statements -- https://mariadb.com/kb/en/drop-user +-- +-- DROP USER [IF EXISTS] user_name [, user_name] ... -- ---------------------------------------------------------------------------- DROP USER bob@'%' ; @@ -1226,6 +1334,72 @@ DROP USER IF EXISTS bob, clara@localhost ; -- ------------------------------- -- Grant Statements -- https://mariadb.com/kb/en/grant +-- +-- GRANT +-- priv_type [(column_list)] +-- [, priv_type [(column_list)]] ... +-- ON [object_type] priv_level +-- TO user_specification [ user_options ...] +-- +-- user_specification: +-- username [authentication_option] +-- +-- authentication_option: +-- IDENTIFIED BY 'password' +-- | IDENTIFIED BY PASSWORD 'password_hash' +-- | IDENTIFIED {VIA|WITH} authentication_rule [OR authentication_rule ...] +-- +-- authentication_rule: +-- authentication_plugin +-- | authentication_plugin {USING|AS} 'authentication_string' +-- | authentication_plugin {USING|AS} PASSWORD('password') +-- +-- GRANT PROXY ON username +-- TO user_specification [, user_specification ...] +-- [WITH GRANT OPTION] +-- +-- GRANT rolename TO grantee [, grantee ...] +-- [WITH ADMIN OPTION] +-- +-- grantee: +-- rolename +-- username [authentication_option] +-- +-- user_options: +-- [REQUIRE {NONE | tls_option [[AND] tls_option] ...}] +-- [WITH with_option [with_option] ...] +-- +-- object_type: +-- TABLE +-- | FUNCTION +-- | PROCEDURE +-- | PACKAGE +-- +-- priv_level: +-- * +-- | *.* +-- | db_name.* +-- | db_name.tbl_name +-- | tbl_name +-- | db_name.routine_name +-- +-- with_option: +-- GRANT OPTION +-- | resource_option +-- +-- resource_option: +-- MAX_QUERIES_PER_HOUR count +-- | MAX_UPDATES_PER_HOUR count +-- | MAX_CONNECTIONS_PER_HOUR count +-- | MAX_USER_CONNECTIONS count +-- | MAX_STATEMENT_TIME time +-- +-- tls_option: +-- SSL +-- | X509 +-- | CIPHER 'cipher' +-- | ISSUER 'issuer' +-- | SUBJECT 'subject' -- ---------------------------------------------------------------------------- GRANT @@ -1384,6 +1558,9 @@ GRANT rolename TO role, user IDENTIFIED BY 'password' WITH ADMIN OPTION ; -- ------------------------------- -- Rename User Statements -- https://mariadb.com/kb/en/rename-user +-- +-- RENAME USER old_user TO new_user +-- [, old_user TO new_user] ... -- ---------------------------------------------------------------------------- RENAME @@ -1422,6 +1599,15 @@ RENAME USER 'donald' TO 'duck'@'localhost', 'mickey' TO 'mouse'@'localhost'; -- ------------------------------- -- Revoke Statements -- https://mariadb.com/kb/en/revoke +-- +-- REVOKE +-- priv_type [(column_list)] +-- [, priv_type [(column_list)]] ... +-- ON [object_type] priv_level +-- FROM user [, user] ... +-- +-- REVOKE ALL PRIVILEGES, GRANT OPTION +-- FROM user [, user] ... -- ---------------------------------------------------------------------------- REVOKE ; @@ -1495,6 +1681,13 @@ REVOKE role1, role2 FROM grantee, grantee2 ; -- ------------------------------- -- Set Password Statements -- https://mariadb.com/kb/en/set-password +-- +-- SET PASSWORD [FOR user] = +-- { +-- PASSWORD('some password') +-- | OLD_PASSWORD('some password') +-- | 'encrypted password' +-- } -- ---------------------------------------------------------------------------- SET @@ -1567,6 +1760,8 @@ SET PASSWORD for `user@`@'%' = 'encrypted password'; -- ------------------------------- -- Set Role Statements -- https://mariadb.com/kb/en/set-role +-- +-- SET ROLE { role | NONE } -- ---------------------------------------------------------------------------- SET ROLE NONE @@ -1617,6 +1812,8 @@ SET DEFAULT ROLE role FOR user@host -- ---------------------------------------------------------------------------- -- Show Create Event Statements -- https://mariadb.com/kb/en/show-create-event +-- +-- SHOW CREATE EVENT event_name -- ---------------------------------------------------------------------------- SHOW CREATE EVENT db_name.event_name @@ -1649,6 +1846,8 @@ SHOW CREATE USER user_name -- ------------------------------- -- Show Grants Statements -- https://mariadb.com/kb/en/show-grants +-- +-- SHOW CREATE USER user_name -- ---------------------------------------------------------------------------- SHOW GRANTS From 3ac3b2da9845d6e74478bcc70cbe6f2cae37640f Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Mon, 18 Jul 2022 18:54:23 +0200 Subject: [PATCH 181/250] MySQL: Add CREATE PROCEDURE tests --- SQL/SQL (basic).sublime-syntax | 6 ++-- SQL/tests/syntax/syntax_test_mysql.sql | 48 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 857b544944..dcd58c4e25 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -800,7 +800,7 @@ contexts: built-in-type: - match: \b{{simple_types}}\b scope: storage.type.sql - pop: 1 + set: maybe-group - match: |- (?xi) \b{{types_with_optional_number}}\b @@ -810,11 +810,11 @@ contexts: 1: constant.numeric.sql 2: punctuation.separator.sequence.sql 3: constant.numeric.sql - pop: 1 + set: maybe-group expect-user-type: - match: (?=\S) - set: inside-user-type + set: [maybe-group, inside-user-type] inside-user-type: # note: may contain foreign variable interpolation diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 2dd7301a0d..c21ef43adc 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -438,6 +438,54 @@ CREATE AGGREGATE FUNCTION -- Valid SQL procedure statement -- ---------------------------------------------------------------------------- +CREATE PROCEDURE +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.function +-- ^^^^^^^^^ meta.statement.create.sql meta.function.sql keyword.other.ddl.sql + +CREATE OR REPLACE PROCEDURE sp_name (param int, out args varchar(200)) SELECT foo FROM bar; +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.parameters.sql meta.group.sql +-- ^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ meta.function.sql keyword.other.ddl.sql +-- ^^^^^^^ entity.name.function.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ variable.parameter.sql +-- ^^^ storage.type.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^ storage.modifier.sql +-- ^^^^ variable.parameter.sql +-- ^^^^^^^ support.type.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^ constant.numeric.value.sql +-- ^^ punctuation.section.group.end.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^^^ meta.column-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^ meta.table-name.sql +-- ^ punctuation.terminator.statement.sql + +CREATE PROCEDURE + sp_name + NOT DETERMINISTIC +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^ storage.modifier.sql + SQL SECURITY INVOKER +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^ constant.language.user.sql + COMMENT 'my procedure' +-- <- meta.statement.create.sql meta.function.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + -- ---------------------------------------------------------------------------- -- Create Role Statements From 253037d96108145232ec2caef2c5fc0ac02722b5 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Mon, 18 Jul 2022 19:02:14 +0200 Subject: [PATCH 182/250] MySQL: Add CREATE FUNCTION UDF statements Adds `SONAME` keyword. --- SQL/MySQL.sublime-syntax | 2 ++ SQL/tests/syntax/syntax_test_mysql.sql | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 486e8b231a..0f8dc57943 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -657,6 +657,8 @@ contexts: scope: storage.modifier.sql - match: \b(?i:definer|invoker)\b scope: constant.language.user.sql + - match: \b(?i:soname)\b + scope: keyword.other.ddl.sql ###[ USER MANAGEMENT EXPRESSIONS ]############################################# diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index c21ef43adc..9f9249aa04 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -296,6 +296,10 @@ CREATE EVENT event_name -- -- func_body: -- Valid SQL procedure statement +-- +-- CREATE [OR REPLACE] [AGGREGATE] FUNCTION [IF NOT EXISTS] function_name +-- RETURNS {STRING|INTEGER|REAL|DECIMAL} +-- SONAME shared_library_name -- ---------------------------------------------------------------------------- CREATE DEFINER = CURRENT_ROLE AGGREGATE FUNCTION foo @@ -410,6 +414,17 @@ CREATE AGGREGATE FUNCTION -- ^^^^^^^ meta.statement.create.sql meta.function.sql -- ^ - meta.statement - meta.function +CREATE FUNCTION function_name RETURNS STRING SONAME 'ha_connect.so'; +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.function +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^ entity.name.function.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ support.type.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.terminator.statement.sql -- ---------------------------------------------------------------------------- -- Create Procedure Statements From 412bf152f3f0d2ca1b88313b6c3323b22ff6201a Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Thu, 4 Aug 2022 17:25:48 +0200 Subject: [PATCH 183/250] SQL: Common scheme of DDL statement arguments Introduce dedicated `create/drop/alter-...-args` comments to let dialects support keywords/expressions per statement. Nearly each statement supports a dedicated set of keywords and/or expressions. --- SQL/Cassandra.sublime-syntax | 21 ++---- SQL/MySQL.sublime-syntax | 3 - SQL/PostgreSQL.sublime-syntax | 52 ++++++++------ SQL/SQL (basic).sublime-syntax | 80 +++++++++++++++++----- SQL/tests/syntax/syntax_test_postgres.psql | 9 ++- 5 files changed, 108 insertions(+), 57 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 6cbea16923..60172bb0d6 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -37,7 +37,7 @@ contexts: - match: \b(?i:type)\b scope: keyword.other.ddl.cql push: - - target-on + - create-type-args - maybe-column-declaration-list - expect-type-creation-name - create-type-condition @@ -46,9 +46,11 @@ contexts: - meta_include_prototype: false - include: maybe-condition -###[ DDL STATEMENT PROTOTYPES ]################################################ + create-type-args: + - meta_scope: meta.type.sql + - include: create-common-args - target-on: + create-common-args: - meta_prepend: true - match: \b(?i:clustering)\b scope: keyword.other.cql @@ -180,19 +182,6 @@ contexts: scope: punctuation.separator.sequence.cql - include: expect-column-names -###[ IDENTIFIERS ]############################################################# - - expect-type-creation-name: - - meta_include_prototype: false - - include: comments - - match: (?=\S) - set: [type-creation-name, single-identifier] - - type-creation-name: - - meta_include_prototype: false - - meta_scope: entity.name.type.cql - - include: immediately-pop - ###[ TYPES ]################################################################### built-in-type: diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 0f8dc57943..9921f8860c 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -72,9 +72,6 @@ contexts: create-target: - meta_prepend: true - # index modifiers - - match: \b(?i:unique|fulltext|spatial)\b - scope: keyword.other.ddl.sql - include: algorithms - include: definers - include: create-database diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 6478e804d0..42e35a7c26 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -66,7 +66,7 @@ contexts: - match: \b(?i:extension|domain)\b scope: keyword.other.ddl.psql set: - - target-options + - create-extension-args - expect-extension-name-declaration - create-extension-condition @@ -74,22 +74,41 @@ contexts: - meta_include_prototype: false - include: maybe-condition + create-extension-args: + - meta_scope: meta.extension.sql + - match: \b(?i:with)\b + scope: keyword.other.psql + - match: \b(?i:schema)\b + scope: storage.modifier.psql + push: expect-schema-name + - include: extension-attributes + - include: expressions + create-index-condition: # https://www.postgresql.org/docs/current/sql-createindex.html - meta_prepend: true - match: \b(?i:concurrently)\b scope: keyword.other.ddl.psql + create-common-args: + - meta_prepend: true + - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b + scope: keyword.other.psql + - match: \b(?i:for\s+each\s+row\s+execute\s+procedure)\b + scope: keyword.other.psql + ###[ DDL DROP STATEMENTS ]##################################################### drop-target: - meta_prepend: true + - include: drop-extension + + drop-extension: # https://www.postgresql.org/docs/current/sql-dropextension.html - match: \b(?i:extension|domain)\b scope: keyword.other.ddl.psql set: - - target-options - - drop-extension-name-list + - drop-extension-args - expect-extension-name - drop-extension-condition @@ -97,10 +116,12 @@ contexts: - meta_include_prototype: false - include: maybe-condition - drop-extension-name-list: + drop-extension-args: + - meta_scope: meta.extension.psql - match: ',' scope: punctuation.separator.sequence.psql push: expect-extension-name + - include: extension-attributes - include: else-pop ###[ DDL ALTER STATEMENTS ]#################################################### @@ -137,27 +158,12 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ - target-options: - - meta_prepend: true - - match: \b(?i:for\s+each\s+row\s+execute\s+procedure)\b - scope: keyword.other.psql - - match: \b(?i:with)\b - scope: keyword.other.psql - - match: \b(?i:schema)\b - scope: storage.modifier.psql - push: expect-schema-name - - match: \b(?i:version|cascade|restrict)\b - scope: storage.modifier.psql - - target-on: - - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b - scope: keyword.other.psql + on-tables: - match: \b(?i:(on)(?:\s+(only))?)\b captures: 1: keyword.other.sql 2: keyword.other.psql push: expect-table-name - - include: else-pop ###[ EXPRESSIONS ]############################################################# @@ -172,6 +178,12 @@ contexts: - match: ':(?!:)' scope: keyword.operator.range.psql +###[ EXTENSION EXPRESSIONS ]################################################### + + extension-attributes: + - match: \b(?i:cascade|restrict|version)\b + scope: storage.modifier.psql + ###[ FUNCTION EXPRESSIONS ]#################################################### expect-function-characteristics: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index dcd58c4e25..203b376279 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -147,8 +147,7 @@ contexts: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql set: - - target-options - - target-on + - create-index-args - expect-index-creation-name - create-index-condition @@ -156,13 +155,18 @@ contexts: - meta_include_prototype: false - include: maybe-condition + create-index-args: + - meta_scope: meta.index.sql + - include: on-tables + - include: create-common-args + create-table: - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql set: - - target-on + - create-table-args - maybe-column-declaration-list - expect-table-creation-name - create-table-condition @@ -171,12 +175,15 @@ contexts: - meta_include_prototype: false - include: maybe-condition + create-table-args: + - meta_scope: meta.table.sql + - include: create-common-args + create-other: - match: \b{{ddl_target_other}}\b scope: keyword.other.ddl.sql set: - - target-options - - target-on + - create-other-args - expect-other-creation-name - create-other-condition @@ -184,6 +191,17 @@ contexts: - meta_include_prototype: false - include: maybe-condition + create-other-args: + - match: \b(?i:as)\b + scope: keyword.context.block.sql + pop: 1 + - include: on-tables + - include: create-common-args + + create-common-args: + - include: expressions + - include: pop-on-top-level-reserved-word + ###[ DDL DROP STATEMENTS ]##################################################### drop-statements: @@ -209,6 +227,7 @@ contexts: - match: \b{{ddl_target_function}}\b scope: keyword.other.ddl.sql set: + - drop-function-args - expect-function-name - drop-function-condition @@ -216,10 +235,16 @@ contexts: - meta_include_prototype: false - include: maybe-condition + drop-function-args: + - meta_include_prototype: false + - meta_scope: meta.function.sql + - include: immediately-pop + drop-index: - match: \b(?i:index)\b scope: keyword.other.ddl.sql set: + - drop-index-args - expect-index-name - drop-index-condition @@ -227,12 +252,17 @@ contexts: - meta_include_prototype: false - include: maybe-condition + drop-index-args: + - meta_scope: meta.index.sql + - include: maybe-on-table + drop-table: - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql set: + - drop-table-args - expect-table-name - drop-table-condition @@ -240,11 +270,16 @@ contexts: - meta_include_prototype: false - include: maybe-condition + drop-table-args: + - meta_include_prototype: false + - meta_scope: meta.table.sql + - include: immediately-pop + drop-other: - match: \b{{ddl_target_other}}\b scope: keyword.other.ddl.sql set: - - target-on + - drop-other-args - expect-other-name - drop-other-condition @@ -252,6 +287,9 @@ contexts: - meta_include_prototype: false - include: maybe-condition + drop-other-args: + - include: maybe-on-table + ###[ DDL ALTER STATEMENTS ]#################################################### alter-statements: @@ -371,18 +409,14 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ - target-options: - - match: \b(?i:as)\b - scope: keyword.context.block.sql - pop: 1 - - include: expressions - - include: pop-on-top-level-reserved-word + maybe-on-table: + - include: on-tables + - include: else-pop - target-on: + on-tables: - match: \b(?i:on)\b scope: keyword.other.sql push: expect-table-name - - include: else-pop ###[ DML STATEMENTS ]########################################################## @@ -620,14 +654,16 @@ contexts: expect-function-characteristics: - meta_scope: meta.function.sql + - match: \b(?i:as|return)\b + scope: keyword.context.block.sql + pop: 1 - match: \b(?i:language)\b scope: storage.modifier.sql push: expect-function-language-name - match: \b(?i:returns)\b scope: keyword.other.ddl.sql push: expect-type - - include: expressions - - include: pop-on-top-level-reserved-word + - include: create-common-args expect-function-language-name: - match: '{{simple_identifier}}' @@ -1015,6 +1051,18 @@ contexts: - meta_content_scope: meta.table-alias-name.sql - include: immediately-pop + expect-type-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [type-creation-name, single-identifier] + + type-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.type.cql + - include: immediately-pop + expect-other-creation-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index 505c5861dd..99478e231b 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -207,10 +207,15 @@ SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; -- ^^^^^^^ meta.table-name --- ----------------- +-- ---------------------------------------------------------------------------- -- CREATE EXTENSION -- https://www.postgresql.org/docs/current/sql-createextension.html --- ----------------- +-- +-- CREATE EXTENSION [ IF NOT EXISTS ] extension_name +-- [ WITH ] [ SCHEMA schema_name ] +-- [ VERSION version ] +-- [ CASCADE ] +-- ---------------------------------------------------------------------------- CREATE EXTENSION hstore SCHEMA addons; -- <- meta.statement.create.sql keyword.other.ddl From 0fdce03ed76d253750dc97d6bd1c29fd73abca26 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 6 Aug 2022 17:47:12 +0200 Subject: [PATCH 184/250] MySQL: Add CREATE/DROP INDEX statements --- SQL/MySQL.sublime-syntax | 129 ++++++++++++-- SQL/tests/syntax/syntax_test_mysql.sql | 194 ++++++++++++++++----- SQL/tests/syntax/syntax_test_postgres.psql | 14 +- 3 files changed, 280 insertions(+), 57 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 9921f8860c..5a9ce3e930 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -94,12 +94,11 @@ contexts: create-database-args: - meta_scope: meta.database.sql - - match: \b(?i:comment)\b - scope: keyword.other.ddl.sql - match: \b(?i:(?:default\s+)?(?:character\s+set|collate))\b scope: variable.parameter.database.sql - match: = scope: keyword.operator.assignment.sql + - include: comment-keywords - include: strings - include: else-pop @@ -121,6 +120,18 @@ contexts: - include: event-options - include: pop-on-top-level-reserved-word + create-index-args: + # https://mariadb.com/kb/en/create-index + - meta_prepend: true + - include: index-algorithm-args + - include: index-clustering-args + - include: index-lock-args + - include: index-parser-args + - include: index-type-args + - include: index-wait-args + - include: index-other-args + - include: comment-keywords + create-role: # https://mariadb.com/kb/en/create-role - match: \b(?i:role)\b @@ -210,6 +221,10 @@ contexts: - meta_scope: meta.event.sql - include: immediately-pop + drop-index-args: + - meta_prepend: true + - include: index-wait-args + drop-user: # https://mariadb.com/kb/en/drop-role # https://mariadb.com/kb/en/drop-user @@ -350,9 +365,7 @@ contexts: - set-role-name set-role-name: - - match: \b(?i:none)\b - scope: constant.language.null.sql - pop: 1 + - include: none-constant - include: expect-user-name set-other-assignment: @@ -595,8 +608,7 @@ contexts: - match: \b(?i:do)\b scope: keyword.other.ddl.sql pop: 1 - - match: \b(?i:comment)\b - scope: keyword.other.ddl.sql + - include: comment-keywords - include: event-schedule-args - include: event-enable-args - include: event-completion-args @@ -642,8 +654,6 @@ contexts: - match: \b(?i:return)\b scope: keyword.control.flow.return.sql pop: 1 - - match: \b(?i:comment)\b - scope: keyword.other.ddl.sql - match: \b(?i:not)\b scope: keyword.operator.logical.sql - match: \b(?i:deterministic)\b @@ -656,6 +666,72 @@ contexts: scope: constant.language.user.sql - match: \b(?i:soname)\b scope: keyword.other.ddl.sql + - include: comment-keywords + +###[ INDEX EXPRESSIONS ]####################################################### + + index-algorithm-args: + - match: \b(?i:algorithm)\b + scope: keyword.other.ddl.sql + push: index-algorithm-value + + index-algorithm-value: + - match: \b(?i:inplace|copy|nocopy|instant)\b + scope: constant.language.algorithm.sql + pop: 1 + - include: default-constant + - include: else-pop + + index-clustering-args: + - match: \b(?i:clustering)\b + scope: keyword.other.ddl.sql + + index-lock-args: + - match: \b(?i:lock)\b + scope: keyword.other.ddl.sql + push: index-lock-value + + index-lock-value: + - match: \b(?i:shared|exclusive)\b + scope: constant.language.lock-option.sql + pop: 1 + - include: default-constant + - include: none-constant + - include: else-pop + + index-parser-args: + - match: \b(?i:with\s+parser)\b + scope: keyword.other.ddl.sql + push: expect-other-name + + index-type-args: + - match: \b(?i:using)\b + scope: keyword.other.ddl.sql + push: index-type-value + + index-type-value: + - match: \b(?i:btree|hash|rtree)\b + scope: constant.language.index-type.sql + pop: 1 + - include: else-pop + + index-wait-args: + - match: \b(?i:nowait)\b + scope: keyword.other.ddl.sql + - match: \b(?i:wait)\b + scope: keyword.other.ddl.sql + push: index-wait-value + + index-wait-value: + - include: numbers + - include: time-units + - include: else-pop + + index-other-args: + - match: \b(?i:ignored)\b + scope: keyword.other.ddl.sql + - match: \b(?i:key_block_size)\b + scope: keyword.other.ddl.sql ###[ USER MANAGEMENT EXPRESSIONS ]############################################# @@ -793,8 +869,7 @@ contexts: scope: keyword.operator.logical.sql - match: \b(?i:ssl|x509|cipher|issuer|subject)\b scope: constant.language.sql - - match: \b(?i:none)\b - scope: constant.language.null.sql + - include: none-constants user-privileges: - include: column-reference-lists @@ -924,6 +999,38 @@ contexts: ###[ LITERALS ]################################################################ + comment-keywords: + - match: \b(?i:comment)\b + scope: keyword.other.ddl.sql + + constants: + - meta_append: true + - include: default-constants + - include: none-constants + - include: yesno-constants + + default-constants: + - match: \b(?i:default)\b + scope: constant.language.default.sql + + default-constant: + - match: \b(?i:default)\b + scope: constant.language.default.sql + pop: 1 + + yesno-constants: + - match: \b(?i:yes|no)\b + scope: constant.language.boolean.sql + + none-constants: + - match: \b(?i:none)\b + scope: constant.language.null.sql + + none-constant: + - match: \b(?i:none)\b + scope: constant.language.null.sql + pop: 1 + time-units: - match: '{{time_unit}}' scope: keyword.other.unit.sql diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 9f9249aa04..c1fb4d3198 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -502,6 +502,137 @@ CREATE PROCEDURE -- ^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ---------------------------------------------------------------------------- +-- Create Index Statements +-- https://mariadb.com/kb/en/create-index +-- +-- CREATE [OR REPLACE] [UNIQUE|FULLTEXT|SPATIAL] INDEX +-- [IF NOT EXISTS] index_name +-- [index_type] +-- ON tbl_name (index_col_name,...) +-- [WAIT n | NOWAIT] +-- [index_option] +-- [algorithm_option | lock_option] ... +-- +-- index_col_name: +-- col_name [(length)] [ASC | DESC] +-- +-- index_type: +-- USING {BTREE | HASH | RTREE} +-- +-- index_option: +-- [ KEY_BLOCK_SIZE [=] value +-- | index_type +-- | WITH PARSER parser_name +-- | COMMENT 'string' +-- | CLUSTERING={YES| NO} ] +-- [ IGNORED | NOT IGNORED ] +-- +-- algorithm_option: +-- ALGORITHM [=] {DEFAULT|INPLACE|COPY|NOCOPY|INSTANT} +-- +-- lock_option: +-- LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE} +-- ---------------------------------------------------------------------------- + +CREATE INDEX ON fancy_table(mytime); +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^ meta.statement.create.sql - meta.index +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.other +-- ^^^^^^^^^^^ meta.table-name +-- ^^^^^^^^ meta.group.sql + +CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^ meta.statement.create.sql - meta.index +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^ keyword.other.ddl +-- ^^^^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ meta.statement.create keyword.other +-- ^^^^^^^^^^^ meta.table-name +-- ^ meta.group punctuation.section.group.begin +-- ^^^^^^^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.separator.sequence +-- ^^^^^^^ meta.group meta.column-name +-- ^ meta.group punctuation.section.group.end +-- ^^^^^ keyword.other.dml.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql + +create fulltext index if not exists `myindex` ON mytable; +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.index +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.control.conditional.if +-- ^^^ keyword.operator.logical +-- ^^^^^^ keyword.operator.logical +-- ^^^^^^^^^ entity.name.struct.index +-- ^^ keyword.other +-- ^^^^^^^ meta.table-name +-- ^ punctuation.terminator.statement + +CREATE INDEX index_name +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql +-- ^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.struct.index.sql + USING BTREE +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.index-type.sql + ON tbl_name (col1(100) ASC, col2 DESC) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^ keyword.other.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^ punctuation.section.group.end.sql + NOWAIT +-- ^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^ keyword.other.ddl.sql + WAIT 1 DAY +-- ^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^ keyword.other.ddl.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^ keyword.other.unit.sql + COMMENT 'my comment' +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + WITH PARSER parser_name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ meta.other-name.sql + CLUSTERING = YES +-- ^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^ keyword.operator.comparison.sql +-- ^^^ constant.language.boolean.sql + KEY_BLOCK_SIZE 20 +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql + NOT IGNORED +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^ keyword.other.ddl.sql + ALGORITHM INPLACE +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ constant.language.algorithm.sql + LOCK SHARED +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^ constant.language.lock-option.sql + + -- ---------------------------------------------------------------------------- -- Create Role Statements -- https://mariadb.com/kb/en/create-role @@ -1322,6 +1453,25 @@ DROP EVENT IF EXISTS event ; -- ^ punctuation.terminator.statement.sql +-- ---------------------------------------------------------------------------- +-- Drop Index Statements +-- https://mariadb.com/kb/en/drop-index +-- +-- DROP INDEX [IF EXISTS] index_name ON tbl_name +-- [WAIT n |NOWAIT] +-- ---------------------------------------------------------------------------- + +DROP INDEX index_name ON tbl_name NOWAIT; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.index +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.index.sql +-- ^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^ keyword.other.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^ keyword.other.ddl.sql + -- ---------------------------------------------------------------------------- -- Drop Role Statements -- https://mariadb.com/kb/en/drop-role @@ -2099,50 +2249,6 @@ create table fancy_table ( -- ^^^^^^^^^^ meta.column-name ); -CREATE INDEX ON fancy_table(mytime); --- <- meta.statement.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql --- ^^^^^ keyword.other.ddl --- ^^ keyword.other --- ^^^^^^^^^^^ meta.table-name - -CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); --- <- meta.statement.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql --- ^^^ keyword.other.ddl --- ^^^^^ keyword.other.ddl --- ^^ keyword.other --- ^^^^^^^^^^^ meta.table-name --- ^^^^^ keyword.other - -CREATE UNIQUE INDEX ON fancy_table(fancy_column,mycount) WHERE myflag IS NULL; --- <- meta.statement.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql --- ^^^ keyword.other.ddl --- ^^^^^^ keyword.other.ddl --- ^^^^^ keyword.other.ddl --- ^^ meta.statement.create keyword.other --- ^^^^^^^^^^^ meta.table-name --- ^ meta.group punctuation.section.group.begin --- ^^^^^^^^^^^^ meta.group meta.column-name --- ^ meta.group punctuation.separator.sequence --- ^^^^^^^ meta.group meta.column-name --- ^ meta.group punctuation.section.group.end --- ^^^^^ keyword.other.dml.sql --- ^^ keyword.operator.logical.sql --- ^^^^ constant.language.null.sql - -create fulltext index if not exists `myindex` ON mytable; --- ^^^^^^^^ keyword.other.ddl --- ^^^^^ keyword.other.ddl --- ^^ keyword.control.conditional.if --- ^^^ keyword.operator.logical --- ^^^^^^ keyword.operator.logical --- ^^^^^^^^^ entity.name.struct.index --- ^^ keyword.other --- ^^^^^^^ meta.table-name --- ^ punctuation.terminator.statement - ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; -- <- meta.statement.alter.sql keyword.other.ddl -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index 99478e231b..d502954d1c 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -343,7 +343,7 @@ CREATE INDEX index_name USING method_name -- ^^^ keyword.other.ddl.sql -- ^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^ entity.name.struct.index.sql --- ^^^^^ keyword.other.mysql +-- ^^^^^ keyword.other CREATE UNIQUE INDEX IF NOT EXISTS index_name ON table_name -- <- meta.statement.create.sql keyword.other.ddl.sql @@ -386,8 +386,18 @@ CREATE UNIQUE INDEX CONCURRENTLY IF EXISTS index_name ON ONLY table_name USING m -- ^^ keyword.other.sql -- ^^^^ keyword.other.psql -- ^^^^^^^^^^ meta.table-name.sql --- ^^^^^ keyword.other.mysql +-- ^^^^^ keyword.other +CREATE INDEX ON fancy_table USING gin (fancy_column gin_trgm_ops); +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^ meta.statement.create.sql - meta.index +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql +-- ^^^ keyword.other.ddl +-- ^^^^^ keyword.other.ddl +-- ^^ keyword.other +-- ^^^^^^^^^^^ meta.table-name +-- ^^^^^ keyword.other +-- ^^^ meta.function-call.sql support.function.sql -- ----------------- -- CREATE TABLE From 5fe0636fc47985b4fa4df7f0ab7264da65fa537c Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sat, 6 Aug 2022 18:09:29 +0200 Subject: [PATCH 185/250] MySQL: Improve CREATE TABLE statements --- SQL/MySQL.sublime-syntax | 134 ++++- SQL/SQL (basic).sublime-syntax | 28 + SQL/tests/syntax/syntax_test_mysql.sql | 735 ++++++++++++++++++++----- 3 files changed, 763 insertions(+), 134 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 5a9ce3e930..0b66f1cf1e 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -13,6 +13,23 @@ variables: function_parameter_modifier: |- (?xi: in\s*out | in | out ) + database_parameters: |- + (?xi: (?:default\s+)? (?: character\s+set | collate ) ) + + partition_parameters: |- + (?xi: (?:storage\s+)?engine | (?:data|index)\s+directory | max_rows | min_rows | nodegroup ) + + table_parameters: |- + (?xi: (?:storage\s+)?engine | (?:default\s+)?(?: character\s+set | collate ) + | auto_increment | avg_row_length | checksum | connection | data\s+directory + | delay_key_write | encrypted | encryption_key_id | ietf_quotes | index\s+directory + | insert_method | key_block_size | max_rows | min_rows | pack_keys | page_checksum + | page_compressed | page_compression_level | password | row_format | sequence + | stats_auto_recalc | stats_persistent | stats_sample_pages | transactional | union + | with\s+system\s+versioning ) + table_row_formats: |- + (?xi: dynamic | fixed | compressed | redundant | compact | page ) + simple_types: |- (?xi: bigint | bigserial | bit | bool | boolean | box | bytea | cidr | circle | date | datetime | double\s+precision | enum | inet | integer | line @@ -94,10 +111,9 @@ contexts: create-database-args: - meta_scope: meta.database.sql - - match: \b(?i:(?:default\s+)?(?:character\s+set|collate))\b + - match: \b{{database_parameters}}\b scope: variable.parameter.database.sql - - match: = - scope: keyword.operator.assignment.sql + - include: assignment-operators - include: comment-keywords - include: strings - include: else-pop @@ -149,6 +165,13 @@ contexts: - meta_scope: meta.user.sql - include: maybe-with-admin-user + create-table-args: + # https://mariadb.com/kb/en/create-table + - meta_prepend: true + - include: partition-lists + - include: partition-options + - include: table-options + create-user: # https://mariadb.com/kb/en/create-user - match: \b(?i:user)\b @@ -733,6 +756,101 @@ contexts: - match: \b(?i:key_block_size)\b scope: keyword.other.ddl.sql +###[ PARTITION EXPRESSIONS ]################################################### + + partition-lists: + - match: \( + scope: punctuation.section.sequence.begin.sql + push: inside-partition-list + + inside-partition-list: + - meta_scope: meta.sequence.partitions.sql + - match: \) + scope: punctuation.section.sequence.end.sql + pop: 1 + # partition and subpartition declarations + - match: \b(?i:(?:sub)?partition)\b + scope: keyword.other.ddl.sql + push: expect-partition-creation-name + # partition parameters + - match: \b(?i:values)\b + scope: keyword.other.ddl.sql + - match: \b(?i:in|less\s+than)\b + scope: keyword.operator.logical.sql + push: maybe-group + - match: \b{{partition_parameters}}\b + scope: variable.parameter.sql + - include: partition-lists + - include: comment-keywords + - include: maxvalue-constants + - include: tablespaces + - include: expressions + + partition-options: + # partition keywords + - match: \b(?i:(?:sub)?partition by)\b + scope: keyword.other.sql + - match: \b(?i:(?:sub)?partitions)\b + scope: keyword.other.sql + # partition arguments + - match: \b(?i:linear)\b + scope: storage.modifier.sql + - match: \b(?i:hash|range|list)\b + scope: support.function.sql + push: maybe-group + - match: \b(?i:key)\b + scope: support.function.sql + push: maybe-column-reference-list + - match: \b(?i:limit|system_time)\b + scope: keyword.other.sql + - include: intervals + - include: time-units + +###[ TABLE EXPRESSIONS ]####################################################### + + table-options: + - include: comment-keywords + # table options with special treatment + - include: tablespaces + - match: \b(?i:like)\b + scope: keyword.other.sql + push: expect-table-name + - match: \b(?i:union)\b + scope: variable.parameter.sql + push: maybe-table-reference-list + # common table options + - match: \b{{table_parameters}}\b + scope: variable.parameter.sql + - match: \b{{table_row_formats}}\b + scope: constant.language.sql + # common table option values + - match: \b(?i:first|last)\b + scope: constant.language.sql + + tablespaces: + - match: \b(?i:tablespace)\b + scope: variable.parameter.sql + push: maybe-tablespace-name + + maybe-tablespace-name: + - include: assignment-operators + - include: expect-other-name + + maybe-table-reference-list: + - match: \( + scope: punctuation.section.sequence.begin.sql + set: inside-table-reference-list + - include: assignment-operators + - include: else-pop + + inside-table-reference-list: + - meta_scope: meta.sequence.tables.sql + - match: \) + scope: punctuation.section.sequence.end.sql + pop: 1 + - include: comma-separators + - include: expect-table-names + ###[ USER MANAGEMENT EXPRESSIONS ]############################################# maybe-with-admin-user: @@ -909,7 +1027,7 @@ contexts: inside-column-declaration-list: - meta_prepend: true - match: \b(?i:auto_increment)\b - scope: keyword.other.mysql + scope: storage.modifier.sql - match: \b(?i:(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)) scope: keyword.other.object-comments.sql @@ -922,7 +1040,7 @@ contexts: after-type: - meta_prepend: true - match: \b(?i:unsigned)\b - scope: storage.modifier.mysql + scope: storage.modifier.sql pop: 1 - match: \b(?i:with(?:out)?\s+time\s+zone)\b scope: storage.type.sql @@ -1001,7 +1119,7 @@ contexts: comment-keywords: - match: \b(?i:comment)\b - scope: keyword.other.ddl.sql + scope: variable.parameter.sql constants: - meta_append: true @@ -1018,6 +1136,10 @@ contexts: scope: constant.language.default.sql pop: 1 + maxvalue-constants: + - match: \b(?i:maxvalue)\b + scope: constant.language.sql + yesno-constants: - match: \b(?i:yes|no)\b scope: constant.language.boolean.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 203b376279..d5aaa48bf4 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -998,6 +998,30 @@ contexts: - match: (?=\S) set: [procedure-creation-name, single-identifier] + expect-partition-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [partition-creation-name, single-identifier] + + partition-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.struct.partition.sql + - include: immediately-pop + + expect-partition-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [partition-name, single-identifier] + + partition-name: + - meta_include_prototype: false + - meta_scope: meta.partition-name.sql + - include: immediately-pop + procedure-creation-name: - meta_include_prototype: false - meta_content_scope: entity.name.function.sql @@ -1027,6 +1051,10 @@ contexts: - meta_scope: entity.name.struct.table.sql - include: immediately-pop + expect-table-names: + - match: (?=\S) + push: [table-name, single-identifier] + expect-table-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index c1fb4d3198..68900339fb 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -98,14 +98,14 @@ CREATE OR REPLACE SCHEMA schema_name COMMENT = 'My new database' -- <- meta.statement.create.sql meta.database.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql --- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.sql -- ^ keyword.operator.assignment.sql -- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql COMMENT 'My new database' -- <- meta.statement.create.sql meta.database.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.database.sql --- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.sql -- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql @@ -252,7 +252,7 @@ CREATE EVENT event_name COMMENT 'my comment' -- <- meta.statement.create.sql meta.event.sql -- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.event.sql --- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.sql -- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql DO UPDATE myschema.mytable SET mycol = mycol + 1; @@ -406,7 +406,7 @@ CREATE AGGREGATE FUNCTION COMMENT 'string' -- <- meta.statement.create.sql meta.function.sql -- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql --- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.sql -- ^^^^^^^^ meta.string.sql string.quoted.single.sql RETURN @@ -498,7 +498,7 @@ CREATE PROCEDURE COMMENT 'my procedure' -- <- meta.statement.create.sql meta.function.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql --- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.sql -- ^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql @@ -604,7 +604,7 @@ CREATE INDEX index_name -- ^^^ keyword.other.unit.sql COMMENT 'my comment' -- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql --- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.sql -- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql WITH PARSER parser_name -- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql @@ -699,6 +699,605 @@ CREATE ROLE role WITH ADMIN CURRENT_ROLE -- ^^^^^^^^^^^^ support.function.scalar.sql +-- ---------------------------------------------------------------------------- +-- Create Table Statements +-- https://mariadb.com/kb/en/create-table +-- +-- CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name +-- (create_definition,...) [table_options ]... [partition_options] +-- CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name +-- [(create_definition,...)] [table_options ]... [partition_options] +-- select_statement +-- CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name +-- { LIKE old_table_name | (LIKE old_table_name) } +-- +-- create_definition: +-- { col_name column_definition | index_definition | period_definition | CHECK (expr) } +-- +-- column_definition: +-- data_type +-- [NOT NULL | NULL] [DEFAULT default_value | (expression)] +-- [ON UPDATE [NOW | CURRENT_TIMESTAMP] [(precision)]] +-- [AUTO_INCREMENT] [ZEROFILL] [UNIQUE [KEY] | [PRIMARY] KEY] +-- [INVISIBLE] [{WITH|WITHOUT} SYSTEM VERSIONING] +-- [COMMENT 'string'] [REF_SYSTEM_ID = value] +-- [reference_definition] +-- | data_type [GENERATED ALWAYS] +-- AS { { ROW {START|END} } | { (expression) [VIRTUAL | PERSISTENT | STORED] } } +-- [UNIQUE [KEY]] [COMMENT 'string'] +-- +-- constraint_definition: +-- CONSTRAINT [constraint_name] CHECK (expression) +-- +-- select_statement: +-- [IGNORE | REPLACE] [AS] SELECT ... (Some legal select statement) +-- +-- table_options: +-- table_option, [table_option ...] +-- +-- table_option: +-- [STORAGE] ENGINE [=] engine_name +-- | AUTO_INCREMENT [=] value +-- | AVG_ROW_LENGTH [=] value +-- | [DEFAULT] CHARACTER SET [=] charset_name +-- | CHECKSUM [=] {0 | 1} +-- | [DEFAULT] COLLATE [=] collation_name +-- | COMMENT [=] 'string' +-- | CONNECTION [=] 'connect_string' +-- | DATA DIRECTORY [=] 'absolute path to directory' +-- | DELAY_KEY_WRITE [=] {0 | 1} +-- | ENCRYPTED [=] {YES | NO} +-- | ENCRYPTION_KEY_ID [=] value +-- | IETF_QUOTES [=] {YES | NO} +-- | INDEX DIRECTORY [=] 'absolute path to directory' +-- | INSERT_METHOD [=] { NO | FIRST | LAST } +-- | KEY_BLOCK_SIZE [=] value +-- | MAX_ROWS [=] value +-- | MIN_ROWS [=] value +-- | PACK_KEYS [=] {0 | 1 | DEFAULT} +-- | PAGE_CHECKSUM [=] {0 | 1} +-- | PAGE_COMPRESSED [=] {0 | 1} +-- | PAGE_COMPRESSION_LEVEL [=] {0 .. 9} +-- | PASSWORD [=] 'string' +-- | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT|PAGE} +-- | SEQUENCE [=] {0|1} +-- | STATS_AUTO_RECALC [=] {DEFAULT|0|1} +-- | STATS_PERSISTENT [=] {DEFAULT|0|1} +-- | STATS_SAMPLE_PAGES [=] {DEFAULT|value} +-- | TABLESPACE tablespace_name +-- | TRANSACTIONAL [=] {0 | 1} +-- | UNION [=] (tbl_name[,tbl_name]...) +-- | WITH SYSTEM VERSIONING +-- +-- partition_options: +-- PARTITION BY +-- { [LINEAR] HASH(expr) +-- | [LINEAR] KEY(column_list) +-- | RANGE(expr) +-- | LIST(expr) +-- | SYSTEM_TIME [INTERVAL time_quantity time_unit] [LIMIT num] } +-- [PARTITIONS num] +-- [SUBPARTITION BY +-- { [LINEAR] HASH(expr) +-- | [LINEAR] KEY(column_list) } +-- [SUBPARTITIONS num] +-- ] +-- [(partition_definition [, partition_definition] ...)] +-- +-- partition_definition: +-- PARTITION partition_name +-- [VALUES {LESS THAN {(expr) | MAXVALUE} | IN (value_list)}] +-- [[STORAGE] ENGINE [=] engine_name] +-- [COMMENT [=] 'comment_text' ] +-- [DATA DIRECTORY [=] 'data_dir'] +-- [INDEX DIRECTORY [=] 'index_dir'] +-- [MAX_ROWS [=] max_number_of_rows] +-- [MIN_ROWS [=] min_number_of_rows] +-- [TABLESPACE [=] tablespace_name] +-- [NODEGROUP [=] node_group_id] +-- [(subpartition_definition [, subpartition_definition] ...)] +-- +-- subpartition_definition: +-- SUBPARTITION logical_name +-- [[STORAGE] ENGINE [=] engine_name] +-- [COMMENT [=] 'comment_text' ] +-- [DATA DIRECTORY [=] 'data_dir'] +-- [INDEX DIRECTORY [=] 'index_dir'] +-- [MAX_ROWS [=] max_number_of_rows] +-- [MIN_ROWS [=] min_number_of_rows] +-- [TABLESPACE [=] tablespace_name] +-- [NODEGROUP [=] node_group_id] +-- ---------------------------------------------------------------------------- + +CREATE TABLE foo +-- <- meta.statement.create.sql keyword.other.ddl +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^ keyword.other.ddl +-- ^ - keyword +-- ^^^^^ keyword.other.ddl +-- ^ - keyword +-- ^^^ entity.name.struct.table.sql + +;CREATE OR REPLACE TABLE foo (id INTEGER PRIMARY KEY); +-- <- punctuation.terminator.statement.sql + -- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^^ keyword.other.ddl +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^ entity.name.struct +-- ^ - entity.name +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +create table some_schema.test2( id serial ); +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ entity.name.struct +-- ^ punctuation.accessor.dot +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^ storage.type.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +create table some_schema . test2 ( id serial ); +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^ - entity.name +-- ^^^^^^^^^^^^^^^^^^^ entity.name.struct +-- ^ - entity.name +-- ^ punctuation.accessor.dot +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^ storage.type.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +create temporary table "testing123" (id integer); +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ entity.name.struct.table.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +create table if not exists `dbo`."testing123" (id integer); +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^^^^ entity.name.struct.table.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.accessor.dot.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql + +create table IF NOT EXISTS `testing123` ( +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql - meta.group +-- ^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^ entity.name.struct.table.sql +-- ^ punctuation.section.group.begin.sql + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql +-- ^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^ constant.numeric.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^^^^^^^^^^ storage.modifier.sql +-- ^ punctuation.separator.sequence.sql + `lastchanged` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +-- ^^^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^^^^^^^ support.function.scalar.sql +-- ^^^^^^^^^ storage.modifier.sql + `col` bool DEFAULT FALSE, +-- ^^^^ storage.type.sql +-- ^^^^^^^ storage.modifier.sql +-- ^^^^^ constant.language.boolean.sql +-- ^ punctuation.separator.sequence + `fkey` INT UNSIGNED NULL REFERENCES test2(id), +-- ^^^^^^^^^^ storage.modifier.sql + `version` tinytext DEFAULT NULL COMMENT 'important clarification', +-- ^^^^^^^^ storage.type.sql + `percentage` float DEFAULT '0', + UNIQUE KEY `testing123_search` (`col`, `version`), +-- ^^^^^^^^^^ storage.modifier.sql + KEY `testing123_col` (`col`), +-- ^^^ storage.modifier.sql + FULLTEXT KEY `testing123_version` (`version`) +) ENGINE=MyISAM AUTO_INCREMENT=42 DEFAULT CHARACTER SET=utf8; + +create table fancy_table ( + id SERIAL, +-- ^^^^^^ storage.type.sql + foreign_id integer, +-- ^^^^^^^ storage.type.sql + myflag boolean DEFAULT false, +-- ^^^^^^^ storage.type.sql + mycount double precision DEFAULT 1, +-- ^^^^^^^^^^^^^^^^^ storage.type.sql + fancy_column character varying(42) DEFAULT 'nice'::character varying, +-- ^^^^^^^^^^^^^^^^^^^^^^ storage.type.sql + mytime timestamp(3) without time zone DEFAULT now(), +-- ^^^^^^^^^^^^ storage.type.sql +-- ^ constant.numeric +-- ^^^^^^^^^^^^^^^^^ storage.type.sql +-- ^^^^^^^ storage.modifier +-- ^^^ meta.function-call support.function +-- ^ punctuation.section.arguments.begin +-- ^ punctuation.section.arguments.end +-- ^ punctuation.separator.sequence + mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, -- TODO: seems like :: is a postgresql cast operator +-- ^^^^^^^^^^^^^^^^^^^ storage.type.sql + some_number numeric(5, 2) DEFAULT 0, +-- ^^^^^^^^^^^ meta.column-name +-- ^^^^^^^^^^^^^ storage.type +-- ^ constant.numeric +-- ^ punctuation.separator.sequence +-- ^ constant.numeric +-- ^^^^^^^ storage.modifier +-- ^ meta.number.integer.decimal constant.numeric.value + primary key (id), +-- ^^^^^^^^^^^ storage.modifier.sql + UNIQUE (foreign_id), + CONSTRAINT fancy_table_valid1 CHECK (id <> foreign_id) +-- ^^^^^^^^^^ storage.modifier.sql +-- ^^^^^ keyword.other +-- ^^^^^^^^^^^^^^^^^^ meta.group meta.group +-- ^^ meta.column-name +-- ^^ keyword.operator.comparison +-- ^^^^^^^^^^ meta.column-name +); + +CREATE TABLE foo LIKE bar; +-- <- meta.statement.create.sql keyword.other.ddl.sql +-- ^^^^ meta.statement.create.sql - meta.table +-- ^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^ entity.name.struct.table.sql +-- ^^^^ keyword.other.sql +-- ^^^ meta.table-name.sql +-- ^ punctuation.terminator.statement.sql + + +CREATE TABLE foo (col1, col2) + ENGINE = engine_name, +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql + STORAGE ENGINE = engine_name, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql + AUTO_INCREMENT = 30, +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql + AVG_ROW_LENGTH = 30, +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql + DEFAULT CHARACTER SET = 'utf-8', +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^^^^^ variable.parameter.sql + CHARACTER SET = 'utf-16', +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^ variable.parameter.sql + CHECKSUM = 0, -- {0 | 1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^ variable.parameter.sql + COLLATE = collation_name, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^ variable.parameter.sql + DEFAULT COLLATE = collation_name, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.sql + COMMENT = 'string', +-- ^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^ variable.parameter.sql + CONNECTION = 'connect_string', +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^ variable.parameter.sql + DATA DIRECTORY = 'absolute path to directory', +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql + DELAY_KEY_WRITE = 0, -- {0 | 1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.sql + ENCRYPTED = NO, -- {YES | NO} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^ variable.parameter.sql + ENCRYPTION_KEY_ID = 30, +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^ variable.parameter.sql + IETF_QUOTES = YES, -- {YES | NO} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^ variable.parameter.sql + INDEX DIRECTORY = 'absolute path to directory', +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.sql + INSERT_METHOD = FIRST, -- { NO | FIRST | LAST } +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^ variable.parameter.sql + KEY_BLOCK_SIZE = 30, +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql + MAX_ROWS = 30, +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^ variable.parameter.sql + MIN_ROWS = 30, +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^ variable.parameter.sql + PACK_KEYS = 1, -- {0 | 1 | DEFAULT} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^ variable.parameter.sql + PAGE_CHECKSUM = 0, -- {0 | 1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^ variable.parameter.sql + PAGE_COMPRESSED = 0, -- {0 | 1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.sql + PAGE_COMPRESSION_LEVEL = 9, -- {0 .. 9} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.sql + PASSWORD = 'string', +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^ variable.parameter.sql + ROW_FORMAT = DYNAMIC, -- {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT|PAGE} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^^^ constant.language.sql + SEQUENCE = 0, -- {0|1} +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^ variable.parameter.sql + STATS_AUTO_RECALC = DEFAULT, -- {DEFAULT|0|1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^ variable.parameter.sql + STATS_PERSISTENT = DEFAULT, -- {DEFAULT|0|1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^ variable.parameter.sql + STATS_SAMPLE_PAGES = DEFAULT, -- {DEFAULT|value} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^^ variable.parameter.sql + TABLESPACE tablespace_name, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^ variable.parameter.sql +-- ^^^^^^^^^^^^^^^ meta.other-name.sql + TRANSACTIONAL = 0, -- {0 | 1} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^ variable.parameter.sql + UNION = (`table1`, "table2", table3), -- (tbl_name[,tbl_name]...) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^ variable.parameter.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence.tables.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.table-name.sql +-- ^ punctuation.section.sequence.end.sql + WITH SYSTEM VERSIONING +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.sql +; +-- <- punctuation.terminator.statement.sql + +CREATE + TABLE +-- ^^^^^ meta.statement.create.sql meta.table.sql keyword.other.ddl.sql + foo +-- ^^^ meta.statement.create.sql meta.table.sql entity.name.struct.table.sql + (col1, col2) +-- ^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql + PARTITION BY +-- ^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql keyword.other.sql + LINEAR HASH( 20 + YEAR(col2) ) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^ storage.modifier.sql +-- ^^^^ support.function.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ keyword.operator.arithmetic.sql +-- ^^^^^^^^^^ meta.function-call +-- ^^^^ support.function.sql +-- ^^^^^^ meta.group.sql +-- ^ punctuation.section.arguments.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.arguments.end.sql +-- ^ punctuation.section.group.end.sql + LINEAR KEY(col1, col2) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^ storage.modifier.sql +-- ^^^ support.function.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + RANGE(10) +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^ support.function.sql +-- ^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.section.group.end.sql + LIST() +-- ^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^ support.function.sql +-- ^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^ punctuation.section.group.end.sql + SYSTEM_TIME INTERVAL 10 DAY LIMIT 10 +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^ storage.type.interval.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^ keyword.other.unit.sql +-- ^^^^^ keyword.other.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql + + PARTITIONS 3 +-- ^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^ keyword.other.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + SUBPARTITION BY +-- ^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql +-- ^^^^^^^^^^^^^^^ keyword.other.sql + LINEAR HASH(10 + 20) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql + + LINEAR KEY(col1, col2) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql + SUBPARTITIONS 3 +-- ^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql + + ( +-- ^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^ punctuation.section.sequence.begin.sql + PARTITION partition1 +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.struct.partition.sql + VALUES LESS THAN MAXVALUE +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ constant.language.sql + VALUES LESS THAN (20) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.operator.logical.sql +-- ^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.section.group.end.sql + ENGINE = engine_name +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql + COMMENT = 'comment_text' +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + DATA DIRECTORY = 'data_dir' +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql + INDEX DIRECTORY = 'index_dir' +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^^^^^^^ meta.string.sql string.quoted.single.sql + MAX_ROWS = 20 +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql + MIN_ROWS = 4 +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql + TABLESPACE = tablespace_name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.assignment.sql +-- ^^^^^^^^^^^^^^^ meta.other-name.sql + NODEGROUP = 32 + + ( +-- ^ meta.sequence.partitions.sql - meta.sequence meta.sequence +-- ^^ meta.sequence.partitions.sql meta.sequence.partitions.sql +-- ^ punctuation.section.sequence.begin.sql + subpartition parition1 +-- ^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ entity.name.struct.partition.sql + ENGINE engine_name +-- ^^^^^^ variable.parameter.sql + COMMENT 'comment_text' +-- ^^^^^^^ variable.parameter.sql +-- ^^^^^^^^^^^^^^ string.quoted.single.sql + + , subpartition parition2 +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ entity.name.struct.partition.sql + ), +-- ^^ meta.sequence.partitions.sql meta.sequence.partitions.sql +-- ^ meta.sequence.partitions.sql - meta.sequence meta.sequence +-- ^ punctuation.section.sequence.end.sql +-- ^ punctuation.separator.sequence.sql + + PARTITION partition2 +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ entity.name.struct.partition.sql + VALUES IN ("value1", "value2", "value3") +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^^ meta.string.sql string.quoted.double.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.string.sql string.quoted.double.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.string.sql string.quoted.double.sql +-- ^ punctuation.section.group.end.sql +-- + STORAGE ENGINE = engine_name +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^ variable.parameter.sql +-- ^ keyword.operator.comparison.sql + ) +-- ^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^ punctuation.section.sequence.end.sql + + -- ---------------------------------------------------------------------------- -- Create User Statements -- https://mariadb.com/kb/en/create-user @@ -998,7 +1597,7 @@ ALTER SCHEMA schema_name COMMENT = 'My new database' -- <- meta.statement.alter.sql meta.database.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.database.sql --- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.sql -- ^ keyword.operator.assignment.sql -- ^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql @@ -1133,7 +1732,7 @@ ALTER EVENT event_name COMMENT 'my comment' -- <- meta.statement.alter.sql meta.event.sql -- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.event.sql --- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ variable.parameter.sql -- ^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql DO UPDATE myschema.mytable SET mycol = mycol + 1; @@ -2128,126 +2727,6 @@ SELECT "My -- Crazy Column Name" FROM my_table; SELECT "My /* Crazy Column Name" FROM my_table; -- ^^ - comment - punctuation -CREATE TABLE foo --- <- meta.statement.create.sql keyword.other.ddl --- ^^^^^^^^^^^^^^ meta.statement.create.sql --- ^^^ keyword.other.ddl --- ^ - keyword --- ^^^^^ keyword.other.ddl --- ^ - keyword --- ^^^ entity.name.struct.table.sql - -;CREATE TABLE foo (id INTEGER PRIMARY KEY); --- <- punctuation.terminator.statement.sql - -- <- meta.statement.create keyword.other.ddl ---^^^^^ keyword.other.ddl --- ^^^^^ keyword.other --- ^^^ entity.name.struct --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - entity.name - -create table some_schema.test2( id serial ); ---^^^^ meta.statement.create keyword.other.ddl --- ^^^^^ meta.statement.create keyword.other --- ^^^^^^^^^^^^^^^^^ entity.name.struct --- ^ punctuation.accessor.dot --- ^^^^^^^^^^^^^^ - entity.name - -create table some_schema . test2 ( id serial ); ---^^^^ meta.statement.create keyword.other.ddl --- ^^^^^ meta.statement.create keyword.other --- ^^^^^^^^^^^^^^^^^^^ entity.name --- ^ punctuation.accessor.dot --- ^^^^^^^^^^^^^^^ - entity.name - -create table "testing123" (id integer); ---^^^^ meta.statement.create keyword.other.ddl --- ^^^^^ meta.statement.create keyword.other --- ^ punctuation.definition.identifier.begin --- ^^^^^^^^^^ entity.name.struct --- ^ punctuation.definition.identifier.end - -create table `dbo`."testing123" (id integer); ---^^^^ meta.statement.create keyword.other.ddl --- ^^^^^ meta.statement.create keyword.other --- ^^^^^^^^^^^^^^^^^^ entity.name.struct --- ^ punctuation.accessor.dot --- ^^^^^^^^^^^^^^^ - entity.name - -create table IF NOT EXISTS `testing123` ( --- ^^^^^^^^^^^^^^^^^^^^^^^^ - meta.toc-list --- ^^ keyword.control.conditional.if --- ^^^ keyword.operator.logical --- ^^^^^^ keyword.operator.logical - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, --- ^^^^ meta.column-name --- ^^^^^^^ storage.type --- ^^^^^^^^ storage.modifier --- ^^^ keyword.operator.logical --- ^^^^ constant.language.null --- ^^^^^^^^^^^^^^ keyword.other --- ^ punctuation.separator.sequence - `lastchanged` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, --- ^^^^^^^^^ storage.type.sql --- ^^^^^^^^^^^^^^^^^ support.function.scalar.sql --- ^^^^^^^^^ storage.modifier.sql - `col` bool DEFAULT FALSE, --- ^^^^ storage.type.sql --- ^^^^^^^ storage.modifier.sql --- ^^^^^ constant.language.boolean.sql --- ^ punctuation.separator.sequence - `fkey` INT UNSIGNED NULL REFERENCES test2(id), --- ^^^^^^^^^^ storage.modifier.sql - `version` tinytext DEFAULT NULL COMMENT 'important clarification', --- ^^^^^^^^ storage.type.sql - `percentage` float DEFAULT '0', - UNIQUE KEY `testing123_search` (`col`, `version`), --- ^^^^^^^^^^ storage.modifier.sql - KEY `testing123_col` (`col`), --- ^^^ storage.modifier.sql - FULLTEXT KEY `testing123_version` (`version`) -) ENGINE=MyISAM AUTO_INCREMENT=42 DEFAULT CHARSET=utf8; - -create table fancy_table ( - id SERIAL, --- ^^^^^^ storage.type.sql - foreign_id integer, --- ^^^^^^^ storage.type.sql - myflag boolean DEFAULT false, --- ^^^^^^^ storage.type.sql - mycount double precision DEFAULT 1, --- ^^^^^^^^^^^^^^^^^ storage.type.sql - fancy_column character varying(42) DEFAULT 'nice'::character varying, --- ^^^^^^^^^^^^^^^^^^^^^^ storage.type.sql - mytime timestamp(3) without time zone DEFAULT now(), --- ^^^^^^^^^^^^ storage.type.sql --- ^ constant.numeric --- ^^^^^^^^^^^^^^^^^ storage.type.sql --- ^^^^^^^ storage.modifier --- ^^^ meta.function-call support.function --- ^ punctuation.section.arguments.begin --- ^ punctuation.section.arguments.end --- ^ punctuation.separator.sequence - mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, -- TODO: seems like :: is a postgresql cast operator --- ^^^^^^^^^^^^^^^^^^^ storage.type.sql - some_number numeric(5, 2) DEFAULT 0, --- ^^^^^^^^^^^ meta.column-name --- ^^^^^^^^^^^^^ storage.type --- ^ constant.numeric --- ^ punctuation.separator.sequence --- ^ constant.numeric --- ^^^^^^^ storage.modifier --- ^ meta.number.integer.decimal constant.numeric.value - primary key (id), --- ^^^^^^^^^^^ storage.modifier.sql - UNIQUE (foreign_id), - CONSTRAINT fancy_table_valid1 CHECK (id <> foreign_id) --- ^^^^^^^^^^ storage.modifier.sql --- ^^^^^ keyword.other --- ^^^^^^^^^^^^^^^^^^ meta.group meta.group --- ^^ meta.column-name --- ^^ keyword.operator.comparison --- ^^^^^^^^^^ meta.column-name -); ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; -- <- meta.statement.alter.sql keyword.other.ddl From dab0197a971e0a64552f6127dfdc4b0218616fba Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 30 Jul 2023 21:12:38 +0300 Subject: [PATCH 186/250] [SQL] PHP fixes --- .../SQL (for PHP Interpolated).sublime-syntax | 7 ++--- PHP/tests/syntax_test_php.php | 28 +++++++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax b/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax index d049b45b4a..d8ace3203c 100644 --- a/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax +++ b/PHP/Embeddings/SQL (for PHP Interpolated).sublime-syntax @@ -24,12 +24,11 @@ contexts: inside-like-single-quoted-string: - meta_prepend: true - - include: Packages/PHP/PHP Source.sublime-syntax#string-interpolations + - include: string-interpolation - string-escape: - # this context is included in anonymous string contexts + inside-single-quoted-string: - meta_prepend: true - - include: Packages/PHP/PHP Source.sublime-syntax#string-interpolations + - include: string-interpolation string-interpolation: # this context is included in anonymous string contexts diff --git a/PHP/tests/syntax_test_php.php b/PHP/tests/syntax_test_php.php index b57d7cab2b..3dfab36a18 100644 --- a/PHP/tests/syntax_test_php.php +++ b/PHP/tests/syntax_test_php.php @@ -5107,12 +5107,36 @@ function testTypeCasts() // ^^^^^^ meta.interpolation.php variable.other.php // ^ punctuation.definition.identifier.end.sql -$sql = "SELECT " . $col . "FROM $table WHERE ( first_$name =" . $name . ")" ; . "GROUP BY" ; $sql = "SELECT * FROM users where first_name = $user_name"; // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php - meta.interpolation -// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string +// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string.quoted.double // ^ meta.string.php - meta.interpolation +$sql = "SELECT * FROM users where first_name = '$user_name'"; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php - meta.interpolation +// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string.quoted +// ^ meta.string.php - meta.interpolation + +$sql = "SELECT * FROM users where first_name = `$user_name`"; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php - meta.interpolation +// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string +// ^ meta.string.php - meta.interpolation + +$sql = "SELECT * FROM users where first_name = %r{^$user_name}"; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php - meta.interpolation +// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string +// ^^ meta.string.php - meta.interpolation + +$sql = "SELECT * FROM users where first_name LIKE $user_name"; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php - meta.interpolation +// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string +// ^ meta.string.php - meta.interpolation + +$sql = "SELECT * FROM users where first_name LIKE '$user_name'"; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.php - meta.interpolation +// ^^^^^^^^^^ meta.string.php meta.interpolation.php variable.other.php - string +// ^ meta.string.php - meta.interpolation + $sql = "SELECT " . $col . "FROM $table WHERE ( first_name =" . $name . ")" ; . "GROUP BY" ; // ^ meta.string.php - meta.interpolation // ^^^^^^^ meta.string.php source.sql.embedded.php From 9b67bd8190ebce10607c1f16c508f7d08547df82 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 2 May 2023 22:00:40 +0300 Subject: [PATCH 187/250] [SQL] more improvements - regarding users and permissions/roles - fix bug with declaring multiple variables in one statement in TSQL - support for double colon accessor in TSQL - support for object oriented function calls in TSQL - fix scoping of `MAX` as a size parameter to a variable length data type - support unquoted strings and generic identifiers as `WITH` values in TSQL - scope "datepart" units in TSQL --- SQL/MySQL.sublime-syntax | 5 + SQL/PostgreSQL.sublime-syntax | 1 + SQL/SQL (basic).sublime-syntax | 36 ++++- SQL/TSQL.sublime-syntax | 120 ++++++++++++++-- SQL/tests/syntax/syntax_test_tsql.sql | 190 ++++++++++++++++++++++++++ 5 files changed, 343 insertions(+), 9 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 0b66f1cf1e..68bb9c22df 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -199,6 +199,11 @@ contexts: - meta_scope: meta.user.sql - include: user-options + create-other-args: + - meta_prepend: true + - match: (?=\() + push: column-declaration-list + ###[ DDL DROP STATEMENTS ]##################################################### drop-target: diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 42e35a7c26..f9e6eddbdd 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -94,6 +94,7 @@ contexts: - meta_prepend: true - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b scope: keyword.other.psql + push: maybe-on-table - match: \b(?i:for\s+each\s+row\s+execute\s+procedure)\b scope: keyword.other.psql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index d5aaa48bf4..a7a9c2859a 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -26,7 +26,7 @@ variables: (?xi: procedure | function ) ddl_target_other: |- (?xi: aggregate | constraint | conversion | database | domain | group - | language | operator\s+class | operator | rule | schema | sequence + | language | member | operator\s+class | operator | role | rule | schema | sequence | tablespace | trigger | type | user | view ) ddl_target_function_modifier: |- @@ -195,6 +195,7 @@ contexts: - match: \b(?i:as)\b scope: keyword.context.block.sql pop: 1 + - include: grant - include: on-tables - include: create-common-args @@ -276,6 +277,12 @@ contexts: - include: immediately-pop drop-other: + - match: \b(?i:user)\b(?!\s+(?i:if)\b) + scope: storage.type.sql + set: + - grant + - user-name + - single-identifier - match: \b{{ddl_target_other}}\b scope: keyword.other.ddl.sql set: @@ -492,6 +499,7 @@ contexts: other-statements: - match: \b(?i:grant(?:\s+with\s+grant\s+option)?|revoke)\b scope: keyword.other.authorization.sql + push: grant ###[ EXPRESSIONS ]############################################################# @@ -1276,6 +1284,32 @@ contexts: - match: ';' scope: punctuation.terminator.statement.sql +###[ USERS AND PERMISSIONS ]################################################### + + grant: + - match: \b(?i:showplan)\b + scope: constant.language.sql + - match: \b(?i:create\s*{{ddl_target}})\b + scope: constant.language.sql + - match: \b(?i:to)\b + scope: keyword.context.sql + push: + - user-name + - single-identifier + - include: pop-on-top-level-reserved-word + + user-name: + - meta_content_scope: meta.username.sql + - match: '' + pop: true + + expect-user-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [user-name, single-identifier] + ###[ PROTOTYPES ]############################################################## else-pop: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 9132848072..9983e21dcb 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -58,7 +58,9 @@ contexts: scope: variable.other.readwrite.declaration.tsql captures: 1: punctuation.definition.variable.tsql - set: expect-type + push: expect-type + - match: ',' + scope: punctuation.separator.sequence.tsql - include: else-pop ###[ DDL CREATE STATEMENTS ]################################################### @@ -82,6 +84,16 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ + alter-common: + - meta_prepend: true + - include: with-options + - match: \b(?i:(add)\s+(member))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + push: + - expect-user-name + target-options: - meta_prepend: true - include: with-table-options @@ -234,6 +246,8 @@ contexts: push: [maybe-table-alias, maybe-group] - match: \b(?i:for)\b scope: keyword.other.tsql + - match: \b\w+(?=::) + scope: storage.type.tsql - match: \b(\w+)(:) captures: 1: entity.name.label.tsql @@ -299,6 +313,8 @@ contexts: scope: storage.modifier.output.tsql - match: \b(?i:over|partition\s+by)\b scope: keyword.other.sql + - match: \b(?i:unbounded|preceding|following|current\s+row|(?:rows|range)\s+between)\b + scope: keyword.other.sql - match: \b(?i:cursor)\b scope: support.type.tsql push: inside-cursor-declaration @@ -307,6 +323,8 @@ contexts: push: merge-condition - match: \b(?i:include)\b scope: keyword.other.sql + - match: \b(?i:within\s+group)\b + scope: keyword.other.tsql built-in-scalar-function-calls: - meta_append: true @@ -353,6 +371,10 @@ contexts: scope: punctuation.separator.arguments.sql - include: expressions-or-column-names + inside-function-call-arguments: + - meta_prepend: true + - include: datepart-units + user-defined-function-calls: - meta_append: true - match: (?={{identifier_for_lookahead}}\s*\() @@ -479,12 +501,22 @@ contexts: 1: keyword.other.tsql 2: keyword.operator.assignment.tsql push: expect-table-name + - include: with-simple-options + + with-options: + - match: \b(?i:with)\b + scope: keyword.other.dml.sql + set: with-simple-options + + with-simple-options: - match: '{{simple_identifier}}' scope: constant.language.with.tsql - match: '=' scope: keyword.operator.assignment.tsql push: with-other-assignment - include: comma-separators + - match: (?=;) + pop: true maybe-filegroup: - match: \b(?i:on)\b(?!\s*{{identifier_for_lookahead}}\s*=) @@ -521,6 +553,18 @@ contexts: pop: 1 - include: onoff-constants - include: expressions + - match: (?=") + set: + - generic-identifier-name + - single-identifier + - match: \w+ + scope: string.unquoted.tsql + + generic-identifier-name: + - meta_include_prototype: false + - meta_content_scope: string.quoted.tsql + - include: immediately-pop + ###[ LIKE EXPRESSIONS ]######################################################## @@ -758,14 +802,8 @@ contexts: {{enclosed_type_begin}} {{types_with_optional_number}} {{enclosed_type_end}} - (?:\s*\(\s*(?:(\d+)|(max))\s*(?:(,)\s*(\d+))?\))? scope: storage.type.sql - captures: - 1: constant.numeric.sql - 2: constant.language.max.sql - 3: punctuation.separator.sequence.sql - 4: constant.numeric.sql - pop: 1 + set: optional-number-after-type - match: |- (?xi) (?:{{enclosed_type_begin}}|\b) @@ -773,6 +811,31 @@ contexts: (?:{{enclosed_type_end}}|\b) scope: storage.type.sql pop: 1 + - match: |- + (?xi) + {{types_with_optional_number}} + scope: storage.type.sql + set: optional-number-after-type + + optional-number-after-type: + - match: |- + (?x) + \s* + (\()\s* + (?i:(\d+)|(max)) + \s*(?:(,)\s*(\d+))? + (\)) + scope: storage.type.sql + captures: + 1: punctuation.section.group.begin.tsql + 2: constant.numeric.sql + 3: constant.language.max.sql + 4: punctuation.separator.sequence.sql + 5: constant.numeric.sql + 6: punctuation.section.group.end.tsql + pop: true + - match: (?=\S) + pop: true inside-user-type: - meta_prepend: true @@ -898,6 +961,7 @@ contexts: scope: variable.other.readwrite.sql captures: 1: punctuation.definition.variable.sql + push: maybe-variable-scoped-function-call - match: |- (?xi)(@@) (?: cursor_rows | connections | cpu_busy | datefirst | dbts | error @@ -910,13 +974,53 @@ contexts: captures: 1: punctuation.definition.variable.sql + maybe-variable-scoped-function-call: + - match: \s*\.(?=\s*\w+\s*\() + scope: punctuation.accessor.dot.tsql + - include: immediately-pop + + datepart-units: + # https://learn.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql?view=sql-server-ver16 + - match: \b(?i:DAY|MONTH|YEAR|QUARTER|DAYOFYEAR|WEEK|HOUR|MINUTE|SECOND|MILLISECOND|MICROSECOND|NANOSECOND)\b(?!\s*\.) + scope: constant.language.tsql + - match: \b(?i:D?D|YYYY|YY?|Q?Q|M?M|DY|WK|WW|HH|MI|N|SS?|MS|MCS|NS)\b(?!\s*\.) + scope: constant.language.tsql + ###[ OPERATORS ]############################################################### operators: - meta_append: true - match: '%' scope: keyword.operator.arithmetic.tsql + - match: '::' + scope: punctuation.accessor.double-colon.tsql augmented-assignment-operators: - match: '[-+/*%^|]=' scope: keyword.operator.assignment.tsql + +###[ USERS AND PERMISSIONS ]################################################### + + grant: + - meta_prepend: true + - match: \b(?i:from\s+external\s+provider)\b + scope: constant.language.tsql + - include: with-options + - match: \b(?i:control)\b + scope: constant.language.tsql + - match: \b(?i:on)\b + scope: keyword.context.resource.tsql + push: qualified-identifier + + qualified-identifier: + - match: \b(?i:(database))(::) + captures: + 1: storage.type.tsql + 2: punctuation.accessor.double-colon.tsql + set: + - database-name + - single-identifier + - match: (?=\S) + set: + - generic-identifier-name + - single-identifier diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index b9bad3c8cc..b48b5189b6 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -718,6 +718,7 @@ END select A.A , CASE WHEN B.B IS NOT NULL THEN B.B ELSE DATEADD(d, 1 - DATEPART(d, GETDATE()), DATEADD(m, B.MonthsInFuture, DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0))) END AS FirstDayOfFutureMonth + -- ^ constant.language.tsql -- ^ punctuation.separator.sequence -- ^^^^ keyword.control.conditional.case , B.* @@ -1705,7 +1706,9 @@ SELECT a.* -- ^ meta.table-alias-name DECLARE @Data NVARCHAR(MAX) +-- ^^^^^^^^^^^^^ storage.type.sql -- ^ punctuation.section.group.begin +-- ^^^ constant.language.max.sql -- ^ punctuation.section.group.end SELECT @Data = ( SELECT [CustomerID] as "@CustomerID", @@ -2036,3 +2039,190 @@ END -- ^^^^^^^^^^^^ support.function.scalar.sql -- ^^^^^^^^^^^ support.function.scalar.sql -- ^^^^ support.function.scalar.sql + +GRANT CREATE TABLE TO MelanieK; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^ constant.language.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +GRANT SHOWPLAN TO AuditMonitor; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^ constant.language.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + +GRANT CREATE VIEW TO CarmineEs WITH GRANT OPTION; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^ constant.language.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^ meta.username.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^ constant.language.with.tsql +-- ^^^^^^ constant.language.with.tsql + +GRANT CONTROL ON DATABASE::AdventureWorks2012 TO Sarah; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^ constant.language.tsql +-- ^^ keyword.context.resource.tsql +-- ^^^^^^^^ storage.type.tsql +-- ^^ punctuation.accessor.double-colon.tsql +-- ^^^^^^^^^^^^^^^^^^ meta.database-name.sql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql + +ALTER ROLE buyers WITH NAME = purchasing; +--^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^^^^^^^^^^ string.unquoted.tsql +-- ^ punctuation.terminator.statement.sql + +ALTER ROLE Sales ADD MEMBER Barry; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^ meta.other-name.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql +ALTER ROLE Sales DROP MEMBER Barry; +--^^^^^^^^^^^^^^^ meta.statement.alter.sql +--^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ meta.other-name.sql +-- ^ punctuation.terminator.statement.sql + +CREATE USER "some-name-here" FROM external provider with OBJECT_ID="ba5615a6-f2ca-4517-97d1-36fc8a595fc9"; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ entity.name +-- ^^^^^^^^^^^^^^^^^^^^^^ constant.language.tsql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.tsql +ALTER ROLE "db_datareader" ADD MEMBER "some-name-here"; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.other-name.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql +ALTER USER [yourUser] WITH DEFAULT_SCHEMA = myschema; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.other-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^^^^^^^^ string.unquoted.tsql +-- ^ punctuation.terminator.statement.sql + +create user user_name_in_sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ entity.name + with sid = 0x67453e129be8d312a456426614174000, +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.dml.sql +-- ^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.number.integer.hexadecimal.tsql +-- ^ punctuation.separator.sequence.sql + type = E; +--^^^^^^^^ meta.statement.create.sql +-- ^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^ string.unquoted.tsql +-- ^ punctuation.terminator.statement.sql + +DROP USER IF EXISTS "some-name-here"; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^ keyword.other.ddl.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.terminator.statement.sql + +-- https://stackoverflow.com/a/14860368/4473405 +SELECT a, + b, + COUNT(*) OVER (ORDER BY a + ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS [Rows], +-- ^^^^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^^ keyword.other.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^ keyword.other.sql + COUNT(*) OVER (ORDER BY a + RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS [Range], +-- ^^^^^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^^ keyword.other.sql +-- ^^^^^^^^^ keyword.other.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^ keyword.other.sql + COUNT(*) OVER() AS [Over()] + FROM t; + +SELECT STRING_AGG (CONVERT(NVARCHAR(max),FirstName), CHAR(13)) AS csv +-- ^^^^^^^^ storage.type.sql +-- ^ +-- ^^^ constant.language.max.sql +FROM Person.Person; + +SELECT STRING_AGG(CONVERT(NVARCHAR(max), ISNULL(FirstName,'N/A')), ',') AS csv +FROM Person.Person; + +SELECT TOP 10 City, STRING_AGG(CONVERT(NVARCHAR(max), EmailAddress), ';') WITHIN GROUP (ORDER BY EmailAddress ASC) AS Emails +-- ^^^^^^^^^^^^ keyword.other.tsql +-- ^ meta.group.sql punctuation.section.group.begin.sql +-- ^^^^^^^^ meta.group.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^ meta.group.sql meta.column-name.sql +-- ^^^ meta.group.sql keyword.other.order.sql +-- ^ meta.group.sql punctuation.section.group.end.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^ meta.column-alias.sql +FROM Person.BusinessEntityAddress AS BEA +INNER JOIN Person.Address AS A ON BEA.AddressID = A.AddressID +INNER JOIN Person.EmailAddress AS EA ON BEA.BusinessEntityID = EA.BusinessEntityID +GROUP BY City; + +DECLARE @g geography; +SET @g = geography::Point(47.65100, -122.34900, 4326) +-- ^^^^^^^^^ storage.type.tsql +-- ^^ punctuation.accessor.double-colon.tsql +-- ^^^^^ meta.function-call.sql support.function.sql +SELECT @g.ToString(); +-- ^^^ keyword.other.dml.sql +-- ^ variable.other.readwrite.sql punctuation.definition.variable.sql +-- ^ variable.other.readwrite.sql +-- ^ punctuation.accessor.dot.tsql +-- ^^^^^^^^ meta.function-call.sql support.function.sql +-- ^ meta.function-call.sql meta.group.sql punctuation.section.arguments.begin.sql +-- ^ meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql +-- ^ punctuation.terminator.statement.sql + +DECLARE @FromTimeUTC DATETIME2, @ToTimeUTC DATETIME2 +-- ^^^^ keyword.declaration.variable.sql +-- ^^^^^^^^^^^^ variable.other.readwrite.declaration.tsql +-- ^^^^^^^^^ storage.type.sql +-- ^ punctuation.separator.sequence.tsql +-- ^^^^^^^^^^ variable.other.readwrite.declaration.tsql +-- ^^^^^^^^^ storage.type.sql From ebca6753a5110779022f3f2002bbc6c5055e7de0 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 31 Jul 2023 12:38:17 +0300 Subject: [PATCH 188/250] [SQL] support GRANT UPDATE permission TO user --- SQL/SQL (basic).sublime-syntax | 6 +++++- SQL/tests/syntax/syntax_test_tsql.sql | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index a7a9c2859a..7d45b7fc2a 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -1289,7 +1289,9 @@ contexts: grant: - match: \b(?i:showplan)\b scope: constant.language.sql - - match: \b(?i:create\s*{{ddl_target}})\b + - match: \b(?i:(?:create|drop)\s*{{ddl_target}})\b + scope: constant.language.sql + - match: \b(?i:update|delete)\b scope: constant.language.sql - match: \b(?i:to)\b scope: keyword.context.sql @@ -1297,6 +1299,8 @@ contexts: - user-name - single-identifier - include: pop-on-top-level-reserved-word + - match: (?=\() + push: column-reference-list user-name: - meta_content_scope: meta.username.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index b48b5189b6..57d16eb919 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2073,6 +2073,23 @@ GRANT CONTROL ON DATABASE::AdventureWorks2012 TO Sarah; -- ^^ keyword.context.sql -- ^^^^^ meta.username.sql +GRANT UPDATE ON dbo.some_table (some_id, [some_field]) TO Sarah; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^ constant.language.sql +-- ^^ keyword.context.resource.tsql +-- ^^^^^^^^^^^^^^ string.quoted.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^ meta.column-name.sql +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql +-- ^ punctuation.section.group.end.sql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + ALTER ROLE buyers WITH NAME = purchasing; --^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql From b26f93d3c8d4c52d28971087e13df4ede9982557 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 31 Jul 2023 12:41:43 +0300 Subject: [PATCH 189/250] [SQL] support clustered index creation --- SQL/SQL (basic).sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_tsql.sql | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 7d45b7fc2a..bd27a7110d 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -32,7 +32,7 @@ variables: ddl_target_function_modifier: |- (?xi: aggregate ) ddl_target_index_modifier: |- - (?xi: fulltext | spatial | unique ) + (?xi: clustered | fulltext | spatial | unique ) ddl_target_table_modifier: |- (?xi: temp(?:orary)? ) diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 57d16eb919..e6f3c40e14 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2243,3 +2243,20 @@ DECLARE @FromTimeUTC DATETIME2, @ToTimeUTC DATETIME2 -- ^ punctuation.separator.sequence.tsql -- ^^^^^^^^^^ variable.other.readwrite.declaration.tsql -- ^^^^^^^^^ storage.type.sql + +CREATE CLUSTERED INDEX ix_some_table_some_field_another_field ON dbo.some_table (some_field, another_field); +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^ punctuation.terminator.statement.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ meta.index.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.index.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.struct.index.sql +-- ^^ keyword.other.sql +-- ^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql From 33c5a061577c09a3922a6d67601a32ef22ec3e81 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 31 Jul 2023 13:05:33 +0300 Subject: [PATCH 190/250] [SQL] support GRANT SELECT permission ON schema TO user --- SQL/SQL (basic).sublime-syntax | 2 +- SQL/TSQL.sublime-syntax | 8 ++++++++ SQL/tests/syntax/syntax_test_tsql.sql | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index bd27a7110d..a81dd48681 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -1291,7 +1291,7 @@ contexts: scope: constant.language.sql - match: \b(?i:(?:create|drop)\s*{{ddl_target}})\b scope: constant.language.sql - - match: \b(?i:update|delete)\b + - match: \b(?i:select|update|delete)\b scope: constant.language.sql - match: \b(?i:to)\b scope: keyword.context.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 9983e21dcb..1a94742670 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -1022,5 +1022,13 @@ contexts: - single-identifier - match: (?=\S) set: + - maybe-double-colon-accessor - generic-identifier-name - single-identifier + + maybe-double-colon-accessor: + - match: '::' + scope: punctuation.accessor.double-colon.tsql + set: qualified-identifier + - match: (?=\S) + pop: true diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index e6f3c40e14..f46b1a863e 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2090,6 +2090,17 @@ GRANT UPDATE ON dbo.some_table (some_id, [some_field]) TO Sarah; -- ^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql +GRANT SELECT ON schema::some_schema TO Sarah; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^ constant.language.sql +-- ^^ keyword.context.resource.tsql +-- ^^^^^^ string.quoted.tsql +-- ^^ punctuation.accessor.double-colon.tsql +-- ^^^^^^^^^^^ string.quoted.tsql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + ALTER ROLE buyers WITH NAME = purchasing; --^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql From 1fef6f98aa69cdfbffb06188bc4047ca9e034eeb Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 31 Jul 2023 13:25:41 +0300 Subject: [PATCH 191/250] [SQL] fix Golang SQL embedding --- .../SQL (for Go Embedded Backtick Strings).sublime-syntax | 2 +- Go/tests/syntax_test_go.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Go/Embeddings/SQL (for Go Embedded Backtick Strings).sublime-syntax b/Go/Embeddings/SQL (for Go Embedded Backtick Strings).sublime-syntax index e128b0cd6a..00e4668473 100644 --- a/Go/Embeddings/SQL (for Go Embedded Backtick Strings).sublime-syntax +++ b/Go/Embeddings/SQL (for Go Embedded Backtick Strings).sublime-syntax @@ -2,7 +2,7 @@ --- name: SQL inside Go backtick string scope: source.sql.go-embedded-backtick-string -version: 1 +version: 2 hidden: true extends: Packages/SQL/SQL.sublime-syntax diff --git a/Go/tests/syntax_test_go.go b/Go/tests/syntax_test_go.go index 63711cde55..9dc2db5fb3 100644 --- a/Go/tests/syntax_test_go.go +++ b/Go/tests/syntax_test_go.go @@ -5759,7 +5759,7 @@ func lang_embedding() { // ^ meta.string.go string.quoted.backtick.go punctuation.definition.string.begin.go // ^ meta.string.go meta.embedded.go source.sql.embedded.go update schema.table - // ^^^^^^ meta.string.go meta.embedded.go source.sql.embedded.go keyword.other.DML.sql + // ^^^^^^ meta.string.go meta.embedded.go source.sql.embedded.go keyword.other.dml.sql set some_field = null where From 990b1668be2f4ada80c5a9ab778f1bf2256957d5 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 31 Jul 2023 13:34:03 +0300 Subject: [PATCH 192/250] [SQL] support GRANT INSERT permissions --- SQL/SQL (basic).sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_tsql.sql | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index a81dd48681..2775af5db4 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -1291,7 +1291,7 @@ contexts: scope: constant.language.sql - match: \b(?i:(?:create|drop)\s*{{ddl_target}})\b scope: constant.language.sql - - match: \b(?i:select|update|delete)\b + - match: \b(?i:select|insert|update|delete)\b scope: constant.language.sql - match: \b(?i:to)\b scope: keyword.context.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index f46b1a863e..a408ab368c 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2073,6 +2073,15 @@ GRANT CONTROL ON DATABASE::AdventureWorks2012 TO Sarah; -- ^^ keyword.context.sql -- ^^^^^ meta.username.sql +GRANT INSERT ON dbo.some_table TO Sarah; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^ constant.language.sql +-- ^^ keyword.context.resource.tsql +-- ^^^^^^^^^^^^^^ string.quoted.tsql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + GRANT UPDATE ON dbo.some_table (some_id, [some_field]) TO Sarah; -- ^^ keyword.other.authorization.sql -- ^^^^^^ constant.language.sql From 733265f4b6adcc6970f1a91dbe1e04e6a0d6c473 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 4 Aug 2023 21:33:07 +0300 Subject: [PATCH 193/250] [SQL] manually make the wildcard scope adjustments after merge from master --- SQL/MySQL.sublime-syntax | 12 ++++++------ SQL/SQL (basic).sublime-syntax | 4 ++-- SQL/tests/syntax/syntax_test_cassandra.cql | 4 ++-- SQL/tests/syntax/syntax_test_mysql.sql | 22 +++++++++++----------- SQL/tests/syntax/syntax_test_tsql.sql | 10 +++++----- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 68bb9c22df..a38fc11587 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -1020,9 +1020,9 @@ contexts: - match: (\*)(?:(\.)(\*))? scope: meta.other-name.sql captures: - 1: variable.language.wildcard.asterisk.sql + 1: constant.other.wildcard.asterisk.sql 2: punctuation.accessor.dot.sql - 3: variable.language.wildcard.asterisk.sql + 3: constant.other.wildcard.asterisk.sql pop: 1 # named privilidge level: database, table or method - include: expect-other-name @@ -1098,24 +1098,24 @@ contexts: identifier-host-part: - meta_include_prototype: false - match: \% - scope: variable.language.wildcard.percent.sql + scope: constant.other.wildcard.percent.sql pop: 1 - match: (')(%)(') captures: 1: punctuation.definition.identifier.begin.sql - 2: variable.language.wildcard.percent.sql + 2: constant.other.wildcard.percent.sql 3: punctuation.definition.identifier.end.sql pop: 1 - match: (")(%)(") captures: 1: punctuation.definition.identifier.begin.sql - 2: variable.language.wildcard.percent.sql + 2: constant.other.wildcard.percent.sql 3: punctuation.definition.identifier.end.sql pop: 1 - match: (`)(%)(`) captures: 1: punctuation.definition.identifier.begin.sql - 2: variable.language.wildcard.percent.sql + 2: constant.other.wildcard.percent.sql 3: punctuation.definition.identifier.end.sql pop: 1 - include: identifier-part diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 2775af5db4..fd108b30e4 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -1136,7 +1136,7 @@ contexts: - match: \s*(\.)\s*(\*) captures: 1: punctuation.accessor.dot.sql - 2: variable.language.wildcard.asterisk.sql + 2: constant.other.wildcard.asterisk.sql pop: 1 - match: \s*(\.) captures: @@ -1195,7 +1195,7 @@ contexts: wildcard-identifiers: - match: \* - scope: variable.language.wildcard.asterisk.sql + scope: constant.other.wildcard.asterisk.sql ###[ LITERALS ]################################################################ diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 69baed4789..2fa6a56779 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -231,7 +231,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS foo_by_bar AS -- ^^ keyword.context.block SELECT * -- ^^^^^^ keyword.other.dml --- ^ variable.language.wildcard.asterisk +-- ^ constant.other.wildcard.asterisk FROM foo WHERE bar IS NOT NULL PRIMARY KEY (foo_id, bar_id) @@ -377,7 +377,7 @@ select uuid(), now(), * -- ^ punctuation.separator.sequence -- ^^^ meta.function-call support.function -- ^ punctuation.separator.sequence --- ^ variable.language.wildcard.asterisk +-- ^ constant.other.wildcard.asterisk from test_by_example; COPY table1 (column1, column2, column3) FROM 'table1data.csv' diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 68900339fb..4d23ca07f6 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -1380,7 +1380,7 @@ CREATE USER IF NOT EXISTS -- ^ punctuation.definition.identifier.end.sql -- ^ punctuation.accessor.at.sql -- ^ punctuation.definition.identifier.begin.sql --- ^ variable.language.wildcard.percent.sql +-- ^ constant.other.wildcard.percent.sql -- ^ punctuation.definition.identifier.end.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql @@ -2229,16 +2229,16 @@ GRANT ALTER COLUMN ON * -- <- meta.statement.grant.sql keyword.other.ddl.sql -- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql -- ^^ keyword.other.ddl.sql --- ^ meta.other-name.sql variable.language.wildcard.asterisk.sql +-- ^ meta.other-name.sql constant.other.wildcard.asterisk.sql GRANT ALTER TABLE ON *.* -- <- meta.statement.grant.sql keyword.other.ddl.sql -- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql -- ^^ keyword.other.ddl.sql -- ^^^ meta.other-name.sql --- ^ variable.language.wildcard.asterisk.sql +-- ^ constant.other.wildcard.asterisk.sql -- ^ punctuation.accessor.dot.sql --- ^ variable.language.wildcard.asterisk.sql +-- ^ constant.other.wildcard.asterisk.sql GRANT ALTER INDEX ON db_name.* -- <- meta.statement.grant.sql keyword.other.ddl.sql @@ -2246,7 +2246,7 @@ GRANT ALTER INDEX ON db_name.* -- ^^ keyword.other.ddl.sql -- ^^^^^^^^^ meta.other-name.sql -- ^ punctuation.accessor.dot.sql --- ^ variable.language.wildcard.asterisk.sql +-- ^ constant.other.wildcard.asterisk.sql GRANT ALTER COLUMN ON db_name.table_name -- <- meta.statement.grant.sql keyword.other.ddl.sql @@ -2267,11 +2267,11 @@ GRANT CREATE INDEX ON TABLE * TO user1@% IDENTIFIED BY 'password' ; -- ^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql -- ^^^^^ storage.type.sql --- ^ meta.other-name.sql variable.language.wildcard.asterisk.sql +-- ^ meta.other-name.sql constant.other.wildcard.asterisk.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^ meta.user-name.sql -- ^ punctuation.accessor.at.sql --- ^ variable.language.wildcard.percent.sql +-- ^ constant.other.wildcard.percent.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql @@ -2458,9 +2458,9 @@ REVOKE SUPER ON *.* FROM 'alexander'@'localhost'; -- ^^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql -- ^^^ meta.other-name.sql --- ^ variable.language.wildcard.asterisk.sql +-- ^ constant.other.wildcard.asterisk.sql -- ^ punctuation.accessor.dot.sql --- ^ variable.language.wildcard.asterisk.sql +-- ^ constant.other.wildcard.asterisk.sql -- ^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.user-name.sql -- ^ punctuation.terminator.statement.sql @@ -2560,7 +2560,7 @@ SET PASSWORD for `user@`@'%' = 'encrypted password'; -- ^ punctuation.definition.identifier.end.sql -- ^ punctuation.accessor.at.sql -- ^ punctuation.definition.identifier.begin.sql --- ^ variable.language.wildcard.percent.sql +-- ^ constant.other.wildcard.percent.sql -- ^ punctuation.definition.identifier.end.sql -- ^ keyword.operator.assignment.sql -- ^^^^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql @@ -2799,7 +2799,7 @@ select SELECT *, -- ^^^ keyword.other.dml.sql --- ^ variable.language.wildcard.asterisk.sql +-- ^ constant.other.wildcard.asterisk.sql f.id AS database_id -- ^^ keyword.operator.assignment.alias.sql -- ^^^^^^^^^^^ meta.column-alias diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index a408ab368c..f6679834a4 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -430,7 +430,7 @@ SELECT foo AS foobar, COUNT(*) AS tally -- ^^^^^ support.function.aggregate -- ^^^ meta.group -- ^ punctuation.section.arguments.begin --- ^ variable.language.wildcard.asterisk +-- ^ constant.other.wildcard.asterisk -- ^ punctuation.section.arguments.end -- ^^ keyword.operator.assignment.alias -- ^^^^^ meta.column-alias @@ -447,7 +447,7 @@ from (select * from some_table) alias_table WITH (NOLOCK) -- ^ keyword.other.dml -- ^ punctuation.section.group.begin -- ^^^^^^ keyword.other.dml --- ^ variable.language.wildcard.asterisk +-- ^ constant.other.wildcard.asterisk -- ^^^^^^^^^^ meta.table-name -- ^ punctuation.section.group.end -- ^^^^^^^^^^^ meta.table-alias-name @@ -683,7 +683,7 @@ BEGIN -- ^ meta.group variable.other.readwrite punctuation.definition.variable -- ^^^^^ meta.group variable.other.readwrite -- ^ meta.group punctuation.section.group.end --- ^ variable.language.wildcard.asterisk +-- ^ constant.other.wildcard.asterisk -- ^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^ punctuation.definition.identifier.begin @@ -725,7 +725,7 @@ select A.A -- ^ punctuation.separator.sequence -- ^^ meta.column-name -- ^ punctuation.accessor.dot --- ^ variable.language.wildcard.asterisk +-- ^ constant.other.wildcard.asterisk into #temp -- ^ keyword.other.dml -- ^^^^^ meta.table-name @@ -828,7 +828,7 @@ WITH cte_table AS ( SELECT blah ) SELECT cte_table.* FROM cte_table -- ^^^ keyword.other.dml -- ^^^^^^^^^^ meta.column-name --- ^ variable.language.wildcard.asterisk +-- ^ constant.other.wildcard.asterisk -- ^^^^ keyword.other.dml -- ^^^^^^^^^ meta.table-name From d67c7183fbc69effa253a84a240679141e65a4b6 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 4 Aug 2023 21:38:36 +0300 Subject: [PATCH 194/250] [SQL] more manual wildcard scope adjustments --- SQL/TSQL.sublime-syntax | 6 ++-- SQL/tests/syntax/syntax_test_tsql.sql | 40 +++++++++++++-------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 1a94742670..aa611ea810 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -645,8 +645,10 @@ contexts: 2: keyword.control.set.negation.sql 3: constant.other.range.sql 4: keyword.control.set.end.sql - - match: '[%_]' - scope: keyword.operator.wildcard.sql + - match: '%' + scope: constant.other.wildcard.percent.sql + - match: '_' + scope: constant.other.wildcard.underscore.sql like-else-fail: - match: (?=\S) diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index f6679834a4..cbb1e25c89 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -9,12 +9,12 @@ SELECT columns FROM table WHERE -- ^^^^ keyword.operator.logical -- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.like string.quoted.single -- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^^^ meta.set.like -- ^ keyword.control.set.begin -- ^ keyword.control.set.end -- ^^^^^^^^^^^^^^^^^^ - constant - keyword --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^ punctuation.definition.string.end -- ^^ - meta.string - string @@ -23,12 +23,12 @@ SELECT columns FROM table WHERE -- ^^^^ keyword.operator.logical -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.string.like string.quoted.single -- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^^^^^^^^^^^^^^^^^^^ meta.set.like -- ^ keyword.control.set.begin -- ^ keyword.control.set.end -- ^^^^^^^^^^^^^^^ - constant - keyword --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^ punctuation.definition.string.end -- ^^ - meta.string - string @@ -37,13 +37,13 @@ SELECT columns FROM table WHERE -- ^^^^ keyword.operator.logical -- ^^^^^^^^^^ meta.string.like string.quoted.single -- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^^^^^^ meta.set.like -- ^ keyword.control.set.begin -- ^ keyword.control.set.negation -- ^ constant.other.range -- ^ keyword.control.set.end --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^ punctuation.definition.string.end -- ^^ - meta.string - string @@ -52,19 +52,19 @@ SELECT columns FROM table WHERE -- ^^^^ keyword.operator.logical -- ^^^^^^^^^^^^ meta.string.like string.quoted.single -- ^ punctuation.definition.string.begin --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.underscore -- ^ punctuation.definition.string.end -- ^^ - meta.string - string SELECT columns FROM table WHERE column LIKE '%\[SQL Server Driver]^%\__' ESCAPE '\' -- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^^ constant.character.escape -- ^ - constant --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^^ constant.character.escape --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.underscore -- ^^^^^^ keyword.operator.word -- ^^^ string.quoted.single -- ^ punctuation.definition.string.begin @@ -74,12 +74,12 @@ SELECT columns FROM table WHERE SELECT columns FROM table WHERE column LIKE '%\[SQL Server Driver]^%\__' -- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^^ constant.character.escape -- ^ - constant --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^^ constant.character.escape --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.underscore ESCAPE '\' -- ^^^^^^ keyword.operator.word -- ^^^ string.quoted.single @@ -90,11 +90,11 @@ SELECT columns FROM table WHERE SELECT columns FROM table WHERE column LIKE '%\^[SQL Server Driver]^%_^_' ESCAPE '^' -- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.percent -- ^ - constant -- ^^ constant.character.escape -- ^^ constant.character.escape --- ^ keyword.operator.wildcard +-- ^ constant.other.wildcard.underscore -- ^^ constant.character.escape -- ^^^^^^ keyword.operator.word -- ^^^ string.quoted.single @@ -105,13 +105,13 @@ SELECT columns FROM table WHERE SELECT columns FROM table WHERE column LIKE '%\^[SQL Server Driver]^%_^_\_{{--' ESCAPE '{' -- uncatered for escape char, scope operators as though unescaped -- ^^^^ keyword.operator.logical --- ^ keyword.operator.wildcard --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - constant +-- ^ constant.other.wildcard.percent +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - constant.character.escape -- ^^^^^^^^^^^^^^^^^^^ meta.set.like -- ^^^^^^^^^^^ - meta.set --- ^^ keyword.operator.wildcard --- ^ keyword.operator.wildcard --- ^ keyword.operator.wildcard +-- ^^ constant.other.wildcard +-- ^ constant.other.wildcard.underscore +-- ^ constant.other.wildcard.underscore -- ^^^^^^^^^^^^^^^ - comment -- ^^^^^^ keyword.operator.word -- ^^^ string.quoted.single From a99b7ea4a1af1bc15e289115c993754424b9cef4 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 4 Aug 2023 21:40:37 +0300 Subject: [PATCH 195/250] fix after merge from master reintroduced syntax test file which was moved --- SQL/syntax_test_sql.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 SQL/syntax_test_sql.sql diff --git a/SQL/syntax_test_sql.sql b/SQL/syntax_test_sql.sql deleted file mode 100644 index e69de29bb2..0000000000 From edb2cc799da4fc9825e33d4f5385b786f95ac861 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 12 Aug 2023 09:37:40 +0300 Subject: [PATCH 196/250] [SQL] improve postgresql syntax slightly with scoping for: - $$ - for loops --- SQL/PostgreSQL.sublime-syntax | 11 +++++++++++ SQL/tests/syntax/syntax_test_postgres.psql | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index f9e6eddbdd..97582765b6 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -34,7 +34,16 @@ contexts: statements: - meta_prepend: true + - match: (\$\$)\s+(LANGUAGE)\s+(\w+)(?:\s+(IMMUTABLE|STABLE)\b)? + captures: + 1: punctuation.section.block.end.psql + 2: keyword.other.psql + 3: constant.language.psql + 4: storage.modifier.psql - match: \$\$ + scope: punctuation.section.block.begin.psql + - match: \b(?i:for|loop)\b + scope: keyword.control.loop.psql ###[ DECLARE STATEMENTS ]###################################################### @@ -271,6 +280,8 @@ contexts: scope: keyword.operator.cast.psql push: expect-type - include: regex-operators + - match: \.\. + scope: keyword.operator.psql regex-operators: # https://www.postgresql.org/docs/7.4/functions-matching.html#FUNCTIONS-POSIX-REGEXP diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index d502954d1c..0ee6a038ee 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -483,6 +483,7 @@ CREATE TRIGGER blah AFTER INSERT OR UPDATE CREATE FUNCTION highlight_result_array(vals varchar[], something tsquery, something_else boolean) RETURNS varchar[] AS $$ +-- ^^ punctuation.section.block.begin DECLARE -- ^^^^ keyword.declaration.variable output varchar[]; @@ -497,12 +498,25 @@ DECLARE BEGIN -- ^^ keyword.other.luw FOR I IN array_lower(vals, 1)..array_upper(vals, 1) LOOP +-- ^^^ keyword.control.loop +-- ^^ keyword.operator.logical +-- ^^^^^^^^^^^ meta.function-call support.function +-- ^^ keyword.operator +-- ^^^^^^^^^^^ meta.function-call support.function +-- ^^^^ keyword.control.loop output[I] := compute_result(vals[I], something, something_else); END LOOP; +-- ^^^ keyword.control.flow.end +-- ^^^^ keyword.control.loop RETURN output; -- ^^^^^^ keyword.control.flow.return END; $$ LANGUAGE plpgsql STABLE; +-- <- punctuation.section.block.end +-- ^^^^^^^^ keyword.other +-- ^^^^^^^ constant.language +-- ^^^^^^ storage.modifier +-- ^ punctuation.terminator.statement DECLARE var varchar[]; -- ^ - variable From dc1185ad82aae131da0cec675f209f46c1f464ec Mon Sep 17 00:00:00 2001 From: deathaxe Date: Tue, 16 May 2023 17:30:50 +0200 Subject: [PATCH 197/250] [SQL] Move user identifier to SQL (Basic) This commit... 1. moves user-name related contexts to SQL (Basic) 2. adds a `builtin_user_functions` variable, which can be modified by MySQL to re-use `built-in-user-function-call(s)` contexts from SQL (Basic) 3. fixes scope name of user functions => `support.function.user` 4. adjusts MySQL's user name meta scope to `meta.username.sql` --- SQL/MySQL.sublime-syntax | 79 +-------------------- SQL/SQL (basic).sublime-syntax | 95 ++++++++++++++++++++----- SQL/TSQL.sublime-syntax | 6 +- SQL/tests/syntax/syntax_test_mysql.sql | 98 +++++++++++++------------- SQL/tests/syntax/syntax_test_tsql.sql | 8 +-- 5 files changed, 137 insertions(+), 149 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index a38fc11587..6c993186cb 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -43,6 +43,9 @@ variables: (?xi: year | quarter | month | day | hour | minute | week | second | year_month | day_hour | day_minute | day_second | hour_minute | hour_second | minute_second ) + builtin_user_functions: |- + \b(?xi: (?: current | session | system )_(?: role | user ))\b + contexts: sql: - meta_append: true @@ -589,16 +592,6 @@ contexts: - match: \b(?i:using)\b scope: keyword.other.mysql - built-in-user-function-calls: - - match: \b(?i:(?:current|session|system)_(?:role|user))\b - scope: support.function.scalar.sql - push: function-call-arguments - - built-in-user-function-call: - - match: \b(?i:(?:current|session|system)_(?:role|user))\b - scope: support.function.scalar.sql - set: function-call-arguments - table-name-or-subquery: - meta_prepend: true - meta_include_prototype: false @@ -1053,72 +1046,6 @@ contexts: ###[ IDENTIFIERS ]############################################################# - expect-user-name: - # prevent prototypes from inheriting syntaxes - - meta_include_prototype: false - - include: comments - - include: built-in-user-function-call - - match: (?=\S) - set: [user-name, user-identifier] - - user-name: - - meta_include_prototype: false - - meta_content_scope: meta.user-name.sql - - include: immediately-pop - - expect-user-name-declaration: - # prevent prototypes from inheriting syntaxes - - meta_include_prototype: false - - include: comments - - match: (?=\S) - set: [user-name-declaration, user-identifier] - - user-name-declaration: - - meta_include_prototype: false - - meta_content_scope: entity.name.user.sql - - include: immediately-pop - - user-identifier: - # https://mariadb.com/kb/en/grant/#account-names - - meta_include_prototype: false - - include: pop-on-top-level-reserved-word - - match: '' - set: - - identifier-host-accessor - - identifier-part - - identifier-host-accessor: - - meta_include_prototype: false - - match: \s*(@) - captures: - 1: punctuation.accessor.at.sql - set: identifier-host-part - - include: immediately-pop - - identifier-host-part: - - meta_include_prototype: false - - match: \% - scope: constant.other.wildcard.percent.sql - pop: 1 - - match: (')(%)(') - captures: - 1: punctuation.definition.identifier.begin.sql - 2: constant.other.wildcard.percent.sql - 3: punctuation.definition.identifier.end.sql - pop: 1 - - match: (")(%)(") - captures: - 1: punctuation.definition.identifier.begin.sql - 2: constant.other.wildcard.percent.sql - 3: punctuation.definition.identifier.end.sql - pop: 1 - - match: (`)(%)(`) - captures: - 1: punctuation.definition.identifier.begin.sql - 2: constant.other.wildcard.percent.sql - 3: punctuation.definition.identifier.end.sql - pop: 1 - - include: identifier-part ###[ LITERALS ]################################################################ diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index fd108b30e4..2bd9f32995 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -44,6 +44,9 @@ variables: types_with_optional_number: |- (?xi: number | n?(?:var)?char | varbinary ) + builtin_user_functions: |- + \b(?xi: (?: current | session | system )_user )\b + contexts: prototype: - include: comments @@ -579,10 +582,15 @@ contexts: push: function-call-arguments built-in-user-function-calls: - - match: \b(?i:(?:current|session|system)_user)\b - scope: support.function.scalar.sql + - match: '{{builtin_user_functions}}' + scope: support.function.user.sql push: function-call-arguments + built-in-user-function-call: + - match: '{{builtin_user_functions}}' + scope: support.function.user.sql + set: function-call-arguments + user-defined-function-calls: - match: \b{{simple_identifier}}(?=\s*\() scope: support.function.sql @@ -1087,6 +1095,73 @@ contexts: - meta_content_scope: meta.table-alias-name.sql - include: immediately-pop + expect-user-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - include: built-in-user-function-call + - match: (?=\S) + set: [user-name, user-identifier] + + user-name: + - meta_include_prototype: false + - meta_content_scope: meta.username.sql + - include: immediately-pop + + expect-user-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [user-name-declaration, user-identifier] + + user-name-declaration: + - meta_include_prototype: false + - meta_content_scope: entity.name.user.sql + - include: immediately-pop + + user-identifier: + # https://mariadb.com/kb/en/grant/#account-names + - meta_include_prototype: false + - include: pop-on-top-level-reserved-word + - match: '' + set: + - identifier-host-accessor + - identifier-part + + identifier-host-accessor: + - meta_include_prototype: false + - match: \s*(@) + captures: + 1: punctuation.accessor.at.sql + set: identifier-host-part + - include: immediately-pop + + identifier-host-part: + - meta_include_prototype: false + - match: \% + scope: constant.other.wildcard.percent.sql + pop: 1 + - match: (')(%)(') + captures: + 1: punctuation.definition.identifier.begin.sql + 2: constant.other.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - match: (")(%)(") + captures: + 1: punctuation.definition.identifier.begin.sql + 2: constant.other.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - match: (`)(%)(`) + captures: + 1: punctuation.definition.identifier.begin.sql + 2: constant.other.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - include: identifier-part + expect-type-creation-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false @@ -1295,25 +1370,11 @@ contexts: scope: constant.language.sql - match: \b(?i:to)\b scope: keyword.context.sql - push: - - user-name - - single-identifier + push: expect-user-name - include: pop-on-top-level-reserved-word - match: (?=\() push: column-reference-list - user-name: - - meta_content_scope: meta.username.sql - - match: '' - pop: true - - expect-user-name: - # prevent prototypes from inheriting syntaxes - - meta_include_prototype: false - - include: comments - - match: (?=\S) - set: [user-name, single-identifier] - ###[ PROTOTYPES ]############################################################## else-pop: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index aa611ea810..a6e5b00b06 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -37,6 +37,9 @@ variables: types_with_optional_number: |- (?xi: n?char | n?varchar | binary | varbinary | decimal | money | numeric ) + builtin_user_functions: |- + \b(?xi: (?: current_ | session_ | system_ )? user )\b + contexts: sql: @@ -342,8 +345,6 @@ contexts: - match: \b(?i:getdate)(?=\s*\() scope: support.function.scalar.sql push: function-call-arguments - - match: \b(?i:user)\b - scope: support.function.scalar.sql cast-arguments: - meta_scope: meta.function-call.sql @@ -565,7 +566,6 @@ contexts: - meta_content_scope: string.quoted.tsql - include: immediately-pop - ###[ LIKE EXPRESSIONS ]######################################################## like-expressions: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 4d23ca07f6..9ce2f9c107 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -151,7 +151,7 @@ CREATE DEFINER = user@host EVENT event_name -- ^^^ keyword.other.ddl.sql -- ^^^^^^^ variable.parameter.definer.sql -- ^ keyword.operator.assignment.sql --- ^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^ meta.username.sql -- ^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^ entity.name.event.sql @@ -309,7 +309,7 @@ CREATE DEFINER = CURRENT_ROLE AGGREGATE FUNCTION foo -- ^^^ keyword.other.ddl.sql -- ^^^^^^^ variable.parameter.definer.sql -- ^ keyword.operator.assignment.sql --- ^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^^^^^^^^^^^^ meta.function-call.sql support.function.user.sql -- ^^^^^^^^^ keyword.other.ddl.sql -- ^^^^^^^^ keyword.other.ddl.sql -- ^^^ entity.name.function.sql @@ -687,7 +687,7 @@ CREATE OR REPLACE ROLE with WITH ADMIN lorinda@localhost -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^^ keyword.other.ddl.sql -- ^^^^^ keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^^^^^^^^^ meta.username.sql -- ^ punctuation.accessor.at.sql CREATE ROLE role WITH ADMIN CURRENT_ROLE @@ -696,7 +696,7 @@ CREATE ROLE role WITH ADMIN CURRENT_ROLE -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^^ keyword.other.ddl.sql -- ^^^^^ keyword.other.ddl.sql --- ^^^^^^^^^^^^ support.function.scalar.sql +-- ^^^^^^^^^^^^ support.function.user.sql -- ---------------------------------------------------------------------------- @@ -1631,7 +1631,7 @@ ALTER DEFINER = user@host EVENT event_name -- ^^ keyword.other.ddl.sql -- ^^^^^^^ variable.parameter.definer.sql -- ^ keyword.operator.assignment.sql --- ^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^ meta.username.sql -- ^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^ meta.event-name.sql @@ -1809,13 +1809,13 @@ ALTER USER IF EXISTS user1, -- <- meta.statement.alter.sql meta.user.sql -- ^^^^^^^^ meta.statement.alter.sql meta.user.sql --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql user2 IDENTIFIED BY 'password', -- <- meta.statement.alter.sql meta.user.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql @@ -1824,7 +1824,7 @@ ALTER USER IF EXISTS user3 IDENTIFIED BY PASSWORD 'password_hash', -- <- meta.statement.alter.sql meta.user.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^^ storage.modifier.sql @@ -1834,7 +1834,7 @@ ALTER USER IF EXISTS user4 IDENTIFIED VIA -- <- meta.statement.alter.sql meta.user.sql -- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql meta.user.sql --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^^ keyword.other.ddl.sql @@ -2086,7 +2086,7 @@ DROP ROLE role ; -- ^ - keyword -- ^^^^ keyword.other.ddl.sql -- ^ - keyword --- ^^^^ meta.user-name.sql +-- ^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql DROP ROLE IF EXISTS role1, role2, role3; @@ -2101,11 +2101,11 @@ DROP ROLE IF EXISTS role1, role2, role3; -- ^ - keyword -- ^^^^^^ keyword.operator.logical.sql -- ^ - keyword --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql @@ -2122,7 +2122,7 @@ DROP USER bob@'%' ; -- ^^^^^^^^^^^^^ meta.statement.drop.sql meta.user.sql -- ^ keyword.other.ddl.sql -- ^^^^ keyword.other.ddl.sql --- ^^^^^^^ meta.user-name.sql +-- ^^^^^^^ meta.username.sql -- ^ punctuation.accessor.at.sql -- ^ punctuation.terminator.statement.sql @@ -2134,9 +2134,9 @@ DROP USER IF EXISTS bob, clara@localhost ; -- ^^^^ keyword.other.ddl.sql -- ^^ keyword.control.conditional.if.sql -- ^^^^^^ keyword.operator.logical.sql --- ^^^ meta.user-name.sql +-- ^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql --- ^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^^^^^^^ meta.username.sql -- ^ punctuation.accessor.at.sql -- ^ punctuation.terminator.statement.sql @@ -2269,7 +2269,7 @@ GRANT CREATE INDEX ON TABLE * TO user1@% IDENTIFIED BY 'password' ; -- ^^^^^ storage.type.sql -- ^ meta.other-name.sql constant.other.wildcard.asterisk.sql -- ^^ keyword.other.ddl.sql --- ^^^^^^^ meta.user-name.sql +-- ^^^^^^^ meta.username.sql -- ^ punctuation.accessor.at.sql -- ^ constant.other.wildcard.percent.sql -- ^^^^^^^^^^ keyword.other.ddl.sql @@ -2285,7 +2285,7 @@ GRANT CREATE INDEX ON PROCEDURE *.* TO user1 IDENTIFIED BY PASSWORD 'password_ha -- ^^^^^^^^^ storage.type.sql -- ^^^ meta.other-name.sql -- ^^ keyword.other.ddl.sql --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^^ storage.modifier.sql @@ -2300,7 +2300,7 @@ GRANT CREATE INDEX ON PACKAGE *.* TO "user1" IDENTIFIED VIA auth1 or auth2 ; -- ^^^^^^^ storage.type.sql -- ^^^ meta.other-name.sql -- ^^ keyword.other.ddl.sql --- ^^^^^^^ meta.user-name.sql +-- ^^^^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^^ keyword.other.ddl.sql -- ^^^^^ meta.other-name.sql @@ -2317,12 +2317,12 @@ GRANT PROXY -- <- meta.statement.grant.sql -- ^^^^^^^^^^^^^ meta.statement.grant.sql -- ^^ keyword.other.ddl.sql --- ^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^ meta.username.sql TO user1 IDENTIFIED BY 'password', -- <- meta.statement.grant.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql -- ^^ keyword.other.ddl.sql --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql @@ -2330,7 +2330,7 @@ GRANT PROXY user2 IDENTIFIED VIA auth USING PASSWORD('passord') -- <- meta.statement.grant.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^^ keyword.other.ddl.sql -- ^^^^ meta.other-name.sql @@ -2352,11 +2352,11 @@ GRANT rolename TO role, user IDENTIFIED BY 'password' WITH ADMIN OPTION ; -- <- meta.statement.grant.sql keyword.other.ddl.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql -- ^^ keyword.other.ddl.sql --- ^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^ meta.username.sql -- ^^ keyword.other.ddl.sql --- ^^^^ meta.user-name.sql +-- ^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql --- ^^^^ meta.user-name.sql +-- ^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql -- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql @@ -2396,13 +2396,13 @@ RENAME USER 'donald' TO 'duck'@'localhost', 'mickey' TO 'mouse'@'localhost'; -- ^ - keyword -- ^^^^ keyword.other.ddl.sql -- ^ - keyword --- ^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^ meta.username.sql -- ^^ keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^^^^^^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql --- ^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^ meta.username.sql -- ^^ keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql @@ -2447,9 +2447,9 @@ REVOKE ALL PRIVILEGES, GRANT OPTION FROM user@'%', user2 ; -- ^ punctuation.separator.sequence.sql -- ^^^^^^^^^^^^ constant.language.sql -- ^^^^ keyword.other.ddl.sql --- ^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql --- ^^^^^ meta.user-name.sql +-- ^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql REVOKE SUPER ON *.* FROM 'alexander'@'localhost'; @@ -2462,7 +2462,7 @@ REVOKE SUPER ON *.* FROM 'alexander'@'localhost'; -- ^ punctuation.accessor.dot.sql -- ^ constant.other.wildcard.asterisk.sql -- ^^^^ keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql REVOKE ADMIN OPTION FOR role FROM grantee, grantee2 ; @@ -2471,20 +2471,20 @@ REVOKE ADMIN OPTION FOR role FROM grantee, grantee2 ; -- ^^^ keyword.other.ddl.sql -- ^^^^^^^^^^^^ constant.language.sql -- ^^^ keyword.other.ddl.sql --- ^^^^ meta.user-name.sql +-- ^^^^ meta.username.sql -- ^^^^ keyword.other.ddl.sql --- ^^^^^^^ meta.user-name.sql +-- ^^^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql --- ^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql REVOKE role1, role2 FROM grantee, grantee2 ; -- <- meta.statement.revoke.sql keyword.other.ddl.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql -- ^^^^ keyword.other.ddl.sql --- ^^^^^^^ meta.user-name.sql +-- ^^^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql --- ^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql @@ -2521,7 +2521,7 @@ SET PASSWORD FOR user1@localhost = -- ^^^^^^^^ keyword.other.dml.sql -- ^ - keyword -- ^^^ keyword.other.dml.sql --- ^^^^^^^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^^^^^^^ meta.username.sql -- ^ punctuation.accessor.at.sql -- ^ keyword.operator.assignment.sql @@ -2555,7 +2555,7 @@ SET PASSWORD for `user@`@'%' = 'encrypted password'; -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql -- ^^^^^^^^ keyword.other.dml.sql -- ^^^ keyword.other.dml.sql --- ^^^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^^^ meta.username.sql -- ^ punctuation.definition.identifier.begin.sql -- ^ punctuation.definition.identifier.end.sql -- ^ punctuation.accessor.at.sql @@ -2586,7 +2586,7 @@ SET ROLE role -- <- meta.statement.set.sql keyword.other.dml.sql -- ^^^^^^^^^^ meta.statement.set.sql -- ^^^^ keyword.other.dml.sql --- ^^^^ meta.user-name.sql +-- ^^^^ meta.username.sql SET DEFAULT ROLE NONE -- <- meta.statement.set.sql keyword.other.dml.sql @@ -2600,7 +2600,7 @@ SET DEFAULT ROLE role -- ^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql -- ^^^^^^^ keyword.other.dml.sql -- ^^^^ keyword.other.dml.sql --- ^^^^ meta.user-name.sql +-- ^^^^ meta.username.sql SET DEFAULT ROLE NONE FOR user@host -- <- meta.statement.set.sql keyword.other.dml.sql @@ -2609,16 +2609,16 @@ SET DEFAULT ROLE NONE FOR user@host -- ^^^^ keyword.other.dml.sql -- ^^^^ constant.language.null.sql -- ^^^ keyword.other.dml.sql --- ^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^ meta.username.sql SET DEFAULT ROLE role FOR user@host -- <- meta.statement.set.sql keyword.other.dml.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql -- ^^^^^^^ keyword.other.dml.sql -- ^^^^ keyword.other.dml.sql --- ^^^^ meta.user-name.sql +-- ^^^^ meta.username.sql -- ^^^ keyword.other.dml.sql --- ^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^ meta.username.sql -- ---------------------------------------------------------------------------- @@ -2650,7 +2650,7 @@ SHOW CREATE USER user_name -- ^ keyword.other.dml.sql -- ^^^^^^ keyword.other.ddl.sql -- ^^^^ keyword.other.ddl.sql --- ^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^ meta.username.sql -- ---------------------------------------------------------------------------- @@ -2678,7 +2678,7 @@ SHOW GRANTS FOR user@host -- ^^^^^^ keyword.other.dml.sql -- ^ - keyword -- ^^^ keyword.other.dml.sql --- ^^^^^^^^^ meta.user-name.sql +-- ^^^^^^^^^ meta.username.sql SHOW GRANTS FOR role -- <- meta.statement.show.sql keyword.other.dml.sql @@ -2688,17 +2688,17 @@ SHOW GRANTS FOR role -- ^^^^^^ keyword.other.dml.sql -- ^ - keyword -- ^^^ keyword.other.dml.sql --- ^^^^ meta.user-name.sql +-- ^^^^ meta.username.sql SHOW GRANTS FOR CURRENT_USER; -- <- meta.statement.show.sql keyword.other.dml.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql --- ^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^^^^^^^^^^^^ meta.function-call.sql support.function.user.sql SHOW GRANTS FOR CURRENT_USER(); -- <- meta.statement.show.sql keyword.other.dml.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.show.sql --- ^^^^^^^^^^^^ meta.function-call.sql support.function.scalar.sql +-- ^^^^^^^^^^^^ meta.function-call.sql support.function.user.sql -- ^^ meta.function-call.sql meta.group.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index cbb1e25c89..b589baf971 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2035,10 +2035,10 @@ END -- <- keyword.control.flow.end CURRENT_USER SESSION_USER SYSTEM_USER USER --- ^^^^^^^^^^^^ support.function.scalar.sql --- ^^^^^^^^^^^^ support.function.scalar.sql --- ^^^^^^^^^^^ support.function.scalar.sql --- ^^^^ support.function.scalar.sql +-- ^^^^^^^^^^^^ support.function.user.sql +-- ^^^^^^^^^^^^ support.function.user.sql +-- ^^^^^^^^^^^ support.function.user.sql +-- ^^^^ support.function.user.sql GRANT CREATE TABLE TO MelanieK; -- ^^ keyword.other.authorization.sql From 128b16fb91a46fa71c9d6a5535721d3437b08fb3 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 2 Aug 2023 19:09:26 +0200 Subject: [PATCH 198/250] [SQL] Add variable for builtin scalar functions Same as for builtin user functions before. --- SQL/SQL (basic).sublime-syntax | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 2bd9f32995..9e6f290f7a 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -44,6 +44,9 @@ variables: types_with_optional_number: |- (?xi: number | n?(?:var)?char | varbinary ) + builtin_scalar_functions: |- + \b(?xi: current_(?: date | time(?:stamp)? ) )\b + builtin_user_functions: |- \b(?xi: (?: current | session | system )_user )\b @@ -577,7 +580,7 @@ contexts: built-in-scalar-function-calls: # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - - match: \b(?i:current_(?:date|time(?:stamp)?))\b + - match: '{{builtin_scalar_functions}}' scope: support.function.scalar.sql push: function-call-arguments From fce8721086c6d9377077dbb9bb3aafffc868ed01 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 2 Aug 2023 19:36:02 +0200 Subject: [PATCH 199/250] [SQL] Reorganize grant/revoke statements & expressions This commit... 1. adds a `grant-statements` context to SQL (basic) to follow MySQL's scheme 2. reorganizes existing `grant` contexts under a "user management expressions" section by moving them in order to fulfill following context architecture: All syntaxes are organized like: 1. DDL statements 2. DML statements 3. UML statements (user management) 4. other statements 5. expressions - contexts for re-use in statements 6. names & identifiers (tables, users, ...) 8. operators & literals --- SQL/MySQL.sublime-syntax | 12 ------ SQL/SQL (basic).sublime-syntax | 67 +++++++++++++++++++++++---------- SQL/TSQL.sublime-syntax | 68 +++++++++++++++++----------------- 3 files changed, 81 insertions(+), 66 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 6c993186cb..7843487a5a 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -53,9 +53,7 @@ contexts: statements: - meta_prepend: true - - include: grant-statements - include: rename-statements - - include: revoke-statements - include: show-statements ###[ COMMENTS ]################################################################ @@ -421,11 +419,6 @@ contexts: - grant-to-user - grant-target - grant-meta: - - meta_include_prototype: false - - meta_scope: meta.statement.grant.sql - - include: immediately-pop - grant-target: # grant proxy on name to user - match: \b(?i:proxy)\b @@ -500,11 +493,6 @@ contexts: - revoke-options - revoke-privileges - revoke-meta: - - meta_include_prototype: false - - meta_scope: meta.statement.revoke.sql - - include: immediately-pop - revoke-privileges: - match: (?=[;)]|\b(?i:for|from)\b) pop: 1 diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 9e6f290f7a..363d4e06d2 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -67,6 +67,8 @@ contexts: - include: drop-statements - include: alter-statements - include: dml-statements + - include: grant-statements + - include: revoke-statements - include: other-statements ###[ COMMENTS ]################################################################ @@ -500,12 +502,37 @@ contexts: set-target: - include: else-pop -###[ OTHER STATEMENTS ]######################################################## +###[ GRANT STATEMENTS ]######################################################## - other-statements: - - match: \b(?i:grant(?:\s+with\s+grant\s+option)?|revoke)\b + grant-statements: + - match: \b(?i:grant(?:\s+with\s+grant\s+option)?)\b scope: keyword.other.authorization.sql - push: grant + push: + - grant-meta + - grant + + grant-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.grant.sql + - include: immediately-pop + +###[ REVOKE STATEMENTS ]####################################################### + + revoke-statements: + - match: \b(?i:revoke)\b + scope: keyword.other.ddl.sql + push: + - revoke-meta + - grant + + revoke-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.revoke.sql + - include: immediately-pop + +###[ OTHER STATEMENTS ]######################################################## + + other-statements: [] ###[ EXPRESSIONS ]############################################################# @@ -690,6 +717,22 @@ contexts: pop: 1 - include: else-pop +###[ USER MANAGEMENT EXPRESSIONS ]############################################# + + grant: + - match: \b(?i:showplan)\b + scope: constant.language.sql + - match: \b(?i:(?:create|drop)\s*{{ddl_target}})\b + scope: constant.language.sql + - match: \b(?i:select|insert|update|delete)\b + scope: constant.language.sql + - match: \b(?i:to)\b + scope: keyword.context.sql + push: expect-user-name + - include: pop-on-top-level-reserved-word + - match: (?=\() + push: column-reference-list + ###[ TABLE NAMES ]############################################################# table-name-or-subquery: @@ -1362,22 +1405,6 @@ contexts: - match: ';' scope: punctuation.terminator.statement.sql -###[ USERS AND PERMISSIONS ]################################################### - - grant: - - match: \b(?i:showplan)\b - scope: constant.language.sql - - match: \b(?i:(?:create|drop)\s*{{ddl_target}})\b - scope: constant.language.sql - - match: \b(?i:select|insert|update|delete)\b - scope: constant.language.sql - - match: \b(?i:to)\b - scope: keyword.context.sql - push: expect-user-name - - include: pop-on-top-level-reserved-word - - match: (?=\() - push: column-reference-list - ###[ PROTOTYPES ]############################################################## else-pop: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index a6e5b00b06..93e4a1b839 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -695,6 +695,40 @@ contexts: pop: 1 - include: like-else-fail +###[ USER MANAGEMENT EXPRESSIONS ]############################################# + + grant: + - meta_prepend: true + - match: \b(?i:from\s+external\s+provider)\b + scope: constant.language.tsql + - include: with-options + - match: \b(?i:control)\b + scope: constant.language.tsql + - match: \b(?i:on)\b + scope: keyword.context.resource.tsql + push: qualified-identifier + + qualified-identifier: + - match: \b(?i:(database))(::) + captures: + 1: storage.type.tsql + 2: punctuation.accessor.double-colon.tsql + set: + - database-name + - single-identifier + - match: (?=\S) + set: + - maybe-double-colon-accessor + - generic-identifier-name + - single-identifier + + maybe-double-colon-accessor: + - match: '::' + scope: punctuation.accessor.double-colon.tsql + set: qualified-identifier + - match: (?=\S) + pop: true + ###[ TABLE NAMES ]############################################################# table-name-or-subquery: @@ -1000,37 +1034,3 @@ contexts: augmented-assignment-operators: - match: '[-+/*%^|]=' scope: keyword.operator.assignment.tsql - -###[ USERS AND PERMISSIONS ]################################################### - - grant: - - meta_prepend: true - - match: \b(?i:from\s+external\s+provider)\b - scope: constant.language.tsql - - include: with-options - - match: \b(?i:control)\b - scope: constant.language.tsql - - match: \b(?i:on)\b - scope: keyword.context.resource.tsql - push: qualified-identifier - - qualified-identifier: - - match: \b(?i:(database))(::) - captures: - 1: storage.type.tsql - 2: punctuation.accessor.double-colon.tsql - set: - - database-name - - single-identifier - - match: (?=\S) - set: - - maybe-double-colon-accessor - - generic-identifier-name - - single-identifier - - maybe-double-colon-accessor: - - match: '::' - scope: punctuation.accessor.double-colon.tsql - set: qualified-identifier - - match: (?=\S) - pop: true From a1337d73e050d52a3a75f9374717793a8b4ffd26 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 2 Aug 2023 21:15:39 +0200 Subject: [PATCH 200/250] [SQL] merge MySQL and T-SQL user privileges - adds `grant` and `revoke` to the list of reserved top-level keywords, which terminate statements. - adds "ALL PERMISSIONS" to T-SQL see: https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-database-permissions-transact-sql - share `user-privileges` context across dialects --- SQL/MySQL.sublime-syntax | 27 +++--- SQL/SQL (basic).sublime-syntax | 25 +++--- SQL/TSQL.sublime-syntax | 17 ++-- SQL/tests/syntax/syntax_test_mysql.sql | 120 +++++++++++++------------ SQL/tests/syntax/syntax_test_tsql.sql | 19 ++-- 5 files changed, 114 insertions(+), 94 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 7843487a5a..e64879aaa4 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -412,7 +412,7 @@ contexts: grant-statements: # https://mariadb.com/kb/en/grant - match: \b(?i:grant)\b - scope: keyword.other.ddl.sql + scope: keyword.other.authorization.sql push: - grant-meta - grant-options @@ -440,12 +440,12 @@ contexts: grant-on-user: - match: \b(?i:on)\b - scope: keyword.other.ddl.sql + scope: keyword.context.sql - include: expect-user-name grant-to-user: - match: \b(?i:to)\b - scope: keyword.other.ddl.sql + scope: keyword.context.sql - include: expect-user-identification-list grant-options: @@ -458,7 +458,7 @@ contexts: rename-statements: # https://mariadb.com/kb/en/rename-user - match: \b(?i:rename)\b - scope: keyword.other.ddl.sql + scope: keyword.other.authorization.sql push: - rename-meta - rename-target @@ -470,7 +470,7 @@ contexts: rename-target: - match: \b(?i:user)\b - scope: keyword.other.ddl.sql + scope: keyword.other.authorization.sql set: - rename-user - expect-user-name @@ -478,7 +478,7 @@ contexts: rename-user: - match: \b(?i:to)\b - scope: keyword.other.ddl.sql + scope: keyword.context.sql push: expect-user-name - include: user-name-list @@ -487,7 +487,7 @@ contexts: revoke-statements: # https://mariadb.com/kb/en/revoke - match: \b(?i:revoke)\b - scope: keyword.other.ddl.sql + scope: keyword.other.authorization.sql push: - revoke-meta - revoke-options @@ -502,7 +502,7 @@ contexts: revoke-options: - match: \b(?i:for|from)\b - scope: keyword.other.ddl.sql + scope: keyword.context.sql push: - user-name-list - expect-user-name @@ -976,13 +976,12 @@ contexts: - include: none-constants user-privileges: - - include: column-reference-lists - - include: user-all-privileges - - include: user-grant-privileges - - user-all-privileges: + - meta_append: true - match: \b(?i:all\s+privileges)\b scope: constant.language.sql + - match: \b(?i:super)\b + scope: constant.language.sql + - include: user-grant-privileges user-grant-privileges: - match: \b(?i:(?:grant|admin)\s+option)\b @@ -990,7 +989,7 @@ contexts: on-privilidge-level: - match: \b(?i:on)\b - scope: keyword.other.ddl.sql + scope: keyword.context.sql set: privilidge-level privilidge-level: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 363d4e06d2..7840436fcd 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -11,8 +11,8 @@ variables: simple_identifier_break: (?!\w) reserved: |- - (?xi: alter | create | delete | drop | from | group | inner | insert | join - | left | on | order | outer | right | select | set | truncate | union + (?xi: alter | create | delete | drop | from | grant | group | inner | insert | join + | left | on | order | outer | revoke | right | select | set | truncate | union | update | where ) additional_reserved: (?!) @@ -25,7 +25,7 @@ variables: ddl_target_function: |- (?xi: procedure | function ) ddl_target_other: |- - (?xi: aggregate | constraint | conversion | database | domain | group + (?xi: aggregate | column | constraint | conversion | database | domain | group | language | member | operator\s+class | operator | role | rule | schema | sequence | tablespace | trigger | type | user | view ) @@ -720,18 +720,21 @@ contexts: ###[ USER MANAGEMENT EXPRESSIONS ]############################################# grant: - - match: \b(?i:showplan)\b - scope: constant.language.sql - - match: \b(?i:(?:create|drop)\s*{{ddl_target}})\b - scope: constant.language.sql - - match: \b(?i:select|insert|update|delete)\b - scope: constant.language.sql - match: \b(?i:to)\b scope: keyword.context.sql push: expect-user-name + - include: comma-separators + - include: user-privileges - include: pop-on-top-level-reserved-word - - match: (?=\() - push: column-reference-list + + user-privileges: + - include: column-reference-lists + - match: \b(?i:all\s+privileges)\b + scope: constant.language.sql + - match: \b(?i:(?:alter|create|drop|grant|revoke)\s+{{ddl_target}})\b + scope: constant.language.sql + - match: \b(?i:select|insert|update|delete|truncate)\b + scope: constant.language.sql ###[ TABLE NAMES ]############################################################# diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 93e4a1b839..7777208d80 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -699,14 +699,21 @@ contexts: grant: - meta_prepend: true - - match: \b(?i:from\s+external\s+provider)\b - scope: constant.language.tsql - - include: with-options - - match: \b(?i:control)\b - scope: constant.language.tsql - match: \b(?i:on)\b scope: keyword.context.resource.tsql push: qualified-identifier + - include: with-options + + user-privileges: + - meta_prepend: true + - match: \b(?i:all(?:\s+permissions)?)\b + scope: constant.language.sql + - match: \b(?i:control)\b + scope: constant.language.tsql + - match: \b(?i:from\s+external\s+provider)\b + scope: constant.language.tsql + - match: \b(?i:showplan)\b + scope: constant.language.sql qualified-identifier: - match: \b(?i:(database))(::) diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 9ce2f9c107..0eb84847d3 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -2215,60 +2215,60 @@ DROP USER IF EXISTS bob, clara@localhost ; -- ---------------------------------------------------------------------------- GRANT --- <- meta.statement.grant.sql keyword.other.ddl.sql --- ^^ meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql +-- ^^ meta.statement.grant.sql keyword.other.authorization.sql -- ^ meta.statement.grant.sql - keyword GRANT DROP TABLE, ALTER COLUMN --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.other.authorization.sql -- ^ punctuation.separator.sequence.sql GRANT ALTER COLUMN ON * --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^ meta.other-name.sql constant.other.wildcard.asterisk.sql GRANT ALTER TABLE ON *.* --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^ meta.other-name.sql -- ^ constant.other.wildcard.asterisk.sql -- ^ punctuation.accessor.dot.sql -- ^ constant.other.wildcard.asterisk.sql GRANT ALTER INDEX ON db_name.* --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^^^^^^ meta.other-name.sql -- ^ punctuation.accessor.dot.sql -- ^ constant.other.wildcard.asterisk.sql GRANT ALTER COLUMN ON db_name.table_name --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^^^^^^^^^^^^^^^ meta.other-name.sql -- ^ punctuation.accessor.dot.sql GRANT ALTER COLUMN ON table_name --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^^^^^^^ meta.other-name.sql GRANT CREATE INDEX ON TABLE * TO user1@% IDENTIFIED BY 'password' ; --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.other.authorization.sql +-- ^^ keyword.context.sql -- ^^^^^ storage.type.sql -- ^ meta.other-name.sql constant.other.wildcard.asterisk.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^^^^ meta.username.sql -- ^ punctuation.accessor.at.sql -- ^ constant.other.wildcard.percent.sql @@ -2278,13 +2278,13 @@ GRANT CREATE INDEX ON TABLE * TO user1@% IDENTIFIED BY 'password' ; -- ^ punctuation.terminator.statement.sql GRANT CREATE INDEX ON PROCEDURE *.* TO user1 IDENTIFIED BY PASSWORD 'password_hash' ; --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.other.authorization.sql +-- ^^ keyword.context.sql -- ^^^^^^^^^ storage.type.sql -- ^^^ meta.other-name.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql @@ -2293,13 +2293,13 @@ GRANT CREATE INDEX ON PROCEDURE *.* TO user1 IDENTIFIED BY PASSWORD 'password_ha -- ^ punctuation.terminator.statement.sql GRANT CREATE INDEX ON PACKAGE *.* TO "user1" IDENTIFIED VIA auth1 or auth2 ; --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.other.authorization.sql +-- ^^ keyword.context.sql -- ^^^^^^^ storage.type.sql -- ^^^ meta.other-name.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^^ keyword.other.ddl.sql @@ -2309,19 +2309,19 @@ GRANT CREATE INDEX ON PACKAGE *.* TO "user1" IDENTIFIED VIA auth1 or auth2 ; -- ^ punctuation.terminator.statement.sql GRANT PROXY --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.other.authorization.sql -- ^^^^^ keyword.other.ddl.sql ON username -- <- meta.statement.grant.sql -- ^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^^^^^ meta.username.sql TO user1 IDENTIFIED BY 'password', -- <- meta.statement.grant.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^^ meta.username.sql -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^ keyword.other.ddl.sql @@ -2349,11 +2349,11 @@ GRANT PROXY -- ^ punctuation.terminator.statement.sql GRANT rolename TO role, user IDENTIFIED BY 'password' WITH ADMIN OPTION ; --- <- meta.statement.grant.sql keyword.other.ddl.sql +-- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.other.authorization.sql -- ^^^^^^^^ meta.username.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql -- ^^^^ meta.username.sql @@ -2376,32 +2376,32 @@ GRANT rolename TO role, user IDENTIFIED BY 'password' WITH ADMIN OPTION ; -- ---------------------------------------------------------------------------- RENAME --- <- meta.statement.rename.sql keyword.other.ddl.sql +-- <- meta.statement.rename.sql keyword.other.authorization.sql -- ^^^^ meta.statement.rename.sql --- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.authorization.sql -- ^ - keyword RENAME USER --- <- meta.statement.rename.sql keyword.other.ddl.sql +-- <- meta.statement.rename.sql keyword.other.authorization.sql -- ^^^^^^^^^ meta.statement.rename.sql --- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.authorization.sql -- ^ - keyword --- ^^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.authorization.sql -- ^ - keyword RENAME USER 'donald' TO 'duck'@'localhost', 'mickey' TO 'mouse'@'localhost'; --- <- meta.statement.rename.sql keyword.other.ddl.sql +-- <- meta.statement.rename.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.rename.sql --- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.authorization.sql -- ^ - keyword --- ^^^^ keyword.other.ddl.sql +-- ^^^^ keyword.other.authorization.sql -- ^ - keyword -- ^^^^^^^^ meta.username.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^^^^^^^^^^^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql -- ^^^^^^^^ meta.username.sql --- ^^ keyword.other.ddl.sql +-- ^^ keyword.context.sql -- ^^^^^^^^^^^^^^^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql @@ -2423,14 +2423,15 @@ RENAME USER 'donald' TO 'duck'@'localhost', 'mickey' TO 'mouse'@'localhost'; -- ---------------------------------------------------------------------------- REVOKE ; --- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- <- meta.statement.revoke.sql keyword.other.authorization.sql -- ^^^^ meta.statement.revoke.sql --- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.authorization.sql -- ^ punctuation.terminator.statement.sql REVOKE ALTER COLUMN (`col1`, `names`) ; --- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- <- meta.statement.revoke.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql +-- ^^^^^^^^^^^^ constant.language.sql -- ^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql -- ^ punctuation.section.group.begin.sql -- ^^^^^^ meta.column-name.sql @@ -2440,48 +2441,49 @@ REVOKE ALTER COLUMN (`col1`, `names`) ; -- ^ punctuation.terminator.statement.sql REVOKE ALL PRIVILEGES, GRANT OPTION FROM user@'%', user2 ; --- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- <- meta.statement.revoke.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql --- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.authorization.sql -- ^^^^^^^^^^^^^^ constant.language.sql -- ^ punctuation.separator.sequence.sql -- ^^^^^^^^^^^^ constant.language.sql --- ^^^^ keyword.other.ddl.sql +-- ^^^^ keyword.context.sql -- ^^^^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql -- ^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql REVOKE SUPER ON *.* FROM 'alexander'@'localhost'; --- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- <- meta.statement.revoke.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql --- ^^^ keyword.other.ddl.sql --- ^^ keyword.other.ddl.sql +-- ^^^ keyword.other.authorization.sql +-- ^^^^^ constant.language.sql +-- ^^ keyword.context.sql -- ^^^ meta.other-name.sql -- ^ constant.other.wildcard.asterisk.sql -- ^ punctuation.accessor.dot.sql -- ^ constant.other.wildcard.asterisk.sql --- ^^^^ keyword.other.ddl.sql +-- ^^^^ keyword.context.sql -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql REVOKE ADMIN OPTION FOR role FROM grantee, grantee2 ; --- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- <- meta.statement.revoke.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql --- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.authorization.sql -- ^^^^^^^^^^^^ constant.language.sql --- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.context.sql -- ^^^^ meta.username.sql --- ^^^^ keyword.other.ddl.sql +-- ^^^^ keyword.context.sql -- ^^^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql -- ^^^^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql REVOKE role1, role2 FROM grantee, grantee2 ; --- <- meta.statement.revoke.sql keyword.other.ddl.sql +-- <- meta.statement.revoke.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.revoke.sql --- ^^^^ keyword.other.ddl.sql +-- ^^^^ keyword.context.sql -- ^^^^^^^ meta.username.sql -- ^ punctuation.separator.sequence.sql -- ^^^^^^^^ meta.username.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index b589baf971..28e71325b1 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2040,6 +2040,10 @@ END -- ^^^^^^^^^^^ support.function.user.sql -- ^^^^ support.function.user.sql +GRANT ALL PERMISSIONS +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^ constant.language.sql + GRANT CREATE TABLE TO MelanieK; -- ^^ keyword.other.authorization.sql -- ^^^^^^^^^^^^ constant.language.sql @@ -2047,12 +2051,10 @@ GRANT CREATE TABLE TO MelanieK; -- ^^^^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql -GRANT SHOWPLAN TO AuditMonitor; +GRANT DROP TABLE, ALTER COLUMN TO me -- ^^ keyword.other.authorization.sql --- ^^^^^^^^ constant.language.sql --- ^^ keyword.context.sql --- ^^^^^^^^^^^^ meta.username.sql --- ^ punctuation.terminator.statement.sql +-- ^ punctuation.separator.sequence.sql +-- ^^ keyword.context.sql GRANT CREATE VIEW TO CarmineEs WITH GRANT OPTION; -- ^^ keyword.other.authorization.sql @@ -2110,6 +2112,13 @@ GRANT SELECT ON schema::some_schema TO Sarah; -- ^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql +GRANT SHOWPLAN TO AuditMonitor; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^ constant.language.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + ALTER ROLE buyers WITH NAME = purchasing; --^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql From c92f79a5be3181f80be2f1bcf4794b9da3c52dd3 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 17 Aug 2023 18:29:58 +0200 Subject: [PATCH 201/250] [SQL] fix ALL PRIVILEGES --- SQL/MySQL.sublime-syntax | 2 -- SQL/SQL (basic).sublime-syntax | 2 +- SQL/TSQL.sublime-syntax | 2 -- SQL/tests/syntax/syntax_test_mysql.sql | 8 ++++++++ SQL/tests/syntax/syntax_test_tsql.sql | 8 ++++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index e64879aaa4..18d860f317 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -977,8 +977,6 @@ contexts: user-privileges: - meta_append: true - - match: \b(?i:all\s+privileges)\b - scope: constant.language.sql - match: \b(?i:super)\b scope: constant.language.sql - include: user-grant-privileges diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 7840436fcd..2be08c2105 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -729,7 +729,7 @@ contexts: user-privileges: - include: column-reference-lists - - match: \b(?i:all\s+privileges)\b + - match: \b(?i:all(?:\s+privileges)?)\b scope: constant.language.sql - match: \b(?i:(?:alter|create|drop|grant|revoke)\s+{{ddl_target}})\b scope: constant.language.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 7777208d80..c2d6027047 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -706,8 +706,6 @@ contexts: user-privileges: - meta_prepend: true - - match: \b(?i:all(?:\s+permissions)?)\b - scope: constant.language.sql - match: \b(?i:control)\b scope: constant.language.tsql - match: \b(?i:from\s+external\s+provider)\b diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 0eb84847d3..603b08e5ef 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -2219,6 +2219,14 @@ GRANT -- ^^ meta.statement.grant.sql keyword.other.authorization.sql -- ^ meta.statement.grant.sql - keyword +GRANT ALL +-- ^^ keyword.other.authorization.sql +-- ^^^ constant.language.sql + +GRANT ALL PRIVILEGES +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^ constant.language.sql + GRANT DROP TABLE, ALTER COLUMN -- <- meta.statement.grant.sql keyword.other.authorization.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 28e71325b1..0499e83b9d 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2040,9 +2040,13 @@ END -- ^^^^^^^^^^^ support.function.user.sql -- ^^^^ support.function.user.sql -GRANT ALL PERMISSIONS +GRANT ALL -- ^^ keyword.other.authorization.sql --- ^^^^^^^^^^^^^^^ constant.language.sql +-- ^^^ constant.language.sql + +GRANT ALL PRIVILEGES +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^ constant.language.sql GRANT CREATE TABLE TO MelanieK; -- ^^ keyword.other.authorization.sql From 5628ec120a0917adfd4c4f76906168ae0e08bf64 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 17 Aug 2023 18:38:04 +0200 Subject: [PATCH 202/250] [SQL] Add missing class types --- SQL/TSQL.sublime-syntax | 17 ++++++++++++++++- SQL/tests/syntax/syntax_test_tsql.sql | 14 ++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index c2d6027047..092944e2e2 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -714,13 +714,28 @@ contexts: scope: constant.language.sql qualified-identifier: - - match: \b(?i:(database))(::) + # https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-transact-sql?view=sql-server-ver16#syntax + - match: \b(?i:(database|schema))(::) captures: 1: storage.type.tsql 2: punctuation.accessor.double-colon.tsql set: - database-name - single-identifier + - match: \b(?i:(login|role|user))(::) + captures: + 1: storage.type.tsql + 2: punctuation.accessor.double-colon.tsql + set: + - user-name + - single-identifier + - match: \b(?i:(object))(::) + captures: + 1: storage.type.tsql + 2: punctuation.accessor.double-colon.tsql + set: + - other-name + - single-identifier - match: (?=\S) set: - maybe-double-colon-accessor diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 0499e83b9d..02ec39a490 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2079,6 +2079,16 @@ GRANT CONTROL ON DATABASE::AdventureWorks2012 TO Sarah; -- ^^ keyword.context.sql -- ^^^^^ meta.username.sql +GRANT CONTROL ON ROLE::Admin TO Sarah; +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^ constant.language.tsql +-- ^^ keyword.context.resource.tsql +-- ^^^^ storage.type.tsql +-- ^^ punctuation.accessor.double-colon.tsql +-- ^^^^^ meta.username.sql +-- ^^ keyword.context.sql +-- ^^^^^ meta.username.sql + GRANT INSERT ON dbo.some_table TO Sarah; -- ^^ keyword.other.authorization.sql -- ^^^^^^ constant.language.sql @@ -2109,9 +2119,9 @@ GRANT SELECT ON schema::some_schema TO Sarah; -- ^^ keyword.other.authorization.sql -- ^^^^^^ constant.language.sql -- ^^ keyword.context.resource.tsql --- ^^^^^^ string.quoted.tsql +-- ^^^^^^ storage.type.tsql -- ^^ punctuation.accessor.double-colon.tsql --- ^^^^^^^^^^^ string.quoted.tsql +-- ^^^^^^^^^^^ meta.database-name.sql -- ^^ keyword.context.sql -- ^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql From 436ba5ad96263618a5f4f8b03075036250663788 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 17 Aug 2023 18:41:01 +0200 Subject: [PATCH 203/250] [SQL] Add generic class type The other GRANT statements at learn.microsoft.com/.../ indicate there are various more class types to consider for highlighting. --- SQL/TSQL.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 092944e2e2..c1f17744c8 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -729,7 +729,7 @@ contexts: set: - user-name - single-identifier - - match: \b(?i:(object))(::) + - match: \b(?i:(\w+))(::) captures: 1: storage.type.tsql 2: punctuation.accessor.double-colon.tsql From aeb3ce6cac39738a05d1b02e61c0332d984d28ce Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 17 Aug 2023 18:44:55 +0200 Subject: [PATCH 204/250] [SQL] Restrict user@host to MySQL --- SQL/MySQL.sublime-syntax | 56 ++++++++++++++++++++++++++++++++++ SQL/SQL (basic).sublime-syntax | 46 ++-------------------------- 2 files changed, 58 insertions(+), 44 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 18d860f317..c19f97bb27 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -1031,6 +1031,62 @@ contexts: ###[ IDENTIFIERS ]############################################################# + expect-user-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [user-name-declaration, user-identifier] + + expect-user-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - include: built-in-user-function-call + - match: (?=\S) + set: [user-name, user-identifier] + + user-identifier: + # https://mariadb.com/kb/en/grant/#account-names + - meta_include_prototype: false + - include: pop-on-top-level-reserved-word + - match: '' + set: + - identifier-host-accessor + - identifier-part + + identifier-host-accessor: + - meta_include_prototype: false + - match: \s*(@) + captures: + 1: punctuation.accessor.at.sql + set: identifier-host-part + - include: immediately-pop + + identifier-host-part: + - meta_include_prototype: false + - match: \% + scope: constant.other.wildcard.percent.sql + pop: 1 + - match: (')(%)(') + captures: + 1: punctuation.definition.identifier.begin.sql + 2: constant.other.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - match: (")(%)(") + captures: + 1: punctuation.definition.identifier.begin.sql + 2: constant.other.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - match: (`)(%)(`) + captures: + 1: punctuation.definition.identifier.begin.sql + 2: constant.other.wildcard.percent.sql + 3: punctuation.definition.identifier.end.sql + pop: 1 + - include: identifier-part ###[ LITERALS ]################################################################ diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 2be08c2105..30ea99fdf5 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -1150,7 +1150,7 @@ contexts: - include: comments - include: built-in-user-function-call - match: (?=\S) - set: [user-name, user-identifier] + set: [user-name, single-identifier] user-name: - meta_include_prototype: false @@ -1162,55 +1162,13 @@ contexts: - meta_include_prototype: false - include: comments - match: (?=\S) - set: [user-name-declaration, user-identifier] + set: [user-name-declaration, single-identifier] user-name-declaration: - meta_include_prototype: false - meta_content_scope: entity.name.user.sql - include: immediately-pop - user-identifier: - # https://mariadb.com/kb/en/grant/#account-names - - meta_include_prototype: false - - include: pop-on-top-level-reserved-word - - match: '' - set: - - identifier-host-accessor - - identifier-part - - identifier-host-accessor: - - meta_include_prototype: false - - match: \s*(@) - captures: - 1: punctuation.accessor.at.sql - set: identifier-host-part - - include: immediately-pop - - identifier-host-part: - - meta_include_prototype: false - - match: \% - scope: constant.other.wildcard.percent.sql - pop: 1 - - match: (')(%)(') - captures: - 1: punctuation.definition.identifier.begin.sql - 2: constant.other.wildcard.percent.sql - 3: punctuation.definition.identifier.end.sql - pop: 1 - - match: (")(%)(") - captures: - 1: punctuation.definition.identifier.begin.sql - 2: constant.other.wildcard.percent.sql - 3: punctuation.definition.identifier.end.sql - pop: 1 - - match: (`)(%)(`) - captures: - 1: punctuation.definition.identifier.begin.sql - 2: constant.other.wildcard.percent.sql - 3: punctuation.definition.identifier.end.sql - pop: 1 - - include: identifier-part - expect-type-creation-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false From 42b187cdf45824fcadf8e0239a449eb8133dd56c Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 18 Aug 2023 10:16:58 +0300 Subject: [PATCH 205/250] [SQL] additional fixes for TSQL --- SQL/TSQL.sublime-syntax | 13 +++++++++++-- SQL/tests/syntax/syntax_test_tsql.sql | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index c1f17744c8..aa8dea2f89 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -85,6 +85,12 @@ contexts: - meta_prepend: true - include: target-options + create-other-args: + - meta_prepend: true + - match: \b(?i:without\s+\w+)\b + scope: storage.modifier.tsql + + ###[ DDL STATEMENT PROTOTYPES ]################################################ alter-common: @@ -328,6 +334,8 @@ contexts: scope: keyword.other.sql - match: \b(?i:within\s+group)\b scope: keyword.other.tsql + - match: \b(?i:at\s+time\s+zone)\b + scope: storage.modifier.tsql built-in-scalar-function-calls: - meta_append: true @@ -510,14 +518,14 @@ contexts: set: with-simple-options with-simple-options: + - match: (?=;|\b(?i:GO|END)\b) # NOTE: we cant use the pop-on-top-level-reserved-word context here because it includes things like GRANT which are valid here + pop: true - match: '{{simple_identifier}}' scope: constant.language.with.tsql - match: '=' scope: keyword.operator.assignment.tsql push: with-other-assignment - include: comma-separators - - match: (?=;) - pop: true maybe-filegroup: - match: \b(?i:on)\b(?!\s*{{identifier_for_lookahead}}\s*=) @@ -553,6 +561,7 @@ contexts: - match: (?=[,)]) pop: 1 - include: onoff-constants + - include: pop-on-top-level-reserved-word - include: expressions - match: (?=") set: diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 02ec39a490..fc2ae8134c 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2303,3 +2303,19 @@ CREATE CLUSTERED INDEX ix_some_table_some_field_another_field ON dbo.some_table -- ^ punctuation.separator.sequence.sql -- ^^^^^^^^^^^^^ meta.column-name.sql -- ^ punctuation.section.group.end.sql + +SET @local_datetime = cast(t.created_date AT TIME ZONE 'UTC' AT TIME ZONE 'Central European Standard Time' as time) +-- ^^^^^^^^^^^^ storage.modifier.tsql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^^^^^^^^^^^^ storage.modifier.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^^ keyword.operator.assignment.tsql +-- ^^^^ storage.type.sql + +DROP USER IF EXISTS [foo] +CREATE USER [foo] WITHOUT LOGIN WITH DEFAULT_SCHEMA=[bar] +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^^^^^^^^^^^ storage.modifier.tsql +-- ^^^^ keyword.other.dml.sql +GO +-- <- keyword.control.flow.go.tsql - meta.statement.create From 649b960f5ef334d8a17b0f6af38e586b1e0d9331 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 18 Aug 2023 10:19:25 +0300 Subject: [PATCH 206/250] [SQL] use tabs for indentation in tmPreferences files --- SQL/Indexed Symbol List.tmPreferences | 14 +++++++------- SQL/Symbol List.tmPreferences | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/SQL/Indexed Symbol List.tmPreferences b/SQL/Indexed Symbol List.tmPreferences index f2fe506f31..7421686520 100644 --- a/SQL/Indexed Symbol List.tmPreferences +++ b/SQL/Indexed Symbol List.tmPreferences @@ -1,12 +1,12 @@ - scope - source.sql entity.name.struct - settings - - showInIndexedSymbolList - 1 - + scope + source.sql entity.name.struct + settings + + showInIndexedSymbolList + 1 + diff --git a/SQL/Symbol List.tmPreferences b/SQL/Symbol List.tmPreferences index 79be334003..0c25d4e279 100644 --- a/SQL/Symbol List.tmPreferences +++ b/SQL/Symbol List.tmPreferences @@ -1,12 +1,12 @@ - scope - source.sql entity.name.struct - settings - - showInSymbolList - 1 - + scope + source.sql entity.name.struct + settings + + showInSymbolList + 1 + From 02161efd303e02e3cdee07131cd6201e947209b9 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Fri, 18 Aug 2023 10:25:54 +0300 Subject: [PATCH 207/250] [SQL] update URL in Cassandra syntax comment --- SQL/Cassandra.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index 60172bb0d6..a1537ba808 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -1,6 +1,6 @@ %YAML 1.2 --- -# https://cassandra.apache.org/doc/latest/cassandra/cql +# https://cassandra.apache.org/doc/latest/cassandra/cql/ name: Cassandra Query Language scope: source.sql.cql version: 2 From 7e834cd22ae981b8c0b4cd0ab7ef9c244f5c61c4 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 21 Aug 2023 07:01:22 +0300 Subject: [PATCH 208/250] [SQL] PostgreSQL improvements --- SQL/PostgreSQL.sublime-syntax | 53 ++++++++++++++++++++-- SQL/tests/syntax/syntax_test_postgres.psql | 17 ++++++- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 97582765b6..c67709a944 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -42,8 +42,28 @@ contexts: 4: storage.modifier.psql - match: \$\$ scope: punctuation.section.block.begin.psql - - match: \b(?i:for|loop)\b + - match: \b(?i:if)\b + scope: keyword.control.conditional.if.psql + - match: \b(?i:for)\b scope: keyword.control.loop.psql + push: + - declaration-variable-name + - single-identifier + - match: \b(?i:loop)\b + scope: keyword.control.loop.psql + # TODO: priortise variables over columns when not in a select statement etc. + + built-in-type: + - meta_prepend: true + - match: |- + (?xi) + \b{{types_with_optional_number}}\b + (\[)(\]) + scope: storage.type.sql + captures: + 1: punctuation.section.brackets.begin.psql + 2: punctuation.section.brackets.end.psql + set: maybe-group ###[ DECLARE STATEMENTS ]###################################################### @@ -185,8 +205,6 @@ contexts: scope: punctuation.section.brackets.begin.psql - match: \] scope: punctuation.section.brackets.end.psql - - match: ':(?!:)' - scope: keyword.operator.range.psql ###[ EXTENSION EXPRESSIONS ]################################################### @@ -279,6 +297,10 @@ contexts: - match: '::' scope: keyword.operator.cast.psql push: expect-type + - match: ':=' + scope: keyword.operator.assignment.psql + - match: ':(?!:)' + scope: keyword.operator.range.psql - include: regex-operators - match: \.\. scope: keyword.operator.psql @@ -299,3 +321,28 @@ contexts: 0: meta.string.regexp.psql punctuation.definition.string.end.psql pop: 1 - include: else-pop + + strings: + - meta_append: true + # https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE + - match: (?i:E)\' + scope: punctuation.definition.string.begin.sql + push: inside-single-quoted-escape-string + + inside-single-quoted-escape-string: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.quoted.single.sql + - match: \'\' + scope: constant.character.escape.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - match: \\[0-7]{1,3} + scope: constant.character.escape.sql + - match: \\x\h{1,2} + scope: constant.character.escape.sql + - match: \\u\h{4} + scope: constant.character.escape.sql + - match: \\U\h{8} + scope: constant.character.escape.sql + - include: string-escapes diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index 0ee6a038ee..fc4ecac99b 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -483,6 +483,9 @@ CREATE TRIGGER blah AFTER INSERT OR UPDATE CREATE FUNCTION highlight_result_array(vals varchar[], something tsquery, something_else boolean) RETURNS varchar[] AS $$ +-- ^^^^^^^^^ storage.type +-- ^ punctuation.section.brackets.begin +-- ^ punctuation.section.brackets.end -- ^^ punctuation.section.block.begin DECLARE -- ^^^^ keyword.declaration.variable @@ -491,7 +494,6 @@ DECLARE -- ^^^^^^ variable.other -- ^ - variable - storage -- ^^^^^^^ storage.type --- ^^ - storage -- ^ punctuation.section.brackets.begin -- ^ punctuation.section.brackets.end -- ^ punctuation.terminator.statement @@ -499,6 +501,7 @@ BEGIN -- ^^ keyword.other.luw FOR I IN array_lower(vals, 1)..array_upper(vals, 1) LOOP -- ^^^ keyword.control.loop +-- ^ variable.other -- ^^ keyword.operator.logical -- ^^^^^^^^^^^ meta.function-call support.function -- ^^ keyword.operator @@ -530,3 +533,15 @@ DROP TRIGGER blah ON some_table; -- ^^ keyword.other -- ^^^^^^^^^^ meta.table-name -- ^ punctuation.terminator.statement + +value := ts_headline(value, query, E'HighlightAll=TRUE, StartSel="\002", StopSel="\003"'); +-- ^^ punctuation.definition.string.begin +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single +-- ^^^^ constant.character.escape +-- ^^^^ constant.character.escape +-- ^ punctuation.definition.string.end +value := E'\u1234 \U9876A001' +-- ^^ keyword.operator.assignment +-- ^^^^^^ constant.character.escape +-- ^ - constant +-- ^^^^^^^^^^ constant.character.escape From 59d96d80538b5be2d0215f257e8161a758493d67 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 21 Aug 2023 09:53:01 +0300 Subject: [PATCH 209/250] [SQL] improve scoping of escapes inside bytea strings in PostgreSQL --- SQL/PostgreSQL.sublime-syntax | 19 ++++++++++++++++++- SQL/tests/syntax/syntax_test_postgres.psql | 10 ++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index c67709a944..1c1c919ee2 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -323,11 +323,14 @@ contexts: - include: else-pop strings: - - meta_append: true + - meta_prepend: true # https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE - match: (?i:E)\' scope: punctuation.definition.string.begin.sql push: inside-single-quoted-escape-string + - match: \'(?=[^']+'::bytea\b) + scope: punctuation.definition.string.begin.sql + push: inside-single-quoted-bytea-string inside-single-quoted-escape-string: - meta_include_prototype: false @@ -346,3 +349,17 @@ contexts: - match: \\U\h{8} scope: constant.character.escape.sql - include: string-escapes + + inside-single-quoted-bytea-string: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.quoted.single.sql + - match: \'\' + scope: constant.character.escape.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - match: \\[0-7]{1,3} + scope: constant.character.escape.sql + - match: \\x\h{8} + scope: constant.character.escape.sql + - include: string-escapes diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index fc4ecac99b..fb7e4bc755 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -96,14 +96,20 @@ CREATE TABLE IF NOT EXISTS public.dropzone_details -- ^ punctuation.section.group.end ) -SELECT '\xDEADBEEF'; +-- https://www.postgresql.org/docs/current/datatype-binary.html#id-1.5.7.12.9 +SELECT '\xDEADBEEF'::bytea; +-- ^^^^^^^^^^ meta.string string.quoted.single constant.character.escape +-- ^ punctuation.definition.string.end +-- ^^ keyword.operator.cast +-- ^^^^^ storage.type SET bytea_output = 'escape'; - SELECT 'abc \153\154\155 \052\251\124'::bytea; +-- ^^^^^^^^^^^^ constant.character.escape -- ^^ keyword.operator.cast -- ^^^^^ storage.type -- ^ punctuation.terminator.statement + CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); -- ^^^ meta.statement.create keyword.other.ddl -- ^^^^ meta.statement.create keyword.other From 880068a453c87b32c6f9040ea6a93316ce35bf5f Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 21 Aug 2023 20:42:33 +0300 Subject: [PATCH 210/250] [SQL] support CREATE SEQUENCE in TSQL --- SQL/TSQL.sublime-syntax | 23 +++++++++++++++++++++-- SQL/tests/syntax/syntax_test_tsql.sql | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index aa8dea2f89..d1db7f2c70 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -80,6 +80,7 @@ contexts: # modifiers - match: \b(?i:unique|clustered|nonclustered)\b scope: keyword.other.ddl.sql + - include: create-sequence expect-function-characteristics: - meta_prepend: true @@ -90,6 +91,22 @@ contexts: - match: \b(?i:without\s+\w+)\b scope: storage.modifier.tsql + create-sequence: + - match: \b(?i:sequence)\b + scope: keyword.other.ddl.sql + set: + - create-sequence-args + - expect-other-creation-name + - create-other-condition + + create-sequence-args: + - match: \b(?i:as)\b + scope: keyword.context.block.sql + push: + - expect-type + - match: \b(?i:START\s+WITH|INCREMENT\s+BY|(?:NO\s+)?(?:MINVALUE|MAXVALUE|CYCLE|CACHE))\b + scope: keyword.other.ddl.basic + - include: create-common-args ###[ DDL STATEMENT PROTOTYPES ]################################################ @@ -185,7 +202,7 @@ contexts: set-target: - meta_prepend: true - - match: \b(?i:nocount|ansi_nulls|quoted_identifier)\b + - match: \b(?i:nocount|ansi_nulls|quoted_identifier|xact_abort)\b scope: constant.language.switch.tsql - match: \b(?i:identity_insert)\b scope: constant.language.switch.tsql @@ -194,6 +211,8 @@ contexts: - include: variables - include: augmented-assignment-operators - include: operators + - match: ',' + scope: punctuation.separator.sequence.tsql ###[ OTHER STATEMENTS ]######################################################## @@ -322,7 +341,7 @@ contexts: scope: storage.modifier.output.tsql - match: \b(?i:over|partition\s+by)\b scope: keyword.other.sql - - match: \b(?i:unbounded|preceding|following|current\s+row|(?:rows|range)\s+between)\b + - match: \b(?i:unbounded|preceding|following|current\s+row|(?:rows|range)\s+between|next\s+value)\b scope: keyword.other.sql - match: \b(?i:cursor)\b scope: support.type.tsql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index fc2ae8134c..1ec95397d6 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -327,6 +327,14 @@ SET NOCOUNT ON --^ keyword.other.dml -- ^^^^^^^ constant.language.switch -- ^^ constant.language.boolean +set nocount, xact_abort on +-- <- meta.statement.set keyword.other.dml +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set +-- ^^^^^^^ constant.language.switch +-- ^ punctuation.separator.sequence +-- ^^^^^^^^^^ constant.language.switch +-- ^^ constant.language.boolean + EXEC master.dbo.xp_fileexist @FromFile, @FileExists OUTPUT -- ^ keyword.control.flow.execute -- ^ - meta.procedure-name @@ -2319,3 +2327,19 @@ CREATE USER [foo] WITHOUT LOGIN WITH DEFAULT_SCHEMA=[bar] -- ^^^^ keyword.other.dml.sql GO -- <- keyword.control.flow.go.tsql - meta.statement.create + +GRANT CREATE SEQUENCE ON SCHEMA::Test TO [AdventureWorks\Larry]; +CREATE SEQUENCE Test.DecSeq + AS decimal(3,0) + START WITH 125 + INCREMENT BY 25 + MINVALUE 100 + MAXVALUE 200 + CYCLE + CACHE 3; +-- ^^^^^ meta.statement.create keyword.other.ddl + +SELECT NEXT VALUE FOR Test.DecSeq; +-- ^^^ keyword.other.dml +-- ^^^^^^^^^^ keyword.other +-- ^^^ keyword.other From 8073d9d2124848d06bdee993b3a0f0a98f404129 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 21 Aug 2023 23:33:51 +0300 Subject: [PATCH 211/250] [SQL] correctly scope TSQL table variable columns --- SQL/TSQL.sublime-syntax | 11 ++++++++++- SQL/tests/syntax/syntax_test_tsql.sql | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index d1db7f2c70..41dbff1fae 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -108,6 +108,11 @@ contexts: scope: keyword.other.ddl.basic - include: create-common-args + create-table-args: + - meta_prepend: true + - match: (?=\b(?i:as)\b) + pop: 1 + ###[ DDL STATEMENT PROTOTYPES ]################################################ alter-common: @@ -848,6 +853,8 @@ contexts: - maybe-with-table-options - maybe-filegroup - inside-column-declaration-list + - match: (?=\S) + pop: 1 inside-column-declaration-list: - meta_prepend: true @@ -894,7 +901,9 @@ contexts: table (?:{{enclosed_type_end}}|\b) scope: storage.type.sql - pop: 1 + set: + - create-table-args + - maybe-column-declaration-list - match: |- (?xi) {{types_with_optional_number}} diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 1ec95397d6..145e5c07d0 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1559,9 +1559,16 @@ USE AdventureWorks2012; GO DECLARE @MyTableVar table( EmpID INT NOT NULL, +-- ^^^^^^^^^^^^^^^^^^^^^ meta.table.sql meta.group.table-columns.sql +-- ^^^^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^ storage.type.sql OldVacationHours INT, NewVacationHours INT, - ModifiedDate datetime); + ModifiedDate datetime, + Primary Key (EmpID)); +-- ^^^^^^^^^^^ meta.table.sql meta.group.table-columns.sql storage.modifier.sql +-- ^ meta.table.sql meta.group.table-columns.sql punctuation.section.group.end.sql +-- ^ punctuation.terminator.statement.sql - meta.group UPDATE TOP (10) HumanResources.Employee -- ^^^ keyword.other.dml -- ^^^ keyword.other.dml From f7fffad313ba908f637d12e913eb7998dfa583f4 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 21 Aug 2023 23:34:11 +0300 Subject: [PATCH 212/250] [SQL] correctly scope TSQL transaction isolation levels --- SQL/TSQL.sublime-syntax | 15 +++++++++++++-- SQL/tests/syntax/syntax_test_tsql.sql | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 41dbff1fae..76059f059a 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -166,8 +166,9 @@ contexts: - join-on - maybe-table-alias - expect-table-name - - match: \b(?i:set)\b - scope: keyword.other.dml.tsql + # - match: \b(?i:set)\b + # scope: keyword.other.dml.tsql + # push: maybe-transaction-isolation-level - include: top dml-delete: @@ -212,6 +213,9 @@ contexts: - match: \b(?i:identity_insert)\b scope: constant.language.switch.tsql push: expect-table-name + - match: \b(?i:transaction\s+isolation\s+level)\b + scope: constant.language.switch.tsql + set: transaction-isolation-level - include: onoff-constants - include: variables - include: augmented-assignment-operators @@ -219,6 +223,13 @@ contexts: - match: ',' scope: punctuation.separator.sequence.tsql + transaction-isolation-level: + - match: \b(?i:READ\s+UNCOMMITTED|READ\s+COMMITTED|REPEATABLE\s+READ|SNAPSHOT|SERIALIZABLE)\b + scope: constant.language.tsql + pop: 1 + - match: (?=\S) + pop: 1 + ###[ OTHER STATEMENTS ]######################################################## other-statements: diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 145e5c07d0..0644fe6eec 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2350,3 +2350,9 @@ SELECT NEXT VALUE FOR Test.DecSeq; -- ^^^ keyword.other.dml -- ^^^^^^^^^^ keyword.other -- ^^^ keyword.other + +set transaction isolation level read committed; +-- <- meta.statement.set.sql keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql constant.language.switch.tsql +-- ^^^^^^^^^^^^^^ meta.statement.set.sql constant.language.tsql +-- ^ punctuation.terminator.statement.sql - meta.statement.set From cf6f6403914d08868834ce9fe574b3ea54024d32 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 23 Aug 2023 06:28:39 +0300 Subject: [PATCH 213/250] [SQL] improve scoping of function parameters in TSQL --- SQL/TSQL.sublime-syntax | 11 +++++++++ SQL/tests/syntax/syntax_test_tsql.sql | 34 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 76059f059a..eaef77b65c 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -483,12 +483,21 @@ contexts: ###[ FUNCTION EXPRESSIONS ]#################################################### expect-function-parameters: + - meta_prepend: true - match: (@){{simple_identifier}} scope: variable.parameter.tsql captures: 1: punctuation.definition.variable.tsql push: expect-type - include: comma-separators + + expect-parameter-name: + - match: (@){{simple_identifier}} + captures: + 0: variable.parameter.sql + 1: punctuation.definition.variable.tsql + - match: \b(?i:as)\b + scope: keyword.context.tsql - include: else-pop ###[ WITH EXPRESSIONS ]######################################################## @@ -944,6 +953,8 @@ contexts: inside-user-type: - meta_prepend: true - include: variables + - match: \b(?i:readonly)\b + scope: storage.modifier.tsql after-type: - meta_prepend: true diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 0644fe6eec..42d847ccd8 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1435,6 +1435,10 @@ END GO CREATE FUNCTION dbo.fn_GetAllEmployeeOfADepartment(@DeptID AS INT) +-- ^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.parameters.sql meta.group.sql +-- ^^^^^^^ variable.parameter.sql +-- ^^ keyword.context.tsql +-- ^^^ storage.type.sql RETURNS TABLE --^^^^^ keyword.other -- ^^^^^ storage.type @@ -1469,6 +1473,36 @@ CREATE FUNCTION foo() RETURNS My@TypeName -- ^^ support.type.sql - variable -- ^^^^^^^^^ support.type.sql variable.other.readwrite.sql +CREATE TYPE some_type AS TABLE ( + some_id int, + some_text varchar(64) +); + +CREATE FUNCTION dbo.select_something (@input some_type READONLY) RETURNS TABLE +-- ^^^^^^ variable.parameter.sql - support +-- ^^^^^^^^^ support.type.sql +-- ^^^^^^^^ storage.modifier.tsql + RETURN SELECT * FROM @input +-- ^^^^^^ keyword.context.block.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^^^^ keyword.other.dml.sql +-- ^ meta.table-name.sql variable.other.readwrite.sql punctuation.definition.variable.sql +-- ^^^^^ meta.table-name.sql variable.other.readwrite.sql +; + + +CREATE FUNCTION dbo.select_something_else (@input int, @another_input char(2)) RETURNS TABLE +-- ^ variable.parameter.sql punctuation.definition.variable.tsql +-- ^^^^^ variable.parameter.sql +-- ^^^ storage.type.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.definition.variable.tsql +-- ^^^^^^^^^^^^^^ variable.parameter.sql +-- ^^^^^^^ storage.type.sql + RETURN SELECT @input, @another_input +; + SELECT * FROM Department D CROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) AS func_call_results_table -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call From a107580b8ae89386d3efc8a99def9c1d2960b74d Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 22 Aug 2023 13:53:50 +0300 Subject: [PATCH 214/250] [SQL] move READONLY to after-type context in TSQL syntax --- SQL/SQL (basic).sublime-syntax | 2 +- SQL/TSQL.sublime-syntax | 4 ++-- SQL/tests/syntax/syntax_test_tsql.sql | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 30ea99fdf5..5d7c50233d 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -915,7 +915,7 @@ contexts: expect-user-type: - match: (?=\S) - set: [maybe-group, inside-user-type] + set: [maybe-group, after-type, inside-user-type] inside-user-type: # note: may contain foreign variable interpolation diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index eaef77b65c..a308320086 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -953,8 +953,6 @@ contexts: inside-user-type: - meta_prepend: true - include: variables - - match: \b(?i:readonly)\b - scope: storage.modifier.tsql after-type: - meta_prepend: true @@ -965,6 +963,8 @@ contexts: set: - maybe-table-alias - maybe-with-group + - match: \b(?i:readonly)\b + scope: storage.modifier.tsql - include: collate-expressions ###[ IDENTIFIERS ]############################################################# diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 42d847ccd8..3f5d61b5b0 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1481,7 +1481,7 @@ CREATE TYPE some_type AS TABLE ( CREATE FUNCTION dbo.select_something (@input some_type READONLY) RETURNS TABLE -- ^^^^^^ variable.parameter.sql - support -- ^^^^^^^^^ support.type.sql --- ^^^^^^^^ storage.modifier.tsql +-- ^^^^^^^^ storage.modifier.tsql - support RETURN SELECT * FROM @input -- ^^^^^^ keyword.context.block.sql -- ^^^^^^ keyword.other.dml.sql From bc5af53cf303f20e9f2081fcfb0e48f151eeb9ca Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 22 Aug 2023 14:04:06 +0300 Subject: [PATCH 215/250] [SQL] add support for CREATE TYPE ... AS TABLE --- SQL/SQL (basic).sublime-syntax | 5 +++++ SQL/tests/syntax/syntax_test_tsql.sql | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 5d7c50233d..4fcda8bf14 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -200,6 +200,11 @@ contexts: - include: maybe-condition create-other-args: + - match: \b(?i:(as)\s+(table))\b + captures: + 1: keyword.context.block.sql + 2: support.type.sql + set: maybe-column-declaration-list - match: \b(?i:as)\b scope: keyword.context.block.sql pop: 1 diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 3f5d61b5b0..c341aeb1bb 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1474,7 +1474,15 @@ CREATE FUNCTION foo() RETURNS My@TypeName -- ^^^^^^^^^ support.type.sql variable.other.readwrite.sql CREATE TYPE some_type AS TABLE ( +-- ^^^^^^^^^ entity.name.struct.other.sql +-- ^^ keyword.context.block.sql +-- ^^^^^ support.type.sql +-- ^ meta.group.table-columns.sql punctuation.section.group.begin.sql some_id int, +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.group.table-columns.sql +-- ^^^^^^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^ storage.type.sql +-- ^ punctuation.separator.sequence.sql some_text varchar(64) ); From 272041d5bc6aac49ce607ff5b46a07f5e2c037e9 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 22 Aug 2023 14:21:22 +0300 Subject: [PATCH 216/250] [SQL] support grant view server state in TSQL --- SQL/TSQL.sublime-syntax | 2 ++ SQL/tests/syntax/syntax_test_tsql.sql | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index a308320086..7e8cc8c04e 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -765,6 +765,8 @@ contexts: scope: constant.language.tsql - match: \b(?i:showplan)\b scope: constant.language.sql + - match: \b(?i:view\s+server\s+state)\b + scope: constant.language.sql qualified-identifier: # https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-transact-sql?view=sql-server-ver16#syntax diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index c341aeb1bb..7c4e04bb43 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2190,6 +2190,14 @@ GRANT SHOWPLAN TO AuditMonitor; -- ^^^^^^^^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql +grant view server state to somebody; +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^^ keyword.context.sql +-- ^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + ALTER ROLE buyers WITH NAME = purchasing; --^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql From 5b1f29de7d8929e30a420e7499d5e885862f60c6 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 22 Aug 2023 14:25:12 +0300 Subject: [PATCH 217/250] [SQL] support GRANT EXECUTE --- SQL/SQL (basic).sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_tsql.sql | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 4fcda8bf14..0c402f73f1 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -738,7 +738,7 @@ contexts: scope: constant.language.sql - match: \b(?i:(?:alter|create|drop|grant|revoke)\s+{{ddl_target}})\b scope: constant.language.sql - - match: \b(?i:select|insert|update|delete|truncate)\b + - match: \b(?i:select|insert|update|delete|truncate|execute)\b scope: constant.language.sql ###[ TABLE NAMES ]############################################################# diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 7c4e04bb43..5793c1ba24 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2198,6 +2198,15 @@ grant view server state to somebody; -- ^^^^^^^^ meta.username.sql -- ^ punctuation.terminator.statement.sql +grant execute on some_schema.some_procedure to somebody; +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.grant.sql +-- ^^ keyword.other.authorization.sql +-- ^^^^^^^ constant.language.sql +-- ^^ keyword.context.resource.tsql +-- ^^ keyword.context.sql +-- ^^^^^^^^ meta.username.sql +-- ^ punctuation.terminator.statement.sql + ALTER ROLE buyers WITH NAME = purchasing; --^^^^^^^^^^^^^^^^ meta.statement.alter.sql -- ^^ keyword.other.ddl.sql From 5b2d73d66575d2a61d0187a7f70cfc0c3094d38c Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 23 Aug 2023 14:23:46 +0300 Subject: [PATCH 218/250] [SQL] better support for MERGE statements in TSQL --- SQL/TSQL.sublime-syntax | 15 ++--- SQL/tests/syntax/syntax_test_tsql.sql | 85 ++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 7e8cc8c04e..9c18732448 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -154,18 +154,19 @@ contexts: - match: \b(?i:open|fetch(?:(?:\s+next)?\s+from)?|close|deallocate)\b scope: keyword.other.sql push: expect-cursor-name - - match: \b(?i:merge)\b + - match: \b(?i:merge(?:\s+into)?)\b scope: keyword.other.tsql push: - maybe-table-alias - expect-table-name - match: \b(?i:using)\b - scope: keyword.other.tsql + scope: keyword.context.resource.tsql push: - table-name-or-subquery - join-on - - maybe-table-alias - - expect-table-name + #- maybe-table-alias + #- maybe-with-table-options + - table-name-or-subquery # - match: \b(?i:set)\b # scope: keyword.other.dml.tsql # push: maybe-transaction-isolation-level @@ -509,9 +510,7 @@ contexts: with-table-options: - match: \b(?i:with)\b scope: keyword.other.dml.sql - push: - - maybe-table-alias - - maybe-with-group + push: maybe-with-group maybe-with-group: - include: with-group @@ -1090,6 +1089,8 @@ contexts: scope: support.variable.global.sql captures: 1: punctuation.definition.variable.sql + - match: '\$action\b' # has to be lowercase + scope: variable.language.tsql maybe-variable-scoped-function-call: - match: \s*\.(?=\s*\w+\s*\() diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 5793c1ba24..79fca7b955 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -1219,7 +1219,7 @@ MERGE sales.category t -- ^ meta.table-alias-name -- ^ - meta.table-alias-name USING sales.category_staging s --- ^^^^^ keyword.other +-- ^^^^^ keyword.context.resource.tsql -- ^ - meta.table-name -- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^ - meta.table-name - meta.table-alias-name @@ -2415,3 +2415,86 @@ set transaction isolation level read committed; -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.set.sql constant.language.switch.tsql -- ^^^^^^^^^^^^^^ meta.statement.set.sql constant.language.tsql -- ^ punctuation.terminator.statement.sql - meta.statement.set + + +declare @foo table (a int, b int) +declare @bar table (a int, b int) +declare @inserted table (action nvarchar(10), a int, b int) + +insert into @foo values + (1,2), + (3,4) + +insert into @bar values + (1,22), + (2,44) + +merge @foo foo +using @bar bar + on foo.a = bar.a +when matched then + update set foo.b = bar.b +when not matched then + insert (a,b) values (bar.a, bar.b) +output $action, inserted.* +into @inserted +; + +select * from @foo +select * from @inserted + +merge into @foo foo +-- ^^^^^^^ keyword.other.tsql +-- ^^^^ meta.table-name.sql variable.other.readwrite.sql +-- ^^^ meta.table-alias-name.sql +using (values ( +-- ^^ keyword.context.resource.tsql +-- ^ meta.group.sql punctuation.section.group.begin.sql +-- ^^^^^^ keyword.other.dml +-- ^ punctuation.section.group.begin.sql + 1, + 22 + )) AS +-- ^ meta.group.sql meta.group.sql punctuation.section.group.end.sql +-- ^ meta.group.sql punctuation.section.group.end.sql - meta.group meta.group +-- ^^ keyword.operator.assignment.alias.sql - meta.group + bar ( +-- ^^^ meta.table-alias-name.sql +-- ^ meta.group.sql punctuation.section.group.begin.sql + a, +-- ^ meta.group.sql meta.column-name.sql + b + ) + on foo.a = bar.a +when matched then + update set foo.b = bar.b +when not matched then + insert (a,b) values (bar.a, bar.b) + +output $action, inserted.* +-- ^^^ storage.modifier.output.tsql +-- ^^^^^^^ variable.language.tsql +into @inserted +; + +MERGE INTO some_schema.some_table WITH (holdlock) AS target +-- ^^^^^^^ keyword.other.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^ meta.group.sql punctuation.section.group.begin.sql +-- ^^^^^^^^ meta.group.sql constant.language.with.tsql +-- ^ meta.group.sql punctuation.section.group.end.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^ meta.table-alias-name.sql +USING some_schema.another_table AS source +-- ^^ keyword.context.resource.tsql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^^ meta.table-alias-name.sql +ON source.some_id = target.some_id +-- <- keyword.operator.join.sql +when matched then + update set target.b = source.b +when not matched then + insert (a,b) values (source.a, source.b); + From 8d22bf3a8e9d19b5f3acb7b48e43f863a144ea39 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 23 Aug 2023 14:26:15 +0300 Subject: [PATCH 219/250] [SQL] add support for DEFAULT when doing inserts --- SQL/TSQL.sublime-syntax | 2 ++ SQL/tests/syntax/syntax_test_tsql.sql | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 9c18732448..4362784ed4 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -1091,6 +1091,8 @@ contexts: 1: punctuation.definition.variable.sql - match: '\$action\b' # has to be lowercase scope: variable.language.tsql + - match: \b(?i:default)\b + scope: variable.language.tsql maybe-variable-scoped-function-call: - match: \s*\.(?=\s*\w+\s*\() diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 79fca7b955..bd3eee85fa 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2496,5 +2496,6 @@ ON source.some_id = target.some_id when matched then update set target.b = source.b when not matched then - insert (a,b) values (source.a, source.b); + insert (a,b,c) values (source.a, source.b, default); +-- ^^^^^^^ meta.group.sql variable.language.tsql From 42ea97d1ed26a238e56018ad1a31ac583c09c7e2 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 29 Aug 2023 12:40:52 +0300 Subject: [PATCH 220/250] [SQL] support cross join --- SQL/SQL (basic).sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_tsql.sql | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 0c402f73f1..bbc3e9f6d3 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -11,7 +11,7 @@ variables: simple_identifier_break: (?!\w) reserved: |- - (?xi: alter | create | delete | drop | from | grant | group | inner | insert | join + (?xi: alter | create | cross | delete | drop | from | grant | group | inner | insert | join | left | on | order | outer | revoke | right | select | set | truncate | union | update | where ) additional_reserved: (?!) diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index bd3eee85fa..768e1ab0b9 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2499,3 +2499,10 @@ when not matched then insert (a,b,c) values (source.a, source.b, default); -- ^^^^^^^ meta.group.sql variable.language.tsql + +INSERT INTO some_schema.some_table + (id, some_field) +SELECT main.id, other.another_field +FROM @table_variable AS main +CROSS JOIN some_func(@param) AS other +-- ^^^^^^^ keyword.other.dml.sql From b574398a0dcd0b433d4aabb5ab5663d117378323 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 29 Aug 2023 12:41:17 +0300 Subject: [PATCH 221/250] [SQL] support deadlock_priority in TSQL --- SQL/TSQL.sublime-syntax | 11 ++++++++++- SQL/tests/syntax/syntax_test_tsql.sql | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 4362784ed4..9183c39a12 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -209,7 +209,7 @@ contexts: set-target: - meta_prepend: true - - match: \b(?i:nocount|ansi_nulls|quoted_identifier|xact_abort)\b + - match: \b(?i:nocount|ansi_nulls|quoted_identifier|xact_abort|ansi_warnings|noexec|showplan_(?:all|text|xml))\b scope: constant.language.switch.tsql - match: \b(?i:identity_insert)\b scope: constant.language.switch.tsql @@ -217,6 +217,9 @@ contexts: - match: \b(?i:transaction\s+isolation\s+level)\b scope: constant.language.switch.tsql set: transaction-isolation-level + - match: \b(?i:deadlock_priority)\b + scope: constant.language.switch.tsql + set: deadlock-priority - include: onoff-constants - include: variables - include: augmented-assignment-operators @@ -231,6 +234,12 @@ contexts: - match: (?=\S) pop: 1 + deadlock-priority: + - match: \b(?i:low|normal|high)\b + scope: constant.language.tsql + pop: 1 + - include: else-pop + ###[ OTHER STATEMENTS ]######################################################## other-statements: diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 768e1ab0b9..df9c117909 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2499,6 +2499,22 @@ when not matched then insert (a,b,c) values (source.a, source.b, default); -- ^^^^^^^ meta.group.sql variable.language.tsql +DECLARE @deadlock_var NCHAR(3); +SET @deadlock_var = N'LOW'; + +SET DEADLOCK_PRIORITY @deadlock_var; +-- ^^^^^^^^^^^^^^^^^ constant.language.switch.tsql +-- ^ punctuation.definition.variable.sql +-- ^^^^^^^^^^^^ variable.other.readwrite.sql +-- ^ punctuation.terminator.statement.sql +SET DEADLOCK_PRIORITY NORMAL; +-- ^^^^^^^^^^^^^^^^^ constant.language.switch.tsql +-- ^^^^^^ constant.language.tsql +SET DEADLOCK_PRIORITY -10; +-- ^^^^^^^^^^^^^^^^^ constant.language.switch.tsql +-- ^ keyword.operator.arithmetic.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.terminator.statement.sql INSERT INTO some_schema.some_table (id, some_field) From cc2a8717795491b44abb710a37340756718ca2c8 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 25 Oct 2023 09:44:40 +0300 Subject: [PATCH 222/250] [SQL] add support for TSQL `ALTER TABLE ... WITH CHECK` and temp tables --- SQL/TSQL.sublime-syntax | 7 +++++ SQL/tests/syntax/syntax_test_tsql.sql | 37 +++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 9183c39a12..957e8b14fd 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -125,6 +125,11 @@ contexts: push: - expect-user-name + alter-table-args: + - meta_prepend: true + - match: \b(?i:with\s+check\b) + scope: keyword.other.ddl.tsql + target-options: - meta_prepend: true - include: with-table-options @@ -1056,6 +1061,8 @@ contexts: inside-simple-identifier-part: - meta_prepend: true - include: variables + - match: \# + scope: punctuation.definition.variable.tsql ###[ LITERALS ]################################################################ diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index df9c117909..7261d2939d 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -649,7 +649,8 @@ INNER JOIN bar (NOLOCK) ON bar.Title = foo.Title COLLATE DATABASE_DEFAULT AND IS SELECT DISTINCT * INTO ##global_temp_table -- ^ keyword.other.dml --- ^^^^^^^^^^^^^^^^^^^ meta.table-name +-- ^^ meta.table-name.sql punctuation.definition.variable.tsql +-- ^^^^^^^^^^^^^^^^^ meta.table-name - punctuation FROM some_long_table_name s LEFT OUTER JOIN another_long_table_name (NOLOCK) a ON s.blah = a.blah AND ISNULL(p.ok, '') = ISNULL(a.ok, '') COLLATE DATABASE_DEFAULT -- ^^^^^^^^^^^^ keyword.other.dml @@ -739,7 +740,8 @@ into #temp -- ^^^^^ meta.table-name from @A A -- ^ keyword.other.dml --- ^^ meta.table-name.sql variable.other.readwrite.sql +-- ^ meta.table-name.sql variable.other.readwrite.sql punctuation.definition.variable.sql +-- ^ meta.table-name.sql variable.other.readwrite.sql -- ^ meta.table-alias-name inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN(B.C) DESC) = B.ID --^^^^^^^^ keyword.other.dml @@ -2522,3 +2524,34 @@ SELECT main.id, other.another_field FROM @table_variable AS main CROSS JOIN some_func(@param) AS other -- ^^^^^^^ keyword.other.dml.sql + +DROP TABLE IF EXISTS #SampleTempTable; +GO +CREATE TABLE #SampleTempTable (id INT, message nvarchar(50)); +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ meta.table.sql entity.name.struct.table.sql +-- ^ punctuation.definition.variable.tsql +INSERT INTO #SampleTempTable VALUES (null, 'hello'); +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ meta.table-name.sql punctuation.definition.variable.tsql +-- ^^^^^^^^^^^^^^^ meta.table-name.sql - punctuation +INSERT INTO #SampleTempTable VALUES (10, null); +INSERT INTO #SampleTempTable VALUES (17, 'abc'); +INSERT INTO #SampleTempTable VALUES (17, 'yes'); +INSERT INTO #SampleTempTable VALUES (null, null); +GO + +SELECT * FROM #SampleTempTable WHERE id IS DISTINCT FROM 17; +DROP TABLE IF EXISTS #SampleTempTable; +GO + +ALTER TABLE a.b WITH CHECK +-- ^^^^^^^^^^ meta.statement.alter.sql keyword.other.ddl.tsql + ADD CONSTRAINT fk_b_c +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql + FOREIGN KEY (some_id) REFERENCES a.c (some_id); +-- ^^^^^^^^^^^ meta.statement.alter.sql storage.modifier.sql From 1f5edeea8c7d075b6727f66c919925ad0f4bbcc0 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 25 Oct 2023 09:51:49 +0300 Subject: [PATCH 223/250] [Go] add support for TSQL in language injections --- .../Go (Embedded TSQL).sublime-syntax | 19 +++++++++++++++++ ... Embedded Backtick Strings).sublime-syntax | 21 +++++++++++++++++++ Go/Go.sublime-syntax | 3 +++ Go/tests/syntax_test_go.go | 11 ++++++++++ 4 files changed, 54 insertions(+) create mode 100644 Go/Embeddings/Go (Embedded TSQL).sublime-syntax create mode 100644 Go/Embeddings/TSQL (for Go Embedded Backtick Strings).sublime-syntax diff --git a/Go/Embeddings/Go (Embedded TSQL).sublime-syntax b/Go/Embeddings/Go (Embedded TSQL).sublime-syntax new file mode 100644 index 0000000000..854c48f25e --- /dev/null +++ b/Go/Embeddings/Go (Embedded TSQL).sublime-syntax @@ -0,0 +1,19 @@ +%YAML 1.2 +--- +name: Go (Embedded T-SQL) +scope: source.go.embedded-backtick-string.tsql +version: 2 +hidden: true + +extends: Packages/Go/Embeddings/Go (Embedded Backtick String).sublime-syntax + +contexts: + match-raw-string: + # replaces Go.sublime-syntax#match-raw-string + - match: '`' + scope: meta.string.go string.quoted.backtick.go punctuation.definition.string.begin.go + embed: scope:source.tsql.go-embedded-backtick-string + embed_scope: meta.string.go meta.embedded.go source.sql.embedded.go + escape: '`' + escape_captures: + 0: meta.string.go string.quoted.backtick.go punctuation.definition.string.end.go diff --git a/Go/Embeddings/TSQL (for Go Embedded Backtick Strings).sublime-syntax b/Go/Embeddings/TSQL (for Go Embedded Backtick Strings).sublime-syntax new file mode 100644 index 0000000000..57128ea3ff --- /dev/null +++ b/Go/Embeddings/TSQL (for Go Embedded Backtick Strings).sublime-syntax @@ -0,0 +1,21 @@ +%YAML 1.2 +--- +name: T-SQL inside Go backtick string +scope: source.tsql.go-embedded-backtick-string +version: 2 +hidden: true + +extends: Packages/SQL/TSQL.sublime-syntax + +contexts: + prototype: + - meta_prepend: true + - include: scope:source.go#match-raw-text-content + + string-escape: + - meta_prepend: true + - include: scope:source.go#match-raw-string-content + + string-interpolation: + - meta_prepend: true + - include: scope:source.go#match-raw-string-content diff --git a/Go/Go.sublime-syntax b/Go/Go.sublime-syntax index ece8a70a52..258a0791e5 100644 --- a/Go/Go.sublime-syntax +++ b/Go/Go.sublime-syntax @@ -250,6 +250,9 @@ contexts: - match: (?i)sql\b scope: meta.annotation.parameters.go constant.other.language-name.go set: scope:source.go.embedded-backtick-string.sql#match-comment-magic-language-injection-inner + - match: (?i)t-?sql\b + scope: meta.annotation.parameters.go constant.other.language-name.go + set: scope:source.go.embedded-backtick-string.tsql#match-comment-magic-language-injection-inner - match: (?i)xml\b scope: meta.annotation.parameters.go constant.other.language-name.go set: scope:source.go.embedded-backtick-string.xml#match-comment-magic-language-injection-inner diff --git a/Go/tests/syntax_test_go.go b/Go/tests/syntax_test_go.go index 9dc2db5fb3..bcfa57413f 100644 --- a/Go/tests/syntax_test_go.go +++ b/Go/tests/syntax_test_go.go @@ -5783,6 +5783,17 @@ func lang_embedding() { not_sql_string = `select not sql` // ^^^^^^^^^^^^^^^^ meta.string.go string.quoted.backtick.go - source.sql + //language=t-sql + // <- comment.line.double-slash.go punctuation.definition.comment.go + //^^^^^^^^^^^^^^^ comment.line.double-slash.go + //^^^^^^^^ meta.annotation.identifier.go + // ^ meta.annotation keyword.operator.assignment.go + // ^^^^^ meta.annotation.parameters.go constant.other.language-name.go + sqlQuery = ` + SELECT id + FROM ##global_temp_table;` + // ^^ punctuation.definition.variable + response := &http.Response{ StatusCode: http.StatusUnauthorized, //language=json From d55ba7cc497fd18cc3c782d0e6227c78da7b686f Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 9 Sep 2023 10:39:24 +0200 Subject: [PATCH 224/250] [SQL] fix some case-insensitive flags --- SQL/SQL (basic).sublime-syntax | 6 +++--- SQL/TSQL.sublime-syntax | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index bbc3e9f6d3..4444969c16 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -150,7 +150,7 @@ contexts: - include: maybe-condition create-index: - - match: \b(?xi:(?:({{ddl_target_index_modifier}})\s+)?(index))\b + - match: \b(?i:(?:({{ddl_target_index_modifier}})\s+)?(index))\b captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql @@ -290,7 +290,7 @@ contexts: - include: immediately-pop drop-other: - - match: \b(?i:user)\b(?!\s+(?i:if)\b) + - match: \b(?i:user(?!\s+if))\b scope: storage.type.sql set: - grant @@ -347,7 +347,7 @@ contexts: - include: maybe-condition alter-index: - - match: \b(?:({{ddl_target_index_modifier}})\s+)?(index)\b + - match: \b(?i:(?:({{ddl_target_index_modifier}})\s+)?(index))\b captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 957e8b14fd..83bb54e106 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -206,7 +206,7 @@ contexts: joins: - meta_append: true - - match: (?i)\b(?:(?:cross|outer)\s+)?apply\b + - match: \b(?i:(?:(?:cross|outer)\s+)?apply)\b scope: keyword.other.dml.sql push: table-name-or-subquery From 071f96bf0658aef7acbfbf85298e7432e511a8d4 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 9 Sep 2023 18:55:40 +0200 Subject: [PATCH 225/250] [SQL] Improve JOIN syntax This commit... 1. refactors JOIN syntax and table-name-or-subquery - fixes nested table references with advanced join expressions 2. restricts table-samples to T-SQL syntax as MySQL doesn't support it. 3. introduces common alias contexts for both, column/table aliases. --- SQL/Cassandra.sublime-syntax | 3 +- SQL/MySQL.sublime-syntax | 158 +++++++++- SQL/SQL (basic).sublime-syntax | 137 +++++---- SQL/TSQL.sublime-syntax | 82 +++-- SQL/tests/syntax/syntax_test_mysql.sql | 397 ++++++++++++++++++++++++- SQL/tests/syntax/syntax_test_tsql.sql | 135 ++++----- 6 files changed, 734 insertions(+), 178 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index a1537ba808..b3a3d034d4 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -80,8 +80,7 @@ contexts: pop: 1 - include: else-pop - joins: - - match: \bjoin\b + join-expressions: [] ###[ OTHER STATEMENTS ]######################################################## diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index c19f97bb27..b80f8085b1 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -356,16 +356,26 @@ contexts: dml-statements: - meta_append: true + - include: index-hint-lists - match: \b(?i:insert(\s+(?:ignore\s+)?into)?)\b scope: keyword.other.dml.sql push: expect-table-name - match: \b(?i:limit)\b scope: keyword.other.dml.sql - joins: - - meta_append: true - - match: \b(?i:straight_join|natural)\b + join-expressions: + # https://mariadb.com/kb/en/join-syntax + - match: \b(?i:(?:(?:cross|inner|(?:natural\s+)?(?:left|right)(?:\s+outer)?)\s+|straight_)?join)\b + scope: keyword.other.dml.sql + push: + - join-condition + - table-name-or-subquery + + join-condition: + - meta_prepend: true + - match: \b(?i:using)\b scope: keyword.other.dml.sql + set: maybe-column-reference-list ###[ DML SET STATEMENTS ]###################################################### @@ -578,14 +588,7 @@ contexts: - match: \b(?i:concatenate|convert|lower|substring|translate|trim|upper)\b scope: support.function.string.sql - match: \b(?i:using)\b - scope: keyword.other.mysql - - table-name-or-subquery: - - meta_prepend: true - - meta_include_prototype: false - - match: (?=#) - pop: 1 - - include: comments + scope: keyword.other.dml.sql ###[ ALGORITHM EXPRESSIONS ]################################################### @@ -792,6 +795,23 @@ contexts: - include: intervals - include: time-units + maybe-partition-name-list: + - include: partition-name-list + - include: else-pop + + partition-name-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-partition-name-list + + inside-partition-name-list: + - meta_scope: meta.group.partitions.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: comma-separators + - include: expect-partition-names + ###[ TABLE EXPRESSIONS ]####################################################### table-options: @@ -803,7 +823,7 @@ contexts: push: expect-table-name - match: \b(?i:union)\b scope: variable.parameter.sql - push: maybe-table-reference-list + push: maybe-table-name-list # common table options - match: \b{{table_parameters}}\b scope: variable.parameter.sql @@ -822,14 +842,14 @@ contexts: - include: assignment-operators - include: expect-other-name - maybe-table-reference-list: + maybe-table-name-list: - match: \( scope: punctuation.section.sequence.begin.sql - set: inside-table-reference-list + set: inside-table-name-list - include: assignment-operators - include: else-pop - inside-table-reference-list: + inside-table-name-list: - meta_scope: meta.sequence.tables.sql - match: \) scope: punctuation.section.sequence.end.sql @@ -1005,6 +1025,114 @@ contexts: # named privilidge level: database, table or method - include: expect-other-name +###[ TABLE NAMES OR SUBQUERIES ]############################################### + + table-subquery: + # https://mariadb.com/kb/en/join-syntax + - match: \( + scope: punctuation.section.group.begin.sql + set: table-subquery-begin + - match: \{ + scope: punctuation.section.braces.begin.mysql + set: + - table-braced-subquery-body + - table-name-or-subquery + - table-braced-subquery-on + + table-braced-subquery-body: + - meta_scope: meta.braces.mysql + - match: \} + scope: punctuation.section.braces.end.mysql + pop: 1 + - include: join-expressions + + table-braced-subquery-on: + - match: \b(?i:on)\b + scope: keyword.other.dml.sql + pop: 1 + - include: else-pop + + table-subquery-begin: + - meta_include_prototype: false + - meta_scope: meta.group.sql + - include: comments + # table subquery + - match: (?=(?i:select)\b) + set: + - maybe-table-alias + - inside-group + # table reference list + - match: (?=\S) + set: inside-table-reference-list + + inside-table-reference-list: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: comma-separators + - include: expect-table-references + + expect-table-references: + - meta_include_prototype: false + - match: (?=\S) + push: + - join-condition + - table-name-or-subquery + + table-name-not-function-call: + - meta_include_prototype: false + - match: '' + set: + - maybe-index-hint-list + - maybe-table-alias + - table-name-fail-if-function-call + - table-name + - single-identifier + + maybe-table-alias: + - meta_prepend: true + - match: (?=(?i:force|ignore|on|use|using)\b) + pop: 1 + - match: \b(?i:partition)\b + scope: keyword.other.dml.sql + push: maybe-partition-name-list + +###[ INDEX HINTS ]############################################################# + + maybe-index-hint-list: + # https://mariadb.com/kb/en/join-syntax + - include: index-hint-lists + - include: comma-separators + - include: else-pop + + index-hint-lists: + - match: \b(?i:(?:force|ignore|use)\s+(?:index|key))\b + scope: keyword.other.dml.sql + push: + - maybe-index-name-list + - maybe-index-hint-target + + maybe-index-hint-target: + - match: \b(?i:for\s+(?:join|(?:group|order)\s+by))\b + scope: keyword.other.dml.sql + pop: 1 + - include: else-pop + + maybe-index-name-list: + - match: \( + scope: punctuation.section.sequence.begin.sql + set: inside-index-name-list + - include: else-pop + + inside-index-name-list: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: comma-separators + - include: expect-index-names + ###[ COLUMN DECLARATIONS ]##################################################### inside-column-declaration-list: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 4444969c16..d33657aa6a 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -455,10 +455,11 @@ contexts: scope: keyword.other.dml.sql push: expect-table-name - include: set-statements + # expressions - match: \b(?i:(?:default\s+)?values)\b scope: keyword.other.dml.II.sql - include: distinct - - include: joins + - include: join-expressions - match: \b(?i:group\s+by|order\s+by|having|where)\b scope: keyword.other.dml.sql - match: \b(?i:from)\b @@ -477,19 +478,25 @@ contexts: - match: \b(?i:distinct)\b scope: keyword.other.dml.sql - joins: - - match: \b(?i:(?:(?:inner|(?:full|left\s+)?outer|cross|left|right)\s+)?join)\b + join-expressions: + - match: \b(?i:(?:(?:cross|inner|(?:full|left|right)(?:\s+outer)?)\s+)?join)\b scope: keyword.other.dml.sql push: - - join-on + - join-condition - table-name-or-subquery - join-on: + join-condition: - match: \b(?i:on)\b - scope: keyword.operator.join.sql - pop: 1 + scope: keyword.control.conditional.sql + set: conditional-expression - include: else-pop + conditional-expression: + - match: (?=[,;)}]|\b(?:{{reserved}}|{{additional_reserved}})\b) + pop: 1 + - include: expressions + - include: expect-column-names + ###[ DML SET STATEMENTS ]###################################################### set-statements: @@ -563,7 +570,12 @@ contexts: alias-expressions: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql - push: expect-column-alias-name + push: expect-alias-name + + alias-expression: + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + set: expect-alias-name case-expressions: - match: \b(?i:case)\b @@ -741,16 +753,22 @@ contexts: - match: \b(?i:select|insert|update|delete|truncate|execute)\b scope: constant.language.sql -###[ TABLE NAMES ]############################################################# +###[ TABLE NAMES OR SUBQUERIES ]############################################### table-name-or-subquery: + - include: table-subquery + - include: table-name-or-function-call + + table-subquery: - match: (?=\() set: - maybe-table-alias - group + + table-name-or-function-call: - match: (?=\S) pop: 1 # pop `table-name-or-subquery` before evaluating branches - branch_point: table-or-table-function + branch_point: table-name-or-function-call branch: - table-name-not-function-call - table-valued-function-call @@ -759,6 +777,7 @@ contexts: - meta_include_prototype: false - match: '' set: + - maybe-table-alias - table-name-fail-if-function-call - table-name - single-identifier @@ -766,9 +785,9 @@ contexts: table-name-fail-if-function-call: - meta_include_prototype: false - match: (?=\() - fail: table-or-table-function + fail: table-name-or-function-call - match: (?=\S) - set: maybe-table-alias + pop: 1 table-valued-function-call: - meta_include_prototype: false @@ -785,42 +804,36 @@ contexts: - include: immediately-pop maybe-table-alias: - - match: \b(?i:as)\b - scope: keyword.operator.assignment.alias.sql - - match: (?=\S) - set: - - maybe-table-sample - - table-alias-name - - single-identifier + - include: pop-on-top-level-reserved-word + - include: table-timespecs + - include: alias-expression + - include: expect-alias-name - maybe-table-sample: - - match: \b(?i:tablesample(?:\s+system)?)\b - scope: keyword.other.sql + table-timespecs: + - match: \b(?i:for\s+system_time)\b + scope: keyword.other.dml.sql + push: table-timespec-args + + table-timespec-args: + - match: \b(?i:as\s+of|between|and|from|to)\b + scope: keyword.operator.logical.sql push: - - after-tablesample-group - - maybe-table-sample-group + - table-timespec-expression + - table-timespec-type + - match: \b(?i:all)\b + scope: constant.other.sql + pop: 1 - include: else-pop - maybe-table-sample-group: - - match: \( - scope: punctuation.section.group.begin.sql - set: inside-tablesample-group + table-timespec-type: + - match: \b(?i:timestamp|transaction)\b + scope: storage.type.sql + set: else-pop - include: else-pop - inside-tablesample-group: - - meta_scope: meta.group.tablesample.sql - - match: \) - scope: punctuation.section.group.end.sql - pop: 1 - - match: \b(?i:rows|percent)\b - scope: constant.language.sql + table-timespec-expression: - include: expressions - - after-tablesample-group: - - match: \b(?i:repeatable)\b - scope: constant.language.sql - pop: 1 - - include: else-pop + - include: immediately-pop ###[ COLUMN DECLARATIONS ]##################################################### @@ -933,6 +946,18 @@ contexts: ###[ IDENTIFIERS ]############################################################# + expect-alias-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [alias-name, single-identifier] + + alias-name: + - meta_include_prototype: false + - meta_content_scope: meta.alias.sql + - include: immediately-pop + expect-column-names: - match: (?=\S) push: [maybe-operator, column-name, single-identifier] @@ -961,13 +986,6 @@ contexts: - meta_content_scope: meta.column-name.sql variable.other.member.declaration.sql - include: immediately-pop - expect-column-alias-name: - # prevent prototypes from inheriting syntaxes - - meta_include_prototype: false - - include: comments - - match: (?=\S) - set: [column-alias-name, single-identifier] - expect-constraint-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false @@ -980,11 +998,6 @@ contexts: - meta_content_scope: meta.constraint-name.sql - include: immediately-pop - column-alias-name: - - meta_include_prototype: false - - meta_content_scope: meta.column-alias.sql - - include: immediately-pop - expect-database-creation-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false @@ -1080,6 +1093,10 @@ contexts: - meta_scope: entity.name.struct.partition.sql - include: immediately-pop + expect-partition-names: + - match: (?=\S) + push: [partition-name, single-identifier] + expect-partition-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false @@ -1137,18 +1154,6 @@ contexts: - meta_content_scope: meta.table-name.sql - include: immediately-pop - expect-table-alias-name: - # prevent prototypes from inheriting syntaxes - - meta_include_prototype: false - - include: comments - - match: (?=\S) - set: [table-alias-name, single-identifier] - - table-alias-name: - - meta_include_prototype: false - - meta_content_scope: meta.table-alias-name.sql - - include: immediately-pop - expect-user-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false @@ -1382,5 +1387,5 @@ contexts: pop: 1 pop-on-top-level-reserved-word: - - match: (?=[;)]|\b(?:{{reserved}}|{{additional_reserved}})\b) + - match: (?=[;)}]|\b(?:{{reserved}}|{{additional_reserved}})\b) pop: 1 diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 83bb54e106..13490f1981 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -164,14 +164,11 @@ contexts: push: - maybe-table-alias - expect-table-name - - match: \b(?i:using)\b + - match: \b(?i:using)\b # note: maybe valid only in merge statements scope: keyword.context.resource.tsql - push: - - table-name-or-subquery - - join-on - #- maybe-table-alias - #- maybe-with-table-options - - table-name-or-subquery + push: table-name-or-subquery + - match: \b(?i:on)\b + scope: keyword.control.conditional.sql # - match: \b(?i:set)\b # scope: keyword.other.dml.tsql # push: maybe-transaction-isolation-level @@ -185,6 +182,12 @@ contexts: - meta_prepend: true - include: top + join-expressions: + - meta_append: true + - match: \b(?i:(?:(?:cross|outer)\s+)?apply)\b + scope: keyword.other.dml.sql + push: table-name-or-subquery + top: - match: (?i)\b(top)\b(?:\s*(?:(\()\s*)?(\d+)(?:\s*(\)))?(?:\s+(percent\b))?)? captures: @@ -204,12 +207,6 @@ contexts: - include: expressions - include: else-pop - joins: - - meta_append: true - - match: \b(?i:(?:(?:cross|outer)\s+)?apply)\b - scope: keyword.other.dml.sql - push: table-name-or-subquery - ###[ DML SET STATEMENTS ]###################################################### set-target: @@ -817,13 +814,13 @@ contexts: - match: (?=\S) pop: true -###[ TABLE NAMES ]############################################################# +###[ TABLE NAMES OR SUBQUERIES ]############################################### - table-name-or-subquery: - - meta_prepend: true + table-subquery: + - meta_append: true - match: \b(?i:openxml)\b scope: meta.table-valued-function-name.sql support.function.tsql - push: + set: - maybe-with-column-definition - function-call-arguments - match: \b(?i:(openrowset))\s*(\() @@ -847,16 +844,55 @@ contexts: - include: table-hints-without-with maybe-table-alias: - - meta_prepend: true + - include: table-timespecs - include: with-table-options - match: (?=\b(?i:unpivot|pivot)\b) pop: 1 + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + set: expect-table-alias-name + - include: expect-table-alias-name + + expect-table-alias-name: + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: + - maybe-table-sample + - alias-name + - single-identifier maybe-table-sample: - - meta_prepend: true - - include: groups # column-alias-list + - include: groups # alias-list - include: table-hints-without-with - include: with-table-options + - match: \b(?i:tablesample(?:\s+system)?)\b + scope: keyword.other.sql + push: + - after-tablesample-group + - maybe-table-sample-group + - include: else-pop + + maybe-table-sample-group: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-tablesample-group + - include: else-pop + + inside-tablesample-group: + - meta_scope: meta.group.tablesample.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - match: \b(?i:rows|percent)\b + scope: constant.language.sql + - include: expressions + + after-tablesample-group: + - match: \b(?i:repeatable)\b + scope: constant.language.sql + pop: 1 + - include: else-pop table-hints-without-with: # https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-ver15#arguments @@ -879,6 +915,12 @@ contexts: set: maybe-column-declaration-list - include: else-pop + table-timespec-args: + - meta_prepend: true + - match: \b(?i:contained\s+in) + scope: keyword.operator.logical.tsql + set: maybe-group + ###[ COLUMN DECLARATIONS ]##################################################### maybe-column-declaration-list: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 603b08e5ef..bf56a4c2a7 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -2712,6 +2712,401 @@ SHOW GRANTS FOR CURRENT_USER(); -- ^^ meta.function-call.sql meta.group.sql +-- ---------------------------------------------------------------------------- +-- Join Syntax +-- https://mariadb.com/kb/en/join-syntax/ +-- +-- table_references: +-- table_reference [, table_reference] ... +-- +-- table_reference: +-- table_factor +-- | join_table +-- +-- table_factor: +-- tbl_name [PARTITION (partition_list)] +-- [query_system_time_period_specification] [[AS] alias] [index_hint_list] +-- | table_subquery [query_system_time_period_specification] [AS] alias +-- | ( table_references ) +-- | { ON table_reference LEFT OUTER JOIN table_reference +-- ON conditional_expr } +-- +-- join_table: +-- table_reference [INNER | CROSS] JOIN table_factor [join_condition] +-- | table_reference STRAIGHT_JOIN table_factor +-- | table_reference STRAIGHT_JOIN table_factor ON conditional_expr +-- | table_reference {LEFT|RIGHT} [OUTER] JOIN table_reference join_condition +-- | table_reference NATURAL [{LEFT|RIGHT} [OUTER]] JOIN table_factor +-- +-- join_condition: +-- ON conditional_expr +-- | USING (column_list) +-- +-- query_system_time_period_specification: +-- FOR SYSTEM_TIME AS OF point_in_time +-- | FOR SYSTEM_TIME BETWEEN point_in_time AND point_in_time +-- | FOR SYSTEM_TIME FROM point_in_time TO point_in_time +-- | FOR SYSTEM_TIME ALL +-- +-- point_in_time: +-- [TIMESTAMP] expression +-- | TRANSACTION expression +-- +-- index_hint_list: +-- index_hint [, index_hint] ... +-- +-- index_hint: +-- USE {INDEX|KEY} +-- [{FOR {JOIN|ORDER BY|GROUP BY}] ([index_list]) +-- | IGNORE {INDEX|KEY} +-- [{FOR {JOIN|ORDER BY|GROUP BY}] (index_list) +-- | FORCE {INDEX|KEY} +-- [{FOR {JOIN|ORDER BY|GROUP BY}] (index_list) +-- +-- index_list: +-- index_name [, index_name] ... +-- +-- ---------------------------------------------------------------------------- + +JOIN (table1 alias, table2 AS alias ON (col1=col2), table3 PARTITION(part1) USE KEY (id), IGNORE INDEX (foo) USING (col1)) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ meta.table-name.sql +-- ^^^^^ meta.alias.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.table-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^ meta.alias.sql +-- ^^ keyword.control.conditional.sql +-- ^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.table-name.sql +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^ meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ keyword.other.dml.sql +-- ^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql +-- ^ punctuation.section.group.end.sql + +JOIN ( ( SELECT * FROM foo JOIN bar IGNORE KEY id ) alias, ( table1, ( SELECT * FROM baz) ) alias ) +-- ^^ meta.group.sql - meta.group meta.group +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql meta.group.sql +-- ^^^^^^^^ meta.group.sql - meta.group meta.group +-- ^^^^^^^^^^ meta.group.sql meta.group.sql - meta.group meta.group meta.group +-- ^^^^^^^^^^^^^^^^^^^^ meta.group.sql meta.group.sql meta.group.sql +-- ^^ meta.group.sql meta.group.sql - meta.group meta.group meta.group +-- ^^^^^^^^ meta.group.sql - meta.group meta.group +-- ^ - meta.group +-- ^ punctuation.section.group.begin.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^ meta.table-name.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^ meta.table-name.sql +-- ^^^^^^^^^^ keyword.other.dml.sql +-- ^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ meta.alias.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ meta.table-name.sql +-- ^ punctuation.separator.sequence.sql + +-- ---------------------------------------------------------------------------- +-- table_reference +-- ---------------------------------------------------------------------------- + +INNER JOIN tbl_name PARTITION (part1, part2, part3) +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.section.group.end.sql + +INNER JOIN tbl_name alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^ meta.alias.sql + +INNER JOIN tbl_name AS alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^ meta.alias.sql + +INNER JOIN tbl_name PARTITION () alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^ meta.group.partitions.sql +-- ^^^^^ meta.alias.sql + +INNER JOIN tbl_name PARTITION () AS alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^ meta.group.partitions.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^ meta.alias.sql + +INNER JOIN tbl_name FOR SYSTEM_TIME ALL alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^ constant.other.sql +-- ^^^^^ meta.alias.sql + +INNER JOIN tbl_name FOR SYSTEM_TIME AS OF 20341 alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^ keyword.operator.logical.sql +-- ^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ meta.alias.sql + +INNER JOIN tbl_name FOR SYSTEM_TIME FROM 20341 TO 423204 alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^ keyword.operator.logical.sql +-- ^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^ keyword.operator.logical.sql +-- ^^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ meta.alias.sql + +INNER JOIN (SELECT * FROM tbl_name) alias USE KEY bar +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ meta.alias.sql +-- ^^^^^^^ keyword.other.dml.sql +-- ^^^ meta.column-name.sql + +INNER JOIN (SELECT * FROM tbl_name) PARTITION (part1, part2, part3) alias +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^ constant.other.wildcard.asterisk.sql +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.partition-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ meta.alias.sql + +INNER JOIN {ON tbl_name LEFT OUTER JOIN other1 other2 ON TRUE} +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.braces.mysql +-- ^^^^ keyword.other.dml.sql +-- ^ punctuation.section.braces.begin.mysql +-- ^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^ meta.table-name.sql +-- ^^^^^^ meta.alias.sql +-- ^^ keyword.control.conditional.sql +-- ^^^^ constant.language.boolean.sql +-- ^ punctuation.section.braces.end.mysql + +-- ---------------------------------------------------------------------------- +-- join_condition +-- ---------------------------------------------------------------------------- + +INNER JOIN tbl_name ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c) +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^ keyword.control.conditional.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^ meta.column-name.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^ meta.column-name.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ meta.column-name.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + +INNER JOIN tbl_name USING (col1, col2) +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + +INNER JOIN tbl_name alias USING (col1, col2) +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^^ meta.alias.sql +-- ^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + +INNER JOIN tbl_name AS alias USING (col1, col2) +-- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^ keyword.operator.assignment.alias.sql +-- ^^^^^ meta.alias.sql +-- ^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + +-- ---------------------------------------------------------------------------- +-- index_hint +-- ---------------------------------------------------------------------------- + +FORCE INDEX FOR JOIN (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +FORCE INDEX FOR ORDER BY (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +FORCE INDEX FOR GROUP BY (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +USE INDEX FOR JOIN (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +USE INDEX FOR ORDER BY (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +USE INDEX FOR GROUP BY (index1, index2, index3) +-- <- keyword.other.dml.sql +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +SELECT * FROM table FORCE INDEX FOR GROUP BY (Name) +-- ^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + +SELECT * FROM table USE INDEX FOR GROUP BY (Name) +-- ^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^ meta.group.sql +-- ^ punctuation.section.sequence.begin.sql +-- ^^^^ meta.index-name.sql +-- ^ punctuation.section.group.end.sql + + -- ---------------------------------------------------------------------------- -- Legacy Tests -- ---------------------------------------------------------------------------- @@ -2812,7 +3207,7 @@ SELECT *, -- ^ constant.other.wildcard.asterisk.sql f.id AS database_id -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^^^^^^^ meta.column-alias +-- ^^^^^^^^^^^ meta.alias FROM foo WHERE f.a IS NULL -- ^^ keyword.other.dml.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 7261d2939d..a04ada42ab 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -432,7 +432,7 @@ SELECT foo AS foobar, COUNT(*) AS tally -- ^^^ keyword.other.dml -- ^^^ meta.column-name -- ^^ keyword.operator.assignment.alias --- ^^^^^^ meta.column-alias +-- ^^^^^^ meta.alias -- ^ punctuation.separator.sequence -- ^^^^^^^^ meta.function-call -- ^^^^^ support.function.aggregate @@ -441,7 +441,7 @@ SELECT foo AS foobar, COUNT(*) AS tally -- ^ constant.other.wildcard.asterisk -- ^ punctuation.section.arguments.end -- ^^ keyword.operator.assignment.alias --- ^^^^^ meta.column-alias +-- ^^^^^ meta.alias FROM bar -- ^ keyword.other.dml -- ^^^ meta.table-name @@ -458,7 +458,7 @@ from (select * from some_table) alias_table WITH (NOLOCK) -- ^ constant.other.wildcard.asterisk -- ^^^^^^^^^^ meta.table-name -- ^ punctuation.section.group.end --- ^^^^^^^^^^^ meta.table-alias-name +-- ^^^^^^^^^^^ meta.alias -- ^^^^ keyword.other.dml -- ^ punctuation.section.group.begin -- ^^^^^^ meta.group constant.language.with @@ -482,9 +482,9 @@ FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^ keyword.other.dml -- ^ - meta.table-name -- ^^^^^^^^^^^^^ meta.table-name --- ^ - meta.table-name - meta.table-alias-name --- ^^^^^^^^^^ meta.table-alias-name --- ^ - meta.table-alias-name +-- ^ - meta.table-name - meta.alias +-- ^^^^^^^^^^ meta.alias +-- ^ - meta.alias -- ^^^^ keyword.other -- ^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ - meta.group @@ -493,21 +493,21 @@ FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^ punctuation.separator.sequence -- ^^^^^^^^^ meta.group constant.language.with -- ^ punctuation.section.group.end -INNER JOIN some_view AS v WITH (NOLOCK) ON v.some_id = TableAlias.some_id +INNER JOIN some_view AS AS WITH (NOLOCK) ON v.some_id = TableAlias.some_id -- ^^^^^^^ keyword.other.dml -- ^ - meta.table-name -- ^^^^^^^^^ meta.table-name -- ^ - meta.table-name -- ^^ keyword.operator.assignment.alias --- ^ - meta.table-alias-name --- ^ meta.table-alias-name --- ^ - meta.table-alias-name +-- ^ - meta.alias +-- ^^ meta.alias +-- ^ - meta.alias -- ^^^^ keyword.other.dml -- ^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^ constant.language.with -- ^ punctuation.section.group.end --- ^^ keyword.operator.join +-- ^^ keyword.control.conditional -- ^ - meta.column-name -- ^^^^^^^^^ meta.column-name -- ^ punctuation.accessor.dot @@ -527,9 +527,9 @@ WHERE TableAlias.some_id IN ( -- ^^^^ keyword.other.dml -- ^ - meta.table-name -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name --- ^ - meta.table-name - meta.table-alias-name --- ^ meta.table-alias-name --- ^ - meta.table-alias-name +-- ^ - meta.table-name - meta.alias +-- ^ meta.alias +-- ^ - meta.alias WHERE a.another_id_column IS NOT NULL -- ^^^^^ keyword.other.dml -- ^ - meta.column-name - keyword @@ -599,7 +599,7 @@ SELECT i.ProductID, p.Name, i.LocationID, i.Quantity -- ^^^^^^^^ meta.group keyword.other.dml -- ^^^^ meta.group keyword.other.order -- ^^ keyword.operator.assignment.alias --- ^^^^ meta.column-alias +-- ^^^^ meta.alias FROM Production.ProductInventory AS i INNER JOIN Production.Product AS p ON i.ProductID = p.ProductID @@ -630,7 +630,7 @@ INNER JOIN bar (NOLOCK) ON bar.Title = foo.Title COLLATE DATABASE_DEFAULT AND IS -- ^^^^^^^ keyword.other.dml -- ^^^ meta.table-name -- ^^^^^^ meta.group invalid.deprecated.table-hint-without-with.tsql constant.language.table-hint.tsql --- ^^ keyword.operator.join +-- ^^ keyword.control.conditional -- ^^^^^^^^^ meta.column-name -- ^ keyword.operator.comparison -- ^^^^^^^^^ meta.column-name @@ -656,8 +656,8 @@ LEFT OUTER JOIN another_long_table_name (NOLOCK) a ON s.blah = a.blah AND ISNULL -- ^^^^^^^^^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^^^^^^ invalid.deprecated.table-hint-without-with.tsql constant.language.table-hint.tsql --- ^ meta.table-alias-name --- ^^ keyword.operator.join +-- ^ meta.alias +-- ^^ keyword.control.conditional -- ^^^^^^ meta.column-name -- ^ keyword.operator.comparison -- ^^^^^^ meta.column-name @@ -742,11 +742,11 @@ from @A A -- ^ keyword.other.dml -- ^ meta.table-name.sql variable.other.readwrite.sql punctuation.definition.variable.sql -- ^ meta.table-name.sql variable.other.readwrite.sql --- ^ meta.table-alias-name +-- ^ meta.alias inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN(B.C) DESC) = B.ID --^^^^^^^^ keyword.other.dml -- ^ meta.table-name --- ^^ keyword.operator.join +-- ^^ keyword.control.conditional -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^^^^^ keyword.other.dml @@ -1089,7 +1089,7 @@ PIVOT -- ^ punctuation.separator.sequence ) AS PivotTable; --^^ keyword.operator.assignment.alias --- ^^^^^^^^^^ meta.table-alias-name +-- ^^^^^^^^^^ meta.alias -- ^ punctuation.terminator.statement SELECT item.ID AS DatePivotID, @@ -1099,7 +1099,7 @@ UNPIVOT (dDate FOR nDate IN (date1, date2, date3, date4)) AS item -- <- keyword.other -- ^^^^ keyword.other -- ^^ keyword.operator.assignment.alias --- ^^^^ meta.table-alias-name +-- ^^^^ meta.alias GROUP BY item.ID -- ^^^^^ keyword.other.dml @@ -1131,7 +1131,7 @@ UNPIVOT ) AS unpvt; -- <- meta.group punctuation.section.group.end --^^ keyword.operator.assignment.alias --- ^^^^^ meta.table-alias-name +-- ^^^^^ meta.alias -- ^ punctuation.terminator.statement GO @@ -1217,18 +1217,18 @@ MERGE sales.category t -- ^^ keyword.other -- ^ - meta.table-name -- ^^^^^^^^^^^^^^ meta.table-name --- ^ - meta.table-name - meta.table-alias-name --- ^ meta.table-alias-name --- ^ - meta.table-alias-name +-- ^ - meta.table-name - meta.alias +-- ^ meta.alias +-- ^ - meta.alias USING sales.category_staging s -- ^^^^^ keyword.context.resource.tsql -- ^ - meta.table-name -- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name --- ^ - meta.table-name - meta.table-alias-name --- ^ meta.table-alias-name --- ^ - meta.table-alias-name +-- ^ - meta.table-name - meta.alias +-- ^ meta.alias +-- ^ - meta.alias ON (s.category_id = t.category_id) --- <- keyword.operator.join +-- <- keyword.control.conditional -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group -- ^^^^^^^^^^^^^ meta.column-name -- ^ keyword.operator.comparison @@ -1522,7 +1522,7 @@ CROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) AS func_call_resu -- ^^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.section.arguments.end -- ^^ keyword.operator.assignment.alias - meta.function-call --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-alias-name +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.alias GO SELECT * FROM Department D @@ -1544,7 +1544,7 @@ CROSS APPLY sys.dm_exec_sql_text(r.plan_handle) st -- ^ meta.function-call meta.group punctuation.section.arguments.begin -- ^^^^^^^^^^^^^ meta.function-call meta.group meta.column-name -- ^ meta.function-call meta.group punctuation.section.arguments.end --- ^^ meta.table-alias-name +-- ^^ meta.alias WHERE r.session_Id > 50 -- Consider spids for users only, no system spids. AND r.session_Id NOT IN (@@SPID) -- Don't include request from current spid. -- ^ meta.group punctuation.section.group.begin @@ -1566,7 +1566,7 @@ SELECT p.BusinessEntityID , -- ^^^^^^^^^^^^^^^^^ variable.function -- ^ punctuation.accessor.dot FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) --- ^ meta.table-alias-name +-- ^ meta.alias -- ^^^^^^^^^^^ keyword.other -- ^^^^^^^^^^^^ meta.group.tablesample -- ^ punctuation.section.group.begin @@ -1578,7 +1578,7 @@ FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) -- ^^^ meta.group meta.number.integer.decimal constant.numeric.value -- ^ meta.group punctuation.section.group.end LEFT OUTER JOIN Person.PersonPhone AS pp TABLESAMPLE SYSTEM (10 ROWS) --- ^^ meta.table-alias-name +-- ^^ meta.alias -- ^^^^^^^^^^^^^^^^^^ keyword.other -- ^^^^^^^^^ meta.group.tablesample -- ^ punctuation.section.group.begin @@ -1586,7 +1586,7 @@ FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) -- ^^^^ constant.language -- ^ punctuation.section.group.end ON pp.BusinessEntityID = p.BusinessEntityID --- ^^ keyword.operator.join +-- ^^ keyword.control.conditional -- ^^^^^^^^^^^^^^^^^^^ meta.column-name -- ^ keyword.operator.comparison -- ^^^^^^^^^^^^^^^^^^ meta.column-name @@ -1741,12 +1741,12 @@ SELECT * FROM table_name AS t1 INNER JOIN (SELECT foo FROM bar) AS t2(id) ON t2.ID = t1.ID -- ^^ keyword.operator.assignment.alias --- ^^ meta.table-alias-name +-- ^^ meta.alias -- ^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^ meta.column-name -- ^ punctuation.section.group.end --- ^^ keyword.operator.join +-- ^^ keyword.control.conditional ---- SELECT a.* @@ -1762,7 +1762,7 @@ SELECT a.* Customers) AS a; -- ^ meta.function-call meta.group punctuation.section.arguments.end -- ^^ keyword.operator.assignment.alias - meta.group - meta.function-call --- ^ meta.table-alias-name +-- ^ meta.alias DECLARE @Data NVARCHAR(MAX) -- ^^^^^^^^^^^^^ storage.type.sql @@ -2334,7 +2334,7 @@ SELECT TOP 10 City, STRING_AGG(CONVERT(NVARCHAR(max), EmailAddress), ';') WITHIN -- ^^^ meta.group.sql keyword.other.order.sql -- ^ meta.group.sql punctuation.section.group.end.sql -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^^ meta.column-alias.sql +-- ^^^^^^ meta.alias.sql FROM Person.BusinessEntityAddress AS BEA INNER JOIN Person.Address AS A ON BEA.AddressID = A.AddressID INNER JOIN Person.EmailAddress AS EA ON BEA.BusinessEntityID = EA.BusinessEntityID @@ -2448,7 +2448,7 @@ select * from @inserted merge into @foo foo -- ^^^^^^^ keyword.other.tsql -- ^^^^ meta.table-name.sql variable.other.readwrite.sql --- ^^^ meta.table-alias-name.sql +-- ^^^ meta.alias.sql using (values ( -- ^^ keyword.context.resource.tsql -- ^ meta.group.sql punctuation.section.group.begin.sql @@ -2461,7 +2461,7 @@ using (values ( -- ^ meta.group.sql punctuation.section.group.end.sql - meta.group meta.group -- ^^ keyword.operator.assignment.alias.sql - meta.group bar ( --- ^^^ meta.table-alias-name.sql +-- ^^^ meta.alias.sql -- ^ meta.group.sql punctuation.section.group.begin.sql a, -- ^ meta.group.sql meta.column-name.sql @@ -2487,14 +2487,14 @@ MERGE INTO some_schema.some_table WITH (holdlock) AS target -- ^^^^^^^^ meta.group.sql constant.language.with.tsql -- ^ meta.group.sql punctuation.section.group.end.sql -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^^ meta.table-alias-name.sql +-- ^^^^^^ meta.alias.sql USING some_schema.another_table AS source -- ^^ keyword.context.resource.tsql -- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name.sql -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^^ meta.table-alias-name.sql +-- ^^^^^^ meta.alias.sql ON source.some_id = target.some_id --- <- keyword.operator.join.sql +-- <- keyword.control.conditional.sql when matched then update set target.b = source.b when not matched then @@ -2525,33 +2525,20 @@ FROM @table_variable AS main CROSS JOIN some_func(@param) AS other -- ^^^^^^^ keyword.other.dml.sql -DROP TABLE IF EXISTS #SampleTempTable; -GO -CREATE TABLE #SampleTempTable (id INT, message nvarchar(50)); --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql --- ^^^ keyword.other.ddl.sql --- ^^^^^^^^^^^^^^^^ meta.table.sql entity.name.struct.table.sql --- ^ punctuation.definition.variable.tsql -INSERT INTO #SampleTempTable VALUES (null, 'hello'); --- ^^^^^^^^ keyword.other.dml.sql --- ^ meta.table-name.sql punctuation.definition.variable.tsql --- ^^^^^^^^^^^^^^^ meta.table-name.sql - punctuation -INSERT INTO #SampleTempTable VALUES (10, null); -INSERT INTO #SampleTempTable VALUES (17, 'abc'); -INSERT INTO #SampleTempTable VALUES (17, 'yes'); -INSERT INTO #SampleTempTable VALUES (null, null); -GO - -SELECT * FROM #SampleTempTable WHERE id IS DISTINCT FROM 17; -DROP TABLE IF EXISTS #SampleTempTable; -GO - -ALTER TABLE a.b WITH CHECK --- ^^^^^^^^^^ meta.statement.alter.sql keyword.other.ddl.tsql - ADD CONSTRAINT fk_b_c --- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql --- ^^^ keyword.other.ddl.sql --- ^^^^^^^^^^ keyword.other.ddl.sql --- ^^^^^^ meta.constraint-name.sql - FOREIGN KEY (some_id) REFERENCES a.c (some_id); --- ^^^^^^^^^^^ meta.statement.alter.sql storage.modifier.sql +SELECT * FROM table FOR SYSTEM_TIME AS OF 131512 alias +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^ keyword.operator.logical +-- ^^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^ meta.alias.sql + +SELECT * FROM table FOR SYSTEM_TIME CONTAINED IN (131512, 231) alias +-- ^^^^^^^^^^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^ keyword.operator.logical +-- ^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ meta.alias.sql +-- From 1cf5566fb5a4023191598c24e79ef52ca19f46ea Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 16 Sep 2023 18:18:33 +0200 Subject: [PATCH 226/250] [SQL] Fix maybe-on-table-name This commit... 1. renames `on-tables` context to `on-table-names` to be more explicit. Maybe there will be an `on-tables` which uses `table-name-or-subquery` in the future. 2. --- SQL/MySQL.sublime-syntax | 7 +++---- SQL/PostgreSQL.sublime-syntax | 4 ++-- SQL/SQL (basic).sublime-syntax | 14 +++++++------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index b80f8085b1..aeb27096ee 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -1036,8 +1036,7 @@ contexts: scope: punctuation.section.braces.begin.mysql set: - table-braced-subquery-body - - table-name-or-subquery - - table-braced-subquery-on + - maybe-on-table table-braced-subquery-body: - meta_scope: meta.braces.mysql @@ -1046,10 +1045,10 @@ contexts: pop: 1 - include: join-expressions - table-braced-subquery-on: + maybe-on-table: - match: \b(?i:on)\b scope: keyword.other.dml.sql - pop: 1 + set: table-name-or-subquery - include: else-pop table-subquery-begin: diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 1c1c919ee2..7af2a977f7 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -123,7 +123,7 @@ contexts: - meta_prepend: true - match: \b(?i:after(?:\s+(?:insert|update|or))+)\b scope: keyword.other.psql - push: maybe-on-table + push: maybe-on-table-name - match: \b(?i:for\s+each\s+row\s+execute\s+procedure)\b scope: keyword.other.psql @@ -188,7 +188,7 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ - on-tables: + on-table-names: - match: \b(?i:(on)(?:\s+(only))?)\b captures: 1: keyword.other.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index d33657aa6a..4d9d4093f4 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -165,7 +165,7 @@ contexts: create-index-args: - meta_scope: meta.index.sql - - include: on-tables + - include: on-table-names - include: create-common-args create-table: @@ -209,7 +209,7 @@ contexts: scope: keyword.context.block.sql pop: 1 - include: grant - - include: on-tables + - include: on-table-names - include: create-common-args create-common-args: @@ -268,7 +268,7 @@ contexts: drop-index-args: - meta_scope: meta.index.sql - - include: maybe-on-table + - include: maybe-on-table-name drop-table: - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b @@ -308,7 +308,7 @@ contexts: - include: maybe-condition drop-other-args: - - include: maybe-on-table + - include: maybe-on-table-name ###[ DDL ALTER STATEMENTS ]#################################################### @@ -429,11 +429,11 @@ contexts: ###[ DDL STATEMENT PROTOTYPES ]################################################ - maybe-on-table: - - include: on-tables + maybe-on-table-name: + - include: on-table-names - include: else-pop - on-tables: + on-table-names: - match: \b(?i:on)\b scope: keyword.other.sql push: expect-table-name From 91761383360b1eaa70f3533688c86c891bcc161d Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sun, 17 Sep 2023 17:47:52 +0200 Subject: [PATCH 227/250] [SQL] Rename column-reference-list This commit renames column reference contexts to `column-name-list` and arranges their section alphabetically within expressions. --- SQL/Cassandra.sublime-syntax | 4 +- SQL/MySQL.sublime-syntax | 22 ++--- SQL/PostgreSQL.sublime-syntax | 14 ++-- SQL/SQL (basic).sublime-syntax | 148 ++++++++++++++++----------------- SQL/TSQL.sublime-syntax | 43 +++++----- 5 files changed, 115 insertions(+), 116 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index b3a3d034d4..cac4e4c6fc 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -143,7 +143,7 @@ contexts: - match: '{{simple_identifier}}' scope: meta.mapping.key.cql string.unquoted.cql -###[ COLUMN DECLARATIONS ]##################################################### +###[ COLUMN EXPRESSIONS ]###################################################### inside-column-declaration-list: - meta_scope: meta.group.table-columns.sql @@ -158,7 +158,7 @@ contexts: - match: \b(?i:primary\s+key)\b scope: storage.modifier.cql - include: expressions - - include: column-declaration + - include: expect-column-declarations inside-partition-key: - meta_content_scope: meta.group.partition-key.cql diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index aeb27096ee..3ec182c3cc 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -375,7 +375,7 @@ contexts: - meta_prepend: true - match: \b(?i:using)\b scope: keyword.other.dml.sql - set: maybe-column-reference-list + set: maybe-column-name-list ###[ DML SET STATEMENTS ]###################################################### @@ -614,6 +614,15 @@ contexts: scope: variable.parameter.definer.sql push: maybe-user-assignment +###[ COLUMN EXPRESSIONS ]###################################################### + + inside-column-declaration-list: + - meta_prepend: true + - match: \b(?i:auto_increment)\b + scope: storage.modifier.sql + - match: \b(?i:(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)) + scope: keyword.other.object-comments.sql + ###[ EVENT EXPRESSIONS ]####################################################### event-options: @@ -789,7 +798,7 @@ contexts: push: maybe-group - match: \b(?i:key)\b scope: support.function.sql - push: maybe-column-reference-list + push: maybe-column-name-list - match: \b(?i:limit|system_time)\b scope: keyword.other.sql - include: intervals @@ -1132,15 +1141,6 @@ contexts: - include: comma-separators - include: expect-index-names -###[ COLUMN DECLARATIONS ]##################################################### - - inside-column-declaration-list: - - meta_prepend: true - - match: \b(?i:auto_increment)\b - scope: storage.modifier.sql - - match: \b(?i:(comment\s+on\s+(table|column|aggregate|constraint|database|domain|function|index|operator|rule|schema|sequence|trigger|type|view))\s+.*?\s+(is)) - scope: keyword.other.object-comments.sql - ###[ TYPES ]################################################################### intervals: diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 7af2a977f7..aac510eeff 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -206,6 +206,13 @@ contexts: - match: \] scope: punctuation.section.brackets.end.psql +###[ COLUMN EXPRESSIONS ]###################################################### + + inside-column-declaration-list: + - meta_prepend: true + - match: \b(?i:unique)\b + scope: keyword.other.psql + ###[ EXTENSION EXPRESSIONS ]################################################### extension-attributes: @@ -221,13 +228,6 @@ contexts: scope: keyword.other.ddl.sql pop: 1 -###[ COLUMN DECLARATIONS ]##################################################### - - inside-column-declaration-list: - - meta_prepend: true - - match: \b(?i:unique)\b - scope: keyword.other.psql - ###[ IDENTIFIERS ]############################################################# expect-extension-name: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 4d9d4093f4..c8203147d6 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -682,6 +682,79 @@ contexts: pop: 1 - include: sql +###[ COLUMN EXPRESSIONS ]###################################################### + + maybe-column-declaration-list: + - include: column-declaration-list + - include: else-pop + + column-declaration-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-column-declaration-list + + inside-column-declaration-list: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - match: \b(?i:constraint)\b + scope: storage.modifier.sql + push: expect-constraint-name + - include: column-modifiers + - include: expressions + - include: expect-column-declarations + + expect-column-declarations: + - match: (?=\S) + push: + - after-type + - expect-type + - column-name-declaration + - single-identifier + + maybe-column-modifier: + - include: column-modifiers + - include: else-pop + + column-modifiers: + - match: \b(?i:check)\b + scope: keyword.other.sql + - match: |- + \b(?xi: + (?: (?: foreign | fulltext | primary | unique ) \s+ )? key + | on \s+ (?: delete | update ) (?: \s+ cascade )? + | default + )\b + scope: storage.modifier.sql + push: maybe-column-name-list + - match: \b(?i:references)\b + scope: storage.modifier.sql + push: + - maybe-column-name-list + - expect-table-name + + maybe-column-name-list: + - include: column-name-list + - include: else-pop + + column-name-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-column-name-list + + column-name-lists: + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-column-name-list + + inside-column-name-list: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: expressions-or-column-names + ###[ FUNCTION EXPRESSIONS ]#################################################### expect-function-parameters: @@ -745,7 +818,7 @@ contexts: - include: pop-on-top-level-reserved-word user-privileges: - - include: column-reference-lists + - include: column-name-lists - match: \b(?i:all(?:\s+privileges)?)\b scope: constant.language.sql - match: \b(?i:(?:alter|create|drop|grant|revoke)\s+{{ddl_target}})\b @@ -835,79 +908,6 @@ contexts: - include: expressions - include: immediately-pop -###[ COLUMN DECLARATIONS ]##################################################### - - maybe-column-declaration-list: - - include: column-declaration-list - - include: else-pop - - column-declaration-list: - - match: \( - scope: punctuation.section.group.begin.sql - set: inside-column-declaration-list - - inside-column-declaration-list: - - meta_scope: meta.group.table-columns.sql - - match: \) - scope: punctuation.section.group.end.sql - pop: 1 - - match: \b(?i:constraint)\b - scope: storage.modifier.sql - push: expect-constraint-name - - include: column-modifiers - - include: expressions - - include: column-declaration - - column-declaration: - - match: (?=\S) - push: - - after-type - - expect-type - - column-name-declaration - - single-identifier - - maybe-column-modifier: - - include: column-modifiers - - include: else-pop - - column-modifiers: - - match: \b(?i:check)\b - scope: keyword.other.sql - - match: |- - \b(?xi: - (?: (?: foreign | fulltext | primary | unique ) \s+ )? key - | on \s+ (?: delete | update ) (?: \s+ cascade )? - | default - )\b - scope: storage.modifier.sql - push: maybe-column-reference-list - - match: \b(?i:references)\b - scope: storage.modifier.sql - push: - - maybe-column-reference-list - - expect-table-name - - maybe-column-reference-list: - - include: column-reference-list - - include: else-pop - - column-reference-list: - - match: \( - scope: punctuation.section.group.begin.sql - set: inside-column-reference-list - - column-reference-lists: - - match: \( - scope: punctuation.section.group.begin.sql - push: inside-column-reference-list - - inside-column-reference-list: - - meta_scope: meta.group.table-columns.sql - - match: \) - scope: punctuation.section.group.end.sql - pop: 1 - - include: expressions-or-column-names - ###[ TYPES ]################################################################### expect-type: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 13490f1981..6b3a45a863 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -340,7 +340,7 @@ contexts: scope: keyword.other.dml.sql push: - cte-as - - maybe-column-reference-list + - maybe-column-name-list - expect-cte-table-name - match: \b(?i:with)\b #(?=\s*(?:\[\w+\]|\w+)\s*\bas\b) scope: keyword.other.dml.sql @@ -355,7 +355,7 @@ contexts: - match: ',' scope: punctuation.separator.sequence.cte.tsql push: - - maybe-column-reference-list + - maybe-column-name-list - expect-cte-table-name - include: expressions @@ -492,6 +492,24 @@ contexts: - include: dml-statements - include: expressions +###[ COLUMN EXPRESSIONS ]###################################################### + + maybe-column-declaration-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: + - maybe-with-table-options + - maybe-filegroup + - inside-column-declaration-list + - include: else-pop + + inside-column-declaration-list: + - meta_prepend: true + - match: \b(?i:rowguidcol|clustered|nonclustered)\b + scope: storage.modifier.tsql + - match: \b(?i:period\s+for\s+system_time)\b + scope: storage.modifier.tsql + ###[ FUNCTION EXPRESSIONS ]#################################################### expect-function-parameters: @@ -593,7 +611,7 @@ contexts: scope: meta.group.tsql punctuation.section.group.end.tsql pop: 1 - include: comma-separators - - include: column-reference-list + - include: column-name-list - include: literals-and-variables - include: expect-index-names @@ -921,25 +939,6 @@ contexts: scope: keyword.operator.logical.tsql set: maybe-group -###[ COLUMN DECLARATIONS ]##################################################### - - maybe-column-declaration-list: - - match: \( - scope: punctuation.section.group.begin.sql - set: - - maybe-with-table-options - - maybe-filegroup - - inside-column-declaration-list - - match: (?=\S) - pop: 1 - - inside-column-declaration-list: - - meta_prepend: true - - match: \b(?i:rowguidcol|clustered|nonclustered)\b - scope: storage.modifier.tsql - - match: \b(?i:period\s+for\s+system_time)\b - scope: storage.modifier.tsql - ###[ TYPES ]################################################################### expect-type: From 2c290935474a87aed45a0fd5aa46a323cb3e31ef Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 23 Sep 2023 12:36:44 +0200 Subject: [PATCH 228/250] [SQL] Drop redundant pattern The `+` operator pattern in MySQL is redundant as it is already part of `expressions`. --- SQL/MySQL.sublime-syntax | 2 -- 1 file changed, 2 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 3ec182c3cc..74a7c33dce 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -657,8 +657,6 @@ contexts: 2: keyword.other.ddl.sql - match: \b(?i:starts|ends)\b scope: keyword.other.ddl.sql - - match: \+ - scope: keyword.operator.arithmetic.sql - match: \b(?i:at)\b scope: keyword.other.ddl.sql - match: \b(?i:every)\b From ec6fdc6457b237948d9ba3ee522ff12b1fec7731 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 23 Sep 2023 12:41:56 +0200 Subject: [PATCH 229/250] [SQL] Move stray brackets into separate contexts Embedding syntaxes may want or require to disable invalid stray highlighting to avoid false positives after interrupted expressions or interpolation. --- SQL/SQL (basic).sublime-syntax | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index c8203147d6..34a29b1484 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -562,8 +562,8 @@ contexts: - include: function-calls - include: comma-separators - include: groups - - match: \) - scope: invalid.illegal.trailing-paren.sql + - include: illegal-stray-brackets + - include: illegal-stray-parens - match: (?=;) pop: 1 @@ -1376,6 +1376,16 @@ contexts: - match: ';' scope: punctuation.terminator.statement.sql +###[ ILLEGALS ]################################################################ + + illegal-stray-brackets: + - match: \] + scope: invalid.illegal.stray.sql + + illegal-stray-parens: + - match: \) + scope: invalid.illegal.stray.sql + ###[ PROTOTYPES ]############################################################## else-pop: From ae2f0da28ebd0bfccea5892bb121e49e6c61bb2f Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 30 Sep 2023 10:47:24 +0200 Subject: [PATCH 230/250] [SQL] Globally match reserved/built-in types --- SQL/Cassandra.sublime-syntax | 7 +- SQL/MySQL.sublime-syntax | 78 ++++++-- SQL/PostgreSQL.sublime-syntax | 1 + SQL/SQL (basic).sublime-syntax | 76 ++++++-- SQL/TSQL.sublime-syntax | 9 +- SQL/tests/syntax/syntax_test_cassandra.cql | 6 +- SQL/tests/syntax/syntax_test_mysql.sql | 201 +++++++++++++++++++-- 7 files changed, 314 insertions(+), 64 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index cac4e4c6fc..ead24f0fd8 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -14,15 +14,16 @@ variables: ddl_target_function: |- (?xi: function ) + ddl_target_other: |- (?xi: keyspace | type | user | (?: materialized \s+ )? view ) simple_types: |- - \b(?xi: + (?xi: ASCII | BIGINT | BLOB | BOOLEAN | COUNTER | DATE | DECIMAL | DOUBLE | DURATION | FLOAT | INET | INT | SMALLINT | TEXT | TIME | TIMESTAMP - | TIMEUUID | TINYINT | UUID | VARCHAR | VARINT - )\b + | TIMEUUID | TINYINT | UUID | VARCHAR | VARINT ) + types_with_optional_number: (?!) contexts: diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 74a7c33dce..93ac71e83f 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -30,21 +30,42 @@ variables: table_row_formats: |- (?xi: dynamic | fixed | compressed | redundant | compact | page ) + # https://mariadb.com/kb/en/data-types simple_types: |- - (?xi: bigint | bigserial | bit | bool | boolean | box | bytea | cidr | circle - | date | datetime | double\s+precision | enum | inet | integer | line - | longtext | lseg | macaddr | money | ntext | oid | path | point | polygon - | real | serial | smallint | sysdate | sysname | text | tinytext ) - types_with_optional_number: |- - (?xi: bit\s+varying | character\s+(?:varying)? | tinyint | var\s+char | float - | int | interval | numeric | decimal | times? | timestamp(?:s | tz)? ) + (?xi: boolean | bool | uuid | year ) - time_unit: |- - (?xi: year | quarter | month | day | hour | minute | week | second | year_month - | day_hour | day_minute | day_second | hour_minute | hour_second | minute_second ) + types_with_optional_number: |- + (?xi: + # numeric data types + (?: big | medium | middle | small | tiny ) int + | bit(?: \s+ varying )? + | date(?: time )? + | dec(?: imal )? + | double(?: \s+ precision )? + | fixed + | float[48]? + | int(?: [12348] | eger )? + | number + | numeric + | real + | (?: local )?time(?: stamp )? + # string data types + | (?: long | medium | tiny )? (?: blob | text ) + | binary (?: \s+ varying )? + | char \s+ byte + | (?: national \s+ )? char(?: acter )? (?: \s+ varying )? + | inet[46] + | long(?: \s+ varchar )? + | var(?: binary | char (?: acter )? ) + ) + + time_units: |- + (?xi: year(?: _month )? | day(?: _hour | _minute | _second | _microsecond )? + | hour(?: _minute | _second | _microsecond )? | minute(?: _second | _microsecond )? + | second(?: _microsecond )? | quarter | month | week ) builtin_user_functions: |- - \b(?xi: (?: current | session | system )_(?: role | user ))\b + (?xi: (?: current | session | system )_(?: role | user )) contexts: sql: @@ -1145,13 +1166,38 @@ contexts: - match: \b(?i:interval)\b scope: storage.type.interval.sql + built-in-types: + - meta_prepend: true + # https://mariadb.com/kb/en/row + - match: \b(?i:row)\b + scope: storage.type.sql + push: + - after-type + - maybe-column-declaration-list + - match: \b(?i:set)(?=\s*\() + scope: storage.type.sql + push: + - after-type + - maybe-group + + built-in-type: + - meta_prepend: true + # https://mariadb.com/kb/en/row + - match: \b(?i:row)\b + scope: storage.type.sql + set: + - after-type + - maybe-column-declaration-list + - match: \b(?i:set)\b + scope: storage.type.sql + set: + - after-type + - maybe-group + after-type: - meta_prepend: true - - match: \b(?i:unsigned)\b - scope: storage.modifier.sql - pop: 1 - match: \b(?i:with(?:out)?\s+time\s+zone)\b - scope: storage.type.sql + scope: storage.modifier.sql pop: 1 ###[ IDENTIFIERS ]############################################################# @@ -1252,7 +1298,7 @@ contexts: pop: 1 time-units: - - match: '{{time_unit}}' + - match: \b{{time_unit}}(?!\()\b scope: keyword.other.unit.sql regexps: diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index aac510eeff..9812f590f1 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -23,6 +23,7 @@ variables: | tsvector | tsquery | uuid | text | xml | jsonb? ) + types_with_optional_number: |- (?xi: (?: bit | character ) (?:\s+varying)? | char | decimal | numeric | varchar ) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 34a29b1484..b496b489ce 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -40,15 +40,19 @@ variables: (?xi: inout | in | out ) simple_types: |- - (?xi: bit | bool | boolean | datetime | int ) + (?xi: boolean | bool | year ) + types_with_optional_number: |- - (?xi: number | n?(?:var)?char | varbinary ) + (?xi: bit | datetime | int | number | n?(?:var)?char | varbinary ) + + type_modifiers: |- + (?xi: signed | unsigned | zerofill ) builtin_scalar_functions: |- - \b(?xi: current_(?: date | time(?:stamp)? ) )\b + (?xi: current_(?: date | time(?:stamp)? ) ) builtin_user_functions: |- - \b(?xi: (?: current | session | system )_user )\b + (?xi: (?: current | session | system )_user ) contexts: prototype: @@ -500,7 +504,7 @@ contexts: ###[ DML SET STATEMENTS ]###################################################### set-statements: - - match: \b(?i:set)\b + - match: \b(?i:set)\b(?!\s*\() scope: keyword.other.dml.sql push: - set-meta @@ -554,14 +558,14 @@ contexts: - include: expect-column-names expressions: + - include: groups + - include: comma-separators + - include: operators - include: alias-expressions - include: case-expressions - include: collate-expressions - include: literals-and-variables - - include: operators - include: function-calls - - include: comma-separators - - include: groups - include: illegal-stray-brackets - include: illegal-stray-parens - match: (?=;) @@ -624,17 +628,17 @@ contexts: built-in-scalar-function-calls: # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html - - match: '{{builtin_scalar_functions}}' + - match: \b{{builtin_scalar_functions}}\b scope: support.function.scalar.sql push: function-call-arguments built-in-user-function-calls: - - match: '{{builtin_user_functions}}' + - match: \b{{builtin_user_functions}}\b scope: support.function.user.sql push: function-call-arguments built-in-user-function-call: - - match: '{{builtin_user_functions}}' + - match: \b{{builtin_user_functions}}\b scope: support.function.user.sql set: function-call-arguments @@ -916,20 +920,47 @@ contexts: - include: built-in-type - include: expect-user-type + built-in-types: + - match: \b(?i:enum)\b + scope: storage.type.sql + push: + - after-type + - maybe-group + - match: |- + (?x) + \b(?: {{simple_types}} | {{types_with_optional_number}} ) + (?: ((\()(\d+)(?:\s*(,)\s*(\d+))?(\)) | \b(?!\s*\() ) ) + scope: storage.type.sql + captures: + 1: meta.parens.sql + 2: punctuation.definition.parens.begin.sql + 3: meta.number.integer.decimal.sql constant.numeric.value.sql + 4: punctuation.separator.sequence.sql + 5: meta.number.integer.decimal.sql constant.numeric.value.sql + 6: punctuation.definition.parens.end.sql + push: after-type + - match: \b{{type_modifiers}}\b + scope: storage.modifier.sql + built-in-type: - - match: \b{{simple_types}}\b + - match: \b(?i:enum)\b scope: storage.type.sql - set: maybe-group + set: + - after-type + - maybe-group - match: |- - (?xi) - \b{{types_with_optional_number}}\b - (?:\s*\((\d+)(?:\s*(,)\s*(\d+))?\))? + (?x) + \b(?: {{simple_types}} | {{types_with_optional_number}} ) + (?: ((\()(\d+)(?:\s*(,)\s*(\d+))?(\)) | \b(?!\s*\() ) ) scope: storage.type.sql captures: - 1: constant.numeric.sql - 2: punctuation.separator.sequence.sql - 3: constant.numeric.sql - set: maybe-group + 1: meta.parens.sql + 2: punctuation.definition.parens.begin.sql + 3: meta.number.integer.decimal.sql constant.numeric.value.sql + 4: punctuation.separator.sequence.sql + 5: meta.number.integer.decimal.sql constant.numeric.value.sql + 6: punctuation.definition.parens.end.sql + set: after-type expect-user-type: - match: (?=\S) @@ -942,6 +973,10 @@ contexts: pop: 1 after-type: + - match: \b{{type_modifiers}}\b + scope: storage.modifier.sql + pop: 1 + - include: assignment-operators - include: else-pop ###[ IDENTIFIERS ]############################################################# @@ -1292,6 +1327,7 @@ contexts: ###[ LITERALS ]################################################################ literals-and-variables: + - include: built-in-types - include: constants - include: numbers - include: strings diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 6b3a45a863..2207607c03 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -35,10 +35,10 @@ variables: | geometry | hierarchyid | image | n?text | rowversion | sql_variant | sysname | uniqueidentifier | xml ) types_with_optional_number: |- - (?xi: n?char | n?varchar | binary | varbinary | decimal | money | numeric ) + (?xi: n?(?:var)?char | binary | varbinary | decimal | money | numeric ) builtin_user_functions: |- - \b(?xi: (?: current_ | session_ | system_ )? user )\b + (?xi: (?: current_ | session_ | system_ )? user ) contexts: @@ -1002,9 +1002,8 @@ contexts: 4: punctuation.separator.sequence.sql 5: constant.numeric.sql 6: punctuation.section.group.end.tsql - pop: true - - match: (?=\S) - pop: true + pop: 1 + - include: else-pop inside-user-type: - meta_prepend: true diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 2fa6a56779..abcc5f41e8 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -202,9 +202,9 @@ CREATE TABLE IF NOT EXISTS date_by_userid ( -- ^^^^ storage.type -- ^^^^^^^^^^^ storage.modifier -- ^ punctuation.separator.sequence - date timestamp --- ^^^^ meta.column-name --- ^^^^^^^^^ storage.type + `date` timestamp +-- ^^^^^^ meta.column-name +-- ^^^^^^^^^ storage.type ); diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index bf56a4c2a7..a365b8e111 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -1,5 +1,131 @@ -- SYNTAX TEST "Packages/SQL/MySQL.sublime-syntax" +-- ---------------------------------------------------------------------------- +-- Data Types +-- https://mariadb.com/kb/en/data-types +-- ---------------------------------------------------------------------------- + + BIT BOOLEAN +-- ^ - storage +-- ^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^ storage.type.sql +-- ^ - storage + + INT INT1 INT2 INT3 INT4 INT8 INTEGER FLOAT FLOAT4 FLOAT8 +-- ^ - storage +-- ^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^ storage.type.sql +-- ^ - storage + + BIGINT MEDIUMINT SMALLINT TINYINT +-- ^ - storage +-- ^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^ storage.type.sql +-- ^ - storage + + DECIMAL DEC NUMBER NUMERIC FIXED +-- ^ - storage +-- ^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^ storage.type.sql +-- ^ - storage + + DOUBLE PRECISION DOUBLE FLOAT REAL +-- ^ - storage +-- ^^^^^^^^^^^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^^ storage.type.sql +-- ^ - storage +-- ^^^^ storage.type.sql +-- ^ - storage + + CHAR BYTE +-- ^^^^^^^^^ storage.type.sql + + NATIONAL CHAR +-- ^^^^^^^^^^^^^ storage.type.sql + + ENUM('foo', 'bar') +-- ^^^^^^^^^^^^^^^^^^ - meta.function-call +-- ^^^^ storage.type.sql +-- ^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.group.end.sql + + ENUM ('foo', 'bar') +-- ^^^^^^^^^^^^^^^^^^^ - meta.function-call +-- ^^^^ storage.type.sql +-- ^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.group.end.sql + + INT(10) FIXED(10,2) TEXT(200) VARCHAR(10) +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function-call +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.type.sql +-- ^^^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.type.sql + + SET SET('foo', 'bar') +-- ^^^ keyword.other.dml.sql +-- ^^^ storage.type.sql +-- ^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.group.end.sql + + UUID UUID() +-- ^^^^ storage.type.sql +-- ^^^^ meta.function-call.sql support.function.sql + + YEAR YEAR() +-- ^^^^ storage.type.sql +-- ^^^^ meta.function-call.sql support.function.sql + + SIGNED UNSIGNED ZEROFILL +-- ^^^^^^ storage.modifier.sql +-- ^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^ storage.modifier.sql + -- ---------------------------------------------------------------------------- -- Data Definition Statements -- https://mariadb.com/kb/en/data-definition @@ -326,11 +452,11 @@ CREATE FUNCTION func_name(IN param_name number, IN OUT out varchar) RETURN -- ^ punctuation.section.group.begin.sql -- ^^ storage.modifier.sql -- ^^^^^^^^^^ variable.parameter.sql --- ^^^^^^ support.type.sql +-- ^^^^^^ storage.type.sql -- ^ punctuation.separator.sequence.sql -- ^^^^^^ storage.modifier.sql -- ^^^ variable.parameter.sql --- ^^^^^^^ support.type.sql +-- ^^^^^^^ storage.type.sql -- ^ punctuation.section.group.end.sql -- ^^^^^^ keyword.control.flow.return.sql -- @@ -354,11 +480,11 @@ CREATE AGGREGATE FUNCTION -- <- meta.statement.create.sql meta.function.sql -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql -- ^^^^^^^ keyword.other.ddl.sql --- ^^^^^^^ support.type.sql --- ^^^^^ meta.group.sql --- ^ punctuation.section.group.begin.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^ meta.parens.sql +-- ^ punctuation.definition.parens.begin.sql -- ^^^ meta.number.integer.decimal.sql constant.numeric.value.sql --- ^ punctuation.section.group.end.sql +-- ^ punctuation.definition.parens.end.sql LANGUAGE SQL -- <- meta.statement.create.sql meta.function.sql @@ -473,10 +599,11 @@ CREATE OR REPLACE PROCEDURE sp_name (param int, out args varchar(200)) SELECT fo -- ^ punctuation.separator.sequence.sql -- ^^^ storage.modifier.sql -- ^^^^ variable.parameter.sql --- ^^^^^^^ support.type.sql --- ^ punctuation.section.group.begin.sql --- ^^^ constant.numeric.value.sql --- ^^ punctuation.section.group.end.sql +-- ^^^^^^^ storage.type.sql - meta.parens +-- ^^^^^ storage.type.sql meta.parens.sql +-- ^ punctuation.definition.parens.begin.sql +-- ^^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.definition.parens.end.sql -- ^^^^^^ keyword.other.dml.sql -- ^^^ meta.column-name.sql -- ^^^^ keyword.other.dml.sql @@ -500,7 +627,20 @@ CREATE PROCEDURE -- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.function.sql -- ^^^^^^^ variable.parameter.sql -- ^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql +BEGIN + DECLARE r ROW (c1 INT, c2 VARCHAR(10)); +-- ^^^ storage.type.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^ storage.type.sql +-- ^ punctuation.separator.sequence.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^^^^^ storage.type.sql +-- ^ punctuation.section.group.end.sql + +END -- ---------------------------------------------------------------------------- -- Create Index Statements @@ -847,7 +987,7 @@ create table some_schema.test2( id serial ); -- ^ punctuation.accessor.dot -- ^ punctuation.section.group.begin.sql -- ^^ meta.column-name.sql variable.other.member.declaration.sql --- ^^^^^^ storage.type.sql +-- ^^^^^^ support.type.sql -- ^ punctuation.section.group.end.sql -- ^ punctuation.terminator.statement.sql @@ -863,7 +1003,7 @@ create table some_schema . test2 ( id serial ); -- ^ punctuation.accessor.dot -- ^ punctuation.section.group.begin.sql -- ^^ meta.column-name.sql variable.other.member.declaration.sql --- ^^^^^^ storage.type.sql +-- ^^^^^^ support.type.sql -- ^ punctuation.section.group.end.sql -- ^ punctuation.terminator.statement.sql @@ -915,11 +1055,19 @@ create table IF NOT EXISTS `testing123` ( -- ^^^^^^ keyword.operator.logical.sql -- ^^^^^^^^^^^^ entity.name.struct.table.sql -- ^ punctuation.section.group.begin.sql + + -- ------------------ + -- column definitions + -- ------------------ + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.table-columns.sql -- ^^^^ meta.column-name.sql --- ^^^^^^^ storage.type.sql --- ^^ constant.numeric.sql +-- ^^^ storage.type.sql - meta.parens +-- ^^^^ storage.type.sql meta.parens.sql +-- ^ punctuation.definition.parens.begin.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.definition.parens.end.sql -- ^^^^^^^^ storage.modifier.sql -- ^^^ keyword.operator.logical.sql -- ^^^^ constant.language.null.sql @@ -939,16 +1087,35 @@ create table IF NOT EXISTS `testing123` ( `version` tinytext DEFAULT NULL COMMENT 'important clarification', -- ^^^^^^^^ storage.type.sql `percentage` float DEFAULT '0', + + `set` SET ('value1', 'value2') NOT NULL, +-- ^^^^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^ storage.type.sql +-- ^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.group.end.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^ punctuation.separator.sequence.sql + + -- ------------------ + -- index definitions + -- ------------------ + UNIQUE KEY `testing123_search` (`col`, `version`), -- ^^^^^^^^^^ storage.modifier.sql KEY `testing123_col` (`col`), -- ^^^ storage.modifier.sql FULLTEXT KEY `testing123_version` (`version`) + ) ENGINE=MyISAM AUTO_INCREMENT=42 DEFAULT CHARACTER SET=utf8; create table fancy_table ( id SERIAL, --- ^^^^^^ storage.type.sql +-- ^^^^^^ support.type.sql foreign_id integer, -- ^^^^^^^ storage.type.sql myflag boolean DEFAULT false, @@ -960,14 +1127,14 @@ create table fancy_table ( mytime timestamp(3) without time zone DEFAULT now(), -- ^^^^^^^^^^^^ storage.type.sql -- ^ constant.numeric --- ^^^^^^^^^^^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^^^^^^^ storage.modifier.sql -- ^^^^^^^ storage.modifier -- ^^^ meta.function-call support.function -- ^ punctuation.section.arguments.begin -- ^ punctuation.section.arguments.end -- ^ punctuation.separator.sequence mytime2 timestamp(3) without time zone DEFAULT '2008-01-18 00:00:00'::timestamp(3) without time zone, -- TODO: seems like :: is a postgresql cast operator --- ^^^^^^^^^^^^^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^^^^^^^^^ storage.modifier.sql some_number numeric(5, 2) DEFAULT 0, -- ^^^^^^^^^^^ meta.column-name -- ^^^^^^^^^^^^^ storage.type From f04117c374dc7a6da396819984c40324ec9f2962 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 30 Sep 2023 10:47:50 +0200 Subject: [PATCH 231/250] [SQL] Add globally reserved words This commit prevents globally reserved keywords to be matched as identifiers (column names, table names, ...). --- SQL/MySQL.sublime-syntax | 38 ++++++++++++-- SQL/SQL (basic).sublime-syntax | 17 +++--- SQL/TSQL.sublime-syntax | 2 +- SQL/tests/syntax/syntax_test_mysql.sql | 71 ++++++++++++++++++++++++++ 4 files changed, 117 insertions(+), 11 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 93ac71e83f..8d82c922aa 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -7,8 +7,22 @@ version: 2 extends: Packages/SQL/SQL (basic).sublime-syntax variables: - additional_reserved: |- - (?xi: begin | end | return | grant | rename | revoke | show ) + additional_toplevel_reserved: |- + (?xi: {{conditional_keywords}} | {{flow_keywords}} | {{loop_keywords}} + | begin | end | rename | show ) + + conditional_keywords: |- + (?xi: if | end\s+if | else(?:if)? | then ) + + flow_keywords: |- + (?xi: continue | exit | return ) + + loop_keywords: |- + (?xi: loop | end\s+(?: loop | repeat | while ) | repeat | while ) + + other_keywords: |- + (?xi: close | cursor | declare | deallocate | delimiter | execute | fetch + | for | found | open | prepare | with ) function_parameter_modifier: |- (?xi: in\s*out | in | out ) @@ -595,10 +609,18 @@ contexts: ###[ OTHER STATEMENTS ]######################################################## other-statements: + - match: \b{{conditional_keywords}}\b + scope: keyword.control.conditional.sql + - match: \b{{loop_keywords}}\b + scope: keyword.control.loop.sql - match: \b(?i:begin(\s+work)?|start\s+transaction|commit(\s+work)?|rollback(\s+work)?)\b scope: keyword.other.luw.sql - match: \b(?i:end)\b scope: keyword.control.flow.end.sql + - match: \b(?i:continue)\b + scope: keyword.control.flow.continue.sql + - match: \b(?i:exit)\b + scope: keyword.control.flow.exit.sql - match: \b(?i:return)\b scope: keyword.control.flow.return.sql @@ -606,6 +628,8 @@ contexts: expressions: - meta_prepend: true + - match: \b{{other_keywords}}\b + scope: keyword.other.sql - match: \b(?i:concatenate|convert|lower|substring|translate|trim|upper)\b scope: support.function.string.sql - match: \b(?i:using)\b @@ -1261,6 +1285,10 @@ contexts: ###[ LITERALS ]################################################################ + literals-and-variables: + - meta_prepend: true + - include: time-units + comment-keywords: - match: \b(?i:comment)\b scope: variable.parameter.sql @@ -1298,7 +1326,7 @@ contexts: pop: 1 time-units: - - match: \b{{time_unit}}(?!\()\b + - match: \b{{time_units}}(?!\()\b scope: keyword.other.unit.sql regexps: @@ -1364,6 +1392,10 @@ contexts: - meta_append: true - match: \|\| scope: keyword.operator.concatenation.sql + - match: \! + scope: keyword.operator.logical.sql + - match: \b(?i:div|mod)\b + scope: keyword.operator.arithmetic.sql ###[ PROTOTYPES ]############################################################## diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index b496b489ce..f574bea469 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -10,11 +10,11 @@ variables: simple_identifier: (?:\w+) simple_identifier_break: (?!\w) - reserved: |- + toplevel_reserved: |- (?xi: alter | create | cross | delete | drop | from | grant | group | inner | insert | join | left | on | order | outer | revoke | right | select | set | truncate | union | update | where ) - additional_reserved: (?!) + additional_toplevel_reserved: (?!) # TODO: not all are supported by all dialects! ddl_target: |- @@ -496,7 +496,7 @@ contexts: - include: else-pop conditional-expression: - - match: (?=[,;)}]|\b(?:{{reserved}}|{{additional_reserved}})\b) + - match: (?=[,;)}]|\b(?:{{toplevel_reserved}}|{{additional_toplevel_reserved}})\b) pop: 1 - include: expressions - include: expect-column-names @@ -564,6 +564,7 @@ contexts: - include: alias-expressions - include: case-expressions - include: collate-expressions + - include: constraint-expressions - include: literals-and-variables - include: function-calls - include: illegal-stray-brackets @@ -614,6 +615,11 @@ contexts: pop: 1 - include: else-pop + constraint-expressions: + - match: \b(?i:constraint)\b + scope: storage.modifier.sql + push: expect-constraint-name + function-calls: - include: built-in-aggregate-function-calls - include: built-in-scalar-function-calls @@ -702,9 +708,6 @@ contexts: - match: \) scope: punctuation.section.group.end.sql pop: 1 - - match: \b(?i:constraint)\b - scope: storage.modifier.sql - push: expect-constraint-name - include: column-modifiers - include: expressions - include: expect-column-declarations @@ -1433,5 +1436,5 @@ contexts: pop: 1 pop-on-top-level-reserved-word: - - match: (?=[;)}]|\b(?:{{reserved}}|{{additional_reserved}})\b) + - match: (?=[;)}]|\b(?:{{toplevel_reserved}}|{{additional_toplevel_reserved}})\b) pop: 1 diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 2207607c03..34c9717d43 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -10,7 +10,7 @@ variables: string_escape: (?:'') simple_identifier_break: (?![\w#@]) - additional_reserved: |- + additional_toplevel_reserved: |- (?xi: backup | begin | break | bulk | continue | declare | else | end | exec(?:ute)? | for | go | if | insert | merge | on | print | raiserror | return | throw | use | waitfor | when | while | with ) diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index a365b8e111..dd21989620 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -126,6 +126,29 @@ -- ^^^^^^^^ storage.modifier.sql -- ^^^^^^^^ storage.modifier.sql +-- ---------------------------------------------------------------------------- +-- Units +-- https://mariadb.com/kb/en/reserved-words +-- ---------------------------------------------------------------------------- + + DAY_HOUR DAY_MICROSECOND DAY_MINUTE DAY_SECOND +-- ^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^ keyword.other.unit.sql + + HOUR_MICROSECOND HOUR_MINUTE HOUR_SECOND +-- ^^^^^^^^^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^^ keyword.other.unit.sql + + MINUTE_MICROSECOND MINUTE_SECOND +-- ^^^^^^^^^^^^^^^^^^ keyword.other.unit.sql +-- ^^^^^^^^^^^^^ keyword.other.unit.sql + + SECOND_MICROSECOND +-- ^^^^^^^^^^^^^^^^^^ keyword.other.unit.sql + -- ---------------------------------------------------------------------------- -- Data Definition Statements -- https://mariadb.com/kb/en/data-definition @@ -640,6 +663,54 @@ BEGIN -- ^^^^^^^^^^^ storage.type.sql -- ^ punctuation.section.group.end.sql + IF @var = TRUE THEN +-- ^^ keyword.control.conditional.sql +-- ^^^^ variable.other.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^ constant.language.boolean.sql +-- ^^^^ keyword.control.conditional.sql + + ELSEIF @var = FALSE THEN +-- ^^^^^^ keyword.control.conditional.sql +-- ^^^^ variable.other.sql +-- ^ keyword.operator.comparison.sql +-- ^^^^^ constant.language.boolean.sql +-- ^^^^ keyword.control.conditional.sql + + ELSE +-- ^^^^ keyword.control.conditional.sql + + END IF +-- ^^^^^^ keyword.control.conditional.sql + + LOOP +-- ^^^^ keyword.control.loop.sql + + END LOOP +-- ^^^^^^^^ keyword.control.loop.sql + + REPEAT +-- ^^^^^^ keyword.control.loop.sql + + END REPEAT +-- ^^^^^^^^^^ keyword.control.loop.sql + + WHILE TRUE +-- ^^^^^ keyword.control.loop.sql +-- ^^^^ constant.language.boolean.sql + + END WHILE +-- ^^^^^^^^^ keyword.control.loop.sql + + CONTINUE +-- ^^^^^^^^ keyword.control.flow.continue.sql + + EXIT +-- ^^^^ keyword.control.flow.exit.sql + + RETURN +-- ^^^^^^ keyword.control.flow.return.sql + END -- ---------------------------------------------------------------------------- From 245a439ec68fde7aa116ba917b7228989d06c667 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Mon, 25 Sep 2023 21:45:56 +0200 Subject: [PATCH 232/250] [SQL] Simplify literal constants Literal constants belong to reserved words and thus can be matched globally. --- SQL/MySQL.sublime-syntax | 60 ++++++-------------------- SQL/tests/syntax/syntax_test_mysql.sql | 54 +++++++++++++++++++++-- 2 files changed, 63 insertions(+), 51 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 8d82c922aa..6e9a6b4a8c 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -39,8 +39,7 @@ variables: | delay_key_write | encrypted | encryption_key_id | ietf_quotes | index\s+directory | insert_method | key_block_size | max_rows | min_rows | pack_keys | page_checksum | page_compressed | page_compression_level | password | row_format | sequence - | stats_auto_recalc | stats_persistent | stats_sample_pages | transactional | union - | with\s+system\s+versioning ) + | stats_auto_recalc | stats_persistent | stats_sample_pages | transactional ) table_row_formats: |- (?xi: dynamic | fixed | compressed | redundant | compact | page ) @@ -78,6 +77,12 @@ variables: | hour(?: _minute | _second | _microsecond )? | minute(?: _second | _microsecond )? | second(?: _microsecond )? | quarter | month | week ) + builtin_constants: |- + (?xi: all | default | maxvalue + # index algorithm/lock values + | inplace | copy | nocopy | instant | exclusive | shared + | system\s+versioning ) + builtin_user_functions: |- (?xi: (?: current | session | system )_(?: role | user )) @@ -707,7 +712,6 @@ contexts: - match: \b(?i:every)\b scope: keyword.other.ddl.sql - include: intervals - - include: time-units - include: expressions ###[ FUNCTION EXPRESSIONS ]#################################################### @@ -737,14 +741,6 @@ contexts: index-algorithm-args: - match: \b(?i:algorithm)\b scope: keyword.other.ddl.sql - push: index-algorithm-value - - index-algorithm-value: - - match: \b(?i:inplace|copy|nocopy|instant)\b - scope: constant.language.algorithm.sql - pop: 1 - - include: default-constant - - include: else-pop index-clustering-args: - match: \b(?i:clustering)\b @@ -753,15 +749,6 @@ contexts: index-lock-args: - match: \b(?i:lock)\b scope: keyword.other.ddl.sql - push: index-lock-value - - index-lock-value: - - match: \b(?i:shared|exclusive)\b - scope: constant.language.lock-option.sql - pop: 1 - - include: default-constant - - include: none-constant - - include: else-pop index-parser-args: - match: \b(?i:with\s+parser)\b @@ -775,21 +762,13 @@ contexts: index-type-value: - match: \b(?i:btree|hash|rtree)\b - scope: constant.language.index-type.sql + scope: constant.language.sql pop: 1 - include: else-pop index-wait-args: - - match: \b(?i:nowait)\b - scope: keyword.other.ddl.sql - - match: \b(?i:wait)\b + - match: \b(?i:nowait|wait)\b scope: keyword.other.ddl.sql - push: index-wait-value - - index-wait-value: - - include: numbers - - include: time-units - - include: else-pop index-other-args: - match: \b(?i:ignored)\b @@ -823,7 +802,6 @@ contexts: scope: variable.parameter.sql - include: partition-lists - include: comment-keywords - - include: maxvalue-constants - include: tablespaces - include: expressions @@ -1286,7 +1264,7 @@ contexts: ###[ LITERALS ]################################################################ literals-and-variables: - - meta_prepend: true + - meta_append: true - include: time-units comment-keywords: @@ -1295,24 +1273,12 @@ contexts: constants: - meta_append: true - - include: default-constants + - include: bool-constants - include: none-constants - - include: yesno-constants - - default-constants: - - match: \b(?i:default)\b - scope: constant.language.default.sql - - default-constant: - - match: \b(?i:default)\b - scope: constant.language.default.sql - pop: 1 - - maxvalue-constants: - - match: \b(?i:maxvalue)\b + - match: \b{{builtin_constants}}\b scope: constant.language.sql - yesno-constants: + bool-constants: - match: \b(?i:yes|no)\b scope: constant.language.boolean.sql diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index dd21989620..9e6d450b64 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -1,5 +1,50 @@ -- SYNTAX TEST "Packages/SQL/MySQL.sublime-syntax" +-- ---------------------------------------------------------------------------- +-- Constants +-- https://mariadb.com/kb/en/reserved-words +-- ---------------------------------------------------------------------------- + + null none true false +-- ^ - constant +-- ^^^^ constant.language.null.sql +-- ^ - constant +-- ^^^^ constant.language.null.sql +-- ^ - constant +-- ^^^^ constant.language.boolean.sql +-- ^ - constant +-- ^^^^^ constant.language.boolean.sql +-- ^ - constant + + all default maxvalue +-- ^ - constant +-- ^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^^^ constant.language.sql +-- ^ - constant + + inplace copy nocopy instant exclusive shared +-- ^ - constant +-- ^^^^^^^ constant.language.sql +-- ^ - constant +-- ^^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^^^^ constant.language.sql +-- ^ - constant +-- ^^^^^^ constant.language.sql +-- ^ - constant + + system versioning +-- ^ - constant +-- ^^^^^^^^^^^^^^^^^ constant.language.sql +-- ^ - constant + -- ---------------------------------------------------------------------------- -- Data Types -- https://mariadb.com/kb/en/data-types @@ -797,7 +842,7 @@ CREATE INDEX index_name USING BTREE -- ^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql -- ^^^^^ keyword.other.ddl.sql --- ^^^^^ constant.language.index-type.sql +-- ^^^^^ constant.language.sql ON tbl_name (col1(100) ASC, col2 DESC) -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql -- ^^ keyword.other.sql @@ -837,11 +882,11 @@ CREATE INDEX index_name ALGORITHM INPLACE -- ^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql -- ^^^^^^^^^ keyword.other.ddl.sql --- ^^^^^^^ constant.language.algorithm.sql +-- ^^^^^^^ constant.language.sql LOCK SHARED -- ^^^^^^^^^^^^^ meta.statement.create.sql meta.index.sql -- ^^^^ keyword.other.ddl.sql --- ^^^^^^ constant.language.lock-option.sql +-- ^^^^^^ constant.language.sql -- ---------------------------------------------------------------------------- @@ -1356,7 +1401,8 @@ CREATE TABLE foo (col1, col2) -- ^ punctuation.section.sequence.end.sql WITH SYSTEM VERSIONING -- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql --- ^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.sql +-- ^^^^ keyword.other.sql +-- ^^^^^^^^^^^^^^^^^ constant.language.sql ; -- <- punctuation.terminator.statement.sql From 3205950ae2823c272719f7c95575a6ea2cef9fa3 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 30 Sep 2023 10:44:05 +0200 Subject: [PATCH 233/250] [SQL] Add variables This commit scopes variables such as `@var` in MySQL. --- SQL/MySQL.sublime-syntax | 7 +++++++ SQL/tests/syntax/syntax_test_mysql.sql | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 6e9a6b4a8c..97ab06a236 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -1266,6 +1266,7 @@ contexts: literals-and-variables: - meta_append: true - include: time-units + - include: variables comment-keywords: - match: \b(?i:comment)\b @@ -1295,6 +1296,12 @@ contexts: - match: \b{{time_units}}(?!\()\b scope: keyword.other.unit.sql + variables: + - match: (@){{simple_identifier}}\b + scope: variable.other.sql + captures: + 1: punctuation.definition.variable.sql + regexps: - match: /(?=\S.*/) scope: punctuation.definition.string.begin.sql diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 9e6d450b64..f21e003fdc 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -697,6 +697,14 @@ CREATE PROCEDURE -- ^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql BEGIN + DECLARE @var INT = 0; +-- ^^^^^^^ keyword.other.sql +-- ^^^^ variable.other.sql +-- ^^^ storage.type +-- ^ keyword.operator.assignment.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^ punctuation.terminator.statement.sql + DECLARE r ROW (c1 INT, c2 VARCHAR(10)); -- ^^^ storage.type.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql From dcc2a931c21a66bd0882db61fb8387c540ad9cd2 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 30 Sep 2023 18:34:31 +0200 Subject: [PATCH 234/250] [SQL] Add string literal tests --- SQL/tests/syntax/syntax_test_mysql.sql | 71 ++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index f21e003fdc..ab6dd55e63 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -1,5 +1,76 @@ -- SYNTAX TEST "Packages/SQL/MySQL.sublime-syntax" +-- ---------------------------------------------------------------------------- +-- String Literals +-- https://mariadb.com/kb/en/string-literals +-- ---------------------------------------------------------------------------- + + '\0' -- ASCII NUL (0x00). +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\'' -- Single quote (“'”). +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\"' -- Double quote (“"”). +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\b' -- Backspace. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\n' -- Newline, or linefeed,. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\r' -- Carriage return. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\t' -- Tab. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\Z' -- ASCII 26 (Control+Z). See note following the table. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\\' -- Backslash (“\”). +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\%' -- “%” character. See note following the table. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + + '\_' -- A “_” character. See note following the table. +-- ^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.definition.string.begin.sql +-- ^^ constant.character.escape.sql +-- ^ punctuation.definition.string.end.sql + -- ---------------------------------------------------------------------------- -- Constants -- https://mariadb.com/kb/en/reserved-words From d79bcbe9258f1b443abba6f518d17c5c3b1dd7cc Mon Sep 17 00:00:00 2001 From: deathaxe Date: Fri, 29 Sep 2023 18:06:02 +0200 Subject: [PATCH 235/250] [SQL] Add ALTER TABLE support for MySQL --- SQL/MySQL.sublime-syntax | 262 ++++++- SQL/PostgreSQL.sublime-syntax | 5 - SQL/SQL (basic).sublime-syntax | 48 +- SQL/tests/syntax/syntax_test_mysql.sql | 919 +++++++++++++++++++++++-- 4 files changed, 1173 insertions(+), 61 deletions(-) diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 97ab06a236..0d25fa53bb 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -209,7 +209,7 @@ contexts: create-table-args: # https://mariadb.com/kb/en/create-table - meta_prepend: true - - include: partition-lists + - include: partition-declaration-lists - include: partition-options - include: table-options @@ -322,6 +322,8 @@ contexts: - include: alter-event - include: alter-user +###[ DDL ALTER COLUMNS STATEMENTS ]############################################ + alter-columns: - meta_prepend: true - match: \b(?i:(change)\s+(column))\b @@ -333,6 +335,8 @@ contexts: - expect-column-name-declaration - expect-column-name +###[ DDL ALTER DATABASE STATEMENTS ]########################################### + alter-database: # https://mariadb.com/kb/en/alter-database - match: \b(?i:database|schema)\b @@ -355,6 +359,8 @@ contexts: pop: 1 - include: create-database-args +###[ DDL ALTER EVENT STATEMENTS ]############################################## + alter-event: # https://mariadb.com/kb/en/alter-event - match: \b(?i:event)\b @@ -373,6 +379,200 @@ contexts: - include: event-options - include: pop-on-top-level-reserved-word +###[ DDL ALTER TABLE STATEMENTS ]############################################## + + alter-table: + - meta_prepend: true + - match: \b(?i:online|ignore)\b + scope: keyword.other.ddl.sql + + alter-table-args: + - match: \b(?i:add)\b + scope: keyword.other.ddl.sql + push: alter-table-add-target + - match: \b(?i:change)\b + scope: keyword.other.ddl.sql + push: alter-table-change-target + - match: \b(?i:drop)\b + scope: keyword.other.ddl.sql + push: alter-table-drop-target + - match: \b(?i:modify)\b + scope: keyword.other.ddl.sql + push: alter-table-modify-target + - match: \b(?i:rename)\b + scope: keyword.other.ddl.sql + push: alter-table-rename-target + # drop args + - match: \b(?i:cascade|restrict)\b + scope: keyword.other.ddl.sql + # partition commands + - match: \b(?i:check)\b + scope: keyword.other.sql + # table options + - include: index-wait-args + - include: partition-options + - include: table-options + # expressions + - include: pop-on-top-level-reserved-word + - include: literals-and-variables + - include: comma-separators + - include: operators + + alter-table-add-target: + - include: system-versioning + - include: alter-table-add-index + - include: alter-table-add-partition + - include: alter-table-add-period + - include: alter-table-add-column # must be the last one + + alter-table-add-column: + - match: (?=\S) + set: + - maybe-column-position + - expect-column-declaration + - maybe-condition + - maybe-column + + alter-table-add-index: + - match: \b(?i:constraint)\b + scope: keyword.other.ddl.sql + push: + - maybe-check + - expect-constraint-name + - match: \b(?i:(primary)\s+(key))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: alter-table-add-index-args + - match: \b(?i:(?:(foreign|fulltext|spatial|unique)\s+)?(index|key))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - alter-table-add-index-args + - expect-index-name + - maybe-condition + + alter-table-add-index-args: + - include: column-name-lists + - include: comment-keywords + - include: index-algorithm-args + - include: index-clustering-args + - include: index-lock-args + - include: index-parser-args + - include: index-type-args + - include: index-other-args + - include: literals-and-variables + - include: operators + - include: else-pop + + alter-table-add-partition: + - match: \b(?i:partition)\b + scope: keyword.other.ddl.sql + set: + - maybe-partition-declaration-list + - maybe-condition + + alter-table-add-period: + - match: \b(?i:(period)\s+(for)\s+(system_time))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + 3: keyword.other.ddl.sql + set: maybe-column-name-list + + alter-table-change-target: + - include: alter-table-change-column + + alter-table-change-column: + - match: (?=\S) + set: + - after-type + - expect-type + - expect-column-name-declaration + - expect-column-name + - maybe-condition + - maybe-column + + alter-table-drop-target: + - include: system-versioning + - include: alter-table-drop-constraint + - include: alter-table-drop-index + - include: alter-table-drop-partition + - include: alter-table-drop-column # must be the last one + + alter-table-drop-column: + - match: (?=\S) + set: + - expect-column-name + - maybe-condition + - maybe-column + + alter-table-drop-constraint: + - match: \b(?i:constraint)\b + scope: keyword.other.ddl.sql + set: + - expect-constraint-name + - maybe-condition + + alter-table-drop-index: + - match: \b(?i:primary\s+key)\b + scope: keyword.other.ddl.sql + pop: 1 + - match: \b(?i:index|(?:foreign\s+)?key)\b + scope: keyword.other.ddl.sql + set: + - expect-index-name + - maybe-condition + + alter-table-drop-partition: + - match: \b(?i:partition)\b + scope: keyword.other.ddl.sql + set: + - expect-partition-name + - maybe-condition + + alter-table-modify-target: + - include: alter-table-modify-column + + alter-table-modify-column: + - match: (?=\S) + set: + - after-type + - expect-type + - expect-column-name-declaration + - maybe-condition + - maybe-column + + alter-table-rename-target: + - include: alter-table-rename-column + - include: alter-table-rename-index + - include: alter-table-rename-table # must be the last one + + alter-table-rename-column: + - match: \b(?i:column)\b + scope: keyword.other.ddl.sql + set: + - expect-column-name + - maybe-to + - expect-column-name + + alter-table-rename-index: + - match: \b(?i:index|key)\b + scope: keyword.other.ddl.sql + set: + - expect-index-name + - maybe-to + - expect-index-name + + alter-table-rename-table: + - match: (?=\S) + set: + - expect-table-name + - maybe-to + +###[ DDL ALTER USER STATEMENTS ]############################################### + alter-user: # https://mariadb.com/kb/en/alter-user - match: \b(?i:user)\b @@ -778,20 +978,34 @@ contexts: ###[ PARTITION EXPRESSIONS ]################################################### - partition-lists: + maybe-partition-declaration-list: - match: \( - scope: punctuation.section.sequence.begin.sql - push: inside-partition-list + scope: punctuation.section.group.begin.sql + set: + - inside-partition-declaration-list + - expect-partition-creation-name + - maybe-partition + - include: else-pop + + partition-declaration-lists: + - match: \( + scope: punctuation.section.group.begin.sql + push: + - inside-partition-declaration-list + - expect-partition-creation-name + - maybe-partition - inside-partition-list: - - meta_scope: meta.sequence.partitions.sql + inside-partition-declaration-list: + - meta_scope: meta.group.partitions.sql - match: \) - scope: punctuation.section.sequence.end.sql + scope: punctuation.section.group.end.sql pop: 1 # partition and subpartition declarations - - match: \b(?i:(?:sub)?partition)\b - scope: keyword.other.ddl.sql - push: expect-partition-creation-name + - match: ',' + scope: punctuation.separator.sequence.sql + push: + - expect-partition-creation-name + - maybe-partition # partition parameters - match: \b(?i:values)\b scope: keyword.other.ddl.sql @@ -800,11 +1014,16 @@ contexts: push: maybe-group - match: \b{{partition_parameters}}\b scope: variable.parameter.sql - - include: partition-lists + - include: partition-declaration-lists - include: comment-keywords - include: tablespaces - include: expressions + maybe-partition: + - match: \b(?i:(?:sub)?partition)\b + scope: keyword.other.ddl.sql + - include: else-pop + partition-options: # partition keywords - match: \b(?i:(?:sub)?partition by)\b @@ -854,15 +1073,36 @@ contexts: - match: \b(?i:union)\b scope: variable.parameter.sql push: maybe-table-name-list + - match: \b(?i:with)\b + scope: keyword.other.sql # common table options - match: \b{{table_parameters}}\b scope: variable.parameter.sql - match: \b{{table_row_formats}}\b scope: constant.language.sql # common table option values + - match: \b(?i:after)\b + scope: keyword.other.position.sql + push: expect-column-name - match: \b(?i:first|last)\b + scope: keyword.other.position.sql + - match: \b(?i:system\s+versioning)\b scope: constant.language.sql + maybe-column-position: + - match: \b(?i:after)\b + scope: keyword.other.position.sql + set: expect-column-name + - match: \b(?i:first|last)\b + scope: keyword.other.position.sql + pop: 1 + - include: else-pop + + system-versioning: + - match: \b(?i:system\s+versioning)\b + scope: constant.language.sql + pop: 1 + tablespaces: - match: \b(?i:tablespace)\b scope: variable.parameter.sql diff --git a/SQL/PostgreSQL.sublime-syntax b/SQL/PostgreSQL.sublime-syntax index 9812f590f1..04a64f1940 100644 --- a/SQL/PostgreSQL.sublime-syntax +++ b/SQL/PostgreSQL.sublime-syntax @@ -182,11 +182,6 @@ contexts: - include: numbers - include: else-pop - alter-common: - - meta_prepend: true - - match: \b(?i:check)\b - scope: keyword.other.psql - ###[ DDL STATEMENT PROTOTYPES ]################################################ on-table-names: diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index f574bea469..c51e6f0a1f 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -335,6 +335,8 @@ contexts: - include: alter-other - include: else-pop +###[ DDL ALTER FUNCTION STATEMENTS ]########################################### + alter-function: - match: \b(?:({{ddl_target_function_modifier}})\s+)?({{ddl_target_function}})\b captures: @@ -350,13 +352,15 @@ contexts: - meta_include_prototype: false - include: maybe-condition +###[ DDL ALTER INDEX STATEMENTS ]############################################## + alter-index: - match: \b(?i:(?:({{ddl_target_index_modifier}})\s+)?(index))\b captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql set: - - alter-other-args + - alter-index-args - expect-index-name - alter-index-condition @@ -364,6 +368,13 @@ contexts: - meta_include_prototype: false - include: maybe-condition + alter-index-args: + - include: alter-common + - include: pop-on-top-level-reserved-word + - include: expressions-or-column-names + +###[ DDL ALTER TABLE STATEMENTS ]############################################## + alter-table: - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b captures: @@ -620,6 +631,26 @@ contexts: scope: storage.modifier.sql push: expect-constraint-name + maybe-check: + - match: \b(?i:check)\b + scope: keyword.other.sql + set: maybe-group + - include: else-pop + + maybe-column: + - match: \b(?i:column)\b + scope: keyword.other.ddl.sql + pop: 1 + - include: else-pop + + maybe-to: + - match: \b(?i:to)\b + scope: keyword.other.ddl.sql + pop: 1 + - include: else-pop + +###[ FUNCTION EXPRESSIONS ]#################################################### + function-calls: - include: built-in-aggregate-function-calls - include: built-in-scalar-function-calls @@ -671,6 +702,8 @@ contexts: - include: distinct - include: expressions-or-column-names +###[ GROUPS EXPRESSIONS ]###################################################### + maybe-group: - include: group - include: else-pop @@ -694,6 +727,16 @@ contexts: ###[ COLUMN EXPRESSIONS ]###################################################### + expect-column-declaration: + - include: column-declaration-list + - match: (?=\S) + set: + - maybe-column-modifier + - after-type + - expect-type + - column-name-declaration + - single-identifier + maybe-column-declaration-list: - include: column-declaration-list - include: else-pop @@ -715,6 +758,7 @@ contexts: expect-column-declarations: - match: (?=\S) push: + - maybe-column-modifier - after-type - expect-type - column-name-declaration @@ -1027,6 +1071,8 @@ contexts: expect-constraint-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false + - match: (?=(?i:check|foreign|primary|unique|index|key|using|with)\b) + pop: 1 - include: comments - match: (?=\S) set: [constraint-name, single-identifier] diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index ab6dd55e63..247383f72e 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -1557,19 +1557,19 @@ CREATE -- ^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql ( --- ^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql --- ^ punctuation.section.sequence.begin.sql +-- ^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql PARTITION partition1 --- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^ entity.name.struct.partition.sql VALUES LESS THAN MAXVALUE --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^ keyword.operator.logical.sql -- ^^^^^^^^ constant.language.sql VALUES LESS THAN (20) --- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^ keyword.operator.logical.sql -- ^^^^ meta.group.sql @@ -1577,45 +1577,45 @@ CREATE -- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql -- ^ punctuation.section.group.end.sql ENGINE = engine_name --- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^ variable.parameter.sql -- ^ keyword.operator.comparison.sql COMMENT = 'comment_text' --- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^^ variable.parameter.sql -- ^ keyword.operator.comparison.sql -- ^^^^^^^^^^^^^^ meta.string.sql string.quoted.single.sql DATA DIRECTORY = 'data_dir' --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^^^^^^^^^ variable.parameter.sql -- ^ keyword.operator.comparison.sql -- ^^^^^^^^^^ meta.string.sql string.quoted.single.sql INDEX DIRECTORY = 'index_dir' --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^^^^^^^^^^ variable.parameter.sql -- ^ keyword.operator.comparison.sql -- ^^^^^^^^^^^ meta.string.sql string.quoted.single.sql MAX_ROWS = 20 --- ^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^^^ variable.parameter.sql -- ^ keyword.operator.comparison.sql -- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql MIN_ROWS = 4 --- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^^^ variable.parameter.sql -- ^ keyword.operator.comparison.sql -- ^ meta.number.integer.decimal.sql constant.numeric.value.sql TABLESPACE = tablespace_name --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^^^^^ variable.parameter.sql -- ^ keyword.operator.assignment.sql -- ^^^^^^^^^^^^^^^ meta.other-name.sql NODEGROUP = 32 ( --- ^ meta.sequence.partitions.sql - meta.sequence meta.sequence --- ^^ meta.sequence.partitions.sql meta.sequence.partitions.sql --- ^ punctuation.section.sequence.begin.sql +-- ^ meta.group.partitions.sql - meta.sequence meta.sequence +-- ^^ meta.group.partitions.sql meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql subpartition parition1 -- ^^^^^^^^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^ entity.name.struct.partition.sql @@ -1630,17 +1630,17 @@ CREATE -- ^^^^^^^^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^ entity.name.struct.partition.sql ), --- ^^ meta.sequence.partitions.sql meta.sequence.partitions.sql --- ^ meta.sequence.partitions.sql - meta.sequence meta.sequence --- ^ punctuation.section.sequence.end.sql +-- ^^ meta.group.partitions.sql meta.group.partitions.sql +-- ^ meta.group.partitions.sql - meta.sequence meta.sequence +-- ^ punctuation.section.group.end.sql -- ^ punctuation.separator.sequence.sql PARTITION partition2 --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^^^^ keyword.other.ddl.sql -- ^^^^^^^^^^ entity.name.struct.partition.sql VALUES IN ("value1", "value2", "value3") --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^ keyword.other.ddl.sql -- ^^ keyword.operator.logical.sql -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql @@ -1653,12 +1653,12 @@ CREATE -- ^ punctuation.section.group.end.sql -- STORAGE ENGINE = engine_name --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql -- ^^^^^^^^^^^^^^ variable.parameter.sql -- ^ keyword.operator.comparison.sql ) --- ^^ meta.statement.create.sql meta.table.sql meta.sequence.partitions.sql --- ^ punctuation.section.sequence.end.sql +-- ^^ meta.statement.create.sql meta.table.sql meta.group.partitions.sql +-- ^ punctuation.section.group.end.sql -- ---------------------------------------------------------------------------- @@ -2113,6 +2113,858 @@ ALTER EVENT event_name -- ^ punctuation.terminator.statement.sql +-- ---------------------------------------------------------------------------- +-- Alter Table Statements +-- https://mariadb.com/kb/en/alter-table +-- +-- ALTER [ONLINE] [IGNORE] TABLE [IF EXISTS] tbl_name +-- [WAIT n | NOWAIT] +-- alter_specification [, alter_specification] ... +-- +-- alter_specification: +-- table_option ... +-- | ADD [COLUMN] [IF NOT EXISTS] col_name column_definition +-- [FIRST | AFTER col_name ] +-- | ADD [COLUMN] [IF NOT EXISTS] (col_name column_definition,...) +-- | ADD {INDEX|KEY} [IF NOT EXISTS] [index_name] +-- [index_type] (index_col_name,...) [index_option] ... +-- | ADD [CONSTRAINT [symbol]] PRIMARY KEY +-- [index_type] (index_col_name,...) [index_option] ... +-- | ADD [CONSTRAINT [symbol]] +-- UNIQUE [INDEX|KEY] [index_name] +-- [index_type] (index_col_name,...) [index_option] ... +-- | ADD FULLTEXT [INDEX|KEY] [index_name] +-- (index_col_name,...) [index_option] ... +-- | ADD SPATIAL [INDEX|KEY] [index_name] +-- (index_col_name,...) [index_option] ... +-- | ADD [CONSTRAINT [symbol]] +-- FOREIGN KEY [IF NOT EXISTS] [index_name] (index_col_name,...) +-- reference_definition +-- | ADD PERIOD FOR SYSTEM_TIME (start_column_name, end_column_name) +-- | ALTER [COLUMN] col_name SET DEFAULT literal | (expression) +-- | ALTER [COLUMN] col_name DROP DEFAULT +-- | ALTER {INDEX|KEY} index_name [NOT] INVISIBLE +-- | CHANGE [COLUMN] [IF EXISTS] old_col_name new_col_name column_definition +-- [FIRST | AFTER col_name] +-- | MODIFY [COLUMN] [IF EXISTS] col_name column_definition +-- [FIRST | AFTER col_name] +-- | DROP [COLUMN] [IF EXISTS] col_name [RESTRICT|CASCADE] +-- | DROP PRIMARY KEY +-- | DROP {INDEX|KEY} [IF EXISTS] index_name +-- | DROP FOREIGN KEY [IF EXISTS] index_name +-- | DROP CONSTRAINT [IF EXISTS] constraint_name +-- | DISABLE KEYS +-- | ENABLE KEYS +-- | RENAME [TO] new_tbl_name +-- | ORDER BY col_name [, col_name] ... +-- | RENAME COLUMN old_col_name TO new_col_name +-- | RENAME {INDEX|KEY} old_index_name TO new_index_name +-- | CONVERT TO CHARACTER SET charset_name [COLLATE collation_name] +-- | [DEFAULT] CHARACTER SET [=] charset_name +-- | [DEFAULT] COLLATE [=] collation_name +-- | DISCARD TABLESPACE +-- | IMPORT TABLESPACE +-- | ALGORITHM [=] {DEFAULT|INPLACE|COPY|NOCOPY|INSTANT} +-- | LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE} +-- | FORCE +-- | partition_options +-- | CONVERT TABLE normal_table TO partition_definition +-- | CONVERT PARTITION partition_name TO TABLE tbl_name +-- | ADD PARTITION [IF NOT EXISTS] (partition_definition) +-- | DROP PARTITION [IF EXISTS] partition_names +-- | COALESCE PARTITION number +-- | REORGANIZE PARTITION [partition_names INTO (partition_definitions)] +-- | ANALYZE PARTITION partition_names +-- | CHECK PARTITION partition_names +-- | OPTIMIZE PARTITION partition_names +-- | REBUILD PARTITION partition_names +-- | REPAIR PARTITION partition_names +-- | EXCHANGE PARTITION partition_name WITH TABLE tbl_name +-- | REMOVE PARTITIONING +-- | ADD SYSTEM VERSIONING +-- | DROP SYSTEM VERSIONING +-- +-- index_col_name: +-- col_name [(length)] [ASC | DESC] +-- +-- index_type: +-- USING {BTREE | HASH | RTREE} +-- +-- index_option: +-- [ KEY_BLOCK_SIZE [=] value +-- | index_type +-- | WITH PARSER parser_name +-- | COMMENT 'string' +-- | CLUSTERING={YES| NO} ] +-- [ IGNORED | NOT IGNORED ] +-- +-- table_options: +-- table_option [[,] table_option] ... +-- ---------------------------------------------------------------------------- + +ALTER ONLINE IGNORE TABLE IF EXISTS tbl_name WAIT 100 +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- ^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ meta.table-name.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^ meta.number.integer.decimal.sql constant.numeric.value.sql + + ADD id INTEGER PRIMARY KEY +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql + + ADD COLUMN id INTEGER PRIMARY KEY +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql + + ADD COLUMN IF NOT EXISTS id INTEGER PRIMARY KEY +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql + + ADD (id INTEGER PRIMARY KEY, ) +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.section.group.end.sql + + ADD COLUMN (id INTEGER PRIMARY KEY, ) FIRST +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ keyword.other.position.sql + + ADD COLUMN IF NOT EXISTS (id INTEGER PRIMARY KEY, ) AFTER col +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^^^^ storage.type.sql +-- ^^^^^^^^^^^ storage.modifier.sql +-- ^ punctuation.separator.sequence.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^^ keyword.other.position.sql +-- ^^^ meta.column-name.sql + +-- ---------------------------------------------------------------------------- +-- ADD {INDEX|KEY} [IF NOT EXISTS] [index_name] +-- [index_type] (index_col_name,...) [index_option] ... +-- ADD FULLTEXT [INDEX|KEY] [index_name] +-- (index_col_name,...) [index_option] ... +-- ADD SPATIAL [INDEX|KEY] [index_name] +-- (index_col_name,...) [index_option] ... +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + ADD INDEX index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD INDEX IF NOT EXISTS index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD FULLTEXT INDEX index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD SPATIAL INDEX index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD KEY index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD FULLTEXT KEY index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD SPATIAL KEY index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD KEY IF NOT EXISTS index_name, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql + + ADD INDEX index_name USING BTREE (col1, col2, col3), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + + ADD INDEX index_name (col1, col2, col3) USING BTREE KEY_BLOCK_SIZE 10 WITH PARSER parser CLUSTERING = NO NOT IGNORED +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^ keyword.operator.comparison.sql +-- ^^ constant.language.boolean.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^ keyword.other.ddl.sql + +-- ---------------------------------------------------------------------------- +-- ADD [CONSTRAINT [symbol]] +-- FOREIGN KEY [IF NOT EXISTS] [index_name] (index_col_name,...) +-- reference_definition +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + ADD FOREIGN KEY (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + + ADD FOREIGN KEY IF NOT EXISTS (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + + ADD FOREIGN KEY index_name (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + + ADD FOREIGN KEY IF NOT EXISTS index_name (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + + ADD CONSTRAINT FOREIGN KEY index_name (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + + ADD CONSTRAINT symbol FOREIGN KEY index_name (col1, col2), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.separator.sequence.sql + +-- ---------------------------------------------------------------------------- +-- ADD [CONSTRAINT [symbol]] PRIMARY KEY +-- [index_type] (index_col_name,...) [index_option] ... +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + ADD PRIMARY KEY (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql +-- ^ punctuation.separator.sequence.sql + + ADD CONSTRAINT PRIMARY KEY (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + + ADD CONSTRAINT symbol PRIMARY KEY (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + + ADD CONSTRAINT symbol PRIMARY KEY USING BTREE (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql +-- ^^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + +-- ---------------------------------------------------------------------------- +-- ADD [CONSTRAINT [symbol]] +-- UNIQUE [INDEX|KEY] [index_name] +-- [index_type] (index_col_name,...) [index_option] ... +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + ADD UNIQUE INDEX index_name USING BTREE (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + + ADD UNIQUE KEY index_name USING BTREE (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + + ADD CONSTRAINT UNIQUE KEY index_name USING BTREE (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + + ADD CONSTRAINT symbol UNIQUE KEY index_name USING BTREE (col1, col2) WITH PARSER parser, +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^ constant.language.sql +-- ^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.other-name.sql + +-- ---------------------------------------------------------------------------- +-- ADD PARTITION ... +-- ADD PERIOD ... +-- ADD SYSTEM VERSIONING +-- ---------------------------------------------------------------------------- + + ADD PARTITION ( +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^ meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql +-- + partition1 +-- ^^^^^^^^^^ entity.name.struct.partition.sql + VALUES LESS THAN MAXVALUE +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ constant.language.sql + ), + + ADD PARTITION IF NOT EXISTS (partition1 DATA DIRECTORY '../dir'), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.partitions.sql +-- ^ punctuation.section.group.begin.sql +-- ^ punctuation.section.group.end.sql + + ADD PERIOD FOR SYSTEM_TIME (start_column_name, end_column_name), +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^^^^^^^^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^^^^^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + + ADD SYSTEM VERSIONING +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ constant.language.sql + +-- ---------------------------------------------------------------------------- +-- CHANGE [COLUMN] [IF EXISTS] old_col_name new_col_name column_definition +-- [FIRST | AFTER col_name] +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + CHANGE old_col new_col INTEGER NOT NULL FIRST +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql + + CHANGE IF EXISTS old_col new_col INTEGER NOT NULL AFTER col +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql +-- ^^^ meta.column-name.sql + + CHANGE COLUMN old_col new_col INTEGER NOT NULL FIRST +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql + + CHANGE COLUMN IF EXISTS old_col new_col INTEGER NOT NULL AFTER col +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql +-- ^^^ meta.column-name.sql + + CHANGE COLUMN old_col new_col ENUM('foo', 'bar') +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ meta.column-name.sql variable.other.member.declaration.sql +-- ^^^^ storage.type.sql - meta.parens +-- ^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^ meta.string.sql string.quoted.single.sql +-- ^ punctuation.section.group.end.sql + +-- ---------------------------------------------------------------------------- +-- MODIFY [COLUMN] [IF EXISTS] col_name column_definition +-- [FIRST | AFTER col_name] +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + MODIFY col_name INTEGER NOT NULL FIRST +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql + + MODIFY IF EXISTS col_name INTEGER NOT NULL AFTER col +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql +-- ^^^ meta.column-name.sql + + MODIFY COLUMN col_name INTEGER NOT NULL FIRST +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql + + MODIFY COLUMN IF EXISTS col_name INTEGER NOT NULL AFTER col +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^ meta.column-name.sql +-- ^^^^^^^ storage.type.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^ constant.language.null.sql +-- ^^^^^ keyword.other.position.sql +-- ^^^ meta.column-name.sql + +-- ---------------------------------------------------------------------------- +-- DROP [COLUMN] [IF EXISTS] col_name [RESTRICT|CASCADE] +-- DROP PRIMARY KEY +-- DROP {INDEX|KEY} [IF EXISTS] index_name +-- DROP FOREIGN KEY [IF EXISTS] fk_symbol +-- DROP CONSTRAINT [IF EXISTS] constraint_name +-- DROP PARTITION [IF EXISTS] partition_names +-- DROP SYSTEM VERSIONING +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + DROP col_name RESTRICT +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^^ keyword.other.ddl.sql + + DROP IF EXISTS col_name RESTRICT +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^^ keyword.other.ddl.sql + + DROP COLUMN col_name CASCADE +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^ keyword.other.ddl.sql + + DROP COLUMN IF EXISTS col_name CASCADE +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^ keyword.other.ddl.sql + + DROP CONSTRAINT constraint_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^ meta.constraint-name.sql + + DROP CONSTRAINT IF EXISTS constraint_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^ meta.constraint-name.sql + + DROP INDEX index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP INDEX IF EXISTS index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP KEY index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP KEY IF EXISTS index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP FOREIGN KEY index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP FOREIGN KEY IF EXISTS index_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^ meta.index-name.sql + + DROP PRIMARY KEY +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^ keyword.other.ddl.sql + + DROP PARTITION partition_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^ meta.partition-name.sql + + DROP PARTITION IF EXISTS partition_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.control.conditional.if.sql +-- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^ meta.partition-name.sql + + DROP SYSTEM VERSIONING +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^ constant.language.sql + +-- ---------------------------------------------------------------------------- +-- RENAME ... +-- ---------------------------------------------------------------------------- + +ALTER TABLE tbl_name + + RENAME new_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.table-name.sql + + RENAME TO new_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.table-name.sql + + RENAME COLUMN name TO new_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^ meta.column-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql + + RENAME INDEX name TO new_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^^^ keyword.other.ddl.sql +-- ^^^^ meta.index-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.index-name.sql + + RENAME KEY name TO new_name +-- <- meta.statement.alter.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^^^^ keyword.other.ddl.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^ meta.index-name.sql +-- ^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.index-name.sql + +ALTER TABLE tbl_name ALGORITHM = INPLACE +-- <- meta.statement.alter.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql + -- ---------------------------------------------------------------------------- -- Alter User Statements -- https://mariadb.com/kb/en/alter-user @@ -3495,27 +4347,6 @@ SELECT "My -- Crazy Column Name" FROM my_table; SELECT "My /* Crazy Column Name" FROM my_table; -- ^^ - comment - punctuation - -ALTER TABLE dbo.testing123 ADD COLUMN mycolumn longtext; --- <- meta.statement.alter.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql --- ^^ keyword.other.ddl --- ^^^^^ keyword.other.ddl --- ^^^^^^^^^^^^^^ meta.table-name.sql --- ^^^ keyword.other.ddl --- ^^^^^^ keyword.other.ddl --- ^^^^^^^^ meta.column-name --- ^^^^^^^^ storage.type.sql - -ALTER TABLE testing123 CHANGE COLUMN mycolumn mycolumn ENUM('foo', 'bar'); --- <- meta.statement.alter.sql keyword.other.ddl --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql --- ^^^^^^ keyword.other.ddl --- ^^^^^^ keyword.other.ddl --- ^^^^^^^^ meta.column-name --- ^^^^^^^^ meta.column-name variable.other.member.declaration --- ^^^^ storage.type.sql - DROP TABLE IF EXISTS testing123; -- <- meta.statement.drop.sql keyword.other.ddl -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql From ced567151f309514227115506c9f3c56995bbeb1 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 26 Oct 2023 17:42:45 +0200 Subject: [PATCH 236/250] [SQL] Re-add accidentally dropped syntax tests --- SQL/tests/syntax/syntax_test_tsql.sql | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index a04ada42ab..3e735eb542 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2525,6 +2525,37 @@ FROM @table_variable AS main CROSS JOIN some_func(@param) AS other -- ^^^^^^^ keyword.other.dml.sql +DROP TABLE IF EXISTS #SampleTempTable; +GO +CREATE TABLE #SampleTempTable (id INT, message nvarchar(50)); +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^ meta.table.sql entity.name.struct.table.sql +-- ^ punctuation.definition.variable.tsql +INSERT INTO #SampleTempTable VALUES (null, 'hello'); +-- ^^^^^^^^ keyword.other.dml.sql +-- ^ meta.table-name.sql punctuation.definition.variable.tsql +-- ^^^^^^^^^^^^^^^ meta.table-name.sql - punctuation +INSERT INTO #SampleTempTable VALUES (10, null); +INSERT INTO #SampleTempTable VALUES (17, 'abc'); +INSERT INTO #SampleTempTable VALUES (17, 'yes'); +INSERT INTO #SampleTempTable VALUES (null, null); +GO + +SELECT * FROM #SampleTempTable WHERE id IS DISTINCT FROM 17; +DROP TABLE IF EXISTS #SampleTempTable; +GO + +ALTER TABLE a.b WITH CHECK +-- ^^^^^^^^^^ meta.statement.alter.sql keyword.other.ddl.tsql + ADD CONSTRAINT fk_b_c +-- ^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^ keyword.other.ddl.sql +-- ^^^^^^ meta.constraint-name.sql + FOREIGN KEY (some_id) REFERENCES a.c (some_id); +-- ^^^^^^^^^^^ meta.statement.alter.sql storage.modifier.sql + SELECT * FROM table FOR SYSTEM_TIME AS OF 131512 alias -- ^^^^^^^^^^^^^^^ keyword.other.dml.sql -- ^^^^^ keyword.operator.logical From d837ea32bb68acce4af597cd33f4bdfca715562a Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 26 Oct 2023 17:53:53 +0200 Subject: [PATCH 237/250] [SQL] Add some drop user tests --- SQL/tests/syntax/syntax_test_cassandra.cql | 10 ++++++++++ SQL/tests/syntax/syntax_test_mysql.sql | 8 +++++++- SQL/tests/syntax/syntax_test_tsql.sql | 10 ++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index abcc5f41e8..33f1251a0d 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -570,3 +570,13 @@ set x = 4 -- ^ meta.column-name -- ^ keyword.operator -- ^ meta.number.integer.decimal constant.numeric.value + +DROP USER iffy ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^ meta.other-name.sql + +DROP USER IF EXISTS iffy ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^ meta.other-name.sql diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 247383f72e..eeb1d2671f 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -3341,7 +3341,13 @@ DROP USER bob@'%' ; -- ^ punctuation.accessor.at.sql -- ^ punctuation.terminator.statement.sql -DROP USER IF EXISTS bob, clara@localhost ; +DROP USER iffy ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^ meta.statement.drop.sql - meta.user +-- ^^^^^^^^^ meta.statement.drop.sql meta.user.sql +-- ^^^^ meta.username.sql + +DROP USER IF EXISTS ify, clara@localhost ; -- <- meta.statement.drop.sql keyword.other.ddl.sql -- ^^ meta.statement.drop.sql - meta.user -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql meta.user.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 3e735eb542..88e45b3e6d 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2287,6 +2287,16 @@ create user user_name_in_sql -- ^ string.unquoted.tsql -- ^ punctuation.terminator.statement.sql +DROP USER iffy ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^ meta.other-name.sql + +DROP USER IF EXISTS iffy ; +-- <- meta.statement.drop.sql keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql +-- ^^^^ meta.other-name.sql + DROP USER IF EXISTS "some-name-here"; -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql -- ^ keyword.other.ddl.sql From 9ab469de8c14eb686bc3b7a31bde6ad98d618dba Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 31 Oct 2023 23:03:30 +0200 Subject: [PATCH 238/250] [SQL] fix failing syntax test --- SQL/tests/syntax/syntax_test_postgres.psql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/tests/syntax/syntax_test_postgres.psql b/SQL/tests/syntax/syntax_test_postgres.psql index fb7e4bc755..fc1cedd597 100644 --- a/SQL/tests/syntax/syntax_test_postgres.psql +++ b/SQL/tests/syntax/syntax_test_postgres.psql @@ -515,7 +515,7 @@ BEGIN -- ^^^^ keyword.control.loop output[I] := compute_result(vals[I], something, something_else); END LOOP; --- ^^^ keyword.control.flow.end +-- ^^^ keyword.control.loop -- ^^^^ keyword.control.loop RETURN output; -- ^^^^^^ keyword.control.flow.return From 6dcaafe0f73722c6ac64695fed7f4b447d3af1d4 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 31 Oct 2023 23:08:31 +0200 Subject: [PATCH 239/250] [SQL] reintroduce distinction between table aliases and column aliases for more customizable highlighting between the two --- SQL/SQL (basic).sublime-syntax | 34 ++++++++++------ SQL/TSQL.sublime-syntax | 7 +--- SQL/tests/syntax/syntax_test_mysql.sql | 32 +++++++-------- SQL/tests/syntax/syntax_test_tsql.sql | 54 +++++++++++++------------- 4 files changed, 68 insertions(+), 59 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index c51e6f0a1f..88ec584e08 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -572,7 +572,7 @@ contexts: - include: groups - include: comma-separators - include: operators - - include: alias-expressions + - include: column-alias-expressions - include: case-expressions - include: collate-expressions - include: constraint-expressions @@ -583,15 +583,15 @@ contexts: - match: (?=;) pop: 1 - alias-expressions: + column-alias-expressions: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql - push: expect-alias-name + push: expect-column-alias-name - alias-expression: + table-alias-expression: - match: \b(?i:as)\b scope: keyword.operator.assignment.alias.sql - set: expect-alias-name + set: expect-table-alias-name case-expressions: - match: \b(?i:case)\b @@ -930,8 +930,8 @@ contexts: maybe-table-alias: - include: pop-on-top-level-reserved-word - include: table-timespecs - - include: alias-expression - - include: expect-alias-name + - include: table-alias-expression + - include: expect-table-alias-name table-timespecs: - match: \b(?i:for\s+system_time)\b @@ -1028,16 +1028,28 @@ contexts: ###[ IDENTIFIERS ]############################################################# - expect-alias-name: + expect-table-alias-name: # prevent prototypes from inheriting syntaxes - meta_include_prototype: false - include: comments - match: (?=\S) - set: [alias-name, single-identifier] + set: [table-alias-name, single-identifier] - alias-name: + expect-column-alias-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [column-alias-name, single-identifier] + + table-alias-name: + - meta_include_prototype: false + - meta_content_scope: meta.alias.table.sql + - include: immediately-pop + + column-alias-name: - meta_include_prototype: false - - meta_content_scope: meta.alias.sql + - meta_content_scope: meta.alias.column.sql - include: immediately-pop expect-column-names: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 34c9717d43..a399a68747 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -862,14 +862,11 @@ contexts: - include: table-hints-without-with maybe-table-alias: + - meta_prepend: true - include: table-timespecs - include: with-table-options - match: (?=\b(?i:unpivot|pivot)\b) pop: 1 - - match: \b(?i:as)\b - scope: keyword.operator.assignment.alias.sql - set: expect-table-alias-name - - include: expect-table-alias-name expect-table-alias-name: - meta_include_prototype: false @@ -877,7 +874,7 @@ contexts: - match: (?=\S) set: - maybe-table-sample - - alias-name + - table-alias-name - single-identifier maybe-table-sample: diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index eeb1d2671f..61c2a2dad1 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -3993,11 +3993,11 @@ JOIN (table1 alias, table2 AS alias ON (col1=col2), table3 PARTITION(part1) USE -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql -- ^ punctuation.section.group.begin.sql -- ^^^^^^ meta.table-name.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql -- ^ punctuation.separator.sequence.sql -- ^^^^^^ meta.table-name.sql -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql -- ^^ keyword.control.conditional.sql -- ^^^^^^^^^^^ meta.group.sql -- ^ punctuation.section.group.begin.sql @@ -4050,7 +4050,7 @@ JOIN ( ( SELECT * FROM foo JOIN bar IGNORE KEY id ) alias, ( table1, ( SELECT * -- ^^^^^^^^^^ keyword.other.dml.sql -- ^^ meta.column-name.sql -- ^ punctuation.section.group.end.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql -- ^ punctuation.separator.sequence.sql -- ^ punctuation.section.group.begin.sql -- ^^^^^^ meta.table-name.sql @@ -4076,20 +4076,20 @@ INNER JOIN tbl_name PARTITION (part1, part2, part3) INNER JOIN tbl_name alias -- ^^^^ keyword.other.dml.sql -- ^^^^^^^^ meta.table-name.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql INNER JOIN tbl_name AS alias -- ^^^^ keyword.other.dml.sql -- ^^^^^^^^ meta.table-name.sql -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql INNER JOIN tbl_name PARTITION () alias -- ^^^^ keyword.other.dml.sql -- ^^^^^^^^ meta.table-name.sql -- ^^^^^^^^^ keyword.other.dml.sql -- ^^ meta.group.partitions.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql INNER JOIN tbl_name PARTITION () AS alias -- ^^^^ keyword.other.dml.sql @@ -4097,14 +4097,14 @@ INNER JOIN tbl_name PARTITION () AS alias -- ^^^^^^^^^ keyword.other.dml.sql -- ^^ meta.group.partitions.sql -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql INNER JOIN tbl_name FOR SYSTEM_TIME ALL alias -- ^^^^ keyword.other.dml.sql -- ^^^^^^^^ meta.table-name.sql -- ^^^^^^^^^^^^^^^ keyword.other.dml.sql -- ^^^ constant.other.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql INNER JOIN tbl_name FOR SYSTEM_TIME AS OF 20341 alias -- ^^^^ keyword.other.dml.sql @@ -4112,7 +4112,7 @@ INNER JOIN tbl_name FOR SYSTEM_TIME AS OF 20341 alias -- ^^^^^^^^^^^^^^^ keyword.other.dml.sql -- ^^^^^ keyword.operator.logical.sql -- ^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql INNER JOIN tbl_name FOR SYSTEM_TIME FROM 20341 TO 423204 alias -- ^^^^ keyword.other.dml.sql @@ -4122,7 +4122,7 @@ INNER JOIN tbl_name FOR SYSTEM_TIME FROM 20341 TO 423204 alias -- ^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql -- ^^ keyword.operator.logical.sql -- ^^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql INNER JOIN (SELECT * FROM tbl_name) alias USE KEY bar -- ^^^^ keyword.other.dml.sql @@ -4133,7 +4133,7 @@ INNER JOIN (SELECT * FROM tbl_name) alias USE KEY bar -- ^^^^ keyword.other.dml.sql -- ^^^^^^^^ meta.table-name.sql -- ^ punctuation.section.group.end.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql -- ^^^^^^^ keyword.other.dml.sql -- ^^^ meta.column-name.sql @@ -4155,7 +4155,7 @@ INNER JOIN (SELECT * FROM tbl_name) PARTITION (part1, part2, part3) alias -- ^ punctuation.separator.sequence.sql -- ^^^^^ meta.partition-name.sql -- ^ punctuation.section.group.end.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql INNER JOIN {ON tbl_name LEFT OUTER JOIN other1 other2 ON TRUE} -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.braces.mysql @@ -4165,7 +4165,7 @@ INNER JOIN {ON tbl_name LEFT OUTER JOIN other1 other2 ON TRUE} -- ^^^^^^^^ meta.table-name.sql -- ^^^^^^^^^^^^^^^ keyword.other.dml.sql -- ^^^^^^ meta.table-name.sql --- ^^^^^^ meta.alias.sql +-- ^^^^^^ meta.alias.table.sql -- ^^ keyword.control.conditional.sql -- ^^^^ constant.language.boolean.sql -- ^ punctuation.section.braces.end.mysql @@ -4207,7 +4207,7 @@ INNER JOIN tbl_name USING (col1, col2) INNER JOIN tbl_name alias USING (col1, col2) -- ^^^^ keyword.other.dml.sql -- ^^^^^^^^ meta.table-name.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql -- ^^^^^ keyword.other.dml.sql -- ^^^^^^^^^^^^ meta.group.table-columns.sql -- ^ punctuation.section.group.begin.sql @@ -4220,7 +4220,7 @@ INNER JOIN tbl_name AS alias USING (col1, col2) -- ^^^^ keyword.other.dml.sql -- ^^^^^^^^ meta.table-name.sql -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql -- ^^^^^ keyword.other.dml.sql -- ^^^^^^^^^^^^ meta.group.table-columns.sql -- ^ punctuation.section.group.begin.sql @@ -4407,7 +4407,7 @@ SELECT *, -- ^ constant.other.wildcard.asterisk.sql f.id AS database_id -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^^^^^^^ meta.alias +-- ^^^^^^^^^^^ meta.alias.column FROM foo WHERE f.a IS NULL -- ^^ keyword.other.dml.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 88e45b3e6d..d7eefc0276 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -432,7 +432,7 @@ SELECT foo AS foobar, COUNT(*) AS tally -- ^^^ keyword.other.dml -- ^^^ meta.column-name -- ^^ keyword.operator.assignment.alias --- ^^^^^^ meta.alias +-- ^^^^^^ meta.alias.column -- ^ punctuation.separator.sequence -- ^^^^^^^^ meta.function-call -- ^^^^^ support.function.aggregate @@ -441,7 +441,7 @@ SELECT foo AS foobar, COUNT(*) AS tally -- ^ constant.other.wildcard.asterisk -- ^ punctuation.section.arguments.end -- ^^ keyword.operator.assignment.alias --- ^^^^^ meta.alias +-- ^^^^^ meta.alias.column FROM bar -- ^ keyword.other.dml -- ^^^ meta.table-name @@ -458,7 +458,7 @@ from (select * from some_table) alias_table WITH (NOLOCK) -- ^ constant.other.wildcard.asterisk -- ^^^^^^^^^^ meta.table-name -- ^ punctuation.section.group.end --- ^^^^^^^^^^^ meta.alias +-- ^^^^^^^^^^^ meta.alias.table -- ^^^^ keyword.other.dml -- ^ punctuation.section.group.begin -- ^^^^^^ meta.group constant.language.with @@ -483,7 +483,7 @@ FROM RealTableName TableAlias WITH (UPDLOCK, SOMETHING) -- ^ - meta.table-name -- ^^^^^^^^^^^^^ meta.table-name -- ^ - meta.table-name - meta.alias --- ^^^^^^^^^^ meta.alias +-- ^^^^^^^^^^ meta.alias.table -- ^ - meta.alias -- ^^^^ keyword.other -- ^^^^^^^^^^^^^^^^^^^^ meta.group @@ -500,7 +500,7 @@ INNER JOIN some_view AS AS WITH (NOLOCK) ON v.some_id = TableAlias.some_id -- ^ - meta.table-name -- ^^ keyword.operator.assignment.alias -- ^ - meta.alias --- ^^ meta.alias +-- ^^ meta.alias.table -- ^ - meta.alias -- ^^^^ keyword.other.dml -- ^^^^^^^^ meta.group @@ -528,7 +528,7 @@ WHERE TableAlias.some_id IN ( -- ^ - meta.table-name -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^ - meta.table-name - meta.alias --- ^ meta.alias +-- ^ meta.alias.table -- ^ - meta.alias WHERE a.another_id_column IS NOT NULL -- ^^^^^ keyword.other.dml @@ -599,7 +599,7 @@ SELECT i.ProductID, p.Name, i.LocationID, i.Quantity -- ^^^^^^^^ meta.group keyword.other.dml -- ^^^^ meta.group keyword.other.order -- ^^ keyword.operator.assignment.alias --- ^^^^ meta.alias +-- ^^^^ meta.alias.column FROM Production.ProductInventory AS i INNER JOIN Production.Product AS p ON i.ProductID = p.ProductID @@ -656,7 +656,7 @@ LEFT OUTER JOIN another_long_table_name (NOLOCK) a ON s.blah = a.blah AND ISNULL -- ^^^^^^^^^^^^ keyword.other.dml -- ^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^^^^^^ invalid.deprecated.table-hint-without-with.tsql constant.language.table-hint.tsql --- ^ meta.alias +-- ^ meta.alias.table -- ^^ keyword.control.conditional -- ^^^^^^ meta.column-name -- ^ keyword.operator.comparison @@ -742,7 +742,7 @@ from @A A -- ^ keyword.other.dml -- ^ meta.table-name.sql variable.other.readwrite.sql punctuation.definition.variable.sql -- ^ meta.table-name.sql variable.other.readwrite.sql --- ^ meta.alias +-- ^ meta.alias.table inner join B ON (SELECT TOP 1 C.ID FROM C WHERE C.B LIKE B.C + '%' ORDER BY LEN(B.C) DESC) = B.ID --^^^^^^^^ keyword.other.dml -- ^ meta.table-name @@ -1089,7 +1089,7 @@ PIVOT -- ^ punctuation.separator.sequence ) AS PivotTable; --^^ keyword.operator.assignment.alias --- ^^^^^^^^^^ meta.alias +-- ^^^^^^^^^^ meta.alias.table -- ^ punctuation.terminator.statement SELECT item.ID AS DatePivotID, @@ -1099,7 +1099,7 @@ UNPIVOT (dDate FOR nDate IN (date1, date2, date3, date4)) AS item -- <- keyword.other -- ^^^^ keyword.other -- ^^ keyword.operator.assignment.alias --- ^^^^ meta.alias +-- ^^^^ meta.alias.table GROUP BY item.ID -- ^^^^^ keyword.other.dml @@ -1131,7 +1131,7 @@ UNPIVOT ) AS unpvt; -- <- meta.group punctuation.section.group.end --^^ keyword.operator.assignment.alias --- ^^^^^ meta.alias +-- ^^^^^ meta.alias.table -- ^ punctuation.terminator.statement GO @@ -1218,14 +1218,14 @@ MERGE sales.category t -- ^ - meta.table-name -- ^^^^^^^^^^^^^^ meta.table-name -- ^ - meta.table-name - meta.alias --- ^ meta.alias +-- ^ meta.alias.table -- ^ - meta.alias USING sales.category_staging s -- ^^^^^ keyword.context.resource.tsql -- ^ - meta.table-name -- ^^^^^^^^^^^^^^^^^^^^^^ meta.table-name -- ^ - meta.table-name - meta.alias --- ^ meta.alias +-- ^ meta.alias.table -- ^ - meta.alias ON (s.category_id = t.category_id) -- <- keyword.control.conditional @@ -1522,7 +1522,7 @@ CROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) AS func_call_resu -- ^^^^^^^^^^^^^^ meta.column-name -- ^ punctuation.section.arguments.end -- ^^ keyword.operator.assignment.alias - meta.function-call --- ^^^^^^^^^^^^^^^^^^^^^^^ meta.alias +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.alias.table GO SELECT * FROM Department D @@ -1544,7 +1544,7 @@ CROSS APPLY sys.dm_exec_sql_text(r.plan_handle) st -- ^ meta.function-call meta.group punctuation.section.arguments.begin -- ^^^^^^^^^^^^^ meta.function-call meta.group meta.column-name -- ^ meta.function-call meta.group punctuation.section.arguments.end --- ^^ meta.alias +-- ^^ meta.alias.table WHERE r.session_Id > 50 -- Consider spids for users only, no system spids. AND r.session_Id NOT IN (@@SPID) -- Don't include request from current spid. -- ^ meta.group punctuation.section.group.begin @@ -1566,7 +1566,7 @@ SELECT p.BusinessEntityID , -- ^^^^^^^^^^^^^^^^^ variable.function -- ^ punctuation.accessor.dot FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) --- ^ meta.alias +-- ^ meta.alias.table -- ^^^^^^^^^^^ keyword.other -- ^^^^^^^^^^^^ meta.group.tablesample -- ^ punctuation.section.group.begin @@ -1578,7 +1578,7 @@ FROM Person.Person AS p TABLESAMPLE (10 PERCENT) REPEATABLE (123) -- ^^^ meta.group meta.number.integer.decimal constant.numeric.value -- ^ meta.group punctuation.section.group.end LEFT OUTER JOIN Person.PersonPhone AS pp TABLESAMPLE SYSTEM (10 ROWS) --- ^^ meta.alias +-- ^^ meta.alias.table -- ^^^^^^^^^^^^^^^^^^ keyword.other -- ^^^^^^^^^ meta.group.tablesample -- ^ punctuation.section.group.begin @@ -1741,7 +1741,7 @@ SELECT * FROM table_name AS t1 INNER JOIN (SELECT foo FROM bar) AS t2(id) ON t2.ID = t1.ID -- ^^ keyword.operator.assignment.alias --- ^^ meta.alias +-- ^^ meta.alias.table -- ^^^^ meta.group -- ^ punctuation.section.group.begin -- ^^ meta.column-name @@ -1762,7 +1762,7 @@ SELECT a.* Customers) AS a; -- ^ meta.function-call meta.group punctuation.section.arguments.end -- ^^ keyword.operator.assignment.alias - meta.group - meta.function-call --- ^ meta.alias +-- ^ meta.alias.table DECLARE @Data NVARCHAR(MAX) -- ^^^^^^^^^^^^^ storage.type.sql @@ -2344,7 +2344,7 @@ SELECT TOP 10 City, STRING_AGG(CONVERT(NVARCHAR(max), EmailAddress), ';') WITHIN -- ^^^ meta.group.sql keyword.other.order.sql -- ^ meta.group.sql punctuation.section.group.end.sql -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^^ meta.alias.sql +-- ^^^^^^ meta.alias.column.sql FROM Person.BusinessEntityAddress AS BEA INNER JOIN Person.Address AS A ON BEA.AddressID = A.AddressID INNER JOIN Person.EmailAddress AS EA ON BEA.BusinessEntityID = EA.BusinessEntityID @@ -2458,7 +2458,7 @@ select * from @inserted merge into @foo foo -- ^^^^^^^ keyword.other.tsql -- ^^^^ meta.table-name.sql variable.other.readwrite.sql --- ^^^ meta.alias.sql +-- ^^^ meta.alias.table.sql using (values ( -- ^^ keyword.context.resource.tsql -- ^ meta.group.sql punctuation.section.group.begin.sql @@ -2471,7 +2471,7 @@ using (values ( -- ^ meta.group.sql punctuation.section.group.end.sql - meta.group meta.group -- ^^ keyword.operator.assignment.alias.sql - meta.group bar ( --- ^^^ meta.alias.sql +-- ^^^ meta.alias.table.sql -- ^ meta.group.sql punctuation.section.group.begin.sql a, -- ^ meta.group.sql meta.column-name.sql @@ -2497,12 +2497,12 @@ MERGE INTO some_schema.some_table WITH (holdlock) AS target -- ^^^^^^^^ meta.group.sql constant.language.with.tsql -- ^ meta.group.sql punctuation.section.group.end.sql -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^^ meta.alias.sql +-- ^^^^^^ meta.alias.table.sql USING some_schema.another_table AS source -- ^^ keyword.context.resource.tsql -- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.table-name.sql -- ^^ keyword.operator.assignment.alias.sql --- ^^^^^^ meta.alias.sql +-- ^^^^^^ meta.alias.table.sql ON source.some_id = target.some_id -- <- keyword.control.conditional.sql when matched then @@ -2570,7 +2570,7 @@ SELECT * FROM table FOR SYSTEM_TIME AS OF 131512 alias -- ^^^^^^^^^^^^^^^ keyword.other.dml.sql -- ^^^^^ keyword.operator.logical -- ^^^^^^ meta.number.integer.decimal.sql constant.numeric.value.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql SELECT * FROM table FOR SYSTEM_TIME CONTAINED IN (131512, 231) alias -- ^^^^^^^^^^^^^^^ keyword.other.dml.sql @@ -2581,5 +2581,5 @@ SELECT * FROM table FOR SYSTEM_TIME CONTAINED IN (131512, 231) alias -- ^ punctuation.separator.sequence.sql -- ^^^ meta.number.integer.decimal.sql constant.numeric.value.sql -- ^ punctuation.section.group.end.sql --- ^^^^^ meta.alias.sql +-- ^^^^^ meta.alias.table.sql -- From 24583c34ce1d5b9add5f547dc2bc26f7cf8b65c0 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 31 Oct 2023 23:13:59 +0200 Subject: [PATCH 240/250] [SQL] remove unnecessary include --- SQL/TSQL.sublime-syntax | 1 - 1 file changed, 1 deletion(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index a399a68747..2a6e470ff7 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -878,7 +878,6 @@ contexts: - single-identifier maybe-table-sample: - - include: groups # alias-list - include: table-hints-without-with - include: with-table-options - match: \b(?i:tablesample(?:\s+system)?)\b From 6a0de68c4c4d460d08d92bbd8a701d2c940bcc7b Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 31 Oct 2023 23:16:13 +0200 Subject: [PATCH 241/250] [SQL] small tweak to keep using base syntax as much as possible --- SQL/TSQL.sublime-syntax | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 2a6e470ff7..d9a8addc92 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -868,14 +868,10 @@ contexts: - match: (?=\b(?i:unpivot|pivot)\b) pop: 1 - expect-table-alias-name: - - meta_include_prototype: false - - include: comments - - match: (?=\S) - set: - - maybe-table-sample - - table-alias-name - - single-identifier + table-alias-name: + - meta_prepend: true + - match: '' + set: maybe-table-sample maybe-table-sample: - include: table-hints-without-with From c49b7f8a551813cf5ff2104fbc2d3f54dd975d15 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 1 Nov 2023 20:34:08 +0100 Subject: [PATCH 242/250] [SQL] Fix PHP interpolation --- SQL/SQL (basic).sublime-syntax | 1 + 1 file changed, 1 insertion(+) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 88ec584e08..6333c18813 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -880,6 +880,7 @@ contexts: ###[ TABLE NAMES OR SUBQUERIES ]############################################### table-name-or-subquery: + - meta_include_prototype: false - include: table-subquery - include: table-name-or-function-call From a4bad7366868c94c632cdb43f6ff4edd5854179f Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 13 Nov 2023 09:42:08 +0200 Subject: [PATCH 243/250] [SQL] fix source.sql scope not being applied to DELETE statements in Python strings --- Python/tests/syntax_test_python_strings.py | 3 +++ SQL/SQL (basic).sublime-syntax | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Python/tests/syntax_test_python_strings.py b/Python/tests/syntax_test_python_strings.py index 45552f5d60..ddefff8333 100644 --- a/Python/tests/syntax_test_python_strings.py +++ b/Python/tests/syntax_test_python_strings.py @@ -793,6 +793,9 @@ COMMIT;" # ^^^^^^ meta.string.python source.sql - string +sql = "DELETE FROM HumanResources.JobCandidate WHERE JobCandidateID = 13;" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.python source.sql - string.quoted + sql = Ur"SELECT `name` FROM `users` \ WHERE `password` LIKE 'abc'" #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.python source.sql - string.quoted.double diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 6333c18813..1f71bec998 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -462,7 +462,7 @@ contexts: scope: keyword.other.dml.sql - match: \b(?i:(?:delete(?:\s+from)?))\b scope: keyword.other.dml.sql - set: dml-delete + push: dml-delete - match: \b(?i:update)\b scope: keyword.other.dml.sql push: dml-update From 734d51d0e8406b8ad8fe0f9b52f6d8a3dc66e355 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 13 Nov 2023 10:00:58 +0200 Subject: [PATCH 244/250] [SQL] fix foreign key column name references and unique constraints --- SQL/SQL (basic).sublime-syntax | 10 +++++++++- SQL/tests/syntax/syntax_test_tsql.sql | 20 +++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 1f71bec998..7c1655fdf4 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -773,11 +773,19 @@ contexts: scope: keyword.other.sql - match: |- \b(?xi: - (?: (?: foreign | fulltext | primary | unique ) \s+ )? key + (?: (?: fulltext | primary | unique ) \s+ )? key | on \s+ (?: delete | update ) (?: \s+ cascade )? | default )\b scope: storage.modifier.sql + - match: |- + \b(?xi: + foreign\s+key + )\b + scope: storage.modifier.sql + push: column-name-list + - match: \b(?i:unique)\b + scope: storage.modifier.sql push: maybe-column-name-list - match: \b(?i:references)\b scope: storage.modifier.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index d7eefc0276..2711281093 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2564,7 +2564,11 @@ ALTER TABLE a.b WITH CHECK -- ^^^^^^^^^^ keyword.other.ddl.sql -- ^^^^^^ meta.constraint-name.sql FOREIGN KEY (some_id) REFERENCES a.c (some_id); --- ^^^^^^^^^^^ meta.statement.alter.sql storage.modifier.sql +-- ^^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^ meta.group.table-columns.sql +-- ^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^ meta.group.table-columns.sql + SELECT * FROM table FOR SYSTEM_TIME AS OF 131512 alias -- ^^^^^^^^^^^^^^^ keyword.other.dml.sql @@ -2583,3 +2587,17 @@ SELECT * FROM table FOR SYSTEM_TIME CONTAINED IN (131512, 231) alias -- ^ punctuation.section.group.end.sql -- ^^^^^ meta.alias.table.sql -- + +CREATE TABLE a.b ( + id int + CONSTRAINT pk_b PRIMARY KEY, + external_id varchar(256) NOT NULL + CONSTRAINT uq_b_external_id UNIQUE, +-- ^^^^^^^^^^ storage.modifier.sql +-- ^^^^^^^^^^^^^^^^ meta.constraint-name.sql +-- ^^^^^^ storage.modifier.sql +-- ^ punctuation.separator.sequence.sql + name varchar(512) NOT NULL +-- ^^^^ meta.column-name.sql variable.other.member.declaration.sql +); +-- <- meta.statement.create.sql meta.table.sql meta.group.table-columns.sql punctuation.section.group.end.sql From b639a414735f0de4fcee34521b5089dc5f9527db Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 26 Nov 2023 14:31:58 +0200 Subject: [PATCH 245/250] [SQL] fix ALTER TABLE ... ADD sequence TYPE not being scoped correctly ADD SEQUENCE isn't valid inside an ALTER TABLE context, so `sequence` here needs to be treated as a column name --- SQL/SQL (basic).sublime-syntax | 7 +++++-- SQL/tests/syntax/syntax_test_tsql.sql | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 7c1655fdf4..2b51b7a084 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -29,6 +29,9 @@ variables: | language | member | operator\s+class | operator | role | rule | schema | sequence | tablespace | trigger | type | user | view ) + ddl_target_inside_alter_table: |- + (?xi: constraint ) + ddl_target_function_modifier: |- (?xi: aggregate ) ddl_target_index_modifier: |- @@ -412,14 +415,14 @@ contexts: - include: else-pop alter-columns: - - match: \b(?i:(add|alter)(?:\s+(column)|(?!\s+{{ddl_target}})))\b + - match: \b(?i:(?:(add|alter)\b(?:\s+(column)\b|(?!\s+(?:table|{{ddl_target_inside_alter_table}})\b)))) captures: 1: keyword.other.ddl.sql 2: keyword.other.ddl.sql push: - expect-type - expect-column-name-declaration - - match: \b(?i:(drop)(?:\s+(column)|(?!\s+{{ddl_target}})))\b + - match: \b(?i:(drop)(?:\s+(column)\b|(?!\s+{{ddl_target}}\b))) scope: keyword.other.ddl.sql push: expect-column-name diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 2711281093..3634a94d1b 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2601,3 +2601,17 @@ CREATE TABLE a.b ( -- ^^^^ meta.column-name.sql variable.other.member.declaration.sql ); -- <- meta.statement.create.sql meta.table.sql meta.group.table-columns.sql punctuation.section.group.end.sql + +ALTER TABLE schema.table + ADD sequence smallint NOT NULL; +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^^^^^^^^ storage.type.sql + +ALTER TABLE schema.table + ADD constraint_not bit; +-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql +-- ^^^ keyword.other.ddl.sql +-- ^^^^^^^^^^^^^^ meta.column-name.sql +-- ^^^ storage.type.sql From 7477d3fb4f125e6f0e81cdf4d610e9800e856b41 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 13 Nov 2023 10:58:15 +0200 Subject: [PATCH 246/250] [SQL] fix DROP USER scoping of user names beginning with IF --- SQL/SQL (basic).sublime-syntax | 7 +++---- SQL/TSQL.sublime-syntax | 4 ++++ SQL/tests/syntax/syntax_test_cassandra.cql | 4 ++-- SQL/tests/syntax/syntax_test_tsql.sql | 17 +++++++++++++---- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index 2b51b7a084..e47d144994 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -297,12 +297,11 @@ contexts: - include: immediately-pop drop-other: - - match: \b(?i:user(?!\s+if))\b + - match: \b(?i:user)\b scope: storage.type.sql set: - - grant - - user-name - - single-identifier + - expect-user-name + - maybe-condition - match: \b{{ddl_target_other}}\b scope: keyword.other.ddl.sql set: diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index d9a8addc92..c7f73644da 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -641,6 +641,10 @@ contexts: - single-identifier - match: \w+ scope: string.unquoted.tsql + - match: (?=\[) + set: + - generic-identifier-name + - single-identifier generic-identifier-name: - meta_include_prototype: false diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 33f1251a0d..868b3d09ca 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -574,9 +574,9 @@ set x = 4 DROP USER iffy ; -- <- meta.statement.drop.sql keyword.other.ddl.sql -- ^^^^^^^^^^^ meta.statement.drop.sql --- ^^^^ meta.other-name.sql +-- ^^^^ meta.username.sql DROP USER IF EXISTS iffy ; -- <- meta.statement.drop.sql keyword.other.ddl.sql -- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql --- ^^^^ meta.other-name.sql +-- ^^^^ meta.username.sql diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 3634a94d1b..2b87f846e4 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2290,19 +2290,23 @@ create user user_name_in_sql DROP USER iffy ; -- <- meta.statement.drop.sql keyword.other.ddl.sql -- ^^^^^^^^^^^ meta.statement.drop.sql --- ^^^^ meta.other-name.sql +-- ^^^^ storage.type.sql - meta.username +-- ^^^^ meta.username.sql DROP USER IF EXISTS iffy ; -- <- meta.statement.drop.sql keyword.other.ddl.sql -- ^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql --- ^^^^ meta.other-name.sql +-- ^^^^ storage.type.sql - meta.username +-- ^^ keyword.control.conditional.if.sql - meta.username +-- ^^^^^^ keyword.operator.logical.sql - meta.username +-- ^^^^ meta.username.sql DROP USER IF EXISTS "some-name-here"; -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.drop.sql -- ^ keyword.other.ddl.sql --- ^^^^ keyword.other.ddl.sql +-- ^^^^ storage.type.sql -- ^^ keyword.control.conditional.if.sql --- ^^^^^^ keyword.operator.logical.sql +-- ^^^^^^ keyword.operator.logical.sql - meta.username -- ^ punctuation.definition.identifier.begin.sql -- ^ punctuation.definition.identifier.end.sql -- ^ punctuation.terminator.statement.sql @@ -2403,6 +2407,11 @@ CREATE USER [foo] WITHOUT LOGIN WITH DEFAULT_SCHEMA=[bar] -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.create.sql -- ^^^^^^^^^^^^^ storage.modifier.tsql -- ^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^ constant.language.with.tsql +-- ^ keyword.operator.assignment.tsql +-- ^^^^^ string +-- ^ punctuation.definition.identifier.begin.sql +-- ^ punctuation.definition.identifier.end.sql GO -- <- keyword.control.flow.go.tsql - meta.statement.create From 88751b55eb0c7a48b69e18a1a308317f534cd35d Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 14 Nov 2023 08:47:17 +0200 Subject: [PATCH 247/250] [SQL] fix TSQL MERGE WHEN expressions --- SQL/TSQL.sublime-syntax | 11 ++++++--- SQL/tests/syntax/syntax_test_tsql.sql | 35 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index c7f73644da..694fe3e072 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -483,15 +483,20 @@ contexts: scope: keyword.other.tsql - match: \b(?i:then)\b scope: keyword.other.tsql - - match: \b(?i:insert)\b(?=\s*\() - scope: keyword.other.dml.sql - push: values-or-expressions + set: maybe-merge-insert + - include: values-or-expressions - include: pop-on-top-level-reserved-word values-or-expressions: - include: dml-statements - include: expressions + maybe-merge-insert: + - match: \b(?i:insert)\b(?=\s*\() + scope: keyword.other.dml.sql + set: values-or-expressions + - include: else-pop + ###[ COLUMN EXPRESSIONS ]###################################################### maybe-column-declaration-list: diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index 2b87f846e4..b7a7743696 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2624,3 +2624,38 @@ ALTER TABLE schema.table -- ^^^ keyword.other.ddl.sql -- ^^^^^^^^^^^^^^ meta.column-name.sql -- ^^^ storage.type.sql + +MERGE a.b WITH (HOLDLOCK, UPDLOCK) lock +USING (SELECT @name AS name) job + ON lock.name = job.name +WHEN MATCHED AND (acquired IS NULL OR @now > timeout) THEN +-- ^^^^^^^^^ keyword.control.conditional.case.sql +-- ^^^ keyword.operator.logical.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql +-- ^^^^ keyword.other.tsql + UPDATE + SET acquired = @now, timeout = @timeout +WHEN NOT MATCHED AND @insert_if_missing = 1 THEN +-- ^^^^^^^^^^^^^ keyword.control.conditional.case.sql +-- ^^^ keyword.operator.logical.sql +-- ^ variable.other.readwrite.sql punctuation.definition.variable.sql +-- ^^^^^^^^^^^^^^^^^ variable.other.readwrite.sql +-- ^ keyword.operator.comparison.sql +-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql +-- ^^^^ keyword.other.tsql + INSERT (name, acquired, timeout) +-- ^^^^^^ keyword.other.dml.sql +-- ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.sql +-- ^ punctuation.section.group.begin.sql +-- ^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^^ meta.column-name.sql +-- ^ punctuation.separator.sequence.sql +-- ^^^^^^^ meta.column-name.sql +-- ^ punctuation.section.group.end.sql + VALUES (@name, @now, @timeout); +-- ^^^^^^ keyword.other.dml +-- ^ meta.group.sql punctuation.section.group.begin.sql From d7c0650846804107ce9e33d6352bcb53ece6e5d4 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Tue, 14 Nov 2023 08:48:58 +0200 Subject: [PATCH 248/250] [SQL] apparently the maybe-merge-insert context was never really needed --- SQL/TSQL.sublime-syntax | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/SQL/TSQL.sublime-syntax b/SQL/TSQL.sublime-syntax index 694fe3e072..b2ff351bde 100644 --- a/SQL/TSQL.sublime-syntax +++ b/SQL/TSQL.sublime-syntax @@ -483,7 +483,7 @@ contexts: scope: keyword.other.tsql - match: \b(?i:then)\b scope: keyword.other.tsql - set: maybe-merge-insert + pop: 1 - include: values-or-expressions - include: pop-on-top-level-reserved-word @@ -491,12 +491,6 @@ contexts: - include: dml-statements - include: expressions - maybe-merge-insert: - - match: \b(?i:insert)\b(?=\s*\() - scope: keyword.other.dml.sql - set: values-or-expressions - - include: else-pop - ###[ COLUMN EXPRESSIONS ]###################################################### maybe-column-declaration-list: From a2205e9b028c9e78c336c04f6f8da85657589dc6 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 3 Jun 2024 20:48:37 +0300 Subject: [PATCH 249/250] [SQL] add some TSQL WITH XMLNAMESPACES examples/tests --- SQL/tests/syntax/syntax_test_tsql.sql | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/SQL/tests/syntax/syntax_test_tsql.sql b/SQL/tests/syntax/syntax_test_tsql.sql index b7a7743696..cced18ca18 100644 --- a/SQL/tests/syntax/syntax_test_tsql.sql +++ b/SQL/tests/syntax/syntax_test_tsql.sql @@ -2659,3 +2659,39 @@ WHEN NOT MATCHED AND @insert_if_missing = 1 THEN VALUES (@name, @now, @timeout); -- ^^^^^^ keyword.other.dml -- ^ meta.group.sql punctuation.section.group.begin.sql + +WITH XMLNAMESPACES ('uri' as ns1) +SELECT ProductID as 'ns1:ProductID', + Name as 'ns1:Name', + Color as 'ns1:Color' +FROM Production.Product +WHERE ProductID IN (316, 317) +FOR XML RAW ('ns1:Prod'), ELEMENTS; + +WITH XMLNAMESPACES ('uri1' as ns1, +-- ^ keyword.other.dml + 'uri2' as ns2, + DEFAULT 'uri2') +--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.table-columns +-- ^^^^^^^ variable.language +-- ^^^^^^ meta.string string.quoted.single +-- ^ punctuation.section.group.end +-- ^ - meta.group.table-columns +SELECT ProductID, + Name, + Color +FROM Production.Product +WHERE ProductID IN (316, 317) +FOR XML RAW ('ns1:Product'), ROOT('ns2:root'), ELEMENTS; + +SELECT e.BusinessEntityID, e.NationalIDNumber, e.OrganizationNode, e.JobTitle, + X.Y.value('(BankName)[1]', 'VARCHAR(20)') as BankName, +-- ^^^^^^^^^ meta.function-call variable.function +-- ^ punctuation.accessor.dot +-- ^ punctuation.accessor.dot + X.Y.value('(AnnualRevenue)[1]', 'VARCHAR(20)') as AnnualRevenue, + X.Y.value('(BusinessType)[1]', 'VARCHAR(256)') as BusinessType, + X.Y.value('(Specialty)[1]', 'VARCHAR(128)') as Specialty +FROM HumanResources.Employee e +CROSS APPLY e.emp_xml.nodes('EmployeeDetails/StoreDetail/Store') as X(Y) + From 1c49ea3fc7f0280fc5fa6b888902d1ac32b408cd Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 14 Jul 2024 06:21:08 +0300 Subject: [PATCH 250/250] [SQL] add boolean sub-scopes --- SQL/Cassandra.sublime-syntax | 4 ++++ SQL/MySQL.sublime-syntax | 1 + SQL/SQL (basic).sublime-syntax | 8 ++++++-- SQL/tests/syntax/syntax_test_cassandra.cql | 2 +- SQL/tests/syntax/syntax_test_mysql.sql | 16 +++++++++------- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/SQL/Cassandra.sublime-syntax b/SQL/Cassandra.sublime-syntax index ead24f0fd8..01aa50387e 100644 --- a/SQL/Cassandra.sublime-syntax +++ b/SQL/Cassandra.sublime-syntax @@ -215,6 +215,10 @@ contexts: ###[ LITERALS ]################################################################ + constants: + - meta_prepend: true + - include: booleans + literals-and-variables: - meta_prepend: true - include: variables diff --git a/SQL/MySQL.sublime-syntax b/SQL/MySQL.sublime-syntax index 0d25fa53bb..f283776fdb 100644 --- a/SQL/MySQL.sublime-syntax +++ b/SQL/MySQL.sublime-syntax @@ -1520,6 +1520,7 @@ contexts: scope: constant.language.sql bool-constants: + - include: booleans - match: \b(?i:yes|no)\b scope: constant.language.boolean.sql diff --git a/SQL/SQL (basic).sublime-syntax b/SQL/SQL (basic).sublime-syntax index e47d144994..73bff36c7a 100644 --- a/SQL/SQL (basic).sublime-syntax +++ b/SQL/SQL (basic).sublime-syntax @@ -1405,11 +1405,15 @@ contexts: - include: strings constants: - - match: \b(?i:true|false)\b - scope: constant.language.boolean.sql - match: \b(?i:null)\b scope: constant.language.null.sql + booleans: + - match: \b(?i:true)\b + scope: constant.language.boolean.true.sql + - match: \b(?i:false)\b + scope: constant.language.boolean.false.sql + numbers: - match: \b\d+(\.)\d+\b scope: meta.number.float.decimal.sql constant.numeric.value.sql diff --git a/SQL/tests/syntax/syntax_test_cassandra.cql b/SQL/tests/syntax/syntax_test_cassandra.cql index 868b3d09ca..1944904a9b 100644 --- a/SQL/tests/syntax/syntax_test_cassandra.cql +++ b/SQL/tests/syntax/syntax_test_cassandra.cql @@ -399,7 +399,7 @@ WITH HEADER=true; -- ^ keyword.other -- ^^^^^^ string.unquoted -- ^ keyword.operator --- ^^^^ constant.language.boolean +-- ^^^^ constant.language.boolean.true -- ^ punctuation.terminator.statement TRUNCATE table1; diff --git a/SQL/tests/syntax/syntax_test_mysql.sql b/SQL/tests/syntax/syntax_test_mysql.sql index 61c2a2dad1..0fc94dc3b3 100644 --- a/SQL/tests/syntax/syntax_test_mysql.sql +++ b/SQL/tests/syntax/syntax_test_mysql.sql @@ -82,9 +82,9 @@ -- ^ - constant -- ^^^^ constant.language.null.sql -- ^ - constant --- ^^^^ constant.language.boolean.sql +-- ^^^^ constant.language.boolean.true.sql -- ^ - constant --- ^^^^^ constant.language.boolean.sql +-- ^^^^^ constant.language.boolean.false.sql -- ^ - constant all default maxvalue @@ -791,14 +791,14 @@ BEGIN -- ^^ keyword.control.conditional.sql -- ^^^^ variable.other.sql -- ^ keyword.operator.comparison.sql --- ^^^^ constant.language.boolean.sql +-- ^^^^ constant.language.boolean.true.sql -- ^^^^ keyword.control.conditional.sql ELSEIF @var = FALSE THEN -- ^^^^^^ keyword.control.conditional.sql -- ^^^^ variable.other.sql -- ^ keyword.operator.comparison.sql --- ^^^^^ constant.language.boolean.sql +-- ^^^^^ constant.language.boolean.false.sql -- ^^^^ keyword.control.conditional.sql ELSE @@ -821,7 +821,7 @@ BEGIN WHILE TRUE -- ^^^^^ keyword.control.loop.sql --- ^^^^ constant.language.boolean.sql +-- ^^^^ constant.language.boolean.true.sql END WHILE -- ^^^^^^^^^ keyword.control.loop.sql @@ -1275,7 +1275,7 @@ create table IF NOT EXISTS `testing123` ( `col` bool DEFAULT FALSE, -- ^^^^ storage.type.sql -- ^^^^^^^ storage.modifier.sql --- ^^^^^ constant.language.boolean.sql +-- ^^^^^ constant.language.boolean.false.sql -- ^ punctuation.separator.sequence `fkey` INT UNSIGNED NULL REFERENCES test2(id), -- ^^^^^^^^^^ storage.modifier.sql @@ -1315,6 +1315,8 @@ create table fancy_table ( -- ^^^^^^^ storage.type.sql myflag boolean DEFAULT false, -- ^^^^^^^ storage.type.sql +-- ^^^^^^^ storage.modifier.sql +-- ^^^^^ constant.language.boolean.false.sql mycount double precision DEFAULT 1, -- ^^^^^^^^^^^^^^^^^ storage.type.sql fancy_column character varying(42) DEFAULT 'nice'::character varying, @@ -4167,7 +4169,7 @@ INNER JOIN {ON tbl_name LEFT OUTER JOIN other1 other2 ON TRUE} -- ^^^^^^ meta.table-name.sql -- ^^^^^^ meta.alias.table.sql -- ^^ keyword.control.conditional.sql --- ^^^^ constant.language.boolean.sql +-- ^^^^ constant.language.boolean.true.sql -- ^ punctuation.section.braces.end.mysql -- ----------------------------------------------------------------------------