[plt-scheme] Changing source location information

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

Hi All,

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.

A simple version of the problem can be seen in the macro foo below.

The macro application

   (foo "(+ 1 x)")

simply calls read-syntax on the string and returns the result.

The problem is to get the correct source location for, say, x.
A simple way to see the problem is to uncomment the definition
for x - and see how DrScheme can't color the x red.

What I need is a simple way to transfer the source location
information from #'str to the port ip.

#lang at-exp scheme

(require (for-syntax scheme))

(define-syntax (foo stx)
  (syntax-case stx ()
    [(_ str)
     (let ([ip (open-input-string (syntax->datum #'str))])
       (port-count-lines! ip)
       (let ([result (read-syntax stx ip)])
         ;(display #'str) (newline)
         ;(display result) (newline)
         (datum->syntax #'str (syntax->datum result))))]))

(define x 3)

(foo "(+ 1 x)")

@foo{(+ 1 x)}


-- 
Jens Axel Søgaard


Posted on the users mailing list.