Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Vanishing whitespaces due to optional keyword
Vanishing whitespaces due to optional keyword [message #643586] Tue, 07 December 2010 10:05 Go to next message
Eclipse UserFriend
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 13:48 Go to previous messageGo to next message
Eclipse UserFriend
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 15:01 Go to previous message
Eclipse UserFriend
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 Jul 01 23:32:02 EDT 2025

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

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

Back to the top