Hugh Gibson wrote:
> Two things:
>
> 1. It's possible to indent { *and* } - for example:
>
> if (bTest)
> {
> // some code
> }
>
That's (nearly) what you already would get with
compiler.py --pritty-print
--pretty-print-newline-before-open-curly=a
--pretty-print-indent-before-open-curly
in the current (trunk) version of compiler.py which will be in 0.7.
The only difference is that with the current implementation your code
would look like
if (bTest)
{
// some code
}
so the "some code" code block will again be indented. But the closing
curly is kept aligned with the opening one, that's why I didn't add a
specific option for that.
> which is our practice. Looking at compiler.py, it seems that the three calls
> to
>
> write("}")
>
> would have to be prefixed with code to increment the indent, then remove it
> afterwards, if a new flag was set.
>
> Something like:
>
> In generator.py and compiler.py:
>
> parser.add_option("--pretty-print-indent-before-close-curly",
> action="store_true", dest="prettypCloseCurlyIndentBefore", default=False,
> help="Indent \"{\" (default: False)")
>
The implementation of having the contained block be aligned with the
curlies wouldn't be too difficult. But I would probably suggest an
option that reflects more on the block being indented or not (e.g.
something like "--pretty-print-indent-block-..."), rather than on the
closing curly.
> 2. Is it possible to put trailing comments at a fixed column if possible?
>
> --pretty-print-inline-comment-padding=STRING
>
> specifies just a padding for trailing comments. We always try to get ours on
> column 49, to make it easier to read them.
>
We thought about the issue, and might implement it in a later version.
My idea for the options is something along the lines of
--pretty-print-comments-trailing-keepColumn # keep
trailing comments on
# their orig. column if possible
--pretty-print-comments-trailing-commentCols= "49,65,..." #
string with list of columns to use
But we wouldn't want to burden 0.7 with this, because it would mean a
major change to the prettyprint code (e.g. keeping track of the current
column in the current output line). Since I plan a complete rewrite of
the prettyprint code anyway, that seemed like doubled effort (the other
changes were much less invasive).
> It would appear that the fundamental write() function would have to be
> changed to enable this. It would keep track of the column number, after the
> last \n was appended to result. So it could take an optional number, being
> the column to align to, and if the current column is less then append spaces
> to pad it out. If that analysis seems like the right way, I'll spend some
> more time on it.
>
That's definitely how I think about it (I would pass in the complete
'options' object, though). But as I said, the write() function might go
away altogether in the re-write. But I'm open - if everybody agrees to
have this feature in 0.7 I'm more than happy to join forces with you to
implement it in the current version. - Andreas, Sebastian?
> 3. Write() - using string +=
>
> I was surprised to see you using string += to build up "result" in write().
> One of the fundamental rules of Python string operations is to not do this.
>
> See http://www.skymind.com/~ocrow/python_string/ for an analysis and options.
> Using array concatenation (which would enable you to have access to the last
> character in result, for stripping if you need to) gives a factor of 20
> improvement. That should make compiling a lot more efficient.
>
> You should look elsewhere in your code for += constructs and eliminate them.
>
Wow - I didn't reflect on that but it immediately dawns on me. Good
point! And good reference, thanks.
=Thomas
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel