antlr-kotlin
antlr-kotlin copied to clipboard
Charset used to compile the grammar is system default, not UTF-8
I was using the following configuration:
val generateKotlinGrammarSource by tasks.registering(AntlrKotlinTask::class) {
antlrClasspath = configurations.detachedConfiguration(
project.dependencies.create("com.strumenta.antlr-kotlin:antlr-kotlin-target:ebf3caf7ff")
)
source = project.objects
.sourceDirectorySet("antlr", "antlr")
.srcDir("src/main/antlr").apply {
include("**/*.g4")
}
outputDirectory = file("$buildDir/generated-src/antlr/main/kotlin")
}
The grammar appeared to compile fine, but then rules using Unicode inside my .g4 file were not passing the tests.
It turned out I had to manually set the encoding:
val generateKotlinGrammarSource by tasks.registering(AntlrKotlinTask::class) {
arguments = arguments + listOf("-encoding", "UTF-8")
// ...
}
It's 2022; I think UTF-8 can be the default by now and we shouldn't be forcing every project to set this themselves.