Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Conflicting keywords and ID rules
Conflicting keywords and ID rules [message #1119573] Sat, 28 September 2013 12:45 Go to next message
rohit ahuja is currently offline rohit ahuja
Messages: 24
Registered: February 2013
Junior Member
Hi All,

I am unable to use the keyword used in some rule, as the value of another,
For e.g.
Consider the below grammar

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Field:
'name' '=' name=ID ',' 'type' '=' type=ID ';'
;


Now if i try something like,
name = john , type = type;
we get error as mismatched input 'type' expecting RULE_ID, is there any way to allow this?


I saw that we can use the ^symbol, but i am looking for some other way if it exists.
name = john , type = ^type;

Any help would be great.

Thanks in Advance,
Rohit
Re: Conflicting keywords and ID rules [message #1119583 is a reply to message #1119573] Sat, 28 September 2013 13:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6145
Registered: July 2009
Senior Member
Hi introduce a datatype rule:

XID: ID | "type";

.....

And use that one instead Of ID

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Conflicting keywords and ID rules [message #1119584 is a reply to message #1119573] Sat, 28 September 2013 13:01 Go to previous messageGo to next message
Uli Merkel is currently offline Uli Merkel
Messages: 113
Registered: June 2013
Senior Member
there are keywords ans the XTEXT defaults for ID have a built-in way to solve the conflicht with the ^-prefix

I can't understand why you are looking for "some other ways"?

Accepting that keywords have to be keywords wherever they appear:
How do you want the solution to look like?

Or asked the other way: what's worng with the keyword=^keyword

if all you want is to use another character instead of the "^",
just have a look at the ID definitions and create your own MYID
(and adjust a couple of Java Rpoutines to handle the other character)
Re: Conflicting keywords and ID rules [message #1120026 is a reply to message #1119584] Sun, 29 September 2013 01:00 Go to previous messageGo to next message
rohit ahuja is currently offline rohit ahuja
Messages: 24
Registered: February 2013
Junior Member
Christian, Thanks for the reply, it works like a charm!!!

Merkel, i am looking for some other way, as the grammar that i am writing has some legacy cases wherein we need to support this, i understand that it is a keyword, and the ^ symbol is an ex excellent way, but there's no way i can edit the old legacy cases, so i just reproduced the same with a small sample above, and looked for some other workaround..

Re: Conflicting keywords and ID rules [message #1120090 is a reply to message #1120026] Sun, 29 September 2013 02:45 Go to previous message
Uli Merkel is currently offline Uli Merkel
Messages: 113
Registered: June 2013
Senior Member
ahuja, you have not answered my question:

what other workaround you are looking for?

As long as you can not answer this question, one can not help you.

It may be helpful to be more detailed about "the old legacy cases"
Previous Topic:[SOLVED] Error: Multiple markers at this line -Duplicate ...
Next Topic:Accessing files in other projects in xtext
Goto Forum:
  


Current Time: Fri Aug 01 18:35:20 EDT 2014

Powered by FUDForum. Page generated in 0.02251 seconds