From 611bb221a96e50fd8561886ec34d8a42e136b5ce Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 21 Feb 2015 19:24:18 +0100 Subject: throw error instead of assertion when loop is closed (>) or continued (F>) without a corresponding loop start (<) * assertions were introduced very early when there was no proper error handling in SciTECO. However it points to a macro programming error instead of a SciTECO programming error and should not crash the editor. * Perhaps it would be best to check for this kind of "syntax" error also in parse-only modes. This is not done currently. * part of the solution to issue #3 --- src/parser.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index e5d1f22..384c42d 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -858,7 +858,9 @@ StateStart::custom(gchar chr) tecoInt loop_pc, loop_cnt; expressions.discard_args(); - g_assert(expressions.pop_op() == Expressions::OP_LOOP); + if (expressions.pop_op() != Expressions::OP_LOOP) + throw Error("Loop end without corresponding " + "loop start command"); loop_pc = expressions.pop_num(); loop_cnt = expressions.pop_num(); @@ -1482,6 +1484,9 @@ StateFCommand::custom(gchar chr) * In interactive mode, if the loop is incomplete and must * be exited, you can type in the loop's remaining commands * without them being executed (but they are parsed). + * + * Calling \fBF\>\fP outside of a loop will throw an + * error. */ case '>': { tecoInt loop_pc, loop_cnt; @@ -1489,7 +1494,9 @@ StateFCommand::custom(gchar chr) BEGIN_EXEC(&States::start); /* FIXME: what if in brackets? */ expressions.discard_args(); - g_assert(expressions.pop_op() == Expressions::OP_LOOP); + if (expressions.pop_op() != Expressions::OP_LOOP) + throw Error("Jump to loop end without corresponding " + "loop start command"); loop_pc = expressions.pop_num(); loop_cnt = expressions.pop_num(); -- cgit v1.2.3