]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Implement appending strings with +=
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 Feb 2021 19:45:53 +0000 (19:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 Feb 2021 19:45:53 +0000 (19:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/grammar.y
src/libpakfire/parser/scanner.l
tests/libpakfire/parser.c

index 160799ea5f54126b592e80d8c3e0a2ad4d213c7e..74dd2da0f85d841ca6314a479d6ecbae9e338569 100644 (file)
@@ -65,6 +65,7 @@ enum operator {
 %token                                         T_EOL
 
 %token                                         T_ASSIGN
+%token                                         T_APPEND
 
 %type <string>                         key
 %type <string>                         value
@@ -90,6 +91,12 @@ declaration                                  : key T_ASSIGN value T_EOL
                                                                if (r)
                                                                        ABORT;
                                                        }
+                                                       | key T_APPEND value T_EOL
+                                                       {
+                                                               int r = pakfire_parser_append(parser, $1, $3);
+                                                               if (r)
+                                                                       ABORT;
+                                                       }
                                                        ;
 
 key                                                    : T_KEY
index 6c0e29f63860dde0312dfc82415028b361a9f8f2..0177ce495a516e3843b3d3dde6a3c337879936b7 100644 (file)
@@ -85,6 +85,13 @@ key                                          ({letter}|{underscore})(({letter}|{digit}|{underscore})*({letter}|{digi
                                                        return T_ASSIGN;
                                                }
 
+"+="                                   {
+                                                       // Read everything after this
+                                                       yy_push_state(READLINE);
+
+                                                       return T_APPEND;
+                                               }
+
 (.|\n)                                 {
                                                        // Unexpected character
                                                        fprintf(stderr, "Unexpected character: %s\n", yytext);
index 5472537a40a7a10f520fcbb6041de66117b712c8..63516073e6d1499b952ed5e2a2d62a75595949db 100644 (file)
@@ -106,7 +106,7 @@ static int test_parser(const struct test* t) {
 static int test_parser_assign(const struct test* t) {
        PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL);
 
-       static const char* INPUT = "a = 1\nb = 2\nc = %{a}%{b}\n";
+       static const char* INPUT = "a = 1\nb = 2\nc = %{a}%{b}\nd = A\nd += BC\n";
 
        int r = pakfire_parser_parse(parser, INPUT, strlen(INPUT));
        ASSERT(r == 0);
@@ -116,6 +116,9 @@ static int test_parser_assign(const struct test* t) {
        printf("%s\n", s);
        free(s);
 
+       char* value = pakfire_parser_get(parser, "d");
+       ASSERT_STRING_EQUALS(value, "ABC");
+
        pakfire_parser_unref(parser);
 
        return EXIT_SUCCESS;