Factoring out rules with no wrapper return types [message #1066993] |
Fri, 05 July 2013 11:20 |
Alex G 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 |
Jan Koehnlein 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 #1067518 is a reply to message #1067253] |
Tue, 09 July 2013 08:16 |
Jan Koehnlein 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
|
|
|
Powered by
FUDForum. Page generated in 0.02261 seconds