Skip to content


ANTLR’s inherited grammar stuff needs work

I’m a little bit frustrated with ANTLR’s “composite” or “delegate” grammar support now.

The pitch is that you can define a bunch of rules in one file, and then selectively override them in another file. In practice, some painful warts get in the way.

For one thing, my “base” parser cannot have a @header{} block at the same time the children do, which is used for–among other things–setting imports and packages in Java. So I either have to manually edit everything on every build, eliminating the benefits of code-generation… Or I’ll have one AbstractBaseParser.java class always sitting around which is chock-full of errors since it’s missing imports and a package declaration. (And to fix that, I’d still have to do manual changes after each build.) It’s a complicated program, yes, but I’d have hoped these kinds of things would work by now given that bugs about them have been filed about a year ago.

In a sense this is emblematic of my experiences with ANTLR: Incredibly powerfuland convenient, as long as you don’t try to do anything too fancy. Once you do, things begin to explode or get hung up on tiny details that make you roll-back your work, while strange error messages appear which lead to absolutely nothing when searching Google.

I’d post some examples, but I’m still trying to find the right mix of plugins to display the code snippets the way I want.

Posted in Programming.

Tagged with .