-
Notifications
You must be signed in to change notification settings - Fork 17
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
Code generation isn't equal with Grammar-Kit #3
Comments
Ha, I ran into this recently as well. I know what the problem is but I dont know how to fix it. It is because In my own repo I just ended up using mixins instead of a util class because it does not have this problem. |
Also encountered this issue - this plugin doesn't work with the implement interface via method injection method in |
That's really a pity! I feel really bad when I see this |
this looks like a fundumental shortcoming... basically you can't use this plugin if you want to use custom methods. And it seems like it can't be fixed? Or is there some hope? |
There is alway hope :) |
Wat? @hurricup you mean you're working on this and there's some progress? |
Not exactly. I understand where is the problem. But not working on it now. |
@hurricup My guess is that to properly fix it parser generator should parse mixin sources instead of relying on compiled classes... But that's probably substantial rework |
I guess my best workaround for this is not to use "methods" and instead create an interface with those methods and use "implements". Seems cleaner too |
What about writing the full-qualified method signature in the .bnf file? I think in this way GK can do a very very simple parsing and generate the methods. |
@hurricup Any progress? It would be great to have a solution to this issue, even if that is supporting only a subset of the GrammarKit syntax. |
Just encountered the same issue. I worked around it by invoking parser GenerateParser twice.
Edit: You'd also need a second compilation step. |
Did you get this to work inside a gradle build? I've worked around for now by creating a bash script to do the 2 compile dance:
|
Yeah i am using gradle for it. While not a perfect solution, it works. A significant disadvantage is, that i'm required to maintain two projects, because referencing utility classes will not work in the same project that is used for generation. |
So, there should be no additional chicken/egg issues with running gradle in the JVM compared to using the grammarkit plugin. How does grammarkit solve this problem? It's also a .jar also running in the JVM right? There must be some solution (I suspect just specifying -classpath or something?). |
Sorry to bring it up exactly a year later, but this is still unresolved and I want to share how I got it to work more or less okay for me. The key point is that it works if you write your plugin in Kotlin, so you have an additional compilation step without dealing with multiprojects. It is accomplished by a really small snipped in the following gradle build script (click on it) : build.gradle.kts// You may also want to add `outputs.upToDateWhen { false }`
// to the common parser configs if your changes to the BNF
// break stuff and you have to manually remove the 'gen' folder to fix those.
fun generateParserTask(suffix: String = "", config: GenerateParser.() -> Unit = {}) =
task<GenerateParser>("generateParser${suffix.capitalize()}") {
source = "src/main/grammars/grammar.bnf"
// ... other common parser configs
purgeOldFiles = true
config()
}
val generateParserInitial = generateParserTask("initial")
val compileKotlin = tasks.named("compileKotlin") {
dependsOn(generateLexer, generateParserInitial)
}
val generateParser = generateParserTask {
dependsOn(compileKotlin)
classpath(compileKotlin.get().outputs)
}
tasks.named("compileJava") {
dependsOn(generateParser)
} The compilation process then should go this way:
|
What if grammar-kit-plugin generates Lexer after compile task? The whole idea is:
Custom plugin project will have following dependency tree: And gradle will compile module 1 (as dependency) and then compile module 2 in regular build process. I think the idea is better than nothing. |
This worked for the Gradle Kotlin DSL, thank you. It really shouldn't be this hard, #23 is practically the same issue (also see JetBrains/Grammar-Kit#35). It's kind of frustating that we either have to do two passes or manually generate the parser. It's been almost three years. I don't know how hard it would be to fix but the solution using "hidden" annotation processors (#23 (comment)) seems like a good idea if it cleans up our builds. |
The Gradle plugin for Grammar-Kit does not support the usage of Util classes. JetBrains/gradle-grammar-kit-plugin#23 and JetBrains/gradle-grammar-kit-plugin#3.
The Gradle plugin for Grammar-Kit does not support the usage of Util classes. See the following issues from the Gradle plugin. JetBrains/gradle-grammar-kit-plugin#23 JetBrains/gradle-grammar-kit-plugin#3
Is this issue still the thing? |
@hsz Yes, this issue is why we cannot use this for our plugin and we have to resort to committing all generated files to git. |
Commented out parser-build because off JetBrains/gradle-grammar-kit-plugin#3
Yes, this problem is still present and prevents the development of plugins:( |
@hsz is this issue still relevant? If it is, is it documented somewhere? Edit: there is a note on the Grammar-Kit repository
|
I just ran into this issue myself :( Is there some useful workaround when using Java? |
Yes, using |
I was more looking for a good way to make gradle call java compilation twice. I haven't used gradle before this so having this as the way to learn the build tool hasn't been ideal... I am intrigued to know how @BjoernAkAManf solved this. I tried to fix it myself, creating a second project inside of the same build file. This seems to do what the Rust plugin does: https://github.com/intellij-rust/intellij-rust/blob/master/build.gradle.kts but it also does a lot of other things and trying to copy it quickly makes things go south. So ideally some cut-and-paste:able solution would be ideal. |
Reading more abut the Rust solution, it seems like it stores some fake PSI code first. I'd like to avoid that solution. The more I read about this, the less amenable to a fix it seems to be. The rust plugin team did file this pull request: JetBrains/Grammar-Kit#316 |
JetBrains/Grammar-Kit#316 is absolutely not a solution for this issue. Furthermore, I'm not sure this is an issue at all. You can just use |
This may sound like a simple question, but why can't the As I understand it, the issue arises here. After going through the source code, I've realised that the problem lies in the Within Technically, we should be able to do: project.registerService(JavaHelper.class, new JavaHelper.PsiHelper(project)); in exchange for: project.registerService(JavaHelper.class, new JavaHelper.AsmHelper()); after modifying the visibility of the Or simply, will |
I am trying to run the generateParser task. But the generated code isn't the same than if I run the action within context menu.
Versions
jflexRelease = '1.7.0'
grammarKitRelease = '1.5.2'
idea = '2017.2'
Gradle
PluginParser.bnf File
Generated Block interface
Generated Block interface with Grammar-Kit
UtilClass
The text was updated successfully, but these errors were encountered: