add syntactic shorthand for `report`
parent
ecce73cdc3
commit
0ffe317387
@ -1,28 +0,0 @@
|
|||||||
(module reader racket/base
|
|
||||||
(require syntax/module-reader
|
|
||||||
(only-in "../../reader.rkt" make-debug-readtable wrap-reader))
|
|
||||||
|
|
||||||
(provide (rename-out [debug-read read]
|
|
||||||
[debug-read-syntax read-syntax]
|
|
||||||
[debug-get-info get-info]))
|
|
||||||
|
|
||||||
(define-values (debug-read debug-read-syntax debug-get-info)
|
|
||||||
(make-meta-reader
|
|
||||||
'sugar/debug/lang
|
|
||||||
"language path"
|
|
||||||
(lambda (bstr)
|
|
||||||
(let* ([str (bytes->string/latin-1 bstr)]
|
|
||||||
[sym (string->symbol str)])
|
|
||||||
(and (module-path? sym)
|
|
||||||
(vector
|
|
||||||
;; try submod first:
|
|
||||||
`(submod ,sym reader)
|
|
||||||
;; fall back to /lang/reader:
|
|
||||||
(string->symbol (string-append str "/lang/reader"))))))
|
|
||||||
wrap-reader
|
|
||||||
wrap-reader
|
|
||||||
(lambda (proc)
|
|
||||||
(lambda (key defval)
|
|
||||||
(define (fallback) (if proc (proc key defval) defval))
|
|
||||||
(case key
|
|
||||||
[else (fallback)]))))))
|
|
@ -1,42 +0,0 @@
|
|||||||
#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 current-syntax-introducer
|
|
||||||
(make-parameter (λ (x) x)))
|
|
||||||
|
|
||||||
(define (report-proc c in src ln col pos)
|
|
||||||
(define c2 (peek-char in))
|
|
||||||
(define intro (current-syntax-introducer))
|
|
||||||
(cond [(char=? c2 #\^)
|
|
||||||
(read-char in)
|
|
||||||
(define/with-syntax stx (intro (read-syntax/recursive src in)))
|
|
||||||
(intro
|
|
||||||
#'(let ()
|
|
||||||
(local-require (only-in sugar/debug [report/line report/line]))
|
|
||||||
(report/line stx)))]
|
|
||||||
[else
|
|
||||||
(define/with-syntax stx (intro (read-syntax/recursive src in)))
|
|
||||||
(intro
|
|
||||||
#'(let ()
|
|
||||||
(local-require (only-in sugar/debug [report report]))
|
|
||||||
(report stx)))]))
|
|
||||||
|
|
||||||
(define (wrap-reader reader)
|
|
||||||
(define (rd . args)
|
|
||||||
(define intro (make-syntax-introducer))
|
|
||||||
(parameterize ([current-readtable (make-debug-readtable (current-readtable))]
|
|
||||||
[current-syntax-introducer intro])
|
|
||||||
(define stx (apply reader args))
|
|
||||||
(if (syntax? stx)
|
|
||||||
(intro stx)
|
|
||||||
stx)))
|
|
||||||
rd)
|
|
||||||
|
|
Loading…
Reference in New Issue