From 83f16034b079ac7fc33c23b3cca283b359973478 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 10 Jun 2018 23:19:34 -0700 Subject: [PATCH] handle exact quantifier --- brag/rules/parser.rkt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/brag/rules/parser.rkt b/brag/rules/parser.rkt index a239eb0..f51f9f6 100755 --- a/brag/rules/parser.rkt +++ b/brag/rules/parser.rkt @@ -162,12 +162,17 @@ (pattern-repeat (position->pos $1-start-pos) (position->pos $2-end-pos) 1 #f $1)] - [(regexp-match #px"^\\{(\\d+)?,?(\\d+)?\\}$" $2) ; "{min,max}" with both min & max optional + [(regexp-match #px"^\\{(\\d+)?(,)?(\\d+)?\\}$" $2) ; "{min,max}" with both min & max optional => (λ (m) (match-define (list min-repeat max-repeat) (match m - [(list _ min max) (list (if min (string->number min) 0) - (and max (string->number max)))])) + [(list _ min range? max) (let ([min (if min (string->number min) 0)]) + (list + min + (cond + [(and range? max) (string->number max)] + [(and (not range?) (not max)) min] ; {3} -> {3,3} + [(not max) #f])))])) (pattern-repeat (position->pos $1-start-pos) (position->pos $2-end-pos) min-repeat max-repeat $1))]