Can I remove ANTLR dependencies from generated code?
Asked Answered
A

2

8

ANTLR generates java source from the grammar file. Generated source has dependency to ANTLR classes.

Can I generate 'clean' java sources using ANTLR, that do not have any antlr - dependecy?

If not, can someone recommend some java parser that excels with performances and can produce clean java code?

Assignment answered 21/11, 2011 at 14:2 Comment(2)
I think this is an excellent question. With the large availability of tools, frameworks and libraries, limited vertical scaling, and the environmental impact of horizontal scaling and energy consumption overall, I believe that producing lean bloat-free code over functionality should be a foremost concern of modern quality software engineering.Receptionist
Hey @JonathanNeufeld I agree with you - may I quote this? Thats why i coded jodd - to minimize the code base...Assignment
C
2

It really isn't practical to remove runtime dependencies on ANTLR. You need to distribute the ANTLR runtime library with your recognizers.

If I remember correctly, JavaCC creates a copy of the necessary runtime classes (the JavaCC "boilerplate") as part of the "generated" code, so that you don't need to include an additional JAR.

What is the root of your concern about the ANTLR dependencies?

Cameral answered 21/11, 2011 at 14:7 Comment(1)
Generated code should be part of the framework/library, therefore I want to keep dependencies minimal, to avoid possible collisions with different versions of existing client antlr jars. But, more important, I want so ;)Assignment
C
1

You can use the Apache Maven Shade Plugin to relocate the ANTLR to a new package that will not conflict with other ANTLR runtime installations in the same process. StringTemplate 4 uses exactly this method to relocate the ANTLR runtime to package st4hidden.org.antlr as part of the ST4-4.0.8-complete.jar distributable jar.

Calculous answered 11/4, 2014 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.