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 dd04854..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 ]########################################################## @@ -553,7 +554,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 @@ -564,6 +565,10 @@ 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 ng-ternary-expression: - match: ':' @@ -665,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 4cbefac..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 \"" }} @@ -611,7 +693,7 @@ https://angular.dev/guide/templates/expression-syntax#what-operators-are-supported --> - {{ - + * / % === !== == != = < <= >= > && || ! ?? }} + {{ - + * / % === !== == != = < <= >= > && || ! ?? ** }} @@ -630,6 +712,7 @@ + {{ foo ? bar : baz }} @@ -655,6 +738,24 @@ + {{ "model" in cars }} + + + + + {{ type = typeof 32 }} + + + + + + + {{ type = void 32 }} + + + + + {{ person['name'][0] = "Mirabel" }}