Skip to content

Commit

Permalink
fix(angular): Update grammars from upstream
Browse files Browse the repository at this point in the history
This includes upstream fixes such as

* `@let` syntaxes
* Separate syntaxes for tags to take advantage of `injectionSelector`
* Using scss for inline style language
* Updated embedded languages for block syntax
* Allowing block syntax highlighting to work with `{` on separate lines
  • Loading branch information
atscott committed Jul 22, 2024
1 parent bd2fd44 commit c143125
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 177 deletions.
2 changes: 1 addition & 1 deletion grammars/angular/syntaxes/expression.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"name": "storage.type.as.ts"
}
},
"end": "(?=$|\"|[;,:})\\]])",
"end": "(?=$|\"|'|[;,:})\\]])",
"patterns": [
{
"include": "#type"
Expand Down
4 changes: 2 additions & 2 deletions grammars/angular/syntaxes/inline-styles.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@
"name": "string"
}
},
"contentName": "source.css",
"contentName": "source.css.scss",
"patterns": [
{
"include": "source.css"
"include": "source.css.scss"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion grammars/angular/syntaxes/inline-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"name": "string"
}
},
"contentName": "text.html",
"contentName": "text.html.derivative",
"patterns": [
{
"include": "text.html.derivative"
Expand Down
52 changes: 52 additions & 0 deletions grammars/angular/syntaxes/let-declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"scopeName": "template.let.ng",
"injectionSelector": "L:text.html -comment -expression.ng -meta.tag -source.css -source.js",
"patterns": [
{
"include": "#letDeclaration"
}
],
"repository": {
"letDeclaration": {
"begin": "(@let)\\s+([_$[:alpha:]][_$[:alnum:]]*)\\s*(=)?",
"beginCaptures": {
"1": {
"name": "storage.type.ng"
},
"2": {
"name": "meta.definition.variable.ng"
},
"3": {
"name": "keyword.operator.assignment.ng"
}
},
"patterns": [
{
"include": "#letInitializer"
}
],
"contentName": "meta.definition.variable.ng",
"end": "(?<=;)"
},
"letInitializer": {
"begin": "\\s*",
"beginCaptures": {
"0": {
"name": "keyword.operator.assignment.ng"
}
},
"contentName": "meta.definition.variable.initializer.ng",
"patterns": [
{
"include": "expression.ng"
}
],
"end": ";",
"endCaptures": {
"0": {
"name": "punctuation.terminator.statement.ng"
}
}
}
}
}
4 changes: 2 additions & 2 deletions grammars/angular/syntaxes/template-blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"name": "keyword.control.block.transition.ng"
},
"block": {
"begin": "(@)((?:\\w+\\s*)+)(?=\\(|\\{)",
"begin": "(@)(if|else if|else|defer|placeholder|loading|error|switch|case|default|for|empty)(?:\\s*)",
"beginCaptures": {
"1": {
"patterns": [
Expand All @@ -33,7 +33,7 @@
"include": "#blockBody"
}
],
"contentName": "control.block.ng",
"name": "control.block.ng",
"end": "(?<=\\})"
},
"blockExpression": {
Expand Down
172 changes: 172 additions & 0 deletions grammars/angular/syntaxes/template-tag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"scopeName": "template.tag.ng",
"injectionSelector": "L:text.html#meta.tag -comment",
"patterns": [
{
"include": "#propertyBinding"
},
{
"include": "#eventBinding"
},
{
"include": "#twoWayBinding"
},
{
"include": "#templateBinding"
}
],
"repository": {
"propertyBinding": {
"begin": "(\\[\\s*@?[-_a-zA-Z0-9.$]*%?\\s*])(=)([\"'])",
"beginCaptures": {
"1": {
"name": "entity.other.attribute-name.html entity.other.ng-binding-name.property.html",
"patterns": [
{
"include": "#bindingKey"
}
]
},
"2": {
"name": "punctuation.separator.key-value.html"
},
"3": {
"name": "string.quoted.html punctuation.definition.string.begin.html"
}
},
"end": "\\3",
"endCaptures": {
"0": {
"name": "string.quoted.html punctuation.definition.string.end.html"
}
},
"name": "meta.ng-binding.property.html",
"contentName": "expression.ng",
"patterns": [
{
"include": "expression.ng"
}
]
},
"eventBinding": {
"begin": "(\\(\\s*@?[-_a-zA-Z0-9.$]*\\s*\\))(=)([\"'])",
"beginCaptures": {
"1": {
"name": "entity.other.attribute-name.html entity.other.ng-binding-name.event.html",
"patterns": [
{
"include": "#bindingKey"
}
]
},
"2": {
"name": "punctuation.separator.key-value.html"
},
"3": {
"name": "string.quoted.html punctuation.definition.string.begin.html"
}
},
"end": "\\3",
"endCaptures": {
"0": {
"name": "string.quoted.html punctuation.definition.string.end.html"
}
},
"name": "meta.ng-binding.event.html",
"contentName": "expression.ng",
"patterns": [
{
"include": "expression.ng"
}
]
},
"twoWayBinding": {
"begin": "(\\[\\s*\\(\\s*@?[-_a-zA-Z0-9.$]*\\s*\\)\\s*\\])(=)([\"'])",
"beginCaptures": {
"1": {
"name": "entity.other.attribute-name.html entity.other.ng-binding-name.two-way.html",
"patterns": [
{
"include": "#bindingKey"
}
]
},
"2": {
"name": "punctuation.separator.key-value.html"
},
"3": {
"name": "string.quoted.html punctuation.definition.string.begin.html"
}
},
"end": "\\3",
"endCaptures": {
"0": {
"name": "string.quoted.html punctuation.definition.string.end.html"
}
},
"name": "meta.ng-binding.two-way.html",
"contentName": "expression.ng",
"patterns": [
{
"include": "expression.ng"
}
]
},
"templateBinding": {
"begin": "(\\*[-_a-zA-Z0-9.$]*)(=)([\"'])",
"beginCaptures": {
"1": {
"name": "entity.other.attribute-name.html entity.other.ng-binding-name.template.html",
"patterns": [
{
"include": "#bindingKey"
}
]
},
"2": {
"name": "punctuation.separator.key-value.html"
},
"3": {
"name": "string.quoted.html punctuation.definition.string.begin.html"
}
},
"end": "\\3",
"endCaptures": {
"0": {
"name": "string.quoted.html punctuation.definition.string.end.html"
}
},
"name": "meta.ng-binding.template.html",
"contentName": "expression.ng",
"patterns": [
{
"include": "expression.ng"
}
]
},
"bindingKey": {
"patterns": [
{
"match": "([\\[\\(]{1,2}|\\*)(?:\\s*)(@?[-_a-zA-Z0-9.$]*%?)(?:\\s*)([\\]\\)]{1,2})?",
"captures": {
"1": {
"name": "punctuation.definition.ng-binding-name.begin.html"
},
"2": {
"name": "entity.other.ng-binding-name.$2.html",
"patterns": [
{
"match": "\\.",
"name": "punctuation.accessor.html"
}
]
},
"3": {
"name": "punctuation.definition.ng-binding-name.end.html"
}
}
}
]
}
}
}
Loading

0 comments on commit c143125

Please sign in to comment.