Rename #:gap-select' -> #:gap-select?' and some minor doc fixes.

This commit is contained in:
Eli Barzilay 2012-04-17 15:56:10 -04:00
parent a14569bfe3
commit 1c9de39348
3 changed files with 27 additions and 17 deletions

View File

@ -240,7 +240,9 @@
;; Returns all the positions at which the pattern matched.
(define (regexp-match-positions* pattern string [start 0] [end #f] [ipre #""]
#:match-select [match-select car])
;; Note: no need for a #:gap-select, since it is easily inferred from the
(unless (procedure? match-select)
(raise-type-error 'regexp-match-positions* "procedure" match-select))
;; Note: no need for a #:gap-select?, since it is easily inferred from the
;; resulting matches
(if (eq? match-select car)
;; common case
@ -297,6 +299,8 @@
(define (regexp-match-peek-positions* pattern string [start 0] [end #f]
[ipre #""]
#:match-select [match-select car])
(unless (procedure? match-select)
(raise-type-error 'regexp-match-peek-positions* "procedure" match-select))
(if (eq? match-select car)
;; common case
(regexp-loop regexp-match-peek-positions* loop start end pattern string ipre
@ -466,7 +470,7 @@
;; other submatches and/or gap strings too.
(define (regexp-match* pattern string [start 0] [end #f] [ipre #""]
#:match-select [match-select car]
#:gap-select [gap-select #f])
#:gap-select? [gap-select #f])
(cond
;; nonsensical case => throw an error
[(and (not match-select) (not gap-select))
@ -480,6 +484,8 @@
(current-continuation-marks)))]
;; no match-select => same as `regexp-split'
[(not match-select) (regexp-split pattern string start end ipre)]
[(not (procedure? match-select))
(raise-type-error 'regexp-match* "procedure-or-#f" match-select)]
;; uncommon case => full code
[(not (eq? match-select car))
(define-values [buf sub] (get-buf+sub string pattern))

View File

@ -402,10 +402,10 @@ bytes. To avoid such interleaving, use @racket[regexp-match-peek]
[end-pos (or/c exact-nonnegative-integer? #f) #f]
[input-prefix bytes? #""]
[#:match-select match-select
(or/c ((listof any?) . -> . (or/c any? (listof any?)))
(or/c (list? . -> . (or/c any/c list?))
#f)
car]
[#:gap-select gap-select boolean? #f])
[#:gap-select? gap-select any/c #f])
(if (and (or (string? pattern) (regexp? pattern))
(or (string? input) (path? input)))
(listof (or/c string? (listof (or/c #f string?))))
@ -462,8 +462,8 @@ return @emph{only} the separators, making such uses equivalent to
@racket[regexp-split].
@examples[
(regexp-match* #rx"x(.)" "12x4x6" #:match-select cadr #:gap-select #t)
(regexp-match* #rx"x(.)" "12x4x6" #:match-select #f #:gap-select #t)
(regexp-match* #rx"x(.)" "12x4x6" #:match-select cadr #:gap-select? #t)
(regexp-match* #rx"x(.)" "12x4x6" #:match-select #f #:gap-select? #t)
]}
@ -528,7 +528,7 @@ positions indicate the number of bytes that were read, including
[end-pos (or/c exact-nonnegative-integer? #f) #f]
[input-prefix bytes? #""]
[#:match-select match-select
((listof any?) . -> . (or/c any? (listof any?)))
(list? . -> . (or/c any/c list?))
car])
(or/c (listof (cons/c exact-nonnegative-integer?
exact-nonnegative-integer?))
@ -544,7 +544,7 @@ like @racket[regexp-match*].
]
Note that unlike @racket[regexp-match*], there is no
@racket[#:gap-select] input keyword, as this information can be easily
@racket[#:gap-select?] input keyword, as this information can be easily
inferred from the resulting matches.
}
@ -661,11 +661,15 @@ blocking. The match fails if not-yet-available characters might be
used to match @racket[pattern].}
@defproc[(regexp-match-peek-positions* [pattern (or/c string? bytes? regexp? byte-regexp?)]
@defproc[(regexp-match-peek-positions*
[pattern (or/c string? bytes? regexp? byte-regexp?)]
[input input-port?]
[start-pos exact-nonnegative-integer? 0]
[end-pos (or/c exact-nonnegative-integer? #f) #f]
[input-prefix bytes? #""])
[input-prefix bytes? #""]
[#:match-select match-select
(list? . -> . (or/c any/c list?))
car])
(or/c (listof (cons/c exact-nonnegative-integer?
exact-nonnegative-integer?))
(listof (listof (or/c #f (cons/c exact-nonnegative-integer?

View File

@ -87,7 +87,7 @@
(for ([cvt (in-list (list values byte-regexp byte-pregexp))])
(test '(#"\x80" #"\x80") regexp-match* (cvt #"\x80") #"a\x80z\x80q"))
;; --------------------
(define (regexp-explode . xs) (apply regexp-match* #:gap-select #t xs))
(define (regexp-explode . xs) (apply regexp-match* #:gap-select? #t xs))
(t regexp-explode)
(t '(" " "a" " " "b" " " "c" " ") eof "[abc]" " a b c ")
(t '("" "a" "+" "b" " = " "c" " ") eof "[abc]" "a+b = c ")
@ -114,10 +114,10 @@
regexp-explode (cvt #"\x80") #"a\x80z\x80q"))
;; --------------------
(t regexp-match*) ; some tests with a match-select etc
;; (tests with #f for #:match-select and #t for #:gap-select done below with
;; (tests with #f for #:match-select and #t for #:gap-select? done below with
;; `regexp-split')
(err/rt-test (regexp-match* "[abc]" "a b c"
#:match-select #f #:gap-select #f))
#:match-select #f #:gap-select? #f))
(t '("a" "b" "c") eof
"<([abc])>" "<a> <b> <c>" #:match-select cadr)
(t '(("a") ("b") ("c")) eof
@ -125,11 +125,11 @@
(t '(("<a>" "a") ("<b>" "b") ("<c>" "c")) eof
"<([abc])>" "<a> <b> <c>" #:match-select values)
(t '("" "a" " + " "b" " = " "c" "") eof
"<([abc])>" "<a> + <b> = <c>" #:match-select cadr #:gap-select #t)
"<([abc])>" "<a> + <b> = <c>" #:match-select cadr #:gap-select? #t)
(t '("" ("<a>" "a") " + " ("<b>" "b") " = " ("<c>" "c") "") eof
"<([abc])>" "<a> + <b> = <c>" #:match-select values #:gap-select #t)
"<([abc])>" "<a> + <b> = <c>" #:match-select values #:gap-select? #t)
(t '("" ("<a" "a" #f) " + " ("<b" "b" #f) " = " ("<c" "c" #f) "") eof
"<([abc])(>)?" "<a + <b = <c" #:match-select values #:gap-select #t)
"<([abc])(>)?" "<a + <b = <c" #:match-select values #:gap-select? #t)
;; --------------------
(t (list regexp-match-positions*
;; also try the generic path
@ -195,7 +195,7 @@
(t (list regexp-split
;; also via an equivalent `regexp-match*' configuration
(lambda xs
(apply regexp-match* xs #:match-select #f #:gap-select #t))))
(apply regexp-match* xs #:match-select #f #:gap-select? #t))))
(t '("1" "2" "3" "4") eof "[abc]" "1a2b3c4")
(t '("2" "3" "4") eof "[abc]" "1a2b3c4" 2)
(t '("" "3" "4") eof "[abc]" "1a2b3c4" 3)