From c5b103d543fa0597a6b690039c7dd4afd115cdde Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 20 Dec 2021 08:58:35 -0600 Subject: [PATCH] changed implicit code block syntax --- src/parser.c | 25 +++++++++++++------------ tests/aoc-2021/day09.onyx | 8 ++++---- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/parser.c b/src/parser.c index c473394c..6d55e323 100644 --- a/src/parser.c +++ b/src/parser.c @@ -759,18 +759,6 @@ static AstTyped* parse_factor(OnyxParser* parser) { // foo(x, y, #code { // // ... // }) - if (next_tokens_are(parser, 2, '#', '{')) { - consume_token(parser); - - AstCodeBlock* code_block = make_node(AstCodeBlock, Ast_Kind_Code_Block); - code_block->token = parser->curr; - code_block->type_node = builtin_code_type; - - code_block->code = (AstNode *) parse_block(parser, 1, NULL); - ((AstBlock *) code_block->code)->rules = Block_Rule_Code_Block; - - bh_arr_push(call_node->args.values, (AstTyped *) code_block); - } // Wrap expressions in AstArgument bh_arr_each(AstTyped *, arg, call_node->args.values) { @@ -1419,6 +1407,19 @@ static AstNode* parse_statement(OnyxParser* parser) { case Token_Type_Literal_Float: case Token_Type_Literal_String: retval = (AstNode *) parse_compound_expression(parser, 1); + if (retval->kind == Ast_Kind_Call) { + if (parser->curr->type == '{') { + AstCodeBlock* code_block = make_node(AstCodeBlock, Ast_Kind_Code_Block); + code_block->token = parser->curr; + code_block->type_node = builtin_code_type; + + code_block->code = (AstNode *) parse_block(parser, 1, NULL); + ((AstBlock *) code_block->code)->rules = Block_Rule_Code_Block; + + bh_arr_push(((AstCall *) retval)->args.values, (AstTyped *) make_argument(context.ast_alloc, (AstTyped *) code_block)); + needs_semicolon = 0; + } + } break; case Token_Type_Keyword_If: diff --git a/tests/aoc-2021/day09.onyx b/tests/aoc-2021/day09.onyx index 4750f7c8..6121a75d 100644 --- a/tests/aoc-2021/day09.onyx +++ b/tests/aoc-2021/day09.onyx @@ -84,14 +84,14 @@ main :: (args) => { } for y: height - 1 do for x: width { - map.update(^heightmap, .{x,y}) #{ + map.update(^heightmap, .{x,y}) { it.dy = it.height - heightmap[Pos.{x,y+1}].height; - }; + } } for x: width - 1 do for y: height { - map.update(^heightmap, .{x,y}) #{ + map.update(^heightmap, .{x,y}) { it.dx = it.height - heightmap[Pos.{x+1,y}].height; - }; + } } lowest: [..] Pos; -- 2.25.1