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:
@@ -1,4 +1,5 @@
|
||||
#include "ctx.h"
|
||||
#include "expr/expr.h"
|
||||
#include "iterate.h"
|
||||
#include "node.h"
|
||||
|
||||
@@ -18,6 +19,13 @@ static struct token_parse_result parse_use_keyword(
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
static struct token_parse_result parse_var_keyword(
|
||||
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_class_keyword(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
@@ -67,6 +75,7 @@ struct ast_node_type unit_node_ops = {
|
||||
KW_PARSER(PACKAGE, parse_package_keyword),
|
||||
KW_PARSER(CLASS, parse_class_keyword),
|
||||
KW_PARSER(USE, parse_use_keyword),
|
||||
KW_PARSER(VAR, parse_var_keyword),
|
||||
},
|
||||
.n_symbol_parsers = {
|
||||
SYM_PARSER(DOT, parse_dot),
|
||||
|
||||
Reference in New Issue
Block a user