Commit 6f918804 authored by Guillaume Charifi's avatar Guillaume Charifi

compiler/parser: Allow newlines between container blocks.

parent f7b6a04f
......@@ -746,6 +746,7 @@ static int parse_ifelse(struct parser_ctx *ctx, unsigned long *cur_tok_id, struc
{
int result;
unsigned long i = *cur_tok_id;
unsigned long i_backup;
struct bm_ast_node ifelse;
struct bm_ast_node expr;
struct bm_ast_node block_if;
......@@ -763,16 +764,24 @@ static int parse_ifelse(struct parser_ctx *ctx, unsigned long *cur_tok_id, struc
parser_node_set_child(&ifelse, BM_AST_NODE_IFELSE_CHILD_EXPR, &expr);
parser_ignore_newlines(ctx, &i);
result = parse_block(ctx, &i, &block_if);
if (result < 0)
goto failed;
parser_node_set_child(&ifelse, BM_AST_NODE_IFELSE_CHILD_BLOCK_IF, &block_if);
i_backup = i;
parser_ignore_newlines(ctx, &i);
if (ctx->in->tokens[i].type == BM_TOK_ELSE)
{
i++;
parser_ignore_newlines(ctx, &i);
result = parse_block(ctx, &i, &block_else);
if (result < 0)
......@@ -784,6 +793,8 @@ static int parse_ifelse(struct parser_ctx *ctx, unsigned long *cur_tok_id, struc
else
{
parser_node_init_instr_noop(&block_else);
i = i_backup;
}
parser_node_set_child(&ifelse, BM_AST_NODE_IFELSE_CHILD_BLOCK_ELSE, &block_else);
......@@ -818,6 +829,8 @@ static int parse_loop(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct
i++;
}
parser_ignore_newlines(ctx, &i);
result = parse_block(ctx, &i, &block);
if (result < 0)
return -1;
......@@ -850,6 +863,8 @@ static int parse_while(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct
parser_node_set_child(&nwhile, BM_AST_NODE_WHILE_CHILD_EXPR, &cond);
parser_ignore_newlines(ctx, &i);
result = parse_block(ctx, &i, &block);
if (result < 0)
goto failed;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment