lang: add missing includes; misc formatting cleanup
This commit is contained in:
@@ -51,7 +51,8 @@ static void print_operand(struct ivy_ast_node *node)
|
||||
}
|
||||
}
|
||||
|
||||
enum ivy_status arith_push_operand(struct expr_parser_state *state, struct ivy_token *tok)
|
||||
enum ivy_status arith_push_operand(
|
||||
struct expr_parser_state *state, struct ivy_token *tok)
|
||||
{
|
||||
switch (tok->t_type) {
|
||||
case IVY_TOK_IDENT: {
|
||||
@@ -493,7 +494,6 @@ struct token_parse_result arith_parse_ident(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
|
||||
result = arith_parse_operator(ctx, tok);
|
||||
state->s_prev_component = EXPR_CMP_MSG;
|
||||
return result;
|
||||
@@ -576,7 +576,8 @@ static struct ivy_ast_selector_node *keyword_selector_from_label_list(b_queue *l
|
||||
return sel;
|
||||
}
|
||||
|
||||
static struct ivy_ast_cascade_node *expr_finalise_cascade(struct expr_parser_state *state)
|
||||
static struct ivy_ast_cascade_node *expr_finalise_cascade(
|
||||
struct expr_parser_state *state)
|
||||
{
|
||||
struct ivy_ast_cascade_node *cascade
|
||||
= (struct ivy_ast_cascade_node *)ast_node_create(IVY_AST_CASCADE);
|
||||
@@ -595,7 +596,8 @@ static struct ivy_ast_cascade_node *expr_finalise_cascade(struct expr_parser_sta
|
||||
return cascade;
|
||||
}
|
||||
|
||||
static struct ivy_ast_msg_node *expr_finalise_keyword_msg(struct expr_parser_state *state)
|
||||
static struct ivy_ast_msg_node *expr_finalise_keyword_msg(
|
||||
struct expr_parser_state *state)
|
||||
{
|
||||
struct ivy_ast_msg_node *msg
|
||||
= (struct ivy_ast_msg_node *)ast_node_create(IVY_AST_MSG);
|
||||
@@ -617,7 +619,8 @@ static struct ivy_ast_msg_node *expr_finalise_keyword_msg(struct expr_parser_sta
|
||||
return msg;
|
||||
}
|
||||
|
||||
static struct ivy_ast_msg_node *expr_finalise_complex_msg(struct expr_parser_state *state)
|
||||
static struct ivy_ast_msg_node *expr_finalise_complex_msg(
|
||||
struct expr_parser_state *state)
|
||||
{
|
||||
struct ivy_ast_msg_node *msg = state->s_msg;
|
||||
if (!msg) {
|
||||
@@ -667,10 +670,11 @@ struct token_parse_result arith_parse_right_paren(
|
||||
|
||||
static enum ivy_status begin_cascade_operation(struct ivy_parser *ctx)
|
||||
{
|
||||
struct expr_parser_state *state = parser_get_state(ctx, struct expr_parser_state);
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
/* this is the beginning of a cascade operation */
|
||||
|
||||
|
||||
struct ivy_ast_msg_node *first_msg = NULL;
|
||||
|
||||
if (state->s_sub_type == EXPR_SUBTYPE_KEYWORD_MSG) {
|
||||
@@ -678,16 +682,19 @@ static enum ivy_status begin_cascade_operation(struct ivy_parser *ctx)
|
||||
parser_pop_state(ctx, 0);
|
||||
} else {
|
||||
/* we need to find who the first message in the cascade is being sent to. */
|
||||
enum ivy_operator_precedence min_precedence = IVY_PRECEDENCE_CASCADE;
|
||||
enum ivy_operator_precedence min_precedence
|
||||
= IVY_PRECEDENCE_CASCADE;
|
||||
|
||||
struct ivy_ast_node *prev = b_unbox(
|
||||
struct ivy_ast_node,
|
||||
b_queue_last(&state->s_operator_stack), n_entry);
|
||||
if (prev && prev->n_type == IVY_AST_MSG) {
|
||||
/* unary complex messages (which will be found on the operator stack) have a very high
|
||||
* precedence (much higher than most arithmetic operators), so the recipient will be much
|
||||
* narrower. this also means that any subsequent messages in the cascade inherit this high
|
||||
* precedence, regardless of their type. */
|
||||
/* unary complex messages (which will be found on the
|
||||
* operator stack) have a very high precedence (much
|
||||
* higher than most arithmetic operators), so the
|
||||
* recipient will be much narrower. this also means that
|
||||
* any subsequent messages in the cascade inherit this
|
||||
* high precedence, regardless of their type. */
|
||||
min_precedence = IVY_PRECEDENCE_UNARY_MSG;
|
||||
}
|
||||
|
||||
@@ -699,16 +706,17 @@ static enum ivy_status begin_cascade_operation(struct ivy_parser *ctx)
|
||||
}
|
||||
|
||||
if (expr->n_type != IVY_AST_MSG) {
|
||||
/* the recipient and first message of the cascade operation is ambiguous due
|
||||
* to operator precedence. this is usually resolved by adding parentheses
|
||||
* (either around the recipient or around the cascade) to make the recipient
|
||||
* and first message clear. */
|
||||
/* the recipient and first message of the cascade
|
||||
* operation is ambiguous due to operator precedence.
|
||||
* this is usually resolved by adding parentheses
|
||||
* (either around the recipient or around the cascade)
|
||||
* to make the recipient and first message clear. */
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
first_msg = (struct ivy_ast_msg_node *)expr;
|
||||
}
|
||||
|
||||
|
||||
struct expr_parser_state *cascade_expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
@@ -765,8 +773,8 @@ struct token_parse_result arith_parse_semicolon(
|
||||
if (end_subexpr) {
|
||||
/* finish parsing this expression and let the parent context handle the semicolon. */
|
||||
struct ivy_ast_node *expr = NULL;
|
||||
enum ivy_status status
|
||||
= expr_finalise_arith(state, &expr, IVY_PRECEDENCE_ASSIGN);
|
||||
enum ivy_status status = expr_finalise_arith(
|
||||
state, &expr, IVY_PRECEDENCE_ASSIGN);
|
||||
if (status != IVY_OK) {
|
||||
return PARSE_RESULT(status, 0);
|
||||
}
|
||||
@@ -776,7 +784,8 @@ struct token_parse_result arith_parse_semicolon(
|
||||
return PARSE_RESULT(IVY_OK, PARSE_REPEAT_TOKEN);
|
||||
}
|
||||
|
||||
struct expr_parser_state *parent_state = parser_get_parent_state(ctx, IVY_AST_EXPR, struct expr_parser_state);
|
||||
struct expr_parser_state *parent_state = parser_get_parent_state(
|
||||
ctx, IVY_AST_EXPR, struct expr_parser_state);
|
||||
|
||||
if (state->s_sub_type == EXPR_SUBTYPE_CASCADE) {
|
||||
/* this is another message in a cascade series. */
|
||||
@@ -845,7 +854,7 @@ struct token_parse_result expr_finalise(
|
||||
}
|
||||
|
||||
if (state->s_sub_type == EXPR_SUBTYPE_COMPLEX_MSG) {
|
||||
/* this is the end of a keyword-message */
|
||||
/* this is the end of a complex message */
|
||||
struct ivy_ast_msg_node *msg = expr_finalise_complex_msg(state);
|
||||
*result = (struct ivy_ast_node *)msg;
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
@@ -860,8 +869,7 @@ struct token_parse_result expr_finalise(
|
||||
|
||||
/* this is the end of a regular expression or sub-expression */
|
||||
struct ivy_ast_node *expr = NULL;
|
||||
enum ivy_status status
|
||||
= expr_finalise_arith(state, &expr, min_precedence);
|
||||
enum ivy_status status = expr_finalise_arith(state, &expr, min_precedence);
|
||||
if (status != IVY_OK) {
|
||||
return PARSE_RESULT(status, 0);
|
||||
}
|
||||
@@ -874,7 +882,8 @@ struct token_parse_result expr_finalise_and_return(
|
||||
struct ivy_parser *ctx, struct expr_parser_state *state)
|
||||
{
|
||||
struct ivy_ast_node *expr_node = NULL;
|
||||
struct token_parse_result result = expr_finalise(ctx, state, IVY_PRECEDENCE_ASSIGN, &expr_node);
|
||||
struct token_parse_result result
|
||||
= expr_finalise(ctx, state, IVY_PRECEDENCE_ASSIGN, &expr_node);
|
||||
|
||||
if (result.r_status != IVY_OK) {
|
||||
return result;
|
||||
@@ -899,22 +908,45 @@ struct token_parse_result arith_parse_dot(
|
||||
/* end-of-expression with mismatched parentheses */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
|
||||
state->s_prev_token = IVY_SYM_DOT;
|
||||
return expr_finalise_and_return(ctx, state);
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_caret(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
/* caret must be used at the beginning of a top-level expression */
|
||||
if (state->s_subexpr_depth > 0 || state->s_paren_depth > 0) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (!b_queue_empty(&state->s_operator_stack)
|
||||
|| !b_queue_empty(&state->s_output_queue)) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
state->s_prev_token = IVY_SYM_CARET;
|
||||
state->s_return = true;
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_comma(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
|
||||
if (state->s_type != EXPR_TYPE_ARITH) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (state->s_paren_depth > 0 && (state->s_prev_component == EXPR_CMP_OPERAND || state->s_prev_component == EXPR_CMP_MSG)) {
|
||||
if (state->s_paren_depth > 0
|
||||
&& (state->s_prev_component == EXPR_CMP_OPERAND
|
||||
|| state->s_prev_component == EXPR_CMP_MSG)) {
|
||||
/* tuple. */
|
||||
return PARSE_RESULT(IVY_ERR_NOT_SUPPORTED, 0);
|
||||
}
|
||||
@@ -952,8 +984,8 @@ struct token_parse_result arith_parse_label(
|
||||
* next argument. terminate here and propagate this label to the
|
||||
* parent keyword-message parser context. */
|
||||
struct ivy_ast_node *expr = NULL;
|
||||
enum ivy_status status
|
||||
= expr_finalise_arith(state, &expr, IVY_PRECEDENCE_ASSIGN);
|
||||
enum ivy_status status = expr_finalise_arith(
|
||||
state, &expr, IVY_PRECEDENCE_ASSIGN);
|
||||
if (status != IVY_OK) {
|
||||
return PARSE_RESULT(status, 0);
|
||||
}
|
||||
@@ -970,13 +1002,13 @@ struct token_parse_result arith_parse_label(
|
||||
bool new_parser = true;
|
||||
|
||||
if (b_queue_empty(&state->s_operator_stack)
|
||||
&& b_queue_empty(&state->s_output_queue)) {
|
||||
&& b_queue_empty(&state->s_output_queue)) {
|
||||
new_parser = false;
|
||||
}
|
||||
|
||||
if (new_parser) {
|
||||
msg_expr = (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
} else {
|
||||
msg_expr = state;
|
||||
}
|
||||
@@ -988,8 +1020,8 @@ struct token_parse_result arith_parse_label(
|
||||
struct ivy_ast_node *expr = NULL;
|
||||
|
||||
if (state->s_sub_type != EXPR_SUBTYPE_MSG) {
|
||||
enum ivy_status status
|
||||
= expr_finalise_arith(state, &expr, IVY_PRECEDENCE_KEYWORD_MSG);
|
||||
enum ivy_status status = expr_finalise_arith(
|
||||
state, &expr, IVY_PRECEDENCE_KEYWORD_MSG);
|
||||
if (status != IVY_OK) {
|
||||
return PARSE_RESULT(status, 0);
|
||||
}
|
||||
@@ -1033,8 +1065,9 @@ enum ivy_status arith_add_child(
|
||||
if (state->s_sub_type == EXPR_SUBTYPE_CASCADE) {
|
||||
/* treat the child node as a cascaded message */
|
||||
b_queue_push_back(&state->s_cascade_msg, &child->n_entry);
|
||||
} else if (state->s_sub_type == EXPR_SUBTYPE_KEYWORD_MSG
|
||||
|| state->s_sub_type == EXPR_SUBTYPE_COMPLEX_MSG) {
|
||||
} else if (
|
||||
state->s_sub_type == EXPR_SUBTYPE_KEYWORD_MSG
|
||||
|| state->s_sub_type == EXPR_SUBTYPE_COMPLEX_MSG) {
|
||||
/* treat the child node as a keyword-message argument */
|
||||
b_queue_push_back(&state->s_args, &child->n_entry);
|
||||
} else if (state->s_sub_type == EXPR_SUBTYPE_KEYWORD_ARG) {
|
||||
@@ -1053,4 +1086,4 @@ enum ivy_status arith_add_child(
|
||||
}
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user