From 906ed7e2582cfb8dc71bf6f757120b8d0105270d Mon Sep 17 00:00:00 2001 From: Shiro Kawai Date: Sun, 29 Dec 2024 20:00:55 -1000 Subject: [PATCH] Propagate numeric parser error message to the generic reader. https://github.com/shirok/Gauche/issues/912 For example: ``` gosh> #e1e325 *** READ-ERROR: Read error at "(standard input)":line 2: bad numeric format: "#e1e325": (such an exact number is out of implementation limitation) ``` (See https://github.com/shirok/Gauche/issues/898) --- ChangeLog | 5 +++++ src/read.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c45b77cf8..9e4dff79a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2024-12-29 Shiro Kawai + + * src/read.c (read_number): Propagate numeric parser error message. + https://github.com/shirok/Gauche/issues/912 + 2024-12-25 Shiro Kawai * src/vector.c: Make uvector print routine follow writeControls diff --git a/src/read.c b/src/read.c index 2af9be9a0..90f03b902 100644 --- a/src/read.c +++ b/src/read.c @@ -1397,13 +1397,15 @@ static ScmObj read_number(ScmPort *port, ScmChar initial, int radix, flags |= SCM_NUMBER_FORMAT_STRICT_R7RS; } int default_radix = radix >= 2? radix : 10; + flags |= SCM_NUMBER_FORMAT_ERROR_MESSAGE; ScmObj num = Scm_StringToNumber(s, default_radix, flags); - if (num == SCM_FALSE) { + if (!SCM_NUMBERP(num)) { if (radix >= 2) { /* In this case, we've read #r syntax */ - Scm_ReadError(port, "bad numeric format: \"#%dr%A\"", radix, s); + Scm_ReadError(port, "bad numeric format: \"#%dr%A\": %A", + radix, s, num); } else { - Scm_ReadError(port, "bad numeric format: %S", s); + Scm_ReadError(port, "bad numeric format: %S: %A", s, num); } } return num;