How to embed XBase expressions in an Xtext DSL
- by Marcus Mathioudakis
I am writing a simple little DSL for specifying constraints on messages, and Have been trying without success for a while to embed XBase expressions into the language.
The Grammar looks like this:
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)?
;
When trying to parse a file such as:
FOR PAYLOAD SimulationSessionEvents ELEMENT matrix CONSTRAINED BY ...
I can't get it to work for ... = any kind of Arithmetic expression, although it works for ...= loop or if expression, or even just a number. As soon as I do something like '-5' or '4-5' it says Couldn't resolve reference to JvmIdentifiableElement '-', even though the Xbase.xtext Grammar looks like it allows these expressions.
I don't think I'm missing any Jars, as it doesn't complain when I run the mwe workflow, but only when trying to parse the input file.
Any help would be much appreciated.