[plt-scheme] Warnings from macros?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Oct 15 22:51:40 EDT 2008

On Oct 15, 2008, at 8:36 PM, Henk Boom wrote:

> This is for a homework assignment, but the assignment was to write a
> parser for a grammar (in a language of our choice), and I decided to
> write a parser generator as a scheme macro instead, (much more fun =D)
> so this question is really outside the scope of the assignment.
> I have a macro parser-from-grammar, and I want to flag detected
> ambiguities based on overlaps between calculated first and follow
> sets. I can call "error", but that will only give one error before
> dying. Is there a way to emit the equivalent of compilation warnings
> from a macro? It seems output from printf gets ignored.

Do you mean this kind of thing? -- Matthias

> #lang scheme
> (define-syntax (parser stx)
>   (syntax-case stx ()
>     [(parser a b)
>      (let* ((f (lambda (x) x))
>             (bad? (lambda (x) #t))
>             [x (f (syntax a))])
>        (if (bad? x)
>            (begin
>              (printf "warning !\n")
>              (syntax '()))
>            (syntax (list b b b))))]))
> (parser 1 2)

Posted on the users mailing list.