pull/6/head
Matthew Butterick 7 years ago
parent 98cb84bdcc
commit 46ddd5cfd4

@ -109,15 +109,17 @@
[(inferred-id NAME repeat) SUB-PAT ...]
MIN-REPEAT-SUB-PATS)
inferred-rules)))]
[(repeat MIN MAX SUB-PAT)
;; finite repeat
(let ([min (syntax-e #'MIN)]
[max (syntax-e #'MAX)])
(recur
(with-syntax ([(MIN-SUBPAT ...) (make-list min #'SUB-PAT)]
(begin
(define min (syntax-e #'MIN))
(define max (syntax-e #'MAX))
(define new-rule-stx (with-syntax ([(MIN-SUBPAT ...) (make-list min #'SUB-PAT)]
[(EXTRA-SUBPAT ...) (make-list (- max min) #'SUB-PAT)])
#'(rule NAME (seq MIN-SUBPAT ... (maybe EXTRA-SUBPAT) ...)))
#f))]
;; has to keep the same name to work correctly
#'(rule NAME (seq MIN-SUBPAT ... (maybe EXTRA-SUBPAT) ...))))
(recur new-rule-stx #f))]
[(maybe SUB-PAT)
(begin

@ -164,9 +164,9 @@
1 #f $1)]
[(regexp-match #px"^\\{(\\d+)?,?(\\d+)?\\}$" $2) ; "{min,max}" with both min & max optional
=> (λ (m)
(match-define (cons min-repeat max-repeat)
(match-define (list min-repeat max-repeat)
(match m
[(list _ min max) (cons (if min (string->number min) 0)
[(list _ min max) (list (if min (string->number min) 0)
(and max (string->number max)))]))
(pattern-repeat (position->pos $1-start-pos)
(position->pos $2-end-pos)

Loading…
Cancel
Save