-
Notifications
You must be signed in to change notification settings - Fork 17
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
Refactor import-expression syntax regex matching #30
Conversation
"0": { | ||
"patterns": [ | ||
{ | ||
"name": "import-expression.templ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This outermost begin pattern matches from @
to the first opening parenthesis and provides the keyword.control.go
to the @
and source.go
to the function name/opening parenthesis. The pattern will end capture immediately after all of its children patterns have completed.
"patterns": [ | ||
{ | ||
"include": "#import-expression-start" | ||
"name": "params.import-expression.templ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This first inner pattern matches from the previous opening parenthesis to the closing and provides punctuation.definition.end.bracket.round.go
to the closing. The function parameters inside are also marked with source.go
.
] | ||
}, | ||
{ | ||
"name": "children.import-expression.templ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, this last inner pattern matches from the previous closing parenthesis and opening curly brace to the closing curly brace of the templ
function. It provides the respective punctuation.brace.*
to the curly braces and marks the captured children with the internal #template-node
pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this, looks great. I'll merge and test it out.
Overview
Relates to a-h/templ#524
Previously, I fixed inline import expressions in #29 by breaking out empty (no children) expressions into their own rule and fixing both styles individually. After taking a deep-dive into the TextMate grammar engine that VSCode uses, I put together a much better approach that resolves inline/multi-line params and children/no-children import expressions all as one rule.
Before
After