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

lac at codespeak.net lac at codespeak.net
Sun Jun 20 18:11:38 CEST 2004


Author: lac
Date: Sun Jun 20 18:11:36 2004
New Revision: 5186

Modified:
   pypy/branch/src-new-utest/pypy/tool/utestconvert.py
Log:
The last refactoring out of common code left some functions and variables
with poor names, an arglist which was a string, no longer a list, for
instance.  Fix the names up.


Modified: pypy/branch/src-new-utest/pypy/tool/utestconvert.py
==============================================================================
--- pypy/branch/src-new-utest/pypy/tool/utestconvert.py	(original)
+++ pypy/branch/src-new-utest/pypy/tool/utestconvert.py	Sun Jun 20 18:11:36 2004
@@ -32,52 +32,30 @@
 
 def comma_to_op(old, new, block, op):
     '''change comma to appropriate op. dictionary dispatched. '''
-    indent, expr, trailer = common_setup(old, block)
+p    indent, expr, trailer = common_setup(old, block)
     new = new + ' '
     op = ' ' + op
     left, right = get_expr(expr, ',')
 
     try:
-        parser.expr(left)  # that paren came off easily
+        parser.expr(left.lstrip())  # that paren came off easily
     except SyntaxError:
         left  = re.sub(linesep, '\\'+linesep, left)
         
-    try:
-        parser.expr(right.lstrip())  # that paren came off easily
-    except SyntaxError:
-        # paste continuation backslashes on our multiline constructs
-        right = handle_multiline(right)
-        
+    right = process_args(right)
+
     if right.startswith(linesep):
         op = op + '\\'
-    return indent + new + left + op + right + trailer
-
-def handle_multiline(expr, sep=','):
-    try:
-        left, right = get_expr(expr, sep)
-        left = re.sub(linesep, '\\'+linesep, left)
-
-        # only repair the lhs.  The rhs may be a multiline string that
-        # can take care of itself.
-            
-        if right.startswith(linesep):# that needs a slash too ...
-            sep = sep + '\\'
-        
-        return left + sep + right
-    except SyntaxError: # just a regular old multiline expression
-        return re.sub(linesep, '\\'+linesep, expr)
 
+    return indent + new + left + op + right + trailer
+ 
 def strip_parens(old, new, block, op):
     '''remove one set of parens. dictionary dispatched. '''
-    indent, expr, trailer = common_setup(old, block)
+    indent, args, trailer = common_setup(old, block)
     new = new + ' '
-    try:
-        parser.expr(expr) # the parens came off easily
-    except SyntaxError:
-        # paste continuation backslashes on our multiline constructs.
-        expr = handle_multiline(expr)
 
-    return indent + new + expr + trailer
+    args = process_args(args)
+    return indent + new + args + trailer
 
 def rounding():
     pass
@@ -159,6 +137,35 @@
     expr, trailer = get_expr(block[pat.end():], ')')
     return indent, expr, trailer
 
+def find_first_expr(args):
+    '''find the first expression, return it, and the rest if it exists'''
+    sep = ','
+    try:
+        left, right = get_expr(args, sep)
+        left = re.sub(linesep, '\\'+linesep, left)
+
+        # only repair the lhs.  The rhs may be a multiline string that
+        # can take care of itself.
+            
+        if right.startswith(linesep):# that needs a slash too ...
+            sep = sep + '\\'
+        
+        return left + sep, right
+    except SyntaxError: # just a regular old multiline expression
+        return re.sub(linesep, '\\'+linesep, args), None
+
+def process_args(args):
+    try:
+        parser.expr(args.lstrip()) # the parens come off easily
+        return args
+    except SyntaxError:
+        # paste continuation backslashes on our multiline constructs.
+        left, right = find_first_expr(args)
+        if right:
+            return left + right
+        else:
+            return left
+
 def get_expr(s, char):
     '''split a string into an expression, and the rest of the string'''
 



More information about the Pypy-commit mailing list