From 2896ea5eeb96e7e915b97b050cea87f5bd920fd2 Mon Sep 17 00:00:00 2001 From: Jack Firth Date: Thu, 31 Mar 2022 19:36:28 -0700 Subject: [PATCH] Use `match-define` --- codegen/runtime.rkt | 15 +++++++-------- rules/parser.rkt | 18 +++++++++--------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/codegen/runtime.rkt b/codegen/runtime.rkt index 80e72fd..5455346 100644 --- a/codegen/runtime.rkt +++ b/codegen/runtime.rkt @@ -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)) diff --git a/rules/parser.rkt b/rules/parser.rkt index 5229f35..b058564 100644 --- a/rules/parser.rkt +++ b/rules/parser.rkt @@ -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)