lang: add var keyword for variable declarations

the var keyword allows greater control over what scope a
particular variable exists in. it clarifies whether a new
variable is being defined or an existing variable is being
assigned to. it will also facilitate the implementation of
global variables.
This commit is contained in:
2025-04-15 11:02:47 +01:00
parent abebdb595a
commit e430b7b2f1
9 changed files with 190 additions and 4 deletions

View File

@@ -101,6 +101,13 @@ static struct token_parse_result parse_symbol(
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
static struct token_parse_result parse_var(
struct ivy_parser *ctx, struct ivy_token *tok)
{
parser_push_state(ctx, IVY_AST_VAR, 0);
return PARSE_RESULT(IVY_OK, 0);
}
static struct token_parse_result parse_expr_begin(
struct ivy_parser *ctx, struct ivy_token *tok)
{
@@ -150,6 +157,7 @@ struct ast_node_type block_node_ops = {
.n_state_size = sizeof(struct block_parser_state),
.n_node_size = sizeof(struct ivy_ast_block_node),
.n_keyword_parsers = {
KW_PARSER(VAR, parse_var),
KW_PARSER(END, parse_end),
KW_PARSER(ELSE, parse_else),
KW_PARSER_FALLBACK(parse_keyword),