diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-08-29 08:34:57 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-08-29 08:34:57 -0700 |
commit | 0d6676975214c406ff4b773c004cdae12e2b063a (patch) | |
tree | cdec67ecf71e99f19a438f73a865facec09c6dd4 /parser.y | |
parent | b9cfb7a7ad2cb64cba3d1863feee63338b49e5eb (diff) | |
download | txr-0d6676975214c406ff4b773c004cdae12e2b063a.tar.gz txr-0d6676975214c406ff4b773c004cdae12e2b063a.tar.bz2 txr-0d6676975214c406ff4b773c004cdae12e2b063a.zip |
Print parser error message for parse-time exceptions.
* parser.y (parse_once, parse): Catch error exceptions
coming out of yyparse, print message, then re-throw. This way we see
the file and line number near where that happened.
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -1481,30 +1481,52 @@ void yybadtoken(parser_t *parser, int tok, val context) int parse_once(val stream, val name, parser_t *parser) { - int res; + int res = 0; parser_common_init(parser); parser->stream = stream; parser->name = name; + uw_catch_begin(cons(error_s, nil), esym, eobj); + res = yyparse(parser->scanner, parser); - parser_cleanup(parser); + uw_catch(esym, eobj) { + yyerrorf(parser->scanner, lit("exception during parse"), nao); + uw_throw(esym, eobj); + } + + uw_unwind { + parser_cleanup(parser); + } + + uw_catch_end; return res; } int parse(parser_t *parser, val name, enum prime_parser prim) { - int res; + int res = 0; parser->errors = 0; parser->prepared_msg = nil; parser->syntax_tree = nil; prime_parser(parser, name, prim); + uw_catch_begin(cons(error_s, nil), esym, eobj); + res = yyparse(parser->scanner, parser); + uw_catch(esym, eobj) { + yyerrorf(parser->scanner, lit("exception during parse"), nao); + uw_throw(esym, eobj); + } + + uw_unwind; + + uw_catch_end; + return res; } |