Skip to main content



      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 07:20 Go to next message
Eclipse UserFriend
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 07:21] by Moderator

Re: Pattern [message #1067222 is a reply to message #1066993] Sun, 07 July 2013 14:39 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Pattern [message #1067253 is a reply to message #1067222] Mon, 08 July 2013 02:27 Go to previous messageGo to next message
Eclipse UserFriend
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 04:16 Go to previous message
Eclipse UserFriend
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
Previous Topic:Xtext - Recursive grammar
Next Topic:Xtext project from ECore with abstract types
Goto Forum:
  


Current Time: Tue Jul 08 15:31:06 EDT 2025

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

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

Back to the top