From 68f7a6f76a45b28bc2033ac4bfee5fa917a51f15 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 10 Mar 2019 16:43:37 +0000 Subject: [PATCH] libpakfire: parser: Allow parsing block assignments Signed-off-by: Michael Tremer --- src/libpakfire/parser/grammar.y | 20 +++++++++++++++++++- src/libpakfire/parser/scanner.l | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y index 53b26280f..e034a1fb4 100644 --- a/src/libpakfire/parser/grammar.y +++ b/src/libpakfire/parser/grammar.y @@ -46,6 +46,8 @@ static void yyerror(const char* s); %token WHITESPACE %token WORD +%type line; +%type text; %type variable; %type value; %type words; @@ -89,7 +91,17 @@ words : WORD { $$ = $1; } - | words WHITESPACE WORD; + | words WHITESPACE WORD + | /* empty */; + +line : whitespace words NEWLINE + { + printf("line = %s\n", $2); + }; + +text : text line + | line + | /* empty */; block_opening : variable NEWLINE { @@ -108,6 +120,7 @@ block : block_opening assignments block_closing assignments : assignments assignment | assignments empty + | assignments block_assignment | /* empty */ ; @@ -116,6 +129,11 @@ assignment : whitespace variable whitespace ASSIGN whitespace value whitespa printf("ASSIGNMENT FOUND: %s = %s\n", $2, $6); }; +block_assignment : whitespace DEFINE WHITESPACE variable NEWLINE text whitespace END NEWLINE + { + printf("BLOCK ASSIGNMENT: %s: %s\n", $4, $6); + } + %% int pakfire_parser_parse_metadata(Pakfire _pakfire, const char* data, size_t len) { diff --git a/src/libpakfire/parser/scanner.l b/src/libpakfire/parser/scanner.l index d1bd32a8f..d920a28dc 100644 --- a/src/libpakfire/parser/scanner.l +++ b/src/libpakfire/parser/scanner.l @@ -32,7 +32,7 @@ int num_lines; digit [0-9] letter [A-Za-z] underscore _ -special [/!@$%&*()+=:<>,;?_\.\[\]\-\\]+ +special [/'!@$%&*()+=:<>,;?_\.\[\]\-\\]+ whitespace ([ \t])+ word ({digit}|{letter}|{special})+ -- 2.39.5