I\'m trying to analyze Java source files with Clojure but I couldn\'t find a way to do that.
First, I thought using Eclipse AST plugin(by copying necessary JAR\'s to
It depends a bit on what you want to do - what are you hoping to get from the analysis?
If you want to actually compile Java or at least build an AST, then you probably need to go the ANTLR or Eclipse AST route. Java isn't that bad of a language to parse, but you still probably don't want to be reinventing too many wheels..... so you might as well build on the Eclipse and OpenJDK work.
If however you are just interesting in parsing the basic syntax and analysing certain features, it might be easier to use a simpler general purpose parser combinator library. Options to explore:
... and it doesn't compile with latest ANTLR ...
I could not reproduce that.
Using ANTLR v3.2, I got some warnings, but no errors. Using both ANTLR v3.3 and v3.4 (latest version), I have no problems generating a parser.
You didn't mention how you're (trying) to generate a lexer/parser, but here's how it works for me:
java -cp antlr-3.4.jar org.antlr.Tool Java.g
Here's my output when running the commands:
ls wget http://www.antlr.org/download/antlr-3.4-complete.jar wget http://openjdk.java.net/projects/compiler-grammar/antlrworks/Java.g java -cp antlr-3.4-complete.jar org.antlr.Tool Java.g ls
As you can see, the .java
files of the lexer and parser are properly created.
Instead of generating a parser yourself (from a grammar), you could use an existing parser like this one (Java 1.5 only AFAIK) and call it from your Clojure code.