> Matching an expr tree with XPath, seems to me like shooting to a fly
> with a cannon.
>   
That appears to be my conclusion as well, I just had to explore it (and 
discuss it).

I wonder if you overestimate how heavy XPath (or a subset) is though as 
the alternatives you suggest seems to me to be just as heavy!

> It will be very slow and not all the possible matching rules will be
> possible with XPath plus I imagine that will be some trickery with
> recursive functions.
>   
Slow: Not slower than any alternatives doing the same thing.
Matching possible: Yes, one would be able to call into any Python 
function so...
Recursive functions: Not sure what you mean. There are potential 
problems related with recursive transforms processes in general but that 
is independent of the mechanism used for node matching.
> class ForInToForFrom(Transformation):
>
>   def ex_match1 (self, tree):
>         return  len(tree) >=3 and tree is ForInStatNode and tree[1] is
> SimpleCallNode and tree[2] is NameNode and tree[2].name == RANGE_ID
>   
I like this.

 From a theoretic perspective though:

But how would you select nodes depending on where it is located (ie all 
nested functions)? So you need to access parent stack as well. And then 
(in theory) you have algorithmic performance worse than with XPath, 
because with XPath you can turn stuff like

(function//function)|(function//for)

into

function//(function|for)

and this transformation is done at Cython launch-time (and if a problem 
can be pickled to speed up Cython launch).

>   def ex_match2 (self, tree):
>         return  tree == ForInStatNode ( SimpleCallNode ( NameNode
> (name = RANGE_ID)))
>   
This would be about the same thing as an XPath approach! But one has to 
write the == machinery, and since that is done manually towards our 
exact tree then some optimizations might creep in.

> def eg_match3 (self,tree):
>       subtree =  buildMatch ("""
> ForInStatNode:
>      SimpleCallNode:
>          NameNode:
>              name = range
>     """)
>     return subtree.matches(tree)
>   
Now you have exactly the XPath approach, except that we have to 
reimplement a custom parser and specify a custom language!

> To better understand what kind of transformation we would like to
> apply I think we should have a 10 / 20 item list of possible
> transforms.
>   
Well said. I think it will probably be the first one, but at least now 
XPath is a bit explored so that one can recognize it if it is needed...

-- 
Dag Sverre

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to