diff --git a/collects/racket/private/string.rkt b/collects/racket/private/string.rkt index 76bdaad44e..df4e844e5f 100644 --- a/collects/racket/private/string.rkt +++ b/collects/racket/private/string.rkt @@ -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)) diff --git a/collects/scribblings/reference/regexps.scrbl b/collects/scribblings/reference/regexps.scrbl index 411953812b..4fe3307ce7 100644 --- a/collects/scribblings/reference/regexps.scrbl +++ b/collects/scribblings/reference/regexps.scrbl @@ -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? diff --git a/collects/tests/racket/string.rktl b/collects/tests/racket/string.rktl index a580b4f2d7..ac41eb5317 100644 --- a/collects/tests/racket/string.rktl +++ b/collects/tests/racket/string.rktl @@ -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])>" " " #:match-select cadr) (t '(("a") ("b") ("c")) eof @@ -125,11 +125,11 @@ (t '(("" "a") ("" "b") ("" "c")) eof "<([abc])>" " " #:match-select values) (t '("" "a" " + " "b" " = " "c" "") eof - "<([abc])>" " + = " #:match-select cadr #:gap-select #t) + "<([abc])>" " + = " #:match-select cadr #:gap-select? #t) (t '("" ("" "a") " + " ("" "b") " = " ("" "c") "") eof - "<([abc])>" " + = " #:match-select values #:gap-select #t) + "<([abc])>" " + = " #:match-select values #:gap-select? #t) (t '("" (")?" ")?" "