From: Michael Tremer Date: Sun, 10 Mar 2019 16:29:09 +0000 (+0000) Subject: libpakfire: parser: Replace VARIABLE/VALUE tokens with WORD X-Git-Tag: 0.9.28~1285^2~1091 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6b03e625248c3062f7b897fc6929ae99fcfa0a51;p=pakfire.git libpakfire: parser: Replace VARIABLE/VALUE tokens with WORD This is more generic although it allows any variable name Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y index cba846bae..53b26280f 100644 --- a/src/libpakfire/parser/grammar.y +++ b/src/libpakfire/parser/grammar.y @@ -34,6 +34,7 @@ extern int yyparse(); extern int num_lines; static Pakfire pakfire; static void yyerror(const char* s); + %} %token APPEND @@ -42,12 +43,12 @@ static void yyerror(const char* s); %token END %token NEWLINE %token TAB -%token VARIABLE -%token VALUE %token WHITESPACE +%token WORD %type variable; %type value; +%type words; %union { char* string; @@ -70,13 +71,12 @@ whitespace : WHITESPACE | /* empty */ ; -variable : VARIABLE +variable : WORD { $$ = $1; }; -value : VALUE - | variable +value : words { $$ = $1; } @@ -85,6 +85,12 @@ value : VALUE $$ = NULL; }; +words : WORD + { + $$ = $1; + } + | words WHITESPACE WORD; + block_opening : variable NEWLINE { printf("BLOCK OPEN: %s\n", $1); diff --git a/src/libpakfire/parser/scanner.l b/src/libpakfire/parser/scanner.l index 1c36a8df8..d1bd32a8f 100644 --- a/src/libpakfire/parser/scanner.l +++ b/src/libpakfire/parser/scanner.l @@ -32,9 +32,10 @@ int num_lines; digit [0-9] letter [A-Za-z] underscore _ -variable {letter}({digit}|{letter}|{underscore})+ +special [/!@$%&*()+=:<>,;?_\.\[\]\-\\]+ whitespace ([ \t])+ -string [a-zA-Z0-9`~!@#$%\^&*()_\-+=:\[\]<>,\.?\\/]+ + +word ({digit}|{letter}|{special})+ %% @@ -49,14 +50,9 @@ string [a-zA-Z0-9`~!@#$%\^&*()_\-+=:\[\]<>,\.?\\/]+ "def" { return DEFINE; } "end" { return END; } -{variable} { - yylval.string = pakfire_strdup(yytext); - return VARIABLE; - } - -{string} { +{word} { yylval.string = pakfire_strdup(yytext); - return VALUE; + return WORD; } %%