]>
Commit | Line | Data |
---|---|---|
f9a691ef MT |
1 | /*############################################################################# |
2 | # # | |
3 | # Pakfire - The IPFire package management system # | |
4 | # Copyright (C) 2019 Pakfire development team # | |
5 | # # | |
6 | # This program is free software: you can redistribute it and/or modify # | |
7 | # it under the terms of the GNU General Public License as published by # | |
8 | # the Free Software Foundation, either version 3 of the License, or # | |
9 | # (at your option) any later version. # | |
10 | # # | |
11 | # This program is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
18 | # # | |
19 | #############################################################################*/ | |
20 | ||
21 | %{ | |
a0258b56 | 22 | #include <pakfire/logging.h> |
35ebb186 MT |
23 | #include <pakfire/types.h> |
24 | ||
f9a691ef MT |
25 | #define YYERROR_VERBOSE 1 |
26 | ||
27 | typedef struct yy_buffer_state* YY_BUFFER_STATE; | |
28 | extern YY_BUFFER_STATE yy_scan_bytes(const char* buffer, size_t len); | |
29 | extern void yy_delete_buffer(YY_BUFFER_STATE buffer); | |
30 | ||
31 | extern int yylex(); | |
32 | extern int yyparse(); | |
6ab14b96 MT |
33 | |
34 | extern int num_lines; | |
e98f46a7 MT |
35 | static Pakfire pakfire; |
36 | static void yyerror(const char* s); | |
6b03e625 | 37 | |
f9a691ef MT |
38 | %} |
39 | ||
40 | %token APPEND | |
41 | %token ASSIGN | |
42 | %token DEFINE | |
43 | %token END | |
44 | %token NEWLINE | |
45 | %token TAB | |
f9a691ef | 46 | %token WHITESPACE |
6b03e625 | 47 | %token <string> WORD |
f9a691ef | 48 | |
28afa9c2 MT |
49 | %type <string> variable; |
50 | %type <string> value; | |
6b03e625 | 51 | %type <string> words; |
28afa9c2 MT |
52 | |
53 | %union { | |
54 | char* string; | |
55 | } | |
f9a691ef | 56 | |
28afa9c2 | 57 | %% |
70425a92 | 58 | |
28afa9c2 MT |
59 | top : top empty |
60 | | top block | |
61 | | empty | |
62 | | block | |
63 | ; | |
64 | ||
65 | empty : WHITESPACE NEWLINE | |
66 | | NEWLINE | |
67 | ; | |
68 | ||
69 | // Optional whitespace | |
70 | whitespace : WHITESPACE | |
71 | | /* empty */ | |
72 | ; | |
73 | ||
6b03e625 | 74 | variable : WORD |
28afa9c2 MT |
75 | { |
76 | $$ = $1; | |
77 | }; | |
78 | ||
6b03e625 | 79 | value : words |
28afa9c2 MT |
80 | { |
81 | $$ = $1; | |
82 | } | |
83 | | /* empty */ | |
84 | { | |
85 | $$ = NULL; | |
86 | }; | |
87 | ||
6b03e625 MT |
88 | words : WORD |
89 | { | |
90 | $$ = $1; | |
91 | } | |
92 | | words WHITESPACE WORD; | |
93 | ||
28afa9c2 MT |
94 | block_opening : variable NEWLINE |
95 | { | |
96 | printf("BLOCK OPEN: %s\n", $1); | |
97 | }; | |
98 | ||
99 | block_closing : END NEWLINE | |
100 | { | |
101 | printf("BLOCK CLOSED\n"); | |
102 | } | |
103 | ||
104 | block : block_opening assignments block_closing | |
105 | { | |
106 | printf("BLOCK FOUND\n"); | |
107 | }; | |
108 | ||
109 | assignments : assignments assignment | |
110 | | assignments empty | |
111 | | /* empty */ | |
112 | ; | |
113 | ||
114 | assignment : whitespace variable whitespace ASSIGN whitespace value whitespace NEWLINE | |
115 | { | |
116 | printf("ASSIGNMENT FOUND: %s = %s\n", $2, $6); | |
117 | }; | |
f9a691ef MT |
118 | |
119 | %% | |
120 | ||
e98f46a7 MT |
121 | int pakfire_parser_parse_metadata(Pakfire _pakfire, const char* data, size_t len) { |
122 | pakfire = _pakfire; | |
123 | ||
a0258b56 MT |
124 | DEBUG(pakfire, "Parsing the following data:\n%s\n", data); |
125 | ||
6ab14b96 MT |
126 | num_lines = 1; |
127 | ||
f9a691ef MT |
128 | YY_BUFFER_STATE buffer = yy_scan_bytes(data, len); |
129 | int r = yyparse(); | |
130 | yy_delete_buffer(buffer); | |
131 | ||
132 | return r; | |
133 | } | |
134 | ||
135 | void yyerror(const char* s) { | |
e98f46a7 | 136 | ERROR(pakfire, "Error (line %d): %s\n", num_lines, s); |
f9a691ef | 137 | } |