Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xbase2 - formatting line breaks
xbase2 - formatting line breaks [message #688035] Thu, 23 June 2011 18:27 Go to next message
Erik Nijkamp is currently offline Erik NijkampFriend
Messages: 3
Registered: June 2011
Junior Member
Hey folks,

I'm fighting with the xbase2 formatter.

This is what I currently have:

@SuppressWarnings("restriction")
public class FooScriptDslFormatter extends XbaseFormatter
{
    @Override
    protected void configureFormatting(FormattingConfig c)
    {
        // xbase
        FooScriptDslGrammarAccess f = (FooScriptDslGrammarAccess) getGrammarAccess();
        configure(c, f.getXbaseGrammarAccess());
    }
}


Unfortunately this does not trigger line breaks for XFeatureCalls:

a() b() c()


Should be transformed to:

a()
b()
c()


Note that we don't want to introduce semicolons. Hence I was not able to determine the correct element for the setLinewrap() invocation.

Do I have to dig deeper or can we play a simple trick here?

Thanks!
erik

Re: xbase2 - formatting line breaks [message #692622 is a reply to message #688035] Mon, 04 July 2011 20:59 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3107
Registered: July 2009
Senior Member
Hi Erik,

IIRC there is no linewrap configured for XFeatureCalls. There will be a
linewrap inside of XBlockExpressions for each expression. Is your list
of feature calls an XBlockExpression (which is acutally instantiated by
the ParserRule XBlockExpression from the XbaseGrammar)?

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

On 23.06.11 20:27, Erik Nijkamp wrote:
> Hey folks,
>
> I'm fighting with the xbase2 formatter.
>
> This is what I currently have:
>
>
> @SuppressWarnings("restriction")
> public class FooScriptDslFormatter extends XbaseFormatter
> {
> @Override
> protected void configureFormatting(FormattingConfig c)
> {
> // xbase
> FooScriptDslGrammarAccess f = (FooScriptDslGrammarAccess)
> getGrammarAccess();
> configure(c, f.getXbaseGrammarAccess());
> }
> }
>
>
> Unfortunately this does not trigger line breaks for XFeatureCalls:
>
>
> a() b() c()
>
>
> Should be transformed to:
>
>
> a()
> b()
> c()
>
>
> Note that we don't want to introduce semicolons. Hence I was not able to
> determine the correct element for the setLinewrap() invocation.
> Do I have to dig deeper or can we play a simple trick here?
>
> Thanks!
> erik
>
>
Re: xbase2 - formatting line breaks [message #901316 is a reply to message #688035] Fri, 10 August 2012 18:24 Go to previous messageGo to next message
Nikola Petrov is currently offline Nikola PetrovFriend
Messages: 4
Registered: August 2012
Junior Member
I am having the same problem and I am using the XBlockExpression ParserRule for my xbase support. I have described the problem as a subpost here with a minimal grammar.

Were you able to fix it after all and if yes how?

[Updated on: Fri, 10 August 2012 18:25]

Report message to a moderator

Re: xbase2 - formatting line breaks [message #901584 is a reply to message #688035] Mon, 13 August 2012 14:18 Go to previous message
Nikola Petrov is currently offline Nikola PetrovFriend
Messages: 4
Registered: August 2012
Junior Member
It seems this is not properly implemented for the xblockexpression as far as I could see it in the code. Here is the code that provides a nice formatting for me.

/**
	 * Some code taken from the Spray project style formatter</a>
	 */
	private void configureXBase(FormattingConfig c, XbaseGrammarAccess grammar) {

		for (Pair<Keyword, Keyword> kw : grammar.findKeywordPairs("{", "}")) {
			c.setLinewrap().after(kw.getFirst());
			c.setLinewrap().around(kw.getSecond());
			c.setIndentation(kw.getFirst(), kw.getSecond());
		}

		// no space before comma, one space after
		for (Keyword kw : grammar.findKeywords(",")) {
			c.setNoSpace().before(kw);
			c.setSpace(" ").after(kw);
		}

		c.setNoSpace().around(
				grammar.getStaticQualifierAccess().getColonColonKeyword_1());
		xbaseFormmater.configureXMemberFeatureCall(c,
				grammar.getXMemberFeatureCallAccess());
		xbaseFormmater.configureXParenthesizedExpression(c,
				grammar.getXParenthesizedExpressionAccess());

		c.setLinewrap().after(grammar.getXExpressionInsideBlockRule());

		Keyword semicolon = grammar.getXBlockExpressionAccess()
				.getSemicolonKeyword_2_1();
		c.setNoLinewrap().before(semicolon);
		c.setNoSpace().before(semicolon);
		c.setLinewrap().after(semicolon);
	}



where xbaseFormmater is an instance of XbaseFormatter which you can inject easily with guice.
Previous Topic:Creating typrefs for bounded wildcards
Next Topic:Method createSequence is exceeding 65535
Goto Forum:
  


Current Time: Sat Feb 22 07:53:57 GMT 2020

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

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

Back to the top