diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2016-08-14 19:25:26 +0200 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2016-08-14 19:25:26 +0200 |
commit | caae83f445935c06cd6aef36f283a4688675278a (patch) | |
tree | 5e63cbfd2877195430a8657dcd75f42b6a4d7110 /ebus-racket/3rdparty/bzlib/parseq/reader.ss | |
download | ebus-caae83f445935c06cd6aef36f283a4688675278a.tar.gz ebus-caae83f445935c06cd6aef36f283a4688675278a.zip |
refactored ebus code
Diffstat (limited to 'ebus-racket/3rdparty/bzlib/parseq/reader.ss')
-rw-r--r-- | ebus-racket/3rdparty/bzlib/parseq/reader.ss | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/ebus-racket/3rdparty/bzlib/parseq/reader.ss b/ebus-racket/3rdparty/bzlib/parseq/reader.ss new file mode 100644 index 0000000..50a5f9d --- /dev/null +++ b/ebus-racket/3rdparty/bzlib/parseq/reader.ss @@ -0,0 +1,41 @@ +#lang scheme/base +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; PARSEQ.PLT +;; A Parser Combinator library. +;; +;; Bonzai Lab, LLC. All rights reserved. +;; +;; Licensed under LGPL. +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; reader.ss - move make-reader & Reader/c here +;; yc 1/18/2010 - first version +;; yc 1/21/2010 - make-reader to take on additional default params +(require "depend.ss" + "input.ss" + "primitive.ss" + "combinator.ss" + (prefix-in c: scheme/contract) + ) +;; use this to create a reader that will read the bytes if the parse succeeds. +(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 (c:->* (Input/c) + (#:sof? boolean? #:eof? boolean? #:default c:any/c) + c:any)) +(provide Reader/c) +(c:provide/contract + (make-reader (c:->* (Parser/c) + (#:sof? boolean? #:eof? boolean? #:default c:any/c) + Reader/c)) + ) + |