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)
(unless (= (length ps) (length acc))
(raise-syntax-error
'match
(format "~a structure ~a: expected ~a but got ~a"
"wrong number for fields for"
(syntax->datum struct-name) (length acc)
(length ps))
stx pats))
(when (< (length acc) (length ps))
(raise-syntax-error
'match
(format "~a structure ~a: expected ~a but got ~a"
"excess number of fields for"
(syntax->datum struct-name) (length acc)
(length ps))
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))]
[else (raise-syntax-error
'match