changed implicit code block syntax
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 20 Dec 2021 14:58:35 +0000 (08:58 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 20 Dec 2021 14:58:35 +0000 (08:58 -0600)
src/parser.c
tests/aoc-2021/day09.onyx

index c473394c2fcb0ae580d22828f6bfa634beed8987..6d55e3239a029f7e4864190ee7b858238361410c 100644 (file)
@@ -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:
index 4750f7c82bd748b7bfd622a9a0adaa36cd2a13ad..6121a75d4ac3ffe350a02801cb95f317f01e31c5 100644 (file)
@@ -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;