diff --git a/scheme/rts/read.scm b/scheme/rts/read.scm index 4d653d4..4f1ed92 100644 --- a/scheme/rts/read.scm +++ b/scheme/rts/read.scm @@ -41,6 +41,30 @@ ; 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 (define (read . port-option) @@ -259,6 +283,8 @@ (define-sharp-macro #\! script-skip) +(define-sharp-macro #\| multi-line-comment-skip) + ; Tokens (define (sub-read-token c port)