handle [+-].[^0-9] symbols (fixes issue #307)

This commit is contained in:
Alex Shinn 2016-02-04 23:30:39 +09:00
parent 3cf21ee8db
commit 8a739d2698
2 changed files with 10 additions and 1 deletions

View file

@ -73,6 +73,8 @@
(vector-set! x 2 x) (vector-set! x 2 x)
x)) x))
(test '+.! (read-from-string "+.!"))
(test 255 (read-from-string "#xff")) (test 255 (read-from-string "#xff"))
(test 99 (read-from-string "#d99")) (test 99 (read-from-string "#d99"))
(test 63 (read-from-string "#o77")) (test 63 (read-from-string "#o77"))

9
sexp.c
View file

@ -2613,6 +2613,12 @@ static sexp sexp_fill_reader_labels(sexp ctx, sexp x, sexp shares, int state) {
} }
#endif #endif
static int sexp_peek_char(sexp ctx, sexp in) {
int c = sexp_read_char(ctx, in);
if (c != EOF) sexp_push_char(ctx, c, in);
return c;
}
sexp sexp_read_raw (sexp ctx, sexp in, sexp *shares) { sexp sexp_read_raw (sexp ctx, sexp in, sexp *shares) {
char *str; char *str;
int c1, c2, line; int c1, c2, line;
@ -3030,7 +3036,8 @@ sexp sexp_read_raw (sexp ctx, sexp in, sexp *shares) {
case '+': case '+':
case '-': case '-':
c2 = sexp_read_char(ctx, in); c2 = sexp_read_char(ctx, in);
if (c2 == '.' || sexp_isdigit(c2)) { if ((c2 == '.' && sexp_isdigit(sexp_peek_char(ctx, in)))
|| sexp_isdigit(c2)) {
sexp_push_char(ctx, c2, in); sexp_push_char(ctx, c2, in);
res = sexp_read_number(ctx, in, 10, 0); res = sexp_read_number(ctx, in, 10, 0);
if ((c1 == '-') && ! sexp_exceptionp(res)) { if ((c1 == '-') && ! sexp_exceptionp(res)) {