From 4e6493da58c96de46f5e4c9ad5a666f252cb9bda Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sat, 20 Jun 2026 15:06:04 +0100 Subject: [PATCH] runtime: lex: fix incorrect state-transition when scanning func keyword --- bshell.runtime/parse/lex/command.c | 5 +++-- bshell.runtime/parse/lex/statement.c | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bshell.runtime/parse/lex/command.c b/bshell.runtime/parse/lex/command.c index 400c4d8..19df4e3 100644 --- a/bshell.runtime/parse/lex/command.c +++ b/bshell.runtime/parse/lex/command.c @@ -188,10 +188,11 @@ enum bshell_status command_pump_token(struct bshell_lex_ctx *ctx) const struct bshell_lex_state_link links[] = { LINK_PUSH(BSHELL_SYM_DQUOTE, BSHELL_LEX_STATE_STRING, 0), - LINK_PUSH( + LINK_PUSH_WITH_TERM( BSHELL_SYM_LEFT_PAREN, BSHELL_LEX_STATE_STATEMENT, - STATEMENT_F_DISABLE_KEYWORDS), + STATEMENT_F_DISABLE_KEYWORDS, + BSHELL_SYM_RIGHT_PAREN), LINK_PUSH(BSHELL_SYM_DOLLAR_LEFT_PAREN, BSHELL_LEX_STATE_STATEMENT, 0), LINK_POP(BSHELL_SYM_RIGHT_PAREN), LINK_POP(BSHELL_SYM_RIGHT_BRACE), diff --git a/bshell.runtime/parse/lex/statement.c b/bshell.runtime/parse/lex/statement.c index b45f754..83fe09f 100644 --- a/bshell.runtime/parse/lex/statement.c +++ b/bshell.runtime/parse/lex/statement.c @@ -142,7 +142,8 @@ static enum bshell_status statement_pump_token(struct bshell_lex_ctx *ctx) } if (newline) { - struct bshell_lex_token *tok = bshell_lex_token_create(BSHELL_TOK_LINEFEED); + struct bshell_lex_token *tok + = bshell_lex_token_create(BSHELL_TOK_LINEFEED); enqueue_token(ctx, tok); handle_lex_state_transition(ctx, BSHELL_TOK_LINEFEED); return BSHELL_SUCCESS; @@ -203,7 +204,11 @@ static const struct bshell_lex_state_link links[] = { BSHELL_SYM_RIGHT_PAREN), /* command tokens */ - LINK_CHANGE(BSHELL_KW_FUNC, BSHELL_LEX_STATE_COMMAND), + LINK_PUSH_WITH_TERM( + BSHELL_KW_FUNC, + BSHELL_LEX_STATE_COMMAND, + 0, + BSHELL_SYM_RIGHT_BRACE), LINK_CHANGE(BSHELL_SYM_AMPERSAND, BSHELL_LEX_STATE_COMMAND), LINK_CHANGE(BSHELL_TOK_WORD, BSHELL_LEX_STATE_COMMAND), LINK_END,