parse: lex: fix some state transition edge cases

This commit is contained in:
2026-05-17 15:29:14 +01:00
parent 05dcf1f8b6
commit d78f80a121
3 changed files with 34 additions and 14 deletions
-1
View File
@@ -149,7 +149,6 @@ static enum bshell_status arithmetic_pump_token(struct lex_ctx *ctx)
}
static const struct lex_state_link links[] = {
LINK_CHANGE(TOK_WORD, LEX_STATE_COMMAND),
LINK_CHANGE(SYM_EQUAL, LEX_STATE_STATEMENT),
LINK_PUSH(SYM_DQUOTE, LEX_STATE_STRING, 0),
LINK_PUSH(SYM_DOLLAR_LEFT_PAREN, LEX_STATE_STATEMENT, 0),
+18 -10
View File
@@ -273,8 +273,10 @@ static struct lex_symbol_node *get_symbol_node(
{
fx_queue_entry *entry = fx_queue_first(&node->s_children);
while (entry) {
struct lex_symbol_node *child
= fx_unbox(struct lex_symbol_node, entry, s_entry);
struct lex_symbol_node *child = fx_unbox(
struct lex_symbol_node,
entry,
s_entry);
if (child->s_char == c) {
return child;
}
@@ -319,8 +321,10 @@ static void destroy_symbol_tree(struct lex_symbol_node *tree)
{
fx_queue_entry *entry = fx_queue_first(&tree->s_children);
while (entry) {
struct lex_symbol_node *node
= fx_unbox(struct lex_symbol_node, entry, s_entry);
struct lex_symbol_node *node = fx_unbox(
struct lex_symbol_node,
entry,
s_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&tree->s_children, entry);
@@ -736,8 +740,9 @@ enum bshell_status read_var(
return ctx->lex_status;
}
struct lex_token *tok
= lex_token_create_with_string(type, fx_string_get_cstr(tmp));
struct lex_token *tok = lex_token_create_with_string(
type,
fx_string_get_cstr(tmp));
*out = tok;
return BSHELL_SUCCESS;
@@ -776,8 +781,9 @@ enum bshell_status read_braced_var(
return ctx->lex_status;
}
struct lex_token *tok
= lex_token_create_with_string(type, fx_string_get_cstr(tmp));
struct lex_token *tok = lex_token_create_with_string(
type,
fx_string_get_cstr(tmp));
*out = tok;
return BSHELL_SUCCESS;
@@ -1321,8 +1327,10 @@ static void discard_all_tokens(struct lex_ctx *ctx)
{
fx_queue_entry *cur = fx_queue_first(&ctx->lex_tokens);
while (cur) {
struct lex_token *tok
= fx_unbox(struct lex_token, cur, tok_entry);
struct lex_token *tok = fx_unbox(
struct lex_token,
cur,
tok_entry);
if (tok->tok_type == TOK_LINEFEED) {
break;
}
+16 -3
View File
@@ -165,11 +165,20 @@ static const struct lex_state_link links[] = {
LINK_CHANGE(TOK_KEYWORD, LEX_STATE_ARITHMETIC),
LINK_CHANGE(TOK_INT, LEX_STATE_ARITHMETIC),
LINK_PUSH(SYM_DOLLAR, LEX_STATE_ARITHMETIC, 0),
LINK_PUSH(SYM_DOLLAR_LEFT_BRACE, LEX_STATE_ARITHMETIC, 0),
LINK_PUSH_WITH_TERM(
SYM_DOLLAR_LEFT_BRACE,
LEX_STATE_ARITHMETIC,
0,
SYM_RIGHT_BRACE),
LINK_CHANGE(SYM_AT_LEFT_BRACE, LEX_STATE_ARITHMETIC),
LINK_PUSH(SYM_AT_LEFT_BRACE, LEX_STATE_HASHTABLE, 0),
LINK_PUSH_WITH_TERM(
SYM_AT_LEFT_BRACE,
LEX_STATE_HASHTABLE,
0,
SYM_RIGHT_BRACE),
LINK_PUSH(SYM_AT, LEX_STATE_ARITHMETIC, 0),
LINK_CHANGE(SYM_LEFT_PAREN, LEX_STATE_ARITHMETIC),
LINK_CHANGE(SYM_LEFT_BRACKET, LEX_STATE_ARITHMETIC),
LINK_CHANGE(SYM_BANG, LEX_STATE_ARITHMETIC),
LINK_PUSH_WITH_TERM(
SYM_LEFT_PAREN,
@@ -178,7 +187,11 @@ static const struct lex_state_link links[] = {
SYM_RIGHT_PAREN),
/* statement tokens */
LINK_PUSH(SYM_LEFT_BRACE, LEX_STATE_STATEMENT, 0),
LINK_PUSH_WITH_TERM(
SYM_LEFT_BRACE,
LEX_STATE_STATEMENT,
0,
SYM_RIGHT_BRACE),
LINK_PUSH_WITH_TERM(
SYM_DOLLAR_LEFT_PAREN,
LEX_STATE_STATEMENT,