summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-06-29 20:12:15 +0200
committerJo-Philipp Wich <jo@mein.io>2021-06-29 20:15:55 +0200
commita97c7a1378addace9d4c413543794a35c19d1f03 (patch)
tree52132145b2238059112dab76ef14ed3c78e0bb04
parent2a838d1f9f58d05bc1e15084efa42ad86fc105e4 (diff)
lexer: transition into EOF state on unrecognized character
The compiler will keep fetching tokens until hitting EOF, so ensure that the lexer produces EOF after an unrecognized character error. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--lexer.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/lexer.c b/lexer.c
index 1be6978..fe3c1fb 100644
--- a/lexer.c
+++ b/lexer.c
@@ -1090,20 +1090,19 @@ lex_step(uc_lexer *lex, FILE *fp)
}
}
+ /* no possible return beyond this point can advance,
+ mark lex state as eof */
+ lex->state = UT_LEX_EOF;
+
/* no token matched and we do have remaining data, junk */
if (buf_remaining(lex))
return emit_op(lex, lex->source->off, TK_ERROR, ucv_string_new("Unexpected character"));
/* we're at eof, allow unclosed statement blocks */
- if (lex->block == STATEMENTS) {
- lex->state = UT_LEX_EOF;
-
+ if (lex->block == STATEMENTS)
return NULL;
- }
/* premature EOF */
- lex->state = UT_LEX_EOF;
-
return emit_op(lex, lex->source->off, TK_ERROR, ucv_string_new("Unterminated template block"));