tests/data/beep-1.3-2.ip3.x86_64.pfm \
\
tests/data/parser/test-comments.txt \
- tests/data/parser/test-declarations.txt
+ tests/data/parser/test-declarations.txt \
+ tests/data/parser/test-subparsers.txt
.PHONY: clean-local-check
clean-local-check:
OP_EQUALS = 0,
};
+static PakfireParser make_child(PakfireParser parent, const char* namespace);
+
%}
%token T_INDENT
%token T_ASSIGN
%token T_APPEND
+%token <string> T_SUBPARSER
+
+%type <parser> grammar
+%type <parser> subparser
+
%type <string> key
%type <string> value
%%
grammar : %empty
+ {
+ $$ = make_child(parser, NULL);
+ }
| grammar declaration
+ | grammar subparser
+ {
+ $$ = pakfire_parser_merge($1, $2);
+ pakfire_parser_unref($2);
+ }
| grammar empty
;
}
;
+subparser : subparser_open T_INDENT grammar T_OUTDENT subparser_close
+ {
+ // Move back to the parent parser
+ parser = pakfire_parser_get_parent(parser);
+
+ // Merge block into the parent parser
+ pakfire_parser_merge(parser, $3);
+
+ // Free block parser
+ pakfire_parser_unref($3);
+ }
+ ;
+
+subparser_open : T_SUBPARSER T_EOL
+ {
+ // Create a new sub-parser which opens a new namespace
+ parser = make_child(parser, $1);
+ }
+ ;
+
+subparser_close : T_END;
+
%%
int pakfire_parser_parse_data(PakfireParser parent, const char* data, size_t len) {
pakfire_unref(pakfire);
}
+
+static PakfireParser make_child(PakfireParser parent, const char* namespace) {
+ PakfireParser parser = pakfire_parser_create_child(parent, namespace);
+ pakfire_parser_unref(parent);
+
+ return parser;
+}
key ({letter}|{underscore})(({letter}|{digit}|{underscore})*({letter}|{digit}))?
+keywords (build|dependencies|distribution|packages?|quality\-agent)
+
%%
<*>\n {
abort();
}
+{keywords}$ {
+ yylval.string = strdup(yytext);
+
+ return T_SUBPARSER;
+ }
+
"=" {
// Read everything after this
yy_push_state(READLINE);
static const char* files[] = {
"data/parser/test-comments.txt",
"data/parser/test-declarations.txt",
+ "data/parser/test-subparsers.txt",
NULL,
};