struct pakfire_parser_declaration* declaration;
}
-%destructor { pakfire_parser_unref($$); } <parser>
+%initial-action {
+ *parser = pakfire_parser_create(pakfire, parent, NULL, 0);
+ if (!*parser)
+ ABORT;
+
+ // This is now the new parent parser
+ if (parent)
+ pakfire_parser_unref(parent);
+ parent = pakfire_parser_ref(*parser);
+};
+
+%destructor { if ($$) pakfire_parser_unref($$); } <parser>
%destructor { pakfire_parser_free_declaration($$); } <declaration>
%start grammar
grammar : %empty
{
- $$ = pakfire_parser_create(pakfire, parent, NULL, 0);
- if (!$$)
- ABORT;
-
- // Make this the root
- if (!*parser)
- *parser = pakfire_parser_ref($$);
-
- // This is now the new parent parser
- parent = $$;
+ $$ = pakfire_parser_ref(parent);
}
| grammar declaration
{
pakfire_parser_unref($2);
if (r)
ABORT;
-
- // Go back to the parent parser
- parent = $$;
}
| grammar if_stmt
{
if (r)
ABORT;
}
-
- // Go back to the parent parser
- parent = $$;
}
| grammar empty
{
}
;
-subgrammar : T_INDENT grammar T_OUTDENT
+subgrammar_open : T_INDENT
{
- $$ = $2;
+ // Create a new parser and make it parent
+ PakfireParser p = pakfire_parser_create(pakfire, parent, NULL, 0);
+ if (!p)
+ ABORT;
- // Go back to the parent parser
- parent = $$;
+ if (parent)
+ pakfire_parser_unref(parent);
+ parent = p;
+ }
+ ;
+
+subgrammar_close : T_OUTDENT
+ {
+ // Move the parent pointer back
+ PakfireParser p = pakfire_parser_get_parent(parent);
+
+ if (parent)
+ pakfire_parser_unref(parent);
+ parent = p;
+ }
+ ;
+
+subgrammar : subgrammar_open grammar subgrammar_close
+ {
+ $$ = $2;
}
;
// Destroy the parser
if (parser)
- pakfire_parser_unref(parser);
+ pakfire_parser_unref(parser);
#ifdef ENABLE_DEBUG
// Save end time