Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to restrict a rule
How to restrict a rule [message #1058265] Mon, 13 May 2013 08:16 Go to next message
rohit ahuja is currently offline rohit ahuja
Messages: 25
Registered: February 2013
Junior Member
I have something like,

Model
exp1= EXPRESSION '+' exp2=EXPRESSION

where EXPRESSION handles all kind of possible cases that i require.

Now the problem is that '+' is also part of an expression, and exp1 basically spans across the '+' symbol and consumes the exp2 as well.

is it possible to do this in some other way?

Thanks,
Rohit
Re: How to restrict a rule [message #1058447 is a reply to message #1058265] Tue, 14 May 2013 03:19 Go to previous messageGo to next message
Colonel Panic is currently offline Colonel Panic
Messages: 7
Registered: May 2013
Junior Member
Before you can answer this question you need to decide for yourself how the compiler should decide which expression belongs in which side of the AST. For example, should it parse:

a + b + c


as
exp1='a' '+' exp2='b + c'

or
exp1='a + b' '+' exp2='c'


Until you can decide this for yourself, there isn't a general case answer to your problem.

It may be the case that you are trying to put too much validation into the parser. Consider parsing 'EXPRESSION + EXPRESSION' in a single rule, rather than two, then deciding in your model validation and/or inference which version of the rule is intended (according to rules of your own choosing).

Hope that helps!
Re: How to restrict a rule [message #1058461 is a reply to message #1058447] Tue, 14 May 2013 04:43 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6230
Registered: July 2009
Senior Member
This might help as well
http://blog.efftinge.de/2010/08/parsing-expressions-with-xtext.html
Previous Topic:Developing custom xtext editor
Next Topic:Generate mydsl Plug-in with Updatesite
Goto Forum:
  


Current Time: Fri Aug 29 04:09:38 EDT 2014

Powered by FUDForum. Page generated in 0.02058 seconds