Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Vanishing whitespaces due to optional keyword
Vanishing whitespaces due to optional keyword [message #643586] Tue, 07 December 2010 15:05 Go to next message
Ulf Rueegg is currently offline Ulf RueeggFriend
Messages: 26
Registered: February 2010
Junior Member
Hi guys,

I'm currently facing a rather strange behaviour which I cannot explain.

Consider the following grammar:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Module:
	"module" name=ID ":" body=ModuleBody "end" "module";
	
ModuleBody:
	name=ID ';'?
;


and this input:
module m1:
foo;
end module


Parsing works fine and as expected, but calling save on the resource results in the following
module m1:
fooend module


The semicolon is not there anymore as it is optional and the serializer cannot know if it was set before or not - so it's omitted. But why is there no whitespace between 'foo' and 'end'?

best regards
Re: Vanishing whitespaces due to optional keyword [message #643668 is a reply to message #643586] Tue, 07 December 2010 18:48 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Ulf,

you'll have to tell your formatter that the whitespace between both
tokens is mandatory.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 07.12.10 16:05, schrieb Ulf:
> Hi guys,
>
> I'm currently facing a rather strange behaviour which I cannot explain.
>
> Consider the following grammar:
>
>
> grammar org.xtext.example.mydsl.MyDsl with
> org.eclipse.xtext.common.Terminals
>
> generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
>
> Module:
> "module" name=ID ":" body=ModuleBody "end" "module";
>
> ModuleBody:
> name=ID ';'?
> ;
>
>
> and this input:
>
> module m1:
> foo;
> end module
>
>
> Parsing works fine and as expected, but calling save on the resource
> results in the following
>
> module m1:
> fooend module
>
>
> The semicolon is not there anymore as it is optional and the serializer
> cannot know if it was set before or not - so it's omitted. But why is
> there no whitespace between 'foo' and 'end'?
>
> best regards
>
Re: Vanishing whitespaces due to optional keyword [message #643679 is a reply to message #643586] Tue, 07 December 2010 20:01 Go to previous message
Ulf Rueegg is currently offline Ulf RueeggFriend
Messages: 26
Registered: February 2010
Junior Member
Hi Sebastian,

Thanks for the quick answer - I realized that the OneWhiteSpaceFormatter would solve the problem but was wondering why the serialzier omits whitespaces just for optional keywords.
Is it because the whitespace is connected to the semicolon and therefore omitted as well?
Or is there no particular reason?

Regards
Previous Topic:Dependencies of one grammar on another
Next Topic:Problems when using xtextEditor which in a MultiPageEditor
Goto Forum:
  


Current Time: Tue Sep 24 13:04:14 GMT 2024

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

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

Back to the top