]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: parser: Replace VARIABLE/VALUE tokens with WORD
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 10 Mar 2019 16:29:09 +0000 (16:29 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 10 Mar 2019 16:29:09 +0000 (16:29 +0000)
This is more generic although it allows any variable name

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

index cba846bae6bb91418d9834a5d1cd2af445ebe18e..53b26280fc9cf172e36124ee9bd475b5e208fffe 100644 (file)
@@ -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 <string>                                        VARIABLE
-%token <string>                                        VALUE
 %token WHITESPACE
+%token <string>                                        WORD
 
 %type <string>                                 variable;
 %type <string>                                 value;
+%type <string>                                 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);
index 1c36a8df844b46b0003c0c8ac3a69cb791b8e394..d1bd32a8f80a2c352298f549c1cfbb850735818a 100644 (file)
@@ -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;
                                }
 
 %%