Skip to content

Commit

Permalink
Propagate numeric parser error message to the generic reader.
Browse files Browse the repository at this point in the history
#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 #898)
  • Loading branch information
shirok committed Dec 30, 2024
1 parent f4f3f76 commit 906ed7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-12-29 Shiro Kawai <shiro@acm.org>

* src/read.c (read_number): Propagate numeric parser error message.
https://github.com/shirok/Gauche/issues/912

2024-12-25 Shiro Kawai <shiro@acm.org>

* src/vector.c: Make uvector print routine follow writeControls
Expand Down
8 changes: 5 additions & 3 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 #<radix>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;
Expand Down

0 comments on commit 906ed7e

Please sign in to comment.