Search code examples
javaxtext

Is there a java grammar file for Xtext?


I want to create certain files from Java-source files (input: *.java files; output: something). Xtext seems like a good tool for this. Of course, you have to define the grammar (in this case: Java) first. But Xtext should be able to parse Java files and generate some files from them (if I write templates).

Somehow I can not image, that this has not been done before. I looked it up, but did not find anything. So the question is:

Is there a Xtext-grammar file, for Java (which defines the Java grammar)?


Solution

  • I had the same issue. Since Xtext uses Antlr under the hood, I was trying to find an Antlr Java grammar. I found this file from Terence Parr. I got about 1000 lines ...

    I took this post into consideration and adjusted the grammar line by line. I took me while Wink I wasn't able to adapt every statement, so I just commented some of them out. I attached the grammar if someone else is trying to build a DSL on top of Java. I don't think that the grammar is completely right, it at least contains the issues listed in the original grammar.

    http://www.eclipse.org/forums/index.php/t/251746/