Added nested multi-line comments. The implementation has two

drawbacks:
1.) Since # and | may be part of an identifier, a#|bla|# is
read as a#|bla|# not as a.

2.) The REPL won't read a comment for its own, it will wait for
another value:
>#|bla|#

3
3
>
This commit is contained in:
mainzelm 2001-01-12 18:16:42 +00:00
parent eb89a60d2c
commit 9035313159
1 changed files with 26 additions and 0 deletions

View File

@ -41,6 +41,30 @@
; was sub-read ^ ; was sub-read ^
(define (multi-line-comment-skip c port)
(read-char port)
(let lp ((state 0) (nested? #f))
(let* ((advance-one-of-two
(lambda (look-for1 state1 look-for2 state2 nested?)
(let ((c (read-char port)))
(if (eof-object? c)
(error
"EOF inside block comment -- #| missing a closing |#")
(lp (cond ((char=? c look-for1) state1)
((char=? c look-for2) state2)
(else 0)) nested?)))))
(advance-if (lambda (look-for state nested?)
(advance-one-of-two look-for state
look-for state
nested?))))
(case state
((0) (advance-one-of-two #\| 1 #\# 5 nested?))
((1) (advance-if #\# 2 nested?))
((2) (if nested? #f (sub-read port)))
((5) (advance-if #\| 6 nested?))
((6) (lp 0 #t) (lp 0 nested?))))))
; scsh stop ; scsh stop
(define (read . port-option) (define (read . port-option)
@ -259,6 +283,8 @@
(define-sharp-macro #\! script-skip) (define-sharp-macro #\! script-skip)
(define-sharp-macro #\| multi-line-comment-skip)
; Tokens ; Tokens
(define (sub-read-token c port) (define (sub-read-token c port)