Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Hidden whitespace causes parsing error
Hidden whitespace causes parsing error [message #629775] Wed, 29 September 2010 14:18 Go to next message
Jan-Patrick Osterloh is currently offline Jan-Patrick OsterlohFriend
Messages: 3
Registered: September 2010
Junior Member
Hi,

I have a problem with my grammar, and I don't know why. I constructed the following example, that has the same problem:
grammar org.xtext.example.mydsl.MyDsl hidden(WS)

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Model: {Model}
NL*
  (
    (greetings+=Greeting) NL
  )*
 ;
	
Greeting:
	'Hello' name=STRING '!' ;

terminal STRING : '\"' ('a'..'z'|'A'..'Z'|'.'|'_'|'#'|':'|'§'|'0'..'9'|'-')* '\"';
terminal WS     : (' '|'\t')*;
terminal NL     : ('\r'? '\n')+;


If I have the following text opened in the editor, a parsing error occours in the third line (mismatched input '\r\n' expecting EOF):
 
Hello "test"!
 
Hello "testa"!

Both lines before the Hello start with a blank and a newline. If I remove the blank in the third line, the error disappears. Unfortunatly I need the NL as part of my grammar, so I cannot add it to the hidden terminals.

Can someone explain why this happen, and how I can solve this problem?

Thanks in advance.
Jan-Patrick
Re: Hidden whitespace causes parsing error [message #629782 is a reply to message #629775] Wed, 29 September 2010 14:24 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 9/29/10 4:18 PM, schrieb Jan-Patrick Osterloh:
> Hi,
> I have a problem with my grammar, and I don't know why. I constructed
> the following example, that has the same problem:
> grammar org.xtext.example.mydsl.MyDsl hidden(WS)
>
> generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> Model: {Model}
> NL*
> (
> (greetings+=Greeting) NL
> )*
> ;
>
> Greeting:
> 'Hello' name=STRING '!' ;
>
> terminal STRING : '\"'
> ('a'..'z'|'A'..'Z'|'.'|'_'|'#'|':'|'§'|'0'..'9'|'-')* '\"';
> terminal WS : (' '|'\t')*;

(unrelated) You should change the quantifier in WS to '+'.

> terminal NL : ('\r'? '\n')+;
>
>
> If I have the following text opened in the editor, a parsing error
> occours in the third line (mismatched input '\r\n' expecting EOF):
>
> Hello "test"!
>
> Hello "testa"!
>
> Both lines before the Hello start with a blank and a newline. If I
> remove the blank in the third line, the error disappears.

NL only recognizes multiple newlines but not two new lines separated
with a blank.

Sven

--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
icon14.gif  Re: Hidden whitespace causes parsing error [message #629812 is a reply to message #629782] Wed, 29 September 2010 15:38 Go to previous message
Jan-Patrick Osterloh is currently offline Jan-Patrick OsterlohFriend
Messages: 3
Registered: September 2010
Junior Member
Thanks! That helped me to fix it.
Previous Topic:Implement ToBeBuiltComputer
Next Topic:import org.eclipse.jdt.core failing on Xtext 1.0.1
Goto Forum:
  


Current Time: Thu Apr 25 11:35:15 GMT 2024

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

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

Back to the top