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:
@@ -472,18 +472,31 @@ struct token_parse_result arith_parse_operator(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
unsigned short tok_id = 0;
|
||||
|
||||
switch (tok->t_type) {
|
||||
case IVY_TOK_SYMBOL:
|
||||
tok_id = tok->t_symbol;
|
||||
state->s_prev_token = tok->t_symbol;
|
||||
break;
|
||||
case IVY_TOK_KEYWORD:
|
||||
tok_id = tok->t_keyword;
|
||||
state->s_prev_token = tok->t_keyword;
|
||||
break;
|
||||
default:
|
||||
tok_id = tok->t_type;
|
||||
state->s_prev_token = tok->t_type;
|
||||
break;
|
||||
}
|
||||
|
||||
if (expr_terminates_at_token(state, tok_id)) {
|
||||
/* treat this as a statement terminator. */
|
||||
struct token_parse_result result
|
||||
= expr_finalise_and_return(ctx, state);
|
||||
result.r_flags |= PARSE_REPEAT_TOKEN;
|
||||
return result;
|
||||
}
|
||||
|
||||
struct ivy_ast_node *op = create_operator_node_from_token(tok);
|
||||
if (!op) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
@@ -1136,6 +1149,14 @@ struct token_parse_result arith_parse_dot(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (expr_terminates_at_token(state, IVY_SYM_DOT)) {
|
||||
/* treat this as a statement terminator. */
|
||||
struct token_parse_result result
|
||||
= expr_finalise_and_return(ctx, state);
|
||||
result.r_flags |= PARSE_REPEAT_TOKEN;
|
||||
return result;
|
||||
}
|
||||
|
||||
state->s_prev_token = IVY_SYM_DOT;
|
||||
return expr_finalise_and_return(ctx, state);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user