Use `match-define`

remotes/jackfirth/master
Jack Firth 3 years ago
parent c339773860
commit 2896ea5eeb

@ -20,14 +20,13 @@
;; function value for the error handler up front. We want to delay that decision
;; till parse time.
(define (the-error-handler tok-ok? tok-name tok-value start-pos end-pos)
(match (positions->srcloc start-pos end-pos)
[(list src line col offset span)
((current-parser-error-handler) tok-name
tok-value
offset
line
col
span)]))
(match-define (list src line col offset span) (positions->srcloc start-pos end-pos))
((current-parser-error-handler) tok-name
tok-value
offset
line
col
span))

@ -165,15 +165,15 @@
[(string=? $2 "?") (cons 0 1)]
[(regexp-match #px"^\\{(\\d+)?(,)?(\\d+)?\\}$" $2) ; "{min,max}" with both min & max optional
=> (λ (m)
(match m
[(list all min range? max) (let* ([min (if min (string->number min) 0)]
[max (cond
[(and range? max) (string->number max)]
[(not (or range? max)) (if (zero? min)
#f ; {} -> {0,}
min)] ; {3} -> {3,3}
[else #f])])
(cons min max))]))]
(match-define (list all min range? max) m)
(let* ([min (if min (string->number min) 0)]
[max (cond
[(and range? max) (string->number max)]
[(not (or range? max)) (if (zero? min)
#f ; {} -> {0,}
min)] ; {3} -> {3,3}
[else #f])])
(cons min max)))]
[else (raise-argument-error 'grammar-parse "unknown repetition operator" $2)]))
(pattern-repeat (position->pos $1-start-pos)
(position->pos $2-end-pos)

Loading…
Cancel
Save