How to embed XBase expressions in an Xtext DSL
Posted
by
Marcus Mathioudakis
on Stack Overflow
See other posts from Stack Overflow
or by Marcus Mathioudakis
Published on 2012-06-26T09:12:48Z
Indexed on
2012/06/26
9:15 UTC
Read the original article
Hit count: 294
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.
© Stack Overflow or respective owner