Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Regarding rule precedence and Optional Category
icon7.gif  Regarding rule precedence and Optional Category [message #1722314] Thu, 04 February 2016 07:16 Go to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
I am trying to create a grammar for a scenario where

1. Categories are optional
2. Category are conditional (Some can exist only if a particular category already exists in the statement)
3. Categories can occur at Multiple places




"plot profit by Month for Jim"

Here,
-Can Occur at multiple places :
"by Month" can occur anywhere after "plot profit" . (not just after "plot profit")
So,plot profit for Jim by Month is also valid

-Conditional
"by Month" should occur only if "plot profit" exists

--Optional
It may not occur at all.

My Grammar looks like this :

(key=QTypekeyWord)? measure=MeasureList (by='by'groupBy=GroupBy)?


QTypekeyWord:
qKeyword='plot'
;
MeasureList : names+=Measure ("," names+=Measure)*;
Measure:ID+;

Dimension:
dimension=ID
;

GroupBy:
group+= Dimension ('and' group+=Dimension)*

But it does not imply all three points. Please let me know if there is a succinct way to represent the grammar.

Should I use " | " to represent all the possibilities of statements or there are other ways.


Re: Regarding rule precedence and Optional Category [message #1722317 is a reply to message #1722314] Thu, 04 February 2016 07:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

can you give a sample model as well? i dont see categeories in your grammar?

some general hint:

- you do not have to encode everything in your grammar. it often helps to move rules to a semantic validation (check method in the validator)
- you can use unordered groups if you want to have grammar stuff in any order


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722321 is a reply to message #1722317] Thu, 04 February 2016 07:30 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
Thanks for the reply.

I wish to have content assist work at any place in a statement like above instead of validation.

Its the dummy one I am using .

Model:
message=Query;

please correct me if I am missing something. Or provide some resource to create a grammar with such requirements. Any examples other than what is mentioned in the doc?

[Updated on: Thu, 04 February 2016 07:30]

Report message to a moderator

Re: Regarding rule precedence and Optional Category [message #1722323 is a reply to message #1722321] Thu, 04 February 2016 07:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you can implement the filtering in the content assist and or scoping as well, but this depends on your concepts.
in the grammar you posted there are IDs only so i do not get any clue how to give further advice.
can you give a complete grammar and model i can simply copy and paste?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722325 is a reply to message #1722323] Thu, 04 February 2016 07:49 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
This is the sample grammar that I am using. I am using this to achieve all three points I stated above. For simplicity I just added ID. You can change the value to any random string as I mentioned in my example.



Model:
greetings=Query;

Query:
(key=QTypekeyWord)?measure=MeasureList (by='by'groupBy=GroupBy)?


QTypekeyWord:
qKeyword='plot'
;

MeasureList : names+=Measure ("," names+=Measure)*;
Measure:ID+;


GroupBy:
group+= Dimension ('and' group+=Dimension)* ;

Dimension:
dimension=ID
;

Re: Regarding rule precedence and Optional Category [message #1722327 is a reply to message #1722325] Thu, 04 February 2016 07:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

yes but this gramamr say: the by comes at the end.

so isnt your semantics

Query:
(key=QTypekeyWord)? parts+=QueryPart+;

QueryPart:
measure=MeasureList (by='by'groupBy=GroupBy)? ;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722329 is a reply to message #1722327] Thu, 04 February 2016 07:54 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
Yeah. It is not complete . I am not sure how to have it conditioned and unordered.
Re: Regarding rule precedence and Optional Category [message #1722330 is a reply to message #1722329] Thu, 04 February 2016 07:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you cannot have conditioned if the decision is static. so what is the condition in your example

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722332 is a reply to message #1722330] Thu, 04 February 2016 08:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
and where is the unordered thing? a group always comes after the measures.

but maybe your grammar is just a mixed list of dimensions and bys?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722339 is a reply to message #1722332] Thu, 04 February 2016 08:14 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
yeah I know there is no condition and unordering. I want to convert this grammar to achieve the three points I mentioned.
Re: Regarding rule precedence and Optional Category [message #1722342 is a reply to message #1722339] Thu, 04 February 2016 08:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes
1. Categories are optional and 3. Categories can occur at Multiple places can be done if you reorganize the grammar

but 2. Category are conditional (Some can exist only if a particular category already exists in the statement) cannot be hardcoded to the grammar.
=> you have to adapt scope provider and/or contentassist


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722347 is a reply to message #1722342] Thu, 04 February 2016 09:05 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
Ok Thank you.Could you please direct me to 3 .any examples.?

[Updated on: Thu, 04 February 2016 09:08]

Report message to a moderator

Re: Regarding rule precedence and Optional Category [message #1722348 is a reply to message #1722347] Thu, 04 February 2016 09:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Model: (list+=StuffOfKindA|list+=StuffOfKindB)+

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722349 is a reply to message #1722348] Thu, 04 February 2016 09:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
or

Model:
stuff+=Stuff+;

Stuff: ... (optionalForStuff=OptionalThing)?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722350 is a reply to message #1722349] Thu, 04 February 2016 09:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
or if the optional and the required stuff should have any order

Model: parts+=Part+;

Part: (required=Required) & (optional=Optional)?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722358 is a reply to message #1722350] Thu, 04 February 2016 09:38 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
So in the following :

(key=QTypekeyWord)? measure=MeasureList (by='by'groupBy=GroupBy)?

In this pattern , QTypeWord and GroupBy are optionals.

while measure=MeasureList is mandatory .

what difference is it to

(key=QTypekeyWord)? (measure=MeasureList)& (by='by'groupBy=GroupBy)?


How do I change it such that even empty state is accepted by the grammar. Right now I am getting a" ()+ did not match any thing at input. Is this because of grammar" in the UI editor. Haven't been able to figure it out .
Re: Regarding rule precedence and Optional Category [message #1722362 is a reply to message #1722358] Thu, 04 February 2016 10:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i still dont get the requirements and semantics of your sample

Model:
greetings=Query;

Query:
(key=QTypekeyWord)? measures+=MeasureList+
;

QTypekeyWord:
qKeyword='plot'
;

MeasureList : names+=Measure ("," names+=Measure)* (by?='by'groupBy=GroupBy)?;
Measure:=> ID+;


GroupBy:
group+= Dimension ('and' group+=Dimension)* ;

Dimension:
dimension=ID
;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722366 is a reply to message #1722362] Thu, 04 February 2016 10:28 Go to previous messageGo to next message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member


Model:
greetings=Query;

Query:
(key=QTypekeyWord)? measures+=MeasureList+ (by='by'groupBy=GroupBy)? (condition=Condtition)? 
;

QTypekeyWord:
qKeyword='plot'
;

MeasureList : names+=Measure ("," names+=Measure)* (by?='by'groupBy=GroupBy)?;
Measure:=> ID+;


GroupBy:
group+= Dimension ('and' group+=Dimension)* ;

Dimension:
dimension=ID
;

DimensionValue:
	value=ID
;

Condtition:
	con='for' dimVal=DimensionValue 
;



I have added condition category to express my point better.
In this example I am trying to match "plot profit by country for tim".



However, in the grammar when I do "plot profit for tim" . the "by" clause is not expected after tim. because my grammar has a place for condition (which is last).

ideally ,
I want to change this grammar such that when I provide "plot profit for tim" it should be able to accept by after tim.

as "by" and "condition" can be interchangeable and should not hold a specific place in a statement




Re: Regarding rule precedence and Optional Category [message #1722367 is a reply to message #1722366] Thu, 04 February 2016 10:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
this is what unordered groups do

((by='by'groupBy=GroupBy)? &(condition=Condtition)? )


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding rule precedence and Optional Category [message #1722458 is a reply to message #1722367] Fri, 05 February 2016 03:00 Go to previous message
pranay roy is currently offline pranay royFriend
Messages: 196
Registered: January 2016
Senior Member
Thank you for this. It worked Smile
Previous Topic:Initializer from XExpression
Next Topic:importing from java in custom expressions
Goto Forum:
  


Current Time: Thu Apr 25 16:36:19 GMT 2024

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

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

Back to the top