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.
31 lines
801 B
Racket
31 lines
801 B
Racket
9 years ago
|
#lang racket/base
|
||
|
|
||
|
(provide make-debug-readtable wrap-reader)
|
||
|
|
||
|
(require racket/syntax)
|
||
|
|
||
|
(define (make-debug-readtable [rt (current-readtable)])
|
||
|
(make-readtable rt
|
||
|
#\^ 'dispatch-macro report-proc
|
||
|
))
|
||
|
|
||
|
(define/with-syntax report (datum->syntax #f 'report))
|
||
|
(define/with-syntax report/line (datum->syntax #f 'report/line))
|
||
|
|
||
|
(define (report-proc c in src ln col pos)
|
||
|
(define c2 (peek-char in))
|
||
|
(cond [(char=? c2 #\^)
|
||
|
(read-char in)
|
||
|
(define stx (read-syntax/recursive src in))
|
||
|
#`(report/line #,stx)]
|
||
|
[else
|
||
|
(define stx (read-syntax/recursive src in))
|
||
|
#`(report #,stx)]))
|
||
|
|
||
|
(define (wrap-reader reader)
|
||
|
(define (rd . args)
|
||
|
(parameterize ([current-readtable (make-debug-readtable (current-readtable))])
|
||
|
(apply reader args)))
|
||
|
rd)
|
||
|
|