Strumenta / antlr-kotlin

Support for Kotlin as a target for ANTLR 4
Apache License 2.0
222 stars 47 forks source link

Allow testing syntax errors #135

Closed lppedd closed 8 months ago

lppedd commented 8 months ago

Trying to support syntax errors testing I ended up using the Visual Basic grammar, which is generated with a segmented serialized ATN. This revealed some issues with segmented ATNs, which are now solved at the template level.

A segmented ATN is now created by using a StringBuilder initialized with the correct size, instead of creating a throwaway list to join each element.

private val SERIALIZED_ATN = buildString(65535 / 3 * 2) {
    append(SERIALIZED_ATN_SEGMENT0)
    append(SERIALIZED_ATN_SEGMENT1)
}
lppedd commented 8 months ago

To be clear, this testing mechanism aims at replicating what https://github.com/antlr/antlr4test-maven-plugin does.

This means you can pretty much just grab grammars and example files from https://github.com/antlr/grammars-v4.

ftomassetti commented 8 months ago

Very nice. I do not see anything wrong, so I am merging