;;; Here documents in Scheme for scsh scripts. ;;; These are like "here documents" for sh and csh shell scripts ;;; (i.e., the < (lambda (line-start) (let ((text (cons line-start text)) (ls-len (string-length line-start))) (lp (if (char=? #\newline (string-ref line-start (- ls-len 1))) text (let ((line-rest (read-line port 'concat))) (if (eof-object? line-rest) (reading-error port "EOF while reading #< here-string.") (cons line-rest text)))))))) ;; We're done. The last line, tho, needs its newline ;; stripped off. ((null? text) "") (else (let* ((last-chunk (car text)) (lc-len (string-length last-chunk)) (last-chunk (substring last-chunk 0 (- lc-len 1))) (text (cons last-chunk (cdr text)))) (make-immutable! (apply string-append (reverse text))))))))))) ;;; If the next chars read from PORT match DELIM, return false. ;;; Otherwise, return the string you read from PORT to determine the non-match. ;;; If EOF is encountered, report an error. (define (delimiter-scan delim port) (let ((len (string-length delim))) (let lp ((i 0)) (and (< i len) (let ((c (read-char port))) (cond ((eof-object? c) (reading-error port "EOF while reading #< here string.")) ((char=? c (string-ref delim i)) (lp (+ i 1))) (else (string-append (substring delim 0 i) (string c))))))))) ;(define-sharp-macro #\< ; (lambda (c port) (read-here-string port)))