> On Jul 4, 2017, at 1:39 PM, reilithion <reilith...@gmail.com> wrote:
> 
> I'd like to be able to get source location information from behind two or 
> more layers of macros.
> 
> Unfortunately, the srcloc that gets stored ends up being the location of the 
> simplifying macro. Not what I want. I need to somehow forward the srcloc of 
> its use-location. 

You can stash the original caller `stx` as a syntax property, which is a 
convenient way of passing "secret" arguments between macros:

#lang racket 
(require "a.rkt" "b.rkt") 
(getloc (simple-data unlucky 262)) 


#lang racket 
(provide simple-data) 
(require "a.rkt") 
(define-syntax (simple-data stx) 
  (syntax-case stx () 
    [(_ name x) 
     (syntax-property #'(mk-data 'name x 42) 'caller-stx stx)])) 

#lang racket 
(provide mk-data getloc) 
(struct data-internal 
  (name x y srcloc) 
  #:guard (λ (n x y srcloc struct-name) 
            (unless (real? x) 
              (raise-argument-error 'data-internal "real?" x)) 
            (unless (real? y) 
              (raise-argument-error 'data-internal "real?" y)) 
            (values n x y srcloc))) 
(define-syntax (mk-data stx) 
  (syntax-case stx () 
    [(_ name x y)
     (let ([stx (or (syntax-property stx 'caller-stx) stx)])
       #`(data-internal name x y (srcloc #,(syntax-source stx) 
                                         #,(syntax-line stx) 
                                         #,(syntax-column stx) 
                                         #,(syntax-position stx) 
                                         #,(syntax-span stx))))])) 
(define (getloc d) (srcloc->string (data-internal-srcloc d))) 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to