Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [SOLVED] Serializer Enum
[SOLVED] Serializer Enum [message #1411842] Sun, 24 August 2014 15:57 Go to next message
Jonas Heinisch is currently offline Jonas HeinischFriend
Messages: 12
Registered: June 2014
Location: Germany
Junior Member
Hi!

I've got a problem regarding the usage of enums.

Here's a part of my used grammar:

// boolAndExpr -> boolOrExpr (andoperation boolOrExpr)*
boolAndExpr returns BooleanExpression:
	boolOrExpr ({BooleanOperatorExpression.left=current} operation=andoperation right=boolOrExpr)*
;
	
// andoperation -> AND
enum andoperation returns BooleanOperations:
	AND
;

// boolOrExpr -> compareExpr (oroperations compareExpr)*
boolOrExpr returns BooleanExpression:
	compareExpr ({BooleanOperatorExpression.left=current} operation=oroperations right=compareExpr)*
;

// oroperations -> OR|XOR
enum oroperations returns BooleanOperations:
	OR | XOR
;


Parsing works pretty good, but when it comes to serializing something containing an AND this Exception comes up:

The value 'AND' is invalid for enum oroperations
Valid values are: OR, XOR
Semantic Object: BooleanOperatorExpression


I think it could be easily changed by changing the model and split up AND- and OR-Operations into two classes. But as it is a running system to which I only add the Xtext-things, I do not want to change the model that much... So any idea how to solve this?

Thanks in advance for any hints!
Jonas

[Updated on: Sun, 24 August 2014 18:18]

Report message to a moderator

Re: Serializer Enum [message #1411854 is a reply to message #1411842] Sun, 24 August 2014 16:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
i thinks the problem is how you missuse the enum


its actual declaration should be

enum BooleanOperations:
AND | OR | XOR
;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializer Enum [message #1411859 is a reply to message #1411854] Sun, 24 August 2014 17:08 Go to previous messageGo to next message
Jonas Heinisch is currently offline Jonas HeinischFriend
Messages: 12
Registered: June 2014
Location: Germany
Junior Member
Hi!

Thanks for the quick response!

I actually know how to do that, but as you may have noticed the Enum is split into two parts ([X]OR and AND) and AND should be only available in the boolAndExpr-rule while the others should be only available in the boolOrExpr-rule. This is to preserve precedence to be able to express things like "x OR y AND z OR p AND f" without using paranthesis or something...

Best regards
Jonas
Re: Serializer Enum [message #1411870 is a reply to message #1411859] Sun, 24 August 2014 17:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
the question is what happens if you write a third rule that is never called but has all options

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon14.gif  Re: Serializer Enum [message #1411877 is a reply to message #1411870] Sun, 24 August 2014 18:18 Go to previous message
Jonas Heinisch is currently offline Jonas HeinischFriend
Messages: 12
Registered: June 2014
Location: Germany
Junior Member
Hi!

Thanks a lot!

This works great:
...

//BooleanExpression -> boolOrExpr (BooleanOperations boolOrExpr)*
// Note: This is a workaround for the serializer to work with AND-Operations!
BooleanExpression:
	boolOrExpr ({BooleanOperatorExpression.left=current} operation=BooleanOperations right=boolOrExpr)*
;

//BooleanOperations -> AND | OR | XOR
enum BooleanOperations:
	AND | OR | XOR
;

// boolAndExpr -> boolOrExpr (andoperation boolOrExpr)*
boolAndExpr returns BooleanExpression:
	boolOrExpr ({BooleanOperatorExpression.left=current} operation=andoperation right=boolOrExpr)*
;
	
// andoperation -> AND
enum andoperation returns BooleanOperations:
	AND
;

// boolOrExpr -> compareExpr (oroperations compareExpr)*
boolOrExpr returns BooleanExpression:
	compareExpr ({BooleanOperatorExpression.left=current} operation=oroperations right=compareExpr)*
;

// oroperations -> OR|XOR
enum oroperations returns BooleanOperations:
	OR | XOR
;

...


Best regards
Jonas

[Updated on: Sun, 24 August 2014 18:19]

Report message to a moderator

Previous Topic:[Xbase] Scripting Language
Next Topic:Xtext and generating JPA annotations
Goto Forum:
  


Current Time: Thu Mar 28 12:34:30 GMT 2024

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

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

Back to the top