]> ocean-lang.org Git - ocean/commitdiff
parsergen: be careful shifting TK_error
authorNeilBrown <neil@brown.name>
Mon, 19 Feb 2018 05:31:14 +0000 (16:31 +1100)
committerNeilBrown <neil@brown.name>
Mon, 19 Feb 2018 05:31:14 +0000 (16:31 +1100)
shift() behaved a little differently when p.tos == 0,
and if the stack is completely empty, there is little
point trying to shift TK_error as there is no state
to work with.

So rearrange the loop slightly.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/parsergen.mdc

index 905e8f8d125ca7432338059d84dae693ae3597fc..c25a87e1f621fd3ffa95d4a809c2276a235b2476 100644 (file)
@@ -2841,9 +2841,9 @@ one symbol for each line where newlines are allowed.
                        short indents = 0, start_of_line;
 
                        err_tk = tok_copy(*tk);
-                       while (shift(&p, TK_error, 0, 0,
-                                    err_tk, states) == 0
-                              && p.tos > 0)
+                       while (p.tos > 0 &&
+                              shift(&p, TK_error, 0, 0,
+                                    err_tk, states) == 0)
                                // discard this state
                                indents += pop(&p, 1, &start_of_line, do_free);
                        if (p.tos == 0) {