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