Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Parse an absolut path
Parse an absolut path [message #1066941] Fri, 05 July 2013 08:22 Go to next message
kon f is currently offline kon fFriend
Messages: 152
Registered: March 2012
Senior Member
Hey,

I'm trying to parse an absolute path that starts with /. It seems to be pretty tricky then I actually thought:

Path:
	'/' VALUE_WITHOUT_SLASH (VALUE_WITH_SLASH)*;

terminal VALUE_WITHOUT_SLASH:
	(CHARACTER)+;

terminal VALUE_WITH_SLASH:
	(CHARACTER | '/')+;

terminal fragment CHARACTER:
	('a'..'z' | 'A'..'Z' | '_' | '0'..'9' | '\\' | '\\(' | '\\)' | '\\ ' | '\\@');


I need to make sure that Path starts with a / that is why I differ between the value with and without the slash. I also thought about:

Path:
	'/' VALUE_WITH_SLASH+;


But this would allow e.g. //. How to I specify the following rule ('/' CHARACTER+)+.

Thank you.

Kon
Re: Parse an absolut path [message #1066972 is a reply to message #1066941] Fri, 05 July 2013 09:57 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

as a general pattern, you might look at the qualified name definition. Don't mess with terminals if you don't really have to. You can always implement validation (or value conversion) in order to make sure that the path has the correct syntax

Path: "/" ID ("/" ID)*;

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: Parse an absolut path [message #1067433 is a reply to message #1066972] Mon, 08 July 2013 16:20 Go to previous message
kon f is currently offline kon fFriend
Messages: 152
Registered: March 2012
Senior Member
Hey Alexander,

thank you! I also added hidden() to omit white spaces between the / and the ID parse rule (that are inherited from Terminals.xtext).

Path hidden(): 
       "/" ID ("/" ID)*;


Thank you.

Kon
Previous Topic:Avoid expensive scope calculation
Next Topic:XText rejects user defined hidden terminal rules
Goto Forum:
  


Current Time: Fri Apr 26 02:42:21 GMT 2024

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

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

Back to the top