Using Actions Correctly in Xtext [message #1014087] |
Mon, 25 February 2013 06:12 |
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?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03029 seconds