Commit c0a73ab4 authored by Taddeus Kroes's avatar Taddeus Kroes

Further improved multiplication sign omission.

parent 01cf1342
...@@ -168,9 +168,10 @@ def generate_line(root): ...@@ -168,9 +168,10 @@ def generate_line(root):
# 2 * a -> 2a # 2 * a -> 2a
l = e[0][-1] l = e[0][-1]
r = e[1][0] r = e[1][0]
left_simple = is_id(left) or is_int(left)
if r == '(' or (l == ')' and r != '-') \ if (r == '(' and left_simple) or (l == ')' and r != '-') \
or ((is_id(left) or is_int(left)) and r.isalpha()): or (left_simple and r.isalpha()):
sep = '' sep = ''
exp = sep.join(e) exp = sep.join(e)
......
...@@ -155,6 +155,9 @@ class TestLine(unittest.TestCase): ...@@ -155,6 +155,9 @@ class TestLine(unittest.TestCase):
mul = N('*', l2, N('^', l2, a)) mul = N('*', l2, N('^', l2, a))
self.assertEquals(generate_line(mul), '2 * 2 ^ a') self.assertEquals(generate_line(mul), '2 * 2 ^ a')
mul = N('*', N('/', a, l2), N('+', a, b))
self.assertEquals(generate_line(mul), 'a / 2 * (a + b)')
def test_plus_to_minus(self): def test_plus_to_minus(self):
plus = N('+', L(1), -L(2)) plus = N('+', L(1), -L(2))
self.assertEquals(generate_line(plus), '1 - 2') self.assertEquals(generate_line(plus), '1 - 2')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment