Skip to content

Commit

Permalink
Merge pull request #159 from dlyongemallo/fraction_num_times_var
Browse files Browse the repository at this point in the history
For fractional phase with variables, accept an integer or fraction followed by a variable (without an intervening "*").
  • Loading branch information
jvdwetering authored Oct 31, 2023
2 parents 703530f + 034c974 commit 1f6f5e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions test/test_editor_base_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion zxlive/editor_base_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion zxlive/parse_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f6f5e9

Please sign in to comment.