]>
Commit | Line | Data |
---|---|---|
08af01c2 | 1 | -*- Autoconf -*- |
90b9908d PB |
2 | |
3 | # Language-independent M4 Macros for Bison. | |
945e396c | 4 | # Copyright (C) 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
90b9908d PB |
5 | |
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 2 of the License, or | |
9 | # (at your option) any later version. | |
10 | ||
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. | |
15 | ||
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
19 | # 02110-1301 USA | |
20 | ||
21 | ||
22 | ## ---------------- ## | |
23 | ## Identification. ## | |
24 | ## ---------------- ## | |
25 | ||
26 | # b4_copyright(TITLE, YEARS) | |
27 | # -------------------------- | |
28 | m4_define([b4_copyright], | |
29 | [b4_comment([A Bison parser, made by GNU Bison b4_version.]) | |
30 | ||
31 | b4_comment([$1 | |
32 | ||
33 | m4_text_wrap([Copyright (C) $2 Free Software Foundation, Inc.], [ ]) | |
34 | ||
35 | This program is free software; you can redistribute it and/or modify | |
36 | it under the terms of the GNU General Public License as published by | |
37 | the Free Software Foundation; either version 2, or (at your option) | |
38 | any later version. | |
39 | ||
40 | This program is distributed in the hope that it will be useful, | |
41 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
42 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
43 | GNU General Public License for more details. | |
44 | ||
45 | You should have received a copy of the GNU General Public License | |
46 | along with this program; if not, write to the Free Software | |
47 | Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
48 | Boston, MA 02110-1301, USA.]) | |
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 | ||
08af01c2 JD |
64 | ## ---------------- ## |
65 | ## Error handling. ## | |
66 | ## ---------------- ## | |
67 | ||
68 | # b4_error(KIND, FORMAT, [ARG1], [ARG2], ...) | |
69 | # --------------------------------------------------------------- | |
70 | # Write @KIND(FORMAT@,ARG1@,ARG2@,...@) to diversion 0. | |
71 | m4_define([b4_error], | |
72 | [m4_divert_push(0)[@]$1[(]$2[]m4_if([$#], [2], [], | |
73 | [m4_foreach([b4_arg], | |
1c7b7e1d | 74 | m4_dquote(m4_shift(m4_shift($@))), |
08af01c2 JD |
75 | [[@,]b4_arg])])[@)]m4_divert_pop(0)]) |
76 | ||
77 | # b4_warn(FORMAT, [ARG1], [ARG2], ...) | |
78 | # -------------------------------------------------------- | |
79 | # Write @warn(FORMAT@,ARG1@,ARG2@,...@) to diversion 0. | |
80 | # | |
81 | # As a simple test suite, this: | |
82 | # | |
83 | # m4_define([asdf], [ASDF]) | |
84 | # m4_define([fsa], [FSA]) | |
85 | # m4_define([fdsa], [FDSA]) | |
86 | # b4_warn([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]]) | |
87 | # m4_divert(0) | |
88 | # b4_warn([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]]) | |
89 | # m4_divert(0) | |
90 | # b4_warn([asdf), asdf], [fsa), fsa], [fdsa), fdsa]) | |
91 | # m4_divert(0) | |
92 | # b4_warn | |
93 | # m4_divert(0) | |
94 | # b4_warn() | |
95 | # m4_divert(0) | |
96 | # b4_warn(1) | |
97 | # m4_divert(0) | |
98 | # b4_warn(1, 2) | |
99 | # | |
100 | # Should produce this: | |
101 | # | |
102 | # @warn([asdf), asdf]@,[fsa), fsa]@,[fdsa), fdsa]@) | |
103 | # @warn(asdf), asdf@,fsa), fsa@,fdsa), fdsa@) | |
104 | # @warn(ASDF), ASDF@,FSA), FSA@,FDSA), FDSA@) | |
105 | # @warn(@) | |
106 | # @warn(@) | |
107 | # @warn(1@) | |
108 | # @warn(1@,2@) | |
109 | m4_define([b4_warn], | |
110 | [b4_error([[warn]], $@)]) | |
111 | ||
112 | # b4_complain(FORMAT, [ARG1], [ARG2], ...) | |
113 | # ------------------------------------------------------------ | |
114 | # Write @complain(FORMAT@,ARG1@,ARG2@,...@) to diversion 0. | |
115 | # | |
116 | # See the test suite for b4_warn above. | |
117 | m4_define([b4_complain], | |
118 | [b4_error([[complain]], $@)]) | |
119 | ||
120 | # b4_fatal(FORMAT, [ARG1], [ARG2], ...) | |
121 | # --------------------------------------------------------- | |
122 | # Write @fatal(FORMAT@,ARG1@,ARG2@,...@) to diversion 0. | |
123 | # | |
124 | # See the test suite for b4_warn above. | |
125 | m4_define([b4_fatal], | |
126 | [b4_error([[fatal]], $@)]) | |
127 | ||
128 | ||
90b9908d PB |
129 | ## ---------------- ## |
130 | ## Default values. ## | |
131 | ## ---------------- ## | |
132 | ||
133 | # m4_define_default([b4_lex_param], []) dnl breaks other skeletons | |
134 | m4_define_default([b4_epilogue], []) | |
135 | m4_define_default([b4_parse_param], []) | |
136 | ||
137 | # The initial column and line. | |
138 | m4_define_default([b4_location_initial_column], [1]) | |
139 | m4_define_default([b4_location_initial_line], [1]) | |
140 | ||
141 | ||
142 | ## ------------ ## | |
143 | ## Data Types. ## | |
144 | ## ------------ ## | |
145 | ||
146 | # b4_ints_in(INT1, INT2, LOW, HIGH) | |
147 | # --------------------------------- | |
148 | # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise. | |
149 | m4_define([b4_ints_in], | |
150 | [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])]) | |
151 | ||
152 | ||
153 | ||
154 | ## ------------------ ## | |
155 | ## Decoding options. ## | |
156 | ## ------------------ ## | |
157 | ||
158 | # b4_flag_if(FLAG, IF-TRUE, IF-FALSE) | |
159 | # ----------------------------------- | |
160 | # Run IF-TRUE if b4_FLAG_flag is 1, IF-FALSE if FLAG is 0, otherwise fail. | |
161 | m4_define([b4_flag_if], | |
162 | [m4_case(b4_$1_flag, | |
163 | [0], [$3], | |
164 | [1], [$2], | |
165 | [m4_fatal([invalid $1 value: ]$1)])]) | |
166 | ||
167 | ||
168 | # b4_define_flag_if(FLAG) | |
169 | # ----------------------- | |
170 | # Define "b4_FLAG_if(IF-TRUE, IF-FALSE)" that depends on the | |
171 | # value of the Boolean FLAG. | |
172 | m4_define([b4_define_flag_if], | |
173 | [_b4_define_flag_if($[1], $[2], [$1])]) | |
174 | ||
175 | # _b4_define_flag_if($1, $2, FLAG) | |
176 | # -------------------------------- | |
177 | # This macro works around the impossibility to define macros | |
178 | # inside macros, because issuing `[$1]' is not possible in M4 :(. | |
179 | # This sucks hard, GNU M4 should really provide M5 like $$1. | |
180 | m4_define([_b4_define_flag_if], | |
181 | [m4_if([$1$2], $[1]$[2], [], | |
182 | [m4_fatal([$0: Invalid arguments: $@])])dnl | |
183 | m4_define([b4_$3_if], | |
184 | [b4_flag_if([$3], [$1], [$2])])]) | |
185 | ||
186 | ||
187 | # b4_FLAG_if(IF-TRUE, IF-FALSE) | |
188 | # ----------------------------- | |
189 | # Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise. | |
190 | b4_define_flag_if([defines]) # Whether headers are requested. | |
191 | b4_define_flag_if([error_verbose]) # Whether error are verbose. | |
192 | b4_define_flag_if([glr]) # Whether a GLR parser is requested. | |
193 | b4_define_flag_if([locations]) # Whether locations are tracked. | |
194 | b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled. | |
7172e23e | 195 | b4_define_flag_if([pull]) # Whether pull parsing is requested. |
90b9908d | 196 | b4_define_flag_if([pure]) # Whether the interface is pure. |
7172e23e | 197 | b4_define_flag_if([push]) # Whether push parsing is requested. |
945e396c JD |
198 | b4_define_flag_if([use_push_for_pull]) # Whether push parsing should be used |
199 | # in place of pull parsing (where | |
200 | # available) for the sake of the test | |
201 | # suite. | |
90b9908d PB |
202 | b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. |
203 | ||
204 | ||
205 | ## ------------------------- ## | |
206 | ## Assigning token numbers. ## | |
207 | ## ------------------------- ## | |
208 | ||
209 | ||
210 | ## ----------- ## | |
211 | ## Synclines. ## | |
212 | ## ----------- ## | |
213 | ||
214 | # b4_basename(NAME) | |
215 | # ----------------- | |
216 | # Similar to POSIX basename; the differences don't matter here. | |
217 | # Beware that NAME is not evaluated. | |
218 | m4_define([b4_basename], | |
219 | [m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])]) | |
220 | ||
221 | ||
222 | # b4_syncline(LINE, FILE) | |
223 | # ----------------------- | |
224 | m4_define([b4_syncline], | |
225 | [b4_flag_if([synclines], [ | |
226 | b4_sync_end([__line__], [b4_basename(m4_quote(__file__))]) | |
227 | b4_sync_start([$1], [$2])])]) | |
228 | ||
229 | m4_define([b4_sync_end], [b4_comment([Line $1 of $2])]) | |
230 | m4_define([b4_sync_start], [b4_comment([Line $1 of $2])]) | |
231 | ||
232 | # b4_user_code(USER-CODE) | |
233 | # ----------------------- | |
234 | # Emit code from the user, ending it with synclines. | |
235 | m4_define([b4_user_code], | |
236 | [$1 | |
237 | b4_syncline([@oline@], [@ofile@])]) | |
238 | ||
239 | ||
240 | # b4_define_user_code(MACRO) | |
241 | # -------------------------- | |
242 | # From b4_MACRO, build b4_user_MACRO that includes the synclines. | |
243 | m4_define([b4_define_user_code], | |
244 | [m4_define([b4_user_$1], | |
245 | [b4_user_code([b4_$1])])]) | |
246 | ||
247 | ||
248 | # b4_user_actions | |
249 | # b4_user_initial_action | |
250 | # b4_user_post_prologue | |
136a0f76 | 251 | # b4_user_pre_prologue |
90b9908d PB |
252 | # b4_user_stype |
253 | # ---------------------- | |
254 | # Macros that issue user code, ending with synclines. | |
255 | b4_define_user_code([actions]) | |
256 | b4_define_user_code([initial_action]) | |
257 | b4_define_user_code([post_prologue]) | |
136a0f76 | 258 | b4_define_user_code([pre_prologue]) |
90b9908d PB |
259 | b4_define_user_code([stype]) |
260 | ||
1c7b7e1d | 261 | |
8e0a5e9e JD |
262 | # b4_check_percent_code_qualifiers([VAILD_QUALIFIER], [VALID_QUALIFIER], ...) |
263 | # --------------------------------------------------------------------------- | |
264 | # Complain if any %code qualifier used in the grammar is not a valid qualifier. | |
265 | # | |
1c7b7e1d JD |
266 | # If no %code qualifiers are used in the grammar, |
267 | # b4_used_percent_code_qualifiers must be undefined or expand to the empty | |
268 | # string. Otherwise, it must expand to a comma-delimited list specifying all | |
269 | # %code qualifiers used in the grammar. Each item in the list must expand to | |
270 | # text that expands to one of those qualifiers. For example, to define | |
271 | # b4_used_percent_code_qualifiers with two qualifiers with correct quoting: | |
272 | # | |
273 | # m4_define([b4_used_percent_code_qualifiers], | |
274 | # [[[[requires]], [[provides]]]]) | |
275 | # | |
276 | # Multiple occurrences of the same qualifier are fine. Empty string qualifiers | |
277 | # are fine. | |
278 | # | |
279 | # Each VALID_QUALIFIER must expand to a valid qualifier. For example, | |
280 | # b4_check_percent_code_qualifiers might be invoked with: | |
281 | # | |
282 | # b4_check_percent_code_qualifiers([[requires]], [[provides]]) | |
8e0a5e9e | 283 | # |
1c7b7e1d JD |
284 | # Multiple occurrences of the same valid qualifier are fine. A VALID_QUALIFIER |
285 | # that expands to the empty string will correctly define the empty string as a | |
286 | # valid qualifier, but it would be ugly for a Bison skeleton to actually use | |
287 | # that. If b4_used_percent_code_qualifiers is invoked with empty parens, then | |
288 | # there is one valid qualifier and it is the empty string. To specify that | |
289 | # there are no valid qualifiers, invoke b4_check_percent_code_qualifiers | |
290 | # without parens. | |
8e0a5e9e | 291 | # |
1c7b7e1d | 292 | # Qualifiers and valid qualifiers must not contain the character `,'. |
8e0a5e9e JD |
293 | m4_define([b4_check_percent_code_qualifiers], |
294 | [m4_ifdef([b4_used_percent_code_qualifiers], [ | |
295 | m4_foreach([b4_qualifier], | |
1c7b7e1d | 296 | b4_used_percent_code_qualifiers, |
8e0a5e9e | 297 | [m4_if(m4_index(m4_if($#, 0, [], [[,]m4_quote($*)[,]]), |
1c7b7e1d | 298 | [,]b4_qualifier[,]), |
8e0a5e9e | 299 | [-1], |
08af01c2 | 300 | [b4_complain([[`%s' is not a recognized %%code qualifier]], |
1c7b7e1d | 301 | [b4_qualifier]) |
08af01c2 | 302 | ]) |
8e0a5e9e JD |
303 | ]) |
304 | ])]) |