[XPAND] Need for formatting commands? [message #505859] |
Tue, 05 January 2010 11:41 |
Erhard Weinell 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 #506611 is a reply to message #506362] |
Fri, 08 January 2010 10:38 |
Erhard Weinell 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02833 seconds