Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Parameterized parser rule(Parameterized parser rule)
Parameterized parser rule [message #991177] Mon, 17 December 2012 15:39 Go to next message
Pawel Pogorzelski is currently offline Pawel PogorzelskiFriend
Messages: 26
Registered: July 2009
Junior Member
I have a following grammar snippet. It describes a list item. Please note that the DSL is whitespace sensitive and TextLine ends with a line delimiter and may not contain '\t'.

UnorderedItem:
	'• ' TextLine
	('\t' TextLine)*;


What I'm not able to do is defining nesting. One approach is to define a second level list as shown below (pseudocode for simplicity):

UnorderedItem0:
	'• ' TextLine
	('\t' TextLine)*
	UnorderedItem1*;

	UnorderedItem1:
	'\t• ' TextLine
	('\t\t' TextLine)*
	UnorderedItem2*;

	UnorderedItem2:
	'\t\t• ' TextLine
	('\t\t\t' TextLine)*
	UnorderedItem3*;


But this is not scalable. What I need is actually something like a parametrized parser rule:

UnorderedItem (prefix):
	prefix '• ' TextLine
	(prefix '\t' TextLine)*
	UnorderedItem(prefix + '\t')*;


Is there anything like it in xtext? Or maybe there's some other solution that fits better.

Cheers,
Pawel
Re: Parameterized parser rule [message #991298 is a reply to message #991177] Tue, 18 December 2012 12:18 Go to previous messageGo to next message
Andreas Brieg is currently offline Andreas BriegFriend
Messages: 48
Registered: November 2012
Member
As far as I know, there aren't parameterized rules. But you don't really need them. Just have a look at arithmetic expressions:
(((3 + 1) + 2) + 4)

The rules for that normally look like (ignoring parenthesis, pseudo code):
expr := number|expr ' + ' number
number := <just a number>

So you are basically building a tree structure and the depth in the tree is the level of nesting. In your case the depth in the tree is the indentation of your item.
Re: Parameterized parser rule [message #991313 is a reply to message #991177] Tue, 18 December 2012 13:32 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1162
Registered: July 2009
Senior Member
Hi,

you'll have to bind your own lexer implementation that creates indent and dedent tokens for creating the block structure. There are some blog posts and examples on the web.

Search for "xtext lexer indent" or "xtext whitespace".

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: Parameterized parser rule [message #991327 is a reply to message #991177] Tue, 18 December 2012 14:26 Go to previous message
Pawel Pogorzelski is currently offline Pawel PogorzelskiFriend
Messages: 26
Registered: July 2009
Junior Member
Guys, thanks for looking into this. I'll look into hooking up a custom lexer.
Previous Topic:How to get collection type parameter (generics) from JvmTypeReference?
Next Topic:Showing and hiding grammar feature in textual representation
Goto Forum:
  


Current Time: Sat Dec 20 03:13:45 GMT 2014

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

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