Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using Actions Correctly in Xtext (A question on scripting language example)
Using Actions Correctly in Xtext [message #1014087] Mon, 25 February 2013 01:12 Go to previous message
Ozan Aksoy is currently offline Ozan Aksoy
Messages: 5
Registered: June 2012
Junior Member
Hi!

There is something I didn't understand well in using actions on parser rules.
Below is a simple example from
http://www.eclipse.org/Xtext/7languagesDoc.html#scripting
Script returns XBlockExpression:
	{Script}
	((expressions+=XExpressionInsideBlock | imports+=Import) ';'?)*;

Import:
	'import' importedNamespace=QualifiedNameWithWildcard;

QualifiedNameWithWildcard:
	QualifiedName '.*'?;


If I understood correctly from my previous tryouts with Xtext, {Script} notation means that the return type after that will be Script Type. Since a return type must be a subtype of the supertype (In this case, XBlockExpression is the supertype), Xtext Framework can consume the notation, create a Script instance every time an expression or import is written in DSL. I hope I got this part right. (I am writing it down so that you can see if I am mistaken)

From this, what I understood is the main reason we should have {Script} notation here is because of imports+=Import expression. If I try other style of coding, I always get a complain about "Import" type not being a subtype of XBlockExpression. But, how is it that, in the current expression, it can delegate to Imports successfully, but lets say underlying Xtext code complains that

Cannot find compatible feature imports in sealed EClass XBlockExpression from imported package http://www.eclipse.org/xtext/xbase/Xbase: The type 'XBlockExpression' does not have a feature 'imports'.

Lets say, when I try:
Script returns XBlockExpression:
	{Script}
	(expressions+=XExpressionInsideBlock';'?)* | (imports+=Import ';'?)*;


Can anyone explain me why the above code cannot work?


 
Read Message
Read Message
Read Message
Previous Topic:Use one grammar within another grammar
Next Topic:xtext-dsl -> enrich-model -> xtend2-template?
Goto Forum:
  


Current Time: Sat May 25 21:47:44 EDT 2013

Powered by FUDForum. Page generated in 0.06844 seconds