With xtext I'm trying to develop a small language.
def sum(Integer a, Integer b):Integer {
return (a+b)
}
This is the grammar I use for this:
Function:
'def' name=ValidID
'('(params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')'
':' type=JvmTypeReference
body=XBlockExpression;
For reasons obvious to me it complains that "Void functions cannot return a value". How do I link the type of the return expression with the type in my function declaration?
You have to put the expression into the context of a JvmOperation. Please refer to the domain model example, the docs and the 7-languages if you want to learn more about the inferred JVM model.
Basically, what you have to do is something along these lines: