aboutsummaryrefslogtreecommitdiff
path: root/src/elixir_math_parser.yrl
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-11-10 12:27:21 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-11-10 12:27:21 +0100
commit96299cbf09bdb75e4d6c6849c9c4c3ce000a6fc5 (patch)
tree7d5f21e6c884a2cd87c619c5d97fddb4cceb7ea8 /src/elixir_math_parser.yrl
parent7536cdbd312dff03ab10e46929dc1b072f881d01 (diff)
feat(parser): supports literal decimal numbers
Diffstat (limited to 'src/elixir_math_parser.yrl')
-rw-r--r--src/elixir_math_parser.yrl12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/elixir_math_parser.yrl b/src/elixir_math_parser.yrl
index 4e8e9e9..635ebd3 100644
--- a/src/elixir_math_parser.yrl
+++ b/src/elixir_math_parser.yrl
@@ -7,7 +7,7 @@ Nonterminals
.
Terminals
- int
+ int float
var
break
'+' '-' '*' '/' '!' '^'
@@ -42,6 +42,7 @@ exprs -> expr : '$1'.
exprs -> expr exprs : {mul_op, '$1', '$2'}.
expr -> int : unwrap('$1').
+expr -> float : unwrap('$1').
expr -> var : '$1'.
expr -> exprs '+' exprs : {add_op, '$1', '$3'}.
expr -> exprs '-' exprs : {sub_op, '$1', '$3'}.
@@ -54,6 +55,9 @@ expr -> '-' exprs : {sub_op, {int, 0, 0}, '$2'}.
Erlang code.
-unwrap({int, Line, Value}) ->
- Match = fun(X) -> not(X == 95) end,
- {int, Line, list_to_integer(lists:filter(Match, Value))}.
+% 95 is the unicode of "_"
+numberMatch(X) -> not(X == 95).
+
+unwrap({int, Line, Value}) -> {int, Line, list_to_integer(lists:filter(fun numberMatch/1, Value))};
+% 48 is the unicode of "0"
+unwrap({float, Line, Value}) -> {float, Line, [48 | lists:filter(fun numberMatch/1, Value)]}.