diff options
Diffstat (limited to 'web/schemeweb/reader.sw')
-rw-r--r-- | web/schemeweb/reader.sw | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/web/schemeweb/reader.sw b/web/schemeweb/reader.sw new file mode 100644 index 0000000000..fee7e1f6ec --- /dev/null +++ b/web/schemeweb/reader.sw @@ -0,0 +1,44 @@ +\documentstyle{article} +% $Id: reader.sw,v 2.0 1994/02/25 14:03:14 ramsdell Exp $ +\title{{\tt read-sw}} +\author{John D. Ramsdell} +\date{\verb$Date: 1994/02/25 14:03:14 $} + +\newcommand{\schemeweb}{Scheme{\tt WEB}} + +\begin{document} + +\maketitle + +\verb|read-sw| reads a {\schemeweb} source file +much as \verb|read| reads a Scheme source file. +(define (read-sw . rest) ; Returns what \verb|read| returns. + (let ((port (if (pair? rest) ; \verb|read-sw| arguments are + (car rest) ; the same as \verb|read|'s. + (current-input-port)))) + (letrec + ((text-mode-and-saw-newline ; Lines of a {\schemeweb} file + (lambda () ; beginning with ``{\tt(}'', + (let ((ch (peek-char port))) ; start a code section. + (cond ((eof-object? ch) ch) + ((char=? ch #\() ; If code section, then use + (got-code (read port))) ; \verb|read| to get code, + (else ; else skip this line as it + (text-mode-within-a-line)))))) ; is a comment. + (text-mode-within-a-line + (lambda () ; Ignore comments. + (let ((ch (read-char port))) + (cond ((eof-object? ch) ch) + ((char=? ch #\newline) + (text-mode-and-saw-newline)) + (else (text-mode-within-a-line)))))) + (got-code + (lambda (code) ; Ignore the remainder of the + (let ((ch (read-char port))) ; last code line and return + (cond ((eof-object? ch) code) ; the results of \verb|read|. + ((char=? ch #\newline) + code) + (else (got-code code))))))) + (text-mode-and-saw-newline) ; Start by looking + ))) ; for a code line. +\end{document} |