%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);
+ };
%%
int num_lines;
+#include <pakfire/util.h>
#include "grammar.h"
%}
underscore _
variable {letter}({digit}|{letter}|{underscore})+
whitespace ([ \t])+
-string [a-zA-Z0-9`~!@#$%\^&*()_\-+=:\[\]<>,\.?\\]+
+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;
+ }
%%