diff --git a/lib/srfi/38.scm b/lib/srfi/38.scm index 82f3d145..98638006 100644 --- a/lib/srfi/38.scm +++ b/lib/srfi/38.scm @@ -145,15 +145,18 @@ (let ((in (if (pair? o) (car o) (current-input-port))) (shared '())) (define (read-label res) - (let ((c (char-downcase (peek-char in)))) - (if (if (char-numeric? c) #t (memv c '(#\a #\b #\c #\d #\e))) - (read-label (cons (read-char in) res)) - (list->string (reverse res))))) + (let ((c (peek-char in))) + (if (and (not (eof-object? c)) + (or (char-numeric? c) + (memv (char-downcase c) '(#\a #\b #\c #\d #\e #\f)))) + (read-label (cons (read-char in) res)) + (list->string (reverse res))))) (define (read-number base) (let* ((str (read-label '())) - (n (string->number str base))) - (if (or (not n) (not (memv (peek-char in) delimiters))) - (error "read error: invalid number syntax" str (peek-char in)) + (n (string->number str base)) + (c (peek-char in))) + (if (or (not n) (not (or (eof-object? c) (memv c delimiters)))) + (error "read error: invalid number syntax" str c) n))) (define (read-float-tail in) ;; called only after a leading period (let lp ((res 0.0) (k 0.1)) diff --git a/tests/srfi-38-tests.scm b/tests/srfi-38-tests.scm index b7f8f48e..10a3c294 100644 --- a/tests/srfi-38-tests.scm +++ b/tests/srfi-38-tests.scm @@ -59,6 +59,11 @@ (vector-set! x 2 x) x)) +(test 255 (read-from-string "#xff")) +(test 99 (read-from-string "#d99")) +(test 63 (read-from-string "#o77")) +(test 3 (read-from-string "#b11")) + (cond-expand (chicken (test-io "(#0=\"abc\" #0# #0#)"