Re: [racket-users] Catching syntax errors

2017-07-01 Thread Ryan Culpepper
Use `convert-syntax-error` from the `syntax/macro-testing` module: 
http://docs.racket-lang.org/syntax/macro-testing.html#(form._((lib._syntax%2Fmacro-testing..rkt)._convert-syntax-error))


Ryan


On 06/30/2017 04:47 PM, Sam Waxman 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 #).

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.


Re: [racket-users] Catching syntax errors

2017-06-30 Thread Philip McGrath
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"
 #
 '(.#))







-Philip

On Fri, Jun 30, 2017 at 3:47 PM, Sam Waxman  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 # #).
>
> 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.


[racket-users] Catching syntax errors

2017-06-30 Thread Sam Waxman
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 #).

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.