Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND] Need for formatting commands?
[XPAND] Need for formatting commands? [message #505859] Tue, 05 January 2010 11:41 Go to next message
Erhard Weinell is currently offline Erhard WeinellFriend
Messages: 39
Registered: January 2010
Location: Kassel, Germany
Member

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 12:49 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

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


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: [XPAND] Need for formatting commands? [message #506113 is a reply to message #505875] Wed, 06 January 2010 04:25 Go to previous messageGo to next message
Erhard Weinell is currently offline Erhard WeinellFriend
Messages: 39
Registered: January 2010
Location: Kassel, Germany
Member
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 09:46 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
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 10:38 Go to previous messageGo to next message
Erhard Weinell is currently offline Erhard WeinellFriend
Messages: 39
Registered: January 2010
Location: Kassel, Germany
Member
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 14:20]

Report message to a moderator

Re: [XPAND] Need for formatting commands? [message #506975 is a reply to message #506611] Mon, 11 January 2010 15:22 Go to previous message
Erhard Weinell is currently offline Erhard WeinellFriend
Messages: 39
Registered: January 2010
Location: Kassel, Germany
Member
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: Fri Mar 29 12:37:06 GMT 2024

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

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

Back to the top