Specify names of missing fields for match on structs

This commit is contained in:
Mira Leung 2015-04-29 22:17:24 -07:00 committed by Sam Tobin-Hochstadt
parent 22adc0253b
commit 56ea9f8b9a

View File

@ -125,13 +125,32 @@
=> =>
(lambda (ps) (lambda (ps)
(unless (= (length ps) (length acc)) (unless (= (length ps) (length acc))
(when (< (length acc) (length ps))
(raise-syntax-error (raise-syntax-error
'match 'match
(format "~a structure ~a: expected ~a but got ~a" (format "~a structure ~a: expected ~a but got ~a"
"wrong number for fields for" "excess number of fields for"
(syntax->datum struct-name) (length acc) (syntax->datum struct-name) (length acc)
(length ps)) (length ps))
stx pats)) stx pats))
(when (> (length acc) (length ps))
(raise-syntax-error
'match
(format
"~a structure ~a: expected ~a but got ~a; ~a ~a"
"insufficient number of fields for"
(syntax->datum struct-name) (length acc)
(length ps)
"missing fields"
(list-tail
(map (lambda (field)
(string->symbol
(substring (symbol->string (syntax->datum field))
(add1 (string-length
(symbol->string (syntax->datum struct-name)))))))
acc)
(length ps)))
stx pats)))
(map parse ps))] (map parse ps))]
[else (raise-syntax-error [else (raise-syntax-error
'match 'match