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 "mk-scanner.h"
22 #include "mk-parser.h"
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))
42 %token DOUBLE_COLON
"::"
46 %token IMMEDIATE_EQUAL
":="
47 %token CONDITIONAL_EQUAL
"?="
58 %token _SECONDEXPANSION
59 %token _DELETE_ON_ERROR
61 %token _LOW_RESOLUTION_TIME
63 %token _EXPORT_ALL_VARIABLES
72 %define api.push_pull
"push"
76 %parse
-param
{void* scanner
}
77 %lex
-param
{void* scanner
}
94 mkp_special_prerequisite
(AnjutaToken
*token
)
96 switch
(anjuta_token_get_type
(token
))
99 return MK_TOKEN_ORDER
;
101 return ANJUTA_TOKEN_NAME
;
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
))
115 switch
(anjuta_token_get_type
(target
))
118 mk_token
= MK_TOKEN__PHONY
;
121 mk_token
= MK_TOKEN__SUFFIXES
;
124 mk_token
= MK_TOKEN__DEFAULT
;
127 mk_token
= MK_TOKEN__PRECIOUS
;
130 mk_token
= MK_TOKEN__INTERMEDIATE
;
133 mk_token
= MK_TOKEN__SECONDARY
;
135 case _SECONDEXPANSION
:
136 mk_token
= MK_TOKEN__SECONDEXPANSION
;
138 case _DELETE_ON_ERROR
:
139 mk_token
= MK_TOKEN__DELETE_ON_ERROR
;
142 mk_token
= MK_TOKEN__IGNORE
;
144 case _LOW_RESOLUTION_TIME
:
145 mk_token
= MK_TOKEN__LOW_RESOLUTION_TIME
;
148 mk_token
= MK_TOKEN__SILENT
;
150 case _EXPORT_ALL_VARIABLES
:
151 mk_token
= MK_TOKEN__EXPORT_ALL_VARIABLES
;
154 mk_token
= MK_TOKEN__NOTPARALLEL
;
157 mk_token
= MK_TOKEN_ORDER
;
165 anjuta_token_set_type
(arg
, mk_token
);
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);
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
, $$
);
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);
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))
227 anjuta_token_set_type
($2, MK_TOKEN_COLON
);
230 anjuta_token_set_type
($2, MK_TOKEN_DOUBLE_COLON
);
235 anjuta_token_merge
($$
, $2);
236 anjuta_token_merge
($$
, $3);
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);
259 *----------------------------------------------------------------------------*/
271 HASH not_eol_list EOL
276 | not_eol_list not_eol_token
281 $$
= anjuta_token_new_static
(MK_TOKEN_PREREQUISITE
, NULL
);
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);
295 prerequisite_list_body:
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);
308 optional_space head_list_body optional_space
{
309 $$
= anjuta_token_merge_previous
($2, $1);
310 anjuta_token_merge
($$
, $3);
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);
327 $$
= anjuta_token_new_static
(MK_TOKEN_COMMAND
, NULL
);
329 | command_line command_token
{
330 anjuta_token_merge
($1, $2);
335 *----------------------------------------------------------------------------*/
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
357 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_NAME
, NULL
);
358 anjuta_token_merge
($$
, $1);
361 anjuta_token_merge
($1, $2);
363 | head variable_token
368 $$
= anjuta_token_new_static
(ANJUTA_TOKEN_VALUE
, NULL
);
369 anjuta_token_merge
($$
, $1);
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);
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
400 $$
= anjuta_token_new_static
(MK_TOKEN_EQUAL
, NULL
);
401 anjuta_token_merge
($$
, $1);
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);
412 $$
= anjuta_token_new_static
(MK_TOKEN_APPEND
, NULL
);
413 anjuta_token_merge
($$
, $1);
419 *----------------------------------------------------------------------------*/
456 mkp_scanner_parse_variable
(scanner
, $$
);
474 | _LOW_RESOLUTION_TIME
476 | _EXPORT_ALL_VARIABLES
512 | _LOW_RESOLUTION_TIME
514 | _EXPORT_ALL_VARIABLES