[naga] Expose lexer/parser in frontend gated by feature flag? #6250
Labels
area: api
Issues related to API surface
area: naga front-end
naga
Shader Translator
type: enhancement
New feature or request
Is your feature request related to a problem? Please describe.
There are some crates out there that, in my opinion, would benefit from being able to directly access the lexer and its tokens, and/or the parser and AST. One such crate that comes to mind is
naga_oil
.I would personally consider the implementation of the extra features in
naga_oil
(like imports and preprocessor definitions) to be fairly hacky as they are parsed using a regex or very basic lexer, which comes with some downsides.Describe the solution you'd like
Exposing the lexer+/parser would allow these crates to use the tokens to their advantage which would be far more flexible and maintainable.
Describe alternatives you've considered
An alternative is to use or make another wgsl (or other language) parser, like
wgsl-parser
. The issue with this is you would be relying on another user to have correctly followed the wgsl spec, correctly implemented the parser and also would be keen on maintining it in the future.There is also then the need to potentially have to take one AST, stringify it, and then run it back through naga's parser. Having the official naga implementation exported would allow people to have flexible wgsl syntax while waiting on those features to possibly be implemented in naga itself, in the future, without needing hacks/forks/other parsers.
On one hand I can understand that perhaps this is not in scope for naga as it could cause people to create custom wgsl shaders that only work using another dep alongside naga, while having others believe that shader should function correctly with naga alone, being unaware that another dep is required. On the other hand, I think this is really unlikely and realistically could already happen with crates like
naga_oil
.The text was updated successfully, but these errors were encountered: