Skip to main content


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 06:12 Go to next message
Ozan Aksoy is currently offline Ozan AksoyFriend
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?


Re: Using Actions Correctly in Xtext [message #1014102 is a reply to message #1014087] Mon, 25 February 2013 06:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Isnt that simply a precedence thing

{} is higher than | =>

((expressions+=XExpressionInsideBlock';'?)* | (imports+=Import ';'?))*;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using Actions Correctly in Xtext [message #1014121 is a reply to message #1014102] Mon, 25 February 2013 07:47 Go to previous message
Ozan Aksoy is currently offline Ozan AksoyFriend
Messages: 5
Registered: June 2012
Junior Member
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.
Previous Topic:Use one grammar within another grammar
Next Topic:xtext-dsl -> enrich-model -> xtend2-template?
Goto Forum:
  


Current Time: Fri Apr 19 00:34:18 GMT 2024

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

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

Back to the top