diff --git a/brag/brag.scrbl b/brag/brag.scrbl index f98df92..9499743 100755 --- a/brag/brag.scrbl +++ b/brag/brag.scrbl @@ -1080,19 +1080,23 @@ In addition to the exports shown below, the @racketmodname[brag/support] module DrRacket should highlight the offending locations in the source.} - -@defproc[(apply-tokenizer-maker [tokenizer-maker procedure?] - [source (or/c string? - input-port?)]) +@defproc[(apply-port-proc [proc procedure?] + [port (or/c string? input-port?) (current-input-port)]) list?]{ - Repeatedly apply @racket[tokenizer-maker] to @racket[source], gathering the resulting tokens into a list. @racket[source] can be a string or an input port. Useful for testing or debugging a tokenizer. + Repeatedly apply @racket[proc] to @racket[port], gathering the results into a list. @racket[port] can be an input port or a string (which is converted to a string port). Useful for testing or debugging a lexer or tokenizer. } @defproc[(apply-lexer [lexer procedure?] - [source (or/c string? - input-port?)]) + [port (or/c string? input-port?) (current-input-port)]) + list?]{ +Alias for @racket[apply-port-proc]. +} + + +@defproc[(apply-tokenizer-maker [tokenizer-maker procedure?] + [port (or/c string? input-port?) (current-input-port)]) list?]{ - Repeatedly apply @racket[lexer] to @racket[source], gathering the resulting tokens into a list. @racket[source] can be a string or an input port. Useful for testing or debugging a lexer. + Repeatedly apply @racket[tokenizer-maker] to @racket[port], gathering the resulting tokens into a list. @racket[port] can be an input port or a string (which is converted to a string port). } diff --git a/brag/support.rkt b/brag/support.rkt index 1af6ddf..b25a1fb 100755 --- a/brag/support.rkt +++ b/brag/support.rkt @@ -60,14 +60,15 @@ (exn:fail:parsing-srclocs instance))) -(provide apply-lexer) -(define (apply-lexer lexer val) - (for/list ([t (in-port lexer (if (string? val) (open-input-string val) val))]) +(provide (rename-out [apply-port-proc apply-lexer]) + apply-port-proc) +(define (apply-port-proc proc [val (current-input-port)]) + (for/list ([t (in-port proc (if (string? val) (open-input-string val) val))]) t)) (provide apply-tokenizer-maker (rename-out [apply-tokenizer-maker apply-tokenizer])) -(define (apply-tokenizer-maker tokenize in) +(define (apply-tokenizer-maker tokenize [in (current-input-port)]) (define input-port (if (string? in) (open-input-string in) in))