From: Michael Tremer Date: Tue, 23 Feb 2021 19:45:53 +0000 (+0000) Subject: parser: Implement appending strings with += X-Git-Tag: 0.9.28~1285^2~713 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4784cd87068d032c9ddc8db32829ffec44683e43;p=pakfire.git parser: Implement appending strings with += Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y index 160799ea5..74dd2da0f 100644 --- a/src/libpakfire/parser/grammar.y +++ b/src/libpakfire/parser/grammar.y @@ -65,6 +65,7 @@ enum operator { %token T_EOL %token T_ASSIGN +%token T_APPEND %type key %type 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 diff --git a/src/libpakfire/parser/scanner.l b/src/libpakfire/parser/scanner.l index 6c0e29f63..0177ce495 100644 --- a/src/libpakfire/parser/scanner.l +++ b/src/libpakfire/parser/scanner.l @@ -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); diff --git a/tests/libpakfire/parser.c b/tests/libpakfire/parser.c index 5472537a4..63516073e 100644 --- a/tests/libpakfire/parser.c +++ b/tests/libpakfire/parser.c @@ -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;