You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket-demo/basic-demo-3/line.rkt

23 lines
653 B
Racket

8 years ago
#lang br
8 years ago
(require "struct.rkt")
(provide b-line raise-line-error)
8 years ago
(define-macro (b-line NUM STATEMENT ...)
(with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
#:source #'NUM)])
(syntax/loc caller-stx
(define (LINE-NUM #:error [msg #f])
8 years ago
(with-handlers
([line-error?
(λ (le) (handle-line-error NUM le))])
8 years ago
(when msg (raise-line-error msg))
STATEMENT ...)))))
8 years ago
(define (raise-line-error error-msg)
(raise (line-error error-msg)))
8 years ago
(define (handle-line-error num le)
8 years ago
(error (format "error in line ~a: ~a"
num (line-error-msg le))))
8 years ago