Two staleness traps cost real debugging time, and both made grammar edits look
like they had no effect:
- compileJava/compileKotlin read src/main/gen with no task dependency, so an
edit to Jai.bnf could be compiled against the previous generated parser. The
compiled JaiParser.class was three minutes older than its source while the
tests reported green. They now depend on generateParser.
- purgeOldFiles is not enough. Grammar-Kit rewrites only the files whose rule
changed, so JaiDeclaration kept a getArgumentList() its regenerated Impl no
longer had and the build failed inside generated code. generateParser now
deletes src/main/gen first.
Grammar: named return defaults use a private rule rather than 'initializer'.
Giving the default its own PSI element made the enclosing procLiteralExpr end
early, so '-> a: int = 1 { }' silently lost its body.
Corpus parse 90.9% (649/714), ratchet at 645.
61 lines
2.2 KiB
Kotlin
61 lines
2.2 KiB
Kotlin
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
|
|
|
|
plugins {
|
|
id("org.jetbrains.kotlin.jvm")
|
|
id("org.jetbrains.changelog")
|
|
id("org.jetbrains.intellij.platform")
|
|
id("org.jetbrains.intellij.platform.grammarkit")
|
|
}
|
|
|
|
// Grammar-Kit output. Committed so diffs are reviewable, never hand-edited.
|
|
sourceSets {
|
|
main {
|
|
java.srcDirs("src/main/gen")
|
|
}
|
|
}
|
|
|
|
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin.html
|
|
dependencies {
|
|
testImplementation(libs.junit)
|
|
|
|
// IntelliJ Platform Gradle Plugin Dependencies Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html
|
|
intellijPlatform {
|
|
intellijIdea("2025.3.5")
|
|
testFramework(TestFrameworkType.Platform)
|
|
|
|
// Add plugin dependencies for compilation here, for example:
|
|
// bundledPlugin("com.intellij.java")
|
|
}
|
|
}
|
|
|
|
tasks.generateParser {
|
|
sourceFile.set(file("src/main/grammar/Jai.bnf"))
|
|
targetRootOutputDir.set(file("src/main/gen"))
|
|
pathToParser.set("dev/hgh/jai/parser/JaiParser.java")
|
|
pathToPsiRoot.set("dev/hgh/jai/psi")
|
|
purgeOldFiles.set(true)
|
|
|
|
// purgeOldFiles is not enough: Grammar-Kit rewrites only the files whose rule
|
|
// changed, so a PSI interface can keep an accessor its regenerated Impl no longer
|
|
// has (`JaiDeclaration.getArgumentList()` with no override) and the build fails on
|
|
// generated code. Always regenerate the whole tree.
|
|
doFirst {
|
|
delete(file("src/main/gen"))
|
|
}
|
|
}
|
|
|
|
// Without this the compile tasks read src/main/gen with no ordering guarantee, so an
|
|
// edit to Jai.bnf could be compiled against the *previous* generated parser and the
|
|
// tests would quietly assert the old grammar. Editing Jai.bnf must be enough.
|
|
tasks.compileJava { dependsOn(tasks.generateParser) }
|
|
|
|
tasks.compileKotlin { dependsOn(tasks.generateParser) }
|
|
|
|
// Forward -Djai.debug.* to the test JVM for the scratch parser harness.
|
|
tasks.test {
|
|
System.getProperties().forEach { key, value ->
|
|
val name = key.toString()
|
|
if (name.startsWith("jai.debug.")) systemProperty(name, value.toString())
|
|
}
|
|
}
|