Let’s build a canonical grammar for Rust!
So I’ve been trying to come up with a plan on how could we make progress, again based on @nikomatsakis’ suggestions:
- Making sure we have a stable way of serializing current Rust AST (@harpocrates was using
rustc -Z ast-json-noexpandas a base for comparison). We like it or not, the current grammar is what the compiler accepts today.
- Try to
stealget inspiration from all the previous attempts at this, in no particular order:
- https://github.com/harpocrates/language-rust/blob/master/src/Language/Rust/Parser/Internal.y (most complete so far)
- Write a minimal subset of the grammar
- Build a test harness that verifies the generated AST against Rust’s AST.
- Continue building up the grammar based on the confidence that we’re keeping compatibility with what exists today in rustc.
- We call the grammar’s implementation complete when we can successfully do something similar to a crater run side-by-side the current compiler and obtain comparable output.
- As a stretch goal, make sure we can auto-generate railroad diagrams from this grammar to feed into the reference documentation we provide to our users.
Putting this potential plan in action!
- Let’s start a WG-Grammar!
- This new group will hold regular meetings, following the same successful format of WG-NLL:
- Focus on identifying and prioritizing tasks.
- Ensure we’re keeping momentum - this can easily become a never-ending project, which can be frustrating
- Offer mentorship for those who want to have fun with grammars and parsers
- Everyone is welcome to join!
- The expected initial outcome from this group is having a clear vision on how can we deliver a formal grammar for Rust.
This is a pretty long and exciting project, with a lot of opportunities for cross-pollination between several sub-teams.