Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Optional values in rules
Optional values in rules [message #636796] Tue, 02 November 2010 19:44 Go to next message
No real name is currently offline No real nameFriend
Messages: 101
Registered: August 2010
Senior Member
Say I have a rule like this:

enum ExitPorts returns HLMExitPorts : ERROR='ERROR' | PASS='PASS' | FAIL='FAIL' ;
Exit : ('exit' | 'Exit') '(' port=ExitPorts (',' bin=INT)? ')' ';' ;


This will generate an API with getBin(), getPort(), setBin(), setPort(). However, since the bin is optional, if it is not defined (i.e., user types exit(PASS) ) how can I determine in the metamodel if the user specified a bin value. For non-primitive datatypes, one can easy check if the value is null, but since bin returns an int, how do I determine if it was specified or not? Thanks.

[Updated on: Tue, 02 November 2010 19:47]

Report message to a moderator

Re: Optional values in rules [message #636799 is a reply to message #636796] Tue, 02 November 2010 20:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the default value is 0 so you have no chance to distinguish this from a set 0. but you have following possibility:

- change the default value using prostprocessing the generated ecore (e.g. to -1)
- change the grammar to something like
Model:
	name=ID bin=BinContainer?;
	
BinContainer: value=INT;


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Optional values in rules [message #636800 is a reply to message #636796] Tue, 02 November 2010 20:15 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You need an additional boolean flag triggered by the precense of some
other marker, in your example, that could be the ',' before the INT.

Exit : ('exit' | 'Exit') '(' port=ExitPorts (binSet?= ',' bin=INT)? ')'
';' ;

Or change the INT from 'int' to 'Integer' so you can use null.

- henrik

On 11/2/10 8:44 PM, pgbackup@yahoo.com wrote:
> Say I have a rule like this:
>
>
> enum ExitPorts returns HLMExitPorts : ERROR='ERROR' | PASS='PASS' |
> FAIL='FAIL' ;
> Exit : ('exit' | 'Exit') '(' port=ExitPorts (',' bin=INT)? ')' ';' ;
>
>
> This will generate an API with getBin(), getPort(), setBin(), setPort().
> However, since the bin is optional, if it is not defined (i.e., user
> types exit(PASS) ) how can I determine in the metamodel if the user
> specified a bin value. For non-primitive datatypes, one can easy check
> if the value is null, but since bin returns an integer, how do I
> determine if it was specified or not? Thanks.
Re: Optional values in rules [message #636801 is a reply to message #636800] Tue, 02 November 2010 20:20 Go to previous message
No real name is currently offline No real nameFriend
Messages: 101
Registered: August 2010
Senior Member
Hi,

Thank you both for the response. I will try changing the int -> Integer in the terminal INT rule. I don't want to introduce another level of indirection with the bin=BinContainer.

Thanks again.
Previous Topic:How to reduce the structure of this....
Next Topic:Importing in a grammar an external metamodel depending on another metamodel
Goto Forum:
  


Current Time: Thu Apr 25 04:28:17 GMT 2024

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

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

Back to the top