From: Brendan Hansen Date: Mon, 29 Aug 2022 02:09:56 +0000 (-0500) Subject: bugfix with nested tags X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=2fe37c7b34a4e15060fc54113808d516581fe6e6;p=onyx.git bugfix with nested tags --- diff --git a/include/parser.h b/include/parser.h index 4c1e505a..48889a86 100644 --- a/include/parser.h +++ b/include/parser.h @@ -34,10 +34,10 @@ typedef struct OnyxParser { bh_arr(AstTyped *) stored_tags; - b32 hit_unexpected_token : 1; + u16 tag_depth : 16; + b32 hit_unexpected_token : 1; b32 parse_calls : 1; - b32 inside_tag : 1; } OnyxParser; const char* onyx_ast_node_kind_string(AstKind kind); diff --git a/src/parser.c b/src/parser.c index cd289d48..7050bf65 100644 --- a/src/parser.c +++ b/src/parser.c @@ -189,7 +189,7 @@ static void expect_no_stored_tags(OnyxParser *parser) { static void flush_stored_tags(OnyxParser *parser, bh_arr(AstTyped *) *out_arr) { // - // When inside_tag is true, no tags will be added to the element. + // When tag_depth > 0, no tags will be added to the element. // This happens if you have a something like so, // // #tag "asdf" @@ -199,7 +199,7 @@ static void flush_stored_tags(OnyxParser *parser, bh_arr(AstTyped *) *out_arr) { // In this situation, the inner procedure defined in the second // tag should NOT consume the "asdf" tag. // - if (bh_arr_length(parser->stored_tags) == 0 || parser->inside_tag) return; + if (bh_arr_length(parser->stored_tags) == 0 || parser->tag_depth > 0) return; bh_arr(AstTyped *) arr = *out_arr; @@ -2066,14 +2066,14 @@ static AstStructType* parse_struct(OnyxParser* parser) { while (parse_possible_directive(parser, "tag")) { if (meta_tags == NULL) bh_arr_new(global_heap_allocator, meta_tags, 1); - parser->inside_tag = 1; + parser->tag_depth += 1; do { AstTyped* expr = parse_expression(parser, 0); bh_arr_push(meta_tags, expr); } while (consume_token_if_next(parser, ',')); - parser->inside_tag = 0; + parser->tag_depth -= 1; } member_is_used = consume_token_if_next(parser, Token_Type_Keyword_Use); @@ -3306,12 +3306,12 @@ static void parse_top_level_statement(OnyxParser* parser) { return; } else if (parse_possible_directive(parser, "tag")) { - parser->inside_tag = 1; + parser->tag_depth += 1; AstTyped *expr = parse_expression(parser, 0); bh_arr_push(parser->stored_tags, expr); - parser->inside_tag = 0; + parser->tag_depth -= 1; return; } else { @@ -3458,6 +3458,7 @@ OnyxParser onyx_parser_create(bh_allocator alloc, OnyxTokenizer *tokenizer) { parser.scope_flags = NULL; parser.stored_tags = NULL; parser.parse_calls = 1; + parser.tag_depth = 0; parser.polymorph_context = (PolymorphicContext) { .root_node = NULL,