简体   繁体   English

在Xtext中组合语法

[英]Combining grammars in Xtext

I have successfully managed to combine two grammars in xtext using the 'with' keyword, however I am having an issue in the language validation and generation. 我已经成功地使用'with'关键字在xtext中合并了两个语法,但是我在语言验证和生成方面遇到了问题。

When there are two grammars combined, any validation / code generation has to be placed in the original grammar or the one extending it? 当将两种语法组合在一起时,是否必须将验证/代码生成放在原始语法中,还是将其扩展? Say I have grammars A and B, and B sits on top of A. Any validation related to the rules in grammar A must be in A, or they have to be in B? 假设我有语法A和B,而B位于A之上。与语法A中的规则相关的任何验证都必须在A中,还是必须在B中? Thanks :) 谢谢 :)

I'm experiencing the same problem and I found a solution looking at this link . 我遇到同样的问题,并且在查看此链接时找到了解决方案。

The trick is to override the method 诀窍是重写方法

protected List<EPackage> getEPackages() {
    List<EPackage> result = super.getEPackages();
    result.add(OdlDataPackage.eINSTANCE);
    return result;
}

In order add the package of the super grammar to the list of the parent package. 为了将超级语法包添加到父包列表中。

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

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