Fix PR 10119.

Give better error messages from `match*' when patterns or expressions are not lists.

svn: r14036
This commit is contained in:
Sam Tobin-Hochstadt 2009-03-10 21:06:43 +00:00
parent 79ee9fbee8
commit 56a3867644
2 changed files with 25 additions and 3 deletions

View File

@ -20,8 +20,14 @@
[(_ es . clauses)
(go parse-id stx #'es #'clauses (syntax-local-certifier))]))
(define-syntax-rule (match arg [p . es] ...)
(match* (arg) [(p) . es] ...))
(define-syntax (match stx)
(syntax-case stx ()
[(match arg cl ...)
(with-syntax ([clauses
(for/list ([c (syntax->list #'(cl ...))])
(syntax-case c ()
[[p . es] (syntax/loc c [(p) . es])]))])
(syntax/loc stx (match* (arg) . clauses)))]))
(define-syntax (match-lambda stx)
(syntax-case stx ()

View File

@ -13,6 +13,11 @@
[([pats . rhs] ...)
(nest
([parameterize ([orig-stx stx])]
[begin (unless (syntax->list exprs)
(raise-syntax-error
'match*
"expected a sequence of expressions to match"
exprs))]
[let ([len (length (syntax->list exprs))])]
[with-syntax ([(xs ...) (generate-temporaries exprs)]
[(exprs ...) exprs]
@ -21,9 +26,20 @@
([body
(compile*
(syntax->list #'(xs ...))
(for/list ([pats (syntax->list #'(pats ...))]
(for/list ([clause (syntax->list clauses)]
[pats (syntax->list #'(pats ...))]
[rhs (syntax->list #'(rhs ...))])
(unless (list? pats)
(raise-syntax-error
'match*
"expected a sequence of patterns"
pats))
(let ([lp (length (syntax->list pats))])
(when (null? (syntax->list rhs))
(raise-syntax-error
'match
"expected at least one expression on the right-hand side"
clause))
(unless (= len lp)
(raise-syntax-error
'match