1

我正在编写一个简单的小 DSL 来指定消息的约束,并且一段时间以来一直在尝试将 XBase 表达式嵌入到语言中,但没有成功。

语法看起来像这样:

grammar org.xtext.businessrules.BusinessRules with org.eclipse.xtext.xbase.Xbase
//import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes
generate businessRules "http://www.xtext.org/businessrules/BusinessRules"

Start:
    rules+=Constraint*;

Constraint:
    {Constraint}
    'FOR' 'PAYLOAD' payload=PAYLOAD 'ELEMENT' element=ID 'CONSTRAINED BY' constraint=XExpression;



PAYLOAD:
    "SimulationSessionEvents"
    |"stacons"
    |"any"
;



Range:
    'above' min=INT ('below' max=INT)?
    |'below' max=INT ('above' min=INT)?
;

尝试解析文件时,例如:

FOR PAYLOAD SimulationSessionEvents ELEMENT 矩阵受 ...

我无法让它适用于 ... = 任何类型的算术表达式,尽管它适用于 ...= 循环或 if 表达式,甚至只是一个数字。一旦我执行“-5”或“4-5”之类的操作,它就会显示Couldn't resolve reference to JvmIdentifiableElement '-',即使 Xbase.xtext 语法看起来允许这些表达式。

我不认为我错过了任何罐子,因为当我运行 mwe 工作流程时它不会抱怨,但只有在尝试解析输入文件时才会抱怨。

任何帮助将非常感激。

编辑:项目的构建路径如下:

C:\Program Files\eclipse\plugins\org.eclipse.xtext_2.2.1.v201112130541.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.ecore.xmi_2.7.0.v20120127-1122.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.ecore_2.7.0.v20120127-1122.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.common_2.7.0.v20120127-1122.jar
C:\Program Files\eclipse\plugins\org.eclipse.xtext.util_2.2.1.v201112130541.jar
C:\Program Files\eclipse\plugins\com.google.guava_10.0.1.1.jar
C:\Program Files\eclipse\plugins\com.google.inject_3.0.0.no_aop.jar
C:\Program Files\eclipse\plugins\javax.inject_1.0.0.v20091030.jar
C:\Program Files\eclipse\plugins\org.antlr.runtime_3.2.0.v201101311130.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.mwe.core_1.2.1.v201112070431.jar
C:\Program Files\eclipse\plugins\org.apache.commons.cli_1.2.0.v201105210650.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.mwe2.runtime_2.2.0.v201112070431.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.mwe.utils_1.2.1.v201112070431.jar
C:\Program Files\eclipse\plugins\org.eclipse.xtext.xbase_2.2.1.v201112130541.jar
C:\Program Files\eclipse\plugins\org.eclipse.xtext.common.types_2.2.1.v201112130541.jar
C:\Program Files\eclipse\plugins\org.apache.log4j_1.2.15.v201012070815.jar
C:\Program Files\eclipse\plugins\org.apache.commons.logging_1.0.4.v201101211617.jar
C:\Program Files\eclipse\plugins\org.eclipse.xtext.generator_2.2.1.v201112130541.jar
C:\Program Files\eclipse\plugins\org.eclipse.xtend_1.1.0.v201108020519.jar
C:\Program Files\eclipse\plugins\com.ibm.icu_4.4.2.v20110823.jar
C:\Program Files\eclipse\plugins\org.eclipse.xpand_1.1.0.v201108020519.jar
C:\Program Files\eclipse\plugins\org.eclipse.xtend.typesystem.emf_1.0.1.v201108020519.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.codegen.ecore_2.7.0.v20120130-0943.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.codegen_2.6.0.v20120130-0943.jar
C:\Program Files\eclipse\plugins\de.itemis.xtext.antlr_2.0.0.v201108011202.jar
C:\Program Files\eclipse\plugins\org.antlr.generator_3.2.0.v201108011202.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.mwe2.lib_2.2.0.v201112070431.jar
C:\Program Files\eclipse\plugins\org.eclipse.xtext.xbase.lib_2.2.1.v201112130541.jar
C:\Program Files\eclipse\plugins\org.eclipse.xtend2.lib_2.2.1.v201112130541.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.mwe2.launch_2.2.0.v201112071250.jar
C:\Program Files\eclipse\plugins\org.eclipse.emf.mwe2.language_2.2.0.v201112071250.jar
4

2 回答 2

1

您必须将 Xtend 库放在包含 DSL 文件的项目的类路径中。

从上下文菜单中选择“构建路径”,然后选择“添加库”。选择 Xtend 库,它应该适合你。

于 2012-06-26T09:41:17.663 回答
0

问题已解决,事实证明您需要在实际声明 DSL 模型的项目的构建路径中包含 xbase.lib jar。

于 2012-06-27T07:53:30.097 回答