diff options
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/parser.c b/src/parser.c index ff34663..a6b4ecf 100644 --- a/src/parser.c +++ b/src/parser.c @@ -48,6 +48,10 @@ int parser_init(Parser *self, amal_compiler *compiler, ArenaAllocator *allocator return PARSER_OK; } +static bool parser_is_current_scope_file_scope(Parser *self) { + return self->current_scope == &self->struct_decl.body; +} + /* BODY_LOOP = BODY* @end_token */ @@ -359,6 +363,12 @@ static CHECK_RESULT FunctionDecl* parser_parse_closure(Parser *self) { if(!signature) return NULL; + /* + TODO: Implement function declaration inside other functions. + Such functions should be moved to the file scope in the bytecode generation + */ + assert(parser_is_current_scope_file_scope(self)); + throw_if_error(arena_allocator_alloc(self->allocator, sizeof(FunctionDecl), (void**)&result)); throw_if_error(funcdecl_init(result, signature, self->current_scope, self->allocator)); signature->func_decl = result; @@ -500,16 +510,20 @@ static CHECK_RESULT ElseIfStatement* parser_parse_else_if_statement(Parser *self } static void parser_parse_else_if_statement_loop(Parser *self, IfStatement *if_stmt) { - ElseIfStatement *else_if_stmt; - else_if_stmt = if_stmt->else_if_stmt; + ElseIfStatement *else_if_stmt = NULL; for(;;) { ElseIfStatement *next_else_if; next_else_if = parser_parse_else_if_statement(self); if(!next_else_if) break; - else_if_stmt->next_else_if_stmt = next_else_if; + + if(!else_if_stmt) + if_stmt->else_if_stmt = next_else_if; + else + else_if_stmt->next_else_if_stmt = next_else_if; + /* else statement that has no condition can't be followed by another else statement */ - if(!else_if_stmt->condition) + if(!next_else_if->condition) break; else_if_stmt = next_else_if; } |