wgsl-tooling-wg / wesl-spec

A set of well-specified language extensions and tools for WGSL
BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

Provide tree-sitter parser for all our extensions #16

Open stefnotch opened 2 weeks ago

stefnotch commented 2 weeks ago

turns out, the gpuweb tree-sitter parser is generated automatically from the spec source. (that's why it is not very practical, e.g. it parses all the Expression non-terminals, but the codegen could be improved) but it means that if we just extend the spec, we get the tree-sitter parser for free 🙂 from k2d222

k2d222 commented 2 weeks ago

I'm experimenting here: https://github.com/k2d222/tree-sitter-wesl

The tree-sitter parser generated from the spec is not very practical from a usability stand-point, e.g. expressions with different precedences are parsed as nested nonterminals (as explained here in the tree-sitter doc. And many grammar rules could be hidden.

So two approaches: patching the spec extractor program to use precedence directives and patch a few grammar rules, or edit manually the generated grammar.

I'm leaning towards option 2.

k2d222 commented 2 weeks ago

Also, the scanner (recognizes template lists and block comments) has a few bugs