Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Grammar(Need a variable to have more than one data type)
Xtext Grammar [message #1015528] Fri, 01 March 2013 06:12 Go to next message
rohit ahuja is currently offline rohit ahuja
Messages: 25
Registered: February 2013
Junior Member
Hi All,

I am new to Xtext and writing a DSL.

I have something like

'Case:' CaseName = ID

Now the variable CaseName can contain simple only Integer Values i.e any combination of 0-9, or only Alphabets i.e. any combination of the A-Z or a-z, or a mixed case.
If i keep it as above, xtext doesn't allow me to have a single int value,

say 'Case: 0'

I tried with the below method
'Case:' CaseName = ID|INT -- but it doesn't work for obvious reasons.

If i try to create another terminal like (0-9|a-z|A-Z)*, it starts interfering with other rules in the grammar.

I think there must be some other way, can anyone help me with this?

In general, can any variable be assigned to two types?

Thanks,
Rohit Ahuja

Re: Xtext Grammar [message #1015530 is a reply to message #1015528] Fri, 01 March 2013 06:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6298
Registered: July 2009
Senior Member
Hi

Did you try a data type rule?

IDORINT: ID|INT;

.... Casename=IDORINT

--
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: Xtext Grammar [message #1015561 is a reply to message #1015530] Fri, 01 March 2013 09:04 Go to previous messageGo to next message
rohit ahuja is currently offline rohit ahuja
Messages: 25
Registered: February 2013
Junior Member
Hi Christian,
Thanks for the reply.

If i try creating something like,
terminal IDORINT: ID|INT;

the other places where i have field=ID, starts causing problems, i also get a error message in the console as below,
The token definitions can never be matched because prior tokens match the same input: RULE_ID,RULE_INT

Am i missing something here?


Thanks,
Rohit Ahuja
Re: Xtext Grammar [message #1015564 is a reply to message #1015561] Fri, 01 March 2013 09:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6298
Registered: July 2009
Senior Member
Hi,

this is a question of lexing and parsing

lexing is done first and is context free.
parsing in done on the lexical token stream and context sensitive.

terminal IDORINT: ID|INT;
is a lexer rule

IDORINT: ID|INT;
is a parser rule (datatype rule)

so use the datatype rule and not the terminal rule
Re: Xtext Grammar [message #1015573 is a reply to message #1015564] Fri, 01 March 2013 09:15 Go to previous message
rohit ahuja is currently offline rohit ahuja
Messages: 25
Registered: February 2013
Junior Member
Thanks a lot Christian!!!, this works like a charm...
Previous Topic:Xtext Grannar
Next Topic:Best organisation to manipulate textual and graphical representation of a model
Goto Forum:
  


Current Time: Wed Sep 17 03:51:34 GMT 2014

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

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