;; ;; Type classes and transformer functions for input streams used by ;; lexgen/abnf and related libraries. ;; ;; Copyright 2010 Ivan Raikov and the Okinawa Institute of ;; Science and Technology. ;; ;; ;; This program is free software: you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation, either version 3 of the ;; License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; A full copy of the GPL license can be found at ;; . (module input-classes ( make- make- make- entity-data->input-port ) (import scheme chicken ports) (require-extension typeclass) ;; input stream type class (define-class empty? head tail) ;; extended input stream type class (define-class ( input) find string->input-stream file->input-stream) ;; entity data type class (for MIME) (define-class ( input) data->list list->data take drop append ) (define=> (entity-data->input-port ) (lambda (d) (make-input-port ;; read (lambda () (let ((v (head d))) (set! d (tail d)) v)) ;; ready? (lambda () (and d (not (empty? d)))) ;; close (lambda () (set! d #f)) ;; peek (lambda () (head d))))) )