yacc: declare yyerror/yylex only when POSIXLY_CORRECT
[bison.git] / data / skeletons / bison.m4
blob037dadcf8c5bf9e05ebac2baf332f9e627006c36
1                                                             -*- Autoconf -*-
3 # Language-independent M4 Macros for Bison.
5 # Copyright (C) 2002, 2004-2015, 2018-2021 Free Software Foundation,
6 # Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
23 # m4_gsub(STRING, RE1, SUBST1, RE2, SUBST2, ...)
24 # ----------------------------------------------
25 # m4 equivalent of
27 #   $_ = STRING;
28 #   s/RE1/SUBST1/g;
29 #   s/RE2/SUBST2/g;
30 #   ...
32 # Really similar to m4_bpatsubsts, but behaves properly with quotes.
33 # See m4.at's "Generating Comments".  Super inelegant, but so far, I
34 # did not find any better solution.
35 m4_define([b4_gsub],
36 [m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([[[[$1]]]],
37                                         [$2], [$3]),
38                            [$4], [$5]),
39               [$6], [$7])])
41 # m4_shift2 and m4_shift3 are provided by m4sugar.
42 m4_define([m4_shift4], [m4_shift(m4_shift(m4_shift(m4_shift($@))))])
45 ## ---------------- ##
46 ## Identification.  ##
47 ## ---------------- ##
49 # b4_generated_by
50 # ---------------
51 m4_define([b4_generated_by],
52 [b4_comment([A Bison parser, made by GNU Bison b4_version_string.])
55 # b4_copyright(TITLE, [YEARS])
56 # ----------------------------
57 # If YEARS are not defined, use b4_copyright_years.
58 m4_define([b4_copyright],
59 [b4_generated_by
60 b4_comment([$1
62 ]m4_dquote(m4_text_wrap([Copyright (C)
63 ]m4_ifval([$2], [[$2]], [m4_defn([b4_copyright_years])])[
64 Free Software Foundation, Inc.]))[
66 This program is free software: you can redistribute it and/or modify
67 it under the terms of the GNU General Public License as published by
68 the Free Software Foundation, either version 3 of the License, or
69 (at your option) any later version.
71 This program is distributed in the hope that it will be useful,
72 but WITHOUT ANY WARRANTY; without even the implied warranty of
73 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
74 GNU General Public License for more details.
76 You should have received a copy of the GNU General Public License
77 along with this program.  If not, see <https://www.gnu.org/licenses/>.])
79 b4_comment([As a special exception, you may create a larger work that contains
80 part or all of the Bison parser skeleton and distribute that work
81 under terms of your choice, so long as that work isn't itself a
82 parser generator using the skeleton or a modified version thereof
83 as a parser skeleton.  Alternatively, if you modify or redistribute
84 the parser skeleton itself, you may (at your option) remove this
85 special exception, which will cause the skeleton and the resulting
86 Bison output files to be licensed under the GNU General Public
87 License without this special exception.
89 This special exception was added by the Free Software Foundation in
90 version 2.2 of Bison.])
94 # b4_disclaimer
95 # -------------
96 # Issue a warning about private implementation details.
97 m4_define([b4_disclaimer],
98 [b4_comment([DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
99 especially those whose name start with YY_ or yy_.  They are
100 private implementation details that can be changed or removed.])
105 # b4_required_version_if(VERSION, IF_NEWER, IF_OLDER)
106 # ---------------------------------------------------
107 # If the version %require'd by the user is VERSION (or newer) expand
108 # IF_NEWER, otherwise IF_OLDER.  VERSION should be an integer, e.g.,
109 # 302 for 3.2.
110 m4_define([b4_required_version_if],
111 [m4_if(m4_eval($1 <= b4_required_version),
112               [1], [$2], [$3])])
115 ## -------- ##
116 ## Output.  ##
117 ## -------- ##
119 # b4_output_begin(FILE1, FILE2)
120 # -----------------------------
121 # Enable output, i.e., send to diversion 0, expand after "#", and
122 # generate the tag to output into FILE.  Must be followed by EOL.
123 # FILE is FILE1 concatenated to FILE2.  FILE2 can be empty, or be
124 # absolute: do the right thing.
125 m4_define([b4_output_begin],
126 [m4_changecom()
127 m4_divert_push(0)dnl
128 @output(m4_unquote([$1])@,m4_unquote([$2])@)@dnl
132 # b4_output_end
133 # -------------
134 # Output nothing, restore # as comment character (no expansions after #).
135 m4_define([b4_output_end],
136 [m4_divert_pop(0)
137 m4_changecom([#])
141 # b4_divert_kill(CODE)
142 # --------------------
143 # Expand CODE for its side effects, discard its output.
144 m4_define([b4_divert_kill],
145 [m4_divert_text([KILL], [$1])])
148 # b4_define_silent(MACRO, CODE)
149 # -----------------------------
150 # Same as m4_define, but throw away the expansion of CODE.
151 m4_define([b4_define_silent],
152 [m4_define([$1], [b4_divert_kill([$2])])])
155 ## ---------------- ##
156 ## Error handling.  ##
157 ## ---------------- ##
159 # The following error handling macros print error directives that should not
160 # become arguments of other macro invocations since they would likely then be
161 # mangled.  Thus, they print to stdout directly.
163 # b4_cat(TEXT)
164 # ------------
165 # Write TEXT to stdout.  Precede the final newline with an @ so that it's
166 # escaped.  For example:
168 #   b4_cat([[@complain(invalid input@)]])
169 m4_define([b4_cat],
170 [m4_syscmd([cat <<'_m4eof'
171 ]m4_bpatsubst(m4_dquote($1), [_m4eof], [_m4@`eof])[@
172 _m4eof
173 ])dnl
174 m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write to stdout])])])
176 # b4_error(KIND, START, END, FORMAT, [ARG1], [ARG2], ...)
177 # -------------------------------------------------------
178 # Write @KIND(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
180 # For example:
182 #   b4_error([[complain]], [[input.y:2.3]], [[input.y:5.4]],
183 #            [[invalid %s]], [[foo]])
184 m4_define([b4_error],
185 [b4_cat([[@complain][(]$1[@,]$2[@,]$3[@,]$4[]]dnl
186 [m4_if([$#], [4], [],
187        [m4_foreach([b4_arg],
188                    m4_dquote(m4_shift4($@)),
189                    [[@,]b4_arg])])[@)]])])
191 # b4_warn(FORMAT, [ARG1], [ARG2], ...)
192 # ------------------------------------
193 # Write @warn(FORMAT@,ARG1@,ARG2@,...@) to stdout.
195 # For example:
197 #   b4_warn([[invalid value for '%s': %s]], [[foo]], [[3]])
199 # As a simple test suite, this:
201 #   m4_divert(-1)
202 #   m4_define([asdf], [ASDF])
203 #   m4_define([fsa], [FSA])
204 #   m4_define([fdsa], [FDSA])
205 #   b4_warn_at([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]])
206 #   b4_warn_at([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]])
207 #   b4_warn_at()
208 #   b4_warn_at(1)
209 #   b4_warn_at(1, 2)
211 # Should produce this without newlines:
213 #   @warn_at([asdf), asdf]@,@,@,[fsa), fsa]@,[fdsa), fdsa]@)
214 #   @warn(asdf), asdf@,@,@,fsa), fsa@,fdsa), fdsa@)
215 #   @warn(@)
216 #   @warn(1@)
217 #   @warn(1@,2@)
218 m4_define([b4_warn],
219 [b4_warn_at([], [], $@)])
221 # b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...)
222 # ---------------------------------------------------
223 # Write @warn(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
225 # For example:
227 #   b4_warn_at([[input.y:2.3]], [[input.y:5.4]], [[invalid %s]], [[foo]])
228 m4_define([b4_warn_at],
229 [b4_error([[warn]], $@)])
231 # b4_complain(FORMAT, [ARG1], [ARG2], ...)
232 # ----------------------------------------
233 # Bounce to b4_complain_at.
235 # See b4_warn example.
236 m4_define([b4_complain],
237 [b4_complain_at([], [], $@)])
239 # b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...)
240 # -------------------------------------------------------
241 # Write @complain(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
243 # See b4_warn_at example.
244 m4_define([b4_complain_at],
245 [b4_error([[complain]], $@)])
247 # b4_fatal(FORMAT, [ARG1], [ARG2], ...)
248 # -------------------------------------
249 # Bounce to b4_fatal_at.
251 # See b4_warn example.
252 m4_define([b4_fatal],
253 [b4_fatal_at([], [], $@)])
255 # b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...)
256 # ----------------------------------------------------
257 # Write @fatal(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout and exit.
259 # See b4_warn_at example.
260 m4_define([b4_fatal_at],
261 [b4_error([[fatal]], $@)dnl
262 m4_exit(1)])
264 # b4_canary(MSG)
265 # --------------
266 # Issue a warning on stderr and in the output.  Used in the test suite
267 # to catch spurious m4 evaluations.
268 m4_define([b4_canary],
269 [m4_errprintn([dead canary: $1])DEAD CANARY($1)])
272 ## ------------ ##
273 ## Data Types.  ##
274 ## ------------ ##
276 # b4_ints_in(INT1, INT2, LOW, HIGH)
277 # ---------------------------------
278 # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
279 m4_define([b4_ints_in],
280 [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
283 # b4_subtract(LHS, RHS)
284 # ---------------------
285 # Evaluate LHS - RHS if they are integer literals, otherwise expand
286 # to (LHS) - (RHS).
287 m4_define([b4_subtract],
288 [m4_bmatch([$1$2], [^[0123456789]*$],
289            [m4_eval([$1 - $2])],
290            [($1) - ($2)])])
292 # b4_join(ARG1, ...)
293 # _b4_join(ARG1, ...)
294 # -------------------
295 # Join with comma, skipping empty arguments.
296 # b4_join calls itself recursively until it sees the first non-empty
297 # argument, then calls _b4_join (i.e., `_$0`) which prepends each
298 # non-empty argument with a comma.
299 m4_define([b4_join],
300 [m4_if([$#$1],
301        [1], [],
302        [m4_ifval([$1],
303                  [$1[]_$0(m4_shift($@))],
304                  [$0(m4_shift($@))])])])
306 # _b4_join(ARGS1, ...)
307 # --------------------
308 m4_define([_b4_join],
309 [m4_if([$#$1],
310        [1], [],
311        [m4_ifval([$1], [, $1])[]$0(m4_shift($@))])])
316 # b4_integral_parser_tables_map(MACRO)
317 # -------------------------------------
318 # Map MACRO on all the integral tables.  MACRO is expected to have
319 # the signature MACRO(TABLE-NAME, CONTENT, COMMENT).
320 m4_define([b4_integral_parser_tables_map],
321 [$1([pact], [b4_pact],
322     [[YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
323 STATE-NUM.]])
325 $1([defact], [b4_defact],
326    [[YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
327 Performed when YYTABLE does not specify something else to do.  Zero
328 means the default is an error.]])
330 $1([pgoto], [b4_pgoto], [[YYPGOTO[NTERM-NUM].]])
332 $1([defgoto], [b4_defgoto], [[YYDEFGOTO[NTERM-NUM].]])
334 $1([table], [b4_table],
335    [[YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
336 positive, shift that token.  If negative, reduce the rule whose
337 number is the opposite.  If YYTABLE_NINF, syntax error.]])
339 $1([check], [b4_check])
341 $1([stos], [b4_stos],
342    [[YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
343 state STATE-NUM.]])
345 $1([r1], [b4_r1],
346    [[YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.]])
348 $1([r2], [b4_r2],
349    [[YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.]])
353 # b4_parser_tables_declare
354 # b4_parser_tables_define
355 # ------------------------
356 # Define/declare the (deterministic) parser tables.
357 m4_define([b4_parser_tables_declare],
358 [b4_integral_parser_tables_map([b4_integral_parser_table_declare])])
360 m4_define([b4_parser_tables_define],
361 [b4_integral_parser_tables_map([b4_integral_parser_table_define])])
365 ## ------------------ ##
366 ## Decoding options.  ##
367 ## ------------------ ##
369 # b4_flag_if(FLAG, IF-TRUE, IF-FALSE)
370 # -----------------------------------
371 # Run IF-TRUE if b4_FLAG_flag is 1, IF-FALSE if FLAG is 0, otherwise fail.
372 m4_define([b4_flag_if],
373 [m4_case(b4_$1_flag,
374          [0], [$3],
375          [1], [$2],
376          [m4_fatal([invalid $1 value: ]b4_$1_flag)])])
379 # b4_define_flag_if(FLAG)
380 # -----------------------
381 # Define "b4_FLAG_if(IF-TRUE, IF-FALSE)" that depends on the
382 # value of the Boolean FLAG.
383 m4_define([b4_define_flag_if],
384 [_b4_define_flag_if($[1], $[2], [$1])])
386 # _b4_define_flag_if($1, $2, FLAG)
387 # --------------------------------
388 # Work around the impossibility to define macros inside macros,
389 # because issuing '[$1]' is not possible in M4.  GNU M4 should provide
390 # $$1 a la M5/TeX.
391 m4_define([_b4_define_flag_if],
392 [m4_if([$1$2], $[1]$[2], [],
393        [m4_fatal([$0: Invalid arguments: $@])])dnl
394 m4_define([b4_$3_if],
395           [b4_flag_if([$3], [$1], [$2])])])
398 # b4_FLAG_if(IF-TRUE, IF-FALSE)
399 # -----------------------------
400 # Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
401 b4_define_flag_if([glr])                # Whether a GLR parser is requested.
402 b4_define_flag_if([has_translations])   # Whether some tokens are internationalized.
403 b4_define_flag_if([header])             # Whether a header is requested.
404 b4_define_flag_if([nondeterministic])   # Whether conflicts should be handled.
405 b4_define_flag_if([token_table])        # Whether yytoken_table is demanded.
406 b4_define_flag_if([yacc])               # Whether POSIX Yacc is emulated.
409 # b4_glr_cc_if([IF-TRUE], [IF-FALSE])
410 # -----------------------------------
411 m4_define([b4_glr_cc_if],
412           [m4_if(m4_bregexp(b4_skeleton, [^"glr.cc"$]), [0], $@)])
415 ## --------- ##
416 ## Symbols.  ##
417 ## --------- ##
419 # For a description of the Symbol handling, see README.md.
421 # The following macros provide access to symbol related values.
423 # __b4_symbol(NUM, FIELD)
424 # -----------------------
425 # Fetch FIELD of symbol #NUM.  Fail if undefined.
426 m4_define([__b4_symbol],
427 [m4_indir([b4_symbol($1, $2)])])
430 # _b4_symbol(NUM, FIELD)
431 # ----------------------
432 # Fetch FIELD of symbol #NUM (or "orig NUM", see README.md).
433 # Fail if undefined.
434 m4_define([_b4_symbol],
435 [m4_ifdef([b4_symbol($1, number)],
436           [__b4_symbol(m4_indir([b4_symbol($1, number)]), $2)],
437           [__b4_symbol([$1], [$2])])])
440 # b4_symbol_token_kind(NUM)
441 # -------------------------
442 # The token kind of this symbol.
443 m4_define([b4_symbol_token_kind],
444 [b4_percent_define_get([api.token.prefix])dnl
445 _b4_symbol([$1], [id])])
448 # b4_symbol_kind_base(NUM)
449 # ------------------------
450 # Build the name of the kind of this symbol.  It must always exist,
451 # otherwise some symbols might not be represented in the enum, which
452 # might be compiled into too small a type to contain all the symbol
453 # numbers.
454 m4_define([b4_symbol_prefix], [b4_percent_define_get([api.symbol.prefix])])
455 m4_define([b4_symbol_kind_base],
456 [b4_percent_define_get([api.symbol.prefix])dnl
457 m4_case([$1],
458   [-2],                             [[YYEMPTY]],
459   [0],                              [[YYEOF]],
460   [1],                              [[YYerror]],
461   [2],                              [[YYUNDEF]],
462   [m4_case(b4_symbol([$1], [tag]),
463       [$accept],                    [[YYACCEPT]],
464       [b4_symbol_if([$1], [has_id], _b4_symbol([$1], [id]),
465                                     [m4_bpatsubst([$1-][]_b4_symbol([$1], [tag]), [[^a-zA-Z_0-9]+], [_])])])])])
468 # b4_symbol_kind(NUM)
469 # -------------------
470 # Same as b4_symbol_kind, but possibly with a prefix in some
471 # languages.  E.g., EOF's kind_base and kind are YYSYMBOL_YYEOF in C,
472 # but are S_YYEMPTY and symbol_kind::S_YYEMPTY in C++.
473 m4_copy([b4_symbol_kind_base], [b4_symbol_kind])
476 # b4_symbol_slot(NUM)
477 # -------------------
478 # The name of union member that contains the value of these symbols.
479 # Currently, we are messy, this should actually be type_tag, but type_tag
480 # has several meanings.
481 m4_define([b4_symbol_slot],
482 [m4_case(b4_percent_define_get([[api.value.type]]),
483          [union],   [b4_symbol([$1], [type_tag])],
484          [variant], [b4_symbol([$1], [type_tag])],
485          [b4_symbol([$1], [type])])])
488 # b4_symbol(NUM, FIELD)
489 # ---------------------
490 # Fetch FIELD of symbol #NUM (or "orig NUM", or "empty").  Fail if undefined.
492 # If FIELD = id, prepend the token prefix.
493 m4_define([b4_symbol],
494 [m4_if([$1], [empty], [b4_symbol([-2], [$2])],
495        [$1], [eof],   [b4_symbol([0], [$2])],
496        [$1], [error], [b4_symbol([1], [$2])],
497        [$1], [undef], [b4_symbol([2], [$2])],
498        [m4_case([$2],
499                 [id],        [b4_symbol_token_kind([$1])],
500                 [kind_base], [b4_symbol_kind_base([$1])],
501                 [kind],      [b4_symbol_kind([$1])],
502                 [slot],      [b4_symbol_slot([$1])],
503                 [_b4_symbol($@)])])])
506 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
507 # -------------------------------------------
508 # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
509 # Otherwise an error.
510 m4_define([b4_symbol_if],
511 [m4_case(b4_symbol([$1], [$2]),
512          [1], [$3],
513          [0], [$4],
514          [m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], [$2]))])])
517 # b4_symbol_tag_comment(SYMBOL-NUM)
518 # ---------------------------------
519 # Issue a comment giving the tag of symbol NUM.
520 m4_define([b4_symbol_tag_comment],
521 [b4_comment([b4_symbol([$1], [tag])])
525 # b4_symbol_action(SYMBOL-NUM, ACTION)
526 # ------------------------------------
527 # Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM.
528 m4_define([b4_symbol_action],
529 [b4_symbol_if([$1], [has_$2],
530 [b4_dollar_pushdef([(*yyvaluep)],
531                    [$1],
532                    [],
533                    [(*yylocationp)])dnl
534     _b4_symbol_case([$1])[]dnl
535 b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
536 b4_symbol([$1], [$2])
537 b4_syncline([@oline@], [@ofile@])dnl
538         break;
540 b4_dollar_popdef[]dnl
541 ])])
544 # b4_symbol_destructor(SYMBOL-NUM)
545 # b4_symbol_printer(SYMBOL-NUM)
546 # --------------------------------
547 m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])])
548 m4_define([b4_symbol_printer],    [b4_symbol_action([$1], [printer])])
551 # b4_symbol_actions(ACTION, [KIND = yykind])
552 # ------------------------------------------
553 # Emit the symbol actions for ACTION ("destructor" or "printer").
554 # Dispatch on KIND.
555 m4_define([b4_symbol_actions],
556 [m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl
557 m4_ifval(m4_defn([b4_actions_]),
558 [switch (m4_default([$2], [yykind]))
559     {
560 m4_defn([b4_actions_])[]dnl
561       default:
562         break;
563     }dnl
565 [b4_use(m4_default([$2], [yykind]));])dnl
566 m4_popdef([b4_actions_])dnl
569 # _b4_symbol_case(SYMBOL-NUM)
570 # ---------------------------
571 # Issue a "case NUM" for SYMBOL-NUM.  Ends with its EOL to make it
572 # easier to use with m4_map, but then, use []dnl to suppress the last
573 # one.
574 m4_define([_b4_symbol_case],
575 [case b4_symbol([$1], [kind]): b4_symbol_tag_comment([$1])])
579 # b4_symbol_foreach(MACRO)
580 # ------------------------
581 # Invoke MACRO(SYMBOL-NUM) for each SYMBOL-NUM.
582 m4_define([b4_symbol_foreach],
583           [m4_map([$1], m4_defn([b4_symbol_numbers]))])
585 # b4_symbol_map(MACRO)
586 # --------------------
587 # Return a list (possibly empty elements) of MACRO invoked for each
588 # SYMBOL-NUM.
589 m4_define([b4_symbol_map],
590 [m4_map_args_sep([$1(], [)], [,], b4_symbol_numbers)])
593 # b4_token_visible_if(NUM, IF-TRUE, IF-FALSE)
594 # -------------------------------------------
595 # Whether NUM denotes a token kind that has an exported definition
596 # (i.e., shows in enum yytokentype).
597 m4_define([b4_token_visible_if],
598 [b4_symbol_if([$1], [is_token],
599               [b4_symbol_if([$1], [has_id], [$2], [$3])],
600               [$3])])
603 # b4_token_has_definition(NUM)
604 # ----------------------------
605 # 1 if NUM is visible, nothing otherwise.
606 m4_define([b4_token_has_definition],
607 [b4_token_visible_if([$1], [1])])
609 # b4_any_token_visible_if([IF-TRUE], [IF-FALSE])
610 # ----------------------------------------------
611 # Whether there is a token that needs to be defined.
612 m4_define([b4_any_token_visible_if],
613 [m4_ifval(b4_symbol_foreach([b4_token_has_definition]),
614           [$1], [$2])])
617 # b4_token_format(FORMAT, NUM)
618 # ----------------------------
619 # If token NUM has a visible ID, format FORMAT with ID, USER_NUMBER.
620 m4_define([b4_token_format],
621 [b4_token_visible_if([$2],
622 [m4_format([[$1]],
623            b4_symbol([$2], [id]),
624            b4_symbol([$2], b4_api_token_raw_if([[number]], [[code]])))])])
627 # b4_last_enum_token
628 # ------------------
629 # The code of the last token visible token.
630 m4_define([_b4_last_enum_token],
631 [b4_token_visible_if([$1],
632    [m4_define([b4_last_enum_token], [$1])])])
633 b4_symbol_foreach([_b4_last_enum_token])
635 # b4_last_symbol
636 # --------------
637 # The code of the last symbol.
638 m4_define([b4_last_symbol], m4_eval(b4_tokens_number + b4_nterms_number - 1))
640 ## ------- ##
641 ## Types.  ##
642 ## ------- ##
644 # _b4_type_action(NUMS)
645 # ---------------------
646 # Run actions for the symbol NUMS that all have the same type-name.
647 # Skip NUMS that have no type-name.
649 # To specify the action to run, define b4_dollar_dollar(SYMBOL-NUM,
650 # TAG, TYPE).
651 m4_define([_b4_type_action],
652 [b4_symbol_if([$1], [has_type],
653 [m4_map([      _b4_symbol_case], [$@])[]dnl
654         b4_dollar_dollar([b4_symbol([$1], [number])],
655                          [b4_symbol([$1], [tag])],
656                          [b4_symbol([$1], [type])]);
657         break;
659 ])])
661 # b4_type_foreach(MACRO, [SEP])
662 # -----------------------------
663 # Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set.
664 m4_define([b4_type_foreach],
665           [m4_map_sep([$1], [$2], m4_defn([b4_type_names]))])
669 ## ----------- ##
670 ## Synclines.  ##
671 ## ----------- ##
673 # b4_basename(NAME)
674 # -----------------
675 # Similar to POSIX basename; the differences don't matter here.
676 # Beware that NAME is not evaluated.
677 m4_define([b4_basename],
678 [m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])])
681 # b4_syncline(LINE, FILE)dnl
682 # --------------------------
683 # Should always be following by a dnl.
685 # Emit "#line LINE FILE /* __LINE__ __FILE__ */".
686 m4_define([b4_syncline],
687 [b4_flag_if([synclines],
688 [b4_sync_start([$1], [$2])[]dnl
689 b4_sync_end([__line__], [b4_basename(m4_quote(__file__))])
690 ])])
692 # b4_sync_start(LINE, FILE)
693 # -----------------------
694 # Syncline for the new place.  Typically a directive for the compiler.
695 m4_define([b4_sync_start], [b4_comment([$2:$1])])
697 # b4_sync_end(LINE, FILE)
698 # -----------------------
699 # Syncline for the current place, which ends.  Typically a comment
700 # left for the reader.
701 m4_define([b4_sync_end],   [ b4_comment([$2:$1])]
703 # This generates dependencies on the Bison skeletons hence lots of
704 # useless 'git diff'.  This location is useless for the regular
705 # user (who does not care about the skeletons) and is actually not
706 # useful for Bison developers too (I, Akim, never used this to locate
707 # the code in skeletons that generated output).  So disable it
708 # completely.  If someone thinks this was actually useful, a %define
709 # variable should be provided to control the level of verbosity of
710 # '#line', in replacement of --no-lines.
711 m4_define([b4_sync_end])
714 # b4_user_code(USER-CODE)
715 # -----------------------
716 # Emit code from the user, ending it with synclines.
717 m4_define([b4_user_code],
719 b4_syncline([@oline@], [@ofile@])])
722 # b4_define_user_code(MACRO, COMMENT)
723 # -----------------------------------
724 # From b4_MACRO, if defined, build b4_user_MACRO that includes the synclines.
725 m4_define([b4_define_user_code],
726 [m4_define([b4_user_$1],
727            [m4_ifdef([b4_$1],
728                      [m4_ifval([$2],
729                                [b4_comment([$2])
730 ])b4_user_code([b4_$1])])])])
732 # b4_user_actions
733 # b4_user_initial_action
734 # b4_user_post_prologue
735 # b4_user_pre_prologue
736 # b4_user_union_members
737 # ----------------------
738 # Macros that issue user code, ending with synclines.
739 b4_define_user_code([actions])
740 b4_define_user_code([initial_action], [User initialization code.])
741 b4_define_user_code([post_prologue], [Second part of user prologue.])
742 b4_define_user_code([pre_prologue], [First part of user prologue.])
743 b4_define_user_code([union_members])
746 # b4_check_user_names(WHAT, USER-LIST, BISON-NAMESPACE)
747 # -----------------------------------------------------
748 # Complain if any name of type WHAT is used by the user (as recorded in
749 # USER-LIST) but is not used by Bison (as recorded by macros in the
750 # namespace BISON-NAMESPACE).
752 # USER-LIST must expand to a list specifying all user occurrences of all names
753 # of type WHAT.   Each item in the list must be a triplet specifying one
754 # occurrence: name, start boundary, and end boundary.  Empty string names are
755 # fine.  An empty list is fine.
757 # For example, to define b4_foo_user_names to be used for USER-LIST with three
758 # name occurrences and with correct quoting:
760 #   m4_define([b4_foo_user_names],
761 #             [[[[[[bar]], [[parser.y:1.7]], [[parser.y:1.16]]]],
762 #               [[[[bar]], [[parser.y:5.7]], [[parser.y:5.16]]]],
763 #               [[[[baz]], [[parser.y:8.7]], [[parser.y:8.16]]]]]])
765 # The macro BISON-NAMESPACE(bar) must be defined iff the name bar of type WHAT
766 # is used by Bison (in the front-end or in the skeleton).  Empty string names
767 # are fine, but it would be ugly for Bison to actually use one.
769 # For example, to use b4_foo_bison_names for BISON-NAMESPACE and define that
770 # the names bar and baz are used by Bison:
772 #   m4_define([b4_foo_bison_names(bar)])
773 #   m4_define([b4_foo_bison_names(baz)])
775 # To invoke b4_check_user_names with TYPE foo, with USER-LIST
776 # b4_foo_user_names, with BISON-NAMESPACE b4_foo_bison_names, and with correct
777 # quoting:
779 #   b4_check_user_names([[foo]], [b4_foo_user_names],
780 #                       [[b4_foo_bison_names]])
781 m4_define([b4_check_user_names],
782 [m4_foreach([b4_occurrence], $2,
783 [m4_pushdef([b4_occurrence], b4_occurrence)dnl
784 m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl
785 m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl
786 m4_pushdef([b4_end], m4_shift2(b4_occurrence))dnl
787 m4_ifndef($3[(]m4_quote(b4_user_name)[)],
788           [b4_complain_at([b4_start], [b4_end],
789                           [[%s '%s' is not used]],
790                           [$1], [b4_user_name])])[]dnl
791 m4_popdef([b4_occurrence])dnl
792 m4_popdef([b4_user_name])dnl
793 m4_popdef([b4_start])dnl
794 m4_popdef([b4_end])dnl
795 ])])
799 ## --------------------- ##
800 ## b4_percent_define_*.  ##
801 ## --------------------- ##
804 # b4_percent_define_use(VARIABLE)
805 # -------------------------------
806 # Declare that VARIABLE was used.
807 m4_define([b4_percent_define_use],
808 [m4_define([b4_percent_define_bison_variables(]$1[)])dnl
811 # b4_percent_define_get(VARIABLE, [DEFAULT])
812 # ------------------------------------------
813 # Mimic muscle_percent_define_get in ../src/muscle-tab.h.  That is, if
814 # the %define variable VARIABLE is defined, emit its value.  Contrary
815 # to its C counterpart, return DEFAULT otherwise.  Also, record
816 # Bison's usage of VARIABLE by defining
817 # b4_percent_define_bison_variables(VARIABLE).
819 # For example:
821 #   b4_percent_define_get([[foo]])
822 m4_define([b4_percent_define_get],
823 [b4_percent_define_use([$1])dnl
824 _b4_percent_define_ifdef([$1],
825                          [m4_indir([b4_percent_define(]$1[)])],
826                          [$2])])
828 # b4_percent_define_get_loc(VARIABLE)
829 # -----------------------------------
830 # Mimic muscle_percent_define_get_loc in ../src/muscle-tab.h exactly.  That is,
831 # if the %define variable VARIABLE is undefined, complain fatally since that's
832 # a Bison or skeleton error.  Otherwise, return its definition location in a
833 # form appropriate for the first two arguments of b4_warn_at, b4_complain_at, or
834 # b4_fatal_at.  Don't record this as a Bison usage of VARIABLE as there's no
835 # reason to suspect that the user-supplied value has yet influenced the output.
837 # For example:
839 #   b4_complain_at(b4_percent_define_get_loc([[foo]]), [[invalid foo]])
840 m4_define([b4_percent_define_get_loc],
841 [m4_ifdef([b4_percent_define_loc(]$1[)],
842           [m4_pushdef([b4_loc], m4_indir([b4_percent_define_loc(]$1[)]))dnl
843 b4_loc[]dnl
844 m4_popdef([b4_loc])],
845           [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
847 # b4_percent_define_get_kind(VARIABLE)
848 # ------------------------------------
849 # Get the kind (code, keyword, string) of VARIABLE, i.e., how its
850 # value was defined (braces, not delimiters, quotes).
852 # If the %define variable VARIABLE is undefined, complain fatally
853 # since that's a Bison or skeleton error.  Don't record this as a
854 # Bison usage of VARIABLE as there's no reason to suspect that the
855 # user-supplied value has yet influenced the output.
856 m4_define([b4_percent_define_get_kind],
857 [m4_ifdef([b4_percent_define_kind(]$1[)],
858           [m4_indir([b4_percent_define_kind(]$1[)])],
859           [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
861 # b4_percent_define_get_syncline(VARIABLE)dnl
862 # -------------------------------------------
863 # Should always be following by a dnl.
865 # Mimic muscle_percent_define_get_syncline in ../src/muscle-tab.h exactly.
866 # That is, if the %define variable VARIABLE is undefined, complain fatally
867 # since that's a Bison or skeleton error.  Otherwise, return its definition
868 # location as a b4_syncline invocation.  Don't record this as a Bison usage of
869 # VARIABLE as there's no reason to suspect that the user-supplied value has yet
870 # influenced the output.
872 # For example:
874 #   b4_percent_define_get_syncline([[foo]])
875 m4_define([b4_percent_define_get_syncline],
876 [m4_ifdef([b4_percent_define_syncline(]$1[)],
877           [m4_indir([b4_percent_define_syncline(]$1[)])],
878           [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
880 # _b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE])
881 # ------------------------------------------------------
882 # If the %define variable VARIABLE is defined, expand IF-TRUE, else expand
883 # IF-FALSE.  Don't record usage of VARIABLE.
885 # For example:
887 #   _b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]])
888 m4_define([_b4_percent_define_ifdef],
889 [m4_ifdef([b4_percent_define(]$1[)],
890           [$2],
891           [$3])])
893 # b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE])
894 # ------------------------------------------------------
895 # Mimic muscle_percent_define_ifdef in ../src/muscle-tab.h exactly.  That is,
896 # if the %define variable VARIABLE is defined, expand IF-TRUE, else expand
897 # IF-FALSE.  Also, record Bison's usage of VARIABLE by defining
898 # b4_percent_define_bison_variables(VARIABLE).
900 # For example:
902 #   b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]])
903 m4_define([b4_percent_define_ifdef],
904 [_b4_percent_define_ifdef([$1],
905                          [b4_percent_define_use([$1])$2],
906                          [$3])])
909 # b4_percent_define_check_file_complain(VARIABLE)
910 # -----------------------------------------------
911 # Warn about %define variable VARIABLE having an incorrect
912 # value.
913 m4_define([b4_percent_define_check_file_complain],
914 [b4_complain_at(b4_percent_define_get_loc([$1]),
915                 [[%%define variable '%s' requires 'none' or '"..."' values]],
916                 [$1])])
919 # b4_percent_define_check_file(MACRO, VARIABLE, DEFAULT)
920 # ------------------------------------------------------
921 # If the %define variable VARIABLE:
922 # - is undefined, then if DEFAULT is non-empty, define MACRO to DEFAULT
923 # - is a string, define MACRO to its value
924 # - is the keyword 'none', do nothing
925 # - otherwise, warn about the incorrect value.
926 m4_define([b4_percent_define_check_file],
927 [b4_percent_define_ifdef([$2],
928   [m4_case(b4_percent_define_get_kind([$2]),
929     [string],
930          [m4_define([$1], b4_percent_define_get([$2]))],
931     [keyword],
932          [m4_if(b4_percent_define_get([$2]), [none], [],
933                 [b4_percent_define_check_file_complain([$2])])],
934     [b4_percent_define_check_file_complain([$2])])
935    ],
936    [m4_ifval([$3],
937              [m4_define([$1], [$3])])])
942 ## --------- ##
943 ## Options.  ##
944 ## --------- ##
947 # b4_percent_define_flag_if(VARIABLE, IF-TRUE, [IF-FALSE])
948 # --------------------------------------------------------
949 # Mimic muscle_percent_define_flag_if in ../src/muscle-tab.h exactly.  That is,
950 # if the %define variable VARIABLE is defined to "" or "true", expand IF-TRUE.
951 # If it is defined to "false", expand IF-FALSE.  Complain if it is undefined
952 # (a Bison or skeleton error since the default value should have been set
953 # already) or defined to any other value (possibly a user error).  Also, record
954 # Bison's usage of VARIABLE by defining
955 # b4_percent_define_bison_variables(VARIABLE).
957 # For example:
959 #   b4_percent_define_flag_if([[foo]], [[it's true]], [[it's false]])
960 m4_define([b4_percent_define_flag_if],
961 [b4_percent_define_ifdef([$1],
962   [m4_case(b4_percent_define_get([$1]),
963            [], [$2], [true], [$2], [false], [$3],
964            [m4_expand_once([b4_complain_at(b4_percent_define_get_loc([$1]),
965                                            [[invalid value for %%define Boolean variable '%s']],
966                                            [$1])],
967                            [[b4_percent_define_flag_if($1)]])])],
968   [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
971 # b4_percent_define_default(VARIABLE, DEFAULT, [KIND = keyword])
972 # --------------------------------------------------------------
973 # Mimic muscle_percent_define_default in ../src/muscle-tab.h exactly.  That is,
974 # if the %define variable VARIABLE is undefined, set its value to DEFAULT.
975 # Don't record this as a Bison usage of VARIABLE as there's no reason to
976 # suspect that the value has yet influenced the output.
978 # For example:
980 #   b4_percent_define_default([[foo]], [[default value]])
981 m4_define([_b4_percent_define_define],
982 [m4_define([b4_percent_define(]$1[)], [$2])dnl
983 m4_define([b4_percent_define_kind(]$1[)],
984           [m4_default([$3], [keyword])])dnl
985 m4_define([b4_percent_define_loc(]$1[)],
986           [[[[<skeleton default value>:-1.-1]],
987             [[<skeleton default value>:-1.-1]]]])dnl
988 m4_define([b4_percent_define_syncline(]$1[)], [[]])])
990 m4_define([b4_percent_define_default],
991 [_b4_percent_define_ifdef([$1], [],
992                           [_b4_percent_define_define($@)])])
995 # b4_percent_define_if_define(NAME, [VARIABLE = NAME])
996 # ----------------------------------------------------
997 # Define b4_NAME_if that executes its $1 or $2 depending whether
998 # VARIABLE was %defined.  The characters '.' and `-' in VARIABLE are mapped
999 # to '_'.
1000 m4_define([_b4_percent_define_if_define],
1001 [m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]),
1002            [b4_percent_define_default([m4_default([$2], [$1])], [[false]])dnl
1003 b4_percent_define_flag_if(m4_default([$2], [$1]),
1004                                      [$3], [$4])])])
1006 m4_define([b4_percent_define_if_define],
1007 [_b4_percent_define_if_define([$1], [$2], $[1], $[2])])
1010 # b4_percent_define_check_kind(VARIABLE, KIND, [DIAGNOSTIC = complain])
1011 # ---------------------------------------------------------------------
1012 m4_define([b4_percent_define_check_kind],
1013 [_b4_percent_define_ifdef([$1],
1014   [m4_if(b4_percent_define_get_kind([$1]), [$2], [],
1015     [b4_error([m4_default([$3], [complain])],
1016               b4_percent_define_get_loc([$1]),
1017               [m4_case([$2],
1018                  [code],    [[%%define variable '%s' requires '{...}' values]],
1019                  [keyword], [[%%define variable '%s' requires keyword values]],
1020                  [string],  [[%%define variable '%s' requires '"..."' values]])],
1021               [$1])])])dnl
1025 # b4_percent_define_check_values(VALUES)
1026 # --------------------------------------
1027 # Mimic muscle_percent_define_check_values in ../src/muscle-tab.h exactly
1028 # except that the VALUES structure is more appropriate for M4.  That is, VALUES
1029 # is a list of sublists of strings.  For each sublist, the first string is the
1030 # name of a %define variable, and all remaining strings in that sublist are the
1031 # valid values for that variable.  Complain if such a variable is undefined (a
1032 # Bison error since the default value should have been set already) or defined
1033 # to any other value (possibly a user error).  Don't record this as a Bison
1034 # usage of the variable as there's no reason to suspect that the value has yet
1035 # influenced the output.
1037 # For example:
1039 #   b4_percent_define_check_values([[[[foo]], [[foo-value1]], [[foo-value2]]]],
1040 #                                  [[[[bar]], [[bar-value1]]]])
1041 m4_define([b4_percent_define_check_values],
1042 [m4_foreach([b4_sublist], m4_quote($@),
1043             [_b4_percent_define_check_values(b4_sublist)])])
1045 m4_define([_b4_percent_define_check_values],
1046 [_b4_percent_define_ifdef([$1],
1047   [b4_percent_define_check_kind(]$1[, [keyword], [deprecated])dnl
1048    m4_pushdef([b4_good_value], [0])dnl
1049    m4_if($#, 1, [],
1050          [m4_foreach([b4_value], m4_dquote(m4_shift($@)),
1051                      [m4_if(m4_indir([b4_percent_define(]$1[)]), b4_value,
1052                             [m4_define([b4_good_value], [1])])])])dnl
1053    m4_if(b4_good_value, [0],
1054          [b4_complain_at(b4_percent_define_get_loc([$1]),
1055                          [[invalid value for %%define variable '%s': '%s']],
1056                          [$1],
1057                          m4_dquote(m4_indir([b4_percent_define(]$1[)])))
1058           m4_foreach([b4_value], m4_dquote(m4_shift($@)),
1059                      [b4_error([[note]], b4_percent_define_get_loc([$1]), []
1060                                      [[accepted value: '%s']],
1061                                      m4_dquote(b4_value))])])dnl
1062    m4_popdef([b4_good_value])],
1063   [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
1065 # b4_percent_code_get([QUALIFIER])
1066 # --------------------------------
1067 # If any %code blocks for QUALIFIER are defined, emit them beginning with a
1068 # comment and ending with synclines and a newline.  If QUALIFIER is not
1069 # specified or empty, do this for the unqualified %code blocks.  Also, record
1070 # Bison's usage of QUALIFIER (if specified) by defining
1071 # b4_percent_code_bison_qualifiers(QUALIFIER).
1073 # For example, to emit any unqualified %code blocks followed by any %code
1074 # blocks for the qualifier foo:
1076 #   b4_percent_code_get
1077 #   b4_percent_code_get([[foo]])
1078 m4_define([b4_percent_code_get],
1079 [m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl
1080 m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl
1081 m4_ifdef(b4_macro_name,
1082 [b4_comment(m4_if([$#], [0], [[[Unqualified %code blocks.]]],
1083                   [[["%code ]$1[" blocks.]]]))
1084 b4_user_code([m4_indir(b4_macro_name)])])dnl
1085 m4_popdef([b4_macro_name])])
1087 # b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE])
1088 # -----------------------------------------------------
1089 # If any %code blocks for QUALIFIER (or unqualified %code blocks if
1090 # QUALIFIER is empty) are defined, expand IF-TRUE, else expand IF-FALSE.
1091 # Also, record Bison's usage of QUALIFIER (if specified) by defining
1092 # b4_percent_code_bison_qualifiers(QUALIFIER).
1093 m4_define([b4_percent_code_ifdef],
1094 [m4_ifdef([b4_percent_code(]$1[)],
1095           [m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])$2],
1096           [$3])])
1099 ## ------------------ ##
1100 ## Common variables.  ##
1101 ## ------------------ ##
1104 # b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
1105 # b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT])
1106 # b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT])
1107 # ----------------------------------------------------------
1108 b4_percent_define_if_define([api.token.raw])
1109 b4_percent_define_if_define([token_ctor], [api.token.constructor])
1110 b4_percent_define_if_define([locations])     # Whether locations are tracked.
1111 b4_percent_define_if_define([parse.assert])
1112 b4_percent_define_if_define([parse.trace])
1113 b4_percent_define_if_define([posix])
1116 # b4_bison_locations_if([IF-TRUE])
1117 # --------------------------------
1118 # Expand IF-TRUE if using locations, and using the default location
1119 # type.
1120 m4_define([b4_bison_locations_if],
1121 [b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])])
1125 # %define parse.error "(custom|detailed|simple|verbose)"
1126 # ------------------------------------------------------
1127 b4_percent_define_default([[parse.error]], [[simple]])
1128 b4_percent_define_check_values([[[[parse.error]],
1129                                  [[custom]], [[detailed]], [[simple]], [[verbose]]]])
1131 # b4_parse_error_case(CASE1, THEN1, CASE2, THEN2, ..., ELSE)
1132 # ----------------------------------------------------------
1133 m4_define([b4_parse_error_case],
1134 [m4_case(b4_percent_define_get([[parse.error]]), $@)])
1136 # b4_parse_error_bmatch(PATTERN1, THEN1, PATTERN2, THEN2, ..., ELSE)
1137 # ------------------------------------------------------------------
1138 m4_define([b4_parse_error_bmatch],
1139 [m4_bmatch(b4_percent_define_get([[parse.error]]), $@)])
1143 # b4_union_if([IF-UNION-ARE-USED], [IF-NOT])
1144 # b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT])
1145 # ----------------------------------------------
1146 # Depend on whether api.value.type is union, or variant.
1147 m4_define([b4_union_flag],   [[0]])
1148 m4_define([b4_variant_flag], [[0]])
1149 b4_percent_define_ifdef([[api.value.type]],
1150    [m4_case(b4_percent_define_get_kind([[api.value.type]]), [keyword],
1151             [m4_case(b4_percent_define_get([[api.value.type]]),
1152                      [union],   [m4_define([b4_union_flag],   [[1]])],
1153                      [variant], [m4_define([b4_variant_flag], [[1]])])])])
1154 b4_define_flag_if([union])
1155 b4_define_flag_if([variant])
1158 ## ----------------------------------------------------------- ##
1159 ## After processing the skeletons, check that all the user's   ##
1160 ## %define variables and %code qualifiers were used by Bison.  ##
1161 ## ----------------------------------------------------------- ##
1163 m4_define([b4_check_user_names_wrap],
1164 [m4_ifdef([b4_percent_]$1[_user_]$2[s],
1165           [b4_check_user_names([[%]$1 $2],
1166                                [b4_percent_]$1[_user_]$2[s],
1167                                [[b4_percent_]$1[_bison_]$2[s]])])])
1169 m4_wrap_lifo([
1170 b4_check_user_names_wrap([[define]], [[variable]])
1171 b4_check_user_names_wrap([[code]], [[qualifier]])
1175 ## ---------------- ##
1176 ## Default values.  ##
1177 ## ---------------- ##
1179 # m4_define_default([b4_lex_param], [])   dnl breaks other skeletons
1180 m4_define_default([b4_epilogue], [])
1181 m4_define_default([b4_parse_param], [])
1183 # The initial column and line.
1184 m4_define_default([b4_location_initial_column], [1])
1185 m4_define_default([b4_location_initial_line],   [1])
1188 ## --------------- ##
1189 ## Sanity checks.  ##
1190 ## --------------- ##
1192 # api.location.type={...} (C, C++ and Java).
1193 b4_percent_define_check_kind([api.location.type], [code], [deprecated])
1195 # api.position.type={...} (Java).
1196 b4_percent_define_check_kind([api.position.type], [code], [deprecated])
1198 # api.prefix >< %name-prefix.
1199 b4_percent_define_check_kind([api.prefix], [code], [deprecated])
1200 b4_percent_define_ifdef([api.prefix],
1201 [m4_ifdef([b4_prefix],
1202 [b4_complain_at(b4_percent_define_get_loc([api.prefix]),
1203                 [['%s' and '%s' cannot be used together]],
1204                 [%name-prefix],
1205                 [%define api.prefix])])])
1207 # api.token.prefix={...}
1208 # Make it a warning for those who used betas of Bison 3.0.
1209 b4_percent_define_check_kind([api.token.prefix], [code], [deprecated])
1211 # api.value.type >< %union.
1212 b4_percent_define_ifdef([api.value.type],
1213 [m4_ifdef([b4_union_members],
1214 [b4_complain_at(b4_percent_define_get_loc([api.value.type]),
1215                 [['%s' and '%s' cannot be used together]],
1216                 [%union],
1217                 [%define api.value.type])])])
1219 # api.value.type=union >< %yacc.
1220 b4_percent_define_ifdef([api.value.type],
1221 [m4_if(b4_percent_define_get([api.value.type]), [union],
1222 [b4_yacc_if(dnl
1223 [b4_complain_at(b4_percent_define_get_loc([api.value.type]),
1224                 [['%s' and '%s' cannot be used together]],
1225                 [%yacc],
1226                 [%define api.value.type "union"])])])])
1228 # api.value.union.name.
1229 b4_percent_define_check_kind([api.value.union.name], [keyword])
1231 # parse.error (custom|detailed) >< token-table.
1232 b4_token_table_if(
1233 [b4_parse_error_bmatch([custom\|detailed],
1234 [b4_complain_at(b4_percent_define_get_loc([parse.error]),
1235                 [['%s' and '%s' cannot be used together]],
1236                 [%token-table],
1237                 [%define parse.error (custom|detailed)])])])