]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: parser: Avoid passing empty parsers up from the bottom
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 May 2019 05:12:02 +0000 (06:12 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 May 2019 05:12:02 +0000 (06:12 +0100)
Instead we pass NULL around and only create an empty parser
when we really need to.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/grammar.y

index 8121f4e39190e7de161e6e217eca528a4df802fd..809fb68af6d9b314512c829cdf9381709ff123da 100644 (file)
@@ -207,14 +207,19 @@ block_assignments                 : block_assignments block_assignment
                                                        {
                                                                $$ = merge_parsers($1, $2);
                                                        }
-                                                       | block_assignment;
+                                                       | block_assignment {
+                                                               if ($1)
+                                                                       $$ = $1;
+                                                               else
+                                                                       $$ = new_parser(parser);
+                                                       };
 
 block_assignment                       : assignment
                                                        | block
                                                        | if_stmt
                                                        | empty
                                                        {
-                                                               $$ = new_parser(parser);
+                                                               $$ = NULL;
                                                        };
 
 assignment                                     : variable T_ASSIGN value T_EOL
@@ -379,7 +384,7 @@ static PakfireParser make_if_stmt(PakfireParser parser, const enum operator op,
        char* v1 = pakfire_parser_expand(parser, namespace, val1);
        char* v2 = pakfire_parser_expand(parser, namespace, val2);
 
-       PakfireParser result;
+       PakfireParser result = NULL;
 
        switch (op) {
                case OP_EQUALS:
@@ -399,8 +404,6 @@ static PakfireParser make_if_stmt(PakfireParser parser, const enum operator op,
 
        if (result)
                result = pakfire_parser_ref(result);
-       else
-               result = new_parser(parser);
 
        return result;
 }