Last week I've made another overhaul of rust-analyzer syntax tree structure. Now the syntax tree itself (but not the parser, it is still hand written) is generated from ungrammar. Ungrammar (made up term) specifies the structure of concrete syntax tree, without specifying the parser/language. It is like ASDL with C.
Because un-grammar doesn't deal with language ambiguities the spec is simple and readable -- 618 lines, including blanks and comments. I think it's the first rust grammar I've seen which fits into my head. Definitely much better than RustParser.bnf
It is production ready in several senses:
- it is a source of truth for rust-analyzer's syntax tree, so it is quite literary used in production (caveat -- rust-analyzer doesn't stresses terminals yet, so there definitely should be a missing comma here and there)
- The names of various productions were carefully
stolen from syn & the referencechosen
- I have a feeling that this spec will last for a while -- it's fourth of fifth iteration, and this time it feels like there's nothing to remove. For this reason, it will live in a repository, separate from rust-analyzer, and each change would reuquire a new version of a cargo package
Besides the spec itself, the link repository also contains a code to parse it into a data structure (this is how rust-analyzer's sytnax tree is generated).