diff options
Diffstat (limited to 'js/scripting-lang/baba-yaga-c/src/parser.c')
-rw-r--r-- | js/scripting-lang/baba-yaga-c/src/parser.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/js/scripting-lang/baba-yaga-c/src/parser.c b/js/scripting-lang/baba-yaga-c/src/parser.c index 896c24f..6c94913 100644 --- a/js/scripting-lang/baba-yaga-c/src/parser.c +++ b/js/scripting-lang/baba-yaga-c/src/parser.c @@ -2618,7 +2618,6 @@ static ASTNode* parser_parse_when_expression(Parser* parser) { Token* current_token = parser_peek(parser); if (current_token->type == TOKEN_LPAREN) { /* Expression in parentheses - parse the expression */ - /* Parse expression but stop at 'is' token */ identifiers[i] = parser_parse_expression(parser); if (identifiers[i] == NULL) { /* Cleanup on error */ @@ -2628,13 +2627,6 @@ static ASTNode* parser_parse_when_expression(Parser* parser) { free(identifiers); return NULL; } - - /* Check if we consumed the 'is' token and back up if needed */ - if (parser->current < parser->token_count && - parser->tokens[parser->current]->type == TOKEN_KEYWORD_IS) { - /* We consumed the 'is' token, need to back up */ - parser->current--; - } } else { /* Identifier - parse as identifier */ Token* id_token = parser_advance(parser); @@ -2644,6 +2636,18 @@ static ASTNode* parser_parse_when_expression(Parser* parser) { /* Create a sequence node for the identifiers */ test = ast_sequence_node(identifiers, identifier_count, when_token->line, when_token->column); + + /* Ensure we're positioned at the 'is' token */ + if (parser->current < parser->token_count && + parser->tokens[parser->current]->type != TOKEN_KEYWORD_IS) { + /* We're not at the 'is' token - find it */ + for (int j = parser->current; j < parser->token_count; j++) { + if (parser->tokens[j]->type == TOKEN_KEYWORD_IS) { + parser->current = j; + break; + } + } + } } else { /* Parse as single expression */ test = parser_parse_expression(parser); @@ -2796,6 +2800,9 @@ static ASTNode* parser_parse_when_pattern(Parser* parser) { /* If we hit a comparison operator, it's not multi-parameter */ literal_count = 0; break; + } else if (token->type == TOKEN_SEMICOLON) { + /* If we hit a semicolon, stop looking */ + break; } else { /* If we hit anything other than a literal or expression, it's not multi-parameter */ literal_count = 0; |