在Xtext中组合语法(Combining grammars in Xtext)

编程入门 行业动态 更新时间:2024-10-25 11:23:06
在Xtext中组合语法(Combining grammars in Xtext)

我已经成功地使用'with'关键字在xtext中组合了两个语法,但是我在语言验证和生成中遇到了问题。

当有两个语法组合时,任何验证/代码生成都必须放在原始语法中或扩展它的那个语法中? 假设我有语法A和B,并且B位于A之上。任何与语法A中的规则相关的验证必须在A中,或者它们必须在B中? 谢谢 :)

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.

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

最满意答案

我遇到了同样的问题,我找到了一个查看此链接的解决方案。

诀窍是覆盖该方法

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

为了将超语法的包添加到父包的列表中。

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.

更多推荐

本文发布于:2023-08-06 23:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457646.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   语法   Xtext   Combining   grammars

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!