checking for eof when reading a list

This commit is contained in:
Alex Shinn 2010-12-29 16:14:06 +09:00
parent c163599685
commit 0ecb8ea665

View file

@ -203,23 +203,26 @@
(read-char in)
(let lp ((res '()))
(skip-whitespace in)
(case (peek-char in)
((#\))
(read-char in)
(reverse res))
((#\.)
(read-char in)
(cond
((memv (peek-char in) delimiters)
(let ((tail (read-one)))
(skip-whitespace in)
(if (eqv? #\) (peek-char in))
(begin (read-char in) (append (reverse res) tail))
(error "expected end of list after dot"))))
((char-numeric? (peek-char in)) (read-float-tail in))
(else (string->symbol (read-name #\. in)))))
(else
(lp (cons (read-one) res))))))
(let ((c (peek-char in)))
(case c
((#\))
(read-char in)
(reverse res))
((#\.)
(read-char in)
(cond
((memv (peek-char in) delimiters)
(let ((tail (read-one)))
(skip-whitespace in)
(if (eqv? #\) (peek-char in))
(begin (read-char in) (append (reverse res) tail))
(error "expected end of list after dot"))))
((char-numeric? (peek-char in)) (read-float-tail in))
(else (string->symbol (read-name #\. in)))))
(else
(if (eof-object? c)
(error "unterminated list")
(lp (cons (read-one) res))))))))
((#\') (read-char in) (list 'quote (read-one)))
((#\`) (read-char in) (list 'quasiquote (read-one)))
((#\,)