The Newsgroup Web Interface is deprecated, and can no longer be used to post. Please use the Community Forums.

Eclipse NewsPortal - eclipse.modeling.tmf

Re: [Xtext] Problem with Rules without Model Elements

Subject: Re: [Xtext] Problem with Rules without Model Elements
From: Sebastian.Zarnekow@xxxxxxxxxxxx (Sebastian Zarnekow)
Newsgroups: eclipse.modeling.tmf
Organization: EclipseCorner
Date: Jul 01 2009 07:32:59
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


Date Subject  Author
31.12. o 


"News-Portal" was written by Florian Amrhein.


Search this group