#lang scheme/base
(require "depend.ss"
"input.ss"
"primitive.ss"
"combinator.ss"
)
(define (make-reader parser #:sof? (sof? #t) #:eof? (eof? #t) #:default (default #f))
(lambda (in #:sof? (sof? sof?) #:eof? (eof? eof?) #:default (default default))
(let-values (((v in)
((seq (if sof? SOF (return #t))
v <- parser
(if eof? EOF (return #t))
(return v)) (make-input in))))
(unless (failed? v) (read-bytes* in))
(if (failed? v)
default
v))))
(define Reader/c (->* (Input/c)
(#:sof? boolean? #:eof? boolean? #:default any/c)
any))
(provide Reader/c)
(provide/contract
(make-reader (->* (Parser/c)
(#:sof? boolean? #:eof? boolean? #:default any/c)
Reader/c))
)