diff --git a/test/test_editor_base_panel.py b/test/test_editor_base_panel.py index 6a9b7156..b27d7671 100644 --- a/test/test_editor_base_panel.py +++ b/test/test_editor_base_panel.py @@ -58,6 +58,15 @@ def _new_var(name: str) -> Poly: # Test a fractional phase specified with variables. assert (string_to_fraction('a*b', _new_var) == Poly([(1, Term([(Var('a', types_dict), 1), (Var('b', types_dict), 1)]))])) + assert (string_to_fraction('2*a', _new_var) == + Poly([(2, Term([(Var('a', types_dict), 1)]))])) + assert (string_to_fraction('2a', _new_var) == + Poly([(2, Term([(Var('a', types_dict), 1)]))])) + assert (string_to_fraction('3/2a', _new_var) == + Poly([(3/2, Term([(Var('a', types_dict), 1)]))])) + assert (string_to_fraction('3a+2b', _new_var) == + Poly([(3, Term([(Var('a', types_dict), 1)])), (2, Term([(Var('b', types_dict), 1)]))])) + # Test bad input. with pytest.raises(ValueError): diff --git a/zxlive/editor_base_panel.py b/zxlive/editor_base_panel.py index e83b54d5..9e1af331 100644 --- a/zxlive/editor_base_panel.py +++ b/zxlive/editor_base_panel.py @@ -168,7 +168,7 @@ def vert_double_clicked(self, v: VT) -> None: else: prompt = "Enter desired phase value (in units of pi):" - error_msg = "Please enter a valid input (e.g., 1/2, 2, 0.25, a)." + error_msg = "Please enter a valid input (e.g., 1/2, 2, 0.25, 2a+b)." input_, ok = QInputDialog.getText( self, "Change Phase", prompt diff --git a/zxlive/parse_poly.py b/zxlive/parse_poly.py index 9e379521..f70a33ab 100644 --- a/zxlive/parse_poly.py +++ b/zxlive/parse_poly.py @@ -8,7 +8,7 @@ poly_grammar = Lark(""" start : "(" start ")" | term ("+" term)* - term : factor ("*" factor)* + term : (intf | frac)? factor ("*" factor)* ?factor : intf | frac | pi | pifrac | var var : CNAME intf : INT