From bb510d2be12e918f58f5f40bcc8ffe5cd567634d Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Thu, 19 Oct 2023 23:13:27 +0900 Subject: [PATCH 1/2] fix: 9 must be treated as a part of integer literal --- package/origlang-compiler/src/lexer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/origlang-compiler/src/lexer.rs b/package/origlang-compiler/src/lexer.rs index 932567b5..e8108995 100644 --- a/package/origlang-compiler/src/lexer.rs +++ b/package/origlang-compiler/src/lexer.rs @@ -300,7 +300,7 @@ impl Lexer<'_> { let r = self.byte_skip_n(plus); if let Ok(b) = r { - if (b'0'..b'9').contains(&b) { + if (b'0'..=b'9').contains(&b) { plus += 1; } else { break From 97a39336c4f1625e9150adc74228eb64702d4264 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Thu, 19 Oct 2023 23:13:38 +0900 Subject: [PATCH 2/2] test: add regression test --- package/origlang-compiler/src/lexer/tests.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/package/origlang-compiler/src/lexer/tests.rs b/package/origlang-compiler/src/lexer/tests.rs index 01e6faef..d5ffc82a 100644 --- a/package/origlang-compiler/src/lexer/tests.rs +++ b/package/origlang-compiler/src/lexer/tests.rs @@ -217,3 +217,19 @@ fn crlf_negative() { char: '\r', }); } + +#[test] +fn off_by_one_range_regression() { + const S: &str = "9"; + let lexer = Lexer::create(S); + assert_eq!(lexer.next(), Pointed { + data: Token::Digits { + sequence: "9".to_string(), + suffix: None, + }, + position: SourcePosition { + line: NonZeroUsize::new(1).unwrap(), + column: NonZeroUsize::new(1).unwrap(), + } + }) +} \ No newline at end of file