From 60ad7b994c2126346c19769a1a5f5c8f679a05ee Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Sat, 9 May 2026 15:25:49 +0300 Subject: Fix lexer processing [+-].\d as symbol instead of number Extended lookahead in the number branch to 3 chars. Added tests for "-.5", "+.5", "-.0" in test_numbers and for "-.", "+.", ".", "+.a", "-.a" in test_ambiguous. --- compiler/src/lexer/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'compiler/src/lexer/mod.rs') diff --git a/compiler/src/lexer/mod.rs b/compiler/src/lexer/mod.rs index 464d88e..f3c8b76 100644 --- a/compiler/src/lexer/mod.rs +++ b/compiler/src/lexer/mod.rs @@ -146,8 +146,12 @@ impl<'a> Iterator for Lexer<'a> { // Number ch if ch.is_ascii_digit() - || matches!(ch, '+' | '-' | '.') - && self.peek_nth(1).is_some_and(|ch| ch.is_ascii_digit()) => + || ch == '.' && self.peek_nth(1).is_some_and(|ch| ch.is_ascii_digit()) + || matches!(ch, '+' | '-') + && self.peek_nth(1).is_some_and(|ch| ch.is_ascii_digit()) + || matches!(ch, '+' | '-') + && self.peek_nth(1).is_some_and(|ch| ch == '.') + && self.peek_nth(2).is_some_and(|ch| ch.is_ascii_digit()) => { Token::Number(self.next_atom()) } -- cgit v1.3