[racket] Typesetting with subscripts in Redex

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Mon Sep 10 00:46:20 EDT 2012

On Sun, Sep 9, 2012 at 6:52 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> Getting the line, column, and span for a rewriter result can be tricky.
> Usually, you want the result of a rewriter to have the same start and
> span as the input. I think I got that part right, below, too.

with-compound-rewriter has some smarts about how to insert lw structs
when it sees non-lws in the resulting list. So you can exploit that by
writing something like this (and thus avoid the need for "collapse"):

(define (dummy-rewriters thunk)
  (with-compound-rewriters
   (['n (lambda (lws)
          (list ""
                (list-ref lws 2)
                (text (symbol->string (lw-e (list-ref lws 1)))
                      `(subscript . ,(default-style))
                      (default-font-size))
                ""))])
   (thunk)))

I've added a note about this trick to the docs.

Robby

Posted on the users mailing list.