From 11b2d5022c2152ce6933d91e8c6012790ea7bd56 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 4 Jun 2025 12:35:26 +0200 Subject: [PATCH 1/4] Add support for typeof and void operators --- NgxHTML.sublime-syntax | 2 ++ tests/syntax_test_scopes.component.html | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/NgxHTML.sublime-syntax b/NgxHTML.sublime-syntax index dd04854..fd4ca21 100644 --- a/NgxHTML.sublime-syntax +++ b/NgxHTML.sublime-syntax @@ -564,6 +564,8 @@ contexts: - match: \?(?!\.) scope: keyword.operator.ternary.ngx push: ng-ternary-expression + - match: (?:typeof|void){{ident_break}} + scope: keyword.operator.type.ngx ng-ternary-expression: - match: ':' diff --git a/tests/syntax_test_scopes.component.html b/tests/syntax_test_scopes.component.html index 4cbefac..741ca40 100644 --- a/tests/syntax_test_scopes.component.html +++ b/tests/syntax_test_scopes.component.html @@ -655,6 +655,19 @@ + {{ type = typeof 32 }} + + + + + + + {{ type = void 32 }} + + + + + {{ person['name'][0] = "Mirabel" }} From 31e6665c6c68b800bb084a89f8d3791d041ae639 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 4 Jun 2025 12:38:59 +0200 Subject: [PATCH 2/4] Add support for exponentiation operator Add dedicated pattern primarily to support ligatures. --- NgxHTML.sublime-syntax | 2 +- tests/syntax_test_scopes.component.html | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/NgxHTML.sublime-syntax b/NgxHTML.sublime-syntax index fd4ca21..a0dda32 100644 --- a/NgxHTML.sublime-syntax +++ b/NgxHTML.sublime-syntax @@ -553,7 +553,7 @@ contexts: scope: punctuation.terminator.expression.ngx - match: '[!=]==?|[<>]=?' scope: keyword.operator.comparison.ngx - - match: '[-+*/%]' + - match: '\*\*|[-+*/%]' scope: keyword.operator.arithmetic.ngx - match: '&&|\|\||!' scope: keyword.operator.logical.ngx diff --git a/tests/syntax_test_scopes.component.html b/tests/syntax_test_scopes.component.html index 741ca40..1e92f3b 100644 --- a/tests/syntax_test_scopes.component.html +++ b/tests/syntax_test_scopes.component.html @@ -611,7 +611,7 @@ https://angular.dev/guide/templates/expression-syntax#what-operators-are-supported --> - {{ - + * / % === !== == != = < <= >= > && || ! ?? }} + {{ - + * / % === !== == != = < <= >= > && || ! ?? ** }} @@ -630,6 +630,7 @@ + {{ foo ? bar : baz }} From 7909b0c59aa107a88ca5443f888e51d56e40c6fe Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 4 Jun 2025 12:41:04 +0200 Subject: [PATCH 3/4] Add support for in operator --- NgxHTML.sublime-syntax | 2 ++ tests/syntax_test_scopes.component.html | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/NgxHTML.sublime-syntax b/NgxHTML.sublime-syntax index a0dda32..365f6c2 100644 --- a/NgxHTML.sublime-syntax +++ b/NgxHTML.sublime-syntax @@ -564,6 +564,8 @@ contexts: - match: \?(?!\.) scope: keyword.operator.ternary.ngx push: ng-ternary-expression + - match: in{{ident_break}} + scope: keyword.operator.comparison.ngx - match: (?:typeof|void){{ident_break}} scope: keyword.operator.type.ngx diff --git a/tests/syntax_test_scopes.component.html b/tests/syntax_test_scopes.component.html index 1e92f3b..3e8bfd2 100644 --- a/tests/syntax_test_scopes.component.html +++ b/tests/syntax_test_scopes.component.html @@ -656,6 +656,11 @@ + {{ "model" in cars }} + + + + {{ type = typeof 32 }} From 370bb1cdec0662394c09019bac417bcabdf296fa Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 4 Jun 2025 12:48:58 +0200 Subject: [PATCH 4/4] Add support for template strings This commit adds basic support for untagged and tagged template strings. Regular expressions are highlighted using ST's RegExp (Basic) syntax as a dedicated JavaScript specific regexp syntax is far inferior, especially with regards to supporting interpolation. --- ... (for Ngx Template Strings).sublime-syntax | 14 +++ NgxHTML.sublime-syntax | 87 +++++++++++++++++++ tests/syntax_test_scopes.component.html | 82 +++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 Embeddings/RegExp (for Ngx Template Strings).sublime-syntax diff --git a/Embeddings/RegExp (for Ngx Template Strings).sublime-syntax b/Embeddings/RegExp (for Ngx Template Strings).sublime-syntax new file mode 100644 index 0000000..6b07909 --- /dev/null +++ b/Embeddings/RegExp (for Ngx Template Strings).sublime-syntax @@ -0,0 +1,14 @@ +%YAML 1.2 +--- +scope: source.regexp.embedded.ngx.template-string +version: 2 +hidden: true + +extends: Packages/Regular Expressions/RegExp (Basic).sublime-syntax + +contexts: + + prototype: + - match: (?=/?`) + pop: 1 + - include: NgxHTML.sublime-syntax#ng-template-text-interpolations diff --git a/NgxHTML.sublime-syntax b/NgxHTML.sublime-syntax index 365f6c2..ae5afd9 100644 --- a/NgxHTML.sublime-syntax +++ b/NgxHTML.sublime-syntax @@ -426,6 +426,7 @@ contexts: - include: ng-constants - include: ng-numbers - include: ng-strings + - include: ng-templates - include: ng-variables ###[ ANGULAR ARRAYS ]########################################################## @@ -669,6 +670,92 @@ contexts: - match: \\. scope: constant.character.escape.ngx + ng-templates: + # tagged template strings + - match: ({{ident_name}})(\`) + captures: + 1: variable.function.tagged-template.ngx + 2: meta.string.template.ngx string.quoted.other.ngx punctuation.definition.string.begin.ngx + push: ng-tagged-template-plain-body + # untagged plain or regexp template strings + - match: \` + scope: string.quoted.other.ngx punctuation.definition.string.begin.ngx + branch_point: template-string + branch: + - ng-template-pattern-begin + - ng-template-plain-body + + ng-tagged-template-plain-body: + - meta_content_scope: meta.string.template.ngx string.quoted.other.ngx + - include: ng-tagged-template-plain-end + - include: ng-template-string-interpolations + - include: ng-string-content + + ng-tagged-template-plain-end: + - match: \` + scope: meta.string.template.ngx string.quoted.other.ngx punctuation.definition.string.end.ngx + pop: 1 + - match: \n + scope: invalid.illegal.newline.ngx + pop: 1 + + ng-template-pattern-begin: + - meta_scope: meta.string.template.regexp.ngx + - match: / + scope: punctuation.definition.pattern.begin.ngx + push: ng-template-pattern-body + - match: '' + fail: template-string + + ng-template-pattern-body: + - match: (/)(\`) + captures: + 1: punctuation.definition.pattern.end.ngx + 2: string.quoted.other.ngx punctuation.definition.string.end.ngx + pop: 2 + - match: (?=\`) + fail: template-string + - match: \n + scope: invalid.illegal.newline.ngx + pop: 2 + - include: scope:source.regexp.embedded.ngx.template-string + apply_prototype: true + + ng-template-plain-body: + - meta_scope: meta.string.template.ngx + - meta_content_scope: string.quoted.other.ngx + - match: \` + scope: string.quoted.other.ngx punctuation.definition.string.end.ngx + pop: 1 + - match: \n + scope: invalid.illegal.newline.ngx + pop: 1 + - include: ng-template-string-interpolations + - include: ng-string-content + + ng-template-string-interpolations: + - match: \$\{ + scope: punctuation.section.interpolation.begin.ngx + push: ng-template-string-interpolation-body + + ng-template-string-interpolation-body: + - clear_scopes: 1 + - meta_scope: meta.interpolation.ngx + - include: ng-template-text-interpolation-body + + ng-template-text-interpolations: + # used by embedded syntaxes (e.g.: CSS or HTML) + - match: \$\{ + scope: punctuation.section.interpolation.begin.ngx + push: ng-template-text-interpolation-body + + ng-template-text-interpolation-body: + - meta_scope: meta.interpolation.ngx + - match: \} + scope: punctuation.section.interpolation.end.ngx + pop: 1 + - include: ng-expressions + ###[ ANGULAR VARIABLES ]####################################################### ng-variables: diff --git a/tests/syntax_test_scopes.component.html b/tests/syntax_test_scopes.component.html index 3e8bfd2..c187c65 100644 --- a/tests/syntax_test_scopes.component.html +++ b/tests/syntax_test_scopes.component.html @@ -513,6 +513,88 @@ + + {{ `Hello ${name + `template ${var}`}` }} + + + + + + + + + + + + + + + + + + + + + + + + + {{ tag`Text \`${var}\`` }} + + + + + + + + + + + + + + + {{ `/^[a-z]${var + `nest\`ed ${ `/\w+/` + pattern}`}\d+/` }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{ "\xAF \u2AFF \n \"" }}