From 441acdeea2e29b8df598408a3405a8866ded2130 Mon Sep 17 00:00:00 2001 From: bog Date: Tue, 2 Apr 2024 00:01:33 +0200 Subject: [PATCH] :bug: usub error with negative numbers. --- features/int.sk | 1 + lib/src/lexer.c | 14 -------------- tests/lexer.h | 8 ++++---- tests/parser.h | 2 +- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/features/int.sk b/features/int.sk index 7fa8bb9..4d4fc2b 100644 --- a/features/int.sk +++ b/features/int.sk @@ -5,4 +5,5 @@ assert 6 * 7 eq 42 assert 1 + 2 * 3 eq 7 assert (1 + 2) * 3 eq 9 assert -2^3 eq -8 +assert -2^4 eq -16 assert 32 % 7 eq 4 diff --git a/lib/src/lexer.c b/lib/src/lexer.c index d624228..cc66efa 100644 --- a/lib/src/lexer.c +++ b/lib/src/lexer.c @@ -200,13 +200,6 @@ struct token* lexer_try_scan_int(struct lexer* self) struct str value; str_init(&value); - if (cursor < self->len - && self->source[cursor] == '-') - { - str_push(&value, self->source[cursor]); - cursor++; - } - while (cursor < self->len && isdigit(self->source[cursor])) { @@ -237,13 +230,6 @@ struct token* lexer_try_scan_float(struct lexer* self) struct str value; str_init(&value); - if (cursor < self->len - && self->source[cursor] == '-') - { - str_push(&value, self->source[cursor]); - cursor++; - } - while (cursor < self->len && isdigit(self->source[cursor])) { diff --git a/tests/lexer.h b/tests/lexer.h index f29fd15..4a6602b 100644 --- a/tests/lexer.h +++ b/tests/lexer.h @@ -42,9 +42,9 @@ static void test_lexer(char const* source, int count, ...) static void test_lexer_int() { - test_lexer(" 4 -23 720 ", 3, + test_lexer(" 4 23 720 ", 3, "INT[4]", - "INT[-23]", + "INT[23]", "INT[720]" ); @@ -77,11 +77,11 @@ static void test_lexer_bool() static void test_lexer_float() { - test_lexer(".4 7. 2.3 -6.12", 4, + test_lexer(".4 7. 2.3 6.12", 4, "FLOAT[.4]", "FLOAT[7.]", "FLOAT[2.3]", - "FLOAT[-6.12]" + "FLOAT[6.12]" ); } diff --git a/tests/parser.h b/tests/parser.h index 93a0c06..33a5484 100644 --- a/tests/parser.h +++ b/tests/parser.h @@ -31,7 +31,7 @@ static void test_parser_int() { test_parser("ROOT(INT[32])", " 32 "); - test_parser("ROOT(INT[32],INT[-2],INT[24])", " 32 -2 24"); + test_parser("ROOT(INT[32],INT[2],INT[24])", " 32 2 24"); test_parser("ROOT(ADD(INT[1],MUL(INT[2],INT[3])))", " 1 + 2 * 3 ");