Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Wrong type binary rule's member
Wrong type binary rule's member [message #900632] Tue, 07 August 2012 21:04 Go to next message
Dobes Vandermeer is currently offline Dobes VandermeerFriend
Messages: 26
Registered: July 2009
Junior Member
I have a rule like this:

Factor: Unary ({FactorOp.left=current} dotOp=("." | "*.") ("[" index=Expr? (range?='to' rangeEnd=Expr)? "]" | member=Name))*;


The problem is that the class generated for this (FactorOp) infers that the type of FactorOp.left will be Unary whereas it may be Unary or another FactorOp if these are chained.

How can I tell Xtext to declare the type of FactorOp.left as Factor or some other common base class of Unary and Factor?

Re: Wrong type binary rule's member [message #900640 is a reply to message #900632] Tue, 07 August 2012 21:53 Go to previous messageGo to next message
Dobes Vandermeer is currently offline Dobes VandermeerFriend
Messages: 26
Registered: July 2009
Junior Member
This typing problem also seems to apply to any left-associative operator. For example when I define a rule :

ImpliesCondition: LogicalOr ({BinaryOp.left=current} =>op=('implies' | '\\implies') right=LogicalOr )*;


The resulting class "BinaryOp" has both left and right with type "LogicalOr" which means it cannot be recursive and have an ImpliesCondition on the left.

For the binary operators I think I can workaround it by using rules like:

ImpliesCondition: LogicalOr ({BinaryOp.left=current} =>op=('implies' | '\\implies') right=ImpliesCondition)?;


But I'm still pondering how to do that for my "Factor" rule above, and I'm not sure these rules should really be right-associative.


Re: Wrong type binary rule's member [message #900642 is a reply to message #900640] Tue, 07 August 2012 22:06 Go to previous messageGo to next message
Dobes Vandermeer is currently offline Dobes VandermeerFriend
Messages: 26
Registered: July 2009
Junior Member
Note this style of left-associative operators came from

http colon //blog.efftinge.de/2010/08/parsing-expressions-with-xtext.html

The Online Help doesn't seem to have any examples of left-associative operators at the moment.
Re: Wrong type binary rule's member [message #900643 is a reply to message #900642] Tue, 07 August 2012 22:15 Go to previous message
Dobes Vandermeer is currently offline Dobes VandermeerFriend
Messages: 26
Registered: July 2009
Junior Member
OK I looked at the Arithmetic example.

Turns out not so much a case of RTFM but check out the examples ...

I need to put "returns Expr" for all of the related rules, then it'll use Expr as the field type and clean up the type hierarchy.
Previous Topic:Documentation for "new" serializer?
Next Topic:How does the Serializer work? Reg. NFA + NodeModel
Goto Forum:
  


Current Time: Tue Apr 23 08:22:19 GMT 2024

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

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

Back to the top