[plt-scheme] expansion source location

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Tue Apr 11 13:26:21 EDT 2006


--- pedro pinto <pedro.e.pinto at gmail.com> wrote:

> Is there a way to get the source location of the
> expansion site of a macro?

Yes.  Code below is from SchemeUnit.

N.

(module location mzscheme
                                                           
                   
  (require (planet "aif.ss" ("schematics" "macro.plt" 1))
           (lib "list.ss" "srfi" "1"))
                                                           
                   
  (provide location-source
           location-line
           location-column
           location-position
           location-span
           syntax->location
           location->string)
                                                           
                   
  ;; type location = (list string string string string
string)
  ;; location : source line column position span
                                                           
                   
  (define location-source first)
  (define location-line second)
  (define location-column third)
  (define location-position fourth)
  (define location-span fifth)
                                                           
                   
  ;; syntax->location : syntax -> location
  (define (syntax->location stx)
    (define (source->string source)
      (cond
       ((string? source) source)
       ((path? source) (path->string source))
       ((not source) "unknown")
       (else (format "~a" source))))
    (define (maybe-number->string number)
      (if (number? number)
          (number->string number)
          "?"))
    (list (source->string (syntax-source stx))
          (maybe-number->string (syntax-line stx))
          (maybe-number->string (syntax-column stx))
          (maybe-number->string (syntax-position stx))
          (maybe-number->string (syntax-span stx))))
                                                           
                   
  ;; location->string : (list-of string) -> string
  (define (location->string location)
    (string-append (location-source location)
                   ":"
                   (location-line location)
                   ":"
                   (location-column location)))
  )


Email: noelwelsh <at> yahoo <dot> com   noel <at> untyped <dot> com
AIM: noelhwelsh
Blogs: http://monospaced.blogspot.com/  http://www.untyped.com/untyping/

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Posted on the users mailing list.