Skip to content
Snippets Groups Projects
Commit c0a73ab4 authored by Taddeus Kroes's avatar Taddeus Kroes
Browse files

Further improved multiplication sign omission.

parent 01cf1342
No related branches found
No related tags found
No related merge requests found
......@@ -168,9 +168,10 @@ def generate_line(root):
# 2 * a -> 2a
l = e[0][-1]
r = e[1][0]
left_simple = is_id(left) or is_int(left)
if r == '(' or (l == ')' and r != '-') \
or ((is_id(left) or is_int(left)) and r.isalpha()):
if (r == '(' and left_simple) or (l == ')' and r != '-') \
or (left_simple and r.isalpha()):
sep = ''
exp = sep.join(e)
......
......@@ -155,6 +155,9 @@ class TestLine(unittest.TestCase):
mul = N('*', l2, N('^', l2, 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):
plus = N('+', L(1), -L(2))
self.assertEquals(generate_line(plus), '1 - 2')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment