diff --git a/brag/codegen/flatten.rkt b/brag/codegen/flatten.rkt index 89ab7b2..74f8a0a 100755 --- a/brag/codegen/flatten.rkt +++ b/brag/codegen/flatten.rkt @@ -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)] - [(EXTRA-SUBPAT ...) (make-list (- max min) #'SUB-PAT)]) - #'(rule NAME (seq MIN-SUBPAT ... (maybe EXTRA-SUBPAT) ...))) - #f))] + (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)]) + ;; 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 diff --git a/brag/rules/parser.rkt b/brag/rules/parser.rkt index 75f33ad..a239eb0 100755 --- a/brag/rules/parser.rkt +++ b/brag/rules/parser.rkt @@ -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)