Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly nicer error message when a body is all definitions. #18

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions private/syntax.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
(define (inc-total!) (set! total-tests (add1 total-tests))))
(require 'test-info)
(with-test-counters [inc-passed! inc-total!]
(dssl-begin expr ...))
#,(expand-dssl-begin #'stx #'(expr ...) #t))
(print-test-results passed-tests total-tests))]))

(define (print-test-results passed total)
Expand Down Expand Up @@ -419,13 +419,22 @@
(define-values (early late) (loop stx0 '() '()))
(values (reverse early) (reverse late)))

(define (expand-dssl-begin stx)
(define (expand-dssl-begin orig-stx stx all-defs-ok?)
(define-values (early late) (split-dssl-definitions stx))
(unless all-defs-ok?
(syntax-parse late
[(_ ... ((~literal dssl-def) _2 ...))
(syntax-error
orig-stx
(~a "body must end with an expression or statement,"
"not a definition; are you forgetting something?"))]
[else
(void)])) ; all clear
#`(begin #,@early #,@late)))

(define-syntax-parser dssl-begin
[(_ . defns)
(expand-dssl-begin #'defns)])
[(~and stx (_ . defns))
(expand-dssl-begin #'stx #'defns #f)])

(define-syntax (dssl-struct stx)
(syntax-error
Expand Down