I want to extend the entity definition language from Xtext documentation(Five simple steps to your JVM language) as:
entity e{
firstName : String
op setFirstName(String firstName) : void{
checker:{name!=null} ⇐
this.firstName = firstName.toFirstLower
}
}
where "checker" is a customized expression and "{name!=null}" is a nested XExpression.
To do this, I append following to grammar:
XPrimaryExpression returns xbase::XExpression:
XConstructorCall |
XBlockExpression |
XSwitchExpression |
XSynchronizedExpression |
XFeatureCall |
XLiteral |
XIfExpression |
XForLoopExpression |
XBasicForLoopExpression |
XWhileExpression |
XDoWhileExpression |
XThrowExpression |
XReturnExpression |
XTryCatchFinallyExpression |
XParenthesizedExpression |
MyChecker
;
MyChecker:
'checker' ':' expression = XBlockExpression
I also implement the TypeComputer for MyChecker to avoid 'Missing type computation' exception.
But it seems that the completion proposal not work in 'checker:{ | }', expression contained in MyChecker rule can't reference it's outer scope.
Thanks very much.