1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
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 "ac-scanner.h"
22 #include "ac-parser.h"
28 #include "libanjuta/anjuta-debug.h"
30 /* Token location is found directly from token value, there is no need to
31 * maintain a separate location variable */
32 #define YYLLOC_DEFAULT(Current, Rhs, N) ((Current) = YYRHSLOC(Rhs, (N) ? 1 : 0))
37 %token END_OF_LINE
'\n'
43 %token RIGHT_PAREN
')'
45 %token RIGHT_CURLY
'}'
47 %token RIGHT_BRACE
']'
52 %token SINGLE_QUOTE
'\''
53 %token DOUBLE_QUOTE
'\"'
63 %token START_SPACE_LIST
73 %token AC_MACRO_WITH_ARG
74 %token AC_MACRO_WITHOUT_ARG
79 %token AC_CHECK_HEADERS
82 %token AC_CONFIG_FILES
83 %token AC_CONFIG_HEADERS
84 %token AC_CONFIG_MACRO_DIR
85 %token AC_CONFIG_SRCDIR
86 %token AC_EGREP_HEADER
92 %token OBSOLETE_AC_OUTPUT
97 %token IT_PROG_INTLTOOL
102 %token AC_TYPE_SIZE_T
104 %token AM_INIT_AUTOMAKE
105 %token AM_GLIB_GNU_GETTEXT
106 %token AM_MAINTAINER_MODE
107 %token AM_PROG_LIBTOOL
108 %token AC_PROG_LIBTOOL
110 %token DEFAULT_LT_INIT
112 %token PKG_CHECK_MODULES
113 %token PKG_PROG_PKG_CONFIG
120 %define api.push_pull
"push"
122 %parse
-param
{AmpAcScanner
* scanner
}
123 %lex
-param
{AmpAcScanner
* scanner
}
125 %name
-prefix
="amp_ac_yy"
135 //amp_ac_yydebug = 1;
138 amp_ac_autoconf_macro
(AnjutaToken
*token
)
140 switch
(anjuta_token_get_type
(token
))
142 case AC_ARG_ENABLE
: return AC_TOKEN_AC_ARG_ENABLE
;
143 case AC_C_CONST
: return AC_TOKEN_AC_C_CONST
;
144 case AC_CHECK_FUNCS
: return AC_TOKEN_AC_CHECK_FUNCS
;
145 case AC_CHECK_HEADERS
: return AC_TOKEN_AC_CHECK_HEADERS
;
146 case AC_CHECK_LIB
: return AC_TOKEN_AC_CHECK_LIB
;
147 case AC_CHECK_PROG
: return AC_TOKEN_AC_CHECK_PROG
;
148 case AC_CONFIG_FILES
: return AC_TOKEN_AC_CONFIG_FILES
;
149 case AC_CONFIG_HEADERS
: return AC_TOKEN_AC_CONFIG_HEADERS
;
150 case AC_CONFIG_MACRO_DIR
: return AC_TOKEN_AC_CONFIG_MACRO_DIR
;
151 case AC_CONFIG_SRCDIR
: return AC_TOKEN_AC_CONFIG_SRCDIR
;
152 case AC_EGREP_HEADER
: return AC_TOKEN_AC_EGREP_HEADER
;
153 case AC_EXEEXT
: return AC_TOKEN_AC_EXEEXT
;
154 case AC_HEADER_STDC
: return AC_TOKEN_AC_HEADER_STDC
;
155 case AC_INIT
: return AC_TOKEN_AC_INIT
;
156 case AC_OBJEXT
: return AC_TOKEN_AC_OBJEXT
;
157 case AC_OUTPUT
: return AC_TOKEN_AC_OUTPUT
;
158 case OBSOLETE_AC_OUTPUT
: return AC_TOKEN_OBSOLETE_AC_OUTPUT
;
159 case AC_PREREQ
: return AC_TOKEN_AC_PREREQ
;
160 case AC_PROG_CC
: return AC_TOKEN_AC_PROG_CC
;
161 case AC_PROG_CPP
: return AC_TOKEN_AC_PROG_CPP
;
162 case AC_PROG_CXX
: return AC_TOKEN_AC_PROG_CXX
;
163 case IT_PROG_INTLTOOL
: return AC_TOKEN_IT_PROG_INTLTOOL
;
164 case AC_PROG_LEX
: return AC_TOKEN_AC_PROG_LEX
;
165 case AC_PROG_RANLIB
: return AC_TOKEN_AC_PROG_RANLIB
;
166 case AC_PROG_YACC
: return AC_TOKEN_AC_PROG_YACC
;
167 case AC_TYPE_SIZE_T
: return AC_TOKEN_AC_TYPE_SIZE_T
;
168 case AC_TYPE_OFF_T
: return AC_TOKEN_AC_TYPE_OFF_T
;
169 case AM_INIT_AUTOMAKE
: return AC_TOKEN_AM_INIT_AUTOMAKE
;
170 case AM_GLIB_GNU_GETTEXT
: return AC_TOKEN_AM_GLIB_GNU_GETTEXT
;
171 case AM_MAINTAINER_MODE
: return AC_TOKEN_AM_MAINTAINER_MODE
;
172 case AC_PROG_LIBTOOL
: return AC_TOKEN_AC_PROG_LIBTOOL
;
173 case AM_PROG_LIBTOOL
: return AC_TOKEN_AM_PROG_LIBTOOL
;
174 case LT_INIT
: return AC_TOKEN_LT_INIT
;
175 case DEFAULT_LT_INIT
: return AC_TOKEN_LT_INIT
;
176 case LT_PREREQ
: return AC_TOKEN_LT_PREREQ
;
177 case PKG_CHECK_MODULES
: return AC_TOKEN_PKG_CHECK_MODULES
;
178 case PKG_PROG_PKG_CONFIG
: return AC_TOKEN_PKG_PROG_PKG_CONFIG
;
179 default
: return anjuta_token_get_type
(token
);
189 | START_SPACE_LIST space_list
198 optional_spaces end_statement
199 | optional_spaces statement end_statement
204 NAME optional_spaces EQUAL value
{
205 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_DEFINITION
, NULL
);
206 if
($2) anjuta_token_set_type
($2, ANJUTA_TOKEN_NEXT
);
207 anjuta_token_merge
($$
, $1);
208 anjuta_token_merge
($$
, $2);
209 anjuta_token_merge
($$
, $3);
210 anjuta_token_merge
($$
, $4);
211 amp_ac_scanner_update_variable
(scanner
, $$
);
213 | NAME optional_spaces EQUAL
{
214 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_DEFINITION
, NULL
);
215 if
($2) anjuta_token_set_type
($2, ANJUTA_TOKEN_NEXT
);
216 anjuta_token_merge
($$
, $1);
217 anjuta_token_merge
($$
, $2);
218 anjuta_token_merge
($$
, $3);
219 amp_ac_scanner_update_variable
(scanner
, $$
);
230 | no_name_token value
231 | NAME optional_spaces
232 | NAME optional_spaces no_equal_token
233 | NAME optional_spaces no_equal_token value
238 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_LIST
, NULL
);
239 anjuta_token_merge
($$
, $1);
241 | value value_token
{
242 anjuta_token_merge
($1, $2);
288 | ac_macro_without_arg
297 *----------------------------------------------------------------------------*/
302 | space_list_body spaces_with_eol
{
303 anjuta_token_set_type
($2, ANJUTA_TOKEN_LAST
);
309 | spaces_with_eol item
{
310 anjuta_token_set_type
($1, ANJUTA_TOKEN_NEXT
);
312 | space_list_body spaces_with_eol item
{
313 anjuta_token_set_type
($2, ANJUTA_TOKEN_NEXT
);
324 anjuta_token_set_type
($1, ANJUTA_TOKEN_OPERATOR
);
330 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_NAME
, NULL
);
331 anjuta_token_merge
($$
, $1);
334 anjuta_token_merge
($1, $2);
339 *----------------------------------------------------------------------------*/
348 DNL not_eol_list end_of_line
{
349 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_COMMENT
, NULL
);
350 anjuta_token_merge
($$
, $1);
351 anjuta_token_merge
($$
, $2);
352 anjuta_token_merge
($$
, $3);
357 M4_INCLUDE arg_list
{
358 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_LIST
, NULL
);
359 anjuta_token_merge
($$
, $1);
360 anjuta_token_merge
($$
, $2);
361 amp_ac_scanner_include
(scanner
, $$
);
367 PKG_CHECK_MODULES arg_list
{
368 $$
= anjuta_token_new_static
(AC_TOKEN_PKG_CHECK_MODULES
, NULL
);
369 anjuta_token_merge
($$
, $1);
370 anjuta_token_merge
($$
, $2);
371 amp_ac_scanner_load_module
(scanner
, $2);
376 /* empty */ %prec EMPTY
377 | COMMA NAME %prec ARG
381 ac_macro_with_arg_token arg_list
{
382 $$
= anjuta_token_new_static
(amp_ac_autoconf_macro
($1), NULL
);
383 anjuta_token_merge
($$
, $1);
384 anjuta_token_merge
($$
, $2);
385 amp_ac_scanner_load_properties
(scanner
, $$
, $2);
389 ac_macro_without_arg:
390 ac_macro_without_arg_token
{
391 anjuta_token_set_type
($1, amp_ac_autoconf_macro
($1));
392 amp_ac_scanner_load_properties
(scanner
, $$
, NULL
);
397 $$
= anjuta_token_new_static
(AC_TOKEN_AC_SUBST
, NULL
);
398 anjuta_token_merge
($$
, $1);
399 anjuta_token_merge
($$
, $2);
400 amp_ac_scanner_subst_variable
(scanner
, $2);
406 anjuta_token_set_type
($1, AC_TOKEN_AC_OUTPUT
);
411 OBSOLETE_AC_OUTPUT arg_list
{
412 $$
= anjuta_token_new_static
(AC_TOKEN_OBSOLETE_AC_OUTPUT
, NULL
);
413 anjuta_token_merge
($$
, $1);
414 anjuta_token_merge
($$
, $2);
415 amp_ac_scanner_load_config
(scanner
, $2);
420 AC_CONFIG_FILES arg_list
{
421 $$
= anjuta_token_new_static
(AC_TOKEN_AC_CONFIG_FILES
, NULL
);
422 anjuta_token_merge
($$
, $1);
423 anjuta_token_merge
($$
, $2);
424 amp_ac_scanner_load_config
(scanner
, $2);
429 *----------------------------------------------------------------------------*/
432 arg_list_body RIGHT_PAREN
{
433 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_LAST
, NULL
);
434 anjuta_token_merge
($$
, $2);
435 anjuta_token_merge
($1, $$
);
438 | spaces_with_eol arg_list_body RIGHT_PAREN
{
439 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_LAST
, NULL
);
440 anjuta_token_merge
($$
, $3);
441 anjuta_token_merge
($2, $$
);
442 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_LIST
, NULL
);
443 anjuta_token_set_type
($1, ANJUTA_TOKEN_START
);
444 anjuta_token_merge
($$
, $1);
445 anjuta_token_merge_children
($$
, $2);
451 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_LIST
, NULL
);
452 anjuta_token_merge
($$
, $1);
453 //fprintf(stdout, "arg_list_body arg\n");
454 //anjuta_token_dump ($1);
456 | arg_list_body separator arg
{
457 //fprintf(stdout, "arg_list_body body\n");
458 //anjuta_token_dump ($1);
459 //fprintf(stdout, "arg_list_body separator\n");
460 //anjuta_token_dump ($2);
461 //fprintf(stdout, "arg_list_body arg\n");
462 //anjuta_token_dump ($3);
463 anjuta_token_merge
($1, $2);
464 anjuta_token_merge
($1, $3);
465 //fprintf(stdout, "arg_list_body merge\n");
466 //anjuta_token_dump ($1);
471 HASH not_eol_list end_of_line
{
472 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_COMMENT
, NULL
);
473 anjuta_token_merge
($$
, $1);
474 anjuta_token_merge
($$
, $2);
475 anjuta_token_merge
($$
, $3);
483 | not_eol_list not_eol_token
{
494 SINGLE_QUOTE single_string_body SINGLE_QUOTE
{
495 anjuta_token_set_type
($1, ANJUTA_TOKEN_OPEN_QUOTE
);
496 anjuta_token_set_type
($3, ANJUTA_TOKEN_CLOSE_QUOTE
);
497 $$
= anjuta_token_merge_previous
($2, $1);
498 anjuta_token_merge
($2, $3);
504 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_STRING
, NULL
);
506 | single_string_body not_single_token
{
507 anjuta_token_merge
($1, $2);
530 DOUBLE_QUOTE double_string_body DOUBLE_QUOTE
{
531 anjuta_token_set_type
($1, ANJUTA_TOKEN_OPEN_QUOTE
);
532 anjuta_token_set_type
($3, ANJUTA_TOKEN_CLOSE_QUOTE
);
533 $$
= anjuta_token_merge_previous
($2, $1);
534 anjuta_token_merge
($2, $3);
540 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_STRING
, NULL
);
542 | double_string_body not_double_token
{
543 anjuta_token_merge
($1, $2);
565 LEFT_BRACE m4_string_body RIGHT_BRACE
{
566 anjuta_token_set_type
($1, ANJUTA_TOKEN_OPEN_QUOTE
);
567 anjuta_token_set_type
($3, ANJUTA_TOKEN_CLOSE_QUOTE
);
568 $$
= anjuta_token_merge_previous
($2, $1);
569 anjuta_token_merge
($2, $3);
575 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_STRING
, NULL
);
577 | m4_string_body not_brace_token
{
578 anjuta_token_merge
($1, $2);
580 | m4_string_body m4_string
{
581 anjuta_token_merge
($1, $2);
586 LEFT_BRACE raw_string_body RIGHT_BRACE
{
587 anjuta_token_set_type
($1, ANJUTA_TOKEN_OPEN_QUOTE
);
588 anjuta_token_set_type
($3, ANJUTA_TOKEN_CLOSE_QUOTE
);
589 $$
= anjuta_token_merge_previous
($2, $1);
590 anjuta_token_merge
($2, $3);
596 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_STRING
, NULL
);
598 | raw_string_body not_brace_token
{
599 anjuta_token_merge
($1, $2);
601 | raw_string_body raw_string
{
602 anjuta_token_merge
($1, $2);
607 LEFT_BRACE arg_string_body RIGHT_BRACE
{
608 anjuta_token_set_type
($1, ANJUTA_TOKEN_OPEN_QUOTE
);
609 anjuta_token_set_type
($3, ANJUTA_TOKEN_CLOSE_QUOTE
);
610 $$
= anjuta_token_merge_previous
($2, $1);
611 anjuta_token_merge
($2, $3);
617 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_STRING
, NULL
);
619 | arg_string_body SPACE
{
620 anjuta_token_merge
($1, $2);
622 | arg_string_body END_OF_LINE
{
623 anjuta_token_merge
($1, $2);
625 | arg_string_body HASH
{
626 anjuta_token_merge
($1, $2);
628 | arg_string_body LEFT_PAREN
{
629 anjuta_token_merge
($1, $2);
631 | arg_string_body RIGHT_PAREN
{
632 anjuta_token_merge
($1, $2);
634 | arg_string_body COMMA
{
635 anjuta_token_merge
($1, $2);
637 | arg_string_body EQUAL
{
638 anjuta_token_merge
($1, $2);
640 | arg_string_body GREATER
{
641 anjuta_token_merge
($1, $2);
643 | arg_string_body LOWER
{
644 anjuta_token_merge
($1, $2);
646 | arg_string_body NAME
{
647 anjuta_token_merge
($1, $2);
649 | arg_string_body VARIABLE
{
650 anjuta_token_merge
($1, $2);
652 | arg_string_body WORD
{
653 anjuta_token_merge
($1, $2);
655 | arg_string_body SINGLE_QUOTE
{
656 anjuta_token_merge
($1, $2);
658 | arg_string_body DOUBLE_QUOTE
{
659 anjuta_token_merge
($1, $2);
661 | arg_string_body macro
662 | arg_string_body dnl
663 | arg_string_body raw_string
{
664 anjuta_token_merge
($1, $2);
669 *----------------------------------------------------------------------------*/
673 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_ITEM
, NULL
);
675 | arg_part arg_body
{
676 //fprintf(stdout, "arg part\n");
677 //anjuta_token_dump ($1);
678 //fprintf(stdout, "arg body\n");
679 //anjuta_token_dump ($2);
680 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_ITEM
, NULL
);
681 anjuta_token_merge
($$
, $1);
682 anjuta_token_merge_children
($$
, $2);
683 //fprintf(stdout, "arg merge\n");
684 //anjuta_token_dump ($1);
690 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_ITEM
, NULL
);
692 | arg_body arg_part_or_space
{
693 $$
= anjuta_token_merge
($1, $2);
725 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_NEXT
, NULL
);
726 anjuta_token_merge
($$
, $1);
728 | COMMA spaces_with_eol
{
729 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_NEXT
, NULL
);
730 //fprintf(stdout, "separator spaces\n");
731 //anjuta_token_dump ($2);
732 //fprintf(stdout, "separator comma\n");
733 //anjuta_token_dump ($1);
734 //fprintf(stdout, "separator next\n");
735 //anjuta_token_dump ($$);
736 anjuta_token_merge
($$
, $1);
737 anjuta_token_merge_children
($$
, $2);
738 //fprintf(stdout, "separator merge\n");
739 //anjuta_token_dump ($$);
744 LEFT_PAREN expression_body RIGHT_PAREN
{
745 $$
= anjuta_token_merge_previous
($2, $1);
746 anjuta_token_merge
($2, $3);
752 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_STRING
, NULL
);
754 | expression_body SPACE
{
755 anjuta_token_merge
($1, $2);
757 | expression_body END_OF_LINE
{
758 anjuta_token_merge
($1, $2);
760 | expression_body comment
761 | expression_body COMMA
{
762 anjuta_token_merge
($1, $2);
764 | expression_body EQUAL
{
765 anjuta_token_merge
($1, $2);
767 | expression_body LOWER
{
768 anjuta_token_merge
($1, $2);
770 | expression_body GREATER
{
771 anjuta_token_merge
($1, $2);
773 | expression_body NAME
{
774 anjuta_token_merge
($1, $2);
776 | expression_body VARIABLE
{
777 anjuta_token_merge
($1, $2);
779 | expression_body WORD
{
780 anjuta_token_merge
($1, $2);
782 | expression_body SINGLE_QUOTE
{
783 anjuta_token_merge
($1, $2);
785 | expression_body DOUBLE_QUOTE
{
786 anjuta_token_merge
($1, $2);
788 | expression_body macro
789 | expression_body expression
{
790 anjuta_token_merge
($1, $2);
792 | expression_body arg_string
{
793 anjuta_token_merge
($1, $2);
806 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_SPACE
, NULL
);
807 anjuta_token_merge
($$
, $1);
810 anjuta_token_merge
($1, $2);
816 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_SPACE
, NULL
);
817 anjuta_token_merge
($$
, $1);
820 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_SPACE
, NULL
);
821 anjuta_token_merge
($$
, $1);
823 | spaces_with_eol SPACE
{
824 anjuta_token_merge
($1, $2);
826 | spaces_with_eol END_OF_LINE
{
827 anjuta_token_merge
($1, $2);
833 *----------------------------------------------------------------------------*/
927 | ac_macro_with_arg_token
928 | ac_macro_without_arg_token
931 ac_macro_without_arg_token:
951 ac_macro_with_arg_token:
959 | AC_CONFIG_MACRO_DIR
966 | AM_GLIB_GNU_GETTEXT
969 | PKG_PROG_PKG_CONFIG
974 anjuta_token_set_type
($1, ANJUTA_TOKEN_EOL
);