lang: ast: implement for-loop parsing

This commit is contained in:
2024-12-06 10:02:31 +00:00
parent f3cd89c72a
commit d88d58be70
7 changed files with 347 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
#include "../node.h"
#include "../block.h"
#include "../debug.h"
#include "../node.h"
#include "expr.h"
#include <blue/object/string.h>
@@ -481,6 +482,40 @@ struct token_parse_result arith_parse_in(
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
struct token_parse_result arith_parse_do(
struct ivy_parser *ctx, struct ivy_token *tok)
{
struct expr_parser_state *state
= parser_get_state(ctx, struct expr_parser_state);
bool terminator = false;
if (state->s_terminator == IVY_KW_DO) {
terminator = true;
}
if (state->s_sub_type == EXPR_SUBTYPE_KEYWORD_MSG
|| state->s_sub_type == EXPR_SUBTYPE_KEYWORD_ARG) {
terminator = true;
}
if (terminator) {
state->s_prev_token = IVY_KW_DO;
struct token_parse_result result
= expr_finalise_and_return(ctx, state);
result.r_flags = PARSE_REPEAT_TOKEN;
return result;
}
/* next component will be a block. */
struct block_parser_state *block
= (struct block_parser_state *)parser_push_state(
ctx, IVY_AST_BLOCK, 0);
/* set the sub-expression depth to be non-zero so the expression parser doesn't consume the expression separator. */
state->s_prev_token = IVY_KW_DO;
return PARSE_RESULT(IVY_OK, 0);
}
struct token_parse_result arith_parse_ident(
struct ivy_parser *ctx, struct ivy_token *tok)
{