Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » grammar mixin(priority of rules)
grammar mixin [message #762079] Wed, 07 December 2011 14:15 Go to next message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
Hello all,

given:

grammar superGrammar with Terminal

Model:elments+=Element*;
Element: 'ct' '(' head = ID ',' text= STRING ')' '.';

grammar subGrammar with superGrammar
Model2: elements2 += Element2*
Element2: Call
Call: 'call' '[' call= Predicate ']' '.';
Predicate: functor = ID '(' Args = ID ')' ;

if this demo would work, my question as i can enter
ct(head1,'text1').
in the first grammar being ct as keyword and colored in red BUT when i enter this in subGrammar:
call[ ct(something)].
The parser complaints because it wants ct(something,'sometext') and not only ct(something) inside call[..] How to understand and manage this priority?
In general does this modularity of mixing grammar have the sense of inheritance and so in OOP or it is just copying whole rules from there to here?

Best regards,
Mokhtar
Re: grammar mixin [message #762119 is a reply to message #762079] Wed, 07 December 2011 15:19 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
'ct' is a keyword for both grammars, since you defined it in the first one. That means that the 'ct' in "call[ ct(..." isn't matched and consumed by functor=ID from the Predicate of the sub grammar, so it cannot parse the Call. Keywords get priority over "more general" terminals like ID.

Re: grammar mixin [message #762129 is a reply to message #762079] Wed, 07 December 2011 15:37 Go to previous messageGo to next message
Max Goltzsche is currently offline Max GoltzscheFriend
Messages: 40
Registered: November 2011
Member
Hey,

As far as I know if you extend a grammar all rules are copied. You can inherit your SubGrammar's Validators, ScopeProvider etc. from superGrammar's Validators, ScopeProvider etc.

But in your example I cannot see how you use your superGrammar in subGrammar. Neither you use Model nor Element.

You can also use / extend your superGrammar's rules but you cannot change its classes because they are already generated.

You should be able to use Element inside call by writing e.g.:
grammar subGrammar with superGrammar
Model2: elements2 += Element2*
Element2: Call
Call: 'call' '[' call=YourCallFork ']' '.';

YourCallFork: ElementCall | Predicate;
ElementCall: element=Element; // from superGrammar

Predicate: functor = ID '(' Args = ID ')';


If you would like to extend a superGrammar's rule you could write sth like:
grammar subGrammar with superGrammar
import "http://www.superGrammar.org" as superGrammar

Model returns superGrammar::Model:
    elments+=Element*;

Element returns superGrammar::Element:
    Call;
...
In this case you have to import the superGrammar with a name and override rules by absolute name.

Hope that helps.

regards,
Max
Re: grammar mixin [message #762228 is a reply to message #762129] Wed, 07 December 2011 18:30 Go to previous messageGo to next message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
Thank you both, that example was just demo. i did it to express my concern. Now my question is why was the input 'ct'.. not consumed by the rule functor = ID ? as the parsing was inside the Call rule from sub and not inside the Element rule from super grammar?

thankyou danke
Re: grammar mixin [message #762287 is a reply to message #762228] Wed, 07 December 2011 20:06 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

i guess the problem is that your keywords win over the ID rule so in this case a keyword 'ct' is recognized and not an ID.
=> you have to introduce a datatype rule IDExtended: 'ct'|ID and change the rule to functor=IDExtended

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:refining generated model
Next Topic:Selectively adding actions to Outline popup menu
Goto Forum:
  


Current Time: Sat Apr 20 03:12:14 GMT 2024

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

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

Back to the top