For testing purposes, I would like to parse a stand-alone expression in my Xtext language.
In my tests, I can parse a complete model using a ParseHelper<Model>
, e.g.,
val model = parseHelper.parse('''function { 1 + 2 }''')
Is it possible to parse a stand-alone expression in a similar way? I have tried injecting a ParseHelper<Expression>
and writing
val expr = parseHelper.parse('''1 + 2''')
but this returns null
for some reason.
The examples above are based on the following dummy grammar.
Model:
functions+=Function*
;
Function:
'function' '{' Expression '}'
;
Expression:
Addition
;
Addition returns Expression:
Literal (=>({Addition.left=current} '+') right=Literal)*
;
Literal returns Expression:
INT
;