| | |
| | | |
| | | def test_prio_product_exponent(self): |
| | | parser = Lark_StandAlone() |
| | | tree = parser.parse("x ** -3 * sin(12)") # => (x^3) * sin(12) |
| | | print(tree.pretty()) |
| | | tree = parser.parse("x ** -3 * sin(12)") |
| | | self.assertEqual('''mul |
| | | exponent |
| | | var x |
| | | neg |
| | | number 3 |
| | | function |
| | | sin |
| | | argv |
| | | number 12 |
| | | ''', tree.pretty(indent_str=' ')) |
| | | |
| | | def test_prio_product_exponent_revert(self): |
| | | parser = Lark_StandAlone() |
| | | tree = parser.parse("sin(12) * x ** sqrt(4)") # => sin(12) * (x ** sqrt(4)) |
| | | print(tree.pretty()) |
| | | print(f">{tree.pretty()}<") |
| | | self.assertEqual('''mul |
| | | function |
| | | sin |
| | | argv |
| | | number 12 |
| | | exponent |
| | | var x |
| | | function |
| | | sqrt |
| | | argv |
| | | number 4 |
| | | ''', tree.pretty(indent_str=' ')) |
| | | |
| | | def test_use_transform(self): |
| | | parser = Lark_StandAlone(transformer=ExpressionTransformer()) |
| | | tree = parser.parse("log(-12, 5) * x ** sqrt(4)") # => sin(12) * (x^sqrt(4)) |
| | | self.assertEqual(tree, 'math.log(-12, 5) * x ** math.sqrt(4)') |
| | | |
| | | print(tree) |
| | | |
| | | def test_use_function_in_function(self): |
| | | parser = Lark_StandAlone(transformer=ExpressionTransformer()) |
| | | tree = parser.parse("tan(radians(x))") # => |
| | | self.assertEqual(tree, 'math.tan(math.radians(x))') |
| | | |
| | | print(tree) |
| | | |
| | | |
| | | |