3 # Language-independent M4 Macros for Bison.
4 # Copyright (C) 2002, 2004-2010 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ## ---------------- ##
22 ## ---------------- ##
24 # b4_copyright(TITLE, [YEARS])
25 # ----------------------------
26 # If YEARS are not defined, use b4_copyright_years.
27 m4_define([b4_copyright],
28 [b4_comment([A Bison parser, made by GNU Bison b4_version.])
32 ]m4_dquote(m4_text_wrap([Copyright (C)
33 ]m4_ifval([$2], [[$2]], [m4_defn([b4_copyright_years])])[
34 Free Software Foundation, Inc.]))[
36 This program is free software: you can redistribute it and/or modify
37 it under the terms of the GNU General Public License as published by
38 the Free Software Foundation, either version 3 of the License, or
39 (at your option) any later version.
41 This program is distributed in the hope that it will be useful,
42 but WITHOUT ANY WARRANTY; without even the implied warranty of
43 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 GNU General Public License for more details.
46 You should have received a copy of the GNU General Public License
47 along with this program. If not, see <http://www.gnu.org/licenses/>.])
49 b4_comment([As a special exception, you may create a larger work that contains
50 part or all of the Bison parser skeleton and distribute that work
51 under terms of your choice, so long as that work isn't itself a
52 parser generator using the skeleton or a modified version thereof
53 as a parser skeleton. Alternatively, if you modify or redistribute
54 the parser skeleton itself, you may (at your option) remove this
55 special exception, which will cause the skeleton and the resulting
56 Bison output files to be licensed under the GNU General Public
57 License without this special exception.
59 This special exception was added by the Free Software Foundation in
60 version 2.2 of Bison.])])
63 ## ---------------- ##
65 ## ---------------- ##
67 # The following error handling macros print error directives that should not
68 # become arguments of other macro invocations since they would likely then be
69 # mangled. Thus, they print to stdout directly.
73 # Write TEXT to stdout. Precede the final newline with an @ so that it's
74 # escaped. For example:
76 # b4_cat([[@complain(invalid input@)]])
78 [m4_syscmd([cat <<'_m4eof'
79 ]m4_bpatsubst(m4_dquote($1), [_m4eof], [_m4@`eof])[@
82 m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write to stdout])])])
84 # b4_error(KIND, FORMAT, [ARG1], [ARG2], ...)
85 # -------------------------------------------
86 # Write @KIND(FORMAT@,ARG1@,ARG2@,...@) to stdout.
90 # b4_error([[warn]], [[invalid value for `%s': %s]], [[foo]], [[3]])
92 [b4_cat([[@]$1[(]$2[]]dnl
95 m4_dquote(m4_shift(m4_shift($@))),
96 [[@,]b4_arg])])[@)]])])
98 # b4_error_at(KIND, START, END, FORMAT, [ARG1], [ARG2], ...)
99 # ----------------------------------------------------------
100 # Write @KIND_at(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
104 # b4_error_at([[complain]], [[input.y:2.3]], [[input.y:5.4]],
105 # [[invalid %s]], [[foo]])
106 m4_define([b4_error_at],
107 [b4_cat([[@]$1[_at(]$2[@,]$3[@,]$4[]]dnl
108 [m4_if([$#], [4], [],
109 [m4_foreach([b4_arg],
110 m4_dquote(m4_shift(m4_shift(m4_shift(m4_shift($@))))),
111 [[@,]b4_arg])])[@)]])])
113 # b4_warn(FORMAT, [ARG1], [ARG2], ...)
114 # ------------------------------------
115 # Write @warn(FORMAT@,ARG1@,ARG2@,...@) to stdout.
119 # b4_warn([[invalid value for `%s': %s]], [[foo]], [[3]])
121 # As a simple test suite, this:
124 # m4_define([asdf], [ASDF])
125 # m4_define([fsa], [FSA])
126 # m4_define([fdsa], [FDSA])
127 # b4_warn([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]])
128 # b4_warn([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]])
133 # Should produce this without newlines:
135 # @warn([asdf), asdf]@,[fsa), fsa]@,[fdsa), fdsa]@)
136 # @warn(asdf), asdf@,fsa), fsa@,fdsa), fdsa@)
141 [b4_error([[warn]], $@)])
143 # b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...)
144 # ---------------------------------------------------
145 # Write @warn(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
149 # b4_warn_at([[input.y:2.3]], [[input.y:5.4]], [[invalid %s]], [[foo]])
150 m4_define([b4_warn_at],
151 [b4_error_at([[warn]], $@)])
153 # b4_complain(FORMAT, [ARG1], [ARG2], ...)
154 # ----------------------------------------
155 # Write @complain(FORMAT@,ARG1@,ARG2@,...@) to stdout.
157 # See b4_warn example.
158 m4_define([b4_complain],
159 [b4_error([[complain]], $@)])
161 # b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...)
162 # -------------------------------------------------------
163 # Write @complain(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
165 # See b4_warn_at example.
166 m4_define([b4_complain_at],
167 [b4_error_at([[complain]], $@)])
169 # b4_fatal(FORMAT, [ARG1], [ARG2], ...)
170 # -------------------------------------
171 # Write @fatal(FORMAT@,ARG1@,ARG2@,...@) to stdout and exit.
173 # See b4_warn example.
174 m4_define([b4_fatal],
175 [b4_error([[fatal]], $@)dnl
178 # b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...)
179 # ----------------------------------------------------
180 # Write @fatal(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout and exit.
182 # See b4_warn_at example.
183 m4_define([b4_fatal_at],
184 [b4_error_at([[fatal]], $@)dnl
188 ## ---------------- ##
189 ## Default values. ##
190 ## ---------------- ##
192 # m4_define_default([b4_lex_param], []) dnl breaks other skeletons
193 m4_define_default([b4_pre_prologue], [])
194 m4_define_default([b4_post_prologue], [])
195 m4_define_default([b4_epilogue], [])
196 m4_define_default([b4_parse_param], [])
198 # The initial column and line.
199 m4_define_default([b4_location_initial_column], [1])
200 m4_define_default([b4_location_initial_line], [1])
207 # b4_ints_in(INT1, INT2, LOW, HIGH)
208 # ---------------------------------
209 # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
210 m4_define([b4_ints_in],
211 [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
214 # b4_subtract(LHS, RHS)
215 # ---------------------
216 # Evaluate LHS - RHS if they are integer literals, otherwise expand
218 m4_define([b4_subtract],
219 [m4_bmatch([$1$2], [^[0123456789]*$],
220 [m4_eval([$1 - $2])],
224 # _b4_args(ARG1, ...)
225 # -------------------
226 # Join with comma, skipping empty arguments.
227 # b4_args calls itself recursively until it sees the first non-empty
228 # argument, then calls _b4_args which prepends each non-empty argument
234 [$1[]_$0(m4_shift($@))],
235 [$0(m4_shift($@))])])])
237 # _b4_args(ARGS1, ...)
238 # --------------------
239 m4_define([_b4_args],
242 [m4_ifval([$1], [, $1])[]$0(m4_shift($@))])])
247 # b4_integral_parser_tables_map(MACRO)
248 # -------------------------------------
249 # Map MACRO on all the integral tables. MACRO is expected to have
250 # the signature MACRO(TABLE-NAME, CONTENT, COMMENT).
251 m4_define([b4_integral_parser_tables_map],
252 [$1([pact], [b4_pact],
253 [[YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
256 $1([defact], [b4_defact],
257 [[YYDEFACT[S] -- default reduction number in state S. Performed when
258 YYTABLE does not specify something else to do. Zero means the default
261 $1([pgoto], [b4_pgoto], [[YYPGOTO[NTERM-NUM].]])
263 $1([defgoto], [b4_defgoto], [[YYDEFGOTO[NTERM-NUM].]])
265 $1([table], [b4_table],
266 [[YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
267 positive, shift that token. If negative, reduce the rule which
268 number is the opposite. If YYTABLE_NINF, syntax error.]])
270 $1([check], [b4_check])
272 $1([stos], [b4_stos],
273 [[STOS_[STATE-NUM] -- The (internal number of the) accessing
274 symbol of state STATE-NUM.]])
277 [[YYR1[YYN] -- Symbol number of symbol that rule YYN derives.]])
280 [[YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.]])
284 # b4_parser_tables_declare
285 # b4_parser_tables_define
286 # ------------------------
287 # Define/declare the (deterministic) parser tables.
288 m4_define([b4_parser_tables_declare],
289 [b4_integral_parser_tables_map([b4_integral_parser_table_declare])])
291 m4_define([b4_parser_tables_define],
292 [b4_integral_parser_tables_map([b4_integral_parser_table_define])])
296 ## ------------------ ##
297 ## Decoding options. ##
298 ## ------------------ ##
300 # b4_flag_if(FLAG, IF-TRUE, IF-FALSE)
301 # -----------------------------------
302 # Run IF-TRUE if b4_FLAG_flag is 1, IF-FALSE if FLAG is 0, otherwise fail.
303 m4_define([b4_flag_if],
307 [m4_fatal([invalid $1 value: ]$1)])])
310 # b4_define_flag_if(FLAG)
311 # -----------------------
312 # Define "b4_FLAG_if(IF-TRUE, IF-FALSE)" that depends on the
313 # value of the Boolean FLAG.
314 m4_define([b4_define_flag_if],
315 [_b4_define_flag_if($[1], $[2], [$1])])
317 # _b4_define_flag_if($1, $2, FLAG)
318 # --------------------------------
319 # This macro works around the impossibility to define macros
320 # inside macros, because issuing `[$1]' is not possible in M4 :(.
321 # This sucks hard, GNU M4 should really provide M5 like $$1.
322 m4_define([_b4_define_flag_if],
323 [m4_if([$1$2], $[1]$[2], [],
324 [m4_fatal([$0: Invalid arguments: $@])])dnl
325 m4_define([b4_$3_if],
326 [b4_flag_if([$3], [$1], [$2])])])
329 # b4_FLAG_if(IF-TRUE, IF-FALSE)
330 # -----------------------------
331 # Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
332 b4_define_flag_if([defines]) # Whether headers are requested.
333 b4_define_flag_if([glr]) # Whether a GLR parser is requested.
334 b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
335 b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
342 # b4_symbol_(NUM, FIELD)
343 # ----------------------
344 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
346 m4_define([b4_symbol_],
347 [m4_indir([b4_symbol($1, $2)])])
350 # b4_symbol(NUM, FIELD)
351 # ---------------------
352 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
353 # undefined. If FIELD = id, prepend the prefix.
354 m4_define([b4_symbol],
356 [id], [m4_do([b4_percent_define_get([api.tokens.prefix])],
357 [b4_symbol_([$1], [id])])],
361 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
362 # -------------------------------------------
363 # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
364 # Otherwise an error.
365 m4_define([b4_symbol_if],
366 [m4_case(b4_symbol([$1], [$2]),
369 [m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], [$2]))])])
372 # b4_symbol_action_location(SYMBOL-NUM, KIND)
373 # -------------------------------------------
374 # Report the location of the KIND action as FILE:LINE.
375 m4_define([b4_symbol_action_location],
376 [b4_symbol([$1], [$2_file]):b4_syncline([b4_symbol([$1], [$2_line])])])
379 # b4_symbol_action(SYMBOL-NUM, KIND)
380 # ----------------------------------
381 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
382 # Same as in C, but using references instead of pointers.
383 m4_define([b4_symbol_action],
384 [b4_symbol_if([$1], [has_$2],
385 [m4_pushdef([b4_dollar_dollar],
386 [b4_symbol_value([(*yyvaluep)],
387 b4_symbol_if([$1], [has_type],
388 [b4_symbol([$1], [type])]))])dnl
389 m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl
390 b4_symbol_case_([$1])
391 b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
392 b4_symbol([$1], [$2])
393 b4_syncline([@oline@], [@ofile@])
396 m4_popdef([b4_at_dollar])dnl
397 m4_popdef([b4_dollar_dollar])dnl
401 # b4_symbol_destructor(SYMBOL-NUM)
402 # b4_symbol_printer(SYMBOL-NUM)
403 # --------------------------------
404 m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])])
405 m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])])
408 # b4_symbol_case_(SYMBOL-NUM)
409 # ---------------------------
410 # Issue a "case NUM" for SYMBOL-NUM.
411 m4_define([b4_symbol_case_],
412 [ case b4_symbol([$1], [number]): // b4_symbol([$1], [tag])
416 # b4_symbol_foreach(MACRO)
417 # ------------------------
418 # Invoke MACRO(SYMBOL-NUM) for each SYMBOL-NUM.
419 m4_define([b4_symbol_foreach],
420 [m4_map([$1], m4_defn([b4_symbol_numbers]))])
427 # b4_type_action_(NUMS)
428 # ---------------------
429 # Run actions for the symbol NUMS that all have the same type-name.
430 # Skip NUMS that have no type-name.
431 m4_define([b4_type_action_],
432 [b4_symbol_if([$1], [has_type],
433 [m4_map([b4_symbol_case_], [$@])[]dnl
434 b4_dollar_dollar([b4_symbol([$1], [number])],
435 [b4_symbol([$1], [tag])],
436 [b4_symbol([$1], [type])]);
441 # b4_type_foreach(MACRO)
442 # ----------------------
443 # Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set.
444 m4_define([b4_type_foreach],
445 [m4_map([$1], m4_defn([b4_type_names]))])
455 # Similar to POSIX basename; the differences don't matter here.
456 # Beware that NAME is not evaluated.
457 m4_define([b4_basename],
458 [m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])])
461 # b4_syncline(LINE, FILE)
462 # -----------------------
463 m4_define([b4_syncline],
464 [b4_flag_if([synclines],
465 [b4_sync_end([__line__], [b4_basename(m4_quote(__file__))])
466 b4_sync_start([$1], [$2])])])
468 m4_define([b4_sync_end], [b4_comment([Line $1 of $2])])
469 m4_define([b4_sync_start], [b4_comment([Line $1 of $2])])
471 # b4_user_code(USER-CODE)
472 # -----------------------
473 # Emit code from the user, ending it with synclines.
474 m4_define([b4_user_code],
476 b4_syncline([@oline@], [@ofile@])])
479 # b4_define_user_code(MACRO)
480 # --------------------------
481 # From b4_MACRO, build b4_user_MACRO that includes the synclines.
482 m4_define([b4_define_user_code],
483 [m4_define([b4_user_$1],
484 [b4_user_code([b4_$1])])])
488 # b4_user_initial_action
489 # b4_user_post_prologue
490 # b4_user_pre_prologue
492 # ----------------------
493 # Macros that issue user code, ending with synclines.
494 b4_define_user_code([actions])
495 b4_define_user_code([initial_action])
496 b4_define_user_code([post_prologue])
497 b4_define_user_code([pre_prologue])
498 b4_define_user_code([stype])
501 # b4_check_user_names(WHAT, USER-LIST, BISON-NAMESPACE)
502 # -----------------------------------------------------
503 # Complain if any name of type WHAT is used by the user (as recorded in
504 # USER-LIST) but is not used by Bison (as recorded by macros in the
505 # namespace BISON-NAMESPACE).
507 # USER-LIST must expand to a list specifying all user occurrences of all names
508 # of type WHAT. Each item in the list must be a triplet specifying one
509 # occurrence: name, start boundary, and end boundary. Empty string names are
510 # fine. An empty list is fine.
512 # For example, to define b4_foo_user_names to be used for USER-LIST with three
513 # name occurrences and with correct quoting:
515 # m4_define([b4_foo_user_names],
516 # [[[[[[bar]], [[parser.y:1.7]], [[parser.y:1.16]]]],
517 # [[[[bar]], [[parser.y:5.7]], [[parser.y:5.16]]]],
518 # [[[[baz]], [[parser.y:8.7]], [[parser.y:8.16]]]]]])
520 # The macro BISON-NAMESPACE(bar) must be defined iff the name bar of type WHAT
521 # is used by Bison (in the front-end or in the skeleton). Empty string names
522 # are fine, but it would be ugly for Bison to actually use one.
524 # For example, to use b4_foo_bison_names for BISON-NAMESPACE and define that
525 # the names bar and baz are used by Bison:
527 # m4_define([b4_foo_bison_names(bar)])
528 # m4_define([b4_foo_bison_names(baz)])
530 # To invoke b4_check_user_names with TYPE foo, with USER-LIST
531 # b4_foo_user_names, with BISON-NAMESPACE b4_foo_bison_names, and with correct
534 # b4_check_user_names([[foo]], [b4_foo_user_names],
535 # [[b4_foo_bison_names]])
536 m4_define([b4_check_user_names],
537 [m4_foreach([b4_occurrence], $2,
538 [m4_pushdef([b4_occurrence], b4_occurrence)dnl
539 m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl
540 m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl
541 m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl
542 m4_ifndef($3[(]m4_quote(b4_user_name)[)],
543 [b4_complain_at([b4_start], [b4_end],
544 [[%s `%s' is not used]],
545 [$1], [b4_user_name])])[]dnl
546 m4_popdef([b4_occurrence])dnl
547 m4_popdef([b4_user_name])dnl
548 m4_popdef([b4_start])dnl
549 m4_popdef([b4_end])dnl
554 ## --------------------- ##
555 ## b4_percent_define_*. ##
556 ## --------------------- ##
559 # b4_percent_define_use(VARIABLE)
560 # -------------------------------
561 # Declare that VARIABLE was used.
562 m4_define([b4_percent_define_use],
563 [m4_define([b4_percent_define_bison_variables(]$1[)])dnl
566 # b4_percent_define_get(VARIABLE, [DEFAULT])
567 # ------------------------------------------
568 # Mimic muscle_percent_define_get in ../src/muscle-tab.h. That is, if
569 # the %define variable VARIABLE is defined, emit its value. Contrary
570 # to its C counterpart, return DEFAULT otherwise. Also, record
571 # Bison's usage of VARIABLE by defining
572 # b4_percent_define_bison_variables(VARIABLE).
576 # b4_percent_define_get([[foo]])
577 m4_define([b4_percent_define_get],
578 [b4_percent_define_use([$1])dnl
579 m4_ifdef([b4_percent_define(]$1[)],
580 [m4_indir([b4_percent_define(]$1[)])],
583 # b4_percent_define_get_loc(VARIABLE)
584 # -----------------------------------
585 # Mimic muscle_percent_define_get_loc in ../src/muscle-tab.h exactly. That is,
586 # if the %define variable VARIABLE is undefined, complain fatally since that's
587 # a Bison or skeleton error. Otherwise, return its definition location in a
588 # form approriate for the first two arguments of b4_warn_at, b4_complain_at, or
589 # b4_fatal_at. Don't record this as a Bison usage of VARIABLE as there's no
590 # reason to suspect that the user-supplied value has yet influenced the output.
594 # b4_complain_at(b4_percent_define_get_loc([[foo]]), [[invalid foo]])
595 m4_define([b4_percent_define_get_loc],
596 [m4_ifdef([b4_percent_define_loc(]$1[)],
597 [m4_pushdef([b4_loc], m4_indir([b4_percent_define_loc(]$1[)]))dnl
599 m4_popdef([b4_loc])],
600 [b4_fatal([[undefined %%define variable `%s' passed to b4_percent_define_get_loc]], [$1])])])
602 # b4_percent_define_get_syncline(VARIABLE)
603 # ----------------------------------------
604 # Mimic muscle_percent_define_get_syncline in ../src/muscle-tab.h exactly.
605 # That is, if the %define variable VARIABLE is undefined, complain fatally
606 # since that's a Bison or skeleton error. Otherwise, return its definition
607 # location as a b4_syncline invocation. Don't record this as a Bison usage of
608 # VARIABLE as there's no reason to suspect that the user-supplied value has yet
609 # influenced the output.
613 # b4_percent_define_get_syncline([[foo]])
614 m4_define([b4_percent_define_get_syncline],
615 [m4_ifdef([b4_percent_define_syncline(]$1[)],
616 [m4_indir([b4_percent_define_syncline(]$1[)])],
617 [b4_fatal([[undefined %%define variable `%s' passed to b4_percent_define_get_syncline]], [$1])])])
619 # b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE])
620 # ------------------------------------------------------
621 # Mimic muscle_percent_define_ifdef in ../src/muscle-tab.h exactly. That is,
622 # if the %define variable VARIABLE is defined, expand IF-TRUE, else expand
623 # IF-FALSE. Also, record Bison's usage of VARIABLE by defining
624 # b4_percent_define_bison_variables(VARIABLE).
628 # b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]])
629 m4_define([b4_percent_define_ifdef],
630 [m4_ifdef([b4_percent_define(]$1[)],
631 [b4_percent_define_use([$1])$2],
640 # b4_percent_define_flag_if(VARIABLE, IF-TRUE, [IF-FALSE])
641 # --------------------------------------------------------
642 # Mimic muscle_percent_define_flag_if in ../src/muscle-tab.h exactly. That is,
643 # if the %define variable VARIABLE is defined to "" or "true", expand IF-TRUE.
644 # If it is defined to "false", expand IF-FALSE. Complain if it is undefined
645 # (a Bison or skeleton error since the default value should have been set
646 # already) or defined to any other value (possibly a user error). Also, record
647 # Bison's usage of VARIABLE by defining
648 # b4_percent_define_bison_variables(VARIABLE).
652 # b4_percent_define_flag_if([[foo]], [[it's true]], [[it's false]])
653 m4_define([b4_percent_define_flag_if],
654 [b4_percent_define_ifdef([$1],
655 [m4_case(b4_percent_define_get([$1]),
656 [], [$2], [true], [$2], [false], [$3],
657 [m4_expand_once([b4_complain_at(b4_percent_define_get_loc([$1]),
658 [[invalid value for %%define Boolean variable `%s']],
660 [[b4_percent_define_flag_if($1)]])])],
661 [b4_fatal([[undefined %%define variable `%s' passed to b4_percent_define_flag_if]], [$1])])])
664 # b4_percent_define_default(VARIABLE, DEFAULT)
665 # --------------------------------------------
666 # Mimic muscle_percent_define_default in ../src/muscle-tab.h exactly. That is,
667 # if the %define variable VARIABLE is undefined, set its value to DEFAULT.
668 # Don't record this as a Bison usage of VARIABLE as there's no reason to
669 # suspect that the value has yet influenced the output.
673 # b4_percent_define_default([[foo]], [[default value]])
674 m4_define([b4_percent_define_default],
675 [m4_ifndef([b4_percent_define(]$1[)],
676 [m4_define([b4_percent_define(]$1[)], [$2])dnl
677 m4_define([b4_percent_define_loc(]$1[)],
678 [[[[<skeleton default value>:-1.-1]],
679 [[<skeleton default value>:-1.-1]]]])dnl
680 m4_define([b4_percent_define_syncline(]$1[)], [[]])])])
683 # b4_percent_define_if_define(VARIABLE)
684 # -------------------------------------
685 # Define b4_VARIABLE_if that executes its $1 or $2 depending whether
686 # VARIABLE was %defined. The characters `.' and `-' in VARIABLE are mapped
688 m4_define([b4_percent_define_if_define_],
689 [m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]),
690 [b4_percent_define_flag_if([$1], [$2], [$3])])])
691 m4_define([b4_percent_define_if_define],
692 [b4_percent_define_default([[$1]], [[false]])
693 b4_percent_define_if_define_([$1], $[1], $[2])])
696 # b4_percent_define_check_values(VALUES)
697 # --------------------------------------
698 # Mimic muscle_percent_define_check_values in ../src/muscle-tab.h exactly
699 # except that the VALUES structure is more appropriate for M4. That is, VALUES
700 # is a list of sublists of strings. For each sublist, the first string is the
701 # name of a %define variable, and all remaining strings in that sublist are the
702 # valid values for that variable. Complain if such a variable is undefined (a
703 # Bison error since the default value should have been set already) or defined
704 # to any other value (possibly a user error). Don't record this as a Bison
705 # usage of the variable as there's no reason to suspect that the value has yet
706 # influenced the output.
710 # b4_percent_define_check_values([[[[foo]], [[foo-value1]], [[foo-value2]]]],
711 # [[[[bar]], [[bar-value1]]]])
712 m4_define([b4_percent_define_check_values],
713 [m4_foreach([b4_sublist], m4_quote($@),
714 [_b4_percent_define_check_values(b4_sublist)])])
716 m4_define([_b4_percent_define_check_values],
717 [m4_ifdef([b4_percent_define(]$1[)],
718 [m4_pushdef([b4_good_value], [0])dnl
720 [m4_foreach([b4_value], m4_dquote(m4_shift($@)),
721 [m4_if(m4_indir([b4_percent_define(]$1[)]), b4_value,
722 [m4_define([b4_good_value], [1])])])])dnl
723 m4_if(b4_good_value, [0],
724 [b4_complain_at(b4_percent_define_get_loc([$1]),
725 [[invalid value for %%define variable `%s': `%s']],
727 m4_dquote(m4_indir([b4_percent_define(]$1[)])))
728 m4_foreach([b4_value], m4_dquote(m4_shift($@)),
729 [b4_complain_at(b4_percent_define_get_loc([$1]),
730 [[accepted value: `%s']],
731 m4_dquote(b4_value))])])dnl
732 m4_popdef([b4_good_value])],
733 [b4_fatal([[undefined %%define variable `%s' passed to b4_percent_define_check_values]], [$1])])])
735 # b4_percent_code_get([QUALIFIER])
736 # --------------------------------
737 # If any %code blocks for QUALIFIER are defined, emit them beginning with a
738 # comment and ending with synclines and a newline. If QUALIFIER is not
739 # specified or empty, do this for the unqualified %code blocks. Also, record
740 # Bison's usage of QUALIFIER (if specified) by defining
741 # b4_percent_code_bison_qualifiers(QUALIFIER).
743 # For example, to emit any unqualified %code blocks followed by any %code
744 # blocks for the qualifier foo:
746 # b4_percent_code_get
747 # b4_percent_code_get([[foo]])
748 m4_define([b4_percent_code_get],
749 [m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl
750 m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl
751 m4_ifdef(b4_macro_name,
752 [b4_comment([m4_if([$#], [0], [[Unqualified %code]],
753 [["%code ]$1["]])[ blocks.]])
754 b4_user_code([m4_indir(b4_macro_name)])
756 m4_popdef([b4_macro_name])])
758 # b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE])
759 # -----------------------------------------------------
760 # If any %code blocks for QUALIFIER (or unqualified %code blocks if
761 # QUALIFIER is empty) are defined, expand IF-TRUE, else expand IF-FALSE.
762 # Also, record Bison's usage of QUALIFIER (if specified) by defining
763 # b4_percent_code_bison_qualifiers(QUALIFIER).
764 m4_define([b4_percent_code_ifdef],
765 [m4_ifdef([b4_percent_code(]$1[)],
766 [m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])$2],
770 ## ------------------ ##
771 ## Common variables. ##
772 ## ------------------ ##
774 # Default values for %define.
775 # ---------------------------
776 # If the api.tokens.prefix, it is empty.
777 m4_percent_define_default([[api.tokens.prefix]], [[]])
779 # b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
780 # b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT])
781 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
782 # b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT])
783 # ----------------------------------------------
784 b4_percent_define_if_define([lex_symbol])
785 b4_percent_define_if_define([locations]) # Whether locations are tracked.
786 b4_percent_define_if_define([parse.assert])
787 b4_percent_define_if_define([parse.trace])
788 b4_percent_define_if_define([variant])
791 # b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT])
792 # ------------------------------------------------------
793 # Map %define parse.error "(simple|verbose)" to b4_error_verbose_if and
794 # b4_error_verbose_flag.
795 b4_percent_define_default([[parse.error]], [[simple]])
796 b4_percent_define_check_values([[[[parse.error]],
797 [[simple]], [[verbose]]]])
798 m4_define([b4_error_verbose_flag],
799 [m4_case(b4_percent_define_get([[parse.error]]),
802 b4_define_flag_if([error_verbose])
805 ## ----------------------------------------------------------- ##
806 ## After processing the skeletons, check that all the user's ##
807 ## %define variables and %code qualifiers were used by Bison. ##
808 ## ----------------------------------------------------------- ##
810 m4_define([b4_check_user_names_wrap],
811 [m4_ifdef([b4_percent_]$1[_user_]$2[s],
812 [b4_check_user_names([[%]$1 $2],
813 [b4_percent_]$1[_user_]$2[s],
814 [[b4_percent_]$1[_bison_]$2[s]])])])
817 b4_check_user_names_wrap([[define]], [[variable]])
818 b4_check_user_names_wrap([[code]], [[qualifier]])