[regexp] linear-time group unpacking, hooray for mutability
This commit is contained in:
parent
2b1ab27825
commit
c5ea8c032c
18
regexp.rkt
18
regexp.rkt
|
@ -45,15 +45,15 @@
|
|||
(syntax-parser
|
||||
[(f pat-stx arg* ...)
|
||||
#:with num-groups (count-groups #'pat-stx #:src #'f)
|
||||
#:with ((index* . group-id*) ...)
|
||||
#`#,(for/list ([i (in-range (syntax-e #'num-groups))])
|
||||
(cons i (format-id #'f "group-~a" i)))
|
||||
;; Chaining list-ref?
|
||||
#'(let ([m (regexp-match pat-stx arg* ...)])
|
||||
(if m
|
||||
(let ([group-id* (or (list-ref m index*) (error 'regexp-match! "Internal error, try Racket's `regexp-match`"))] ...)
|
||||
(list (car m) group-id* ...))
|
||||
m))]
|
||||
#:with (index* ...) #`#,(for/list ([i (in-range (syntax-e #'num-groups))]) i)
|
||||
#'(let ([maybe-match (regexp-match pat-stx arg* ...)])
|
||||
(if maybe-match
|
||||
(let ([m : (Listof (Option String)) maybe-match])
|
||||
(list (car maybe-match)
|
||||
(begin (set! m (cdr m))
|
||||
(or (car m) (error 'regexp-match! (format "Internal error at result index ~a, try Racket's regexp-match" index*))))
|
||||
...))
|
||||
#f))]
|
||||
[(f arg* ...)
|
||||
(syntax/loc #'f (regexp-match arg* ...))]))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user