]>
Commit | Line | Data |
---|---|---|
08af01c2 | 1 | -*- Autoconf -*- |
90b9908d PB |
2 | |
3 | # Language-independent M4 Macros for Bison. | |
7d424de1 | 4 | |
7d6bad19 | 5 | # Copyright (C) 2002, 2004-2013 Free Software Foundation, Inc. |
90b9908d | 6 | |
f16b0819 | 7 | # This program is free software: you can redistribute it and/or modify |
90b9908d | 8 | # it under the terms of the GNU General Public License as published by |
f16b0819 | 9 | # the Free Software Foundation, either version 3 of the License, or |
90b9908d | 10 | # (at your option) any later version. |
f16b0819 | 11 | # |
90b9908d PB |
12 | # This program is distributed in the hope that it will be useful, |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
f16b0819 | 16 | # |
90b9908d | 17 | # You should have received a copy of the GNU General Public License |
f16b0819 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
90b9908d PB |
19 | |
20 | ||
21 | ## ---------------- ## | |
22 | ## Identification. ## | |
23 | ## ---------------- ## | |
24 | ||
a9ce3f54 AD |
25 | # b4_copyright(TITLE, [YEARS]) |
26 | # ---------------------------- | |
27 | # If YEARS are not defined, use b4_copyright_years. | |
90b9908d PB |
28 | m4_define([b4_copyright], |
29 | [b4_comment([A Bison parser, made by GNU Bison b4_version.]) | |
30 | ||
31 | b4_comment([$1 | |
32 | ||
a9ce3f54 AD |
33 | ]m4_dquote(m4_text_wrap([Copyright (C) |
34 | ]m4_ifval([$2], [[$2]], [m4_defn([b4_copyright_years])])[ | |
35 | Free Software Foundation, Inc.]))[ | |
90b9908d | 36 | |
f16b0819 | 37 | This program is free software: you can redistribute it and/or modify |
90b9908d | 38 | it under the terms of the GNU General Public License as published by |
f16b0819 PE |
39 | the Free Software Foundation, either version 3 of the License, or |
40 | (at your option) any later version. | |
90b9908d PB |
41 | |
42 | This program is distributed in the hope that it will be useful, | |
43 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
44 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
45 | GNU General Public License for more details. | |
46 | ||
47 | You should have received a copy of the GNU General Public License | |
f16b0819 | 48 | along with this program. If not, see <http://www.gnu.org/licenses/>.]) |
90b9908d PB |
49 | |
50 | b4_comment([As a special exception, you may create a larger work that contains | |
51 | part or all of the Bison parser skeleton and distribute that work | |
52 | under terms of your choice, so long as that work isn't itself a | |
53 | parser generator using the skeleton or a modified version thereof | |
54 | as a parser skeleton. Alternatively, if you modify or redistribute | |
55 | the parser skeleton itself, you may (at your option) remove this | |
56 | special exception, which will cause the skeleton and the resulting | |
57 | Bison output files to be licensed under the GNU General Public | |
58 | License without this special exception. | |
59 | ||
60 | This special exception was added by the Free Software Foundation in | |
61 | version 2.2 of Bison.])]) | |
62 | ||
63 | ||
1c7ec959 AD |
64 | ## -------- ## |
65 | ## Output. ## | |
66 | ## -------- ## | |
67 | ||
68 | # b4_output_begin(FILE) | |
69 | # --------------------- | |
70 | # Enable output, i.e., send to diversion 0, expand after "#", and | |
71 | # generate the tag to output into FILE. Must be followed by EOL. | |
72 | m4_define([b4_output_begin], | |
73 | [m4_changecom() | |
74 | m4_divert_push(0)dnl | |
75 | @output(m4_unquote([$1])@)@dnl | |
76 | ]) | |
77 | ||
78 | ||
79 | # b4_output_end() | |
80 | # --------------- | |
81 | # Output nothing, restore # as comment character (no expansions after #). | |
82 | m4_define([b4_output_end], | |
83 | [m4_divert_pop(0) | |
84 | m4_changecom([#]) | |
85 | ]) | |
86 | ||
87 | ||
dde95ca4 AD |
88 | # b4_divert_kill(CODE) |
89 | # -------------------- | |
90 | # Expand CODE for its side effects, discard its output. | |
91 | m4_define([b4_divert_kill], | |
92 | [m4_divert_text([KILL], [$1])]) | |
93 | ||
94 | ||
95 | # b4_define_silent(MACRO, CODE) | |
96 | # ----------------------------- | |
97 | # Same as m4_define, but throw away the expansion of CODE. | |
98 | m4_define([b4_define_silent], | |
99 | [m4_define([$1], [b4_divert_kill([$2])])]) | |
100 | ||
101 | ||
08af01c2 JD |
102 | ## ---------------- ## |
103 | ## Error handling. ## | |
104 | ## ---------------- ## | |
105 | ||
7dc4a694 JD |
106 | # The following error handling macros print error directives that should not |
107 | # become arguments of other macro invocations since they would likely then be | |
108 | # mangled. Thus, they print to stdout directly. | |
109 | ||
110 | # b4_cat(TEXT) | |
111 | # ------------ | |
112 | # Write TEXT to stdout. Precede the final newline with an @ so that it's | |
113 | # escaped. For example: | |
114 | # | |
115 | # b4_cat([[@complain(invalid input@)]]) | |
116 | m4_define([b4_cat], | |
117 | [m4_syscmd([cat <<'_m4eof' | |
118 | ]m4_bpatsubst(m4_dquote($1), [_m4eof], [_m4@`eof])[@ | |
66f0441d JD |
119 | _m4eof |
120 | ])dnl | |
7dc4a694 JD |
121 | m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write to stdout])])]) |
122 | ||
c4e3a162 AD |
123 | # b4_error(KIND, START, END, FORMAT, [ARG1], [ARG2], ...) |
124 | # ------------------------------------------------------- | |
125 | # Write @KIND(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout. | |
7dc4a694 JD |
126 | # |
127 | # For example: | |
128 | # | |
c4e3a162 AD |
129 | # b4_error([[complain]], [[input.y:2.3]], [[input.y:5.4]], |
130 | # [[invalid %s]], [[foo]]) | |
08af01c2 | 131 | m4_define([b4_error], |
0505df0c | 132 | [b4_cat([[@complain][(]$1[@,]$2[@,]$3[@,]$4[]]dnl |
7dc4a694 JD |
133 | [m4_if([$#], [4], [], |
134 | [m4_foreach([b4_arg], | |
135 | m4_dquote(m4_shift(m4_shift(m4_shift(m4_shift($@))))), | |
136 | [[@,]b4_arg])])[@)]])]) | |
3fc65ead | 137 | |
08af01c2 | 138 | # b4_warn(FORMAT, [ARG1], [ARG2], ...) |
7eb8a0bc | 139 | # ------------------------------------ |
7dc4a694 JD |
140 | # Write @warn(FORMAT@,ARG1@,ARG2@,...@) to stdout. |
141 | # | |
142 | # For example: | |
143 | # | |
4aa9d1ff | 144 | # b4_warn([[invalid value for '%s': %s]], [[foo]], [[3]]) |
08af01c2 JD |
145 | # |
146 | # As a simple test suite, this: | |
147 | # | |
7dc4a694 | 148 | # m4_divert(-1) |
08af01c2 JD |
149 | # m4_define([asdf], [ASDF]) |
150 | # m4_define([fsa], [FSA]) | |
151 | # m4_define([fdsa], [FDSA]) | |
c4e3a162 AD |
152 | # b4_warn_at([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]]) |
153 | # b4_warn_at([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]]) | |
154 | # b4_warn_at() | |
155 | # b4_warn_at(1) | |
156 | # b4_warn_at(1, 2) | |
08af01c2 | 157 | # |
7dc4a694 | 158 | # Should produce this without newlines: |
08af01c2 | 159 | # |
c4e3a162 AD |
160 | # @warn_at([asdf), asdf]@,@,@,[fsa), fsa]@,[fdsa), fdsa]@) |
161 | # @warn(asdf), asdf@,@,@,fsa), fsa@,fdsa), fdsa@) | |
08af01c2 | 162 | # @warn(@) |
08af01c2 JD |
163 | # @warn(1@) |
164 | # @warn(1@,2@) | |
165 | m4_define([b4_warn], | |
c4e3a162 | 166 | [b4_error([[warn]], [], [], $@)]) |
08af01c2 | 167 | |
3fc65ead | 168 | # b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...) |
7eb8a0bc | 169 | # --------------------------------------------------- |
7dc4a694 JD |
170 | # Write @warn(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout. |
171 | # | |
172 | # For example: | |
173 | # | |
174 | # b4_warn_at([[input.y:2.3]], [[input.y:5.4]], [[invalid %s]], [[foo]]) | |
3fc65ead | 175 | m4_define([b4_warn_at], |
c4e3a162 | 176 | [b4_error([[warn]], $@)]) |
3fc65ead | 177 | |
08af01c2 | 178 | # b4_complain(FORMAT, [ARG1], [ARG2], ...) |
7eb8a0bc | 179 | # ---------------------------------------- |
c4e3a162 | 180 | # Bounce to b4_complain_at. |
08af01c2 | 181 | # |
7dc4a694 | 182 | # See b4_warn example. |
08af01c2 | 183 | m4_define([b4_complain], |
c4e3a162 | 184 | [b4_error([[complain]], [], [], $@)]) |
08af01c2 | 185 | |
3fc65ead | 186 | # b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...) |
7eb8a0bc | 187 | # ------------------------------------------------------- |
7dc4a694 JD |
188 | # Write @complain(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout. |
189 | # | |
190 | # See b4_warn_at example. | |
3fc65ead | 191 | m4_define([b4_complain_at], |
c4e3a162 | 192 | [b4_error([[complain]], $@)]) |
3fc65ead | 193 | |
08af01c2 | 194 | # b4_fatal(FORMAT, [ARG1], [ARG2], ...) |
7eb8a0bc | 195 | # ------------------------------------- |
c4e3a162 | 196 | # Bounce to b4_fatal_at. |
08af01c2 | 197 | # |
7dc4a694 | 198 | # See b4_warn example. |
08af01c2 | 199 | m4_define([b4_fatal], |
c4e3a162 | 200 | [b4_error([[fatal]], [], [], $@)dnl |
7dc4a694 | 201 | m4_exit(1)]) |
08af01c2 | 202 | |
3fc65ead | 203 | # b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...) |
7eb8a0bc | 204 | # ---------------------------------------------------- |
7dc4a694 JD |
205 | # Write @fatal(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout and exit. |
206 | # | |
207 | # See b4_warn_at example. | |
3fc65ead | 208 | m4_define([b4_fatal_at], |
c4e3a162 | 209 | [b4_error([[fatal]], $@)dnl |
7dc4a694 | 210 | m4_exit(1)]) |
3fc65ead | 211 | |
08af01c2 | 212 | |
90b9908d PB |
213 | ## ------------ ## |
214 | ## Data Types. ## | |
215 | ## ------------ ## | |
216 | ||
217 | # b4_ints_in(INT1, INT2, LOW, HIGH) | |
218 | # --------------------------------- | |
219 | # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise. | |
220 | m4_define([b4_ints_in], | |
221 | [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])]) | |
222 | ||
223 | ||
bd187d7b AD |
224 | # b4_subtract(LHS, RHS) |
225 | # --------------------- | |
226 | # Evaluate LHS - RHS if they are integer literals, otherwise expand | |
227 | # to (LHS) - (RHS). | |
228 | m4_define([b4_subtract], | |
229 | [m4_bmatch([$1$2], [^[0123456789]*$], | |
230 | [m4_eval([$1 - $2])], | |
231 | [($1) - ($2)])]) | |
232 | ||
710c4a65 AD |
233 | # b4_join(ARG1, ...) |
234 | # _b4_join(ARG1, ...) | |
e0c653e7 AD |
235 | # ------------------- |
236 | # Join with comma, skipping empty arguments. | |
710c4a65 AD |
237 | # b4_join calls itself recursively until it sees the first non-empty |
238 | # argument, then calls _b4_join which prepends each non-empty argument | |
e0c653e7 | 239 | # with a comma. |
710c4a65 | 240 | m4_define([b4_join], |
e0c653e7 AD |
241 | [m4_if([$#$1], |
242 | [1], [], | |
243 | [m4_ifval([$1], | |
244 | [$1[]_$0(m4_shift($@))], | |
245 | [$0(m4_shift($@))])])]) | |
246 | ||
710c4a65 | 247 | # _b4_join(ARGS1, ...) |
e0c653e7 | 248 | # -------------------- |
710c4a65 | 249 | m4_define([_b4_join], |
e0c653e7 AD |
250 | [m4_if([$#$1], |
251 | [1], [], | |
252 | [m4_ifval([$1], [, $1])[]$0(m4_shift($@))])]) | |
253 | ||
254 | ||
255 | ||
90b9908d | 256 | |
ba206cf4 AD |
257 | # b4_integral_parser_tables_map(MACRO) |
258 | # ------------------------------------- | |
0991e29b AD |
259 | # Map MACRO on all the integral tables. MACRO is expected to have |
260 | # the signature MACRO(TABLE-NAME, CONTENT, COMMENT). | |
ba206cf4 | 261 | m4_define([b4_integral_parser_tables_map], |
0991e29b AD |
262 | [$1([pact], [b4_pact], |
263 | [[YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing | |
264 | STATE-NUM.]]) | |
265 | ||
266 | $1([defact], [b4_defact], | |
6f0a6f27 AD |
267 | [[YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. |
268 | Performed when YYTABLE does not specify something else to do. Zero | |
269 | means the default is an error.]]) | |
0991e29b AD |
270 | |
271 | $1([pgoto], [b4_pgoto], [[YYPGOTO[NTERM-NUM].]]) | |
272 | ||
273 | $1([defgoto], [b4_defgoto], [[YYDEFGOTO[NTERM-NUM].]]) | |
274 | ||
275 | $1([table], [b4_table], | |
6f0a6f27 | 276 | [[YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If |
e672a4ba | 277 | positive, shift that token. If negative, reduce the rule whose |
aa0cb40d | 278 | number is the opposite. If YYTABLE_NINF, syntax error.]]) |
0991e29b AD |
279 | |
280 | $1([check], [b4_check]) | |
281 | ||
282 | $1([stos], [b4_stos], | |
6f0a6f27 | 283 | [[YYSTOS[STATE-NUM] -- The (internal number of the) accessing |
0991e29b AD |
284 | symbol of state STATE-NUM.]]) |
285 | ||
286 | $1([r1], [b4_r1], | |
287 | [[YYR1[YYN] -- Symbol number of symbol that rule YYN derives.]]) | |
288 | ||
289 | $1([r2], [b4_r2], | |
6f0a6f27 | 290 | [[YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.]]) |
0991e29b AD |
291 | ]) |
292 | ||
293 | ||
ba206cf4 AD |
294 | # b4_parser_tables_declare |
295 | # b4_parser_tables_define | |
296 | # ------------------------ | |
0991e29b | 297 | # Define/declare the (deterministic) parser tables. |
ba206cf4 AD |
298 | m4_define([b4_parser_tables_declare], |
299 | [b4_integral_parser_tables_map([b4_integral_parser_table_declare])]) | |
0991e29b | 300 | |
ba206cf4 AD |
301 | m4_define([b4_parser_tables_define], |
302 | [b4_integral_parser_tables_map([b4_integral_parser_table_define])]) | |
0991e29b AD |
303 | |
304 | ||
305 | ||
90b9908d PB |
306 | ## ------------------ ## |
307 | ## Decoding options. ## | |
308 | ## ------------------ ## | |
309 | ||
310 | # b4_flag_if(FLAG, IF-TRUE, IF-FALSE) | |
311 | # ----------------------------------- | |
312 | # Run IF-TRUE if b4_FLAG_flag is 1, IF-FALSE if FLAG is 0, otherwise fail. | |
313 | m4_define([b4_flag_if], | |
314 | [m4_case(b4_$1_flag, | |
315 | [0], [$3], | |
e9690142 | 316 | [1], [$2], |
acb741cd | 317 | [m4_fatal([invalid $1 value: ]b4_$1_flag)])]) |
90b9908d PB |
318 | |
319 | ||
320 | # b4_define_flag_if(FLAG) | |
321 | # ----------------------- | |
322 | # Define "b4_FLAG_if(IF-TRUE, IF-FALSE)" that depends on the | |
323 | # value of the Boolean FLAG. | |
324 | m4_define([b4_define_flag_if], | |
325 | [_b4_define_flag_if($[1], $[2], [$1])]) | |
326 | ||
327 | # _b4_define_flag_if($1, $2, FLAG) | |
328 | # -------------------------------- | |
258cddbc | 329 | # Work around the impossibility to define macros inside macros, |
45eebca4 | 330 | # because issuing '[$1]' is not possible in M4. GNU M4 should provide |
258cddbc | 331 | # $$1 a la M5/TeX. |
90b9908d PB |
332 | m4_define([_b4_define_flag_if], |
333 | [m4_if([$1$2], $[1]$[2], [], | |
334 | [m4_fatal([$0: Invalid arguments: $@])])dnl | |
335 | m4_define([b4_$3_if], | |
336 | [b4_flag_if([$3], [$1], [$2])])]) | |
337 | ||
338 | ||
339 | # b4_FLAG_if(IF-TRUE, IF-FALSE) | |
340 | # ----------------------------- | |
341 | # Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise. | |
e9690142 JD |
342 | b4_define_flag_if([defines]) # Whether headers are requested. |
343 | b4_define_flag_if([glr]) # Whether a GLR parser is requested. | |
344 | b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled. | |
258cddbc | 345 | b4_define_flag_if([token_table]) # Whether yytoken_table is demanded. |
e9690142 | 346 | b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. |
90b9908d PB |
347 | |
348 | ||
cf6fb222 AD |
349 | ## --------- ## |
350 | ## Symbols. ## | |
351 | ## --------- ## | |
352 | ||
e3990e3c AD |
353 | # In order to unify the handling of the various aspects of symbols |
354 | # (tag, type_name, whether terminal, etc.), bison.exe defines one | |
355 | # macro per (token, field), where field can has_id, id, etc.: see | |
356 | # src/output.c:prepare_symbols_definitions(). | |
357 | # | |
3fd1d6b2 AD |
358 | # The various FIELDS are: |
359 | # | |
360 | # - has_id: 0 or 1. | |
361 | # Whether the symbol has an id. | |
362 | # - id: string | |
363 | # If has_id, the id. Guaranteed to be usable as a C identifier. | |
6574576c | 364 | # Prefixed by api.token.prefix if defined. |
3fd1d6b2 AD |
365 | # - tag: string. |
366 | # A representat of the symbol. Can be 'foo', 'foo.id', '"foo"' etc. | |
367 | # - user_number: integer | |
368 | # The assigned (external) number as used by yylex. | |
369 | # - is_token: 0 or 1 | |
370 | # Whether this is a terminal symbol. | |
371 | # - number: integer | |
372 | # The internalized number (used after yytranslate). | |
373 | # - has_type: 0, 1 | |
374 | # Whether has a semantic value. | |
6574576c AD |
375 | # - type_tag: string |
376 | # When api.value.type=union, the generated name for the union member. | |
377 | # yytype_INT etc. for symbols that has_id, otherwise yytype_1 etc. | |
3fd1d6b2 AD |
378 | # - type |
379 | # If it has a semantic value, its type tag, or, if variant are used, | |
380 | # its type. | |
6574576c | 381 | # In the case of api.value.type=union, type is the real type (e.g. int). |
3fd1d6b2 AD |
382 | # - has_printer: 0, 1 |
383 | # - printer: string | |
384 | # - printer_file: string | |
385 | # - printer_line: integer | |
386 | # If the symbol has a printer, everything about it. | |
387 | # - has_destructor, destructor, destructor_file, destructor_line | |
388 | # Likewise. | |
389 | # | |
e3990e3c AD |
390 | # The following macros provide access to these values. |
391 | ||
cf6fb222 AD |
392 | # b4_symbol_(NUM, FIELD) |
393 | # ---------------------- | |
394 | # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if | |
395 | # undefined. | |
396 | m4_define([b4_symbol_], | |
397 | [m4_indir([b4_symbol($1, $2)])]) | |
398 | ||
399 | ||
400 | # b4_symbol(NUM, FIELD) | |
401 | # --------------------- | |
402 | # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if | |
3fd1d6b2 | 403 | # undefined. If FIELD = id, prepend the token prefix. |
cf6fb222 AD |
404 | m4_define([b4_symbol], |
405 | [m4_case([$2], | |
2a6b66c5 | 406 | [id], [m4_do([b4_percent_define_get([api.token.prefix])], |
cf6fb222 AD |
407 | [b4_symbol_([$1], [id])])], |
408 | [b4_symbol_($@)])]) | |
409 | ||
410 | ||
411 | # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE) | |
412 | # ------------------------------------------- | |
413 | # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE. | |
414 | # Otherwise an error. | |
415 | m4_define([b4_symbol_if], | |
416 | [m4_case(b4_symbol([$1], [$2]), | |
417 | [1], [$3], | |
418 | [0], [$4], | |
419 | [m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], [$2]))])]) | |
420 | ||
421 | ||
3fd1d6b2 AD |
422 | # b4_symbol_tag_comment(SYMBOL-NUM) |
423 | # --------------------------------- | |
424 | # Issue a comment giving the tag of symbol NUM. | |
425 | m4_define([b4_symbol_tag_comment], | |
426 | [b4_comment([b4_symbol([$1], [tag])]) | |
427 | ]) | |
428 | ||
429 | ||
3bb21113 AD |
430 | # b4_symbol_action_location(SYMBOL-NUM, KIND) |
431 | # ------------------------------------------- | |
432 | # Report the location of the KIND action as FILE:LINE. | |
433 | m4_define([b4_symbol_action_location], | |
434 | [b4_symbol([$1], [$2_file]):b4_syncline([b4_symbol([$1], [$2_line])])]) | |
435 | ||
436 | ||
cf6fb222 AD |
437 | # b4_symbol_action(SYMBOL-NUM, KIND) |
438 | # ---------------------------------- | |
439 | # Run the action KIND (destructor or printer) for SYMBOL-NUM. | |
440 | # Same as in C, but using references instead of pointers. | |
441 | m4_define([b4_symbol_action], | |
442 | [b4_symbol_if([$1], [has_$2], | |
4323e0da AD |
443 | [b4_dollar_pushdef([(*yyvaluep)], |
444 | b4_symbol_if([$1], [has_type], | |
445 | [m4_dquote(b4_symbol([$1], [type]))]), | |
446 | [(*yylocationp)])dnl | |
c5ae8e85 | 447 | b4_symbol_case_([$1])[]dnl |
cf6fb222 | 448 | b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"]) |
c5ae8e85 | 449 | b4_symbol([$1], [$2]) |
cf6fb222 AD |
450 | b4_syncline([@oline@], [@ofile@]) |
451 | break; | |
452 | ||
4323e0da | 453 | b4_dollar_popdef[]dnl |
cf6fb222 AD |
454 | ])]) |
455 | ||
456 | ||
457 | # b4_symbol_destructor(SYMBOL-NUM) | |
458 | # b4_symbol_printer(SYMBOL-NUM) | |
459 | # -------------------------------- | |
460 | m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])]) | |
461 | m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])]) | |
462 | ||
463 | ||
464 | # b4_symbol_case_(SYMBOL-NUM) | |
465 | # --------------------------- | |
466 | # Issue a "case NUM" for SYMBOL-NUM. | |
467 | m4_define([b4_symbol_case_], | |
c5ae8e85 | 468 | [case b4_symbol([$1], [number]): b4_symbol_tag_comment([$1])]) |
cf6fb222 AD |
469 | ]) |
470 | ||
471 | ||
472 | # b4_symbol_foreach(MACRO) | |
473 | # ------------------------ | |
474 | # Invoke MACRO(SYMBOL-NUM) for each SYMBOL-NUM. | |
475 | m4_define([b4_symbol_foreach], | |
476 | [m4_map([$1], m4_defn([b4_symbol_numbers]))]) | |
e3990e3c AD |
477 | |
478 | # b4_symbol_map(MACRO) | |
479 | # -------------------- | |
480 | # Return a list (possibly empty elements) of MACRO invoked for each | |
481 | # SYMBOL-NUM. | |
482 | m4_define([b4_symbol_map], | |
483 | [m4_map_args_sep([$1(], [)], [,], b4_symbol_numbers)]) | |
484 | ||
485 | ||
486 | # b4_token_visible_if(NUM, IF-TRUE, IF-FALSE) | |
487 | # ------------------------------------------- | |
488 | # Whether NUM denotes a token that has an exported definition (i.e., | |
489 | # shows in enum yytokentype). | |
490 | m4_define([b4_token_visible_if], | |
491 | [b4_symbol_if([$1], [is_token], | |
492 | [b4_symbol_if([$1], [has_id], [$2], [$3])], | |
493 | [$3])]) | |
494 | ||
495 | # b4_token_has_definition(NUM) | |
496 | # ---------------------------- | |
497 | # 1 if NUM is visible, nothing otherwise. | |
498 | m4_define([b4_token_has_definition], | |
499 | [b4_token_visible_if([$1], [1])]) | |
500 | ||
501 | # b4_any_token_visible_if([IF-TRUE], [IF-FALSE]) | |
502 | # ---------------------------------------------- | |
503 | # Whether there is a token that needs to be defined. | |
504 | m4_define([b4_any_token_visible_if], | |
505 | [m4_ifval(b4_symbol_foreach([b4_token_has_definition]), | |
506 | [$1], [$2])]) | |
507 | ||
508 | ||
509 | # b4_token_format(FORMAT, NUM) | |
510 | # ---------------------------- | |
511 | m4_define([b4_token_format], | |
512 | [b4_token_visible_if([$2], | |
513 | [m4_quote(m4_format([$1], | |
514 | [b4_symbol([$2], [id])], | |
515 | [b4_symbol([$2], [user_number])]))])]) | |
cf6fb222 AD |
516 | |
517 | ||
518 | ## ------- ## | |
519 | ## Types. ## | |
520 | ## ------- ## | |
521 | ||
522 | # b4_type_action_(NUMS) | |
523 | # --------------------- | |
524 | # Run actions for the symbol NUMS that all have the same type-name. | |
525 | # Skip NUMS that have no type-name. | |
3fd1d6b2 AD |
526 | # |
527 | # To specify the action to run, define b4_dollar_dollar(NUMBER, | |
528 | # TAG, TYPE). | |
cf6fb222 AD |
529 | m4_define([b4_type_action_], |
530 | [b4_symbol_if([$1], [has_type], | |
462b243e | 531 | [m4_map([ b4_symbol_case_], [$@])[]dnl |
cf6fb222 AD |
532 | b4_dollar_dollar([b4_symbol([$1], [number])], |
533 | [b4_symbol([$1], [tag])], | |
534 | [b4_symbol([$1], [type])]); | |
e9690142 | 535 | break; |
cf6fb222 AD |
536 | |
537 | ])]) | |
538 | ||
539 | # b4_type_foreach(MACRO) | |
540 | # ---------------------- | |
541 | # Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set. | |
542 | m4_define([b4_type_foreach], | |
543 | [m4_map([$1], m4_defn([b4_type_names]))]) | |
544 | ||
545 | ||
546 | ||
90b9908d PB |
547 | ## ----------- ## |
548 | ## Synclines. ## | |
549 | ## ----------- ## | |
550 | ||
551 | # b4_basename(NAME) | |
552 | # ----------------- | |
553 | # Similar to POSIX basename; the differences don't matter here. | |
554 | # Beware that NAME is not evaluated. | |
555 | m4_define([b4_basename], | |
556 | [m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])]) | |
557 | ||
558 | ||
559 | # b4_syncline(LINE, FILE) | |
560 | # ----------------------- | |
561 | m4_define([b4_syncline], | |
fad814bd | 562 | [b4_flag_if([synclines], |
d2e3c807 AD |
563 | [b4_sync_start([$1], [$2]) b4_sync_end([__line__], |
564 | [b4_basename(m4_quote(__file__))])[]dnl | |
565 | ])]) | |
566 | ||
567 | # b4_sync_start(LINE, FILE) | |
568 | # ----------------------- | |
569 | # Syncline for the new place. Typically a directive for the compiler. | |
570 | m4_define([b4_sync_start], [b4_comment([$2:$1])]) | |
571 | ||
572 | # b4_sync_end(LINE, FILE) | |
573 | # ----------------------- | |
574 | # Syncline for the current place, which ends. Typically a comment | |
575 | # left for the reader. | |
576 | m4_define([b4_sync_end], [b4_comment([$2:$1])]) | |
90b9908d | 577 | |
90b9908d PB |
578 | |
579 | # b4_user_code(USER-CODE) | |
580 | # ----------------------- | |
581 | # Emit code from the user, ending it with synclines. | |
582 | m4_define([b4_user_code], | |
583 | [$1 | |
584 | b4_syncline([@oline@], [@ofile@])]) | |
585 | ||
586 | ||
587 | # b4_define_user_code(MACRO) | |
588 | # -------------------------- | |
589 | # From b4_MACRO, build b4_user_MACRO that includes the synclines. | |
590 | m4_define([b4_define_user_code], | |
591 | [m4_define([b4_user_$1], | |
592 | [b4_user_code([b4_$1])])]) | |
593 | ||
594 | ||
595 | # b4_user_actions | |
596 | # b4_user_initial_action | |
597 | # b4_user_post_prologue | |
136a0f76 | 598 | # b4_user_pre_prologue |
c5dbd909 | 599 | # b4_user_union_members |
90b9908d PB |
600 | # ---------------------- |
601 | # Macros that issue user code, ending with synclines. | |
602 | b4_define_user_code([actions]) | |
603 | b4_define_user_code([initial_action]) | |
604 | b4_define_user_code([post_prologue]) | |
136a0f76 | 605 | b4_define_user_code([pre_prologue]) |
c5dbd909 | 606 | b4_define_user_code([union_members]) |
90b9908d | 607 | |
1c7b7e1d | 608 | |
9611cfa2 | 609 | # b4_check_user_names(WHAT, USER-LIST, BISON-NAMESPACE) |
c6abeab1 JD |
610 | # ----------------------------------------------------- |
611 | # Complain if any name of type WHAT is used by the user (as recorded in | |
612 | # USER-LIST) but is not used by Bison (as recorded by macros in the | |
613 | # namespace BISON-NAMESPACE). | |
7eb8a0bc | 614 | # |
f8e7258f JD |
615 | # USER-LIST must expand to a list specifying all user occurrences of all names |
616 | # of type WHAT. Each item in the list must be a triplet specifying one | |
6afc30cc JD |
617 | # occurrence: name, start boundary, and end boundary. Empty string names are |
618 | # fine. An empty list is fine. | |
7eb8a0bc | 619 | # |
a4e25e1d | 620 | # For example, to define b4_foo_user_names to be used for USER-LIST with three |
6afc30cc | 621 | # name occurrences and with correct quoting: |
8e0a5e9e | 622 | # |
a4e25e1d | 623 | # m4_define([b4_foo_user_names], |
7eb8a0bc JD |
624 | # [[[[[[bar]], [[parser.y:1.7]], [[parser.y:1.16]]]], |
625 | # [[[[bar]], [[parser.y:5.7]], [[parser.y:5.16]]]], | |
626 | # [[[[baz]], [[parser.y:8.7]], [[parser.y:8.16]]]]]]) | |
1c7b7e1d | 627 | # |
9611cfa2 JD |
628 | # The macro BISON-NAMESPACE(bar) must be defined iff the name bar of type WHAT |
629 | # is used by Bison (in the front-end or in the skeleton). Empty string names | |
630 | # are fine, but it would be ugly for Bison to actually use one. | |
6afc30cc | 631 | # |
9611cfa2 JD |
632 | # For example, to use b4_foo_bison_names for BISON-NAMESPACE and define that |
633 | # the names bar and baz are used by Bison: | |
1c7b7e1d | 634 | # |
9611cfa2 JD |
635 | # m4_define([b4_foo_bison_names(bar)]) |
636 | # m4_define([b4_foo_bison_names(baz)]) | |
1c7b7e1d | 637 | # |
6afc30cc | 638 | # To invoke b4_check_user_names with TYPE foo, with USER-LIST |
9611cfa2 JD |
639 | # b4_foo_user_names, with BISON-NAMESPACE b4_foo_bison_names, and with correct |
640 | # quoting: | |
1c7b7e1d | 641 | # |
a4e25e1d | 642 | # b4_check_user_names([[foo]], [b4_foo_user_names], |
9611cfa2 | 643 | # [[b4_foo_bison_names]]) |
6afc30cc JD |
644 | m4_define([b4_check_user_names], |
645 | [m4_foreach([b4_occurrence], $2, | |
646 | [m4_pushdef([b4_occurrence], b4_occurrence)dnl | |
647 | m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl | |
648 | m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl | |
649 | m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl | |
a4e25e1d | 650 | m4_ifndef($3[(]m4_quote(b4_user_name)[)], |
c6abeab1 | 651 | [b4_complain_at([b4_start], [b4_end], |
4aa9d1ff | 652 | [[%s '%s' is not used]], |
c6abeab1 | 653 | [$1], [b4_user_name])])[]dnl |
6afc30cc JD |
654 | m4_popdef([b4_occurrence])dnl |
655 | m4_popdef([b4_user_name])dnl | |
656 | m4_popdef([b4_start])dnl | |
657 | m4_popdef([b4_end])dnl | |
658 | ])]) | |
659 | ||
67501061 AD |
660 | |
661 | ||
662 | ## --------------------- ## | |
663 | ## b4_percent_define_*. ## | |
664 | ## --------------------- ## | |
665 | ||
666 | ||
667 | # b4_percent_define_use(VARIABLE) | |
668 | # ------------------------------- | |
669 | # Declare that VARIABLE was used. | |
670 | m4_define([b4_percent_define_use], | |
671 | [m4_define([b4_percent_define_bison_variables(]$1[)])dnl | |
672 | ]) | |
673 | ||
7789b6e3 AD |
674 | # b4_percent_define_get(VARIABLE, [DEFAULT]) |
675 | # ------------------------------------------ | |
676 | # Mimic muscle_percent_define_get in ../src/muscle-tab.h. That is, if | |
677 | # the %define variable VARIABLE is defined, emit its value. Contrary | |
678 | # to its C counterpart, return DEFAULT otherwise. Also, record | |
9611cfa2 JD |
679 | # Bison's usage of VARIABLE by defining |
680 | # b4_percent_define_bison_variables(VARIABLE). | |
a4e25e1d JD |
681 | # |
682 | # For example: | |
683 | # | |
684 | # b4_percent_define_get([[foo]]) | |
685 | m4_define([b4_percent_define_get], | |
67501061 | 686 | [b4_percent_define_use([$1])dnl |
7789b6e3 AD |
687 | m4_ifdef([b4_percent_define(]$1[)], |
688 | [m4_indir([b4_percent_define(]$1[)])], | |
689 | [$2])]) | |
a4e25e1d | 690 | |
35b8730d JD |
691 | # b4_percent_define_get_loc(VARIABLE) |
692 | # ----------------------------------- | |
416a9da6 | 693 | # Mimic muscle_percent_define_get_loc in ../src/muscle-tab.h exactly. That is, |
35b8730d JD |
694 | # if the %define variable VARIABLE is undefined, complain fatally since that's |
695 | # a Bison or skeleton error. Otherwise, return its definition location in a | |
696 | # form approriate for the first two arguments of b4_warn_at, b4_complain_at, or | |
697 | # b4_fatal_at. Don't record this as a Bison usage of VARIABLE as there's no | |
698 | # reason to suspect that the user-supplied value has yet influenced the output. | |
699 | # | |
700 | # For example: | |
701 | # | |
702 | # b4_complain_at(b4_percent_define_get_loc([[foo]]), [[invalid foo]]) | |
703 | m4_define([b4_percent_define_get_loc], | |
704 | [m4_ifdef([b4_percent_define_loc(]$1[)], | |
705 | [m4_pushdef([b4_loc], m4_indir([b4_percent_define_loc(]$1[)]))dnl | |
706 | b4_loc[]dnl | |
707 | m4_popdef([b4_loc])], | |
11872a83 | 708 | [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) |
35b8730d JD |
709 | |
710 | # b4_percent_define_get_syncline(VARIABLE) | |
711 | # ---------------------------------------- | |
416a9da6 | 712 | # Mimic muscle_percent_define_get_syncline in ../src/muscle-tab.h exactly. |
35b8730d JD |
713 | # That is, if the %define variable VARIABLE is undefined, complain fatally |
714 | # since that's a Bison or skeleton error. Otherwise, return its definition | |
715 | # location as a b4_syncline invocation. Don't record this as a Bison usage of | |
716 | # VARIABLE as there's no reason to suspect that the user-supplied value has yet | |
717 | # influenced the output. | |
718 | # | |
719 | # For example: | |
720 | # | |
721 | # b4_percent_define_get_syncline([[foo]]) | |
722 | m4_define([b4_percent_define_get_syncline], | |
723 | [m4_ifdef([b4_percent_define_syncline(]$1[)], | |
724 | [m4_indir([b4_percent_define_syncline(]$1[)])], | |
11872a83 | 725 | [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) |
35b8730d | 726 | |
592d0b1e PB |
727 | # b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE]) |
728 | # ------------------------------------------------------ | |
416a9da6 | 729 | # Mimic muscle_percent_define_ifdef in ../src/muscle-tab.h exactly. That is, |
f124d423 | 730 | # if the %define variable VARIABLE is defined, expand IF-TRUE, else expand |
9611cfa2 JD |
731 | # IF-FALSE. Also, record Bison's usage of VARIABLE by defining |
732 | # b4_percent_define_bison_variables(VARIABLE). | |
733 | # | |
734 | # For example: | |
735 | # | |
736 | # b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]]) | |
592d0b1e PB |
737 | m4_define([b4_percent_define_ifdef], |
738 | [m4_ifdef([b4_percent_define(]$1[)], | |
e9690142 JD |
739 | [b4_percent_define_use([$1])$2], |
740 | [$3])]) | |
592d0b1e | 741 | |
b47b6ff7 | 742 | |
b47b6ff7 AD |
743 | ## --------- ## |
744 | ## Options. ## | |
745 | ## --------- ## | |
746 | ||
747 | ||
592d0b1e PB |
748 | # b4_percent_define_flag_if(VARIABLE, IF-TRUE, [IF-FALSE]) |
749 | # -------------------------------------------------------- | |
416a9da6 | 750 | # Mimic muscle_percent_define_flag_if in ../src/muscle-tab.h exactly. That is, |
9611cfa2 JD |
751 | # if the %define variable VARIABLE is defined to "" or "true", expand IF-TRUE. |
752 | # If it is defined to "false", expand IF-FALSE. Complain if it is undefined | |
753 | # (a Bison or skeleton error since the default value should have been set | |
754 | # already) or defined to any other value (possibly a user error). Also, record | |
755 | # Bison's usage of VARIABLE by defining | |
756 | # b4_percent_define_bison_variables(VARIABLE). | |
757 | # | |
758 | # For example: | |
759 | # | |
760 | # b4_percent_define_flag_if([[foo]], [[it's true]], [[it's false]]) | |
592d0b1e PB |
761 | m4_define([b4_percent_define_flag_if], |
762 | [b4_percent_define_ifdef([$1], | |
9611cfa2 JD |
763 | [m4_case(b4_percent_define_get([$1]), |
764 | [], [$2], [true], [$2], [false], [$3], | |
35b8730d | 765 | [m4_expand_once([b4_complain_at(b4_percent_define_get_loc([$1]), |
4aa9d1ff | 766 | [[invalid value for %%define Boolean variable '%s']], |
35b8730d JD |
767 | [$1])], |
768 | [[b4_percent_define_flag_if($1)]])])], | |
11872a83 | 769 | [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) |
592d0b1e | 770 | |
b3a2272a | 771 | |
a4e25e1d JD |
772 | # b4_percent_define_default(VARIABLE, DEFAULT) |
773 | # -------------------------------------------- | |
416a9da6 | 774 | # Mimic muscle_percent_define_default in ../src/muscle-tab.h exactly. That is, |
9611cfa2 JD |
775 | # if the %define variable VARIABLE is undefined, set its value to DEFAULT. |
776 | # Don't record this as a Bison usage of VARIABLE as there's no reason to | |
777 | # suspect that the value has yet influenced the output. | |
a4e25e1d JD |
778 | # |
779 | # For example: | |
780 | # | |
781 | # b4_percent_define_default([[foo]], [[default value]]) | |
782 | m4_define([b4_percent_define_default], | |
783 | [m4_ifndef([b4_percent_define(]$1[)], | |
9611cfa2 JD |
784 | [m4_define([b4_percent_define(]$1[)], [$2])dnl |
785 | m4_define([b4_percent_define_loc(]$1[)], | |
92822aff JD |
786 | [[[[<skeleton default value>:-1.-1]], |
787 | [[<skeleton default value>:-1.-1]]]])dnl | |
788 | m4_define([b4_percent_define_syncline(]$1[)], [[]])])]) | |
6afc30cc | 789 | |
b3a2272a | 790 | |
62cb570a AD |
791 | # b4_percent_define_if_define(NAME, [VARIABLE = NAME]) |
792 | # ---------------------------------------------------- | |
793 | # Define b4_NAME_if that executes its $1 or $2 depending whether | |
45eebca4 AD |
794 | # VARIABLE was %defined. The characters '.' and `-' in VARIABLE are mapped |
795 | # to '_'. | |
b3a2272a | 796 | m4_define([b4_percent_define_if_define_], |
4f646c37 | 797 | [m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]), |
62cb570a AD |
798 | [b4_percent_define_flag_if(m4_default([$2], [$1]), |
799 | [$3], [$4])])]) | |
b3a2272a | 800 | m4_define([b4_percent_define_if_define], |
62cb570a AD |
801 | [b4_percent_define_default([m4_default([$2], [$1])], [[false]]) |
802 | b4_percent_define_if_define_([$1], [$2], $[1], $[2])]) | |
b3a2272a AD |
803 | |
804 | ||
d782395d JD |
805 | # b4_percent_define_check_values(VALUES) |
806 | # -------------------------------------- | |
416a9da6 | 807 | # Mimic muscle_percent_define_check_values in ../src/muscle-tab.h exactly |
d782395d JD |
808 | # except that the VALUES structure is more appropriate for M4. That is, VALUES |
809 | # is a list of sublists of strings. For each sublist, the first string is the | |
810 | # name of a %define variable, and all remaining strings in that sublist are the | |
811 | # valid values for that variable. Complain if such a variable is undefined (a | |
812 | # Bison error since the default value should have been set already) or defined | |
813 | # to any other value (possibly a user error). Don't record this as a Bison | |
814 | # usage of the variable as there's no reason to suspect that the value has yet | |
815 | # influenced the output. | |
816 | # | |
817 | # For example: | |
818 | # | |
819 | # b4_percent_define_check_values([[[[foo]], [[foo-value1]], [[foo-value2]]]], | |
820 | # [[[[bar]], [[bar-value1]]]]) | |
821 | m4_define([b4_percent_define_check_values], | |
822 | [m4_foreach([b4_sublist], m4_quote($@), | |
823 | [_b4_percent_define_check_values(b4_sublist)])]) | |
824 | ||
825 | m4_define([_b4_percent_define_check_values], | |
826 | [m4_ifdef([b4_percent_define(]$1[)], | |
827 | [m4_pushdef([b4_good_value], [0])dnl | |
828 | m4_if($#, 1, [], | |
829 | [m4_foreach([b4_value], m4_dquote(m4_shift($@)), | |
830 | [m4_if(m4_indir([b4_percent_define(]$1[)]), b4_value, | |
831 | [m4_define([b4_good_value], [1])])])])dnl | |
832 | m4_if(b4_good_value, [0], | |
35b8730d | 833 | [b4_complain_at(b4_percent_define_get_loc([$1]), |
4aa9d1ff | 834 | [[invalid value for %%define variable '%s': '%s']], |
d782395d | 835 | [$1], |
f4909773 JD |
836 | m4_dquote(m4_indir([b4_percent_define(]$1[)]))) |
837 | m4_foreach([b4_value], m4_dquote(m4_shift($@)), | |
c6c8de16 | 838 | [b4_error([[note]], b4_percent_define_get_loc([$1]), [] |
4aa9d1ff | 839 | [[accepted value: '%s']], |
f4909773 | 840 | m4_dquote(b4_value))])])dnl |
d782395d | 841 | m4_popdef([b4_good_value])], |
11872a83 | 842 | [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) |
d782395d | 843 | |
a4e25e1d | 844 | # b4_percent_code_get([QUALIFIER]) |
6afc30cc JD |
845 | # -------------------------------- |
846 | # If any %code blocks for QUALIFIER are defined, emit them beginning with a | |
847 | # comment and ending with synclines and a newline. If QUALIFIER is not | |
592d0b1e | 848 | # specified or empty, do this for the unqualified %code blocks. Also, record |
9611cfa2 JD |
849 | # Bison's usage of QUALIFIER (if specified) by defining |
850 | # b4_percent_code_bison_qualifiers(QUALIFIER). | |
a4e25e1d JD |
851 | # |
852 | # For example, to emit any unqualified %code blocks followed by any %code | |
853 | # blocks for the qualifier foo: | |
854 | # | |
855 | # b4_percent_code_get | |
856 | # b4_percent_code_get([[foo]]) | |
857 | m4_define([b4_percent_code_get], | |
592d0b1e | 858 | [m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl |
9611cfa2 | 859 | m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl |
6afc30cc JD |
860 | m4_ifdef(b4_macro_name, |
861 | [b4_comment([m4_if([$#], [0], [[Unqualified %code]], | |
42ee26bb | 862 | [["%code ]$1["]])[ blocks.]]) |
a4e25e1d JD |
863 | b4_user_code([m4_indir(b4_macro_name)]) |
864 | ])dnl | |
6afc30cc JD |
865 | m4_popdef([b4_macro_name])]) |
866 | ||
592d0b1e PB |
867 | # b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE]) |
868 | # ----------------------------------------------------- | |
869 | # If any %code blocks for QUALIFIER (or unqualified %code blocks if | |
870 | # QUALIFIER is empty) are defined, expand IF-TRUE, else expand IF-FALSE. | |
9611cfa2 JD |
871 | # Also, record Bison's usage of QUALIFIER (if specified) by defining |
872 | # b4_percent_code_bison_qualifiers(QUALIFIER). | |
592d0b1e PB |
873 | m4_define([b4_percent_code_ifdef], |
874 | [m4_ifdef([b4_percent_code(]$1[)], | |
9611cfa2 | 875 | [m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])$2], |
e9690142 | 876 | [$3])]) |
592d0b1e | 877 | |
6afc30cc | 878 | |
ad597a78 AD |
879 | ## ------------------ ## |
880 | ## Common variables. ## | |
881 | ## ------------------ ## | |
882 | ||
5679f311 AD |
883 | # Default values for %define. |
884 | # --------------------------- | |
2a6b66c5 AD |
885 | # If the api.token.prefix, it is empty. |
886 | m4_percent_define_default([[api.token.prefix]], [[]]) | |
5679f311 | 887 | |
ad597a78 AD |
888 | # b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT]) |
889 | # b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT]) | |
e36ec1f4 | 890 | # b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT]) |
ad597a78 | 891 | # ---------------------------------------------- |
e36ec1f4 | 892 | b4_percent_define_if_define([token_ctor], [api.token.constructor]) |
ad597a78 AD |
893 | b4_percent_define_if_define([locations]) # Whether locations are tracked. |
894 | b4_percent_define_if_define([parse.assert]) | |
895 | b4_percent_define_if_define([parse.trace]) | |
bc603897 | 896 | |
ad597a78 | 897 | |
bcd80897 AD |
898 | # b4_bison_locations_if([IF-TRUE]) |
899 | # -------------------------------- | |
900 | # Expand IF-TRUE if using locations, and using the default location | |
901 | # type. | |
902 | m4_define([b4_bison_locations_if], | |
903 | [b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])]) | |
904 | ||
ad597a78 AD |
905 | |
906 | # b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT]) | |
907 | # ------------------------------------------------------ | |
908 | # Map %define parse.error "(simple|verbose)" to b4_error_verbose_if and | |
909 | # b4_error_verbose_flag. | |
910 | b4_percent_define_default([[parse.error]], [[simple]]) | |
911 | b4_percent_define_check_values([[[[parse.error]], | |
912 | [[simple]], [[verbose]]]]) | |
913 | m4_define([b4_error_verbose_flag], | |
82db7cdb JD |
914 | [m4_case(b4_percent_define_get([[parse.error]]), |
915 | [simple], [[0]], | |
916 | [verbose], [[1]])]) | |
ad597a78 | 917 | b4_define_flag_if([error_verbose]) |
5679f311 | 918 | |
f1246164 AD |
919 | # yytoken_table is needed to support verbose errors. |
920 | b4_error_verbose_if([m4_define([b4_token_table_flag], [1])]) | |
921 | ||
5679f311 | 922 | |
bc603897 AD |
923 | # b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT]) |
924 | # ---------------------------------------------- | |
925 | b4_percent_define_if_define([variant]) | |
926 | m4_case(b4_percent_define_get([[api.value.type]]), | |
927 | [variant], [m4_define([b4_variant_flag], [[1]])], | |
928 | [m4_define([b4_variant_flag], [[0]])]) | |
929 | b4_define_flag_if([variant]) | |
930 | ||
931 | ||
9611cfa2 JD |
932 | ## ----------------------------------------------------------- ## |
933 | ## After processing the skeletons, check that all the user's ## | |
934 | ## %define variables and %code qualifiers were used by Bison. ## | |
935 | ## ----------------------------------------------------------- ## | |
6afc30cc | 936 | |
a4e25e1d JD |
937 | m4_define([b4_check_user_names_wrap], |
938 | [m4_ifdef([b4_percent_]$1[_user_]$2[s], | |
939 | [b4_check_user_names([[%]$1 $2], | |
940 | [b4_percent_]$1[_user_]$2[s], | |
9611cfa2 | 941 | [[b4_percent_]$1[_bison_]$2[s]])])]) |
6afc30cc | 942 | |
882a1fbf | 943 | m4_wrap_lifo([ |
a4e25e1d JD |
944 | b4_check_user_names_wrap([[define]], [[variable]]) |
945 | b4_check_user_names_wrap([[code]], [[qualifier]]) | |
6afc30cc | 946 | ]) |
2a824fae AD |
947 | |
948 | ||
949 | ## ---------------- ## | |
950 | ## Default values. ## | |
951 | ## ---------------- ## | |
952 | ||
953 | # m4_define_default([b4_lex_param], []) dnl breaks other skeletons | |
954 | m4_define_default([b4_pre_prologue], []) | |
955 | m4_define_default([b4_post_prologue], []) | |
956 | m4_define_default([b4_epilogue], []) | |
957 | m4_define_default([b4_parse_param], []) | |
958 | ||
959 | # The initial column and line. | |
960 | m4_define_default([b4_location_initial_column], [1]) | |
961 | m4_define_default([b4_location_initial_line], [1]) | |
32ae07ef AD |
962 | |
963 | # Sanity checks. | |
964 | b4_percent_define_ifdef([api.prefix], | |
965 | [m4_ifdef([b4_prefix], | |
966 | [b4_complain_at(b4_percent_define_get_loc([api.prefix]), | |
967 | [['%s' and '%s' cannot be used together]], | |
968 | [%name-prefix], | |
969 | [%define api.prefix])])]) | |
6574576c AD |
970 | |
971 | b4_percent_define_ifdef([api.value.type], | |
972 | [m4_ifdef([b4_union_members], | |
973 | [b4_complain_at(b4_percent_define_get_loc([api.value.type]), | |
974 | [['%s' and '%s' cannot be used together]], | |
975 | [%union], | |
976 | [%define api.value.type])])]) |