Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [SOLVED] Serializer Enum
[SOLVED] Serializer Enum [message #1411842] Sun, 24 August 2014 11:57 Go to next message
Eclipse UserFriend
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 14:18] by Moderator

Re: Serializer Enum [message #1411854 is a reply to message #1411842] Sun, 24 August 2014 12:50 Go to previous messageGo to next message
Eclipse UserFriend
i thinks the problem is how you missuse the enum


its actual declaration should be

enum BooleanOperations:
AND | OR | XOR
;
Re: Serializer Enum [message #1411859 is a reply to message #1411854] Sun, 24 August 2014 13:08 Go to previous messageGo to next message
Eclipse UserFriend
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 13:46 Go to previous messageGo to next message
Eclipse UserFriend
the question is what happens if you write a third rule that is never called but has all options
icon14.gif  Re: Serializer Enum [message #1411877 is a reply to message #1411870] Sun, 24 August 2014 14:18 Go to previous message
Eclipse UserFriend
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 14:19] by Moderator

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


Current Time: Wed Jul 23 17:40:53 EDT 2025

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

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

Back to the top