Optional values in rules [message #636796] |
Tue, 02 November 2010 19:44 |
No real name 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 |
|
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 |
Henrik Lindberg 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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02820 seconds