Hi,
Dag Sverre Seljebotn wrote:
> class WithTransform(VisitorTransform):
> # from with transform PEP...
> with_fragment = TreeFragment(u"""
> _mgr = (EXPR)
> _exit = mgr.__exit__
> _value = mgr.__enter__()
> _exc = True
> try:
> try:
> VAR = _value
> BLOCK
> ...
> <snip>
> ...
> """)
>
> def process_WithStatementNode(self, node):
> return self.with_fragment.substitute({
> "EXPR" : node.expr,
> "VAR" : node.var,
> "BLOCK" : node.body
> })
General comment: I'm not sure templating is better than creating the tree by
hand. For example, you use node.body below, which can expand to anything.
Since I consider writing transformers a rare thing, maybe it would be better
to really write down the node creation code and stick in the bits from the
original tree. To help doing that, we could have a tree dumper that writes out
the class creation calls, so that you can write the Cython code, dump the
tree, and just modify the tree creation code to fit your needs. I find that
simpler and safer than your parsing approach.
> - Some changes to Transform.py which I hope goes through... there's a
> Visitor object there; using the "process_ClassName" pattern (I think
> that was the conclusion for future performance reasons).
Did we really reach a conclusion on this?
> - A clone_node method on Node for proper node copying (shallow object
> copy except child node lists, which are also copied).
Fine.
> In order to be able to provide proper error messages for string-based
> code snippets like the above (which are passed to Parsing.py...); I've
> changed the pointer to the source code (used as the first element in the
> position tuples found everywhere...) from being a string filename to
> being a SourceDescriptor object.
I think being able to parse from a string is a valuable feature in itself.
"pyinline" comes to mind.
> A SourceDescriptor can currently be a FileSourceDescriptor, in which
> case things work like before (it gives the filename on __str__ so much
> code needed not change),
Please make that a method on the SourceDescriptor, like "get_filename()".
Calling str() on it reads like you wanted to print the source.
> or a StringSourceDestriptor which I use for my new code...
How do you create a filename from that one? I mean, the source calls
basename() on it in some places. To me, this indicates that the two are not
really the same.
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev