[Python-porting] 2to3 pattern matching help needed.
Lennart Regebro
regebro at gmail.com
Tue Apr 7 23:59:10 CEST 2009
Help! I need a pattern to match the following code:
@implementor(IFoo)
class C(object):
implements(IFoo)
classProvides(IFooFactory
find_pattern claims that this code should match:
"decorated< decorator< '@' 'implementer' '(' 'IFoo' ')' '\n' >
classdef< 'class' 'C' '(' 'object' ')' ':' suite< '\n' ' '
simple_stmt< power< 'implements' trailer< '(' 'IFoo' ')' > > '\n' >
simple_stmt< power< 'classProvides' trailer< '(' 'IFooFactory' ')' > >
'\n' > '' > > >"
It does not match.
I already have the following similar pattern:
"classdef< 'class' any* ':' suite< any* simple_stmt< power<
statement=(%s) trailer < '(' interface=any ')' > any* > any* > any* >
>"
which matches the following code:
class C(object):
implements(IFoo)
classProvides(IFooFactory
I.e, the same code but without the decorator. But I also need to match
even of the class has decorators, as in the beginning example. If the
decorator matching code is the same or a separate that the one I have,
that doesn't handle decorators, doesn't matter.
--
Lennart Regebro: Pythonista, Barista, Notsotrista.
http://regebro.wordpress.com/
+33 661 58 14 64
More information about the Python-porting
mailing list