Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Dynamic grammar(Predicates / Conditions)
icon5.gif  Dynamic grammar [message #762063] Wed, 07 December 2011 13:54 Go to next message
Jeff MAURY is currently offline Jeff MAURYFriend
Messages: 44
Registered: July 2009
Member
I am facing the following issue:
one of the parameter of one of my rules may have is discret set of values and a following parameter also have a discret set of rules but the set is determined by the value of the previous parameter.
So I tried to use enum for the sets of values but I don't know how to do the dynamic part for the second parameter.
I have look at the predicates functionnality but I don't understand how to use it in my case.
Can someone help ?

Jeff MAURY
Re: Dynamic grammar [message #762131 is a reply to message #762063] Wed, 07 December 2011 15:38 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Could you provide an example of what you have in mind? I don't really understand the question, I think, so I can't comment on whether syntactic predicates are any help here.

Re: Dynamic grammar [message #762153 is a reply to message #762131] Wed, 07 December 2011 16:10 Go to previous messageGo to next message
Jeff MAURY is currently offline Jeff MAURYFriend
Messages: 44
Registered: July 2009
Member
Here is a sample:

enum FirstParm:
FP_VALUE1 |
FP_VALUE2;

enum SecondParmWhenValue1:
SP1_VALUE1_VALUE1 |
SP1_VALUE1_VALUE2;

enum SecondParmWhenValue2:
SP1_VALUE2_VALUE1 |
SP1_VALUE2_VALUE2;

MyRule:
firstParm=FirstParm secondParm=(firstParm==FP_VALUE1)?SecondParmWhenValue1:SecondParmWhenValue2;

Please note that the syntax of MyRule is not XText 2.1 compliant but describe what I want to achieve.
So my rule has two parms, and the set of values of the second is determined by the value of the first one.

Regards
Jeff
Re: Dynamic grammar [message #762172 is a reply to message #762153] Wed, 07 December 2011 16:40 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Now I get it. This is actually an example of a grammar with a semantic predicate, i.e. the syntax is influenced by values in the preceding (con-)text. You'd need a predicated parser for that, but Xtext cannot give you that - strict LL(*) languages only.

However, you could easily separate syntax and semantics by creating a "big enum" with all the SP1_VALUEn_VALUEm keywords and validate the correct use through a @Check validation. You then could tweak the content assist (which can use post-parsing information!) to only give you the correct completions for secondParm. Admittedly, it's not trivial but allows you to accomplish what you want.


Re: Dynamic grammar [message #762535 is a reply to message #762172] Thu, 08 December 2011 09:00 Go to previous message
Jeff MAURY is currently offline Jeff MAURYFriend
Messages: 44
Registered: July 2009
Member
Thanks for your response.
I found another solution using alternative in the grammar but it does not use enum (at least for the first param).
I will try your proposal.

Jeff MAURY
Previous Topic:UML to Ecore
Next Topic:Is Xtext good solution for my project?
Goto Forum:
  


Current Time: Fri Mar 29 11:19:44 GMT 2024

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

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

Back to the top