Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wgsl: discover template lists early (Lookahead disambiguation of less…
…-than vs template argument list (v2)) (gpuweb#3803) * Implement a tree-sitter scanner for template disambiguation Use a custom scanner to disambiguate between template-argument-lists and less-than / greater-than. * Build the treesitter shared library on our own The py-tree-sitter compilation doesn't work on macOS because it doesn't know to use -std=c++17 when compiling C++ code. * Grammar analyzer understands many extra external tokens * Only do slow actions when data is newer. * Grammar.py: Generate syntax_sym references for extra external tokens * Allow syntactic tokens to be named without backticks * Regenerate recursive grammar * type_specifier is fully_qualified_ident This is much simpler than using "expression". But note that in future we may want to have type expressions like unions, as in TypeScript. That door is still open, as the grammar was unambiguous (and recursive-descentable) even with type being "expression" * Add TODOs * Remove extraneous grammar grouping * analyze/Grammar.py: Make _disambiguate_template an empty token In the template-matching scheme, it doesn't appear in source text. Make it empty so that first and follow sets are computed correctly. * Explain the custom tokens Delete redundant syntactic token definitions * Add more TODOs in scan, and more comments * Explain why "var" is special-cased Ben answered * disambiguate token does not have to be optional * Refactor extract-grammar.py Add argument parsing Add a --flow argument to specify which step to run. * Add WGSL parsing unit tests * Fix tree-sitter parsing of bitcast Need to add _disambiguate_template before the template list so they are parsed as templates. * Add more unit tests * analyze/Grammar.py: disambiguate token treated as nonempty * scanner.cc: better comments, and dump "valids" array when dumping * "var" is followed by template list scanner.cc: Remove the "var" exception * Better explanation of synthetic token * Fix comment from merge conflict * Add explicit dependencies on the fixed wgsl include files * Support elements that are hidden spans. * Change _disambiguate_template to a hidden span token It's a Treesitter implementation detail, so it doesn't belong in the spec. * The relational and shift tokens are displayed plainly in the HTML They are remapped to custom tokens by the extract-grammar process. Pretty printing in analyze/Grammar.py has to remove leading underscores so they link correctly to definitions. * Fix formatting of bitcast rule * Start writing template disambiguation * Add TODOs in the custom scanner * Describe the template list discovery algorithm. * Add missing disambiguation for fully-qualified-ident * Custom scanner: correctly mark an ordinary greater-than code point * Better wording of CurrentPosition * scanner.cc: Show more details about expected valid tokens * Add another disambiguation token ident use inin core_lhs_expression makes simple assignments work. * scanner.cc: Add more logging * Lots more logging * Many more unit tests * Make types and type-generating names keywords again Insert disambiguating spans and template_args_start and _end where needed. Fixes: gpuweb#3770 * scanner.cc: Better comment about the sentinel value * extract-grammar.py: GCC wants -shared and -fPIC link flags * extract-grammar:.py: GCC requires link flags after, not before --------- Co-authored-by: Ben Clayton <[email protected]>
- Loading branch information