Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to deal with keywords that are not really reserved?
How to deal with keywords that are not really reserved? [message #675589] Tue, 31 May 2011 23:32 Go to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Greetings,

In my grammar, I specified the following definitions:

Message:
  'message' name=ID '{'
  elements+=MessageElement*
  ('extensions' extensionsFrom=INT 'to' (extensionsTo=INT | 'max') ';')?
  '}'(';')?;

MessageElement:
  Type | Property | Group | ExtendMessage | Option;

Property:
  modifier=Modifier type=AbstractTypeReference name=ID '=' index=INT ';';


According to this grammar, "message" a keyword. It turns out that the language allows 'message' to be a valid name for names of properties!!! so I can also have a property like this:

optional string message = 2;


and right now, the editor is giving me a syntax error. Is there any way to specify that keywords can be used in other context?

Many thanks in advance,
-Alex
Re: How to deal with keywords that are not really reserved? [message #675627 is a reply to message #675589] Wed, 01 June 2011 03:58 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the standard way is escaping the keyword, i.e. writing ^message instead of message, when it is used as ID rather than as a keyword. "^" is dealt with by the the value converter for ID, i.e. it is removed when parsing and added when serialising.

If you don't want the escaping, things become more complicated:
You have to use a datatype rule

IdOrKeyword: ID|'message'|listOfAllOtherKeywordsAllowedAsID;

and use that rule wherever you would use ID (and want the keywords allowed). However, the keywords will be highlighted as such wherever they appear (even if used as id), so you would have to adapt semantic highlighting as well.

Alex
(no subject) [message #675643 is a reply to message #675627] Wed, 01 June 2011 04:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

And if there are some keywords not in listOfAllOtherKeywordsAllowedAsID,
you will still need to escape them which will require a custom
ValueConverterService.

Regards

Ed Willink

On 01/06/2011 04:58, Alexander Nittka wrote:
> Hi,
>
> the standard way is escaping the keyword, i.e. writing ^message
> instead of message, when it is used as ID rather than as a keyword.
> "^" is dealt with by the the value converter for ID, i.e. it is
> removed when parsing and added when serialising.
>
> If you don't want the escaping, things become more complicated:
> You have to use a datatype rule
>
> IdOrKeyword: ID|'message'|listOfAllOtherKeywordsAllowedAsID;
>
> and use that rule wherever you would use ID (and want the keywords
> allowed). However, the keywords will be highlighted as such wherever
> they appear (even if used as id), so you would have to adapt semantic
> highlighting as well.
>
> Alex
Re: (no subject) [message #685132 is a reply to message #675643] Thu, 16 June 2011 22:12 Go to previous message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
I ended up following Alex's suggestion. It was a little bit of work but it work as I wanted Smile

Cheers,
-Alex
Previous Topic:Launch xtend2 code generator
Next Topic:Adding "dynamic attibutes" to EObjects
Goto Forum:
  


Current Time: Tue Apr 23 16:39:56 GMT 2024

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

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

Back to the top