-
Notifications
You must be signed in to change notification settings - Fork 362
WGSL grammar improvements #5461
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
base: main
Are you sure you want to change the base?
Conversation
mehmetoguzderin
left a comment
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.
Thank you for the PR! I had a few questions.
- Could you make sure CI is green? You can replicate the behavior of CI by opening the repo in devcontainer, which should provide a ready setup to test and develop.
- Does the name change to template start and end impact the operation of scanner?
Thanks a lot in advance.
|
My fault, I had only run I haven't figured out exactly what is causing this, but I think it has something to do with the scanner still outputting those tokens with the leading underscore. I'm considering just leaving the bikeshed stuff alone and adding some postprocessing to the grammar.js, finding and replacing all instances of _template_args_start with template_args_start, and same for end. I've already done this manually and it does work. What do you think? |
|
Since deleting the leading underscore in the bnf is inconvenient, and the effects of it are only useful in the final tree-sitter grammar used in the tree-sitter-wgsl repo, i reverted those changes. I left in the shift_operator and comparison_operator definitions though, since those are just improvements that are consistent with other patterns. As for the tree-sitter-wgsl changes, i want to add a very simple postprocessing step that just removes leading underscores from those nodes we want to make named nodes. I did try including those find and replace operations in with the extract_grammar.py script, but the |
|
I created the script to postprocess grammar.js. running |
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.
Instead of creating a new rule for comparison operator, is it possible to keep them as before but just remove underline? This would reduce the diff of this PR and make it easier to review. It seems that removing preceding underlines from the rules uniformly could enable the use case, though it is important to make sure that scanner works well with the adjustments.
Some improvements to the wgsl grammar that enable better tree-sitter querying.
See related PR in tree-sitter-wgsl: gpuweb/tree-sitter-wgsl#5
Added a postprocessing script (wgsl/tools/process-ts-grammar.py) to expose _template_args_start, _template_args_end, and _block_comment as named nodes (replaces occurrences of those strings with leading underscores removed). Intended to be applied to the grammar.js to put in the tree-sitter-wgsl repo.
Changes in syntax.bnf:
->in function header (better highlighting)Other changes in extract_grammar.py: