chiark / gitweb /
src/final.lisp: Improve `test-parser' for testing error reporting.
This is nearly a rewrite. By default, print errors and warnings
encountered during the parse, so that I can test how well the various
parsers cope with errors. The output has changed, and there's a new
`:backtrace' keyword argument for disabling the error-trapping, to make
it easier to track down unexpected errors.
The new code is a little tricky. A `token-scanner' tries to lex its
first token during initialization (`priming the pump'), and can
therefore emit lexical errors at this point. We must therefore
establish `count-and-report-errors' around construction of the token
scanner; but it shouldn't be wrapped around the output stage -- partly
because I think I want to debug errors in that in the traditional way,
but mostly because the output includes the error counts.
So declare the scanner variables early, but initialize them later,
inside the body function. This leaves a further problem: if priming the
pump fails badly, then `scanner' won't get set; so guard the final
output item from silliness in this case.