When using Grammer-Kit to generate parser code for a custom language plugin developed in Kotlin, it reports an error saying that it can't find a method in the class corresponding to psiImplUtilClass.


Psi related settings in bnf:

Definition of the PsiImplUtil class:

Hint in the generated code about the method not being found:

But try it directly in Java code and you can see the methods:

What could this be due to? Which Java and Kotlin interop didn't get it right?


Are you using Gradle Plugin org.jetbrains.grammarkit? This feature is not supported by the Gradle plugin. See the following note from the documentation:

The plugin does not support two-pass generation. Therefore, it does not support method mixins.


No, I'm using IntelliJ IDEA plugin Grammar-Kit.


If you are not using Gradle, then I don't know the problem. Have you tried writing the Util class in Java, just to test if it is working?


Yes, but there was a strange problem. The generation was successful, but when I try Cradle's Run IDE task, it said can't recognize methods in Util class.

But I may have found a way to get it right! I made some BNF adjustments, Because there are other functions that can be implemented without tool methods... and it turns out to be generating, But right now I'm not sure which operation made it generate the correct Token... I'm trying to replicate that operation...


Johannes Spangenberg  I know what's going on.
I have the tokens array defined in my bnf file, and before performing the lexical generation, I comment out an element of the tokens array that does not affect the generation, and this time is when it is true that I can't generate the blending method. Then release that comment and re-execute the generation operation, and the blend-in method is successfully generated.
It's strange, I don't know why.


Sounds strange. Are you sure that it does not just require you to run the generation twice, or something like this? I think I can't give you much more advice on this topic. If you think it is a bug, you could create an issue at https://github.com/JetBrains/Grammar-Kit, assuming there is not already an issue for that.


I've experimented with it and doing multiple generation doesn't make Grammer-Kit recognize those methods. I'll go ahead and add the Issue afterward, thank you!


Please sign in to leave a comment.