1. input-classes
    1. Description
    2. Requires
    3. Version History
    4. License

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/>.