[plt-scheme] Changing source location information

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Tue Aug 4 15:07:45 EDT 2009

2009/8/4 Jens Axel Søgaard <jensaxel at soegaard.net>:
> 2009/8/4 Eli Barzilay <eli at barzilay.org>:
>> On Aug  4, Jens Axel Søgaard wrote:
>>> I want to use the at-exp syntax for a little macro.  My problem is
>>> how to produce the correct source location when reading from the
>>> string.

> I am now experimeting a little with relocate-input-port.

The experiments have led to the sample program below.
Here the source location is correct, but the lexical information
is not. Is there a way to get read-syntax to return syntax objects
with lexical information such that example below will work?

#lang at-exp scheme

(require scheme/port
         (for-syntax scheme))

(define-syntax (foo stx)
  (syntax-case stx ()
    [(_ str str* ...)
     (let* ([from-at? (syntax-property stx 'scribble)]
            [offset   (if from-at? 0 1)]
            [ip (open-input-string
                (apply string-append
                       (map syntax->datum
                            (syntax->list #'(str str* ...)))))])
       (display stx) (newline)
       (port-count-lines! ip)
       (let* ([line (syntax-line #'str)]
              [col  (+ (syntax-column #'str) offset)]
              [pos  (+ (syntax-position #'str) offset)])
         (display (list line col pos)) (newline)
         (let ([rip (relocate-input-port ip line col pos)])
           (port-count-lines! rip)
           (let ([result (read-syntax (syntax-source stx) rip)])
             (display #'str) (newline)
             (display result) (newline)
             #;(datum->syntax stx
                              (syntax->datum result)
                              stx stx)))))]))

#;(datum->syntax #'stx result #f #'stx #'stx)

(define x 3)

(foo "(


Posted on the users mailing list.