[racket-dev] Preserving source location in macro-generating macros, in collects
Why I care: I wrote a macro that both defines a contracted function and
defines a macro that expands to a Scribble 'defproc' with the same
contract. With the source locations gone (recursively), Scribble can't
format the contracts, and I end up with things like (real-in01) instead
of (real-in 0 1).
(I know about scribble/srcdoc, but dependencies keep me from using it.)
Suppose I have a "location reporter" macro, which is generated by a macro:
#lang racket
(require (for-syntax syntax/srcloc))
(provide location-reporter)
(define-syntax (make-location-reporter stx)
(syntax-case stx ()
[(_ name) #'(define-syntax (name inner-stx)
(syntax-case inner-stx ()
[(_) #`#,(source-location->string #'name)]))]))
(make-location-reporter location-reporter)
If I compile this in DrRacket, require it from another module, and do
(location-reporter)
it expands to
"<collects>/plot/location-reporter.rkt:13.24"
as I expect. But if I compile it as part of "raco setup", it expands to
"<collects>/plot/location-reporter.rkt"
I understand that stripping source locations is an optimization. But is
there a way to turn it off, or preserve them, recursively, another way?
Also, exactly how is the location information disappearing? Does it
happen when 'name' above is double-syntax-quoted?
Neil T