diff --git a/mml2sympy/mml.py b/mml2sympy/mml.py index bf1c1a3..d2e39c3 100644 --- a/mml2sympy/mml.py +++ b/mml2sympy/mml.py @@ -9,11 +9,14 @@ MML_SYM = 'mi' ADD_OPS = ['+', '-'] +MUL_OPS = ['/', '*'] EQ_OPS = ['='] SIMILAR_OPS = { '+': ADD_OPS, '-': ADD_OPS, '=': EQ_OPS, + '*': MUL_OPS, + '/': MUL_OPS, } ADD_OPS_TAG = 'madd' @@ -197,10 +200,12 @@ def modify(mmltree): else: # just one element so append as leaf -- extend since list op.extend(grouped_elems) modified_tree.append(op) - else: # no op elements so must be multiple mn/mi + elif len(all_elements) > 1: # no op elements so must be multiple mn/mi mmul = objectify.Element(MUL_OPS_TAG) mmul.extend(all_elements) modified_tree.append(mmul) + else: # only one element so just leave it alone + modified_tree.extend(all_elements) # remove namespaces from objectify and return modified tree objectify.deannotate(modified_tree, cleanup_namespaces=True) @@ -213,6 +218,8 @@ def _modified_tag_for(element): tag = ADD_OPS_TAG elif element.text.strip() in EQ_OPS: tag = EQ_OPS_TAG + elif element.text.strip() in MUL_OPS: + tag = MUL_OPS_TAG else: raise Exception("modified tag not found for: {0}".format(element)) diff --git a/mml2sympy/tests/test_mml.py b/mml2sympy/tests/test_mml.py index de8f91f..19db783 100644 --- a/mml2sympy/tests/test_mml.py +++ b/mml2sympy/tests/test_mml.py @@ -66,6 +66,16 @@ def test_modify(): assert hasattr(modified_tree.meq, 'madd') assert hasattr(modified_tree.meq.madd, 'mmul') + modify_mml = ''' + + 27 + + ''' + tree = mml2tree(modify_mml) + modified_tree = modify(tree) + assert hasattr(modified_tree, 'mn') + assert modified_tree.countchildren() == 1 + def test_table2trees(): mtable_mml = '''