Lisp HUG Maillist Archive

PARSE-ERROR

Hi

the CLHS PARSE-ERROR definition is very terse.  I have a program that 
gets called from a DLL which may throw a PARSE-ERROR while running.  
This is fine, however, I do not have any extra information regarding 
the error itself (e.g. at what position in the stream the error 
happened)

I noticed that PARSE-ERROR has a CONDITIONS::SIMPLE-PARSE-ERROR 
subclass, but I do not think that may be useful either.

Does anybody have a quick suggestion about how to come up with a 
PARSE-ERROR subclass that recorded also the position of the error?

Thanks

marco




--
Marco Antoniotti					http://bioinformatics.nyu.edu
NYU Courant Bioinformatics Group		tel. +1 - 212 - 998 3488
715 Broadway 10th FL				fax. +1 - 212 - 998 3484
New York, NY, 10003, U.S.A.


Re: PARSE-ERROR

* Marco Antoniotti wrote:


> Does anybody have a quick suggestion about how to come up with a 
> PARSE-ERROR subclass that recorded also the position of the error?

I think it's enough to subclass it, adding a slot or slots which
record the information:

(define-condition stream-parse-error (parse-error)
  ((stream :initarg :stream
           :reader stream-parse-error-stream)
   (position :initarg :position
             :reader stream-parse-error-position)))

Now I forget if it's portable to define an INITIALIZE-INSTANCE method
for this thing which will initialize the position from the stream - I
think you need to do it at condition creation time because the stream
could well be closed by the time you want to extract the position.
I think it's probably not portable to do that, but I'm sure it works
in LW anyway.

--tim



Updated at: 2020-12-10 08:57 UTC