-
Notifications
You must be signed in to change notification settings - Fork 371
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
Open
benbaarber
wants to merge
4
commits into
gpuweb:main
Choose a base branch
from
benbaarber:wgsl-grammar-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−40
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3ef3054
wgsl grammar improvements
benbaarber 06ae81b
revert leading underscore deletion for template_args
benbaarber 07b5383
Merge remote-tracking branch 'origin/main' into wgsl-grammar-improvem…
benbaarber e385d5e
grammar.js postprocessing script for tree-sitter-wgsl
benbaarber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <div class='syntax' noexport='true'> | ||
| <dfn for=syntax>comparison_operator</dfn> : | ||
|
|
||
| <span class="choice"></span> <a for=syntax_sym lt=equal_equal>`'=='`</a> | ||
|
|
||
| <span class="choice">|</span> <a for=syntax_sym lt=not_equal>`'!='`</a> | ||
|
|
||
| <span class="choice">|</span> [=syntax_sym/_less_than=] | ||
|
|
||
| <span class="choice">|</span> [=syntax_sym/_less_than_equal=] | ||
|
|
||
| <span class="choice">|</span> [=syntax_sym/_greater_than=] | ||
|
|
||
| <span class="choice">|</span> [=syntax_sym/_greater_than_equal=] | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <div class='syntax' noexport='true'> | ||
| <dfn for=syntax>function_header</dfn> : | ||
|
|
||
| <span class="choice"></span> `'fn'` [=syntax/ident=] <a for=syntax_sym lt=paren_left>`'('`</a> [=syntax/param_list=] ? <a for=syntax_sym lt=paren_right>`')'`</a> ( <a for=syntax_sym lt=arrow>`'->'`</a> [=syntax/attribute=] * [=syntax/template_elaborated_ident=] ) ? | ||
| <span class="choice"></span> `'fn'` [=syntax/ident=] <a for=syntax_sym lt=paren_left>`'('`</a> [=syntax/param_list=] ? <a for=syntax_sym lt=paren_right>`')'`</a> ( <a for=syntax_sym lt=arrow>`'->'`</a> [=syntax/attribute=] * [=syntax/type_specifier=] ) ? | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <div class='syntax' noexport='true'> | ||
| <dfn for=syntax>shift_operator</dfn> : | ||
|
|
||
| <span class="choice"></span> [=syntax_sym/_shift_left=] | ||
|
|
||
| <span class="choice">|</span> [=syntax_sym/_shift_right=] | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Postprocessing grammar.js for tree-sitter-wgsl repository | ||
|
|
||
| Exposes block_comment, template_args_start, and template_args_end as named nodes | ||
| """ | ||
|
|
||
| import argparse | ||
| import sys | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser( | ||
| description="Postprocessing for grammar.js for tree-sitter-wgsl" | ||
| ) | ||
| parser.add_argument("input", help="Input file path") | ||
| parser.add_argument("output", help="Output file path") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| try: | ||
| with open(args.input, "r", encoding="utf-8") as f: | ||
| content = f.read() | ||
| except FileNotFoundError: | ||
| print(f"Error: Input file '{args.input}' not found", file=sys.stderr) | ||
| return 1 | ||
| except Exception as e: | ||
| print(f"Error reading input file: {e}", file=sys.stderr) | ||
| return 1 | ||
|
|
||
| content = content.replace("_block_comment", "block_comment") | ||
| content = content.replace("_template_args_start", "template_args_start") | ||
| content = content.replace("_template_args_end", "template_args_end") | ||
|
|
||
| try: | ||
| with open(args.output, "w", encoding="utf-8") as f: | ||
| f.write(content) | ||
| print(f"Wrote processed file to '{args.output}'") | ||
| except Exception as e: | ||
| print(f"Error writing output file: {e}", file=sys.stderr) | ||
| return 1 | ||
|
|
||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.