XText Grammer for String assignment [message #62962] |
Fri, 24 July 2009 05:03  |
Eclipse User |
|
|
|
Hi,
I have a requirement to get the below mentioned assignment operation
pass with xtext grammer
variable1 = This is the variable Value
variable2 = ?
variable3 = 12
I could not figure out a way to get the String assignment as a value. I
used STRING as well as "string" in the type. But none worked as is.
Model :
(variables += Variable)*;
Variable returns as Variable :
name = ID '=' value=(STRING | INT);
This doesnot work. Any help?
|
|
|
|
|
|
|
Re: XText Grammer for String assignment [message #62976 is a reply to message #62972] |
Fri, 24 July 2009 07:36   |
Eclipse User |
|
|
|
Hi Michael,
you are right, it is not LL(1) but LL(*). This should not expose a
performance problem in this case. However, if you want to stick with
LL(1), I'ld prefer something like:
Value:
IntValue | StringValue;
IntValue:
val=INT;
StringValue:
val=STRING;
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 24.07.2009 12:01 Uhr, schrieb Michael Burkhardt:
> Hi,
>
> > Model:
> > variables += Variable *;
> >
> > Variable:
> > StringVariable | IntVariable;
> >
> > StringVariable:
> > name=ID '=' strValue=STRING;
> >
> > IntVariable:
> > name=ID '=' intValue=INT;
>
> I think, this is not LL(1).
>
> "Too many cooks spoil the broth." I do prefer something like this:
>
> Model:
> assigns += Assign* ;
>
> Variable: name = ID;
>
> Assign:
> variable = Variable '=' value = Value ';';
>
> Value: INT | STRING | ... ;
>
> terminal INT returns ecore::EINT : ... ;
> terminal STRING : ....;
>
> === end ___
>
>
>
> Ciao, Micha
>
>
> --- Original-Nachricht ---
> Absender: Sebastian Zarnekow
> Datum: 24.07.2009 11:38
>> Hi Idicula,
>>
>> which version of Xtext do you use? There have been changes from 0.7.0
>> to 0.7.1 for this usecase. However, since STRING and INT do not have a
>> common supertype, I do not know what you try to achieve. What's the
>> type that you expect for the attribtue Variable.value?
>>
>> If you are on 0.7.0, you may try the following workaround:
>>
>> Variable:
>> name=ID '=' (strValue=STRING | intValue=INT);
>>
>> I would prefer a cleaner solution and use:
>>
>> Model:
>> variables += Variable *;
>>
>> Variable:
>> StringVariable | IntVariable;
>>
>> StringVariable:
>> name=ID '=' strValue=STRING;
>>
>> IntVariable:
>> name=ID '=' intValue=INT;
>>
>> Regars,
>> Sebastian
>>
|
|
|
|
|
|
|
Re: XText Grammer for String assignment [message #63105 is a reply to message #63092] |
Mon, 27 July 2009 06:29  |
Eclipse User |
|
|
|
Hi Idicula,
I don't know your usecase but it seems as if regular expressions may be
a good match. The only way that comes to my mind and will match your rhs
of an assignment without ambiguity is a terminal rule that starts with
an assignment operator '=' and consumes everthing until the end of the line.
Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 27.07.2009 12:12 Uhr, schrieb Idicula:
> Hi Sebastian,
>
> The value can contain any character ended by a new line. This would mean
> all of the below are valid
>
> variable1 = Hello World!
> variable2 = hhhjjj + jhjhjsad _ kkh ~@;
>
>
> stringValue - anything till the end of line after the equals.
>
> regards
> Binu K Idicula
>
|
|
|
Powered by
FUDForum. Page generated in 0.05502 seconds