[pypy-svn] r5126 - pypy/branch/src-new-utest/pypy/tool

lac at codespeak.net lac at codespeak.net
Wed Jun 16 18:43:24 CEST 2004


Author: lac
Date: Wed Jun 16 18:43:23 2004
New Revision: 5126

Modified:
   pypy/branch/src-new-utest/pypy/tool/testconverter.py
Log:
Much smaller now.  But I am not done yet with shrinking this ...


Modified: pypy/branch/src-new-utest/pypy/tool/testconverter.py
==============================================================================
--- pypy/branch/src-new-utest/pypy/tool/testconverter.py	(original)
+++ pypy/branch/src-new-utest/pypy/tool/testconverter.py	Wed Jun 16 18:43:23 2004
@@ -24,13 +24,26 @@
             left, right = body[:p], body[p+1:]
             arglist.append((left, right))
 
-        r = find_comma(arglist)
+        try:
+            r = find_comma(arglist)
+            left, right = find_comma(arglist)
+
+            if right.rstrip()[-1] != ')':
+                # if the last printing char of the string is not ')',
+                # keep the parens for now.
+                return new + left + ') == (' + right
+            else:  # see if we can drop one set of parens
+                #stripped = right.rstrip()[0:-1]
+                l = new + ' ' + left[1:] + ' == ' + right.rstrip()[0:-1] + '\n'
+                try:
+                    compile(l, '', 'exec')
+                    return l
+                except SyntaxError: # too bad, needed them
+                    return new + left + ') == (' + right
 
-        if r is None:
-            print 'malformed block %s cannot be converted' % s
+        except SyntaxError:
+            print 'malformed block %s cannot be converted' % s.rstrip()
             return s
-        else:
-            return new + r[0] + ') == (' + r[1]
         
 def find_comma(tuplelist):
     import parser
@@ -40,14 +53,13 @@
     
     for l, r in tuplelist:
         try:
-            left = l + ')'
-            right = '(' + r
-            parser.expr(left)
-            parser.expr(right)
-            return l , r  # Great!  Both sides are expressions!
+            
+            parser.expr(l + ')')
+            parser.expr('(' + r)
+            return l , r    # Great!  Both sides are expressions!
         except SyntaxError: # It wasn't that comma
             pass
-    return None
+    raise SyntaxError       # We never found anything that worked.
     
 def pos_finder(s, char=','):
     # returns the list of string positions where the char 'char' was found
@@ -63,7 +75,7 @@
     blockstring = ''
     filestring = ''
     was_interesting = False
-    indentation = ''
+    indent = ''
     
     for line in fp:
 
@@ -74,23 +86,19 @@
 
         if interesting :
             # we have found the beginning of a new interesting block.
-            # finish up your business with your last block, and
-            # reset everything
+            # finish up your business with your last block, if 
+            # necessary and reset everything
 
             if was_interesting:
-                filestring += indentation + process_block(blockstring,
-                                                          old_fname, new_fname)
-            else:
-                filestring += line
-
+                filestring += indent + process_block(blockstring,
+                                                     old_fname, new_fname)
             blockstring = line # reset the block
-            indentation = ls.group(1)
+            indent = ls.group(1)
             was_interesting = True
 
         elif not was_interesting and not interesting :
             # the last line was not interesting and this one isn't either.
             # just copy it out.
-
             filestring  += line
 
         else:
@@ -101,18 +109,17 @@
             try:
                 compile(blockstring.lstrip(), '', 'exec')
                 # We were done.  This is a boring old follower
-
-                filestring += indentation + process_block(blockstring, old_fname, new_fname)
-                blockstring = line
+                
+                filestring += indent + process_block(blockstring, old_fname, new_fname)
+                filestring += line
+                #blockstring = ''
                 was_interesting = False
 
             except SyntaxError:  # we haven't got enough yet.
                 blockstring += line
 
     if was_interesting :
-        filestring += indentation + process_block(blockstring, old_fname, new_fname)
-    else:
-        filestring += line
+        filestring += indent + process_block(blockstring, old_fname, new_fname)
     
     print filestring
 



More information about the Pypy-commit mailing list