Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Boolean NOT assignment?
Boolean NOT assignment? [message #62932] Thu, 23 July 2009 11:10 Go to next message
Eclipse UserFriend
In Xtext I can write a rule as follows:

m property ?= "keyword"

which assigns true to the property of the keyword is there.
This work only for properties where the default is false.
I have properties that have true as their default value.
Can I do something like

property != "keyword"

to assign false to the property whenever the keyword is there?

Jos
Re: Boolean NOT assignment? [message #62939 is a reply to message #62932] Thu, 23 July 2009 12:42 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jos,

I'm afraid this is currently not possible. A feature request is welcome :-)

A workaround is to override the IAstFactory#set(..) and assign false
instead of true for your specific feature on a specific class. You'ld
have to ensure that true is default though.

Thanks,
Sebastian

--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 23.07.2009 17:10 Uhr, schrieb Jos Warmer:
> In Xtext I can write a rule as follows:
>
> m property ?= "keyword"
>
> which assigns true to the property of the keyword is there.
> This work only for properties where the default is false.
> I have properties that have true as their default value.
> Can I do something like
>
> property != "keyword"
>
> to assign false to the property whenever the keyword is there?
>
> Jos
>
Re: Boolean NOT assignment? [message #62952 is a reply to message #62939] Fri, 24 July 2009 01:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jos,

Another workaround, as it's been done in the EcoreDsl example project,
is to define custom terminal rules (see rules at bottom in
http://tinyurl.com/nkvdmo) with a corresponding value converter
(http://tinyurl.com/m7uap7). So e.g.

Foo : property?=KEYWORD ;

terminal KEYWORD returns ecore::EBoolean : "keyword" ;

Regards,

--knut

Sebastian Zarnekow wrote:
> Hi Jos,
>
> I'm afraid this is currently not possible. A feature request is welcome :-)
>
> A workaround is to override the IAstFactory#set(..) and assign false
> instead of true for your specific feature on a specific class. You'ld
> have to ensure that true is default though.
>
> Thanks,
> Sebastian
>
Re: Boolean NOT assignment? [message #62978 is a reply to message #62952] Fri, 24 July 2009 07:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: oba.informatik.uni-kiel.de

Hi all,

I find this discussion interesting.
The first thing, I thought, would do was something like this:

terminal NOTKEYWORD: !'keyword';
Foo: property?=NOTKEYWORD;


But this doesn't even compile (due to (a) syntax error(s)). Can someone
say, what my mistake is?

Thanks

mN

Knut Wannheden wrote:



> Hi Jos,
>
> Another workaround, as it's been done in the EcoreDsl example project,
> is to define custom terminal rules (see rules at bottom in
> http://tinyurl.com/nkvdmo) with a corresponding value converter
> (http://tinyurl.com/m7uap7). So e.g.
>
> Foo : property?=KEYWORD ;
>
> terminal KEYWORD returns ecore::EBoolean : "keyword" ;
>
> Regards,
>
> --knut
>
> Sebastian Zarnekow wrote:
>> Hi Jos,
>>
>> I'm afraid this is currently not possible. A feature request is
>> welcome :-)
>>
>> A workaround is to override the IAstFactory#set(..) and assign false
>> instead of true for your specific feature on a specific class. You'ld
>> have to ensure that true is default though.
>>
>> Thanks,
>> Sebastian
>>
Re: Boolean NOT assignment? [message #62982 is a reply to message #62978] Fri, 24 July 2009 08:17 Go to previous messageGo to next message
Eclipse UserFriend
Hi myName,

if this is everything what can be found in your grammar, the syntax
errors occur because you have to start your grammar with a parser rule.

However, the negated token ! means, parser anything at this place but
not the string "keyword". It has no semantics for the assignemnt in the
rule "Foo".

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


Am 24.07.2009 13:47 Uhr, schrieb myName:
> Hi all,
>
> I find this discussion interesting.
> The first thing, I thought, would do was something like this:
>
> terminal NOTKEYWORD: !'keyword';
> Foo: property?=NOTKEYWORD;
>
>
> But this doesn't even compile (due to (a) syntax error(s)). Can someone
> say, what my mistake is?
>
> Thanks
>
> mN
>
> Knut Wannheden wrote:
>
>
>
>> Hi Jos,
>>
>> Another workaround, as it's been done in the EcoreDsl example project,
>> is to define custom terminal rules (see rules at bottom in
>> http://tinyurl.com/nkvdmo) with a corresponding value converter
>> (http://tinyurl.com/m7uap7). So e.g.
>>
>> Foo : property?=KEYWORD ;
>>
>> terminal KEYWORD returns ecore::EBoolean : "keyword" ;
>>
>> Regards,
>>
>> --knut
>>
>> Sebastian Zarnekow wrote:
>>> Hi Jos,
>>>
>>> I'm afraid this is currently not possible. A feature request is
>>> welcome :-)
>>>
>>> A workaround is to override the IAstFactory#set(..) and assign false
>>> instead of true for your specific feature on a specific class. You'ld
>>> have to ensure that true is default though.
>>>
>>> Thanks,
>>> Sebastian
>>>
Re: Boolean NOT assignment? [message #62984 is a reply to message #62982] Fri, 24 July 2009 09:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: oba.informatik.uni-kiel.de

Oh, I misunderstood two things then:

Sebastian Zarnekow wrote:
> Hi myName,
>
> if this is everything what can be found in your grammar, the syntax
> errors occur because you have to start your grammar with a parser rule.

So, Xtext takes the first rule in the grammar as the starting rule and
does _not_ go and search for the first _parser_ rule. Thanks for making
this clear to me.

> However, the negated token ! means, parser anything at this place but
> not the string "keyword". It has no semantics for the assignemnt in the
> rule "Foo".
So, the terminal rule:

terminal NOTKEYWORD: !'keyword';

would return an EString containing everything, I have written except the
word "keyword". So it would cause, that the rest of the file stays
untouched by the parser.

> Regards,
> Sebastian
Thanks a lot!
Re: Boolean NOT assignment? [message #62991 is a reply to message #62984] Fri, 24 July 2009 09:46 Go to previous messageGo to next message
Eclipse UserFriend
Hi myName,

please see below.
Am 24.07.2009 15:09 Uhr, schrieb myName:
> Oh, I misunderstood two things then:
>
> Sebastian Zarnekow wrote:
>> Hi myName,
>>
>> if this is everything what can be found in your grammar, the syntax
>> errors occur because you have to start your grammar with a parser rule.
>
> So, Xtext takes the first rule in the grammar as the starting rule and
> does _not_ go and search for the first _parser_ rule. Thanks for making
> this clear to me.

Exactly.

>
>> However, the negated token ! means, parser anything at this place but
>> not the string "keyword". It has no semantics for the assignemnt in the
>> rule "Foo".
> So, the terminal rule:
>
> terminal NOTKEYWORD: !'keyword';
>
> would return an EString containing everything, I have written except the
> word "keyword". So it would cause, that the rest of the file stays
> untouched by the parser.

This rule would consume exactly one character if only if the following
sequence of characters is not "keyword".

>
>> Regards,
>> Sebastian
> Thanks a lot!

Regards,
Sebastian

--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Boolean NOT assignment? [message #62993 is a reply to message #62991] Fri, 24 July 2009 09:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: oba.informatik.uni-kiel.de

>> So, the terminal rule:
>>
>> terminal NOTKEYWORD: !'keyword';
>>
>> would return an EString containing everything, I have written except the
>> word "keyword". So it would cause, that the rest of the file stays
>> untouched by the parser.
>
> This rule would consume exactly one character if only if the following
> sequence of characters is not "keyword".
I see. So it is like the ANY_OTHER terminal, which does not "see" the
word 'keyword'. That is why, I got warnings about "unreachable
RULE_ANY_OTHER"...because I was leaving ANY_OTHER in shadow.

Thanks again & sorry for understanding so slowly :)

mN
Re: Boolean NOT assignment? [message #538392 is a reply to message #62932] Mon, 07 June 2010 10:35 Go to previous message
Eclipse UserFriend
Jos Warmer wrote on Thu, 23 July 2009 11:10
In Xtext I can write a rule as follows:

m property ?= "keyword"

which assigns true to the property of the keyword is there.
This work only for properties where the default is false.
I have properties that have true as their default value.
Can I do something like

property != "keyword"

to assign false to the property whenever the keyword is there?

Jos
Hi Jos,

I figure you have found a solution by now Smile
I'm posting this reply in case somebody else has this issue.

I faced a similar problem today:
VariableDeclaration: type=Type name=ID (('=' | ':=') value=Expression)?;

I wanted a property "assignable" to be true if the variable was declared with an initial value with ':=', or declared with no initial value (I did not design the language).

Well I found a simple but effective solution, use a property that is the opposite of the property you wanted (opposite in the "logic" sense, not EMF).
In this case, the rule becomes:
VariableDeclaration: type=Type name=ID ((constant?='=' | ':=') value=Expression)?;

Hope that helps whoever might need the same trick Smile

Matthieu
Previous Topic:Deactivate backslash as escape character?
Next Topic:Help with running the generator from an RCP
Goto Forum:
  


Current Time: Tue Jul 08 06:04:39 EDT 2025

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

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

Back to the top