[racket] Redex question: parameterizing a language definition

From: Lindsey Kuper (lkuper at cs.indiana.edu)
Date: Mon Jun 3 16:04:21 EDT 2013

Hi, Racketeers,

On Thu, Apr 4, 2013 at 9:32 PM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> One thing to watch out for, tho, is that redex uses source location
> information to typeset grammars and when macros are involved, the source
> locations (naturally) get mixed up. Since a macro can do arbitrary
> computation at runtime, however, you can fiddle with the source locations in
> the output of your macro to overcome this problem (but it isn't the easiest
> thing in the world).
>
> Robby

It looks like when I try using the Redex typesetting features for
macro-generated Redex, I'm having exactly the problem Robby predicted
I'd have with source location information getting mixed up.

At least, that's what I *think* is going on.  For example, with
render-language, I get errors like this from the innards of Redex:

Welcome to DrRacket, version 5.3.3 [3m].
Language: racket; memory limit: 128 MB.
> (require (submod "natpair-ivars.rkt" language))
> (require redex/pict)
> (render-language LVish-natpair-ivars)
. . eject: lines going backwards (current-line 11 line 0 atom #<pict>
tokens (#(struct:string-token 16 1 ")" roman) #(struct:string-token 9
7 "natural" (italic . roman)) #(struct:string-token 8 1 " " roman)
#(struct:string-token 5 3 "Bot" swiss) #(struct:string-token 4 1 "("
roman) #(struct:pict-token 4 0 #<pict>) #(struct:spacer-token 0 4)))
>

(In this case, the Redex-generating macro in question is
https://github.com/iu-parfunc/lvars/blob/master/redex/LVish/LVish.rkt
and the place it's being used is
https://github.com/iu-parfunc/lvars/blob/master/redex/LVish/natpair-ivars.rkt
.)

So, I'm wondering if anyone has any advice, or code to share, for
preserving source location information in macro output.  Or, if anyone
can think of another workaround, I'm open to suggestions.  I don't
*have* to use Redex typesetting, but it'd be nice to see if I could
make it work.

Thanks,
Lindsey

Posted on the users mailing list.