chickadee » input-classes

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

input-classes

Description

input-classes provides type classes for input streams used by lexgen, abnf and related libraries. The typeclass interface is based on macros defined in the typeclass library.

An input stream type class contains three fields that define:

Thus the typeclass definition of an input stream is the following:

 (define-class <Input> 
   empty? 
   head 
   tail)

The simplest instantiation of class <Input uses lists:

 (define-class <Input> null? car cdr)

input-classes also defines a typeclass for extended input streams, which inherit from the basic input stream typeclass and provide an interface for converting strings and files to input streams.

The extended input stream is defined as follows:

 (define-class <Input+> (<Input> input) 
   find
   string->input-stream
   file->input-stream)

The find procedure must provide semantics to find all non-overlapping instances of its first argument that occur in the second argument. It must have the signature:

find :: <Input+> * <Input+> -> (<Input+>, [(<Input+>, <Input+>)])

An example of extended input streams based on strings is:

(define (string-car x) (string-ref x 0))

(define (string-cdr x) (string-drop x 1))

(define string-<Input>
  (make-<Input> string-null? string-car string-cdr))

(define string-<Input+>
  (make-<Input+> string-<Input> 
		 string-find
		 identity
		 (lambda (x . rest) (read-all x))
		 ))

Requires

Version History

License

 Copyright 2010-2012 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
 <http://www.gnu.org/licenses/>.