Skip to content

Conversation

@benbaarber
Copy link

Did some work on the highlight query so far, initially on a version where i modified the grammar.js to expose some things as named nodes. I reverted those for now since the file has a comment that says it is auto generated. I also wanted to ask how exactly this file is autogenerated, and if it could be altered to add/expose some additional nodes?

Existing nodes that would be useful to make named nodes:

  • block_comment
  • less_than
  • less_than_equal
  • greater_than
  • greater_than_equal
  • shift_left
  • shift_right
  • template_args_start
  • template_args_end

New nodes that would be useful

  • line_comment: line_comment: $ => seq('//', /.*/),

Planning to add fold and indent queries as well

@mehmetoguzderin
Copy link
Member

@benbaarber thank you very much for your draft PR. The grammar.js file is generated through this script: https://github.com/gpuweb/gpuweb/blob/main/wgsl/tools/extract-grammar.py

and that grammar uses following bnf as source of truth: https://github.com/gpuweb/gpuweb/blob/main/wgsl/syntax.bnf

You can create an issue or PR if you believe changes would not change the grammar but just how it is grouped etc. (editorial).

Please let me know when this PR is ready to review.

cc @dneto0

@benbaarber
Copy link
Author

This PR is done now, added more queries and updated the grammar.js. Opened a PR in gpuweb repo to push the edits i made to the syntax.bnf & extract_grammar.py to autogenerate the updated grammar.js: gpuweb/gpuweb#5461

@benbaarber benbaarber marked this pull request as ready for review November 27, 2025 18:06
@benbaarber
Copy link
Author

@mehmetoguzderin nvim-treesitter requires that supported parser repos have the src/grammar.json included because they (god knows why) decided to use a feature from a future version of tree-sitter-cli (0.26) that breaks when trying to tree-sitter generate from just grammar.js. Is it okay to push the src/grammar.json file in this repo in this PR so it can be compatible with nvim-treesitter? Let me know

@benbaarber
Copy link
Author

adding it for now for testing purposes. if you dont want this file pushed to this repo let me know and I will just maintain a fork to be used with nvim-treesitter

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