我正在寫一個簡單的小型DSL來指定對消息的約束,並且一直試圖將XBase表達式嵌入到語言中一段時間沒有成功。如何在Xtext中嵌入XBase表達式DSL
的語法如下:
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)?
;
當試圖解析文件如:
通過約束有效載荷SimulationSessionEvents元矩陣...
我不能讓它爲......工作... =任何類型的算術表達式,儘管它適用於... =循環或表達式,甚至只是一個數字。只要我做'-5'或'4-5'之類的東西,它就表示Couldn't resolve reference to JvmIdentifiableElement '-'
,即使Xbase.xtext語法看起來像它允許這些表達式。
我不認爲我錯過了任何Jars,因爲它不會抱怨當我運行我的工作流程,但只有當試圖解析輸入文件。
任何幫助將不勝感激。
編輯: 該項目的構建路徑如下:
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
「實際上聲明你的DSL模型的項目」是指使用你的DSL的項目?那麼具有* .mydsl文件的項目呢? – alopix
@alopix正好 –