this repo has no description

Fix mul/div precedence to parse left to right (#126)

Multiply and divide should apply left to right when not parenthesized

authored by

Chris Gregory and committed by
GitHub
c468c20d 9d520125

+18 -2
+18 -2
scrapscript.py
··· 303 303 ">>": lp(14), 304 304 "<<": lp(14), 305 305 "^": rp(13), 306 - "*": lp(12), 307 - "/": lp(12), 306 + "*": rp(12), 307 + "/": rp(12), 308 308 "//": lp(12), 309 309 "%": lp(12), 310 310 "+": lp(11), ··· 1924 1924 self.assertEqual( 1925 1925 parse([IntLit(1), Operator("*"), IntLit(2), Operator("+"), IntLit(3)]), 1926 1926 Binop(BinopKind.ADD, Binop(BinopKind.MUL, Int(1), Int(2)), Int(3)), 1927 + ) 1928 + 1929 + def test_mul_and_div_bind_left_to_right(self) -> None: 1930 + self.assertEqual( 1931 + parse([IntLit(1), Operator("/"), IntLit(3), Operator("*"), IntLit(3)]), 1932 + Binop(BinopKind.MUL, Binop(BinopKind.DIV, Int(1), Int(3)), Int(3)), 1927 1933 ) 1928 1934 1929 1935 def test_exp_binds_tighter_than_mul_right(self) -> None: ··· 3928 3934 """ 3929 3935 ), 3930 3936 Variant("true", Hole()), 3937 + ) 3938 + 3939 + def test_mul_and_div_have_left_to_right_precedence(self) -> None: 3940 + self.assertEqual( 3941 + self._run( 3942 + """ 3943 + 1 / 3 * 3 3944 + """ 3945 + ), 3946 + Float(1.0), 3931 3947 ) 3932 3948 3933 3949