Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » hidden whitespaces and formatting(formatting duplicates whitespaces when hidden() is used )
icon5.gif  hidden whitespaces and formatting [message #915517] Mon, 17 September 2012 12:55 Go to next message
Christoph Caks is currently offline Christoph CaksFriend
Messages: 3
Registered: July 2009
Junior Member
Hi,

i'm trying to add formatting to my grammer and stumbled upon the following issue:

when a rule does not hide whitespaces "Fuu hidden():" the formatter autmatically duplicates the whitespaces within the rule.

here is a simple example:

the grammer
grammar example.WSFun with org.eclipse.xtext.common.Terminals

generate wSFun "<url stripped, because the forum won't allow links>"

Model:
	lines+=(WSLine|NoWSLine)+
;

WSLine returns Line:
	{WSLine} 'ws' 'A' 'B' ';'
;

NoWSLine returns Line hidden():
	{NoWSLine} 'nows' WS+ 'A' WS+ 'B' WS* ';'
;

the formatter:
protected void configureFormatting(FormattingConfig c) {
  for (Keyword k : getGrammarAccess().findKeywords(";")) {
    c.setLinewrap().after(k);
    c.setNoSpace().before(k);
  }
}


formatting the WSLine works perfectly fine, but formatting the NoWSLine leads to the issue.

before calling format:
ws A B;nows A B;


after the first call to format:
ws A B;
nows   A   B;


after the second call to format:
ws A B;
nows     A     B;


i used
Xtext SDK 2.3.0.v201206120633 org.eclipse.xtext.sdk.feature.group Eclipse Modeling Project


is there a way to work around this?
I need the whitespaces in my language, so using hidden(WS) is no solution for me :/

greetings Christoph

[Updated on: Mon, 17 September 2012 12:57]

Report message to a moderator

Re: hidden whitespaces and formatting [message #915567 is a reply to message #915517] Mon, 17 September 2012 14:45 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2500
Registered: July 2009
Senior Member
I know how I deal with this in the formatter used by Geppetto - but it
is a new/different formatter. There I make a distinction between
explicit and implied white space and allow the implementor to treat an
explicit whitespace as if it was implied. It is otherwise difficult to
handle non-breaking spaces that are part of the grammar.

Don't remember if a similar concepts is available in the old/current
formatter.

The formatter I wrote for cloudsmith / geppetto is generic, so if you do
not find another solution, you may want to try using it instead (it is
not a plug-and-play replacement though as rules are expressed a
different way).

Regards
- henrik

On 2012-17-09 14:55, Christoph Caks wrote:
> Hi,
>
> i'm trying to add formatting to my grammer and stumbled upon the
> following issue:
>
> when a rule does not hide whitespaces "Fuu hidden():" the formatter
> autmatically duplicates the whitespaces within the rule.
>
> here is a simple example:
>
> the grammer
>
> grammar example.WSFun with org.eclipse.xtext.common.Terminals
>
> generate wSFun "<url stripped, because the forum wont' allow links>"
>
> Model:
> lines+=(WSLine|NoWSLine)+
> ;
>
> WSLine returns Line:
> {WSLine} 'ws' 'A' 'B' ';'
> ;
>
> NoWSLine returns Line hidden():
> {NoWSLine} 'nows' WS+ 'A' WS+ 'B' WS* ';'
> ;
>
> the formatter:
>
> protected void configureFormatting(FormattingConfig c) {
> for (Keyword k : getGrammarAccess().findKeywords(";")) {
> c.setLinewrap().after(k);
> c.setNoSpace().before(k);
> }
> }
>
>
> formatting the WSLine works perfectly fine, but formatting the NoWSLine
> leads to the issue.
>
> before calling format:
> ws A B;nows A B;
>
> after the first call to format:
> ws A B;
> nows A B;
>
> after the second call to format:
> ws A B;
> nows A B;
>
> i used Xtext SDK 2.3.0.v201206120633
> org.eclipse.xtext.sdk.feature.group Eclipse Modeling Project
>
>
> is there a way to work around this?
> I need the whitespaces in my language, so using hidden(WS) is no
> solution for me :/
>
> greetings Christoph
Previous Topic:semantic quick fixes and commens
Next Topic:ECore Double attribute does not show its name in content assist editor
Goto Forum:
  


Current Time: Sun Nov 23 11:25:18 GMT 2014

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

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