Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem in parsing whitespace sensitive DSL
Problem in parsing whitespace sensitive DSL [message #842518] Thu, 12 April 2012 11:23 Go to next message
Mikko Korpela is currently offline Mikko KorpelaFriend
Messages: 9
Registered: April 2012
Junior Member
Hi,

I'm having problem that the parser for some reason tries to match wrong grammar element in wrong place. Could someone explain a little bit what I'm doing wrong here?

Here is my (simplified) grammar:
grammar org.robotframework.text.Space

import 'ecora url .. can not post as I have less then 25 posted messages' as ecore

generate space "yet another url"

Model: 
	'*'+ ' Test Cases ' '*'+
	(NL tests+=TestCase)+;

TestCase:
	name=RobotText
	(NL SEPARATOR steps+=RobotStep)+;

RobotStep:
    keyword=RobotText (SEPARATOR values+=RobotText)*;	

RobotText: TEXT (' ' TEXT)*;

terminal NL: ('\r'|'\n')+;

terminal TEXT: ('a'..'z'|'A'..'Z')+;

terminal SEPARATOR: ' '' '+;


My DSL file:
* Test Cases *
Fooo
   blaah blaah   Blaah T    Blaah
   foo    bar   zoo



This should parse (if doing what I want) "Blaah T" as a RobotText element.
Unfortunately it for some reason tries to match " T " to " Test Cases " ... and doesn't think that this file is valid. Does someone know why does this happen and how could I resolve this issue?

(Two or more spaces is a separator between elements that can contain spaces in the DSL)

Kind Regards,
Mikko Korpela
Re: Problem in parsing whitespace sensitive DSL [message #842654 is a reply to message #842518] Thu, 12 April 2012 13:53 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Rather than '*'+ ' Test Cases ' '*'+ where you have keywords containing (even leading!?) white spaces write something like

'*'+ ' ' 'Test' ' ' 'Cases' ' ' '*'+

The problem is that the lexer is greedy. It tries to make tokens as long as possible seeing " T" it sees that there is a keyword with that prefix and hence tries to match that (as there is no alternative).

Alex
Re: Problem in parsing whitespace sensitive DSL [message #843145 is a reply to message #842654] Thu, 12 April 2012 20:08 Go to previous messageGo to next message
Mikko Korpela is currently offline Mikko KorpelaFriend
Messages: 9
Registered: April 2012
Junior Member
Thanks!

You really helped me in understanding what was going on - I had no clue about the logic behind this problem.

But I have another related question:
I really need to be able to use the whole word "Test" (and also almost everything else) in a TestCase name and also in RobotStep values and keyword..
So how can I achieve this?

Correct me if I'm wrong:
As the lexer now matches the keyword "Test" it will not match to terminal TEXT --> and it will not be a valid in a RobotText.

Kind Regards,
Mikko Korpela
Re: Problem in parsing whitespace sensitive DSL [message #843149 is a reply to message #843145] Thu, 12 April 2012 20:13 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

yes if you want to use it anyway you have to introduce a datatype rule


TEXTOrTest : "Test" | TEXT;

and use this Datatype rule in the places you want to allow Test as well


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Creating common interface
Next Topic:How can I check feature assignment is ok?
Goto Forum:
  


Current Time: Thu Mar 28 20:03:55 GMT 2024

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

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

Back to the top