-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrules.y
289 lines (237 loc) · 8.13 KB
/
rules.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
%{
#include <stdio.h>
#include <string.h>
#include "target.h"
#include "stringbuilder.h"
#include "src_gatherer.h"
#define YYSTYPE char*
extern char* yytext;
extern int yylex (void);
extern int yyget_lineno();
extern void set_parsererror(int, int, char*);
extern void check_namgen_version(const char *);
static target_entry *current_target = NULL;
static stringbuilder *sb = NULL;
void parser_setup(void)
{
current_target = NULL;
sb = sb_new();
}
void parser_cleanup(void)
{
current_target = NULL;
sb_destroy(sb, 1);
}
void yyerror(const char *str)
{
set_parsererror(1, yyget_lineno(), yytext);
}
int yywrap()
{
return 1;
}
%}
%start declarations
%token PROGRAM LIBRARY WORKER COMMAND
SRC DEPENDS FLAGS LIBS LDFLAGS ADD_OBJECTS DESTDIR SKIP_INSTALL SKIP_SHARED
SKIP_STATIC TRUE_VALUE FALSE_VALUE VERSION_INFO VERSION_NUMBER THREE_NUMBERS
VARIABLE WORD WILDCARD FILENAME STUFF EXPR_MARK EQUALS QUOTE OBRACE EBRACE
EXPORT_INC CONVENIENCE_LIB OCOMMENT ECOMMENT SKIP_IF CLEAN_FILES SRC_EXTENSION
REQUIRE_NAMGEN_VERSION CONF_MAKE_INSTALL SRC_DIR PATCHES
%%
declarations:
| declarations declaration
;
declaration:
program_def | library_def | worker_def | cmi_def | comment_line | skip_condition | require_version
;
program_def:
PROGRAM quoted_name
{
current_target = target_entry_new(TYPE_PROGRAM, $2);
}
def_content
{
module_add_target(current_target);
current_target = NULL;
}
library_def:
LIBRARY quoted_name
{
current_target = target_entry_new(TYPE_LIBRARY, $2);
}
def_content
{
module_add_target(current_target);
current_target = NULL;
}
worker_def:
WORKER quoted_name
{
current_target = target_entry_new(TYPE_WORKER, $2);
}
def_content
{
module_add_target(current_target);
current_target = NULL;
}
cmi_def:
CONF_MAKE_INSTALL quoted_name
{
current_target = target_entry_new(TYPE_CMI, $2);
}
def_content
{
module_add_target(current_target);
current_target = NULL;
}
skip_condition: SKIP_IF WORD { module_set_skip_condition($2); }
require_version: REQUIRE_NAMGEN_VERSION WORD { check_namgen_version($2); }
comment_line:
OCOMMENT comment_data ECOMMENT
;
comment_data:
| comment_data comment_blub
;
comment_blub:
SRC
| SRC_DIR
| SRC_EXTENSION
| DEPENDS
| FLAGS
| LIBS
| LDFLAGS
| ADD_OBJECTS
| EXPORT_INC
| DESTDIR
| SKIP_INSTALL
| SKIP_SHARED
| SKIP_STATIC
| CONVENIENCE_LIB
| VERSION_INFO
| VERSION_NUMBER
| TRUE_VALUE
| FALSE_VALUE
| EQUALS
| word_variable_filename_stuff
;
quoted_name:
QUOTE WORD QUOTE
{
$$ = $2;
}
def_content:
OBRACE def_statements EBRACE
;
def_statements:
| def_statements def_statement
;
def_statement:
src_statement ;
| src_dir_statement;
| src_ext_statement;
| depends_statement ;
| patches_statement ;
| destdir_statement { target_set_destdir_path(current_target, $1); }
| flags_statement ;
| ld_flags_statement ;
| libs_statement ;
| version_num_statement ;
| add_objects_statement;
| clean_files_statement;
| export_inc_statement ;
| command_statement ;
| skip_install_statement { target_set_skip_install(current_target, $1); }
| skip_shared_statement { target_set_skip_shared(current_target, $1); }
| skip_static_statement { target_set_skip_static(current_target, $1); }
| convenience_statement { target_set_convencience(current_target, $1); }
| comment_line ;
patches_statement:
PATCHES EQUALS { src_gatherer_reset(); }
list_of_src_expr { current_target->extra_obj = src_gatherer_get_result(); }
src_statement:
SRC EQUALS { src_gatherer_reset(); }
list_of_src_expr { current_target->src = src_gatherer_get_result(); }
src_ext_statement:
SRC_EXTENSION EQUALS WORD
{ current_target->src_ext = $3; }
src_dir_statement:
SRC_DIR EQUALS word_variable_filename_stuff
{ current_target->src_ext = $3; }
add_objects_statement:
ADD_OBJECTS EQUALS { src_gatherer_reset(); }
list_of_src_expr { current_target->extra_obj = src_gatherer_get_result(); }
clean_files_statement:
CLEAN_FILES EQUALS { src_gatherer_reset(); }
list_of_src_expr { current_target->extra_clean = src_gatherer_get_result(); }
command_statement:
COMMAND EQUALS word_variable_filename_stuff
{ current_target->cmd = $3; }
depends_statement:
DEPENDS EQUALS list_of_depends
;
destdir_statement:
DESTDIR EQUALS FILENAME
{
$$ = $3;
}
version_num_statement:
vnum_schema EQUALS three_numbers_or_variable
{ current_target->lib_version_num = strdup($3); }
three_numbers_or_variable: THREE_NUMBERS | VARIABLE
vnum_schema:
VERSION_NUMBER { current_target->other_flags &= ~VERSION_INFO_SCHEMA; }
| VERSION_INFO { current_target->other_flags |= VERSION_INFO_SCHEMA; }
flags_statement:
FLAGS EQUALS { sb_reset(sb); }
list_of_stuff { current_target->compile_flags = sb_make_cstring(sb); }
ld_flags_statement:
LDFLAGS EQUALS { sb_reset(sb); }
list_of_stuff { current_target->link_flags = sb_make_cstring(sb); }
libs_statement:
LIBS EQUALS { sb_reset(sb); }
list_of_stuff { current_target->libs = sb_make_cstring(sb); }
export_inc_statement:
EXPORT_INC EQUALS { sb_reset(sb); }
list_of_stuff { current_target->export_include = sb_make_cstring(sb); }
skip_install_statement:
SKIP_INSTALL EQUALS true_false
{ $$ = $3; }
skip_shared_statement:
SKIP_SHARED EQUALS true_false
{ $$ = $3; }
skip_static_statement:
SKIP_STATIC EQUALS true_false
{ $$ = $3; }
convenience_statement:
CONVENIENCE_LIB EQUALS true_false
{ $$ = $3; }
true_false:
TRUE_VALUE { $$ = "true"; }
| FALSE_VALUE { $$ = "false"; }
list_of_depends:
WORD
{ target_add_dependency(current_target, $1); }
| list_of_depends WORD
{ target_add_dependency(current_target, $2); }
list_of_src_expr:
src_expr
| list_of_src_expr src_expr
;
src_expr:
WORD { src_gatherer_add_file($1); }
| FILENAME { src_gatherer_add_file($1); }
| STUFF { src_gatherer_add_file($1); }
| WILDCARD { src_gatherer_add_wildcard($1); }
| VARIABLE { src_gatherer_add_variable($1); }
| EXPR_MARK { src_gather_set_explicit(); }
list_of_stuff:
word_variable_filename_stuff
{ sb_append_str(sb, $1); sb_append_str(sb, " "); }
| list_of_stuff word_variable_filename_stuff
{ sb_append_str(sb, $2); sb_append_str(sb, " "); }
word_variable_filename_stuff:
WORD { $$ = $1; }
| VARIABLE { $$ = $1; }
| FILENAME { $$ = $1; }
| STUFF { $$ = $1; }