From 1716897f2b206d71a27221791c6a56baaac10ee3 Mon Sep 17 00:00:00 2001 From: Kate F Date: Thu, 4 Jan 2024 15:43:56 +0000 Subject: [PATCH] Handling for the initial token being TOK_UNKNOWN. 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 , and thus never 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. Spotted by @cinco-de-mayonnaise, thank you. --- src/lx/parser.act | 14 +++++++++++++- src/lx/parser.c | 16 ++++++++++++++-- src/lx/parser.h | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/lx/parser.act b/src/lx/parser.act index 78254e123..f9b0b32f9 100644 --- a/src/lx/parser.act +++ b/src/lx/parser.act @@ -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 , and never 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; } diff --git a/src/lx/parser.c b/src/lx/parser.c index cbc2067fd..dfcf36b8f 100644 --- a/src/lx/parser.c +++ b/src/lx/parser.c @@ -3364,11 +3364,23 @@ ZL1:; 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 , and never 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; } -#line 3373 "src/lx/parser.c" +#line 3385 "src/lx/parser.c" /* END OF FILE */ diff --git a/src/lx/parser.h b/src/lx/parser.h index fbe704fc4..bde7c36ab 100644 --- a/src/lx/parser.h +++ b/src/lx/parser.h @@ -29,7 +29,7 @@ extern void p_lx(lex_state, act_state, ast *); /* BEGINNING OF TRAILER */ -#line 877 "src/lx/parser.act" +#line 889 "src/lx/parser.act" #line 36 "src/lx/parser.h"