fix tuple parsing after last commit, some cleanup
authorStefan Behnel <scoder@users.berlios.de>
Thu, 6 May 2010 20:47:57 +0000 (22:47 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 6 May 2010 20:47:57 +0000 (22:47 +0200)
Cython/Compiler/Parsing.py

index 4fc861f3932c3c9927a9b0a5cb4a625689f2cfdc..fb25b2c8022cf5a7679c9ef81a206fd72a0d48c4 100644 (file)
@@ -918,11 +918,8 @@ def p_testlist(s):
     pos = s.position()
     expr = p_test(s)
     if s.sy == ',':
-        exprs = [expr]
-        while s.sy == ',':
-            s.next()
-            exprs.append(p_test(s))
-        return ExprNodes.TupleNode(pos, args = exprs)
+        s.next()
+        return p_testlist_tuple(s, pos, expr)
     else:
         return expr
 
@@ -930,18 +927,24 @@ def p_testlist(s):
 
 def p_testlist_comp(s):
     pos = s.position()
-    expr = p_simple_expr(s)
+    expr = p_test(s)
     if s.sy == ',':
-        exprs = [expr]
-        while s.sy == ',':
-            s.next()
-            exprs.append(p_test(s))
-        return ExprNodes.TupleNode(pos, args = exprs)
+        s.next()
+        return p_testlist_tuple(s, pos, expr)
     elif s.sy == 'for':
         return p_genexp(s, expr)
     else:
         return expr
 
+def p_testlist_tuple(s, pos, expr):
+    exprs = [expr]
+    while s.sy not in expr_terminators:
+        exprs.append(p_test(s))
+        if s.sy != ',':
+            break
+        s.next()
+    return ExprNodes.TupleNode(pos, args = exprs)
+
 def p_genexp(s, expr):
     # s.sy == 'for'
     loop = p_comp_for(s, ExprNodes.YieldExprNode(expr.pos, arg=expr))