better error reporting when a top-level form is wrong

svn: r18575
This commit is contained in:
Matthew Flatt 2010-03-18 14:43:38 +00:00
parent d761a0236a
commit 92487ed9e2

View File

@ -59,4 +59,40 @@
#%provide))))
#`(begin #,expanded (doc-begin m-id post-process exprs . body))]
[_else
#`(doc-begin m-id post-process (#,expanded . exprs) . body)])))]))]))
#`(doc-begin m-id post-process
((pre-part #,expanded body1) . exprs)
. body)])))]))]))
(define-syntax (pre-part stx)
(syntax-case stx ()
[(_ s e)
(if (string? (syntax-e #'s))
#'s
(with-syntax ([src (syntax-source #'e)]
[line (syntax-line #'e)]
[col (syntax-column #'e)]
[pos (syntax-position #'e)]
[span (syntax-column #'e)])
#'(check-pre-part e (vector 'src 'line 'col 'pos 'span))))]))
(define (check-pre-part v s)
(if (pre-part? v)
v
(error
(format
"~a: not valid in document body (need a pre-part for decode) in: ~e"
(cond
[(and (vector-ref s 0)
(vector-ref s 1))
(format "~a:~a:~a"
(vector-ref s 0)
(vector-ref s 1)
(vector-ref s 2))]
[(and (vector-ref s 0)
(vector-ref s 3))
(format "~a:::~a"
(vector-ref s 0)
(vector-ref s 1)
(vector-ref s 3))]
[else 'document])
v))))