Question

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)?

Was it helpful?

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/

OTHER TIPS

Since Xtext uses Antlr under the hood try the follwing link: https://github.com/antlr/grammars-v4/tree/master/java.

Another option now is to use JBase (https://github.com/LorenzoBettini/jbase). JBase was created to support Java expressions in XText languages (see https://dl.acm.org/citation.cfm?id=2972217) and can be incorporated with minor changes by extending JBase instead of XBase.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top