debug-meta-lang: make (require sugar/debug) unnecessary

and make it hygienic
pull/6/head
AlexKnauth 9 years ago
parent aa97dea3f8
commit 65467b72b4

@ -9,22 +9,34 @@
#\^ 'dispatch-macro report-proc
))
(define/with-syntax report (datum->syntax #f 'report))
(define/with-syntax report/line (datum->syntax #f 'report/line))
(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 stx (read-syntax/recursive src in))
#`(report/line #,stx)]
(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 stx (read-syntax/recursive src in))
#`(report #,stx)]))
(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)
(parameterize ([current-readtable (make-debug-readtable (current-readtable))])
(apply reader 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)

@ -1,10 +1,15 @@
#lang sugar/debug/lang racket
(require sugar/debug rackunit)
(let ([out (open-output-string)])
(require rackunit)
(let ([out (open-output-string)]
[let "something else"]
[local-require "something else entirely"]
[only-in "completely unexpected!"]
[report "well, not really"])
(parameterize ([current-error-port out])
#^5)
(check-equal? (get-output-string out) "5 = 5\n"))
(let ([out (open-output-string)])
(let ([out (open-output-string)]
[report/line "outta the blue!"])
(parameterize ([current-error-port out])
#^^5)
(check-equal? (get-output-string out) "5 = 5 on line 9\n"))
(check-equal? (get-output-string out) "5 = 5 on line 14\n"))

Loading…
Cancel
Save