Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND] Need for formatting commands?
[XPAND] Need for formatting commands? [message #505859] Tue, 05 January 2010 06:41 Go to next message
Eclipse UserFriend

Does XPAND need format commands?[ 0 votes ]
1.No (e.g. I prefer external pretty printing) 0 / 0%
2.Yes - pressing issue 0 / 0%
3.Yes - long term goal 0 / 0%

Hello all,

in its current state, XPAND only features few means for code formatting, mainly the option to suppress newlines. Personally, I like to write templates in a way that the generated code is easily readable 'as is', mainly for two reasons:


  • I do not need to provide an own pretty printer for not-so-common target languages. Especially there are still needs to generate properly formatted SQL or, even worse, SQL-strings embedded into Java.
  • the code is readable even if it is syntactically incorrect, which makes it easier to locate template errors. Some pretty printers tend to refuse formatting malformed code.


Whilst properly placed newlines and spaces are more or less a matter of fine-tuning templates, I miss support for indenting code regions. Especially, one cannot know the proper indentation depth of a member declaration, taking nested qualifiers into account. Up to now one can only "simulate" indented regions by writing such code to an extra "buffer" outlet and by merging this buffer back into the real file afterwards. Of course this makes templates really ugly unless the complex syntax is hidden from the template developer.

Would you consider formatting commands such as indented regions a valuable addition to XPAND? Do you suggest other formatting commands?

Best regards,
Erhard
Re: [XPAND] Need for formatting commands? [message #505875 is a reply to message #505859] Tue, 05 January 2010 07:49 Go to previous messageGo to next message
Eclipse UserFriend
This would be a real nice feature. I just cannot imagine how it could ever be realized. Would you be willing to work on that?

~Karsten
Re: [XPAND] Need for formatting commands? [message #506113 is a reply to message #505875] Tue, 05 January 2010 23:25 Go to previous messageGo to next message
Eclipse UserFriend
Hi Karsten,

I can embed our current "work-around" solution into Xpand and post a patch here or in Bugzilla. Would that best apply against org.eclipse.xpand HEAD or preferably a specific version?

Best,
Erhard
Re: [XPAND] Need for formatting commands? [message #506362 is a reply to message #506113] Thu, 07 January 2010 04:46 Go to previous messageGo to next message
Eclipse UserFriend
Hi Erhard,

it would be interesting to hear about your concrete solution/ideas.
Can you give some examples (i.e. code snippets)?

Sven


Erhard Weinell schrieb:
> Hi Karsten,
>
> I can embed our current "work-around" solution into Xpand and post a
> patch here or in Bugzilla. Would that best apply against
> org.eclipse.xpand HEAD or preferably a specific version?
>
> Best,
> Erhard
>


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [XPAND] Need for formatting commands? [message #506611 is a reply to message #506362] Fri, 08 January 2010 05:38 Go to previous messageGo to next message
Eclipse UserFriend
Hi Karsten, Sven,

I imagine something like this:

<<DEFINE class FOR Class>>
<<  visibility()>> class <<name>> {
<<  INDENT "    ">>
<<    EXPAND member FOREACH ownedElement>>
<<  ENDINDENT>>
}
<<ENDDEFINE>>

<<DEFINE member FOR Property>>
<<  visibility()>> <<type.name>> <<name>>;
<<ENDDEFINE>>


The idea is to prefix every line generated inside an INDENT-block with the given string literal (or a sensible default). Having the auto-hyphen option switched on, this should yield properly formatted code out-of-the-box.

One could also remove leading whitespaces such that the specified indentation depth is "enforced". This way, one can properly format Xpand statements without cluttering the generated code..

Edit:
Although quite intuitive, the expected output of this template is e.g.
public class Foo {
    private String bar;
}


Best,
Erhard

[Updated on: Fri, 08 January 2010 09:20] by Moderator

Re: [XPAND] Need for formatting commands? [message #506975 is a reply to message #506611] Mon, 11 January 2010 10:22 Go to previous message
Eclipse UserFriend
I opened #299278 and appended a patch - feel free to comment.

Best,
Erhard
Previous Topic:[Acceleo] Get information about Metamodel in a model
Next Topic:JET Best way to escape standard Jet tags
Goto Forum:
  


Current Time: Wed Jul 02 03:22:00 EDT 2025

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

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

Back to the top