diff --git a/brag/rules/lexer.rkt b/brag/rules/lexer.rkt index 8665142..b5a485e 100755 --- a/brag/rules/lexer.rkt +++ b/brag/rules/lexer.rkt @@ -64,8 +64,11 @@ (token-SPLICE lexeme)] ["|" (token-PIPE lexeme)] - [(:or "+" "*") - (token-REPEAT lexeme)] + [(:or "+" "*" + ;; todo: consolidate next two patterns? + (:: "{" (:* digit) "}") + (:: "{" (:* digit) "," (:* digit) "}")) + (token-REPEAT (let () (println lexeme) lexeme))] [whitespace ;; Skip whitespace (return-without-pos (lex/1 input-port))] diff --git a/brag/rules/parser.rkt b/brag/rules/parser.rkt index 9d25117..05cfa9a 100755 --- a/brag/rules/parser.rkt +++ b/brag/rules/parser.rkt @@ -162,6 +162,12 @@ (pattern-repeat (position->pos $1-start-pos) (position->pos $2-end-pos) 1 $1)] + [(regexp-match #px"^\\{(\\d+)?,?(\\d+)?\\}$" $2) + => (λ (m) + (define pr (match m + [(list _ min max) (cons (and min (string->number min)) + (and max (string->number max)))])) + (error (format "~a" pr)))] [else (error 'grammar-parse "unknown repetition operator ~e" $2)])] [(atomic-pattern)