我正在编写一个简单的小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矩阵受限制......
我无法让它工作... =任何类型的算术表达式,虽然它适用于... =循环或表达式,甚至只是一个数字。只要我执行“-5”或“4-5”之类的操作就会显示Couldn't resolve reference to JvmIdentifiableElement '-'
,即使Xbase.xtext语法看起来像是允许这些表达式。
我不认为我错过了任何Jars,因为它在我运行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
答案 0 :(得分:1)
您必须将Xtend库放在包含DSL文件的项目的类路径中。
从上下文菜单中选择“构建路径”,然后选择“添加库”。选择Xtend库,它应该适合你。
答案 1 :(得分:0)
问题已解决,事实证明你需要在实际声明DSL模型的项目的构建路径中包含xbase.lib jar。