search: Use G_REGEX_MULTILINE for find in files.
[anjuta.git] / plugins / am-project / am-parser.y
blobf1a3bd1508d4c868f956d174b48a3abe4d4eb17f
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * am-parser.y
4 * Copyright (C) Sébastien Granjoux 2009 <seb.sfo@free.fr>
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 "am-scanner.h"
22 #include "am-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 END_OF_FILE
35 %token END_OF_LINE '\n'
36 %token SPACE
37 %token TAB '\t'
38 %token COMMENT '#'
39 %token MACRO
40 %token VARIABLE
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 AM_VARIABLE
53 %token INCLUDE
55 %token SUBDIRS
56 %token DIST_SUBDIRS
57 %token _DATA
58 %token _HEADERS
59 %token _LIBRARIES
60 %token _LISP
61 %token _LTLIBRARIES
62 %token _MANS
63 %token _PROGRAMS
64 %token _PYTHON
65 %token _JAVA
66 %token _SCRIPTS
67 %token _SOURCES
68 %token _TEXINFOS
69 %token _DIR
70 %token _LDFLAGS
71 %token _CPPFLAGS
72 %token _CFLAGS
73 %token _CXXFLAGS
74 %token _JAVACFLAGS
75 %token _VALAFLAGS
76 %token _FCFLAGS
77 %token _OBJCFLAGS
78 %token _LFLAGS
79 %token _YFLAGS
80 %token TARGET_LDFLAGS
81 %token TARGET_CPPFLAGS
82 %token TARGET_CFLAGS
83 %token TARGET_CXXFLAGS
84 %token TARGET_JAVACFLAGS
85 %token TARGET_VALAFLAGS
86 %token TARGET_FCFLAGS
87 %token TARGET_OBJCFLAGS
88 %token TARGET_LFLAGS
89 %token TARGET_YFLAGS
90 %token TARGET_DEPENDENCIES
91 %token TARGET_LIBADD
92 %token TARGET_LDADD
95 %defines
97 %define api.pure
98 %define api.push_pull "push"
100 %parse-param {AmpAmScanner* scanner}
101 %lex-param {AmpAmScanner* scanner}
103 %name-prefix="amp_am_yy"
105 %locations
107 %start file
109 %expect 1
111 %debug
113 %verbose
117 //amp_am_yydebug = 1;
119 static gint
120 amp_am_automake_variable (AnjutaToken *token)
122 switch (anjuta_token_get_type (token))
124 case SUBDIRS: return AM_TOKEN_SUBDIRS;
125 case DIST_SUBDIRS: return AM_TOKEN_DIST_SUBDIRS;
126 case _DATA: return AM_TOKEN__DATA;
127 case _HEADERS: return AM_TOKEN__HEADERS;
128 case _LIBRARIES: return AM_TOKEN__LIBRARIES;
129 case _LISP: return AM_TOKEN__LISP;
130 case _LTLIBRARIES: return AM_TOKEN__LTLIBRARIES;
131 case _MANS: return AM_TOKEN__MANS;
132 case _PROGRAMS: return AM_TOKEN__PROGRAMS;
133 case _PYTHON: return AM_TOKEN__PYTHON;
134 case _JAVA: return AM_TOKEN__JAVA;
135 case _SCRIPTS: return AM_TOKEN__SCRIPTS;
136 case _SOURCES: return AM_TOKEN__SOURCES;
137 case _TEXINFOS: return AM_TOKEN__TEXINFOS;
138 case _DIR: return AM_TOKEN_DIR;
139 case _LDFLAGS: return AM_TOKEN__LDFLAGS;
140 case _CPPFLAGS: return AM_TOKEN__CPPFLAGS;
141 case _CFLAGS: return AM_TOKEN__CFLAGS;
142 case _CXXFLAGS: return AM_TOKEN__CXXFLAGS;
143 case _JAVACFLAGS: return AM_TOKEN__JAVACFLAGS;
144 case _VALAFLAGS: return AM_TOKEN__VALAFLAGS;
145 case _FCFLAGS: return AM_TOKEN__FCFLAGS;
146 case _OBJCFLAGS: return AM_TOKEN__OBJCFLAGS;
147 case _LFLAGS: return AM_TOKEN__LFLAGS;
148 case _YFLAGS: return AM_TOKEN__YFLAGS;
149 case TARGET_LDFLAGS: return AM_TOKEN_TARGET_LDFLAGS;
150 case TARGET_CPPFLAGS: return AM_TOKEN_TARGET_CPPFLAGS;
151 case TARGET_CFLAGS: return AM_TOKEN_TARGET_CFLAGS;
152 case TARGET_CXXFLAGS: return AM_TOKEN_TARGET_CXXFLAGS;
153 case TARGET_JAVACFLAGS: return AM_TOKEN_TARGET_JAVACFLAGS;
154 case TARGET_VALAFLAGS: return AM_TOKEN_TARGET_VALAFLAGS;
155 case TARGET_FCFLAGS: return AM_TOKEN_TARGET_FCFLAGS;
156 case TARGET_OBJCFLAGS: return AM_TOKEN_TARGET_OBJCFLAGS;
157 case TARGET_LFLAGS: return AM_TOKEN_TARGET_LFLAGS;
158 case TARGET_YFLAGS: return AM_TOKEN_TARGET_YFLAGS;
159 case TARGET_DEPENDENCIES: return AM_TOKEN_TARGET_DEPENDENCIES;
160 case TARGET_LIBADD: return AM_TOKEN_TARGET_LIBADD;
161 case TARGET_LDADD: return AM_TOKEN_TARGET_LDADD;
163 default: return ANJUTA_TOKEN_NAME;
171 /* File cannot be empty, there at least the END_OF_FILE token */
172 file:
173 statement
174 | file statement
177 statement:
178 end_of_line
179 | space end_of_line
180 | definition end_of_line
181 | am_variable end_of_line
182 | include end_of_line
183 | line end_of_line
184 | rule command_list
187 am_variable:
188 optional_space automake_token optional_space equal_token value_list {
189 $$ = anjuta_token_new_static (amp_am_automake_variable ($2), NULL);
190 if ($1 != NULL) anjuta_token_set_type ($1, ANJUTA_TOKEN_START);
191 anjuta_token_merge ($$, $2);
192 if ($3 != NULL) anjuta_token_set_type ($3, ANJUTA_TOKEN_NEXT);
193 anjuta_token_merge ($$, $4);
194 anjuta_token_merge ($$, $5);
195 amp_am_scanner_set_am_variable (scanner, $$);
197 | optional_space automake_token optional_space equal_token
199 AnjutaToken *list;
200 list = anjuta_token_new_static (ANJUTA_TOKEN_LIST, NULL);
201 anjuta_token_insert_after ($4, list);
202 $$ = anjuta_token_new_static (amp_am_automake_variable ($2), NULL);
203 anjuta_token_merge ($$, $2);
204 anjuta_token_merge ($$, list);
205 amp_am_scanner_set_am_variable (scanner, $$);
209 include:
210 optional_space include_token value_list {
211 $$ = anjuta_token_new_static (ANJUTA_TOKEN_LIST, NULL);
212 anjuta_token_merge ($$, $2);
213 anjuta_token_merge ($$, $3);
214 amp_am_scanner_include (scanner, $$);
217 definition:
218 head_list equal_token value_list {
219 $$ = anjuta_token_new_static (ANJUTA_TOKEN_DEFINITION, NULL);
220 anjuta_token_merge_own_children ($1);
221 anjuta_token_merge ($$, $1);
222 anjuta_token_merge ($$, $2);
223 anjuta_token_merge ($$, $3);
224 amp_am_scanner_update_variable (scanner, $$);
226 | head_list equal_token {
227 AnjutaToken *list;
228 list = anjuta_token_new_static (ANJUTA_TOKEN_LIST, NULL);
229 anjuta_token_insert_after ($2, list);
230 $$ = anjuta_token_new_static (ANJUTA_TOKEN_DEFINITION, NULL);
231 anjuta_token_merge_own_children ($1);
232 anjuta_token_merge ($$, $1);
233 anjuta_token_merge ($$, $2);
234 anjuta_token_merge ($$, list);
235 amp_am_scanner_update_variable (scanner, $$);
239 rule:
240 depend_list end_of_line
241 | depend_list SEMI_COLON command_line END_OF_LINE
242 | depend_list SEMI_COLON command_line END_OF_FILE
245 depend_list:
246 head_list rule_token prerequisite_list
249 command_list:
250 /* empty */
251 | command_list TAB command_line END_OF_LINE
252 | command_list TAB command_line END_OF_FILE
255 line:
256 head_list
259 /* Lists
260 *----------------------------------------------------------------------------*/
262 end_of_line:
263 END_OF_LINE {
264 anjuta_token_set_type ($1, ANJUTA_TOKEN_EOL);
265 $$ = NULL;
267 | END_OF_FILE {
268 $$ = NULL;
270 | COMMENT {
271 anjuta_token_set_type ($1, ANJUTA_TOKEN_COMMENT);
272 $$ = NULL;
276 not_eol_list:
277 /* empty */
278 | not_eol_list not_eol_token
281 prerequisite_list:
282 /* empty */
283 | space
284 | optional_space prerequisite_list_body optional_space
287 prerequisite_list_body:
288 prerequisite
289 | prerequisite_list_body space prerequisite
292 head_list:
293 optional_space head_list_body optional_space {
294 $$ = anjuta_token_merge_previous ($2, $1);
295 anjuta_token_merge ($$, $3);
299 head_list_body:
300 head {
301 $$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
302 anjuta_token_merge ($$, $1);
304 | head_list_body space next_head {
305 anjuta_token_merge ($1, $2);
306 anjuta_token_merge ($1, $3);
308 | head_list_body space head {
309 anjuta_token_merge ($1, $2);
310 anjuta_token_merge ($1, $3);
314 value_list:
315 space {
316 $$ = anjuta_token_new_static (ANJUTA_TOKEN_LIST, NULL);
317 if ($1 != NULL) anjuta_token_set_type ($1, ANJUTA_TOKEN_START);
318 anjuta_token_merge ($$, $1);
320 | optional_space value_list_body optional_space {
321 if ($1 != NULL) anjuta_token_set_type ($1, ANJUTA_TOKEN_START);
322 if ($3 != NULL) anjuta_token_set_type ($3, ANJUTA_TOKEN_LAST);
323 anjuta_token_merge_previous ($2, $1);
324 anjuta_token_merge ($2, $3);
325 $$ = $2;
328 value_list_body:
329 value {
330 $$ = anjuta_token_new_static (ANJUTA_TOKEN_LIST, NULL);
331 anjuta_token_merge ($$, $1);
333 | value_list_body space value {
334 anjuta_token_set_type ($2, ANJUTA_TOKEN_NEXT);
335 anjuta_token_merge ($1, $2);
336 anjuta_token_merge ($1, $3);
342 command_line:
343 /* empty */
344 | command_line command_token
347 /* Items
348 *----------------------------------------------------------------------------*/
350 optional_space:
351 /* empty */ {
352 $$ = NULL;
354 | space
357 space:
358 space_token {
359 $$ = anjuta_token_new_static (ANJUTA_TOKEN_SPACE, NULL);
360 anjuta_token_merge ($$, $1);
362 /*| space_variable {
363 $$ = anjuta_token_new_static (ANJUTA_TOKEN_SPACE, NULL);
364 anjuta_token_merge ($$, $1);
366 | space space_token {
367 anjuta_token_merge ($1, $2);
369 /*| space space_variable {
370 anjuta_token_merge ($1, $2);
374 head:
375 head_token {
376 $$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
377 anjuta_token_merge ($$, $1);
379 | ac_variable {
380 $$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
381 anjuta_token_merge ($$, $1);
383 | variable {
384 $$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
385 anjuta_token_merge ($$, $1);
387 | head head_token {
388 anjuta_token_merge ($1, $2);
390 | head automake_token {
391 anjuta_token_merge ($1, $2);
393 | head include_token {
394 anjuta_token_merge ($1, $2);
396 | head variable {
397 anjuta_token_merge ($1, $2);
399 | head ac_variable {
400 anjuta_token_merge ($1, $2);
404 next_head:
405 automake_token {
406 $$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
407 anjuta_token_merge ($$, $1);
409 | include_token {
410 $$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
411 anjuta_token_merge ($$, $1);
413 | next_head head_token {
414 anjuta_token_merge ($1, $2);
416 | next_head automake_token {
417 anjuta_token_merge ($1, $2);
419 | next_head include_token {
420 anjuta_token_merge ($1, $2);
422 | next_head variable {
423 anjuta_token_merge ($1, $2);
425 | next_head ac_variable {
426 anjuta_token_merge ($1, $2);
430 value:
431 value_token {
432 $$ = anjuta_token_new_static (ANJUTA_TOKEN_ARGUMENT, NULL);
433 anjuta_token_merge ($$, $1);
435 | variable {
436 $$ = anjuta_token_new_static (ANJUTA_TOKEN_ARGUMENT, NULL);
437 anjuta_token_merge ($$, $1);
439 | ac_variable {
440 $$ = anjuta_token_new_static (ANJUTA_TOKEN_ARGUMENT, NULL);
441 anjuta_token_merge ($$, $1);
443 | value value_token {
444 anjuta_token_merge ($1, $2);
446 | value variable {
447 anjuta_token_merge ($1, $2);
449 | value ac_variable {
450 anjuta_token_merge ($1, $2);
454 prerequisite:
455 name_prerequisite
458 name_prerequisite:
459 prerequisite_token
460 | variable
461 | ac_variable
462 | name_prerequisite prerequisite_token
463 | name_prerequisite variable
464 | name_prerequisite ac_variable
467 variable:
468 VARIABLE {
469 amp_am_scanner_parse_variable (scanner, $$);
473 ac_variable:
474 MACRO {
475 amp_am_scanner_parse_ac_variable (scanner, $$);
479 /* Tokens
480 *----------------------------------------------------------------------------*/
482 not_eol_token:
483 word_token
484 | space_token
487 prerequisite_token:
488 name_token
489 | equal_token
490 | rule_token
493 command_token:
494 name_token
495 | variable_token
496 | automake_token
497 | equal_token
498 | rule_token
499 | depend_token
500 | include_token
501 | space_token
502 | comment_token
505 value_token:
506 name_token
507 | equal_token
508 | rule_token
509 | depend_token
510 | include_token
511 | automake_token
514 head_token:
515 name_token
516 | depend_token
519 space_token:
520 SPACE
521 | TAB
524 comment_token:
525 COMMENT
528 equal_token:
529 EQUAL
530 | IMMEDIATE_EQUAL
531 | CONDITIONAL_EQUAL
532 | APPEND
535 rule_token:
536 COLON
537 | DOUBLE_COLON
540 depend_token:
541 SEMI_COLON
544 word_token:
545 name_token
546 | equal_token
547 | rule_token
548 | depend_token
552 name_token:
553 NAME
554 | CHARACTER
555 | ORDER
558 variable_token:
559 VARIABLE
560 | MACRO
563 automake_token:
564 SUBDIRS
565 | DIST_SUBDIRS
566 | _DATA
567 | _HEADERS
568 | _LIBRARIES
569 | _LISP
570 | _LTLIBRARIES
571 | _MANS
572 | _PROGRAMS
573 | _PYTHON
574 | _JAVA
575 | _SCRIPTS
576 | _SOURCES
577 | _TEXINFOS
578 | _DIR
579 | _LDFLAGS
580 | _CPPFLAGS
581 | _CFLAGS
582 | _CXXFLAGS
583 | _JAVACFLAGS
584 | _VALAFLAGS
585 | _FCFLAGS
586 | _OBJCFLAGS
587 | _LFLAGS
588 | _YFLAGS
589 | TARGET_LDFLAGS
590 | TARGET_CPPFLAGS
591 | TARGET_CFLAGS
592 | TARGET_CXXFLAGS
593 | TARGET_JAVACFLAGS
594 | TARGET_VALAFLAGS
595 | TARGET_FCFLAGS
596 | TARGET_OBJCFLAGS
597 | TARGET_LFLAGS
598 | TARGET_YFLAGS
599 | TARGET_DEPENDENCIES
600 | TARGET_LIBADD
601 | TARGET_LDADD
604 include_token:
605 INCLUDE