简体   繁体   English

Xtext基数元模型

[英]Xtext cardinality meta model

I am currently working on a project, where I am creating a feature model out of Xtext grammar. 我目前正在从事一个项目,该项目是根据Xtext语法创建要素模型的。 My task is to transform grammar syntax into a CSV file importable into eclipse plug-in pure::variants. 我的任务是将语法语法转换为可导入eclipse插件pure :: variants的CSV文件。

Feature model is basicaly tree of features. 特征模型基本上是特征树。 These features are different types ( mandatory, optional, alternative etc. ). 这些功能是不同的类型(强制性,可选,替代性等)。

For constructing the tree, I am using generated ecore meta model of my xtext grammar syntax. 为了构造树,我使用了xtext语法的生成的ecore元模型。 This file ( .ecore ) is basically a XML file with objects of the grammar. 该文件(.ecore)基本上是带有语法对象的XML文件。 It is consistent, simple and easy to create tree out of. 从中创建树是一致,简单和容易的。

My problem is, that I need to assign types ( mandatory, alternative etc. ) to the nodes of my created tree. 我的问题是,我需要为创建的树的节点分配类型(强制性,替代性等)。 These types of features correspond to a cardinality operators. 这些类型的功能对应于基数运算符。 These operators are written in xtext grammar like this: ´(no operator)´, ´?´, ´*´ and ´+´ ( this can be seen in xtext user manual section 2.1.3 https://www.eclipse.org/Xtext/documentation/1_0_1/xtext.pdf ). 这些运算符写在这样XTEXT语法:'?''(没有操作员)','*'和'+'(这可以在XTEXT使用者看到手册第2.1.3节https://www.eclipse.org /Xtext/documentation/1_0_1/xtext.pdf )。 Problem is, that these cardinalities of xtext grammar don't seem to be anywhere to find. 问题是,这些xtext语法的基数似乎找不到任何地方。 I thought that they would appear in .ecore or .genmodel files, but there are no cardinalities at all. 我以为它们会出现在.ecore或.genmodel文件中,但是根本没有基数。

I imagine that if xtext is able to check and control these cardinalities, it has to have some kind of meta model, where these cardinalities can be seen and are easily gettable ( something like .xml file similiar to .ecore or .genmodel file). 我想如果xtext能够检查和控制这些基数,则它必须具有某种元模型,在这些元模型中可以看到这些基数并且很容易获得(类似于.ecore或.genmodel文件的.xml文件)。

So my question is: Is there some kind of xtext generated file, which contains these cardinalities? 所以我的问题是:是否存在某种包含这些基数的xtext生成文件? If there is not, I would have to somehow get these cardinalities out of grammar itself, but it would be unneccessarily time consuming and complicated, maybe even impossible, because written grammar doesn't fully correspond with ecore metamodel I am getting my feature tree out of and is really complex. 如果没有,我将不得不以某种方式从语法本身中去除这些基数,但是这将不必要地耗时且复杂,甚至可能是不可能的,因为书面语法与ecore元模型不完全对应,因此我正在提取特征树真的很复杂。

Only generated file I was able to find, which contains something "maybe useful" is generated file XXXXGrammarAccess.java ( XXXX stands for name of the grammar ), which is complex generated file, with a lot of library depedencies and I have no idea how to get these cardinalities out of that or if it is even possible. 只有生成的文件XXXXGrammarAccess.java(XXXX代表语法的名称)是我能够找到的,其中包含“可能有用的东西”,它是复杂的生成文件,具有许多库依赖关系,我不知道如何从而消除这些基数甚至是可能的话。 I imagine that there is a possibility, because this file uses a lot of IGrammarAccess methods, such as getRule(), getKeyword() and more, but I am not able to use this file, or print something out of it, because it is a generated file and I am not able to run it on itself. 我想这是有可能的,因为该文件使用了很多IGrammarAccess方法,例如getRule(),getKeyword()等,但是我无法使用该文件或从中打印出一些东西,因为它是生成的文件,但我无法自行运行。

If there is not some kind of meta model I am looking for, is there any possibility to somehow get these cardinalities different way during generating? 如果没有我要寻找的元模型,是否有可能在生成过程中以某种方式获得这些基数?

Thank you very much for your answers. 非常感谢您的回答。

first of all the cardinalities in the metamodel and the grammar do not have to match 100%. 首先,元模型和语法中的基数不必匹配100%。 the cardinality validation in the parser is different than the one in ecore. 解析器中的基数验证与ecore中的基数验证不同。

the lower cardinality of 1 (for required) is not there to prevent really ugly error messages. 较低的1基数(必需)不存在,以防止出现真正难看的错误消息。 the :1 or :-1 (=*) is reflected in the ecore though. :1或:-1(= *)反映在ecore中。

this was a deliberate decision when Xtext was created 10 years ago. 在10年前创建Xtext时,这是一个故意的决定。

the grammar access just gives you access to the grammar at runtime. 语法访问仅使您可以在运行时访问语法。

can you elaborate why you actually care? 您能详细说明您为什么真正在乎吗?

The Xtext grammar is itself a model, an instance of http://www.eclipse.org/2008/Xtext . Xtext语法本身就是一个模型,是http://www.eclipse.org/2008/Xtext的实例。 (It used to be possible to demonstrate this by opening a *.xtext file with the Sample Reflective Ecore Editor, but unfortunately the use of classpath: URIs has broken it again.) Nonetheless you can open a *.xtext file programmatically as an EMF Resource and see everything that is in the grammar. (过去可以通过使用示例反射式Ecore编辑器打开* .xtext文件来演示这一点,但是不幸的是,使用classpath:URI再次破坏了它。)尽管如此,您仍可以以编程方式将* .xtext文件作为EMF打开。掌握资源并查看语法中的所有内容。 See https://git.eclipse.org/c/ocl/org.eclipse.ocl.git/tree/examples/org.eclipse.ocl.examples.xtext2lpg/src/org/eclipse/ocl/examples/xtext2lpg/xtext2xbnf.qvto for the first stage of a transformation chain that starts by reading an Xtext grammar and ends up with an LPG grammar. 参见https://git.eclipse.org/c/ocl/org.eclipse.ocl.git/tree/examples/org.eclipse.ocl.examples.xtext2lpg/src/org/eclipse/ocl/examples/xtext2lpg/xtext2xbnf .qvto用于转换链的第一阶段,该阶段从读取Xtext语法开始,最后以LPG语法结束。

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

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