Use annotators instead of duplicating grammar rules
See original GitHub issueIn out RustParser.bnf
file, there’s a pattern repeated thrice, for function
, constant
and type_alias
.
A fake
rule is defined to describe a single PSI element, and then a number of implementations (elementType = bla-bla-bla
) of this rules are provide. The goal of this implementations is to enforce small syntactic differences. For example, top level functions always have body, but functions in interfaces can just end in ;
.
A better way to handle this is to have exactly one non fake rule in .bnf
and write a custom annotator which would say something like “top level functions must have a body, change ;
to {}
?”. See, how this is done in Kotlin: if you write override fun foo()
at the top level, the PSI will containg a FUN
, which would be annotated with two errors (an extra override and a missing body).
So this issue is exactly about removing special casing in the parser and writing an annotator. The best place to start is constant
, then type_alias
. function
might prove to be tricky, because different functions have different grammar for parameters (I hate this). It might be useful to look at the Kotlin’s annotator!
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (16 by maintainers)
Top GitHub Comments
No progress so far, unfortunately. The plan was to finish the simple duplication errors (done), then gain the understanding of all the parameters variety while finishing this issue and after that implement parameter names duplication detection.
So the parameters + functions refactoring is the next in my todo-list, but I can’t make promises on how long it will take. If this work hampers the progress of something else, I can pass the baton back to you. Otherwise, I’ll be glad to try to finish this off.
Okay, I’ll tackle it. Though, that might take time, such kind of gymnastics is new for me 😃