lex & parse the operator

pull/6/head
Matthew Butterick 6 years ago
parent 6090359cf3
commit a5dce2c55e

@ -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))]

@ -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)

Loading…
Cancel
Save