Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext] Problem with Rules without Model Elements
[Xtext] Problem with Rules without Model Elements [message #54514] Wed, 01 July 2009 12:30 Go to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
Hi all,

I'm currently migrating my existing (and working!) oAW Xtext grammar to
TMF Xtext. I've found a problem with rules which do not contain model
elements.

This is an example:

--------------------------------------
Statement:
ReturnStatement |
IfStatement |
...
;

ReturnStatement:
"return" (expression=Expression)? ";";
....
--------------------------------------

These rules worked in the old version, but in the new version return
statements are not recognized by the parser anymore if no expression
(which is optional) is specified (that is no element of ReturnStatement
is created). No error message, they are simply ignored. That is in the
following example, line 1 works, line 2 does not work:

--------------
1: return 1;
2: return;
--------------

The same is true for other constructs. Fortunately I found a workaround:

--------------------------------------
ReturnStatement:
x="return" (expression=Expression)? ";";
--------------------------------------

I can use this solution as a pattern ("x=") in all my rules, such as:

--------------------------------------
Block:
x="{" (statements+=BlockStatement)* "}";
BreakStatement:
x="break" ";";
...
--------------------------------------

Is this simply a bug in the TMF Xtext version? All these rules worked
with the "x="-pattern in the previous version.

Cheers

Jens
Re: [Xtext] Problem with Rules without Model Elements [message #54543 is a reply to message #54514] Wed, 01 July 2009 12:32 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Jens,

please try to use unassigned actions in this case:

ReturnStatement :
"return" {ReturnStatement} expression=Expression? ";";

You'll find more details about them in the docs.

Regards,
Sebastian

Am 01.07.2009 14:30 Uhr, schrieb Jens v.P.:
> Hi all,
>
> I'm currently migrating my existing (and working!) oAW Xtext grammar to
> TMF Xtext. I've found a problem with rules which do not contain model
> elements.
>
> This is an example:
>
> --------------------------------------
> Statement:
> ReturnStatement |
> IfStatement |
> ...
> ;
>
> ReturnStatement:
> "return" (expression=Expression)? ";";
> ....
> --------------------------------------
>
> These rules worked in the old version, but in the new version return
> statements are not recognized by the parser anymore if no expression
> (which is optional) is specified (that is no element of ReturnStatement
> is created). No error message, they are simply ignored. That is in the
> following example, line 1 works, line 2 does not work:
>
> --------------
> 1: return 1;
> 2: return;
> --------------
>
> The same is true for other constructs. Fortunately I found a workaround:
>
> --------------------------------------
> ReturnStatement:
> x="return" (expression=Expression)? ";";
> --------------------------------------
>
> I can use this solution as a pattern ("x=") in all my rules, such as:
>
> --------------------------------------
> Block:
> x="{" (statements+=BlockStatement)* "}";
> BreakStatement:
> x="break" ";";
> ...
> --------------------------------------
>
> Is this simply a bug in the TMF Xtext version? All these rules worked
> with the "x="-pattern in the previous version.
>
> Cheers
>
> Jens
>
Previous Topic:Xtext from Modelling package issues
Next Topic:[Xtext] Problem modifying enumeration in post processing (Xtend)
Goto Forum:
  


Current Time: Thu Jun 27 20:36:35 GMT 2024

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

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

Back to the top