%token <string> T_SUBPARSER
%type <parser> grammar
-%type <parser> subgrammar
+%type <parser> block
%type <parser> subparser
%type <string> subparser_name
%type <parser> if_stmt
}
%initial-action {
+ //*parser = pakfire_parser_ref(parent);
*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>
grammar : %empty
{
- $$ = pakfire_parser_ref(parent);
+ $$ = pakfire_parser_create(pakfire, *parser, NULL, 0);
+ if (!$$)
+ ABORT;
+
+ // This becomes the new top parser
+ if (*parser)
+ pakfire_parser_unref(*parser);
+ *parser = pakfire_parser_ref($$);
}
| grammar declaration
{
}
;
-subgrammar_open : T_INDENT
- {
- // Create a new parser and make it parent
- PakfireParser p = pakfire_parser_create(pakfire, parent, NULL, 0);
- if (!p)
- ABORT;
-
- if (parent)
- pakfire_parser_unref(parent);
- parent = p;
- }
- ;
-
-subgrammar_close : T_OUTDENT
+block : T_INDENT grammar T_OUTDENT
{
- // Move the parent pointer back
- PakfireParser p = pakfire_parser_get_parent(parent);
+ // Reset the top parser
+ PakfireParser p = pakfire_parser_get_parent(*parser);
+ pakfire_parser_unref(*parser);
+ *parser = p;
- if (parent)
- pakfire_parser_unref(parent);
- parent = p;
- }
- ;
-
-subgrammar : subgrammar_open grammar subgrammar_close
- {
$$ = $2;
}
;
}
;
-subparser : subparser_name T_EOL subgrammar T_END T_EOL
+subparser : subparser_name T_EOL block T_END T_EOL
{
pakfire_parser_set_namespace($3, $1);
char* value;
// Create a new parser
- $$ = pakfire_parser_create(pakfire, parent, NULL, 0);
+ $$ = pakfire_parser_create(pakfire, *parser, NULL, 0);
if (!$$)
ABORT;
}
;
-if_stmt : T_IF T_STRING T_EQUALS T_STRING T_EOL subgrammar else_stmt T_END T_EOL
+if_stmt : T_IF T_STRING T_EQUALS T_STRING T_EOL block else_stmt T_END T_EOL
{
$$ = make_if_stmt(pakfire, OP_EQUALS, $2, $4, $6, $7);
}
;
-else_stmt : T_ELSE T_EOL subgrammar
+else_stmt : T_ELSE T_EOL block
{
$$ = $3;
}