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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user