summaryrefslogtreecommitdiff
path: root/web/schemeweb/reader.sw
blob: fee7e1f6ec2453439d4ec096b4ed43dc1415d92c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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}