[regexp] do nothing for regexp or-patterns (|)

This commit is contained in:
ben 2015-12-13 21:42:16 -05:00
parent 13f44e3d78
commit 8777de17b8
3 changed files with 18 additions and 9 deletions

View File

@ -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)]))))

View File

@ -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

View File

@ -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))
)