Hi,
I'm going through the Xtext tutorial can got stuck in the example for inferring a JVM model. In the documentaion the code uses the following for the body of an operation:
Operation:
'op' name=ValidID
'(' (params+=FullJvmFormalParameter
(',' params+=FullJvmFormalParameter)*)? ')'
':' type=JvmTypeReference
body=XBlockExpression;
Operation : {
members += feature.toMethod(feature.name, feature.type) [
documentation = feature.documentation
for (p : feature.params) {
parameters += p.toParameter(p.name, p.parameterType)
}
body = feature.body
]
}
For some reason when I launch eclipse to test the example, I cannot declare anything but variables or assignments, specifically the '+' operator is not recognised and gives the error "+ cannot be resolved.", see the snippet I am using to test:
package test {
entity Person {
firstName : String
lastName : String
op getFullName () : String
{
val temp = 3
val test = firstName
// OK: return firstName.toLowerCase
return firstName + " " + lastName // ERROR:" + cannot be resolved."
}
}
What could be causing this? I can't figure it out, but I'm thinking maybe the documentation is slightly out of date? The reason to suspect that is that drilling down to XBlockExpression in my xtext where I declare the "Operation" rule takes me to Xbase.xtext from org.eclipse.xtext.xbase-2.13.0.jar which is defined as:
XBlockExpression returns XExpression:
{XBlockExpression}
'{'
(expressions+=XExpressionOrVarDeclaration ';'?)*
'}';
XExpressionOrVarDeclaration returns XExpression:
XVariableDeclaration | XExpression;
XVariableDeclaration returns XExpression:
{XVariableDeclaration}
(writeable?='var'|'val') (=>(type=JvmTypeReference name=ValidID) | name=ValidID) ('=' right=XExpression)?;
//...and at the very top:
XExpression returns XExpression :
XAssignment;
If I am reading this correctly, an XBlockExpression is now either a variable declaration or a simple assignment? I am not sure what the "returns XEpression" syntax means but I may be misunderstanding it as it should not accept "return" at all in that case (it's an XReturnExpression which doesn't seem to be included in the rule chain).
Any help will be appreciated.