Open vitorpamplona opened 1 year ago
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 ?
@vitorpamplona I'm having trouble understanding why you can't use a rule index here:
marker.done(CqlRuleTypes.RULE_MAP[ctx.javaClass.simpleName]!!)
But in the parser definition you can:
return when(CqlRuleTypes.RULE_NAMES[elType.ruleIndex]) {
In the second example, won't the rule index be the same for SimpleLiteral
and its two subclasses?
Never mind, you're building IElementTypes from all the class names, not from Parser.ruleNames
.
@vitorpamplona here's my first attempt: https://github.com/antlr/antlr4-intellij-adaptor/pull/28
There's a new constructor in ANTLRParseTreeToPSIConverter
which you could use to provide your own list of IElementTypes for rules:
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. :)