If testing with parenthetical syntax is sufficient, you might want
something like this:

#lang racket

(with-handlers ([exn:fail:syntax? values])
  (eval `(module bad racket (define foo (define bar 1)))
        (make-base-namespace)))

which returns:

(exn:fail:syntax
 "define: not allowed in an expression context"
 #<continuation-mark-set>
 '(.#<syntax (define bar 1)>))







-Philip

On Fri, Jun 30, 2017 at 3:47 PM, Sam Waxman <samwax...@gmail.com> wrote:

> Hello,
>
> I'm trying to test whether or not certain programs result in syntax
> errors. For example the program
>
> #lang racket
> a
>
> will result in an unbound identifier error, even before runtime (you'll
> see the little error message at the bottom because it errored in phase 1).
>
> I know how to catch runtime errors, but I haven't been able to catch these
> expansion time errors as of yet. I've tried doing roughly the same thing as
> catching runtime errors, but with begin-for-syntax, but it hasn't been
> working out for me.
>
> Ideally, I want a macro like
>
> (return-syntax-error stuff-to-expand ...)
>
> that will run stuff-to-expand, and if runs into a syntax error, for it to
> be caught and returned (as the error struct #<exn:fail:syntax *message*
> #<continuation mark>).
>
> Any tips?
>
> Many thanks in advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to