reader: handle whitespace and comments inside lists.
This commit is contained in:
parent
59bd723a8d
commit
6d5811bb98
10
mes.c
10
mes.c
|
@ -711,10 +711,20 @@ readword (int c, char* w, scm *a)
|
|||
return readword (getchar (), strncat (w ? w : buf, &ch, 1), a);
|
||||
}
|
||||
|
||||
int
|
||||
eat_whitespace (int c)
|
||||
{
|
||||
while (c == ' ' || c == '\n') c = getchar ();
|
||||
if (c == ';') return eat_whitespace (readcomment (c));
|
||||
if (c == '#' && peekchar () == '!') {getchar (); readblock (getchar ()); return eat_whitespace (getchar ());}
|
||||
return c;
|
||||
}
|
||||
|
||||
scm *
|
||||
readlis (scm *a)
|
||||
{
|
||||
int c = getchar ();
|
||||
c = eat_whitespace (c);
|
||||
if (c == ')') return &scm_nil;
|
||||
scm *w = readword (c, 0, a);
|
||||
if (w == &scm_dot)
|
||||
|
|
33
mes.mes
33
mes.mes
|
@ -156,9 +156,9 @@
|
|||
(readword (getchar) '() a))
|
||||
|
||||
(define (readword c w a)
|
||||
(display 'mes-readword:)
|
||||
(display c)
|
||||
(newline)
|
||||
;; (display 'mes-readword:)
|
||||
;; (display c)
|
||||
;; (newline)
|
||||
(cond ((eq c -1) ;; eof
|
||||
(cond ((eq w '()) '())
|
||||
(#t (lookup w a))))
|
||||
|
@ -180,13 +180,34 @@
|
|||
(cons (readword (getchar) w a) '())))
|
||||
(#t (ungetchar c) (lookup w a))))
|
||||
((eq c 59) ;; ;
|
||||
(readcomment 59)
|
||||
(readcomment c)
|
||||
(readword 10 w a))
|
||||
((eq c 35) ;; #
|
||||
(cond ((eq (peekchar) 33) ;; !
|
||||
(getchar)
|
||||
(readblock (getchar))
|
||||
(readword 10 w a))
|
||||
(#t (readword (getchar) (append w (cons c '())) a))))
|
||||
(#t (readword (getchar) (append w (cons c '())) a))))
|
||||
|
||||
(define (readblock c)
|
||||
;; (display 'mes-readblock:)
|
||||
;; (display c)
|
||||
;; (newline)
|
||||
(cond ((eq c 33) (cond ((eq (peekchar) 35) (getchar))
|
||||
(#t (readblock (getchar)))))
|
||||
(#t (readblock (getchar)))))
|
||||
|
||||
(define (eat-whitespace)
|
||||
(cond ((eq (peekchar) 10) (getchar) (eat-whitespace))
|
||||
((eq (peekchar) 32) (getchar) (eat-whitespace))
|
||||
((eq (peekchar) 35) (getchar) (eat-whitespace))
|
||||
(#t #t)))
|
||||
|
||||
(define (readlis a)
|
||||
(display 'mes-readlis:)
|
||||
(newline)
|
||||
;; (display 'mes-readlis:)
|
||||
;; (newline)
|
||||
(eat-whitespace)
|
||||
(cond ((eq (peekchar) 41) ;; )
|
||||
(getchar)
|
||||
'())
|
||||
|
|
Loading…
Reference in a new issue