Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar: Start implementing expression grammar and use it for template literals #930

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
- Highlight tagged template literal functions as functions. https://github.com/rescript-lang/rescript-vscode/pull/920
- Complete for `type t` values when encountering a `type t` in relevant scenarios. https://github.com/rescript-lang/rescript-vscode/pull/924
- Highlight escaped sequences as a whole and not only the first character. https://github.com/rescript-lang/rescript-vscode/pull/929
- Start highlighting escaped sequences in template literals. https://github.com/rescript-lang/rescript-vscode/pull/929
- Highlight escaped sequences in template strings. https://github.com/rescript-lang/rescript-vscode/pull/929
- Highlight trailing backslash for multi-line strings. https://github.com/rescript-lang/rescript-vscode/pull/929
- Highlight comments, `int`, `float`, `bool`, and `char` values inside of embeded expressions in template strings. https://github.com/rescript-lang/rescript-vscode/pull/930

## 1.38.0

Expand Down
143 changes: 73 additions & 70 deletions grammars/rescript.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,84 +119,87 @@
}
]
},
"expression": {
"patterns": [
{ "include": "#constant" },
{ "include": "#bracketAccess" },
{ "include": "#string" },
{ "include": "#number" },
{ "include": "#character" }
Comment on lines +124 to +128
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be much more than these 5.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And bracketAccess should be replaced with an array constructor.

]
},
"string-character-escape": {
"name": "constant.character.escape",
"match": "\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u{[0-9A-Fa-f]+}|[0-2][0-7]{0,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)"
},
"string": {
"string-double-quoted": {
"name": "string.quoted.double",
"begin": "\"",
"end": "\"",
"beginCaptures": {
"1": {
"name": "punctuation.definition.string.begin"
}
},
"endCaptures": {
"1": {
"name": "punctuation.definition.string.end"
}
},
"patterns": [
{
"name": "string.quoted.double",
"begin": "\"",
"end": "\"",
"beginCaptures": {
"1": {
"name": "punctuation.definition.string.begin"
}
},
"endCaptures": {
"1": {
"name": "punctuation.definition.string.end"
}
},
"patterns": [
{
"include": "#string-character-escape"
}
]
"include": "#string-character-escape"
}
]
},
"template": {
"name": "string.template",
"begin": "([a-z_][0-9a-zA-Z_]*)?(`)",
"end": "(?<!\\\\)`",
"beginCaptures": {
"1": {
"name": "entity.name.function"
},
{
"name": "string.template",
"begin": "([a-z_][0-9a-zA-Z_]*)?(`)",
"end": "(?<!\\\\)`",
"beginCaptures": {
"1": {
"name": "entity.name.function"
},
"2": {
"name": "punctuation.definition.string.template.begin"
}
},
"endCaptures": {
"1": {
"name": "punctuation.definition.string.template.end"
}
},
"patterns": [
{
"include": "#string-character-escape"
},
{
"name": "meta.template.expression",
"begin": "\\$\\{",
"beginCaptures": {
"0": {
"name": "punctuation.definition.template-expression.begin"
}
},
"end": "\\}",
"endCaptures": {
"0": {
"name": "punctuation.definition.template-expression.end"
}
},
"patterns": [
{
"match": "[a-z_][0-9a-zA-Z_]*"
},
{
"include": "#operator"
},
{
"include": "#punctuations"
},
{
"include": "#string"
}
]
}
]
"2": {
"name": "punctuation.definition.string.template.begin"
}
},
"endCaptures": {
"1": {
"name": "punctuation.definition.string.template.end"
}
},
"patterns": [
{ "include": "#string-character-escape" },
{ "include": "#template-substitution-element" }
]
},
"template-substitution-element": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Structured it more similar to ts grammar

"name": "meta.template.expression",
"begin": "\\$\\{",
"beginCaptures": {
"0": {
"name": "punctuation.definition.template-expression.begin"
}
},
"end": "\\}",
"endCaptures": {
"0": {
"name": "punctuation.definition.template-expression.end"
}
},
"patterns": [
{ "include": "#commentLine" },
{ "include": "#commentBlock" },
{ "include": "#operator" },
{ "include": "#punctuations" },
Comment on lines +194 to +195
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of highlighting operators and punctuations separately, they should be part of expression

{ "include": "#expression" }
]
},
"string": {
"patterns": [
{ "include": "#string-double-quoted" },
{ "include": "#template" }
]
},
"function": {
Expand Down
Loading