ソースを参照

Latest commit seemed to screw up multiplications o mlutiplications, not anymore...

Taddeus Kroes 13 年 前
コミット
a9eb446fb0
2 ファイル変更6 行追加1 行削除
  1. 2 1
      line.py
  2. 4 0
      tests/test_line.py

+ 2 - 1
line.py

@@ -247,7 +247,8 @@ def generate_line(root):
             lparens = is_right_assoc(left.title()) or is_right_assoc(op)
 
         if rpred < op_pred:
-            rparens = not unary_right or len(right[0]) > 1
+            rparens = not unary_right \
+                    or (pred(right[0]) < op_pred and len(right[0]) > 1)
         elif rpred == op_pred and len(right) > 1:
             if right.title() == op:
                 rparens = not is_right_assoc(op)

+ 4 - 0
tests/test_line.py

@@ -348,3 +348,7 @@ class TestLine(unittest.TestCase):
 
         root = N('/', L(1), N('*', -L('a'), L('b')))
         self.assertEquals(generate_line(root), '1 / ((-a)b)')
+
+        root = N('*', N('*', L(2), L('b')), -N('*', L(3), L('b')))
+        self.assertEquals(generate_line(root), '2b * -3b')
+