summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parser.y4
-rw-r--r--txr.c32
-rw-r--r--unwind.h11
3 files changed, 38 insertions, 9 deletions
diff --git a/parser.y b/parser.y
index 265e4e30..a29403f0 100644
--- a/parser.y
+++ b/parser.y
@@ -1839,7 +1839,7 @@ int parse_once(val stream, val name, parser_t *parser)
parser_resolve_circ(parser);
uw_catch(esym, eobj) {
- yyerrorf(parser->scanner, lit("exception during parse"), nao);
+ yyerrorf(parser->scanner, lit("error exception during parse"), nao);
uw_throw(esym, eobj);
}
@@ -1878,7 +1878,7 @@ int parse(parser_t *parser, val name, enum prime_parser prim)
parser_resolve_circ(parser);
uw_catch(esym, eobj) {
- yyerrorf(parser->scanner, lit("exception during parse"), nao);
+ yyerrorf(parser->scanner, lit("error exception during parse"), nao);
uw_throw(esym, eobj);
}
diff --git a/txr.c b/txr.c
index 2591b339..cee8ac51 100644
--- a/txr.c
+++ b/txr.c
@@ -447,6 +447,20 @@ static void no_dbg_support(val arg)
}
#endif
+static int parse_once_noerr(val stream, val name, parser_t *parser)
+{
+ val pfx = format(nil, lit("~a:"), name, nao);
+ ignerr_func_body(int, 0, parse_once(stream, name, parser),
+ exsym, exargs, std_error, pfx);
+}
+
+static val read_eval_stream_noerr(val stream, val name, val error_stream)
+{
+ val pfx = format(nil, lit("~a:"), name, nao);
+ ignerr_func_body(val, nil, read_eval_stream(stream, error_stream),
+ exsym, exargs, std_error, pfx);
+}
+
int txr_main(int argc, char **argv)
{
uses_or2;
@@ -974,27 +988,30 @@ int txr_main(int argc, char **argv)
{
int gc = gc_state(0);
parser_t parser;
- parse_once(parse_stream, spec_file_str, &parser);
+ parse_once_noerr(parse_stream, spec_file_str, &parser);
gc_state(gc);
close_stream(parse_stream, nil);
uw_release_deferred_warnings();
- if (parser.errors)
- return EXIT_FAILURE;
-
spec = parser.syntax_tree;
opt_loglevel = match_loglevel;
+ reg_var(intern(lit("*self-path*"), user_package), spec_file_str);
+
+ if (parser.errors) {
+ if (enter_repl)
+ goto repl;
+ return EXIT_FAILURE;
+ }
+
if (opt_loglevel >= 2) {
format(std_error, lit("spec:\n~s\n"), spec, nao);
format(std_error, lit("bindings:\n~s\n"), bindings, nao);
}
- reg_var(intern(lit("*self-path*"), user_package), spec_file_str);
-
{
val result = extract(spec, arg_list, bindings);
cons_bind (new_bindings, success, result);
@@ -1014,7 +1031,8 @@ int txr_main(int argc, char **argv)
}
{
- val result = read_eval_stream(parse_stream, std_error);
+ val result = read_eval_stream_noerr(parse_stream, spec_file_str,
+ std_error);
close_stream(parse_stream, nil);
diff --git a/unwind.h b/unwind.h
index a173e39d..5c4786f3 100644
--- a/unwind.h
+++ b/unwind.h
@@ -276,3 +276,14 @@ noreturn val type_mismatch(val, ...);
internal_error("assertion " \
#EXPR \
" failed")
+
+#define ignerr_func_body(type, init, expr, exsym, \
+ exargs, stream, prefix) \
+ type (_r_e_t) = (init); \
+ uw_catch_begin (cons(error_s, nil), exsym, exargs); \
+ _r_e_t = expr; \
+ uw_catch(exsym, exargs) \
+ error_trace(exsym, exargs, stream, prefix); \
+ uw_unwind { } \
+ uw_catch_end; \
+ return _r_e_t;