[plt-scheme] Reporting syntax-error to a DrScheme tool

From: Robby Findler (robby at cs.uchicago.edu)
Date: Tue Feb 28 21:40:57 EST 2006

At Wed, 01 Mar 2006 02:12:08 +0100, Jens Axel Søgaard wrote:
> Robby Findler wrote:
> > At Wed, 01 Mar 2006 01:41:07 +0100, Jens Axel Søgaard wrote:
> > 
> >>Robby Findler wrote:
> >>
> >>>Is errortrace annotating the code? 
> >>
> >>No? 
> > 
> > The error highlighting works by having the errortrace library rewrite
> > the program to insert continuation marks all over the place. The
> > error-display-handler (that you installed) reads out the continuation
> > marks and uses them to display the error. So, I guess you'll want to
> > read about errortrace. In the teaching languages, I install it in the
> > eval-handler (the program must be fully expanded before calling
> > errortrace). If the docs aren't clear from here, pls. ask more
> > questions -- you might also look at
> > plt/collects/drscheme/private/debug.ss.
> 
> Okay. I think what misled me was this note from the parser-tools/doc.txt
> 
>  > (file-path string) - sets the parameter file-path, which the lexer
>     will use as the source location if it raises a read error.  This
>     allows DrScheme to open the file containing the error.
> 
> and the example parser has the following
> 
>   (error (lambda (a name val start end)
>                (raise-read-error
>                 "read-error"
>                 source-name
>                 (position-line start)
>                 (position-col start)
>                 (position-offset start)
>                 (- (position-offset end)
>                    (position-offset start)))))
> 
> So I was thinking: "To signal an error just raise an read-error
> exception".
> 
> I hadn't look at errortrace before (since the parse error is raised
> before any "code" is generated).

Oh! That's different. I misunderstood.

If you embed a source location into the exception record, that should
be showing up, even without errortrace.

I'm not sure what the `raise-read-error' function is doing but this
(directly in the graphical language) does what you would expect:

  (define-syntax (m stx) (raise-syntax-error 'm "hi" stx))
  (m 1)

and it is using the debug-error-display-handler.

If you're not sure what that function is doing, my best advice wrap it
in a with-handlers and take a look at the exception. In particular, see
if exn:srclocs? returns #t for the exception (which it should) and if
this expression:

 ((exn:srclocs-accessor exn) exn)

gives you back the right thing.

hth,
Robby


Posted on the users mailing list.