Build: regenerate the parser on every build, and always from scratch
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.
This commit is contained in:
@@ -7,6 +7,7 @@ plugins {
|
||||
id("org.jetbrains.intellij.platform.grammarkit")
|
||||
}
|
||||
|
||||
// Grammar-Kit output. Committed so diffs are reviewable, never hand-edited.
|
||||
sourceSets {
|
||||
main {
|
||||
java.srcDirs("src/main/gen")
|
||||
@@ -33,4 +34,27 @@ tasks.generateParser {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user