]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
libpakfire: parser: Read variable assignments
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 9 Mar 2019 21:00:48 +0000 (21:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 9 Mar 2019 21:00:48 +0000 (21:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/grammar.y
src/libpakfire/parser/scanner.l

index 91f45a0de39b11092c03efaa7ec3df5ddbab1f37..cba846bae6bb91418d9834a5d1cd2af445ebe18e 100644 (file)
@@ -42,19 +42,73 @@ static void yyerror(const char* s);
 %token END
 %token NEWLINE
 %token TAB
-%token VARIABLE
-%token VALUE
+%token <string>                                        VARIABLE
+%token <string>                                        VALUE
 %token WHITESPACE
 
-%%
+%type <string>                                 variable;
+%type <string>                                 value;
+
+%union {
+       char* string;
+}
 
-top                            : top empty
-                               | empty
-                               ;
+%%
 
-empty                  : WHITESPACE NEWLINE
-                               | NEWLINE
-                               ;
+top                                                    : top empty
+                                                       | top block
+                                                       | empty
+                                                       | block
+                                                       ;
+
+empty                                          : WHITESPACE NEWLINE
+                                                       | NEWLINE
+                                                       ;
+
+// Optional whitespace
+whitespace                                     : WHITESPACE
+                                                       | /* empty */
+                                                       ;
+
+variable                                       : VARIABLE
+                                                       {
+                                                               $$ = $1;
+                                                       };
+
+value                                          : VALUE
+                                                       | variable
+                                                       {
+                                                               $$ = $1;
+                                                       }
+                                                       | /* empty */
+                                                       {
+                                                               $$ = NULL;
+                                                       };
+
+block_opening                          : variable NEWLINE
+                                                       {
+                                                               printf("BLOCK OPEN: %s\n", $1);
+                                                       };
+
+block_closing                          : END NEWLINE
+                                                       {
+                                                               printf("BLOCK CLOSED\n");
+                                                       }
+
+block                                          : block_opening assignments block_closing
+                                                       {
+                                                               printf("BLOCK FOUND\n");
+                                                       };
+
+assignments                                    : assignments assignment
+                                                       | assignments empty
+                                                       | /* empty */
+                                                       ;
+
+assignment                                     : whitespace variable whitespace ASSIGN whitespace value whitespace NEWLINE
+                                                       {
+                                                               printf("ASSIGNMENT FOUND: %s = %s\n", $2, $6);
+                                                       };
 
 %%
 
index 21db9800d66f66d45210696cfda8e214d4fe902f..1c36a8df844b46b0003c0c8ac3a69cb791b8e394 100644 (file)
@@ -25,6 +25,7 @@
 
 int num_lines;
 
+#include <pakfire/util.h>
 #include "grammar.h"
 %}
 
@@ -33,7 +34,7 @@ letter                        [A-Za-z]
 underscore             _
 variable               {letter}({digit}|{letter}|{underscore})+
 whitespace             ([ \t])+
-string                 [a-zA-Z0-9`~!@#$%\^&*()_\-+=:\[\]<>,\.?\\]+
+string                 [a-zA-Z0-9`~!@#$%\^&*()_\-+=:\[\]<>,\.?\\/]+
 
 %%
 
@@ -48,7 +49,14 @@ string                       [a-zA-Z0-9`~!@#$%\^&*()_\-+=:\[\]<>,\.?\\]+
 "def"                  { return DEFINE; }
 "end"                  { return END; }
 
-{variable}             { return VARIABLE; }
-{string}               { return VALUE; }
+{variable}             {
+                                       yylval.string = pakfire_strdup(yytext);
+                                       return VARIABLE;
+                               }
+
+{string}               {
+                                       yylval.string = pakfire_strdup(yytext);
+                                       return VALUE;
+                               }
 
 %%