简体   繁体   English

是否有 Xtext 的 java 语法文件?

[英]Is there a java grammar file for Xtext?

I want to create certain files from Java-source files (input: *.java files; output: something).我想从 Java 源文件(输入:*.java 文件;输出:某物)创建某些文件。 Xtext seems like a good tool for this. Xtext 似乎是一个很好的工具。 Of course, you have to define the grammar (in this case: Java) first.当然,您必须先定义语法(在本例中:Java)。 But Xtext should be able to parse Java files and generate some files from them (if I write templates).但是 Xtext 应该能够解析 Java 文件并从中生成一些文件(如果我编写模板)。

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)?是否有用于 Java(定义 Java 语法)的 Xtext-grammar 文件?

I had the same issue.我遇到过同样的问题。 Since Xtext uses Antlr under the hood, I was trying to find an Antlr Java grammar.由于 Xtext 在幕后使用 Antlr,我试图找到 Antlr Java 语法。 I found this file from Terence Parr .我从Terence Parr找到了这个文件。 I got about 1000 lines ...我有大约 1000 行...

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.我在 Wink 的时候带我我无法适应每一个陈述,所以我只是评论了其中的一些。 I attached the grammar if someone else is trying to build a DSL on top of Java.如果其他人试图在 Java 之上构建 DSL,我附上了语法。 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/ http://www.eclipse.org/forums/index.php/t/251746/

由于 Xtext 在幕后使用 Antlr,请尝试以下链接: https : //github.com/antlr/grammars-v4/tree/master/java

Another option now is to use JBase ( https://github.com/LorenzoBettini/jbase ).现在的另一个选择是使用 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. JBase 的创建是为了支持 XText 语言中的 Java 表达式(请参阅https://dl.acm.org/citation.cfm?id=2972217 ),并且可以通过扩展 JBase 而不是 XBase 进行细微的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM