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

Refactor import-expression syntax regex matching #30

Merged
merged 4 commits into from
Feb 18, 2024

Conversation

alehechka
Copy link
Contributor

@alehechka alehechka commented Feb 14, 2024

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

Screenshot 2024-02-14 at 10 50 57 AM

After

Screenshot 2024-02-14 at 10 50 05 AM

"0": {
"patterns": [
{
"name": "import-expression.templ",
Copy link
Contributor Author

@alehechka alehechka Feb 16, 2024

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",
Copy link
Contributor Author

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",
Copy link
Contributor Author

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.

Copy link
Collaborator

@a-h a-h left a 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.

@a-h a-h merged commit df5ce57 into templ-go:main Feb 18, 2024
@alehechka alehechka deleted the issue_524 branch February 18, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants