Using Actions Correctly in Xtext [message #1014087] |
Mon, 25 February 2013 01:12  |
Eclipse User |
|
|
|
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?
|
|
|
|
Re: Using Actions Correctly in Xtext [message #1014121 is a reply to message #1014102] |
Mon, 25 February 2013 02:47  |
Eclipse User |
|
|
|
Isn't{Script} is the return value for all the expression in both cases? I thought operation order would not be a issue since it was given at the beginning of the statement. I understood as if it recursively replaces all return types even without the explicit use of '('...
Hmmm... I guess I got it now.
So,
((expressions+=XExpressionInsideBlock)';'?)* | {Script} ((imports+=Import) ';'?)*
Would also work.
|
|
|
Powered by
FUDForum. Page generated in 0.27591 seconds