Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Parameterized parser rule(Parameterized parser rule)
Parameterized parser rule [message #991177] Mon, 17 December 2012 10:39 Go to next message
Eclipse UserFriend
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 07:18 Go to previous messageGo to next message
Eclipse UserFriend
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 08:32 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Parameterized parser rule [message #991327 is a reply to message #991177] Tue, 18 December 2012 09:26 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 10:49:34 EDT 2025

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

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

Back to the top