Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Confusing error message when switching on type with rewrite rule
Confusing error message when switching on type with rewrite rule [message #1771276] Wed, 23 August 2017 15:53 Go to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
I have a type defined using rewrite rules as follows:

Expression: ExpBinOr;
ExpBinOr: ExpBinAnd ( {OpBoolean.left=current} ops+='||' rights+=ExpBinAnd)*;
ExpBinAnd: ExpEquality ({OpBoolean.left=current} ops+='&&' rights+=ExpEquality)*;


Which my generator then tries to address as follows:

def String compileExpression(Expression e) {
	switch (e) {
		OpBoolean, OpEquality, OpInequality, OpMath:
			compileExpression(e.left)
...


The problem is that this gives an error message saying that "left is undefined for ExpBinAnd". I don't understand why this is coming up - although it is true that the ExpBinAnd rule does not contain a left feature, all of the four classes listed in the switch statement do, and I thought the Xtend switch statement automatically cast the value to the matched type, which cannot be ExpBinAnd since it is not in the list.
Re: Confusing error message when switching on type with rewrite rule [message #1771279 is a reply to message #1771276] Wed, 23 August 2017 15:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
do you mean

{ExpBinAnd.left=current}

???


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Confusing error message when switching on type with rewrite rule [message #1771280 is a reply to message #1771279] Wed, 23 August 2017 16:15 Go to previous messageGo to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
No, it is meant to be a rewrite action as described under the heading "Assigned Actions" in the Xtext parser documeentation.
Re: Confusing error message when switching on type with rewrite rule [message #1771284 is a reply to message #1771280] Wed, 23 August 2017 16:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
can you please give a complete minimal reproducing grammar?

if you do a switch with multiple types it will get its supertype

looks like the common supertype of OpBoolean, OpEquality, OpInequality, OpMath is ExpBinAnd



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Confusing error message when switching on type with rewrite rule [message #1771294 is a reply to message #1771284] Wed, 23 August 2017 18:04 Go to previous messageGo to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
Ah, ok. Is there any way to create a superclass for these? The documentation says this can be done by creating a proxy parser rule that is never used. But that only works if the subtypes are rules, not types invoked through rewrite actions.
Re: Confusing error message when switching on type with rewrite rule [message #1771320 is a reply to message #1771294] Thu, 24 August 2017 04:02 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Actually not you can write something like (uncalled)

Supertype: Subtype1 | Subtype2 | .... ;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:SyntaxErrorMessageProvider custom implementation
Next Topic:building the xtext project with the maven build with other java projects
Goto Forum:
  


Current Time: Tue Mar 19 08:42:18 GMT 2024

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

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

Back to the top