[Python-checkins] r56368 - in sandbox/trunk/2to3: fixes/fix_dict.py fixes/fix_filter.py fixes/fix_map.py patcomp.py

collin.winter python-checkins at python.org
Sat Jul 14 20:22:12 CEST 2007


Author: collin.winter
Date: Sat Jul 14 20:22:12 2007
New Revision: 56368

Modified:
   sandbox/trunk/2to3/   (props changed)
   sandbox/trunk/2to3/fixes/fix_dict.py
   sandbox/trunk/2to3/fixes/fix_filter.py
   sandbox/trunk/2to3/fixes/fix_map.py
   sandbox/trunk/2to3/patcomp.py
Log:
Add a compile_pattern() shortcut function to patcomp.py (and use it in several fixers).


Modified: sandbox/trunk/2to3/fixes/fix_dict.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_dict.py	(original)
+++ sandbox/trunk/2to3/fixes/fix_dict.py	Sat Jul 14 20:22:12 2007
@@ -68,13 +68,13 @@
         return new
 
     P1 = "power< func=NAME trailer< '(' node=any ')' > any* >"
-    p1 = patcomp.PatternCompiler().compile_pattern(P1)
+    p1 = patcomp.compile_pattern(P1)
 
     P2 = """for_stmt< 'for' any 'in' node=any ':' any* >
             | list_for< 'for' any 'in' node=any any* >
             | gen_for< 'for' any 'in' node=any any* >
          """
-    p2 = patcomp.PatternCompiler().compile_pattern(P2)
+    p2 = patcomp.compile_pattern(P2)
 
     def in_special_context(self, node, isiter):
         if node.parent is None:

Modified: sandbox/trunk/2to3/fixes/fix_filter.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_filter.py	(original)
+++ sandbox/trunk/2to3/fixes/fix_filter.py	Sat Jul 14 20:22:12 2007
@@ -62,7 +62,7 @@
             | list_for< 'for' any 'in' node=any any* >
             | gen_for< 'for' any 'in' node=any any* >
          """
-    p0 = patcomp.PatternCompiler().compile_pattern(P0)
+    p0 = patcomp.compile_pattern(P0)
 
     P1 = """
     power<
@@ -71,7 +71,7 @@
         any*
     >
     """
-    p1 = patcomp.PatternCompiler().compile_pattern(P1)
+    p1 = patcomp.compile_pattern(P1)
 
     P2 = """
     power<
@@ -80,7 +80,7 @@
         any*
     >
     """
-    p2 = patcomp.PatternCompiler().compile_pattern(P2)
+    p2 = patcomp.compile_pattern(P2)
 
     def in_special_context(self, node):
         p = node.parent

Modified: sandbox/trunk/2to3/fixes/fix_map.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_map.py	(original)
+++ sandbox/trunk/2to3/fixes/fix_map.py	Sat Jul 14 20:22:12 2007
@@ -74,7 +74,7 @@
             | list_for< 'for' any 'in' node=any any* >
             | gen_for< 'for' any 'in' node=any any* >
          """
-    p0 = patcomp.PatternCompiler().compile_pattern(P0)
+    p0 = patcomp.compile_pattern(P0)
 
     P1 = """
     power<
@@ -83,7 +83,7 @@
         any*
     >
     """
-    p1 = patcomp.PatternCompiler().compile_pattern(P1)
+    p1 = patcomp.compile_pattern(P1)
 
     P2 = """
     power<
@@ -92,7 +92,7 @@
         any*
     >
     """
-    p2 = patcomp.PatternCompiler().compile_pattern(P2)
+    p2 = patcomp.compile_pattern(P2)
 
     def in_special_context(self, node):
         p = node.parent

Modified: sandbox/trunk/2to3/patcomp.py
==============================================================================
--- sandbox/trunk/2to3/patcomp.py	(original)
+++ sandbox/trunk/2to3/patcomp.py	Sat Jul 14 20:22:12 2007
@@ -182,15 +182,5 @@
         return pytree.Leaf(type, value, context=context)
 
 
-_SAMPLE = """(a=(power< ('apply' trailer<'(' b=(not STRING) ')'> ) >){1})
-{1,1}"""
-
-
-def _test():
-    pc = PatternCompiler()
-    pat = pc.compile_pattern(_SAMPLE)
-    print pat
-
-
-if __name__ == "__main__":
-    _test()
+def compile_pattern(pattern):
+    return PatternCompiler().compile_pattern(pattern)


More information about the Python-checkins mailing list