Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Factoring out rules with no wrapper return types
Factoring out rules with no wrapper return types [message #1066993] Fri, 05 July 2013 11:20 Go to next message
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012
Member
Hi!

Lets consider the following grammar excerpt:

RuleA returns MyTypeA:
    "Some" "rule" myList = RuleList
;

RuleB returns MyTypeB:
    "Other" "rule" myList = RuleList
;

RuleList returns MyList:
    "[" item+=MyItem ("," item+=MyItem)* "]"
;


The types MyTypeA, MyTypeB, MyList and MyItem come from an imported Ecore metamodel.
Both rules RuleA and RuleB need a rule RuleList.
However RuleList returns a wrapper type MyList for a list attribute.

What I want to achieve is to have ONE rule RuleList and no wrapper type for that rule, i.e. the following grammar

RuleA returns MyTypeA:
    "Some" "rule" "[" item+=MyItem ("," item+=MyItem)* "]"
;

RuleB returns MyTypeB:
    "Other" "rule" "[" item+=MyItem ("," item+=MyItem)* "]"
;



but with the
 "[" item+=MyItem ("," item+=MyItem)* "]" 

factored out to another rule RuleList (as before) which does not return any wrapper type for a list, i.e. something like

RuleA returns MyTypeA:
    "Some" "rule" RuleList
;

RuleB returns MyTypeB:
    "Other" "rule" RuleList
;

RuleList: ???
    "[" item+=MyItem ("," item+=MyItem)* "]"
;




Is this achievable with XText?

Best regards,
Alex.

[Updated on: Fri, 05 July 2013 11:21]

Report message to a moderator

Re: Pattern [message #1067222 is a reply to message #1066993] Sun, 07 July 2013 18:39 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You can just inline the elements of RuleList in RuleA and RuleB.
The DRY principle does not really count for the syntactical part of
Xtext grammars, especially not when the Ecore model is fixed.

Am 05.07.13 13:20, schrieb Alex G:
> Hi!
>
> Lets consider the following grammar excerpt:
>
>
> RuleA returns MyTypeA:
> "Some" "rule" myList = RuleList
> ;
>
> RuleB returns MyTypeB:
> "Other" "rule" myList = RuleList
> ;
>
> RuleList returns MyList:
> "[" item+=MyItem ("," item+=MyItem)* "]"
> ;
>
>
> The types MyTypeA, MyTypeB, MyList and MyItem come from an imported
> Ecore metamodel.
> Both rules RuleA and RuleB need a rule RuleList.
> However RuleList returns a wrapper type MyList for a list attribute.
>
> What I want to achieve is to have ONE rule RuleList and no wrapper type
> for that rule, i.e. the following grammar
>
>
> RuleA returns MyTypeA:
> "Some" "rule" "[" item+=MyItem ("," item+=MyItem)* "]"
> ;
>
> RuleB returns MyTypeB:
> "Other" "rule" "[" item+=MyItem ("," item+=MyItem)* "]"
> ;
>
>
>
> but with the "[" item+=MyItem ("," item+=MyItem)* "]" factored out to
> another rule RuleList (as before) which does not return any wrapper type
> for a list, i.e. something like
>
>
> RuleA returns MyTypeA:
> "Some" "rule" RuleList
> ;
>
> RuleB returns MyTypeB:
> "Other" "rule" RuleList
> ;
>
> RuleList: ???
> "[" item+=MyItem ("," item+=MyItem)* "]"
> ;
>
>
>
>
> Is this achievable with XText?
>
> Best regards,
> Alex.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Pattern [message #1067253 is a reply to message #1067222] Mon, 08 July 2013 06:27 Go to previous messageGo to next message
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012
Member
Jan Kohnlein wrote on Sun, 07 July 2013 14:39
You can just inline the elements of RuleList in RuleA and RuleB.
The DRY principle does not really count for the syntactical part of
Xtext grammars, especially not when the Ecore model is fixed.


I see. Thank you for the information.

Are there plans to assist these kinds of factorings in a later Xtext version?
Re: Pattern [message #1067518 is a reply to message #1067253] Tue, 09 July 2013 08:16 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Currently we don't have such plans.

Am 08.07.13 08:27, schrieb Alex G:
> Jan Kohnlein wrote on Sun, 07 July 2013 14:39
>> You can just inline the elements of RuleList in RuleA and RuleB.
>> The DRY principle does not really count for the syntactical part of
>> Xtext grammars, especially not when the Ecore model is fixed.
>
>
> I see. Thank you for the information.
>
> Are there plans to assist these kinds of factorings in a later Xtext
> version?


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Xtext - Recursive grammar
Next Topic:Xtext project from ECore with abstract types
Goto Forum:
  


Current Time: Tue Apr 16 09:58:19 GMT 2024

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

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

Back to the top