%parse-param
{yyscan_t* scanner}
- {PakfireParser* parser}
{Pakfire pakfire}
+ {PakfireParser* parser}
+ {PakfireParser parent}
{struct pakfire_parser_error** error}
// Make the parser reentrant
OP_EQUALS = 0,
};
-static void yyerror(yyscan_t* scanner, PakfireParser* parser, Pakfire pakfire,
- struct pakfire_parser_error** error, const char* s) {
+static void yyerror(yyscan_t* scanner, Pakfire pakfire, PakfireParser* parser,
+ PakfireParser parent, struct pakfire_parser_error** error, const char* s) {
ERROR(pakfire, "Error (line %d): %s\n", num_lines, s);
// Create a new error object
}
}
-static PakfireParser make_if_stmt(Pakfire pakfire, PakfireParser* parser, const enum operator op,
+static PakfireParser make_if_stmt(Pakfire pakfire, PakfireParser parser, const enum operator op,
const char* val1, const char* val2, PakfireParser if_block, PakfireParser else_block);
static int pakfire_parser_new_declaration(
grammar : %empty
{
- $$ = pakfire_parser_create(pakfire, NULL, NULL, 0);
+ $$ = 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 = $$;
}
| grammar declaration
{
$$ = $1;
int r = pakfire_parser_merge($1, $2);
+ pakfire_parser_unref($2);
if (r)
ABORT;
- pakfire_parser_unref($2);
+ // 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
{
$$ = $2;
+
+ // Go back to the parent parser
+ parent = $$;
}
;
char* value;
// Create a new parser
- $$ = pakfire_parser_create(pakfire, NULL, NULL, 0);
+ $$ = pakfire_parser_create(pakfire, parent, NULL, 0);
if (!$$)
ABORT;
if_stmt : T_IF T_STRING T_EQUALS T_STRING T_EOL subgrammar else_stmt T_END T_EOL
{
- $$ = make_if_stmt(pakfire, parser, OP_EQUALS, $2, $4, $6, $7);
-
- pakfire_parser_unref($6);
- pakfire_parser_unref($7);
+ $$ = make_if_stmt(pakfire, parent, OP_EQUALS, $2, $4, $6, $7);
}
;
num_lines = 1;
YY_BUFFER_STATE buffer = yy_scan_bytes(data, len, scanner);
- int r = yyparse(scanner, &parser, pakfire, error);
+ int r = yyparse(scanner, pakfire, &parser, parent, error);
yy_delete_buffer(buffer, scanner);
// If everything was parsed successfully, we merge the sub-parser into
// the parent parser. That way, it will be untouched if something could
// not be successfully parsed.
if (r == 0) {
- pakfire_parser_merge(parent, parser);
+ if (parser)
+ pakfire_parser_merge(parent, parser);
}
// Destroy the parser
- pakfire_parser_unref(parser);
+ if (parser)
+ pakfire_parser_unref(parser);
#ifdef ENABLE_DEBUG
// Save end time
return r;
}
-static PakfireParser make_if_stmt(Pakfire pakfire, PakfireParser* parser, const enum operator op,
+static PakfireParser make_if_stmt(Pakfire pakfire, PakfireParser parser, const enum operator op,
const char* val1, const char* val2, PakfireParser if_block, PakfireParser else_block) {
switch (op) {
case OP_EQUALS:
break;
}
- DEBUG(pakfire, " parser = %p, if = %p, else = %p\n", *parser, if_block, else_block);
+ DEBUG(pakfire, " parent = %p, if = %p, else = %p\n", parser, if_block, else_block);
// Expand values
- char* v1 = pakfire_parser_expand(*parser, NULL, val1);
- char* v2 = pakfire_parser_expand(*parser, NULL, val2);
+ char* v1 = pakfire_parser_expand(parser, NULL, val1);
+ char* v2 = pakfire_parser_expand(parser, NULL, val2);
PakfireParser result = NULL;