#!/usr/local/bin/scsh \ -o srfi-6 -s ;;; (Yet Another) Scheme-embedded-in-HTML preprocessor ;;; $Id: spp.scm,v 1.2 2002/07/02 08:07:52 tjaden Exp $ !# ;; Read Scheme-embedded-HTML from port and returns a list of forms ;; to be evaluated that will produce the output. (define (process port) (let ((x (read-char port))) (if (eof-object? x) '() (if (and (char=? x #\,) (not (char-whitespace? (peek-char port)))) (cons (read port) (process port)) (let ((s (collect-string port x))) (if (string=? s (string #\newline)) ;aesthetic reasons (process port) (cons `(display ,s) (process port)))))))) ;; Helper to collect plain text up to the next , or EOF. (define (collect-string port initial) (let ((s (open-output-string))) (display initial s) (let lp ((y (peek-char port))) (if (or (eof-object? y) (char=? y #\,)) (get-output-string s) (begin (display (read-char port) s) (lp (peek-char port))))))) (cond ((null? command-line-arguments) (format (error-output-port) "usage: ~A input-file~%" (argv 0)) (exit 1))) (eval `(begin (define *input-file-name* ,(car command-line-arguments)) ,@(call-with-input-file (car command-line-arguments) process)) (interaction-environment))