diff --git a/regexp.rkt b/regexp.rkt index f5b4b39..c436496 100644 --- a/regexp.rkt +++ b/regexp.rkt @@ -84,6 +84,7 @@ [(f pat-stx arg* ...) #:with pat-stx+ (expand-expr #'pat-stx) #:with (num-groups . T) (count-groups #'pat-stx+) + #:when (syntax-e #'num-groups) #:with (index* ...) #`#,(for/list ([i (in-range (syntax-e #'num-groups))]) i) #'(let ([maybe-match (regexp-match pat-stx+ arg* ...)]) (if maybe-match @@ -106,15 +107,6 @@ (format "Valid regexp pattern (contains unmatched ~a)" reason) str)) -(define-for-syntax (quoted-stx-value? stx) - (and - (syntax? stx) - (let ([v (syntax-e stx)]) - (and - (list? v) - (free-identifier=? (car v) (syntax/loc stx quote)) - (syntax-e (cadr v)))))) - (define-for-syntax (count-groups v-stx) (cond [(syntax-property v-stx num-groups-key) @@ -163,6 +155,9 @@ (eq? #\\ (string-ref str (+ i 1)))) (loop (+ i 3) in-paren num-groups) (loop (+ i 2) in-paren num-groups))] + [(#\|) + ;; Nope! Can't handle pipes + #f] [else (loop (+ i 1) in-paren num-groups)])))) diff --git a/test/regexp-fail.rkt b/test/regexp-fail.rkt index e215159..69db9ba 100644 --- a/test/regexp-fail.rkt +++ b/test/regexp-fail.rkt @@ -43,6 +43,11 @@ (define rx "he(l*)(o*)") (regexp-match: rx "helloooooooo")) (U #f (List String String String)))) + ;; --- Can't handle |, yet + (module t typed/racket/base (require trivial/regexp) + (ann + (regexp-match: "this(group)|that" "that") + (U #f (List String String)))) ))) (module+ test diff --git a/test/regexp-pass.rkt b/test/regexp-pass.rkt index e3619ab..1783634 100644 --- a/test/regexp-pass.rkt +++ b/test/regexp-pass.rkt @@ -247,4 +247,13 @@ (U #f (List Bytes Bytes Bytes))) '(#"hellooo" #"ll" #"ooo")) + ;; -- special cases / miscellaneous + + ;; --- Can't handle |, yet + (check-equal? + (ann + (regexp-match: "this(group)|that" "that") + (U #f (Listof (U #f String)))) + '("that" #f)) + )