From caae83f445935c06cd6aef36f283a4688675278a Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sun, 14 Aug 2016 19:25:26 +0200 Subject: refactored ebus code --- ebus-racket/3rdparty/bzlib/parseq/reader.ss | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ebus-racket/3rdparty/bzlib/parseq/reader.ss (limited to 'ebus-racket/3rdparty/bzlib/parseq/reader.ss') 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)) + ) + -- cgit v1.2.1