Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cannot use literal in following ID terminal rule
Cannot use literal in following ID terminal rule [message #1067340] Mon, 08 July 2013 11:10 Go to next message
kon f is currently offline kon fFriend
Messages: 152
Registered: March 2012
Senior Member
Hey,

I encountered some parsing behavior that I do not understand. I cannot use some fixed literals in the following ID terminal rule. It can be visualized by the Hello World example:

Greeting:
	'Hello' name=ID '!';


also if I use Hello for the ID rule:

Hello Hello !


I get the error message: mismatched input 'Hello' expecting RULE_ID (the second Hello is marked)

Hello is a valid content for ID but it is still marked. How do I adjust the grammar the right way?

Thank you!

Kon
Re: Cannot use literal in following ID terminal rule [message #1067344 is a reply to message #1067340] Mon, 08 July 2013 11:22 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

Hello is not a "valid" content for ID, as it is a keyword. Terminals may overlap and only one definition wins. If you want Hello to be a valid id you have to introduce a datatype rule

MyId: ID|'Hello';

and use that instead of ID for id features.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Cannot use literal in following ID terminal rule [message #1067348 is a reply to message #1067344] Mon, 08 July 2013 11:41 Go to previous messageGo to next message
kon f is currently offline kon fFriend
Messages: 152
Registered: March 2012
Senior Member
Thank you Alex, that worked! Just the highlighting in the editor seems a bit strange Wink
Re: Cannot use literal in following ID terminal rule [message #1067356 is a reply to message #1067348] Mon, 08 July 2013 11:55 Go to previous messageGo to next message
Claudio Heeg is currently offline Claudio HeegFriend
Messages: 75
Registered: April 2013
Member
kon f wrote on Mon, 08 July 2013 13:41
Thank you Alex, that worked! Just the highlighting in the editor seems a bit strange Wink

Keeping that issue in check gets especially difficult on case-insensitive grammars with lots of keywords.
Don't see how things could work otherwise, though, unless Lexing would be altered massively.
Or case-insentivity could be specified for only certain keywords (length>2 or so) - it might only be slightly related to the topic, but could such a thing be possible?

[Updated on: Mon, 08 July 2013 12:04]

Report message to a moderator

Re: Cannot use literal in following ID terminal rule [message #1067358 is a reply to message #1067348] Mon, 08 July 2013 12:04 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
well, a keyword is a keyword (try naming a class class in Java). You can escape IDs

Hello ^Hello!

But of course this works only, if you have control over the language, i.e. you are not forced to make it work without escaping.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Cannot use literal in following ID terminal rule [message #1067360 is a reply to message #1067358] Mon, 08 July 2013 12:07 Go to previous messageGo to next message
Claudio Heeg is currently offline Claudio HeegFriend
Messages: 75
Registered: April 2013
Member
I realise - sadly I don't have that control. Easy example could be SQL - we define a PRIMARY KEY and a table has an attribute called .key.
And selective case-insensitivity (see my edit above) couldn't be implemented easily, I'd reckon?

One would likely have to put that insensitivity into the grammar manually, by having ('SELECT'|'select')-keywords, I suppose..
Re: Cannot use literal in following ID terminal rule [message #1096243 is a reply to message #1067360] Wed, 28 August 2013 06:03 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Is there other way to make xtext accept the static grammar keywords as part of ID?
Re: Cannot use literal in following ID terminal rule [message #1096305 is a reply to message #1096243] Wed, 28 August 2013 08:02 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the only way besides escaping is to introduce a datatype rule:

MyID: ID | "keyword"; and use that one instead of ID


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to get scope for jvm type or pojo
Next Topic:Generate non-Java code from the Ecore model of the grammar
Goto Forum:
  


Current Time: Thu Apr 25 00:08:53 GMT 2024

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

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

Back to the top