Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ID and a more relaxed version living together
ID and a more relaxed version living together [message #1755879] Wed, 08 March 2017 20:52 Go to next message
Rodrigo Ruiz is currently offline Rodrigo RuizFriend
Messages: 28
Registered: March 2017
Junior Member
Hi i need to support a structure like this:
varname=nodeOne/node-2/node-3

at first i implemented it changing the definition for ID, just including the '-' in it, but since i also support math expressions, if you do this:

sum= node1-node2 (without space in the middle)
the parser will think node1-node2 is a single ID.

If i try to include a more relaxed version of ID, like SEGMENT to live along with ID then the parser can't distinguish between ID and SEGMENT, forcing me to put an ^ before my id, which is bad for my users.
Do you have any tip for situations like this?

this is my definition for SEGMENT and ID (the standard one):
terminal SEGMENT: ('a'..'z'|'A'..'Z'|'_') (  'a'..'z'|'A'..'Z'|'_'|'-'|'0'..'9')*;
@Override
terminal ID  		: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;

Thanks for your help!
Re: ID and a more relaxed version living together [message #1755880 is a reply to message #1755879] Wed, 08 March 2017 21:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 10789
Registered: July 2009
Senior Member
how do you know if x-y is a SEGEMENT or is ID-ID

if you can know it from place of occurence you could introduce a datatype rule

SEGMENT: ID ("-" (ID|INT))+;


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: ID and a more relaxed version living together [message #1756339 is a reply to message #1755880] Wed, 15 March 2017 14:36 Go to previous message
Rodrigo Ruiz is currently offline Rodrigo RuizFriend
Messages: 28
Registered: March 2017
Junior Member
Thank you Christian, i ended up introducing more elements to better distinguish between both rules.
But i implemented also your suggestion Smile
All the best!
Previous Topic:IAutoWrapFormatter with indent ignores newline under certain conditions
Next Topic:Input with multiple alternatives
Goto Forum:
  


Current Time: Mon Jun 26 14:10:49 GMT 2017

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

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