Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XBlockExpression is only variable or assignment?(Is this documentation up to date)
XBlockExpression is only variable or assignment? [message #1783774] Fri, 16 March 2018 18:53 Go to next message
Alexandros Karypidis is currently offline Alexandros KarypidisFriend
Messages: 97
Registered: March 2010
Member
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.
Re: XBlockExpression is only variable or assignment? [message #1783775 is a reply to message #1783774] Fri, 16 March 2018 18:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
how does your model project look like
- should be a java project
- model files should reside in a source folder
- project needs xtext builder and nature
- xbase.lib needs to be on the classpath (e.g. by adding the xtend libary)


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XBlockExpression is only variable or assignment? [message #1783815 is a reply to message #1783775] Sun, 18 March 2018 14:18 Go to previous message
Alexandros Karypidis is currently offline Alexandros KarypidisFriend
Messages: 97
Registered: March 2010
Member
Hi Christian,

The culprit was missing xbase from my classpath. As per the documentation "To add this, right-click on the project and go to Java Build Path → Libraries → Add Library and choose Xtend Library." which fixed the issue.
Previous Topic:[deleted]
Next Topic:Regarding Validations in Xtext
Goto Forum:
  


Current Time: Sun Sep 23 05:23:48 GMT 2018

Powered by FUDForum. Page generated in 0.02060 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top