parse: lex: fix some state transition edge cases
This commit is contained in:
@@ -149,7 +149,6 @@ static enum bshell_status arithmetic_pump_token(struct lex_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct lex_state_link links[] = {
|
static const struct lex_state_link links[] = {
|
||||||
LINK_CHANGE(TOK_WORD, LEX_STATE_COMMAND),
|
|
||||||
LINK_CHANGE(SYM_EQUAL, LEX_STATE_STATEMENT),
|
LINK_CHANGE(SYM_EQUAL, LEX_STATE_STATEMENT),
|
||||||
LINK_PUSH(SYM_DQUOTE, LEX_STATE_STRING, 0),
|
LINK_PUSH(SYM_DQUOTE, LEX_STATE_STRING, 0),
|
||||||
LINK_PUSH(SYM_DOLLAR_LEFT_PAREN, LEX_STATE_STATEMENT, 0),
|
LINK_PUSH(SYM_DOLLAR_LEFT_PAREN, LEX_STATE_STATEMENT, 0),
|
||||||
|
|||||||
+18
-10
@@ -273,8 +273,10 @@ static struct lex_symbol_node *get_symbol_node(
|
|||||||
{
|
{
|
||||||
fx_queue_entry *entry = fx_queue_first(&node->s_children);
|
fx_queue_entry *entry = fx_queue_first(&node->s_children);
|
||||||
while (entry) {
|
while (entry) {
|
||||||
struct lex_symbol_node *child
|
struct lex_symbol_node *child = fx_unbox(
|
||||||
= fx_unbox(struct lex_symbol_node, entry, s_entry);
|
struct lex_symbol_node,
|
||||||
|
entry,
|
||||||
|
s_entry);
|
||||||
if (child->s_char == c) {
|
if (child->s_char == c) {
|
||||||
return child;
|
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);
|
fx_queue_entry *entry = fx_queue_first(&tree->s_children);
|
||||||
while (entry) {
|
while (entry) {
|
||||||
struct lex_symbol_node *node
|
struct lex_symbol_node *node = fx_unbox(
|
||||||
= fx_unbox(struct lex_symbol_node, entry, s_entry);
|
struct lex_symbol_node,
|
||||||
|
entry,
|
||||||
|
s_entry);
|
||||||
fx_queue_entry *next = fx_queue_next(entry);
|
fx_queue_entry *next = fx_queue_next(entry);
|
||||||
fx_queue_delete(&tree->s_children, entry);
|
fx_queue_delete(&tree->s_children, entry);
|
||||||
|
|
||||||
@@ -736,8 +740,9 @@ enum bshell_status read_var(
|
|||||||
return ctx->lex_status;
|
return ctx->lex_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lex_token *tok
|
struct lex_token *tok = lex_token_create_with_string(
|
||||||
= lex_token_create_with_string(type, fx_string_get_cstr(tmp));
|
type,
|
||||||
|
fx_string_get_cstr(tmp));
|
||||||
|
|
||||||
*out = tok;
|
*out = tok;
|
||||||
return BSHELL_SUCCESS;
|
return BSHELL_SUCCESS;
|
||||||
@@ -776,8 +781,9 @@ enum bshell_status read_braced_var(
|
|||||||
return ctx->lex_status;
|
return ctx->lex_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lex_token *tok
|
struct lex_token *tok = lex_token_create_with_string(
|
||||||
= lex_token_create_with_string(type, fx_string_get_cstr(tmp));
|
type,
|
||||||
|
fx_string_get_cstr(tmp));
|
||||||
|
|
||||||
*out = tok;
|
*out = tok;
|
||||||
return BSHELL_SUCCESS;
|
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);
|
fx_queue_entry *cur = fx_queue_first(&ctx->lex_tokens);
|
||||||
while (cur) {
|
while (cur) {
|
||||||
struct lex_token *tok
|
struct lex_token *tok = fx_unbox(
|
||||||
= fx_unbox(struct lex_token, cur, tok_entry);
|
struct lex_token,
|
||||||
|
cur,
|
||||||
|
tok_entry);
|
||||||
if (tok->tok_type == TOK_LINEFEED) {
|
if (tok->tok_type == TOK_LINEFEED) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,11 +165,20 @@ static const struct lex_state_link links[] = {
|
|||||||
LINK_CHANGE(TOK_KEYWORD, LEX_STATE_ARITHMETIC),
|
LINK_CHANGE(TOK_KEYWORD, LEX_STATE_ARITHMETIC),
|
||||||
LINK_CHANGE(TOK_INT, LEX_STATE_ARITHMETIC),
|
LINK_CHANGE(TOK_INT, LEX_STATE_ARITHMETIC),
|
||||||
LINK_PUSH(SYM_DOLLAR, LEX_STATE_ARITHMETIC, 0),
|
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_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_PUSH(SYM_AT, LEX_STATE_ARITHMETIC, 0),
|
||||||
LINK_CHANGE(SYM_LEFT_PAREN, LEX_STATE_ARITHMETIC),
|
LINK_CHANGE(SYM_LEFT_PAREN, LEX_STATE_ARITHMETIC),
|
||||||
|
LINK_CHANGE(SYM_LEFT_BRACKET, LEX_STATE_ARITHMETIC),
|
||||||
LINK_CHANGE(SYM_BANG, LEX_STATE_ARITHMETIC),
|
LINK_CHANGE(SYM_BANG, LEX_STATE_ARITHMETIC),
|
||||||
LINK_PUSH_WITH_TERM(
|
LINK_PUSH_WITH_TERM(
|
||||||
SYM_LEFT_PAREN,
|
SYM_LEFT_PAREN,
|
||||||
@@ -178,7 +187,11 @@ static const struct lex_state_link links[] = {
|
|||||||
SYM_RIGHT_PAREN),
|
SYM_RIGHT_PAREN),
|
||||||
|
|
||||||
/* statement tokens */
|
/* 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(
|
LINK_PUSH_WITH_TERM(
|
||||||
SYM_DOLLAR_LEFT_PAREN,
|
SYM_DOLLAR_LEFT_PAREN,
|
||||||
LEX_STATE_STATEMENT,
|
LEX_STATE_STATEMENT,
|
||||||
|
|||||||
Reference in New Issue
Block a user