From 106c2547b556186d7776f14834723a59b3e3f5e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Sun, 4 May 2025 18:10:50 +0200 Subject: [PATCH] fix(errors): unexpected char errors were pointing one char too far --- notes.org | 6 +++++- src/tokens.rs | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/notes.org b/notes.org index 2162255..54bdf33 100644 --- a/notes.org +++ b/notes.org @@ -185,6 +185,10 @@ CLOCK: [2025-05-04 dim. 14:01]--[2025-05-04 dim. 14:14] => 0:13 :EFFORT: 10 :END: -* TODO error offsets are incorrect +* DONE error offsets are incorrect * TODO remove old FromStr parser implementation + +* TODO use a better readline impl + +* TODO handle non-interactive input better diff --git a/src/tokens.rs b/src/tokens.rs index 5177532..86180fd 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -216,11 +216,12 @@ impl Tokenizer { } else if c.is_whitespace() { self.advance(); } else { - self.advance(); - return Err(ScanError { + let result = Err(ScanError { location: self.current_location(1), kind: ScanErrorKind::UnexpectedChar(c), }); + self.advance(); + return result; } } else { return Ok(None);