aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-11-10 00:06:09 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-11-10 00:06:09 +0100
commit2019a495893f138f70e189483f36b219eabe20e2 (patch)
tree2056409e1a1b3fde5ac01806aa08f9af1bfcf604
parentcd6918ab9604268d53b5fe1cf1921f95ec3dea80 (diff)
feat(calc): supports unary minus
-rw-r--r--README.md2
-rw-r--r--example/input.txt2
-rw-r--r--src/elixir_math_parser.yrl1
3 files changed, 3 insertions, 2 deletions
diff --git a/README.md b/README.md
index 65f2454..ea7d98c 100644
--- a/README.md
+++ b/README.md
@@ -2,4 +2,4 @@
A math script parser in Elixir.
-Using leex, yecc and ratio.
+Using leex, yecc and a modified version of Ratio from hexpm.
diff --git a/example/input.txt b/example/input.txt
index 8cb02c5..32146f2 100644
--- a/example/input.txt
+++ b/example/input.txt
@@ -6,4 +6,4 @@ y = 2!
z = y/2
10 + 4(z / y)(x / 4)
-x^(0-y)
+x^(-y)
diff --git a/src/elixir_math_parser.yrl b/src/elixir_math_parser.yrl
index 006c768..f8de916 100644
--- a/src/elixir_math_parser.yrl
+++ b/src/elixir_math_parser.yrl
@@ -50,6 +50,7 @@ expr -> exprs '/' exprs : {div_op, '$1', '$3'}.
expr -> expr '!' : {factor_op, '$1'}.
expr -> exprs '^' exprs : {exp_op, '$1', '$3'}.
expr -> '(' exprs ')' : '$2'.
+expr -> '-' exprs : {sub_op, {int, 0, 0}, '$2'}.
Erlang code.