]>
Commit | Line | Data |
---|---|---|
087b9fdf | 1 | # Checking the Bison scanner. -*- Autotest -*- |
7d424de1 | 2 | |
34136e65 | 3 | # Copyright (C) 2002-2012 Free Software Foundation, Inc. |
9b2d0677 | 4 | |
f16b0819 | 5 | # This program is free software: you can redistribute it and/or modify |
9b2d0677 | 6 | # it under the terms of the GNU General Public License as published by |
f16b0819 PE |
7 | # the Free Software Foundation, either version 3 of the License, or |
8 | # (at your option) any later version. | |
9 | # | |
9b2d0677 AD |
10 | # This program is distributed in the hope that it will be useful, |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
f16b0819 | 14 | # |
9b2d0677 | 15 | # You should have received a copy of the GNU General Public License |
f16b0819 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
9b2d0677 AD |
17 | |
18 | AT_BANNER([[Input Processing.]]) | |
19 | ||
20 | # Mostly test that we are robust to mistakes. | |
21 | ||
6c35d22c | 22 | |
baf0bd61 AD |
23 | ## ---------------- ## |
24 | ## Invalid inputs. ## | |
25 | ## ---------------- ## | |
26 | ||
27 | AT_SETUP([Invalid inputs]) | |
28 | ||
29 | AT_DATA([input.y], | |
95066e92 AD |
30 | [[\000\001\002\377? |
31 | %% | |
baf0bd61 AD |
32 | ? |
33 | default: 'a' } | |
34 | %& | |
35 | %a-does-not-exist | |
36 | %- | |
37 | %{ | |
38 | ]]) | |
95066e92 | 39 | AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y || exit 77]]) |
baf0bd61 AD |
40 | |
41 | AT_BISON_CHECK([input.y], [1], [], | |
68ac70bc | 42 | [[input.y:1.1-2: error: invalid characters: '\0\001\002\377?' |
04901623 AD |
43 | input.y:3.1: error: invalid character: '?' |
44 | input.y:4.14: error: invalid character: '}' | |
45 | input.y:5.1: error: invalid character: '%' | |
46 | input.y:5.2: error: invalid character: '&' | |
47 | input.y:6.1-17: error: invalid directive: '%a-does-not-exist' | |
48 | input.y:7.1: error: invalid character: '%' | |
49 | input.y:7.2: error: invalid character: '-' | |
50 | input.y:8.1-9.0: error: missing '%}' at end of file | |
51 | input.y:8.1-9.0: error: syntax error, unexpected %{...%} | |
baf0bd61 AD |
52 | ]]) |
53 | ||
54 | AT_CLEANUP | |
55 | ||
56 | ||
57 | AT_SETUP([Invalid inputs with {}]) | |
58 | ||
59 | # We used to SEGV here. See | |
60 | # http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html | |
61 | ||
62 | AT_DATA([input.y], | |
63 | [[ | |
64 | %destructor | |
65 | %initial-action | |
66 | %lex-param | |
67 | %parse-param | |
68 | %printer | |
69 | %union | |
70 | ]]) | |
71 | ||
72 | AT_BISON_CHECK([input.y], [1], [], | |
04901623 | 73 | [[input.y:3.1-15: error: syntax error, unexpected %initial-action, expecting {...} |
baf0bd61 AD |
74 | ]]) |
75 | ||
76 | AT_CLEANUP | |
77 | ||
78 | ||
79 | ||
9b2d0677 AD |
80 | ## ------------ ## |
81 | ## Invalid $n. ## | |
82 | ## ------------ ## | |
83 | ||
287b314e | 84 | AT_SETUP([Invalid $n and @n]) |
9b2d0677 AD |
85 | |
86 | AT_DATA([input.y], | |
87 | [[%% | |
bfcf1f3a | 88 | exp: { $$ = $1 ; }; |
bfcf1f3a | 89 | exp: { @$ = @1 ; }; |
9b2d0677 AD |
90 | ]]) |
91 | ||
0242bf04 | 92 | AT_BISON_CHECK([-fcaret input.y], [1], [], |
b8e7ad58 | 93 | [[input.y:2.13-14: error: integer out of range: '$1' |
0242bf04 TR |
94 | exp: { $$ = $1 ; }; |
95 | ^^ | |
b8e7ad58 | 96 | input.y:3.13-14: error: integer out of range: '@1' |
0242bf04 TR |
97 | exp: { @$ = @1 ; }; |
98 | ^^ | |
9b2d0677 AD |
99 | ]]) |
100 | ||
101 | AT_CLEANUP | |
9af3fbce AD |
102 | |
103 | ||
104 | ## -------------- ## | |
e776192e | 105 | ## Type Clashes. ## |
9af3fbce AD |
106 | ## -------------- ## |
107 | ||
e776192e | 108 | AT_SETUP([Type Clashes]) |
9af3fbce AD |
109 | |
110 | AT_DATA([input.y], | |
ffa4ba3a JD |
111 | [[%union { int bar; } |
112 | %token foo | |
9af3fbce AD |
113 | %type <bar> exp |
114 | %% | |
ffa4ba3a | 115 | exp: foo { $$; } foo { $2; } foo |
9af3fbce AD |
116 | | foo |
117 | | /* Empty. */ | |
118 | ; | |
119 | ]]) | |
120 | ||
0242bf04 | 121 | AT_BISON_CHECK([-fcaret input.y], [1], [], |
b8e7ad58 | 122 | [[input.y:5.12-13: error: $$ for the midrule at $2 of 'exp' has no declared type |
0242bf04 TR |
123 | exp: foo { $$; } foo { $2; } foo |
124 | ^^ | |
b8e7ad58 | 125 | input.y:5.24-25: error: $2 of 'exp' has no declared type |
0242bf04 TR |
126 | exp: foo { $$; } foo { $2; } foo |
127 | ^^ | |
73370a9d | 128 | input.y:5.6-32: warning: type clash on default action: <bar> != <> [-Wother] |
0242bf04 TR |
129 | exp: foo { $$; } foo { $2; } foo |
130 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
73370a9d | 131 | input.y:6.6-8: warning: type clash on default action: <bar> != <> [-Wother] |
0242bf04 TR |
132 | | foo |
133 | ^^^ | |
73370a9d | 134 | input.y:7.5: warning: empty rule for typed nonterminal, and no action [-Wother] |
0242bf04 TR |
135 | | /* Empty. */ |
136 | ^ | |
9af3fbce AD |
137 | ]]) |
138 | ||
139 | AT_CLEANUP | |
5a08f1ce AD |
140 | |
141 | ||
ffa4ba3a | 142 | # _AT_UNUSED_VALUES_DECLARATIONS() |
dab244d5 | 143 | # -------------------------------- |
ffa4ba3a JD |
144 | # Generate the token, type, and destructor |
145 | # declarations for the unused values tests. | |
ffa4ba3a JD |
146 | m4_define([_AT_UNUSED_VALUES_DECLARATIONS], |
147 | [[[%token <integer> INT; | |
148 | %type <integer> a b c d e f g h i j k l; | |
149 | %destructor { destroy ($$); } INT a b c d e f g h i j k l;]]]) | |
378f4bd8 | 150 | |
ffa4ba3a | 151 | |
17bd8a73 | 152 | # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES) |
dab244d5 AD |
153 | # ---------------------------------------------------------------- |
154 | # Generate a grammar to test unused values, compile it, run it. If | |
155 | # DECLARATIONS_AFTER is set, then the token, type, and destructor | |
156 | # declarations are generated after the rules rather than before. If | |
157 | # CHECK_MIDRULE_VALUES is set, then --warnings=midrule-values is set. | |
ffa4ba3a JD |
158 | m4_define([AT_CHECK_UNUSED_VALUES], |
159 | [AT_DATA([input.y], | |
160 | m4_ifval($1, [ | |
161 | ||
162 | ||
163 | ], [_AT_UNUSED_VALUES_DECLARATIONS | |
164 | ])[[%% | |
27622431 | 165 | start: |
e8cd1ad6 DJ |
166 | 'a' a { $]2[; } | 'b' b { $]2[; } | 'c' c { $]2[; } | 'd' d { $]2[; } |
167 | | 'e' e { $]2[; } | 'f' f { $]2[; } | 'g' g { $]2[; } | 'h' h { $]2[; } | |
168 | | 'i' i { $]2[; } | 'j' j { $]2[; } | 'k' k { $]2[; } | 'l' l { $]2[; } | |
378f4bd8 | 169 | ; |
27622431 PE |
170 | |
171 | a: INT | INT { } INT { } INT { }; | |
172 | b: INT | /* empty */; | |
e8cd1ad6 DJ |
173 | c: INT | INT { $]1[; } INT { $<integer>2; } INT { $<integer>4; }; |
174 | d: INT | INT { } INT { $]1[; } INT { $<integer>2; }; | |
175 | e: INT | INT { } INT { } INT { $]1[; }; | |
ffa4ba3a | 176 | f: INT | INT { } INT { } INT { $]$[ = $]1[ + $]3[ + $]5[; }; |
ddc8ede1 PE |
177 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; |
178 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; | |
ffa4ba3a JD |
179 | i: INT | INT INT { } { $]$[ = $]1[ + $]2[; }; |
180 | j: INT | INT INT { $<integer>$ = 1; } { $]$[ = $]1[ + $]2[; }; | |
ddc8ede1 PE |
181 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; |
182 | l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };]]m4_ifval($1, [ | |
ffa4ba3a JD |
183 | _AT_UNUSED_VALUES_DECLARATIONS]) |
184 | ) | |
185 | ||
23589235 AD |
186 | AT_BISON_CHECK(m4_ifval($2, [--warnings=midrule-values ])[-fcaret input.y], |
187 | [0], [], | |
0906b12c | 188 | [[input.y:11.10-32: warning: unset value: $][$ [-Wother] |
23589235 AD |
189 | a: INT | INT { } INT { } INT { }; |
190 | ^^^^^^^^^^^^^^^^^^^^^^^ | |
0906b12c | 191 | input.y:11.10-12: warning: unused value: $][1 [-Wother] |
23589235 AD |
192 | a: INT | INT { } INT { } INT { }; |
193 | ^^^ | |
0906b12c | 194 | input.y:11.18-20: warning: unused value: $][3 [-Wother] |
23589235 AD |
195 | a: INT | INT { } INT { } INT { }; |
196 | ^^^ | |
0906b12c | 197 | input.y:11.26-28: warning: unused value: $][5 [-Wother] |
23589235 AD |
198 | a: INT | INT { } INT { } INT { }; |
199 | ^^^ | |
73370a9d | 200 | input.y:12.9: warning: empty rule for typed nonterminal, and no action [-Wother] |
23589235 AD |
201 | b: INT | /* empty */; |
202 | ^ | |
0906b12c | 203 | ]]m4_ifval($2, [[[input.y:13.14-20: warning: unset value: $][$ [-Wmidrule-values] |
23589235 AD |
204 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; }; |
205 | ^^^^^^^ | |
0906b12c | 206 | input.y:13.26-41: warning: unset value: $][$ [-Wmidrule-values] |
23589235 AD |
207 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; }; |
208 | ^^^^^^^^^^^^^^^^ | |
0906b12c | 209 | ]]])[[input.y:13.10-62: warning: unset value: $][$ [-Wother] |
23589235 AD |
210 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; }; |
211 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
0906b12c | 212 | input.y:13.22-24: warning: unused value: $][3 [-Wother] |
23589235 AD |
213 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; }; |
214 | ^^^ | |
0906b12c | 215 | input.y:13.43-45: warning: unused value: $][5 [-Wother] |
23589235 AD |
216 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; }; |
217 | ^^^ | |
0906b12c | 218 | ]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $][$ [-Wmidrule-values] |
23589235 AD |
219 | d: INT | INT { } INT { $][1; } INT { $<integer>2; }; |
220 | ^^^ | |
0906b12c | 221 | ]]])[[input.y:14.10-49: warning: unset value: $][$ [-Wother] |
23589235 AD |
222 | d: INT | INT { } INT { $][1; } INT { $<integer>2; }; |
223 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
0906b12c | 224 | input.y:14.18-20: warning: unused value: $][3 [-Wother] |
23589235 AD |
225 | d: INT | INT { } INT { $][1; } INT { $<integer>2; }; |
226 | ^^^ | |
0906b12c | 227 | input.y:14.30-32: warning: unused value: $][5 [-Wother] |
23589235 AD |
228 | d: INT | INT { } INT { $][1; } INT { $<integer>2; }; |
229 | ^^^ | |
0906b12c | 230 | input.y:15.10-37: warning: unset value: $][$ [-Wother] |
23589235 AD |
231 | e: INT | INT { } INT { } INT { $][1; }; |
232 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
0906b12c | 233 | input.y:15.18-20: warning: unused value: $][3 [-Wother] |
23589235 AD |
234 | e: INT | INT { } INT { } INT { $][1; }; |
235 | ^^^ | |
0906b12c | 236 | input.y:15.27-29: warning: unused value: $][5 [-Wother] |
23589235 AD |
237 | e: INT | INT { } INT { } INT { $][1; }; |
238 | ^^^ | |
0906b12c | 239 | input.y:17.10-58: warning: unset value: $][$ [-Wother] |
23589235 AD |
240 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; |
241 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
0906b12c | 242 | input.y:17.10-12: warning: unused value: $][1 [-Wother] |
23589235 AD |
243 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; |
244 | ^^^ | |
0906b12c | 245 | ]]m4_ifval($2, [[[input.y:17.14-29: warning: unused value: $][2 [-Wmidrule-values] |
23589235 AD |
246 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; |
247 | ^^^^^^^^^^^^^^^^ | |
0906b12c | 248 | ]]])[[input.y:17.31-33: warning: unused value: $][3 [-Wother] |
23589235 AD |
249 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; |
250 | ^^^ | |
0906b12c | 251 | ]]m4_ifval($2, [[[input.y:17.35-50: warning: unused value: $][4 [-Wmidrule-values] |
23589235 AD |
252 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; |
253 | ^^^^^^^^^^^^^^^^ | |
0906b12c | 254 | ]]])[[input.y:17.52-54: warning: unused value: $][5 [-Wother] |
23589235 AD |
255 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; |
256 | ^^^ | |
0906b12c | 257 | input.y:18.10-72: warning: unset value: $][$ [-Wother] |
23589235 AD |
258 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; |
259 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
0906b12c | 260 | input.y:18.10-12: warning: unused value: $][1 [-Wother] |
23589235 AD |
261 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; |
262 | ^^^ | |
0906b12c | 263 | input.y:18.31-33: warning: unused value: $][3 [-Wother] |
23589235 AD |
264 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; |
265 | ^^^ | |
0906b12c | 266 | ]]m4_ifval($2, [[[input.y:18.35-64: warning: unused value: $][4 [-Wmidrule-values] |
23589235 AD |
267 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; |
268 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
0906b12c | 269 | ]]])[[input.y:18.66-68: warning: unused value: $][5 [-Wother] |
23589235 AD |
270 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; |
271 | ^^^ | |
0906b12c | 272 | ]]m4_ifval($2, [[[input.y:20.18-37: warning: unused value: $][3 [-Wmidrule-values] |
23589235 AD |
273 | j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; }; |
274 | ^^^^^^^^^^^^^^^^^^^^ | |
0906b12c | 275 | ]]])[[input.y:21.10-68: warning: unset value: $][$ [-Wother] |
23589235 AD |
276 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; |
277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
0906b12c | 278 | input.y:21.10-12: warning: unused value: $][1 [-Wother] |
23589235 AD |
279 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; |
280 | ^^^ | |
0906b12c | 281 | input.y:21.14-16: warning: unused value: $][2 [-Wother] |
23589235 AD |
282 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; |
283 | ^^^ | |
0906b12c | 284 | ]]m4_ifval($2, [[[input.y:21.35-64: warning: unused value: $][4 [-Wmidrule-values] |
23589235 AD |
285 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; |
286 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
287 | ]]])) | |
288 | ]) | |
378f4bd8 | 289 | |
ffa4ba3a JD |
290 | ## --------------- ## |
291 | ## Unused values. ## | |
292 | ## --------------- ## | |
293 | ||
294 | AT_SETUP([Unused values]) | |
295 | AT_CHECK_UNUSED_VALUES | |
17bd8a73 | 296 | AT_CHECK_UNUSED_VALUES(, [1]) |
ffa4ba3a JD |
297 | AT_CLEANUP |
298 | ||
299 | ||
300 | ## ------------------------------------------ ## | |
301 | ## Unused values before symbol declarations. ## | |
302 | ## ------------------------------------------ ## | |
84866159 | 303 | |
ffa4ba3a JD |
304 | AT_SETUP([Unused values before symbol declarations]) |
305 | AT_CHECK_UNUSED_VALUES([1]) | |
17bd8a73 | 306 | AT_CHECK_UNUSED_VALUES([1], [1]) |
84866159 | 307 | AT_CLEANUP |
378f4bd8 AD |
308 | |
309 | ||
ec5479ce JD |
310 | ## --------------------------------------------- ## |
311 | ## Default %printer and %destructor redeclared. ## | |
312 | ## --------------------------------------------- ## | |
313 | ||
314 | AT_SETUP([Default %printer and %destructor redeclared]) | |
315 | ||
316 | AT_DATA([[input.y]], | |
12e35840 | 317 | [[%destructor { destroy ($$); } <*> <*> |
abcd36ca | 318 | %printer { print ($$); } <*> <*> |
ec5479ce | 319 | |
12e35840 | 320 | %destructor { destroy ($$); } <*> |
abcd36ca | 321 | %printer { print ($$); } <*> |
12e35840 | 322 | |
3ebecc24 | 323 | %destructor { destroy ($$); } <> <> |
abcd36ca | 324 | %printer { print ($$); } <> <> |
12e35840 | 325 | |
3ebecc24 | 326 | %destructor { destroy ($$); } <> |
abcd36ca | 327 | %printer { print ($$); } <> |
ec5479ce JD |
328 | |
329 | %% | |
330 | ||
331 | start: ; | |
332 | ||
12e35840 | 333 | %destructor { destroy ($$); } <*>; |
abcd36ca | 334 | %printer { print ($$); } <*>; |
12e35840 | 335 | |
3ebecc24 | 336 | %destructor { destroy ($$); } <>; |
abcd36ca | 337 | %printer { print ($$); } <>; |
ec5479ce JD |
338 | ]]) |
339 | ||
0242bf04 | 340 | AT_BISON_CHECK([-fcaret input.y], [1], [], |
11b19212 | 341 | [[input.y:1.13-29: error: %destructor redeclaration for <*> |
0242bf04 TR |
342 | %destructor { destroy ($$); } <*> <*> |
343 | ^^^^^^^^^^^^^^^^^ | |
cbaea010 | 344 | input.y:1.13-29: previous declaration |
0242bf04 TR |
345 | %destructor { destroy ($$); } <*> <*> |
346 | ^^^^^^^^^^^^^^^^^ | |
11b19212 | 347 | input.y:2.10-24: error: %printer redeclaration for <*> |
0242bf04 TR |
348 | %printer { print ($$); } <*> <*> |
349 | ^^^^^^^^^^^^^^^ | |
cbaea010 | 350 | input.y:2.10-24: previous declaration |
0242bf04 TR |
351 | %printer { print ($$); } <*> <*> |
352 | ^^^^^^^^^^^^^^^ | |
11b19212 | 353 | input.y:4.13-29: error: %destructor redeclaration for <*> |
0242bf04 TR |
354 | %destructor { destroy ($$); } <*> |
355 | ^^^^^^^^^^^^^^^^^ | |
cbaea010 | 356 | input.y:1.13-29: previous declaration |
0242bf04 TR |
357 | %destructor { destroy ($$); } <*> <*> |
358 | ^^^^^^^^^^^^^^^^^ | |
11b19212 | 359 | input.y:5.10-24: error: %printer redeclaration for <*> |
0242bf04 TR |
360 | %printer { print ($$); } <*> |
361 | ^^^^^^^^^^^^^^^ | |
cbaea010 | 362 | input.y:2.10-24: previous declaration |
0242bf04 TR |
363 | %printer { print ($$); } <*> <*> |
364 | ^^^^^^^^^^^^^^^ | |
11b19212 | 365 | input.y:7.13-29: error: %destructor redeclaration for <> |
0242bf04 TR |
366 | %destructor { destroy ($$); } <> <> |
367 | ^^^^^^^^^^^^^^^^^ | |
cbaea010 | 368 | input.y:7.13-29: previous declaration |
0242bf04 TR |
369 | %destructor { destroy ($$); } <> <> |
370 | ^^^^^^^^^^^^^^^^^ | |
11b19212 | 371 | input.y:8.10-24: error: %printer redeclaration for <> |
0242bf04 TR |
372 | %printer { print ($$); } <> <> |
373 | ^^^^^^^^^^^^^^^ | |
cbaea010 | 374 | input.y:8.10-24: previous declaration |
0242bf04 TR |
375 | %printer { print ($$); } <> <> |
376 | ^^^^^^^^^^^^^^^ | |
11b19212 | 377 | input.y:10.13-29: error: %destructor redeclaration for <> |
0242bf04 TR |
378 | %destructor { destroy ($$); } <> |
379 | ^^^^^^^^^^^^^^^^^ | |
cbaea010 | 380 | input.y:7.13-29: previous declaration |
0242bf04 TR |
381 | %destructor { destroy ($$); } <> <> |
382 | ^^^^^^^^^^^^^^^^^ | |
11b19212 | 383 | input.y:11.10-24: error: %printer redeclaration for <> |
0242bf04 TR |
384 | %printer { print ($$); } <> |
385 | ^^^^^^^^^^^^^^^ | |
cbaea010 | 386 | input.y:8.10-24: previous declaration |
0242bf04 TR |
387 | %printer { print ($$); } <> <> |
388 | ^^^^^^^^^^^^^^^ | |
11b19212 | 389 | input.y:17.13-29: error: %destructor redeclaration for <*> |
0242bf04 TR |
390 | %destructor { destroy ($$); } <*>; |
391 | ^^^^^^^^^^^^^^^^^ | |
cbaea010 | 392 | input.y:4.13-29: previous declaration |
0242bf04 TR |
393 | %destructor { destroy ($$); } <*> |
394 | ^^^^^^^^^^^^^^^^^ | |
11b19212 | 395 | input.y:18.10-24: error: %printer redeclaration for <*> |
0242bf04 TR |
396 | %printer { print ($$); } <*>; |
397 | ^^^^^^^^^^^^^^^ | |
cbaea010 | 398 | input.y:5.10-24: previous declaration |
0242bf04 TR |
399 | %printer { print ($$); } <*> |
400 | ^^^^^^^^^^^^^^^ | |
11b19212 | 401 | input.y:20.13-29: error: %destructor redeclaration for <> |
0242bf04 TR |
402 | %destructor { destroy ($$); } <>; |
403 | ^^^^^^^^^^^^^^^^^ | |
cbaea010 | 404 | input.y:10.13-29: previous declaration |
0242bf04 TR |
405 | %destructor { destroy ($$); } <> |
406 | ^^^^^^^^^^^^^^^^^ | |
11b19212 | 407 | input.y:21.10-24: error: %printer redeclaration for <> |
0242bf04 TR |
408 | %printer { print ($$); } <>; |
409 | ^^^^^^^^^^^^^^^ | |
cbaea010 | 410 | input.y:11.10-24: previous declaration |
0242bf04 TR |
411 | %printer { print ($$); } <> |
412 | ^^^^^^^^^^^^^^^ | |
ec5479ce JD |
413 | ]]) |
414 | ||
415 | AT_CLEANUP | |
416 | ||
417 | ||
b2a0b7ca JD |
418 | ## ---------------------------------------------- ## |
419 | ## Per-type %printer and %destructor redeclared. ## | |
420 | ## ---------------------------------------------- ## | |
421 | ||
422 | AT_SETUP([Per-type %printer and %destructor redeclared]) | |
423 | ||
424 | AT_DATA([[input.y]], | |
425 | [[%destructor { destroy ($$); } <field1> <field2> | |
abcd36ca | 426 | %printer { print ($$); } <field1> <field2> |
b2a0b7ca JD |
427 | |
428 | %destructor { destroy ($$); } <field1> <field1> | |
abcd36ca | 429 | %printer { print ($$); } <field2> <field2> |
b2a0b7ca JD |
430 | |
431 | %% | |
432 | ||
433 | start: ; | |
434 | ||
435 | %destructor { destroy ($$); } <field2> <field1>; | |
abcd36ca | 436 | %printer { print ($$); } <field2> <field1>; |
b2a0b7ca JD |
437 | ]]) |
438 | ||
da730230 | 439 | AT_BISON_CHECK([input.y], [1], [], |
b8e7ad58 | 440 | [[input.y:4.13-29: error: %destructor redeclaration for <field1> |
cbaea010 | 441 | input.y:1.13-29: previous declaration |
b8e7ad58 | 442 | input.y:4.13-29: error: %destructor redeclaration for <field1> |
cbaea010 | 443 | input.y:4.13-29: previous declaration |
b8e7ad58 | 444 | input.y:5.10-24: error: %printer redeclaration for <field2> |
cbaea010 | 445 | input.y:2.10-24: previous declaration |
b8e7ad58 | 446 | input.y:5.10-24: error: %printer redeclaration for <field2> |
cbaea010 | 447 | input.y:5.10-24: previous declaration |
b8e7ad58 | 448 | input.y:11.13-29: error: %destructor redeclaration for <field1> |
cbaea010 | 449 | input.y:4.13-29: previous declaration |
b8e7ad58 | 450 | input.y:11.13-29: error: %destructor redeclaration for <field2> |
cbaea010 | 451 | input.y:1.13-29: previous declaration |
b8e7ad58 | 452 | input.y:12.10-24: error: %printer redeclaration for <field1> |
cbaea010 | 453 | input.y:2.10-24: previous declaration |
b8e7ad58 | 454 | input.y:12.10-24: error: %printer redeclaration for <field2> |
cbaea010 | 455 | input.y:5.10-24: previous declaration |
b2a0b7ca JD |
456 | ]]) |
457 | ||
458 | AT_CLEANUP | |
459 | ||
31557b9e AD |
460 | ## ------------------- ## |
461 | ## Undefined symbols. ## | |
462 | ## ------------------- ## | |
b921d92f | 463 | |
31557b9e | 464 | AT_SETUP([Undefined symbols]) |
b921d92f VS |
465 | |
466 | AT_DATA([[input.y]], | |
3b0b682f AD |
467 | [[%printer {} foo baz |
468 | %destructor {} bar | |
31557b9e | 469 | %type <foo> qux |
b921d92f | 470 | %% |
3b0b682f | 471 | exp: bar; |
b921d92f VS |
472 | ]]) |
473 | ||
0242bf04 | 474 | AT_BISON_CHECK([-fcaret input.y], [1], [], |
11b19212 | 475 | [[input.y:2.16-18: error: symbol bar is used, but is not defined as a token and has no rules |
0242bf04 TR |
476 | %destructor {} bar |
477 | ^^^ | |
73370a9d | 478 | input.y:1.17-19: warning: symbol baz is used, but is not defined as a token and has no rules [-Wother] |
0242bf04 TR |
479 | %printer {} foo baz |
480 | ^^^ | |
73370a9d | 481 | input.y:1.13-15: warning: symbol foo is used, but is not defined as a token and has no rules [-Wother] |
0242bf04 TR |
482 | %printer {} foo baz |
483 | ^^^ | |
31557b9e | 484 | input.y:3.13-15: warning: symbol qux is used, but is not defined as a token and has no rules [-Wother] |
0242bf04 TR |
485 | %type <foo> qux |
486 | ^^^ | |
b921d92f VS |
487 | ]]) |
488 | ||
489 | AT_CLEANUP | |
490 | ||
b2a0b7ca | 491 | |
9641b918 VS |
492 | ## ----------------------------------------------------- ## |
493 | ## Unassociated types used for a printer or destructor. ## | |
494 | ## ----------------------------------------------------- ## | |
495 | ||
496 | AT_SETUP([Unassociated types used for a printer or destructor]) | |
497 | ||
498 | AT_DATA([[input.y]], | |
499 | [[%token <type1> tag1 | |
500 | %type <type2> tag2 | |
501 | ||
502 | %printer { } <type1> <type3> | |
503 | %destructor { } <type2> <type4> | |
504 | ||
505 | %% | |
506 | ||
507 | exp: tag1 { $1; } | |
508 | | tag2 { $1; } | |
509 | ||
510 | tag2: "a" { $$; } | |
511 | ]]) | |
512 | ||
513 | AT_BISON_CHECK([input.y], [0], [], | |
73370a9d VS |
514 | [[input.y:4.22-28: warning: type <type3> is used, but is not associated to any symbol [-Wother] |
515 | input.y:5.25-31: warning: type <type4> is used, but is not associated to any symbol [-Wother] | |
9641b918 VS |
516 | ]]) |
517 | ||
518 | AT_CLEANUP | |
519 | ||
520 | ||
ea9a35c6 VS |
521 | ## --------------------------------- ## |
522 | ## Useless printers or destructors. ## | |
523 | ## --------------------------------- ## | |
524 | ||
525 | AT_SETUP([Useless printers or destructors]) | |
526 | ||
9534d2be AD |
527 | # AT_TEST([INPUT], [STDERR]) |
528 | # -------------------------- | |
529 | m4_pushdef([AT_TEST], | |
530 | [AT_DATA([[input.y]], | |
531 | [$1 | |
532 | ]) | |
533 | AT_BISON_CHECK([input.y], [0], [], [$2 | |
534 | ])]) | |
535 | ||
536 | AT_TEST([[%token <type1> token1 | |
ea9a35c6 VS |
537 | %token <type2> token2 |
538 | %token <type3> token3 | |
539 | %token <type4> token4 | |
540 | %token <type5> token51 token52 | |
541 | %token <type6> token61 token62 | |
542 | %token <type7> token7 | |
543 | ||
544 | %printer {} token1 | |
545 | %destructor {} token2 | |
546 | %printer {} token51 | |
547 | %destructor {} token61 | |
548 | ||
549 | %printer {} token7 | |
550 | ||
551 | %printer {} <type1> | |
552 | %destructor {} <type2> | |
553 | %printer {} <type3> | |
554 | %destructor {} <type4> | |
555 | ||
556 | %printer {} <type5> | |
557 | %destructor {} <type6> | |
558 | ||
559 | %destructor {} <type7> | |
560 | ||
561 | %% | |
9534d2be | 562 | exp: "a";]], |
73370a9d | 563 | [[input.y:16.13-19: warning: useless %printer for type <type1> [-Wother] |
9534d2be AD |
564 | input.y:17.16-22: warning: useless %destructor for type <type2> [-Wother]]]) |
565 | ||
566 | # If everybody is typed, <> is useless. | |
567 | AT_TEST([[%type <type> exp | |
568 | %token <type> a | |
569 | %printer {} <> <*> | |
570 | %% | |
571 | exp: a;]], | |
572 | [[input.y:3.13-14: warning: useless %printer for type <> [-Wother]]]) | |
573 | ||
84271837 | 574 | # If nobody is typed, <*> is useless. |
9534d2be AD |
575 | AT_TEST([[%token a |
576 | %printer {} <> <*> | |
577 | %% | |
578 | exp: a;]], | |
579 | [[input.y:2.16-18: warning: useless %printer for type <*> [-Wother]]]) | |
ea9a35c6 | 580 | |
9534d2be | 581 | m4_popdef([AT_TEST]) |
ea9a35c6 VS |
582 | |
583 | AT_CLEANUP | |
584 | ||
585 | ||
ec5479ce JD |
586 | ## ---------------------------------------- ## |
587 | ## Unused values with default %destructor. ## | |
588 | ## ---------------------------------------- ## | |
589 | ||
590 | AT_SETUP([Unused values with default %destructor]) | |
591 | ||
592 | AT_DATA([[input.y]], | |
3ebecc24 | 593 | [[%destructor { destroy ($$); } <> |
12e35840 JD |
594 | %type <tag> tagged |
595 | ||
596 | %% | |
597 | ||
598 | start: end end tagged tagged { $<tag>1; $3; } ; | |
599 | end: { } ; | |
600 | tagged: { } ; | |
601 | ]]) | |
602 | ||
0242bf04 | 603 | AT_BISON_CHECK([-fcaret input.y], [0], [], |
73370a9d | 604 | [[input.y:6.8-45: warning: unset value: $$ [-Wother] |
0242bf04 TR |
605 | start: end end tagged tagged { $<tag>1; $3; } ; |
606 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
0906b12c | 607 | input.y:6.12-14: warning: unused value: $2 [-Wother] |
0242bf04 TR |
608 | start: end end tagged tagged { $<tag>1; $3; } ; |
609 | ^^^ | |
73370a9d | 610 | input.y:7.6-8: warning: unset value: $$ [-Wother] |
0242bf04 TR |
611 | end: { } ; |
612 | ^^^ | |
12e35840 JD |
613 | ]]) |
614 | ||
615 | AT_DATA([[input.y]], | |
616 | [[%destructor { destroy ($$); } <*> | |
617 | %type <tag> tagged | |
ec5479ce JD |
618 | |
619 | %% | |
620 | ||
12e35840 JD |
621 | start: end end tagged tagged { $<tag>1; $3; } ; |
622 | end: { } ; | |
623 | tagged: { } ; | |
ec5479ce JD |
624 | ]]) |
625 | ||
da730230 | 626 | AT_BISON_CHECK([input.y], [0], [], |
0906b12c | 627 | [[input.y:6.23-28: warning: unused value: $4 [-Wother] |
73370a9d | 628 | input.y:8.9-11: warning: unset value: $$ [-Wother] |
ec5479ce JD |
629 | ]]) |
630 | ||
631 | AT_CLEANUP | |
632 | ||
633 | ||
b2a0b7ca JD |
634 | ## ----------------------------------------- ## |
635 | ## Unused values with per-type %destructor. ## | |
636 | ## ----------------------------------------- ## | |
637 | ||
638 | AT_SETUP([Unused values with per-type %destructor]) | |
639 | ||
640 | AT_DATA([[input.y]], | |
641 | [[%destructor { destroy ($$); } <field1> | |
642 | %type <field1> start end | |
643 | ||
644 | %% | |
645 | ||
646 | start: end end { $1; } ; | |
647 | end: { } ; | |
648 | ]]) | |
649 | ||
0242bf04 | 650 | AT_BISON_CHECK([-fcaret input.y], [0], [], |
73370a9d | 651 | [[input.y:6.8-22: warning: unset value: $$ [-Wother] |
0242bf04 TR |
652 | start: end end { $1; } ; |
653 | ^^^^^^^^^^^^^^^ | |
0906b12c | 654 | input.y:6.12-14: warning: unused value: $2 [-Wother] |
0242bf04 TR |
655 | start: end end { $1; } ; |
656 | ^^^ | |
73370a9d | 657 | input.y:7.6-8: warning: unset value: $$ [-Wother] |
0242bf04 TR |
658 | end: { } ; |
659 | ^^^ | |
b2a0b7ca JD |
660 | ]]) |
661 | ||
662 | AT_CLEANUP | |
663 | ||
664 | ||
df09ef2e AD |
665 | ## ---------------------- ## |
666 | ## Incompatible Aliases. ## | |
667 | ## ---------------------- ## | |
668 | ||
669 | AT_SETUP([Incompatible Aliases]) | |
670 | ||
671 | AT_DATA([input.y], | |
672 | [[%token foo "foo" | |
673 | ||
674 | %type <bar> foo | |
675 | %printer {bar} foo | |
676 | %destructor {bar} foo | |
677 | %left foo | |
678 | ||
679 | %type <baz> "foo" | |
680 | %printer {baz} "foo" | |
681 | %destructor {baz} "foo" | |
682 | %left "foo" | |
683 | ||
684 | %% | |
685 | exp: foo; | |
686 | ]]) | |
687 | ||
0242bf04 | 688 | AT_BISON_CHECK([-fcaret input.y], [1], [], |
b8e7ad58 | 689 | [[input.y:8.7-11: error: %type redeclaration for foo |
0242bf04 TR |
690 | %type <baz> "foo" |
691 | ^^^^^ | |
cbaea010 | 692 | input.y:3.7-11: previous declaration |
0242bf04 TR |
693 | %type <bar> foo |
694 | ^^^^^ | |
b8e7ad58 | 695 | input.y:10.13-17: error: %destructor redeclaration for foo |
0242bf04 TR |
696 | %destructor {baz} "foo" |
697 | ^^^^^ | |
cbaea010 | 698 | input.y:5.13-17: previous declaration |
0242bf04 TR |
699 | %destructor {bar} foo |
700 | ^^^^^ | |
b8e7ad58 | 701 | input.y:9.10-14: error: %printer redeclaration for foo |
0242bf04 TR |
702 | %printer {baz} "foo" |
703 | ^^^^^ | |
cbaea010 | 704 | input.y:4.10-14: previous declaration |
0242bf04 TR |
705 | %printer {bar} foo |
706 | ^^^^^ | |
b8e7ad58 | 707 | input.y:11.1-5: error: %left redeclaration for foo |
0242bf04 TR |
708 | %left "foo" |
709 | ^^^^^ | |
cbaea010 | 710 | input.y:6.1-5: previous declaration |
0242bf04 TR |
711 | %left foo |
712 | ^^^^^ | |
df09ef2e AD |
713 | ]]) |
714 | ||
715 | AT_CLEANUP | |
716 | ||
717 | ||
5a08f1ce AD |
718 | |
719 | ## ----------------------- ## | |
720 | ## Torturing the Scanner. ## | |
721 | ## ----------------------- ## | |
722 | ||
723 | # Be sure to compile and run, so that the C compiler checks what | |
724 | # we do. | |
725 | ||
726 | AT_SETUP([Torturing the Scanner]) | |
727 | ||
71c7e24f | 728 | AT_BISON_OPTION_PUSHDEFS |
0baf7c50 | 729 | AT_DATA([input.y], []) |
da730230 | 730 | AT_BISON_CHECK([input.y], [1], [], |
b8e7ad58 | 731 | [[input.y:1.1: error: syntax error, unexpected end of file |
0baf7c50 PE |
732 | ]]) |
733 | ||
734 | ||
e9071366 | 735 | AT_DATA([input.y], |
b2ddc3f3 AD |
736 | [{} |
737 | ]) | |
0242bf04 | 738 | AT_BISON_CHECK([-fcaret input.y], [1], [], |
b8e7ad58 | 739 | [[input.y:1.1-2: error: syntax error, unexpected {...} |
0242bf04 TR |
740 | {} |
741 | ^^ | |
b2ddc3f3 AD |
742 | ]]) |
743 | ||
744 | ||
9501dc6e | 745 | AT_DATA_GRAMMAR([input.y], |
5a08f1ce AD |
746 | [[%{ |
747 | /* This is seen in GCC: a %{ and %} in middle of a comment. */ | |
748 | const char *foo = "So %{ and %} can be here too."; | |
749 | ||
dda7a53e PE |
750 | #if 0 |
751 | /* These examples test Bison while not stressing C compilers too much. | |
752 | Many C compilers mishandle backslash-newlines, so this part of the | |
753 | test is inside "#if 0". The comment and string are written so that | |
754 | the "#endif" will be seen regardless of the C compiler bugs that we | |
755 | know about, namely: | |
756 | ||
757 | HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a | |
758 | comment. | |
759 | ||
760 | The Apple Darwin compiler (as of late 2002) mishandles | |
761 | \\[newline]' within a character constant. | |
762 | ||
763 | */ | |
764 | ||
206fe6a5 | 765 | /\ |
dda7a53e PE |
766 | * A comment with backslash-newlines in it. %} *\ |
767 | \ | |
206fe6a5 | 768 | / |
dda7a53e | 769 | /* { Close the above comment, if the C compiler mishandled it. */ |
206fe6a5 PE |
770 | |
771 | char str[] = "\\ | |
772 | " A string with backslash-newlines in it %{ %} \\ | |
dda7a53e | 773 | \ |
206fe6a5 PE |
774 | ""; |
775 | ||
dda7a53e | 776 | char apostrophe = '\''; |
206fe6a5 PE |
777 | #endif |
778 | ||
5a08f1ce | 779 | #include <stdio.h> |
c4bd5bf7 | 780 | #include <stdlib.h> |
77519a7d | 781 | #include <assert.h> |
5a08f1ce AD |
782 | %} |
783 | /* %{ and %} can be here too. */ | |
784 | ||
785 | %{ | |
786 | /* Exercise pre-prologue dependency to %union. */ | |
051ade83 | 787 | typedef int value; |
5a08f1ce AD |
788 | %} |
789 | ||
790 | /* Exercise M4 quoting: '@:>@@:>@', 0. */ | |
791 | ||
792 | /* Also exercise %union. */ | |
793 | %union | |
794 | { | |
051ade83 | 795 | value ival; /* A comment to exercise an old bug. */ |
5a08f1ce AD |
796 | }; |
797 | ||
798 | ||
799 | /* Exercise post-prologue dependency to %union. */ | |
800 | %{ | |
051ade83 | 801 | static YYSTYPE value_as_yystype (value val); |
5a08f1ce AD |
802 | |
803 | /* Exercise quotes in declarations. */ | |
804 | char quote[] = "@:>@@:>@,"; | |
805 | %} | |
806 | ||
807 | %{ | |
55f48c48 AD |
808 | ]AT_YYERROR_DECLARE[ |
809 | ]AT_YYLEX_DECLARE[ | |
5a08f1ce AD |
810 | %} |
811 | ||
206fe6a5 | 812 | %type <ival> '@<:@' |
5a08f1ce AD |
813 | |
814 | /* Exercise quotes in strings. */ | |
3dc4c5fa | 815 | %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1" |
5a08f1ce AD |
816 | |
817 | %% | |
206fe6a5 | 818 | /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */ |
087b9fdf | 819 | exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt |
5a08f1ce AD |
820 | { |
821 | /* Exercise quotes in braces. */ | |
822 | char tmp[] = "@<:@%c@:>@,\n"; | |
823 | printf (tmp, $1); | |
824 | } | |
825 | ; | |
5b7f88c7 PE |
826 | |
827 | two: '\x000000000000000000000000000000000000000000000000000000000000000000002'; | |
828 | oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_'; | |
087b9fdf | 829 | output.or.oline.opt: ;|oline;;|output;;; |
5b7f88c7 | 830 | output: '#' 'o' 'u' 't' 'p' 'u' 't' ' '; |
5a08f1ce | 831 | %% |
206fe6a5 | 832 | /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */ |
5a08f1ce AD |
833 | |
834 | static YYSTYPE | |
051ade83 | 835 | value_as_yystype (value val) |
5a08f1ce AD |
836 | { |
837 | YYSTYPE res; | |
838 | res.ival = val; | |
839 | return res; | |
840 | } | |
71c7e24f | 841 | ]AT_YYERROR_DEFINE[ |
7172e23e | 842 | static int |
5a08f1ce AD |
843 | yylex (void) |
844 | { | |
cf806753 | 845 | static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\ |
5b7f88c7 PE |
846 | #output "; /* " |
847 | */ | |
cf806753 | 848 | static size_t toknum; |
77519a7d | 849 | assert (toknum < sizeof input); |
cf806753 PE |
850 | yylval = value_as_yystype (input[toknum]); |
851 | return input[toknum++]; | |
5a08f1ce | 852 | } |
5a08f1ce AD |
853 | ]]) |
854 | ||
9501dc6e AD |
855 | # Pacify Emacs'font-lock-mode: " |
856 | ||
5a08f1ce | 857 | AT_DATA([main.c], |
051ade83 | 858 | [[typedef int value; |
5a08f1ce AD |
859 | #include "input.h" |
860 | ||
861 | int yyparse (void); | |
862 | ||
863 | int | |
864 | main (void) | |
865 | { | |
866 | return yyparse (); | |
867 | } | |
868 | ]]) | |
71c7e24f | 869 | AT_BISON_OPTION_POPDEFS |
5a08f1ce | 870 | |
da730230 | 871 | AT_BISON_CHECK([-d -v -o input.c input.y]) |
91ce0b3a AD |
872 | AT_COMPILE([input.o]) |
873 | AT_COMPILE([main.o]) | |
efc6bf1b | 874 | AT_COMPILE([input], [input.o main.o]) |
1154cced | 875 | AT_PARSER_CHECK([./input], 0, |
206fe6a5 | 876 | [[[@<:@], |
5a08f1ce AD |
877 | ]]) |
878 | ||
879 | AT_CLEANUP | |
e59adf8f PE |
880 | |
881 | ||
882 | ## ---------------------- ## | |
883 | ## Typed symbol aliases. ## | |
884 | ## ---------------------- ## | |
885 | ||
886 | AT_SETUP([Typed symbol aliases]) | |
887 | ||
888 | # Bison 2.0 broke typed symbol aliases - ensure they work. | |
889 | ||
890 | AT_DATA_GRAMMAR([input.y], | |
891 | [[%union | |
892 | { | |
893 | int val; | |
894 | }; | |
895 | %token <val> MY_TOKEN "MY TOKEN" | |
896 | %type <val> exp | |
897 | %% | |
898 | exp: "MY TOKEN"; | |
899 | %% | |
900 | ]]) | |
901 | ||
da730230 | 902 | AT_BISON_CHECK([-o input.c input.y]) |
e59adf8f PE |
903 | |
904 | AT_CLEANUP | |
b50d2359 AD |
905 | |
906 | ||
907 | ## --------- ## | |
908 | ## Require. ## | |
909 | ## --------- ## | |
910 | ||
911 | m4_define([AT_CHECK_REQUIRE], | |
912 | [AT_SETUP([Require $1]) | |
913 | AT_DATA_GRAMMAR([input.y], | |
914 | [[%require "$1"; | |
915 | %% | |
916 | empty_file:; | |
917 | ]]) | |
da730230 | 918 | AT_BISON_CHECK([-o input.c input.y], $2, [], ignore) |
b50d2359 AD |
919 | AT_CLEANUP |
920 | ]) | |
921 | ||
922 | AT_CHECK_REQUIRE(1.0, 0) | |
923 | AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0) | |
924 | ## FIXME: Some day augment this version number. | |
9b8a5ce0 | 925 | AT_CHECK_REQUIRE(100.0, 63) |
1f6b3679 JD |
926 | |
927 | ||
928 | ## ------------------------------------- ## | |
929 | ## String aliases for character tokens. ## | |
930 | ## ------------------------------------- ## | |
931 | ||
932 | AT_SETUP([String aliases for character tokens]) | |
933 | ||
dab244d5 AD |
934 | # Bison once thought a character token and its alias were different |
935 | # symbols with the same user token number. | |
1f6b3679 JD |
936 | |
937 | AT_DATA_GRAMMAR([input.y], | |
938 | [[%token 'a' "a" | |
939 | %% | |
940 | start: 'a'; | |
941 | %% | |
942 | ]]) | |
943 | ||
da730230 | 944 | AT_BISON_CHECK([-o input.c input.y]) |
1f6b3679 JD |
945 | |
946 | AT_CLEANUP | |
47aee066 JD |
947 | |
948 | ||
746ee38c AD |
949 | ## -------------- ## |
950 | ## Symbol names. ## | |
951 | ## -------------- ## | |
952 | ||
953 | AT_SETUP([Symbols]) | |
954 | ||
55f48c48 | 955 | AT_BISON_OPTION_PUSHDEFS |
746ee38c AD |
956 | AT_DATA_GRAMMAR([input.y], |
957 | [[%token WITH-DASH | |
958 | %token WITHOUT_DASH "WITHOUT-DASH" | |
959 | %token WITH.PERIOD | |
960 | %token WITHOUT_PERIOD "WITHOUT.PERIOD" | |
d521ee19 | 961 | %code { |
55f48c48 AD |
962 | ]AT_YYERROR_DECLARE[ |
963 | ]AT_YYLEX_DECLARE[ | |
d521ee19 | 964 | } |
746ee38c AD |
965 | %% |
966 | start: with-dash without_dash with.period without_period; | |
967 | with-dash: WITH-DASH; | |
968 | without_dash: "WITHOUT-DASH"; | |
969 | with.period: WITH.PERIOD; | |
970 | without_period: "WITHOUT.PERIOD"; | |
971 | %% | |
55f48c48 AD |
972 | ]AT_YYERROR_DEFINE[ |
973 | ]AT_YYLEX_DEFINE[ | |
746ee38c | 974 | ]]) |
55f48c48 | 975 | AT_BISON_OPTION_POPDEFS |
746ee38c AD |
976 | |
977 | # POSIX Yacc accept periods, but not dashes. | |
1048a1c9 AD |
978 | AT_BISON_CHECK([--yacc -Wno-error input.y], [], [], |
979 | [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc] | |
980 | input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc] | |
746ee38c AD |
981 | ]]) |
982 | ||
983 | # So warn about them. | |
984 | AT_BISON_CHECK([-Wyacc input.y], [], [], | |
73370a9d VS |
985 | [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc] |
986 | input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc] | |
746ee38c AD |
987 | ]]) |
988 | ||
989 | # Dashes are fine for GNU Bison. | |
990 | AT_BISON_CHECK([-o input.c input.y]) | |
991 | ||
992 | # Make sure we don't export silly token identifiers with periods or dashes. | |
91ce0b3a | 993 | AT_COMPILE([input.o]) |
746ee38c AD |
994 | |
995 | ||
82f3355e JD |
996 | # Periods are genuine letters, they can start identifiers. |
997 | # Digits and dashes cannot. | |
746ee38c | 998 | AT_DATA_GRAMMAR([input.y], |
cdf3f113 | 999 | [[%token .GOOD |
84a1cb5a AD |
1000 | -GOOD |
1001 | 1NV4L1D | |
82f3355e | 1002 | -123 |
746ee38c | 1003 | %% |
82f3355e | 1004 | start: .GOOD GOOD |
746ee38c AD |
1005 | ]]) |
1006 | AT_BISON_CHECK([-o input.c input.y], [1], [], | |
b8e7ad58 TR |
1007 | [[input.y:10.10: error: invalid character: '-' |
1008 | input.y:11.10-16: error: invalid identifier: '1NV4L1D' | |
1009 | input.y:12.10: error: invalid character: '-' | |
746ee38c AD |
1010 | ]]) |
1011 | ||
1012 | AT_CLEANUP | |
1013 | ||
1014 | ||
ab2a9f57 AD |
1015 | ## ----------------- ## |
1016 | ## Numbered tokens. ## | |
1017 | ## ----------------- ## | |
1018 | ||
1019 | AT_SETUP([Numbered tokens]) | |
1020 | ||
83b60c97 JD |
1021 | AT_DATA_GRAMMAR([redecl.y], |
1022 | [[%token DECIMAL_1 11259375 | |
1023 | HEXADECIMAL_1 0xabcdef | |
1024 | HEXADECIMAL_2 0xFEDCBA | |
1025 | DECIMAL_2 16702650 | |
ab2a9f57 | 1026 | %% |
83b60c97 | 1027 | start: DECIMAL_1 HEXADECIMAL_2; |
8893145a AD |
1028 | ]]) |
1029 | ||
83b60c97 | 1030 | AT_BISON_CHECK([redecl.y], [1], [], |
b8e7ad58 | 1031 | [[redecl.y:10.10-22: error: user token number 11259375 redeclaration for HEXADECIMAL_1 |
b506d9bf | 1032 | redecl.y:9.8-16: previous declaration for DECIMAL_1 |
b8e7ad58 | 1033 | redecl.y:12.10-18: error: user token number 16702650 redeclaration for DECIMAL_2 |
b506d9bf | 1034 | redecl.y:11.10-22: previous declaration for HEXADECIMAL_2 |
8893145a AD |
1035 | ]]) |
1036 | ||
83b60c97 | 1037 | AT_DATA_GRAMMAR([too-large.y], |
ab2a9f57 AD |
1038 | [[%token TOO_LARGE_DEC 999999999999999999999 |
1039 | TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF | |
1040 | %% | |
1041 | start: TOO_LARGE_DEC TOO_LARGE_HEX | |
1042 | %% | |
1043 | ]]) | |
1044 | ||
83b60c97 | 1045 | AT_BISON_CHECK([too-large.y], [1], [], |
b8e7ad58 TR |
1046 | [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999' |
1047 | too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF' | |
ab2a9f57 AD |
1048 | ]]) |
1049 | ||
1050 | AT_CLEANUP | |
1051 | ||
1052 | ||
47aee066 JD |
1053 | ## --------------------- ## |
1054 | ## Unclosed constructs. ## | |
1055 | ## --------------------- ## | |
1056 | ||
1057 | AT_SETUP([Unclosed constructs]) | |
1058 | ||
dab244d5 AD |
1059 | # Bison's scan-gram.l once forgot to STRING_FINISH some unclosed |
1060 | # constructs, so they were prepended to whatever it STRING_GROW'ed | |
1061 | # next. It also threw them away rather than returning them to the | |
1062 | # parser. The effect was confusing subsequent error messages. | |
47aee066 JD |
1063 | |
1064 | AT_DATA([input.y], | |
1065 | [[%token A "a | |
1066 | %token B "b" | |
1067 | %token AB "ab" // Used to complain that "ab" was already used. | |
1068 | %token C '1 | |
1069 | %token TWO "2" | |
1070 | %token TICK_TWELVE "'12" // Used to complain that "'12" was already used. | |
1071 | ||
1072 | %% | |
1073 | ||
1074 | start: ; | |
1075 | ||
1076 | // Used to report a syntax error because it didn't see any kind of symbol | |
1077 | // identifier. | |
1078 | %type <f> 'a | |
1079 | ; | |
1080 | %type <f> "a | |
1081 | ; | |
1082 | // Used to report a syntax error because it didn't see braced code. | |
1083 | %destructor { free ($$) | |
1084 | ]]) | |
1085 | ||
505ece51 TR |
1086 | AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [], |
1087 | [[input.y:1.10-2.0: error: missing '"' at end of line | |
1088 | %token A "a | |
1089 | ^^ | |
1090 | input.y:4.10-5.0: error: missing "'" at end of line | |
1091 | %token C '1 | |
1092 | ^^ | |
1093 | input.y:14.11-15.0: error: missing "'" at end of line | |
1094 | %type <f> 'a | |
1095 | ^^ | |
1096 | input.y:16.11-17.0: error: missing '"' at end of line | |
1097 | %type <f> "a | |
1098 | ^^ | |
1099 | input.y:19.13-20.0: error: missing '}' at end of file | |
1100 | %destructor { free ($$) | |
1101 | ^^^^^^^^^^^ | |
1102 | input.y:20.1: error: syntax error, unexpected end of file | |
1103 | ]]) | |
1104 | ||
47aee066 | 1105 | AT_CLEANUP |
4d7370cb JD |
1106 | |
1107 | ||
1108 | ## ------------------------- ## | |
1109 | ## %start after first rule. ## | |
1110 | ## ------------------------- ## | |
1111 | ||
1112 | AT_SETUP([%start after first rule]) | |
1113 | ||
dab244d5 AD |
1114 | # Bison once complained that a %start after the first rule was a |
1115 | # redeclaration of the start symbol. | |
4d7370cb JD |
1116 | |
1117 | AT_DATA([input.y], | |
1118 | [[%% | |
1119 | false_start: ; | |
1120 | start: false_start ; | |
1121 | %start start; | |
1122 | ]]) | |
1123 | ||
da730230 | 1124 | AT_BISON_CHECK([-o input.c input.y]) |
4d7370cb JD |
1125 | |
1126 | AT_CLEANUP | |
26b8a438 JD |
1127 | |
1128 | ||
1129 | ## --------------------- ## | |
1130 | ## %prec takes a token. ## | |
1131 | ## --------------------- ## | |
1132 | ||
1133 | AT_SETUP([%prec takes a token]) | |
1134 | ||
1135 | # Bison once allowed %prec sym where sym was a nonterminal. | |
1136 | ||
1137 | AT_DATA([input.y], | |
1138 | [[%% | |
1139 | start: PREC %prec PREC ; | |
1140 | PREC: ; | |
1141 | ]]) | |
1142 | ||
da730230 | 1143 | AT_BISON_CHECK([input.y], [1], [], |
b8e7ad58 | 1144 | [[input.y:3.1-4: error: rule given for PREC, which is a token |
26b8a438 JD |
1145 | ]]) |
1146 | ||
1147 | AT_CLEANUP | |
8e0a5e9e JD |
1148 | |
1149 | ||
8bb3a2e7 JD |
1150 | ## ------------------------------- ## |
1151 | ## %prec's token must be defined. ## | |
1152 | ## ------------------------------- ## | |
1153 | ||
1154 | AT_SETUP([[%prec's token must be defined]]) | |
1155 | ||
1156 | # According to POSIX, a %prec token must be defined separately. | |
1157 | ||
1158 | AT_DATA([[input.y]], | |
1159 | [[%% | |
1160 | start: %prec PREC ; | |
1161 | ]]) | |
1162 | ||
02354690 | 1163 | AT_BISON_CHECK([[input.y]], [[0]], [], |
73370a9d | 1164 | [[input.y:2.8-17: warning: token for %prec is not defined: PREC [-Wother] |
8bb3a2e7 JD |
1165 | ]]) |
1166 | ||
1167 | AT_CLEANUP | |
1168 | ||
1169 | ||
6afc30cc JD |
1170 | ## -------------------------------- ## |
1171 | ## Reject unused %code qualifiers. ## | |
1172 | ## -------------------------------- ## | |
8e0a5e9e | 1173 | |
6afc30cc | 1174 | AT_SETUP([Reject unused %code qualifiers]) |
8e0a5e9e JD |
1175 | |
1176 | AT_DATA([input-c.y], | |
16dc6a9e JD |
1177 | [[%code q {} |
1178 | %code bad {} | |
1179 | %code bad {} | |
8405b70c | 1180 | %code format {} |
8e0a5e9e JD |
1181 | %% |
1182 | start: ; | |
1183 | ]]) | |
c6abeab1 | 1184 | AT_BISON_CHECK([[input-c.y]], [[1]], [], |
b8e7ad58 TR |
1185 | [[input-c.y:1.7: error: %code qualifier 'q' is not used |
1186 | input-c.y:2.7-9: error: %code qualifier 'bad' is not used | |
1187 | input-c.y:3.7-9: error: %code qualifier 'bad' is not used | |
1188 | input-c.y:4.7-12: error: %code qualifier 'format' is not used | |
08af01c2 | 1189 | ]]) |
8e0a5e9e JD |
1190 | |
1191 | AT_DATA([input-c-glr.y], | |
16dc6a9e JD |
1192 | [[%code q {} |
1193 | %code bad {} | |
1194 | %code bad {} | |
8e0a5e9e JD |
1195 | %% |
1196 | start: ; | |
1197 | ]]) | |
c6abeab1 | 1198 | AT_BISON_CHECK([[input-c-glr.y]], [[1]], [], |
b8e7ad58 TR |
1199 | [[input-c-glr.y:1.7: error: %code qualifier 'q' is not used |
1200 | input-c-glr.y:2.7-9: error: %code qualifier 'bad' is not used | |
1201 | input-c-glr.y:3.8-10: error: %code qualifier 'bad' is not used | |
08af01c2 | 1202 | ]]) |
8e0a5e9e JD |
1203 | |
1204 | AT_DATA([input-c++.y], | |
16dc6a9e JD |
1205 | [[%code q {} |
1206 | %code bad {} | |
1207 | %code q {} | |
8e0a5e9e JD |
1208 | %% |
1209 | start: ; | |
1210 | ]]) | |
c6abeab1 | 1211 | AT_BISON_CHECK([[input-c++.y]], [[1]], [], |
b8e7ad58 TR |
1212 | [[input-c++.y:1.7: error: %code qualifier 'q' is not used |
1213 | input-c++.y:2.7-9: error: %code qualifier 'bad' is not used | |
1214 | input-c++.y:3.8: error: %code qualifier 'q' is not used | |
08af01c2 | 1215 | ]]) |
8e0a5e9e JD |
1216 | |
1217 | AT_DATA([input-c++-glr.y], | |
16dc6a9e JD |
1218 | [[%code bad {} |
1219 | %code q {} | |
1220 | %code q {} | |
8e0a5e9e JD |
1221 | %% |
1222 | start: ; | |
1223 | ]]) | |
c6abeab1 | 1224 | AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [], |
b8e7ad58 TR |
1225 | [[input-c++-glr.y:1.7-9: error: %code qualifier 'bad' is not used |
1226 | input-c++-glr.y:2.7: error: %code qualifier 'q' is not used | |
1227 | input-c++-glr.y:3.7: error: %code qualifier 'q' is not used | |
3fc65ead JD |
1228 | ]]) |
1229 | ||
1230 | AT_DATA([special-char-@@.y], | |
16dc6a9e JD |
1231 | [[%code bad {} |
1232 | %code q {} | |
1233 | %code q {} | |
3fc65ead JD |
1234 | %% |
1235 | start: ; | |
1236 | ]]) | |
c6abeab1 | 1237 | AT_BISON_CHECK([[special-char-@@.y]], [[1]], [], |
b8e7ad58 TR |
1238 | [[special-char-@@.y:1.7-9: error: %code qualifier 'bad' is not used |
1239 | special-char-@@.y:2.7: error: %code qualifier 'q' is not used | |
1240 | special-char-@@.y:3.7: error: %code qualifier 'q' is not used | |
3fc65ead JD |
1241 | ]]) |
1242 | ||
1243 | AT_DATA([special-char-@:>@.y], | |
16dc6a9e JD |
1244 | [[%code bad {} |
1245 | %code q {} | |
1246 | %code q {} | |
3fc65ead JD |
1247 | %% |
1248 | start: ; | |
1249 | ]]) | |
c6abeab1 | 1250 | AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [], |
b8e7ad58 TR |
1251 | [[special-char-@:>@.y:1.7-9: error: %code qualifier 'bad' is not used |
1252 | special-char-@:>@.y:2.7: error: %code qualifier 'q' is not used | |
1253 | special-char-@:>@.y:3.7: error: %code qualifier 'q' is not used | |
08af01c2 | 1254 | ]]) |
8e0a5e9e JD |
1255 | |
1256 | AT_CLEANUP | |
7eb8a0bc JD |
1257 | |
1258 | ||
1259 | ## ---------------- ## | |
1260 | ## %define errors. ## | |
1261 | ## ---------------- ## | |
1262 | ||
1263 | AT_SETUP([%define errors]) | |
1264 | ||
0b6d43c5 | 1265 | AT_DATA([input-redefined.y], |
16dc6a9e JD |
1266 | [[%define var "value1" |
1267 | %define var "value1" | |
1268 | %define var "value2" | |
1269 | %define special1 "@:>@" | |
1270 | %define special2 "@<:@" | |
7eb8a0bc JD |
1271 | %% |
1272 | start: ; | |
1273 | ]]) | |
1274 | ||
0b6d43c5 | 1275 | AT_BISON_CHECK([[input-redefined.y]], [[1]], [], |
b8e7ad58 | 1276 | [[input-redefined.y:2.9-11: error: %define variable 'var' redefined |
6b1e1872 | 1277 | input-redefined.y:1.9-11: previous definition |
b8e7ad58 | 1278 | input-redefined.y:3.10-12: error: %define variable 'var' redefined |
6b1e1872 | 1279 | input-redefined.y:2.9-11: previous definition |
0b6d43c5 JD |
1280 | ]]) |
1281 | ||
1282 | AT_DATA([input-unused.y], | |
1283 | [[%define var "value" | |
1284 | %% | |
1285 | start: ; | |
1286 | ]]) | |
1287 | ||
c6abeab1 | 1288 | AT_BISON_CHECK([[input-unused.y]], [[1]], [], |
b8e7ad58 | 1289 | [[input-unused.y:1.9-11: error: %define variable 'var' is not used |
7eb8a0bc JD |
1290 | ]]) |
1291 | ||
1292 | AT_CLEANUP | |
c1d19e10 | 1293 | |
58697c6d | 1294 | |
de5ab940 JD |
1295 | ## ----------------------------------- ## |
1296 | ## %define, --define, --force-define. ## | |
1297 | ## ----------------------------------- ## | |
58697c6d | 1298 | |
c6abeab1 | 1299 | AT_SETUP([[%define, --define, --force-define]]) |
de5ab940 | 1300 | |
c6abeab1 | 1301 | AT_DATA([[skel.c]], |
de5ab940 JD |
1302 | [[m4@&t@_divert_push(0)@ |
1303 | @output(b4_parser_file_name@)@ | |
1304 | [var-dd: ]b4_percent_define_get([[var-dd]])[ | |
1305 | var-ff: ]b4_percent_define_get([[var-ff]])[ | |
de5ab940 JD |
1306 | var-dfg: ]b4_percent_define_get([[var-dfg]])[ |
1307 | var-fd: ]b4_percent_define_get([[var-fd]]) | |
1308 | m4@&t@_divert_pop(0) | |
1309 | ]]) | |
c6abeab1 | 1310 | AT_DATA([[input.y]], |
0b6d43c5 | 1311 | [[%define var-dfg "gram" |
58697c6d AD |
1312 | %% |
1313 | start: ; | |
1314 | ]]) | |
de5ab940 JD |
1315 | AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \ |
1316 | -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \ | |
de5ab940 JD |
1317 | -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \ |
1318 | -Fvar-fd=cmd-f -Dvar-fd=cmd-d \ | |
c6abeab1 | 1319 | --skeleton ./skel.c input.y]]) |
de5ab940 JD |
1320 | AT_CHECK([[cat input.tab.c]], [[0]], |
1321 | [[var-dd: cmd-d2 | |
1322 | var-ff: cmd-f2 | |
de5ab940 JD |
1323 | var-dfg: cmd-f |
1324 | var-fd: cmd-d | |
58697c6d AD |
1325 | ]]) |
1326 | ||
c6abeab1 | 1327 | AT_DATA([[input-dg.y]], |
0b6d43c5 JD |
1328 | [[%define var "gram" |
1329 | %% | |
1330 | start: ; | |
1331 | ]]) | |
0b6d43c5 | 1332 | AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [], |
b8e7ad58 | 1333 | [[input-dg.y:1.9-11: error: %define variable 'var' redefined |
9c4788b7 | 1334 | <command line>:2: previous definition |
0b6d43c5 JD |
1335 | ]]) |
1336 | ||
505ece51 TR |
1337 | AT_DATA([[input-dg.y]], |
1338 | [[%define var "gram" | |
1339 | %% | |
1340 | start: ; | |
1341 | ]]) | |
1342 | AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [], | |
1343 | [[input-dg.y:1.9-11: error: %define variable 'var' redefined | |
1344 | %define var "gram" | |
1345 | ^^^ | |
9c4788b7 | 1346 | <command line>:3: previous definition |
505ece51 TR |
1347 | ]]) |
1348 | ||
c6abeab1 JD |
1349 | AT_DATA([[input-unused.y]], |
1350 | [[%% | |
1351 | start: ; | |
1352 | ]]) | |
1353 | AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [], | |
9c4788b7 TR |
1354 | [[<command line>:2: error: %define variable 'unused-d' is not used |
1355 | <command line>:3: error: %define variable 'unused-f' is not used | |
c6abeab1 JD |
1356 | ]]) |
1357 | ||
58697c6d AD |
1358 | AT_CLEANUP |
1359 | ||
c1d19e10 | 1360 | ## --------------------------- ## |
d782395d | 1361 | ## %define Boolean variables. ## |
c1d19e10 PB |
1362 | ## --------------------------- ## |
1363 | ||
1a06f28e | 1364 | AT_SETUP([["%define" Boolean variables]]) |
c1d19e10 PB |
1365 | |
1366 | AT_DATA([Input.y], | |
1367 | [[%language "Java" | |
1368 | %define public "maybe" | |
1369 | %define parser_class_name "Input" | |
1370 | %% | |
1371 | start: ; | |
1372 | ]]) | |
1373 | ||
da730230 | 1374 | AT_BISON_CHECK([[Input.y]], [1], [], |
b8e7ad58 | 1375 | [[Input.y:2.9-14: error: invalid value for %define Boolean variable 'public' |
c1d19e10 PB |
1376 | ]]) |
1377 | ||
1378 | AT_CLEANUP | |
d782395d | 1379 | |
f4909773 JD |
1380 | ## ------------------------ ## |
1381 | ## %define enum variables. ## | |
1382 | ## ------------------------ ## | |
7254f6a8 | 1383 | |
1a06f28e AD |
1384 | AT_SETUP([["%define" enum variables]]) |
1385 | ||
1386 | # Check errors from the front-end, and the back-end. Since the | |
1387 | # front-end quits before calling the back-end, these tests cannot be | |
1388 | # fused. | |
7254f6a8 | 1389 | |
f4909773 | 1390 | # Front-end. |
7254f6a8 | 1391 | AT_DATA([[input.y]], |
f3bc3386 | 1392 | [[%define lr.default-reduction bogus |
7254f6a8 JD |
1393 | %% |
1394 | start: ; | |
1395 | ]]) | |
1a06f28e | 1396 | AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]], |
f3bc3386 | 1397 | [[input.y:1.9-28: error: invalid value for %define variable 'lr.default-reduction': 'bogus' |
1a06f28e AD |
1398 | %define lr.default-reduction bogus |
1399 | ^^^^^^^^^^^^^^^^^^^^ | |
f3bc3386 AD |
1400 | input.y:1.9-28: accepted value: 'most' |
1401 | input.y:1.9-28: accepted value: 'consistent' | |
1402 | input.y:1.9-28: accepted value: 'accepting' | |
7254f6a8 JD |
1403 | ]]) |
1404 | ||
f4909773 | 1405 | # Back-end. |
67212941 | 1406 | AT_DATA([[input.y]], |
cf499cff | 1407 | [[%define api.push-pull neither |
67212941 JD |
1408 | %% |
1409 | start: ; | |
1410 | ]]) | |
1a06f28e | 1411 | AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]], |
b8e7ad58 | 1412 | [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither' |
1a06f28e AD |
1413 | %define api.push-pull neither |
1414 | ^^^^^^^^^^^^^ | |
c6c8de16 TR |
1415 | input.y:1.9-21: accepted value: 'pull' |
1416 | input.y:1.9-21: accepted value: 'push' | |
1417 | input.y:1.9-21: accepted value: 'both' | |
67212941 JD |
1418 | ]]) |
1419 | ||
1420 | AT_CLEANUP | |
1421 | ||
1422 | ## -------------------------------- ## | |
1423 | ## %define backward compatibility. ## | |
1424 | ## -------------------------------- ## | |
1425 | ||
1a06f28e | 1426 | AT_SETUP([["%define" backward compatibility]]) |
67212941 | 1427 | |
1a06f28e | 1428 | # The error messages tell us whether the variables are properly updated. |
d782395d | 1429 | AT_DATA([[input.y]], |
1a06f28e AD |
1430 | [[%define api.push_pull both |
1431 | %define lr.keep_unreachable_states maybe | |
1432 | %define namespace "foo" | |
1433 | %define api.namespace "foo" | |
1434 | %define variant | |
d782395d JD |
1435 | %% |
1436 | start: ; | |
1437 | ]]) | |
ea9e670d | 1438 | AT_BISON_CHECK([[-fcaret input.y]], [1], [], |
1a06f28e AD |
1439 | [[input.y:1.9-21: warning: deprecated directive, use '%define api.push-pull both' [-Wdeprecated] |
1440 | %define api.push_pull both | |
ea9e670d | 1441 | ^^^^^^^^^^^^^ |
1a06f28e AD |
1442 | input.y:2.9-34: warning: deprecated directive, use '%define lr.keep-unreachable-state maybe' [-Wdeprecated] |
1443 | %define lr.keep_unreachable_states maybe | |
1444 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
1445 | input.y:3.9-17: warning: deprecated directive, use '%define api.namespace foo' [-Wdeprecated] | |
1446 | %define namespace "foo" | |
1447 | ^^^^^^^^^ | |
1448 | input.y:4.9-21: error: %define variable 'api.namespace' redefined | |
1449 | %define api.namespace "foo" | |
ea9e670d | 1450 | ^^^^^^^^^^^^^ |
1a06f28e AD |
1451 | input.y:3.9-17: previous definition |
1452 | %define namespace "foo" | |
1453 | ^^^^^^^^^ | |
1454 | input.y:5.9-15: warning: deprecated directive, use '%define api.value.type variant' [-Wdeprecated] | |
1455 | %define variant | |
1456 | ^^^^^^^ | |
67212941 JD |
1457 | ]]) |
1458 | ||
d782395d | 1459 | AT_CLEANUP |
793fbca5 | 1460 | |
d9df47b6 JD |
1461 | ## ------------------------- ## |
1462 | ## Unused %define api.pure. ## | |
1463 | ## ------------------------- ## | |
1464 | ||
1465 | AT_SETUP([[Unused %define api.pure]]) | |
1466 | ||
1467 | # AT_CHECK_API_PURE(DECLS, VALUE) | |
1468 | # ------------------------------- | |
1469 | # Make sure Bison reports that `%define api.pure VALUE' is unused when DECLS | |
1470 | # are specified. | |
1471 | m4_define([AT_CHECK_API_PURE], | |
1472 | [ | |
1473 | AT_DATA([[input.y]], | |
1474 | [[%define api.pure ]$2[ | |
1475 | ]$1[ | |
1476 | %% | |
1477 | start: ; | |
1478 | ]]) | |
1479 | ||
c6abeab1 | 1480 | AT_BISON_CHECK([[input.y]], [[1]], [], |
b8e7ad58 | 1481 | [[input.y:1.9-16: error: %define variable 'api.pure' is not used |
d9df47b6 JD |
1482 | ]]) |
1483 | ]) | |
1484 | ||
1485 | AT_CHECK_API_PURE([[%language "c++" %defines]], [[]]) | |
cf499cff | 1486 | AT_CHECK_API_PURE([[%language "c++" %defines]], [[false]]) |
d9df47b6 | 1487 | AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[""]]) |
cf499cff JD |
1488 | AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[false]]) |
1489 | AT_CHECK_API_PURE([[%language "java"]], [[true]]) | |
1490 | AT_CHECK_API_PURE([[%language "java"]], [[false]]) | |
d9df47b6 JD |
1491 | |
1492 | AT_CLEANUP | |
1493 | ||
793fbca5 JD |
1494 | ## -------------------------------- ## |
1495 | ## C++ namespace reference errors. ## | |
1496 | ## -------------------------------- ## | |
1497 | ||
1498 | AT_SETUP([[C++ namespace reference errors]]) | |
1499 | ||
1500 | # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...) | |
1501 | # ------------------------------------------------------------- | |
1502 | # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL". | |
1503 | m4_define([AT_CHECK_NAMESPACE_ERROR], | |
1504 | [ | |
1505 | AT_DATA([[input.y]], | |
1506 | [[%language "C++" | |
1507 | %defines | |
67501061 | 1508 | %define api.namespace "]$1[" |
793fbca5 JD |
1509 | %% |
1510 | start: ; | |
1511 | ]]) | |
1512 | ||
da730230 | 1513 | AT_BISON_CHECK([[input.y]], [1], [], |
793fbca5 | 1514 | [m4_foreach([b4_arg], m4_dquote(m4_shift($@)), |
11b19212 | 1515 | [[input.y:3.9-21: error: ]b4_arg[ |
793fbca5 JD |
1516 | ]])]) |
1517 | ]) | |
1518 | ||
1519 | AT_CHECK_NAMESPACE_ERROR([[]], | |
1520 | [[namespace reference is empty]]) | |
1521 | AT_CHECK_NAMESPACE_ERROR([[ ]], | |
1522 | [[namespace reference is empty]]) | |
1523 | AT_CHECK_NAMESPACE_ERROR([[foo::::bar]], | |
1524 | [[namespace reference has consecutive "::"]]) | |
1525 | AT_CHECK_NAMESPACE_ERROR([[foo:: ::bar]], | |
1526 | [[namespace reference has consecutive "::"]]) | |
1527 | AT_CHECK_NAMESPACE_ERROR([[::::bar]], | |
1528 | [[namespace reference has consecutive "::"]]) | |
1529 | AT_CHECK_NAMESPACE_ERROR([[:: ::bar]], | |
1530 | [[namespace reference has consecutive "::"]]) | |
1531 | AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ::]], | |
1532 | [[namespace reference has consecutive "::"]], | |
1533 | [[namespace reference has a trailing "::"]]) | |
1534 | AT_CHECK_NAMESPACE_ERROR([[foo::bar::]], | |
1535 | [[namespace reference has a trailing "::"]]) | |
1536 | AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ]], | |
1537 | [[namespace reference has a trailing "::"]]) | |
1538 | AT_CHECK_NAMESPACE_ERROR([[::]], | |
1539 | [[namespace reference has a trailing "::"]]) | |
1540 | ||
1541 | AT_CLEANUP | |
3208e3f4 JD |
1542 | |
1543 | ## ------------------------ ## | |
1544 | ## Bad character literals. ## | |
1545 | ## ------------------------ ## | |
1546 | ||
1547 | # Bison used to accept character literals that were empty or contained | |
1548 | # too many characters. | |
1549 | ||
b70c7fb4 JD |
1550 | # FIXME: AT_DATA or some variant of AT_DATA may eventually permit |
1551 | # the final newline to be omitted. See the threads starting at | |
3208e3f4 JD |
1552 | # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>. |
1553 | ||
1554 | AT_SETUP([[Bad character literals]]) | |
1555 | ||
1556 | AT_DATA([empty.y], | |
1557 | [[%% | |
1558 | start: ''; | |
1559 | start: ' | |
1560 | ]]) | |
ff020c30 | 1561 | AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]]) |
3208e3f4 | 1562 | |
c1b2677a | 1563 | AT_BISON_CHECK([-fcaret empty.y], [1], [], |
73370a9d | 1564 | [[empty.y:2.8-9: warning: empty character literal [-Wother] |
c1b2677a TR |
1565 | start: ''; |
1566 | ^^ | |
b8e7ad58 | 1567 | empty.y:3.8-4.0: error: missing "'" at end of line |
c1b2677a TR |
1568 | start: ' |
1569 | ^ | |
1570 | empty.y:3.8-4.0: warning: empty character literal [-Wother] | |
1571 | start: ' | |
1572 | ^ | |
b8e7ad58 | 1573 | empty.y:4.8: error: missing "'" at end of file |
c1b2677a TR |
1574 | start: ' |
1575 | ^ | |
1576 | empty.y:4.8: warning: empty character literal [-Wother] | |
1577 | start: ' | |
1578 | ^ | |
3208e3f4 JD |
1579 | ]]) |
1580 | ||
1581 | AT_DATA([two.y], | |
1582 | [[%% | |
1583 | start: 'ab'; | |
1584 | start: 'ab | |
1585 | ]]) | |
ff020c30 | 1586 | AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]]) |
3208e3f4 JD |
1587 | |
1588 | AT_BISON_CHECK([two.y], [1], [], | |
73370a9d | 1589 | [[two.y:2.8-11: warning: extra characters in character literal [-Wother] |
b8e7ad58 | 1590 | two.y:3.8-4.0: error: missing "'" at end of line |
c1b2677a | 1591 | two.y:3.8-4.0: warning: extra characters in character literal [-Wother] |
b8e7ad58 | 1592 | two.y:4.8-10: error: missing "'" at end of file |
c1b2677a | 1593 | two.y:4.8-10: warning: extra characters in character literal [-Wother] |
3208e3f4 JD |
1594 | ]]) |
1595 | ||
1596 | AT_DATA([three.y], | |
1597 | [[%% | |
1598 | start: 'abc'; | |
1599 | start: 'abc | |
1600 | ]]) | |
ff020c30 | 1601 | AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]]) |
3208e3f4 JD |
1602 | |
1603 | AT_BISON_CHECK([three.y], [1], [], | |
73370a9d | 1604 | [[three.y:2.8-12: warning: extra characters in character literal [-Wother] |
b8e7ad58 | 1605 | three.y:3.8-4.0: error: missing "'" at end of line |
c1b2677a | 1606 | three.y:3.8-4.0: warning: extra characters in character literal [-Wother] |
b8e7ad58 | 1607 | three.y:4.8-11: error: missing "'" at end of file |
c1b2677a | 1608 | three.y:4.8-11: warning: extra characters in character literal [-Wother] |
3208e3f4 JD |
1609 | ]]) |
1610 | ||
1611 | AT_CLEANUP | |
c2724603 JD |
1612 | |
1613 | ## ------------------------- ## | |
1614 | ## Bad escapes in literals. ## | |
1615 | ## ------------------------- ## | |
1616 | ||
1617 | AT_SETUP([[Bad escapes in literals]]) | |
1618 | ||
1619 | AT_DATA([input.y], | |
1620 | [[%% | |
1621 | start: '\777' '\0' '\xfff' '\x0' | |
1622 | '\uffff' '\u0000' '\Uffffffff' '\U00000000' | |
1623 | '\ ' '\A'; | |
1624 | ]]) | |
3bed3a75 | 1625 | |
b70c7fb4 | 1626 | # It is not easy to create special characters, we cannot even trust tr. |
3bed3a75 AD |
1627 | # Beside we cannot even expect "echo '\0'" to output two characters |
1628 | # (well three with \n): at least Bash 3.2 converts the two-character | |
1629 | # sequence "\0" into a single NUL character. | |
ff020c30 | 1630 | AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \ |
b70c7fb4 | 1631 | || exit 77]]) |
c2724603 JD |
1632 | |
1633 | AT_BISON_CHECK([input.y], [1], [], | |
b8e7ad58 | 1634 | [[input.y:2.9-12: error: invalid number after \-escape: 777 |
73370a9d | 1635 | input.y:2.8-13: warning: empty character literal [-Wother] |
b8e7ad58 | 1636 | input.y:2.16-17: error: invalid number after \-escape: 0 |
73370a9d | 1637 | input.y:2.15-18: warning: empty character literal [-Wother] |
b8e7ad58 | 1638 | input.y:2.21-25: error: invalid number after \-escape: xfff |
73370a9d | 1639 | input.y:2.20-26: warning: empty character literal [-Wother] |
b8e7ad58 | 1640 | input.y:2.29-31: error: invalid number after \-escape: x0 |
73370a9d | 1641 | input.y:2.28-32: warning: empty character literal [-Wother] |
b8e7ad58 | 1642 | input.y:3.9-14: error: invalid number after \-escape: uffff |
73370a9d | 1643 | input.y:3.8-15: warning: empty character literal [-Wother] |
b8e7ad58 | 1644 | input.y:3.18-23: error: invalid number after \-escape: u0000 |
73370a9d | 1645 | input.y:3.17-24: warning: empty character literal [-Wother] |
b8e7ad58 | 1646 | input.y:3.27-36: error: invalid number after \-escape: Uffffffff |
73370a9d | 1647 | input.y:3.26-37: warning: empty character literal [-Wother] |
b8e7ad58 | 1648 | input.y:3.40-49: error: invalid number after \-escape: U00000000 |
73370a9d | 1649 | input.y:3.39-50: warning: empty character literal [-Wother] |
b8e7ad58 | 1650 | input.y:4.9-10: error: invalid character after \-escape: ' ' |
73370a9d | 1651 | input.y:4.8-11: warning: empty character literal [-Wother] |
b8e7ad58 | 1652 | input.y:4.14-15: error: invalid character after \-escape: A |
73370a9d | 1653 | input.y:4.13-16: warning: empty character literal [-Wother] |
b8e7ad58 TR |
1654 | input.y:5.9-16: error: invalid character after \-escape: \t |
1655 | input.y:5.17: error: invalid character after \-escape: \f | |
1656 | input.y:5.18: error: invalid character after \-escape: \0 | |
1657 | input.y:5.19: error: invalid character after \-escape: \001 | |
c2724603 JD |
1658 | ]]) |
1659 | ||
1660 | AT_CLEANUP | |
bf35c71c JD |
1661 | |
1662 | ## ------------------------- ## | |
1663 | ## LAC: Errors for %define. ## | |
1664 | ## ------------------------- ## | |
1665 | ||
1666 | AT_SETUP([[LAC: Errors for %define]]) | |
1667 | ||
1668 | AT_DATA([[input.y]], | |
1669 | [[%% | |
1670 | start: ; | |
1671 | ]]) | |
1672 | ||
1673 | # parse.lac.* options are useless if LAC isn't actually activated. | |
1674 | AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]], | |
1675 | [[1]], [], | |
9c4788b7 | 1676 | [[<command line>:2: error: %define variable 'parse.lac.es-capacity-initial' is not used |
bf35c71c | 1677 | ]]) |
107844a3 JD |
1678 | AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]], |
1679 | [[1]], [], | |
9c4788b7 | 1680 | [[<command line>:2: error: %define variable 'parse.lac.memory-trace' is not used |
107844a3 | 1681 | ]]) |
bf35c71c JD |
1682 | |
1683 | AT_CLEANUP | |
bf0e44e8 JD |
1684 | |
1685 | ## --------------------------------------------- ## | |
1686 | ## -Werror is not affected by -Wnone and -Wall. ## | |
1687 | ## --------------------------------------------- ## | |
1688 | ||
1689 | AT_SETUP([[-Werror is not affected by -Wnone and -Wall]]) | |
1690 | ||
1691 | AT_DATA([[input.y]], | |
1692 | [[%% | |
1693 | foo-bar: ; | |
1694 | ]]) | |
1695 | ||
1696 | # -Werror is not enabled by -Wall or equivalent. | |
1697 | AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]], | |
73370a9d | 1698 | [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar [-Wyacc] |
bf0e44e8 JD |
1699 | ]]) |
1700 | AT_BISON_CHECK([[-W input.y]], [[0]], [[]], | |
73370a9d | 1701 | [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar [-Wyacc] |
bf0e44e8 JD |
1702 | ]]) |
1703 | AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]], | |
73370a9d | 1704 | [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar [-Wyacc] |
bf0e44e8 JD |
1705 | ]]) |
1706 | ||
1707 | # -Werror is not disabled by -Wnone or equivalent. | |
1708 | AT_BISON_CHECK([[-Werror,none,yacc input.y]], [[1]], [[]], [[stderr]]) | |
1709 | AT_CHECK([[sed 's/^.*bison:/bison:/' stderr]], [[0]], | |
46bdb8ec | 1710 | [[input.y:2.1-7: error: POSIX Yacc forbids dashes in symbol names: foo-bar [-Werror=yacc] |
bf0e44e8 JD |
1711 | ]]) |
1712 | [mv stderr experr] | |
1713 | AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]]) | |
1714 | ||
1715 | AT_CLEANUP | |
32ae07ef AD |
1716 | |
1717 | ||
1718 | ## ------------------------------------------------------ ## | |
1719 | ## %name-prefix and %define api.prefix are incompatible. ## | |
1720 | ## ------------------------------------------------------ ## | |
1721 | ||
1a06f28e | 1722 | AT_SETUP([[%name-prefix and api.prefix are incompatible]]) |
32ae07ef AD |
1723 | |
1724 | # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION) | |
1725 | # -------------------------------------------- | |
1726 | m4_pushdef([AT_TEST], | |
1727 | [AT_DATA([[input.y]], | |
1728 | [[$1 | |
1729 | %% | |
1730 | exp:; | |
1731 | ]]) | |
1732 | AT_BISON_CHECK([[$2 input.y]], [[1]], [[]], | |
b8e7ad58 | 1733 | [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together |
32ae07ef AD |
1734 | ]]) |
1735 | ]) | |
1736 | ||
1737 | AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18]) | |
9c4788b7 TR |
1738 | AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:2]) |
1739 | AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:2]) | |
32ae07ef AD |
1740 | AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18]) |
1741 | ||
1742 | m4_popdef([AT_TEST]) | |
1743 | ||
1744 | AT_CLEANUP | |
8617d87e AD |
1745 | |
1746 | ||
26313726 AD |
1747 | ## -------------- ## |
1748 | ## Stray $ or @. ## | |
1749 | ## -------------- ## | |
1750 | ||
1751 | AT_SETUP([[Stray $ or @]]) | |
1752 | ||
1c292035 AD |
1753 | # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to |
1754 | # check that the warnings are reported once, not three times. | |
1755 | ||
26313726 | 1756 | AT_DATA_GRAMMAR([[input.y]], |
4323e0da AD |
1757 | [[%type <TYPE> exp |
1758 | %token <TYPE> TOK TOK2 | |
1c292035 | 1759 | %destructor { $%; @%; } <*> exp TOK; |
26313726 | 1760 | %initial-action { $%; @%; }; |
1c292035 | 1761 | %printer { $%; @%; } <*> exp TOK; |
b8a8cc42 | 1762 | %{ $ @ %} // Should not warn. |
26313726 | 1763 | %% |
1c292035 | 1764 | exp: TOK { $%; @%; $$ = $1; }; |
b8a8cc42 AD |
1765 | %% |
1766 | $ @ // Should not warn. | |
26313726 AD |
1767 | ]]) |
1768 | ||
b8a8cc42 | 1769 | AT_BISON_CHECK([[-Wall input.y]], 0, [], |
4323e0da AD |
1770 | [[input.y:11.19: warning: stray '$' [-Wother] |
1771 | input.y:11.23: warning: stray '@' [-Wother] | |
1772 | input.y:12.19: warning: stray '$' [-Wother] | |
1773 | input.y:12.23: warning: stray '@' [-Wother] | |
1774 | input.y:13.19: warning: stray '$' [-Wother] | |
1775 | input.y:13.23: warning: stray '@' [-Wother] | |
b8a8cc42 AD |
1776 | input.y:16.19: warning: stray '$' [-Wother] |
1777 | input.y:16.23: warning: stray '@' [-Wother] | |
26313726 AD |
1778 | ]]) |
1779 | ||
1780 | AT_CLEANUP | |
1781 | ||
1782 | ||
1783 | ||
8617d87e AD |
1784 | ## ---------------- ## |
1785 | ## Code injection. ## | |
1786 | ## ---------------- ## | |
1787 | ||
1788 | ||
1789 | AT_SETUP([[Code injection]]) | |
1790 | ||
1791 | m4_pattern_allow([^m4_errprintn$]) | |
1792 | ||
1793 | # AT_TEST([MACRO]) | |
1794 | # ---------------- | |
1795 | # Try to have MACRO be run by bison. | |
1796 | m4_pushdef([AT_TEST], | |
1797 | [AT_DATA([[input.y]], | |
1798 | [[%type <$1(DEAD %type)> exp | |
1799 | %token <$1(DEAD %token)> a | |
4323e0da | 1800 | %token b |
8617d87e AD |
1801 | %initial-action |
1802 | { | |
1803 | $$; | |
1804 | $<$1(DEAD %initial-action)>$ | |
1805 | }; | |
9a86ee60 AD |
1806 | %printer |
1807 | { | |
1808 | $$ | |
1809 | $<$1(DEAD %printer)>$ | |
1810 | } <> <*>; | |
1811 | %lex-param | |
1812 | { | |
1813 | $1(DEAD %lex-param) | |
1814 | }; | |
1815 | %parse-param | |
1816 | { | |
1817 | $1(DEAD %parse-param) | |
1818 | }; | |
8617d87e AD |
1819 | %% |
1820 | exp: | |
4323e0da | 1821 | a a[name] b |
8617d87e AD |
1822 | { |
1823 | $$; | |
1824 | $][1; | |
1825 | $<$1(DEAD action 1)>$ | |
1826 | $<$1(DEAD action 2)>1 | |
4323e0da | 1827 | $<$1(DEAD action 3)>name |
8617d87e AD |
1828 | $<$1(DEAD action 4)>0 |
1829 | ; | |
1830 | }; | |
1831 | ]]) | |
1832 | ||
1833 | # FIXME: Provide a means to iterate over all the skeletons. | |
1834 | AT_BISON_CHECK([[-d input.y]]) | |
1835 | AT_BISON_CHECK([[-d -S glr.c input.y]]) | |
1836 | AT_BISON_CHECK([[-d -S lalr1.cc input.y]]) | |
1837 | AT_BISON_CHECK([[-d -S glr.cc input.y]]) | |
1838 | AT_BISON_CHECK([[ -S lalr1.java input.y]]) | |
1839 | ]) | |
1840 | ||
1841 | AT_TEST([m4_errprintn]) | |
1842 | AT_TEST([@:>@m4_errprintn]) | |
1843 | ||
1844 | m4_popdef([AT_TEST]) | |
1845 | ||
1846 | AT_CLEANUP | |
0f92546f TR |
1847 | |
1848 | ##----------------------- ## | |
1849 | ## Deprecated directives. ## | |
1850 | ## ---------------------- ## | |
1851 | ||
1852 | AT_SETUP([[Deprecated directives]]) | |
1853 | ||
1854 | AT_KEYWORDS([[deprec]]) | |
1855 | ||
1856 | AT_DATA_GRAMMAR([[input.y]], | |
1857 | [[ | |
1858 | %default_prec | |
1859 | %error_verbose | |
ed91d427 | 1860 | %expect_rr 0 |
0f92546f TR |
1861 | %file-prefix = "foo" |
1862 | %file-prefix | |
1863 | = | |
1864 | "bar" | |
1865 | %fixed-output_files | |
1866 | %fixed_output-files | |
1867 | %fixed-output-files | |
1868 | %name-prefix= "foo" | |
1869 | %no-default_prec | |
1870 | %no_default-prec | |
1871 | %no_lines | |
1872 | %output = "foo" | |
1873 | %pure_parser | |
1874 | %token_table | |
ed91d427 | 1875 | %glr-parser |
0f92546f TR |
1876 | %% exp : '0' |
1877 | ]]) | |
1878 | ||
1879 | AT_BISON_CHECK([[input.y]], [[0]], [[]], | |
1880 | [[input.y:10.1-13: warning: deprecated directive: '%default_prec', use '%default-prec' [-Wdeprecated] | |
1881 | input.y:11.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated] | |
1882 | input.y:12.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated] | |
1883 | input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated] | |
1884 | input.y:14.1-15.2: warning: deprecated directive: '%file-prefix\n =', use '%file-prefix' [-Wdeprecated] | |
1885 | input.y:17.1-19: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated] | |
1886 | input.y:18.1-19: warning: deprecated directive: '%fixed_output-files', use '%fixed-output-files' [-Wdeprecated] | |
1887 | input.y:20.1-13: warning: deprecated directive: '%name-prefix=', use '%name-prefix' [-Wdeprecated] | |
1888 | input.y:21.1-16: warning: deprecated directive: '%no-default_prec', use '%no-default-prec' [-Wdeprecated] | |
1889 | input.y:22.1-16: warning: deprecated directive: '%no_default-prec', use '%no-default-prec' [-Wdeprecated] | |
1890 | input.y:23.1-9: warning: deprecated directive: '%no_lines', use '%no-lines' [-Wdeprecated] | |
1891 | input.y:24.1-9: warning: deprecated directive: '%output =', use '%output' [-Wdeprecated] | |
1892 | input.y:25.1-12: warning: deprecated directive: '%pure_parser', use '%pure-parser' [-Wdeprecated] | |
1893 | input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated] | |
0f92546f TR |
1894 | ]]) |
1895 | ||
1896 | AT_CLEANUP | |
1897 | ||
1898 | ## ---------------------------- ## | |
1899 | ## Unput's effect on locations. ## | |
1900 | ## ---------------------------- ## | |
1901 | dnl When the scanner detects a deprecated construct, it unputs the correct | |
1902 | dnl version, but it should *not* have any impact on the scanner cursor. If it | |
1903 | dnl does, the locations of directives on the same line become erroneous. | |
1904 | ||
1905 | AT_SETUP([[Unput's effect on locations]]) | |
1906 | ||
1907 | AT_KEYWORDS([[deprec]]) | |
1908 | ||
1909 | AT_DATA_GRAMMAR([[input.y]], | |
1910 | [[ | |
1911 | %glr-parser | |
1912 | %expect_rr 42 %expect_rr 42 | |
1913 | %expect_rr 42 | |
1914 | %error_verbose %error_verbose | |
1915 | %error_verbose | |
1916 | %% exp: '0' | |
1917 | ]]) | |
1918 | ||
1919 | AT_BISON_CHECK([[input.y]], [[1]], [[]], | |
1920 | [[input.y:11.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated] | |
1921 | input.y:11.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated] | |
1922 | input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated] | |
1923 | input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated] | |
1924 | input.y:13.16-29: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated] | |
1925 | input.y:13.11-21: error: %define variable 'parse.error' redefined | |
1926 | input.y:13-6: previous definition | |
1927 | input.y:14.16-29: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated] | |
1928 | input.y:14.11-21: error: %define variable 'parse.error' redefined | |
1929 | input.y:13.11-21: previous definition | |
1930 | ]]) | |
1931 | ||
1932 | AT_CLEANUP | |
1933 | ||
1934 | ##--------------------------- ## | |
1935 | ## Non-deprecated directives. ## | |
1936 | ## -------------------------- ## | |
1937 | ||
1938 | AT_SETUP([[Non-deprecated directives]]) | |
1939 | ||
1940 | AT_KEYWORDS([[deprec]]) | |
1941 | ||
1942 | AT_DATA_GRAMMAR([[input.y]], | |
1943 | [[ | |
1944 | %default-prec | |
1945 | %error-verbose | |
1946 | %expect-rr 42 | |
1947 | %file-prefix "foo" | |
1948 | %file-prefix | |
1949 | "bar" | |
1950 | %fixed-output-files | |
1951 | %name-prefix "foo" | |
1952 | %no-default-prec | |
1953 | %no-lines | |
1954 | %output "foo" | |
1955 | %pure-parser | |
1956 | %token-table | |
1957 | %% exp : '0' | |
1958 | ]]) | |
1959 | ||
1960 | AT_BISON_CHECK([[input.y]], [[0]], [[]], | |
1961 | [[input.y: warning: %expect-rr applies only to GLR parsers [-Wother] | |
1962 | ]]) | |
1963 | ||
1964 | AT_CLEANUP |