summaryrefslogtreecommitdiff
path: root/support/schemetex/reader.tex
blob: 631c38d5c9466eaa3dc7108d67a36e2a211e91af (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
45
\documentstyle[astyped]{article}
% @(#)reader.st 1.3 88/06/30
\title{{\tt read-st}}
\author{John D. Ramsdell}
\date{
88/06/30
}

\begin{document}

\maketitle

\verb;read-st; converts Scheme\TeX{} representations of Scheme objects
into the objects themselves much as \verb;read; does.  It uses the
non-standard, but generally available routine \verb;peek-char;.
\begin{astyped}
(define (read-st . rest)                \notastyped{; Returns what \verb;read; returns.}
  (let ((port (if (pair? rest)          \notastyped{; \verb;read-st; arguments are}
                  (car rest)            \notastyped{; the same as \verb;read;'s.}
                  (current-input-port))))
    (letrec                             \notastyped{; Lines of a Scheme\TeX{} file}
        (((text-mode-and-saw-newline)   \notastyped{; beginning with ``{\tt(}'', }
          (let ((ch (peek-char port)))  \notastyped{; start a code section.}
            (cond ((eof-object? ch) ch)
                  ((char=? ch \verb-#-\verb-\-()      \notastyped{; If code section, then use}
                   (got-code (read port))) \notastyped{; \verb;read; to get code,}
                  (else                 \notastyped{; else skip this line as}
                   (text-mode-within-a-line))))) \notastyped{; it is a comment.}
         ((text-mode-within-a-line)     
          (let ((ch (read-char port)))
            (cond ((eof-object? ch) ch)
                  ((char=? ch \verb-#-\verb-\-newline)
                   (text-mode-and-saw-newline))
                  (else (text-mode-within-a-line)))))
         ((got-code code)               \notastyped{; Ignore the remainder of the }
          (let ((ch (read-char port)))  \notastyped{; last code line and return}
            (cond ((eof-object? ch) code) \notastyped{;  the results of \verb;read;.}
                  ((char=? ch \verb-#-\verb-\-newline)
                   code)
                  (else (got-code code))))))
      (text-mode-and-saw-newline)       \notastyped{; Start by looking }
      )))                               \notastyped{; for a code line.}
\end{astyped}
\end{document}