|
Re: [Xtext] Format Converter for Enums [message #1710658 is a reply to message #1710570] |
Thu, 08 October 2015 08:58 |
Hauke Fuhrmann Messages: 30 Registered: January 2015 |
Member |
|
|
Am 07.10.2015 17:10, schrieb Hauke Fuhrmann:
> I have a simple legacy language for key/value Pairs, where all values
> are written in double quotes, independent of their type.
>
> E.g.
>
> Hallo="Hallo"
> Number="123"
> Direction="Left"
>
> For an integer I wrote a simple value converter that strips the quotes
> or adds them when serializing.
>
> What would be the approach for enums?
> My first approach is to define a Literal with double quotes, which is
> quite ugly for further processing of EObjects but works for
> serialization and parsing.
>
> enum Direction:
> Left='"Left"' | Right='"Right"'
> ;
>
> How to do it right? Can it be done by a value converter? How would it
> look like? Can it be a generic converter for all kinds of enums?
I also tried the straight-forward approach to define the quotes in the
grammar, but it does not work...
Entry:
'{' number=STRINGINT ',' '\"' direction=Direction '\"' '}'
;
No matter whether I use the escaping '\' character or not, I always get
parsing errors like
{ "1" , "Left" } gives: mismatched input '"Left"' expecting '"'
So I assumed "Left" might be a problem due to the quotes without any
whitespace, so the parser has a problem. However:
{ "1" , " Left " } gives: mismatched input '" Left "' expecting '"'
Even with whitespace this cannot be parsed. Why not?
Cheers,
Hauke
|
|
|
|
Powered by
FUDForum. Page generated in 0.03332 seconds