diff --git a/lang/ast/cascade.c b/lang/ast/cascade.c index a5337a9..99dbdab 100644 --- a/lang/ast/cascade.c +++ b/lang/ast/cascade.c @@ -1,8 +1,7 @@ #include "ctx.h" +#include "iterate.h" #include "node.h" -#include - static void collect_children( struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator) { diff --git a/lang/ast/ctx.c b/lang/ast/ctx.c index d01056d..18ad892 100644 --- a/lang/ast/ctx.c +++ b/lang/ast/ctx.c @@ -1,5 +1,6 @@ #include "ctx.h" +#include "../debug.h" #include "node.h" #include @@ -16,8 +17,9 @@ static void print_state_stack(struct ivy_parser *parser) b_queue_foreach (&it, &parser->p_state) { struct parser_state *state = b_unbox(struct parser_state, it.entry, s_entry); - debug_printf(" %s\n", - ivy_ast_node_type_to_string(state->s_node->n_type)); + debug_printf( + " %s\n", + ivy_ast_node_type_to_string(state->s_node->n_type)); } } #endif @@ -97,7 +99,8 @@ struct parser_state *parser_get_state_generic(struct ivy_parser *parser) return state; } -struct parser_state *parser_get_parent_state_generic(struct ivy_parser *parser, enum ivy_ast_node_type type) +struct parser_state *parser_get_parent_state_generic( + struct ivy_parser *parser, enum ivy_ast_node_type type) { b_queue_entry *entry = b_queue_last(&parser->p_state); if (!entry) { diff --git a/lang/ast/expr/arith.c b/lang/ast/expr/arith.c index d3bc6f0..4c4ad71 100644 --- a/lang/ast/expr/arith.c +++ b/lang/ast/expr/arith.c @@ -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; -} \ No newline at end of file +} diff --git a/lang/ast/expr/stmt.c b/lang/ast/expr/stmt.c index 0d805cb..29b3891 100644 --- a/lang/ast/expr/stmt.c +++ b/lang/ast/expr/stmt.c @@ -13,8 +13,8 @@ struct token_parse_result stmt_parse_while( = parser_get_state(ctx, struct expr_parser_state); if (state->s_sub_type == EXPR_SUBTYPE_KEYWORD_ARG) { - /* keyword messages have a higher precedence than inline conditionals, so - * treat this as a statement terminator. */ + /* keyword messages have a higher precedence than inline + * conditionals, so treat this as a statement terminator. */ struct token_parse_result result = expr_finalise_and_return(ctx, state); result.r_flags |= PARSE_REPEAT_TOKEN; @@ -30,7 +30,8 @@ struct token_parse_result stmt_parse_while( state->s_prev_token = IVY_KW_WHILE; - if (b_queue_empty(&state->s_operator_stack) && b_queue_empty(&state->s_output_queue)) { + if (b_queue_empty(&state->s_operator_stack) + && b_queue_empty(&state->s_output_queue)) { parser_pop_state(ctx, 0); } @@ -47,7 +48,8 @@ struct token_parse_result stmt_parse_match( struct expr_parser_state *state = parser_get_state(ctx, struct expr_parser_state); - if (state->s_prev_component == EXPR_CMP_OPERAND || state->s_prev_component == EXPR_CMP_MSG) { + if (state->s_prev_component == EXPR_CMP_OPERAND + || state->s_prev_component == EXPR_CMP_MSG) { /* match statements are operands. */ return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0); } @@ -61,7 +63,8 @@ struct token_parse_result stmt_parse_match( state->s_prev_token = IVY_KW_MATCH; - if (b_queue_empty(&state->s_operator_stack) && b_queue_empty(&state->s_output_queue)) { + if (b_queue_empty(&state->s_operator_stack) + && b_queue_empty(&state->s_output_queue)) { parser_pop_state(ctx, 0); } @@ -81,8 +84,8 @@ struct token_parse_result stmt_parse_if( = parser_get_state(ctx, struct expr_parser_state); if (state->s_sub_type == EXPR_SUBTYPE_KEYWORD_ARG) { - /* keyword messages have a higher precedence than inline conditionals, so - * treat this as a statement terminator. */ + /* keyword messages have a higher precedence than inline + * conditionals, so treat this as a statement terminator. */ struct token_parse_result result = expr_finalise_and_return(ctx, state); result.r_flags |= PARSE_REPEAT_TOKEN; @@ -98,7 +101,8 @@ struct token_parse_result stmt_parse_if( state->s_prev_token = IVY_KW_IF; - if (b_queue_empty(&state->s_operator_stack) && b_queue_empty(&state->s_output_queue)) { + if (b_queue_empty(&state->s_operator_stack) + && b_queue_empty(&state->s_output_queue)) { parser_pop_state(ctx, 0); } @@ -142,4 +146,4 @@ struct token_parse_result stmt_parse_end( struct token_parse_result result = expr_finalise_and_return(ctx, state); result.r_flags |= PARSE_REPEAT_TOKEN; return result; -} \ No newline at end of file +} diff --git a/lang/ast/match.c b/lang/ast/match.c index e32e2d8..b317d75 100644 --- a/lang/ast/match.c +++ b/lang/ast/match.c @@ -1,6 +1,6 @@ #include "block.h" -#include "iterate.h" #include "expr/expr.h" +#include "iterate.h" struct match_parser_state { struct parser_state s_base; @@ -16,14 +16,11 @@ struct match_parser_state { static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_t arg) { - struct match_parser_state *state - = (struct match_parser_state *)sp; + struct match_parser_state *state = (struct match_parser_state *)sp; state->s_prev_node = (struct ivy_ast_node *)arg; } -struct token_parse_result parse_match( - struct ivy_parser *ctx, - struct ivy_token *tok) +struct token_parse_result parse_match(struct ivy_parser *ctx, struct ivy_token *tok) { struct match_parser_state *state = parser_get_state(ctx, struct match_parser_state); @@ -32,7 +29,8 @@ struct token_parse_result parse_match( return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0); } - state->s_cur_branch = (struct ivy_ast_cond_node *)ast_node_create(IVY_AST_COND); + state->s_cur_branch + = (struct ivy_ast_cond_node *)ast_node_create(IVY_AST_COND); if (!state->s_cur_branch) { return PARSE_RESULT(IVY_ERR_NO_MEMORY, 0); } @@ -53,12 +51,12 @@ static enum ivy_status flush_current_branch(struct match_parser_state *state) if (!state->s_cur_branch) { return IVY_ERR_INTERNAL_FAILURE; } - + b_queue_push_back(&state->s_branches, &state->s_cur_branch->n_base.n_entry); - + state->s_cur_branch = (struct ivy_ast_cond_node *)ast_node_create(IVY_AST_COND); - + if (!state->s_cur_branch) { return IVY_ERR_NO_MEMORY; } @@ -96,7 +94,7 @@ struct token_parse_result parse_in(struct ivy_parser *ctx, struct ivy_token *tok return PARSE_RESULT(IVY_OK, 0); } -static enum ivy_status finalise_match(struct match_parser_state* state) +static enum ivy_status finalise_match(struct match_parser_state *state) { struct ivy_ast_match_node *match = (struct ivy_ast_match_node *)state->s_base.s_node; @@ -119,7 +117,8 @@ static struct token_parse_result parse_arrow( struct match_parser_state *state = parser_get_state(ctx, struct match_parser_state); - if (state->s_prev_token != IVY_KW_IN && state->s_prev_token != IVY_SYM_COMMA) { + if (state->s_prev_token != IVY_KW_IN + && state->s_prev_token != IVY_SYM_COMMA) { /* this token can only appear after the `in` keyword and an expression. */ return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0); } @@ -171,7 +170,8 @@ static struct token_parse_result parse_comma( return PARSE_RESULT(IVY_OK, 0); } -static struct token_parse_result parse_end(struct ivy_parser *ctx, struct ivy_token *tok) +static struct token_parse_result parse_end( + struct ivy_parser *ctx, struct ivy_token *tok) { struct match_parser_state *state = parser_get_state(ctx, struct match_parser_state); @@ -202,13 +202,12 @@ static struct token_parse_result parse_end(struct ivy_parser *ctx, struct ivy_to static enum ivy_status add_child( struct parser_state *parent, struct ivy_ast_node *child) { - struct match_parser_state *state - = (struct match_parser_state *)parent; + struct match_parser_state *state = (struct match_parser_state *)parent; if (state->s_prev_node) { return IVY_ERR_BAD_SYNTAX; } - + state->s_prev_node = child; return IVY_OK; } @@ -216,14 +215,14 @@ static enum ivy_status add_child( static void match_collect_children( struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator) { - struct ivy_ast_match_node *match - = (struct ivy_ast_match_node *)node; + struct ivy_ast_match_node *match = (struct ivy_ast_match_node *)node; ast_node_iterator_enqueue_node(iterator, node, match->n_cond); b_queue_iterator it = {0}; b_queue_foreach (&it, &match->n_branches) { - struct ivy_ast_node *branch = b_unbox(struct ivy_ast_node, it.entry, n_entry); + struct ivy_ast_node *branch + = b_unbox(struct ivy_ast_node, it.entry, n_entry); ast_node_iterator_enqueue_node(iterator, node, branch); } } diff --git a/lang/ast/msgh.c b/lang/ast/msgh.c index 30a3dce..822b506 100644 --- a/lang/ast/msgh.c +++ b/lang/ast/msgh.c @@ -98,7 +98,7 @@ static enum ivy_status add_child( return IVY_OK; } -static void init_state(struct ivy_parser *ctx, struct parser_state *sp) +static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_t arg) { struct msgh_parser_state *state = (struct msgh_parser_state *)sp; state->s_oneline = false; diff --git a/lang/ast/while.c b/lang/ast/while.c index 3580d33..5111a28 100644 --- a/lang/ast/while.c +++ b/lang/ast/while.c @@ -1,6 +1,6 @@ #include "block.h" -#include "iterate.h" #include "expr/expr.h" +#include "iterate.h" struct while_parser_state { struct parser_state s_base; @@ -14,14 +14,11 @@ struct while_parser_state { static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_t arg) { - struct while_parser_state *state - = (struct while_parser_state *)sp; + struct while_parser_state *state = (struct while_parser_state *)sp; state->s_prev_node = (struct ivy_ast_node *)arg; } -struct token_parse_result parse_while( - struct ivy_parser* ctx, - struct ivy_token* tok) +struct token_parse_result parse_while(struct ivy_parser *ctx, struct ivy_token *tok) { struct while_parser_state *state = parser_get_state(ctx, struct while_parser_state); @@ -41,11 +38,13 @@ struct token_parse_result parse_while( state->s_prev_token = IVY_KW_WHILE; expr->s_subexpr_depth = 1; + expr->s_terminator = IVY_KW_DO; return PARSE_RESULT(IVY_OK, 0); } -static struct token_parse_result parse_do(struct ivy_parser *ctx, struct ivy_token *tok) +static struct token_parse_result parse_do( + struct ivy_parser *ctx, struct ivy_token *tok) { struct while_parser_state *state = parser_get_state(ctx, struct while_parser_state); @@ -77,7 +76,8 @@ static struct token_parse_result parse_do(struct ivy_parser *ctx, struct ivy_tok return PARSE_RESULT(IVY_OK, 0); } -static struct token_parse_result parse_expr_begin(struct ivy_parser* ctx, struct ivy_token* tok) +static struct token_parse_result parse_expr_begin( + struct ivy_parser *ctx, struct ivy_token *tok) { struct while_parser_state *state = parser_get_state(ctx, struct while_parser_state); @@ -87,7 +87,9 @@ static struct token_parse_result parse_expr_begin(struct ivy_parser* ctx, struct return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0); } - struct block_parser_state *block = (struct block_parser_state *)parser_push_state(ctx, IVY_AST_BLOCK, 0); + struct block_parser_state *block + = (struct block_parser_state *)parser_push_state( + ctx, IVY_AST_BLOCK, 0); block->s_terminator = IVY_KW_END; return PARSE_RESULT(IVY_OK, PARSE_REPEAT_TOKEN); } @@ -106,7 +108,7 @@ static enum ivy_status finalise_while_loop(struct while_parser_state *state) /* the condition and body are parsed in reverse order for inline loops. */ loop->n_cond = state->s_prev_node; - loop->n_body = state->s_body; + loop->n_body = state->s_body; state->s_prev_node = NULL; return IVY_OK; } @@ -116,7 +118,6 @@ static enum ivy_status finalise_while_loop(struct while_parser_state *state) return IVY_ERR_BAD_SYNTAX; } - loop->n_cond = state->s_cond; loop->n_body = state->s_prev_node; @@ -146,7 +147,8 @@ static struct token_parse_result parse_punct_terminator( return PARSE_RESULT(IVY_OK, PARSE_REPEAT_TOKEN); } -static struct token_parse_result parse_end(struct ivy_parser *ctx, struct ivy_token *tok) +static struct token_parse_result parse_end( + struct ivy_parser *ctx, struct ivy_token *tok) { struct while_parser_state *state = parser_get_state(ctx, struct while_parser_state); @@ -168,13 +170,12 @@ static struct token_parse_result parse_end(struct ivy_parser *ctx, struct ivy_to static enum ivy_status add_child( struct parser_state *parent, struct ivy_ast_node *child) { - struct while_parser_state *state - = (struct while_parser_state *)parent; + struct while_parser_state *state = (struct while_parser_state *)parent; if (state->s_prev_node) { return IVY_ERR_BAD_SYNTAX; } - + state->s_prev_node = child; return IVY_OK; } @@ -182,7 +183,8 @@ static enum ivy_status add_child( static void collect_children( struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator) { - struct ivy_ast_while_loop_node *loop = (struct ivy_ast_while_loop_node *)node; + struct ivy_ast_while_loop_node *loop + = (struct ivy_ast_while_loop_node *)node; if (loop->n_cond) { ast_node_iterator_enqueue_node(iterator, node, loop->n_cond); @@ -213,4 +215,4 @@ struct ast_node_type while_loop_node_ops = { .n_expr_parser = { .expr_begin = parse_expr_begin, }, -}; \ No newline at end of file +}; diff --git a/lang/debug.h b/lang/debug.h index af949ff..427bacc 100644 --- a/lang/debug.h +++ b/lang/debug.h @@ -3,10 +3,13 @@ #include +/* uncomment this to enable super-verbose debugging output */ +// #define IVY_LANG_DEBUG + #if defined(IVY_LANG_DEBUG) #define debug_printf(...) printf(__VA_ARGS__) #else #define debug_printf(...) #endif -#endif \ No newline at end of file +#endif diff --git a/lang/misc.c b/lang/misc.c deleted file mode 100644 index e69de29..0000000