Skip to content

Commit

Permalink
Handling for the initial token being TOK_UNKNOWN.
Browse files Browse the repository at this point in the history
My intended idea was to have all syntax errors go through the same actions driven by parser.sid. But in this case SID's generated parser bails out immediately on TOK_UNKNOWN, and we never reach an ## alt. So we never reach <make-ast>, and thus never <err-syntax> about it.

That's what the assertion was about; the generated parser should never return with a NULL AST.

My workaround for this is just to recreate the equivalent syntax error at the top-level, which isn't very satisfying at all. But it does what we need here.
  • Loading branch information
katef committed Jan 4, 2024
1 parent 84d7da4 commit e156cd5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/lx/parser.act
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,19 @@

lx->free(lx->buf_opaque);

assert(ast != NULL);
/*
* This can happen when the first token is TOK_UNKNOWN.
* SID's generated parser bails out immediately.
* So we never reach <make-ast>, and never <err-syntax> about it.
*
* Really I wanted this handled along with the usual syntax error
* case, from ## alts inside parser.sid, instead of reproducing
* the same error here.
*/
if (ast == NULL) {
err(lex_state, "Syntax error");
exit(EXIT_FAILURE);
}

return ast;
}
Expand Down
16 changes: 14 additions & 2 deletions src/lx/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lx/parser.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e156cd5

Please sign in to comment.