Updated Spanish translation
[anjuta.git] / plugins / mk-project / mk-parser.y
blob52dd83b762e6f32ccea8d6aec5b8feac94aff962
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * mk-parser.y
4 * Copyright (C) Sébastien Granjoux 2009 <seb.sfo@free.fr>
5 *
6 * main.c is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * main.c is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "mk-scanner.h"
22 #include "mk-parser.h"
24 #include <stdlib.h>
26 #define YYDEBUG 1
28 /* Token location is found directly from token value, there is no need to
29 * maintain a separate location variable */
30 #define YYLLOC_DEFAULT(Current, Rhs, N) ((Current) = YYRHSLOC(Rhs, (N) ? 1 : 0))
34 %token EOL '\n'
35 %token SPACE ' '
36 %token TAB '\t'
37 %token HASH '#'
38 %token MACRO
39 %token VARIABLE
40 %token COMMA ','
41 %token COLON ':'
42 %token DOUBLE_COLON "::"
43 %token ORDER '|'
44 %token SEMI_COLON ';'
45 %token EQUAL '='
46 %token IMMEDIATE_EQUAL ":="
47 %token CONDITIONAL_EQUAL "?="
48 %token APPEND "+="
49 %token CHARACTER
50 %token NAME
51 %token MK_VARIABLE
52 %token _PHONY
53 %token _SUFFIXES
54 %token _DEFAULT
55 %token _PRECIOUS
56 %token _INTERMEDIATE
57 %token _SECONDARY
58 %token _SECONDEXPANSION
59 %token _DELETE_ON_ERROR
60 %token _IGNORE
61 %token _LOW_RESOLUTION_TIME
62 %token _SILENT
63 %token _EXPORT_ALL_VARIABLES
64 %token _NOTPARALLEL
65 %token IFEQ
66 %token ELSE
67 %token ENDIF
69 %defines
71 %define api.pure
72 %define api.push_pull "push"
74 /*%glr-parser*/
76 %parse-param {void* scanner}
77 %lex-param {void* scanner}
79 %name-prefix="mkp_yy"
81 %locations
83 %expect 1
85 %start file
87 %debug
91 //mkp_yydebug = 1;
93 static gint
94 mkp_special_prerequisite (AnjutaToken *token)
96 switch (anjuta_token_get_type (token))
98 case ORDER:
99 return MK_TOKEN_ORDER;
100 default:
101 return ANJUTA_TOKEN_NAME;
105 static void
106 mkp_special_target (AnjutaToken *list)
108 AnjutaToken *arg = anjuta_token_first_item (list);
109 AnjutaToken *target = arg != NULL ? anjuta_token_first_item (arg) : NULL;
111 if ((target != NULL) && (anjuta_token_next_item (target) == NULL))
113 gint mk_token = 0;
115 switch (anjuta_token_get_type (target))
117 case _PHONY:
118 mk_token = MK_TOKEN__PHONY;
119 break;
120 case _SUFFIXES:
121 mk_token = MK_TOKEN__SUFFIXES;
122 break;
123 case _DEFAULT:
124 mk_token = MK_TOKEN__DEFAULT;
125 break;
126 case _PRECIOUS:
127 mk_token = MK_TOKEN__PRECIOUS;
128 break;
129 case _INTERMEDIATE:
130 mk_token = MK_TOKEN__INTERMEDIATE;
131 break;
132 case _SECONDARY:
133 mk_token = MK_TOKEN__SECONDARY;
134 break;
135 case _SECONDEXPANSION:
136 mk_token = MK_TOKEN__SECONDEXPANSION;
137 break;
138 case _DELETE_ON_ERROR:
139 mk_token = MK_TOKEN__DELETE_ON_ERROR;
140 break;
141 case _IGNORE:
142 mk_token = MK_TOKEN__IGNORE;
143 break;
144 case _LOW_RESOLUTION_TIME:
145 mk_token = MK_TOKEN__LOW_RESOLUTION_TIME;
146 break;
147 case _SILENT:
148 mk_token = MK_TOKEN__SILENT;
149 break;
150 case _EXPORT_ALL_VARIABLES:
151 mk_token = MK_TOKEN__EXPORT_ALL_VARIABLES;
152 break;
153 case _NOTPARALLEL:
154 mk_token = MK_TOKEN__NOTPARALLEL;
155 break;
156 case ORDER:
157 mk_token = MK_TOKEN_ORDER;
158 break;
159 default:
160 break;
163 if (mk_token)
165 anjuta_token_set_type (arg, mk_token);
174 file:
175 statement
176 | file statement
179 statement:
180 end_of_line
181 | space end_of_line
182 | definition end_of_line
183 | conditional end_of_line
184 | rule command_list {
185 anjuta_token_merge_children ($1, $2);
186 mkp_scanner_add_rule (scanner, $1);
190 definition:
191 head_list equal_group value {
192 $$ = anjuta_token_new_static (ANJUTA_TOKEN_DEFINITION, NULL);
193 anjuta_token_merge_own_children ($1);
194 anjuta_token_merge ($$, $1);
195 anjuta_token_merge ($$, $2);
196 anjuta_token_merge ($$, $3);
197 mkp_scanner_update_variable (scanner, $$);
199 | head_list equal_group {
200 $$ = anjuta_token_new_static (ANJUTA_TOKEN_DEFINITION, NULL);
201 anjuta_token_merge_own_children ($1);
202 anjuta_token_merge ($$, $1);
203 anjuta_token_merge ($$, $2);
204 mkp_scanner_update_variable (scanner, $$);
208 rule:
209 depend_list end_of_line {
210 anjuta_token_merge ($1, $2);
212 | depend_list SEMI_COLON command_line EOL {
213 anjuta_token_merge ($1, $2);
214 anjuta_token_merge ($1, $3);
215 anjuta_token_merge ($1, $4);
219 depend_list:
220 head_list rule_token prerequisite_list {
221 $$ = anjuta_token_new_static (MK_TOKEN_RULE, NULL);
222 anjuta_token_merge ($$, $1);
223 mkp_special_target ($1);
224 switch (anjuta_token_get_type ($2))
226 case COLON:
227 anjuta_token_set_type ($2, MK_TOKEN_COLON);
228 break;
229 case DOUBLE_COLON:
230 anjuta_token_set_type ($2, MK_TOKEN_DOUBLE_COLON);
231 break;
232 default:
233 break;
235 anjuta_token_merge ($$, $2);
236 anjuta_token_merge ($$, $3);
240 command_list:
241 /* empty */ {
242 $$ = anjuta_token_new_static (MK_TOKEN_COMMANDS, NULL);
244 | command_list TAB command_line EOL {
245 anjuta_token_merge ($1, $2);
246 anjuta_token_merge ($1, $3);
247 anjuta_token_merge ($1, $4);
251 conditional:
252 IFEQ value
253 | ELSE
254 | ENDIF
258 /* Lists
259 *----------------------------------------------------------------------------*/
261 end_of_line:
262 EOL {
263 $$ = NULL;
265 | comment {
266 $$ = NULL;
270 comment:
271 HASH not_eol_list EOL
274 not_eol_list:
275 /* empty */
276 | not_eol_list not_eol_token
279 prerequisite_list:
280 /* empty */ {
281 $$ = anjuta_token_new_static (MK_TOKEN_PREREQUISITE, NULL);
283 | space {
284 $$ = anjuta_token_new_static (MK_TOKEN_PREREQUISITE, NULL);
286 | optional_space prerequisite_list_body optional_space {
287 if ($1) anjuta_token_set_type ($1, ANJUTA_TOKEN_START);
288 if ($3) anjuta_token_set_type ($3, ANJUTA_TOKEN_LAST);
289 anjuta_token_merge_previous ($2, $1);
290 anjuta_token_merge ($2, $3);
291 $$ = $2;
295 prerequisite_list_body:
296 prerequisite {
297 $$ = anjuta_token_new_static (MK_TOKEN_PREREQUISITE, NULL);
298 anjuta_token_merge ($$, $1);
300 | prerequisite_list_body space prerequisite {
301 anjuta_token_set_type ($2, ANJUTA_TOKEN_NEXT);
302 anjuta_token_merge ($1, $2);
303 anjuta_token_merge ($1, $3);
307 head_list:
308 optional_space head_list_body optional_space {
309 $$ = anjuta_token_merge_previous ($2, $1);
310 anjuta_token_merge ($$, $3);
314 head_list_body:
315 head {
316 $$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
317 anjuta_token_merge ($$, $1);
319 | head_list_body space head {
320 anjuta_token_merge ($1, $2);
321 anjuta_token_merge ($1, $3);
325 command_line:
326 /* empty */ {
327 $$ = anjuta_token_new_static (MK_TOKEN_COMMAND, NULL);
329 | command_line command_token {
330 anjuta_token_merge ($1, $2);
334 /* Items
335 *----------------------------------------------------------------------------*/
337 optional_space:
338 /* empty */ {
339 $$ = NULL;
341 | space
344 space:
345 space_token {
346 $$ = anjuta_token_new_static (ANJUTA_TOKEN_SPACE, NULL);
347 anjuta_token_merge ($$, $1);
349 | space space_token {
350 anjuta_token_merge ($1, $2);
352 | space variable_token
355 head:
356 head_token {
357 $$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
358 anjuta_token_merge ($$, $1);
360 | head head_token {
361 anjuta_token_merge ($1, $2);
363 | head variable_token
366 value:
367 value_token {
368 $$ = anjuta_token_new_static (ANJUTA_TOKEN_VALUE, NULL);
369 anjuta_token_merge ($$, $1);
371 | space_token {
372 $$ = anjuta_token_new_static (ANJUTA_TOKEN_VALUE, NULL);
373 anjuta_token_merge ($$, $1);
375 | value value_token {
376 anjuta_token_merge ($1, $2);
378 | value space_token {
379 anjuta_token_merge ($1, $2);
383 prerequisite:
384 name_prerequisite
387 name_prerequisite:
388 prerequisite_token {
389 $$ = anjuta_token_new_static (mkp_special_prerequisite ($1), NULL);
390 anjuta_token_merge ($$, $1);
392 | name_prerequisite prerequisite_token {
393 anjuta_token_merge ($1, $2);
395 | name_prerequisite variable_token
398 equal_group:
399 EQUAL {
400 $$ = anjuta_token_new_static (MK_TOKEN_EQUAL, NULL);
401 anjuta_token_merge ($$, $1);
403 | IMMEDIATE_EQUAL {
404 $$ = anjuta_token_new_static (MK_TOKEN_IMMEDIATE_EQUAL, NULL);
405 anjuta_token_merge ($$, $1);
407 | CONDITIONAL_EQUAL {
408 $$ = anjuta_token_new_static (MK_TOKEN_CONDITIONAL_EQUAL, NULL);
409 anjuta_token_merge ($$, $1);
411 | APPEND {
412 $$ = anjuta_token_new_static (MK_TOKEN_APPEND, NULL);
413 anjuta_token_merge ($$, $1);
418 /* Tokens
419 *----------------------------------------------------------------------------*/
421 not_eol_token:
422 word_token
423 | space_token
426 prerequisite_token:
427 name_token
428 | equal_token
429 | rule_token
432 command_token:
433 name_token
434 | variable_token
435 | equal_token
436 | rule_token
437 | depend_token
438 | space_token
441 value_token:
442 name_token
443 | variable_token
444 | equal_token
445 | rule_token
446 | depend_token
449 head_token:
450 name_token
451 | depend_token
454 variable_token:
455 VARIABLE {
456 mkp_scanner_parse_variable (scanner, $$);
460 name_token:
461 NAME
462 | CHARACTER
463 | COMMA
464 | ORDER
465 | _PHONY
466 | _SUFFIXES
467 | _DEFAULT
468 | _PRECIOUS
469 | _INTERMEDIATE
470 | _SECONDARY
471 | _SECONDEXPANSION
472 | _DELETE_ON_ERROR
473 | _IGNORE
474 | _LOW_RESOLUTION_TIME
475 | _SILENT
476 | _EXPORT_ALL_VARIABLES
477 | _NOTPARALLEL
480 rule_token:
481 COLON
482 | DOUBLE_COLON
485 depend_token:
486 SEMI_COLON
489 word_token:
490 VARIABLE
491 | NAME
492 | CHARACTER
493 | ORDER
494 | HASH
495 | COMMA
496 | COLON
497 | DOUBLE_COLON
498 | SEMI_COLON
499 | EQUAL
500 | IMMEDIATE_EQUAL
501 | CONDITIONAL_EQUAL
502 | APPEND
503 | _PHONY
504 | _SUFFIXES
505 | _DEFAULT
506 | _PRECIOUS
507 | _INTERMEDIATE
508 | _SECONDARY
509 | _SECONDEXPANSION
510 | _DELETE_ON_ERROR
511 | _IGNORE
512 | _LOW_RESOLUTION_TIME
513 | _SILENT
514 | _EXPORT_ALL_VARIABLES
515 | _NOTPARALLEL
516 | IFEQ
517 | ELSE
518 | ENDIF
521 space_token:
522 SPACE
523 | TAB
526 equal_token:
527 EQUAL
528 | IMMEDIATE_EQUAL
529 | CONDITIONAL_EQUAL
530 | APPEND