add argument to `regexp-try-match' to match docs

Closes PR 6579 --- which was actually about the
 now next-to-last argument, but close enough
This commit is contained in:
Matthew Flatt 2011-01-17 13:53:58 -07:00
parent 70e3074baf
commit d5fdee7e06
2 changed files with 14 additions and 2 deletions

View File

@ -87,14 +87,14 @@
(or (hash-ref t key #f) (or (hash-ref t key #f)
(let ([rx* (run-tweak)]) (hash-set! t key rx*) rx*)))))) (let ([rx* (run-tweak)]) (hash-set! t key rx*) rx*))))))
(define (regexp-try-match pattern input-port [start-k 0] [end-k #f] [out #f]) (define (regexp-try-match pattern input-port [start-k 0] [end-k #f] [out #f] [prefix #""])
(unless (input-port? input-port) (unless (input-port? input-port)
(raise-type-error 'regexp-try-match (raise-type-error 'regexp-try-match
"input port" input-port)) "input port" input-port))
(unless (or (not out) (output-port? out)) (unless (or (not out) (output-port? out))
(raise-type-error 'regexp-try-match (raise-type-error 'regexp-try-match
"output port or #f" out)) "output port or #f" out))
(let ([m (regexp-match-peek-positions pattern input-port start-k end-k)]) (let ([m (regexp-match-peek-positions pattern input-port start-k end-k #f prefix)])
(and m (and m
;; What happens if someone swipes our bytes before we can get them? ;; What happens if someone swipes our bytes before we can get them?
(let ([drop (caar m)]) (let ([drop (caar m)])

View File

@ -39,6 +39,18 @@
(test #f regexp-match/fail-without-reading #rx"hello there!!!" s) (test #f regexp-match/fail-without-reading #rx"hello there!!!" s)
(test "hello there" read-string 50 s)) (test "hello there" read-string 50 s))
;; Check remaining `regexp-match/fail-without-reading' arguments
(let ([s (open-input-string "hello there")]
[o (open-output-bytes)])
(test #f regexp-match/fail-without-reading #rx"not there" s 0 5 o)
(test #"" get-output-bytes o)
(test #f regexp-match/fail-without-reading #rx"^hello" s 1 #f o)
(test #"" get-output-bytes o)
(test #f regexp-match/fail-without-reading #rx"^hello" s 0 #f o #"_")
(test #"" get-output-bytes o)
(test '(#"ello") regexp-match/fail-without-reading #rx"ello" s 0 #f o)
(test #"h" get-output-bytes o))
(let ([g->re-test (let ([g->re-test
(lambda (glob . more) (lambda (glob . more)
(let ([re (apply glob->regexp glob more)]) (let ([re (apply glob->regexp glob more)])