From 244e46ed692e9d2a7c4be7c0f5adda03239ee2fd Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Mon, 10 Nov 2025 00:21:40 +0100 Subject: feat(parser): supports _ in numbers --- example/input.txt | 2 +- src/elixir_math_parser.yrl | 4 +++- src/elixir_math_parser_lexer.xrl | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/example/input.txt b/example/input.txt index 32146f2..1f4789b 100644 --- a/example/input.txt +++ b/example/input.txt @@ -1,7 +1,7 @@ a = 7;; b = 4 (a + b) * 10 / 2 -x = 20 +x = 2_0 y = 2! z = y/2 10 + 4(z / y)(x / 4) diff --git a/src/elixir_math_parser.yrl b/src/elixir_math_parser.yrl index f8de916..4e8e9e9 100644 --- a/src/elixir_math_parser.yrl +++ b/src/elixir_math_parser.yrl @@ -54,4 +54,6 @@ expr -> '-' exprs : {sub_op, {int, 0, 0}, '$2'}. Erlang code. -unwrap({int, Line, Value}) -> {int, Line, list_to_integer(Value)}. +unwrap({int, Line, Value}) -> + Match = fun(X) -> not(X == 95) end, + {int, Line, list_to_integer(lists:filter(Match, Value))}. diff --git a/src/elixir_math_parser_lexer.xrl b/src/elixir_math_parser_lexer.xrl index c29416e..c418c02 100644 --- a/src/elixir_math_parser_lexer.xrl +++ b/src/elixir_math_parser_lexer.xrl @@ -1,5 +1,5 @@ Definitions. -INT = [0-9]+ +INT = [0-9_]+ NAME = [a-zA-Z_][a-zA-Z0-9_]* WHITESPACE = [\s\t\r] COMMENT = #[^\n]*\n? -- cgit v1.2.3