-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ANTLRParseTreeToPSIConverter aware of Rule subtypes #26
Comments
hi. So does this improve the ability to auto complete or something? I'm missing the goal in terms of the user experience. thanks. |
In our case, it was the only way to add semantical attributes (return type) in the PSI three, which drove the auto completion work. |
So it sounds like you're providing some thing internally that other programmers could use rather than something to user would experience? Is this something for my generic antlr jetbrains plug-in library or is this for the actual antlr plugin? Thanks... My memory is extremely fuzzy on this project |
It would be an alternative to this class: https://github.com/antlr/antlr4-intellij-adaptor/blob/master/src/main/java/org/antlr/intellij/adaptor/parser/ANTLRParseTreeToPSIConverter.java So, anyone else with an Antlr grammar that uses these rule subtypes can easily use this adaptor to build their plugins. |
Oh sorry. I misread the repository. Yes this is the appropriate spot. Unfortunately I can't remember enough about what's going on to make a decision here... @bjansen ? |
marker.done(CqlRuleTypes.RULE_MAP[ctx.javaClass.simpleName]!!)
return when(CqlRuleTypes.RULE_NAMES[elType.ruleIndex]) {
Never mind, you're building IElementTypes from all the class names, not from |
@vitorpamplona here's my first attempt: #28 There's a new constructor in new ANTLRParseTreeToPSIConverter(lang, myParser, builder, new ClassNameIElementTypeMapper(CqlRuleTypes.RULES)); |
I'd like to propose a second "rule" processor (
ANTLRParseTreeToPSIConverter
) by the Rule Context's class name instead of the rule index in Antlr's generated Parser class. The goal is to provide enough information to the Parser Definition'screateElement
, thoughASTNodes.elementType
, to replicate the Context classes in the PSI TreeAntlr has a generator option that includes subclassing rules by name. The grammar below generates a single Rule integer for
simpleLiteral
but three Context classes in the parser:SimpleLiteralContext
,SimpleStringLiteralContext
,SimpleNumberLiteralContext
.SimpleStringLiteralContext
,SimpleNumberLiteralContext
extendSimpleLiteralContext
The change would need a RuleMap class as below:
And then a new
ANTLRParseTreeToPSIConverter
listener that would be very similar to the current one but withmaker.done
by Class name and not rule index.The Parser Definition then create PSINodes for each subclass
We implemented this variation in this project: https://github.com/Path-Check/intellij-cql
As you can see, we had to go around some of the interface design (Map of Rules instead of List) for the adaptor's converters to make it work.
Apologies for blending Java and Kotlin in the same text. :)
The text was updated successfully, but these errors were encountered: