[plt-scheme] Defining syntax inside the transformer environment

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Mon Dec 12 09:43:03 EST 2005

Daniel Franke wrote:
> I'm working on a macro for expanding infix math expressions (written as strings)
> into Scheme S-expressions. I defined a macro (using defmacro.ss) called
> lex-state which returns lambda expressions. Basically, the lambda expression
> reperesents a single state of the DFA that drives the lexical analyzer. Then,
> with define-values-for-syntax, I've bound several symbols, L0 through L7 (each
> representing one state), to the procedures that result from evaluating the
> lambda expressions to which lex-state expands.  Later, the main macro (the one
> exported outside my module) will call these procedures in order to lex the
> string passed to it.
> 
> The problem is, lex-state doesn't seem to exist in the transformer environment.
> When I go to bind L0 through L7 to its expansion, the compiler errors out and
> tells me that lex-state isn't bound. I've worked around the problem by putting
> lex-state in a separate module and then importing it via require-for-syntax.
> However, this seems like a kludge at best.  Is there a better way of going about
> this? Something along the lines of define-macro-for-syntax?

Maybe there is a good idea hidden in the source of Jacoc's quasistring.plt?

   quasistring.plt contributed by jacob
   documentation - latest package version: (1.0)
   (require (planet "quasistring.ss" ("jacob" "quasistring.plt" 1 0)))

   Implements a string-interpolation syntax; (qs "$(+ 1 2) = 3")
   evaluates to "3 = 3".

If I recall correctly it works so well the syntax checker can
color the content of a string correctly.

<http://planet.plt-scheme.org/207.1/docs/jacob/quasistring.plt/1/0/doc.txt>

-- 
Jens Axel Søgaard





Posted on the users mailing list.