bugfix with nested tags
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 29 Aug 2022 02:09:56 +0000 (21:09 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 29 Aug 2022 02:09:56 +0000 (21:09 -0500)
include/parser.h
src/parser.c

index 4c1e505a21ad6e6e0a48d2c4127da2d3aa21b0b7..48889a86784d8531593040dec768c5bb4c320ae5 100644 (file)
@@ -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);
index cd289d4821255e65c18b724653864b6b63cb394a..7050bf65f1f65fbc941a1a24f0c533c4a3ec4f5f 100644 (file)
@@ -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,