]> git.saurik.com Git - bison.git/blob - tests/input.at
tests: sort
[bison.git] / tests / input.at
1 # Checking the Bison scanner. -*- Autotest -*-
2
3 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
4
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
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.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 AT_BANNER([[Input Processing.]])
19
20 # Mostly test that we are robust to mistakes.
21
22
23 ## ---------------- ##
24 ## Invalid inputs. ##
25 ## ---------------- ##
26
27 AT_SETUP([Invalid inputs])
28
29 AT_DATA([input.y],
30 [[%%
31 ?
32 default: 'a' }
33 %&
34 %a-does-not-exist
35 %-
36 %{
37 ]])
38
39 AT_BISON_CHECK([input.y], [1], [],
40 [[input.y:2.1: invalid character: '?'
41 input.y:3.14: invalid character: '}'
42 input.y:4.1: invalid character: '%'
43 input.y:4.2: invalid character: '&'
44 input.y:5.1-17: invalid directive: '%a-does-not-exist'
45 input.y:6.1: invalid character: '%'
46 input.y:6.2: invalid character: '-'
47 input.y:7.1-8.0: missing '%}' at end of file
48 input.y:7.1-8.0: syntax error, unexpected %{...%}
49 ]])
50
51 AT_CLEANUP
52
53
54 AT_SETUP([Invalid inputs with {}])
55
56 # We used to SEGV here. See
57 # http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html
58
59 AT_DATA([input.y],
60 [[
61 %destructor
62 %initial-action
63 %lex-param
64 %parse-param
65 %printer
66 %union
67 ]])
68
69 AT_BISON_CHECK([input.y], [1], [],
70 [[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...}
71 ]])
72
73 AT_CLEANUP
74
75
76
77 ## ------------ ##
78 ## Invalid $n. ##
79 ## ------------ ##
80
81 AT_SETUP([Invalid $n and @n])
82
83 AT_DATA([input.y],
84 [[%%
85 exp: { $$ = $1 ; };
86 exp: { @$ = @1 ; };
87 ]])
88
89 AT_BISON_CHECK([input.y], [1], [],
90 [[input.y:2.13-14: integer out of range: '$1'
91 input.y:3.13-14: integer out of range: '@1'
92 ]])
93
94 AT_CLEANUP
95
96
97 ## -------------- ##
98 ## Type Clashes. ##
99 ## -------------- ##
100
101 AT_SETUP([Type Clashes])
102
103 AT_DATA([input.y],
104 [[%union { int bar; }
105 %token foo
106 %type <bar> exp
107 %%
108 exp: foo { $$; } foo { $2; } foo
109 | foo
110 | /* Empty. */
111 ;
112 ]])
113
114 AT_BISON_CHECK([input.y], [1], [],
115 [[input.y:5.12-13: $$ for the midrule at $2 of 'exp' has no declared type
116 input.y:5.24-25: $2 of 'exp' has no declared type
117 input.y:5.6-32: warning: type clash on default action: <bar> != <>
118 input.y:6.6-8: warning: type clash on default action: <bar> != <>
119 input.y:7.5: warning: empty rule for typed nonterminal, and no action
120 ]])
121
122 AT_CLEANUP
123
124
125 # _AT_UNUSED_VALUES_DECLARATIONS()
126 # --------------------------------
127 # Generate the token, type, and destructor
128 # declarations for the unused values tests.
129
130 m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
131 [[[%token <integer> INT;
132 %type <integer> a b c d e f g h i j k l;
133 %destructor { destroy ($$); } INT a b c d e f g h i j k l;]]])
134
135
136 # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
137 # ------------------------------------------------------------------
138 # Generate a grammar to test unused values,
139 # compile it, run it. If DECLARATIONS_AFTER
140 # is set, then the token, type, and destructor
141 # declarations are generated after the rules
142 # rather than before. If CHECK_MIDRULE_VALUES
143 # is set, then --warnings=midrule-values is
144 # set.
145
146 m4_define([AT_CHECK_UNUSED_VALUES],
147 [AT_DATA([input.y],
148 m4_ifval($1, [
149
150
151 ], [_AT_UNUSED_VALUES_DECLARATIONS
152 ])[[%%
153 start:
154 'a' a { $]2[; } | 'b' b { $]2[; } | 'c' c { $]2[; } | 'd' d { $]2[; }
155 | 'e' e { $]2[; } | 'f' f { $]2[; } | 'g' g { $]2[; } | 'h' h { $]2[; }
156 | 'i' i { $]2[; } | 'j' j { $]2[; } | 'k' k { $]2[; } | 'l' l { $]2[; }
157 ;
158
159 a: INT | INT { } INT { } INT { };
160 b: INT | /* empty */;
161 c: INT | INT { $]1[; } INT { $<integer>2; } INT { $<integer>4; };
162 d: INT | INT { } INT { $]1[; } INT { $<integer>2; };
163 e: INT | INT { } INT { } INT { $]1[; };
164 f: INT | INT { } INT { } INT { $]$[ = $]1[ + $]3[ + $]5[; };
165 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
166 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
167 i: INT | INT INT { } { $]$[ = $]1[ + $]2[; };
168 j: INT | INT INT { $<integer>$ = 1; } { $]$[ = $]1[ + $]2[; };
169 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
170 l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };]]m4_ifval($1, [
171 _AT_UNUSED_VALUES_DECLARATIONS])
172 )
173
174 AT_BISON_CHECK(m4_ifval($2, [ --warnings=midrule-values ])[ input.y], [0], [],
175 [[input.y:11.10-32: warning: unset value: $]$[
176 input.y:11.10-32: warning: unused value: $]1[
177 input.y:11.10-32: warning: unused value: $]3[
178 input.y:11.10-32: warning: unused value: $]5[
179 input.y:12.9: warning: empty rule for typed nonterminal, and no action
180 ]]m4_ifval($2, [[[input.y:13.14-20: warning: unset value: $$
181 input.y:13.26-41: warning: unset value: $$
182 ]]])[[input.y:13.10-62: warning: unset value: $]$[
183 input.y:13.10-62: warning: unused value: $]3[
184 input.y:13.10-62: warning: unused value: $]5[
185 ]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $$
186 ]]])[[input.y:14.10-49: warning: unset value: $]$[
187 input.y:14.10-49: warning: unused value: $]3[
188 input.y:14.10-49: warning: unused value: $]5[
189 input.y:15.10-37: warning: unset value: $]$[
190 input.y:15.10-37: warning: unused value: $]3[
191 input.y:15.10-37: warning: unused value: $]5[
192 input.y:17.10-58: warning: unset value: $]$[
193 input.y:17.10-58: warning: unused value: $]1[
194 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]2[
195 ]]])[[input.y:17.10-58: warning: unused value: $]3[
196 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]4[
197 ]]])[[input.y:17.10-58: warning: unused value: $]5[
198 input.y:18.10-72: warning: unset value: $]$[
199 input.y:18.10-72: warning: unused value: $]1[
200 input.y:18.10-72: warning: unused value: $]3[
201 ]]m4_ifval($2, [[[input.y:18.10-72: warning: unused value: $]4[
202 ]]])[[input.y:18.10-72: warning: unused value: $]5[
203 ]]m4_ifval($2, [[[input.y:20.10-55: warning: unused value: $]3[
204 ]]])[[input.y:21.10-68: warning: unset value: $]$[
205 input.y:21.10-68: warning: unused value: $]1[
206 input.y:21.10-68: warning: unused value: $]2[
207 ]]m4_ifval($2, [[[input.y:21.10-68: warning: unused value: $]4[
208 ]]]))])
209
210
211 ## --------------- ##
212 ## Unused values. ##
213 ## --------------- ##
214
215 AT_SETUP([Unused values])
216 AT_CHECK_UNUSED_VALUES
217 AT_CHECK_UNUSED_VALUES(, [1])
218 AT_CLEANUP
219
220
221 ## ------------------------------------------ ##
222 ## Unused values before symbol declarations. ##
223 ## ------------------------------------------ ##
224
225 AT_SETUP([Unused values before symbol declarations])
226 AT_CHECK_UNUSED_VALUES([1])
227 AT_CHECK_UNUSED_VALUES([1], [1])
228 AT_CLEANUP
229
230
231 ## --------------------------------------------- ##
232 ## Default %printer and %destructor redeclared. ##
233 ## --------------------------------------------- ##
234
235 AT_SETUP([Default %printer and %destructor redeclared])
236
237 AT_DATA([[input.y]],
238 [[%destructor { destroy ($$); } <*> <*>
239 %printer { print ($$); } <*> <*>
240
241 %destructor { destroy ($$); } <*>
242 %printer { print ($$); } <*>
243
244 %destructor { destroy ($$); } <> <>
245 %printer { print ($$); } <> <>
246
247 %destructor { destroy ($$); } <>
248 %printer { print ($$); } <>
249
250 %%
251
252 start: ;
253
254 %destructor { destroy ($$); } <*>;
255 %printer { print ($$); } <*>;
256
257 %destructor { destroy ($$); } <>;
258 %printer { print ($$); } <>;
259 ]])
260
261 AT_BISON_CHECK([input.y], [1], [],
262 [[input.y:1.13-29: redeclaration for default tagged %destructor
263 input.y:1.13-29: previous declaration
264 input.y:2.10-24: redeclaration for default tagged %printer
265 input.y:2.10-24: previous declaration
266 input.y:4.13-29: redeclaration for default tagged %destructor
267 input.y:1.13-29: previous declaration
268 input.y:5.10-24: redeclaration for default tagged %printer
269 input.y:2.10-24: previous declaration
270 input.y:7.13-29: redeclaration for default tagless %destructor
271 input.y:7.13-29: previous declaration
272 input.y:8.10-24: redeclaration for default tagless %printer
273 input.y:8.10-24: previous declaration
274 input.y:10.13-29: redeclaration for default tagless %destructor
275 input.y:7.13-29: previous declaration
276 input.y:11.10-24: redeclaration for default tagless %printer
277 input.y:8.10-24: previous declaration
278 input.y:17.13-29: redeclaration for default tagged %destructor
279 input.y:4.13-29: previous declaration
280 input.y:18.10-24: redeclaration for default tagged %printer
281 input.y:5.10-24: previous declaration
282 input.y:20.13-29: redeclaration for default tagless %destructor
283 input.y:10.13-29: previous declaration
284 input.y:21.10-24: redeclaration for default tagless %printer
285 input.y:11.10-24: previous declaration
286 ]])
287
288 AT_CLEANUP
289
290
291 ## ---------------------------------------------- ##
292 ## Per-type %printer and %destructor redeclared. ##
293 ## ---------------------------------------------- ##
294
295 AT_SETUP([Per-type %printer and %destructor redeclared])
296
297 AT_DATA([[input.y]],
298 [[%destructor { destroy ($$); } <field1> <field2>
299 %printer { print ($$); } <field1> <field2>
300
301 %destructor { destroy ($$); } <field1> <field1>
302 %printer { print ($$); } <field2> <field2>
303
304 %%
305
306 start: ;
307
308 %destructor { destroy ($$); } <field2> <field1>;
309 %printer { print ($$); } <field2> <field1>;
310 ]])
311
312 AT_BISON_CHECK([input.y], [1], [],
313 [[input.y:4.13-29: %destructor redeclaration for <field1>
314 input.y:1.13-29: previous declaration
315 input.y:4.13-29: %destructor redeclaration for <field1>
316 input.y:4.13-29: previous declaration
317 input.y:5.10-24: %printer redeclaration for <field2>
318 input.y:2.10-24: previous declaration
319 input.y:5.10-24: %printer redeclaration for <field2>
320 input.y:5.10-24: previous declaration
321 input.y:11.13-29: %destructor redeclaration for <field1>
322 input.y:4.13-29: previous declaration
323 input.y:11.13-29: %destructor redeclaration for <field2>
324 input.y:1.13-29: previous declaration
325 input.y:12.10-24: %printer redeclaration for <field1>
326 input.y:2.10-24: previous declaration
327 input.y:12.10-24: %printer redeclaration for <field2>
328 input.y:5.10-24: previous declaration
329 ]])
330
331 AT_CLEANUP
332
333
334 ## ---------------------------------------- ##
335 ## Unused values with default %destructor. ##
336 ## ---------------------------------------- ##
337
338 AT_SETUP([Unused values with default %destructor])
339
340 AT_DATA([[input.y]],
341 [[%destructor { destroy ($$); } <>
342 %type <tag> tagged
343
344 %%
345
346 start: end end tagged tagged { $<tag>1; $3; } ;
347 end: { } ;
348 tagged: { } ;
349 ]])
350
351 AT_BISON_CHECK([input.y], [0], [],
352 [[input.y:6.8-45: warning: unset value: $$
353 input.y:6.8-45: warning: unused value: $2
354 input.y:7.6-8: warning: unset value: $$
355 ]])
356
357 AT_DATA([[input.y]],
358 [[%destructor { destroy ($$); } <*>
359 %type <tag> tagged
360
361 %%
362
363 start: end end tagged tagged { $<tag>1; $3; } ;
364 end: { } ;
365 tagged: { } ;
366 ]])
367
368 AT_BISON_CHECK([input.y], [0], [],
369 [[input.y:6.8-45: warning: unused value: $4
370 input.y:8.9-11: warning: unset value: $$
371 ]])
372
373 AT_CLEANUP
374
375
376 ## ----------------------------------------- ##
377 ## Unused values with per-type %destructor. ##
378 ## ----------------------------------------- ##
379
380 AT_SETUP([Unused values with per-type %destructor])
381
382 AT_DATA([[input.y]],
383 [[%destructor { destroy ($$); } <field1>
384 %type <field1> start end
385
386 %%
387
388 start: end end { $1; } ;
389 end: { } ;
390 ]])
391
392 AT_BISON_CHECK([input.y], [0], [],
393 [[input.y:6.8-22: warning: unset value: $$
394 input.y:6.8-22: warning: unused value: $2
395 input.y:7.6-8: warning: unset value: $$
396 ]])
397
398 AT_CLEANUP
399
400
401 ## ---------------------- ##
402 ## Incompatible Aliases. ##
403 ## ---------------------- ##
404
405 AT_SETUP([Incompatible Aliases])
406
407 AT_DATA([input.y],
408 [[%token foo "foo"
409
410 %type <bar> foo
411 %printer {bar} foo
412 %destructor {bar} foo
413 %left foo
414
415 %type <baz> "foo"
416 %printer {baz} "foo"
417 %destructor {baz} "foo"
418 %left "foo"
419
420 %%
421 exp: foo;
422 ]])
423
424 AT_BISON_CHECK([input.y], [1], [],
425 [[input.y:8.7-11: %type redeclaration for foo
426 input.y:3.7-11: previous declaration
427 input.y:10.13-17: %destructor redeclaration for foo
428 input.y:5.13-17: previous declaration
429 input.y:9.10-14: %printer redeclaration for foo
430 input.y:4.10-14: previous declaration
431 input.y:11.1-5: %left redeclaration for foo
432 input.y:6.1-5: previous declaration
433 ]])
434
435 AT_CLEANUP
436
437
438
439 ## ----------------------- ##
440 ## Torturing the Scanner. ##
441 ## ----------------------- ##
442
443 # Be sure to compile and run, so that the C compiler checks what
444 # we do.
445
446 AT_SETUP([Torturing the Scanner])
447
448 AT_BISON_OPTION_PUSHDEFS
449 AT_DATA([input.y], [])
450 AT_BISON_CHECK([input.y], [1], [],
451 [[input.y:1.1: syntax error, unexpected end of file
452 ]])
453
454
455 AT_DATA([input.y],
456 [{}
457 ])
458 AT_BISON_CHECK([input.y], [1], [],
459 [[input.y:1.1-2: syntax error, unexpected {...}
460 ]])
461
462
463 AT_DATA_GRAMMAR([input.y],
464 [[%{
465 /* This is seen in GCC: a %{ and %} in middle of a comment. */
466 const char *foo = "So %{ and %} can be here too.";
467
468 #if 0
469 /* These examples test Bison while not stressing C compilers too much.
470 Many C compilers mishandle backslash-newlines, so this part of the
471 test is inside "#if 0". The comment and string are written so that
472 the "#endif" will be seen regardless of the C compiler bugs that we
473 know about, namely:
474
475 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
476 comment.
477
478 The Apple Darwin compiler (as of late 2002) mishandles
479 \\[newline]' within a character constant.
480
481 */
482
483 /\
484 * A comment with backslash-newlines in it. %} *\
485 \
486 /
487 /* { Close the above comment, if the C compiler mishandled it. */
488
489 char str[] = "\\
490 " A string with backslash-newlines in it %{ %} \\
491 \
492 "";
493
494 char apostrophe = '\'';
495 #endif
496
497 #include <stdio.h>
498 #include <stdlib.h>
499 #include <assert.h>
500 %}
501 /* %{ and %} can be here too. */
502
503 %{
504 /* Exercise pre-prologue dependency to %union. */
505 typedef int value;
506 %}
507
508 /* Exercise M4 quoting: '@:>@@:>@', 0. */
509
510 /* Also exercise %union. */
511 %union
512 {
513 value ival; /* A comment to exercise an old bug. */
514 };
515
516
517 /* Exercise post-prologue dependency to %union. */
518 %{
519 static YYSTYPE value_as_yystype (value val);
520
521 /* Exercise quotes in declarations. */
522 char quote[] = "@:>@@:>@,";
523 %}
524
525 %{
526 ]AT_YYERROR_DECLARE[
527 ]AT_YYLEX_DECLARE[
528 %}
529
530 %type <ival> '@<:@'
531
532 /* Exercise quotes in strings. */
533 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
534
535 %%
536 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
537 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
538 {
539 /* Exercise quotes in braces. */
540 char tmp[] = "@<:@%c@:>@,\n";
541 printf (tmp, $1);
542 }
543 ;
544
545 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
546 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
547 output.or.oline.opt: ;|oline;;|output;;;
548 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
549 %%
550 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
551
552 static YYSTYPE
553 value_as_yystype (value val)
554 {
555 YYSTYPE res;
556 res.ival = val;
557 return res;
558 }
559 ]AT_YYERROR_DEFINE[
560 static int
561 yylex (void)
562 {
563 static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
564 #output "; /* "
565 */
566 static size_t toknum;
567 assert (toknum < sizeof input);
568 yylval = value_as_yystype (input[toknum]);
569 return input[toknum++];
570 }
571 ]])
572
573 # Pacify Emacs' font-lock-mode: "
574
575 AT_DATA([main.c],
576 [[typedef int value;
577 #include "input.h"
578
579 int yyparse (void);
580
581 int
582 main (void)
583 {
584 return yyparse ();
585 }
586 ]])
587 AT_BISON_OPTION_POPDEFS
588
589 AT_BISON_CHECK([-d -v -o input.c input.y])
590 AT_COMPILE([input.o])
591 AT_COMPILE([main.o])
592 AT_COMPILE([input], [input.o main.o])
593 AT_PARSER_CHECK([./input], 0,
594 [[[@<:@],
595 ]])
596
597 AT_CLEANUP
598
599
600 ## ---------------------- ##
601 ## Typed symbol aliases. ##
602 ## ---------------------- ##
603
604 AT_SETUP([Typed symbol aliases])
605
606 # Bison 2.0 broke typed symbol aliases - ensure they work.
607
608 AT_DATA_GRAMMAR([input.y],
609 [[%union
610 {
611 int val;
612 };
613 %token <val> MY_TOKEN "MY TOKEN"
614 %type <val> exp
615 %%
616 exp: "MY TOKEN";
617 %%
618 ]])
619
620 AT_BISON_CHECK([-o input.c input.y])
621
622 AT_CLEANUP
623
624
625 ## --------- ##
626 ## Require. ##
627 ## --------- ##
628
629 m4_define([AT_CHECK_REQUIRE],
630 [AT_SETUP([Require $1])
631 AT_DATA_GRAMMAR([input.y],
632 [[%require "$1";
633 %%
634 empty_file:;
635 ]])
636 AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
637 AT_CLEANUP
638 ])
639
640 AT_CHECK_REQUIRE(1.0, 0)
641 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
642 ## FIXME: Some day augment this version number.
643 AT_CHECK_REQUIRE(100.0, 63)
644
645
646 ## ------------------------------------- ##
647 ## String aliases for character tokens. ##
648 ## ------------------------------------- ##
649
650 AT_SETUP([String aliases for character tokens])
651
652 # Bison once thought a character token and its alias were different symbols
653 # with the same user token number.
654
655 AT_DATA_GRAMMAR([input.y],
656 [[%token 'a' "a"
657 %%
658 start: 'a';
659 %%
660 ]])
661
662 AT_BISON_CHECK([-o input.c input.y])
663
664 AT_CLEANUP
665
666
667 ## -------------- ##
668 ## Symbol names. ##
669 ## -------------- ##
670
671 AT_SETUP([Symbols])
672
673 AT_BISON_OPTION_PUSHDEFS
674 AT_DATA_GRAMMAR([input.y],
675 [[%token WITH-DASH
676 %token WITHOUT_DASH "WITHOUT-DASH"
677 %token WITH.PERIOD
678 %token WITHOUT_PERIOD "WITHOUT.PERIOD"
679 %code {
680 ]AT_YYERROR_DECLARE[
681 ]AT_YYLEX_DECLARE[
682 }
683 %%
684 start: with-dash without_dash with.period without_period;
685 with-dash: WITH-DASH;
686 without_dash: "WITHOUT-DASH";
687 with.period: WITH.PERIOD;
688 without_period: "WITHOUT.PERIOD";
689 %%
690 ]AT_YYERROR_DEFINE[
691 ]AT_YYLEX_DEFINE[
692 ]])
693 AT_BISON_OPTION_POPDEFS
694
695 # POSIX Yacc accept periods, but not dashes.
696 AT_BISON_CHECK([--yacc input.y], [1], [],
697 [[input.y:9.8-16: POSIX Yacc forbids dashes in symbol names: WITH-DASH
698 input.y:18.8-16: POSIX Yacc forbids dashes in symbol names: with-dash
699 ]])
700
701 # So warn about them.
702 AT_BISON_CHECK([-Wyacc input.y], [], [],
703 [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH
704 input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash
705 ]])
706
707 # Dashes are fine for GNU Bison.
708 AT_BISON_CHECK([-o input.c input.y])
709
710 # Make sure we don't export silly token identifiers with periods or dashes.
711 AT_COMPILE([input.o])
712
713
714 # Periods are genuine letters, they can start identifiers.
715 # Digits and dashes cannot.
716 AT_DATA_GRAMMAR([input.y],
717 [[%token .GOOD
718 -GOOD
719 1NV4L1D
720 -123
721 %%
722 start: .GOOD GOOD
723 ]])
724 AT_BISON_CHECK([-o input.c input.y], [1], [],
725 [[input.y:10.10: invalid character: '-'
726 input.y:11.10-16: invalid identifier: '1NV4L1D'
727 input.y:12.10: invalid character: '-'
728 ]])
729
730 AT_CLEANUP
731
732
733 ## ----------------- ##
734 ## Numbered tokens. ##
735 ## ----------------- ##
736
737 AT_SETUP([Numbered tokens])
738
739 AT_DATA_GRAMMAR([redecl.y],
740 [[%token DECIMAL_1 11259375
741 HEXADECIMAL_1 0xabcdef
742 HEXADECIMAL_2 0xFEDCBA
743 DECIMAL_2 16702650
744 %%
745 start: DECIMAL_1 HEXADECIMAL_2;
746 ]])
747
748 AT_BISON_CHECK([redecl.y], [1], [],
749 [[redecl.y:10.10-22: user token number 11259375 redeclaration for HEXADECIMAL_1
750 redecl.y:9.8-16: previous declaration for DECIMAL_1
751 redecl.y:12.10-18: user token number 16702650 redeclaration for DECIMAL_2
752 redecl.y:11.10-22: previous declaration for HEXADECIMAL_2
753 ]])
754
755 AT_DATA_GRAMMAR([too-large.y],
756 [[%token TOO_LARGE_DEC 999999999999999999999
757 TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF
758 %%
759 start: TOO_LARGE_DEC TOO_LARGE_HEX
760 %%
761 ]])
762
763 AT_BISON_CHECK([too-large.y], [1], [],
764 [[too-large.y:9.22-42: integer out of range: '999999999999999999999'
765 too-large.y:10.24-44: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
766 ]])
767
768 AT_CLEANUP
769
770
771 ## --------------------- ##
772 ## Unclosed constructs. ##
773 ## --------------------- ##
774
775 AT_SETUP([Unclosed constructs])
776
777 # Bison's scan-gram.l once forgot to STRING_FINISH some unclosed constructs, so
778 # they were prepended to whatever it STRING_GROW'ed next. It also threw them
779 # away rather than returning them to the parser. The effect was confusing
780 # subsequent error messages.
781
782 AT_DATA([input.y],
783 [[%token A "a
784 %token B "b"
785 %token AB "ab" // Used to complain that "ab" was already used.
786 %token C '1
787 %token TWO "2"
788 %token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
789
790 %%
791
792 start: ;
793
794 // Used to report a syntax error because it didn't see any kind of symbol
795 // identifier.
796 %type <f> 'a
797 ;
798 %type <f> "a
799 ;
800 // Used to report a syntax error because it didn't see braced code.
801 %destructor { free ($$)
802 ]])
803
804 AT_BISON_CHECK([-o input.c input.y], 1, [],
805 [[input.y:1.10-2.0: missing '"' at end of line
806 input.y:4.10-5.0: missing "'" at end of line
807 input.y:14.11-15.0: missing "'" at end of line
808 input.y:16.11-17.0: missing '"' at end of line
809 input.y:19.13-20.0: missing '}' at end of file
810 input.y:20.1: syntax error, unexpected end of file
811 ]])
812
813 AT_CLEANUP
814
815
816 ## ------------------------- ##
817 ## %start after first rule. ##
818 ## ------------------------- ##
819
820 AT_SETUP([%start after first rule])
821
822 # Bison once complained that a %start after the first rule was a redeclaration
823 # of the start symbol.
824
825 AT_DATA([input.y],
826 [[%%
827 false_start: ;
828 start: false_start ;
829 %start start;
830 ]])
831
832 AT_BISON_CHECK([-o input.c input.y])
833
834 AT_CLEANUP
835
836
837 ## --------------------- ##
838 ## %prec takes a token. ##
839 ## --------------------- ##
840
841 AT_SETUP([%prec takes a token])
842
843 # Bison once allowed %prec sym where sym was a nonterminal.
844
845 AT_DATA([input.y],
846 [[%%
847 start: PREC %prec PREC ;
848 PREC: ;
849 ]])
850
851 AT_BISON_CHECK([input.y], [1], [],
852 [[input.y:3.1-4: rule given for PREC, which is a token
853 ]])
854
855 AT_CLEANUP
856
857
858 ## ------------------------------- ##
859 ## %prec's token must be defined. ##
860 ## ------------------------------- ##
861
862 AT_SETUP([[%prec's token must be defined]])
863
864 # According to POSIX, a %prec token must be defined separately.
865
866 AT_DATA([[input.y]],
867 [[%%
868 start: %prec PREC ;
869 ]])
870
871 AT_BISON_CHECK([[input.y]], [[0]], [],
872 [[input.y:2.8-17: warning: token for %prec is not defined: PREC
873 ]])
874
875 AT_CLEANUP
876
877
878 ## -------------------------------- ##
879 ## Reject unused %code qualifiers. ##
880 ## -------------------------------- ##
881
882 AT_SETUP([Reject unused %code qualifiers])
883
884 AT_DATA([input-c.y],
885 [[%code q {}
886 %code bad {}
887 %code bad {}
888 %code format {}
889 %%
890 start: ;
891 ]])
892 AT_BISON_CHECK([[input-c.y]], [[1]], [],
893 [[input-c.y:1.7: %code qualifier 'q' is not used
894 input-c.y:2.7-9: %code qualifier 'bad' is not used
895 input-c.y:3.7-9: %code qualifier 'bad' is not used
896 input-c.y:4.7-12: %code qualifier 'format' is not used
897 ]])
898
899 AT_DATA([input-c-glr.y],
900 [[%code q {}
901 %code bad {}
902 %code bad {}
903 %%
904 start: ;
905 ]])
906 AT_BISON_CHECK([[input-c-glr.y]], [[1]], [],
907 [[input-c-glr.y:1.7: %code qualifier 'q' is not used
908 input-c-glr.y:2.7-9: %code qualifier 'bad' is not used
909 input-c-glr.y:3.8-10: %code qualifier 'bad' is not used
910 ]])
911
912 AT_DATA([input-c++.y],
913 [[%code q {}
914 %code bad {}
915 %code q {}
916 %%
917 start: ;
918 ]])
919 AT_BISON_CHECK([[input-c++.y]], [[1]], [],
920 [[input-c++.y:1.7: %code qualifier 'q' is not used
921 input-c++.y:2.7-9: %code qualifier 'bad' is not used
922 input-c++.y:3.8: %code qualifier 'q' is not used
923 ]])
924
925 AT_DATA([input-c++-glr.y],
926 [[%code bad {}
927 %code q {}
928 %code q {}
929 %%
930 start: ;
931 ]])
932 AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [],
933 [[input-c++-glr.y:1.7-9: %code qualifier 'bad' is not used
934 input-c++-glr.y:2.7: %code qualifier 'q' is not used
935 input-c++-glr.y:3.7: %code qualifier 'q' is not used
936 ]])
937
938 AT_DATA([special-char-@@.y],
939 [[%code bad {}
940 %code q {}
941 %code q {}
942 %%
943 start: ;
944 ]])
945 AT_BISON_CHECK([[special-char-@@.y]], [[1]], [],
946 [[special-char-@@.y:1.7-9: %code qualifier 'bad' is not used
947 special-char-@@.y:2.7: %code qualifier 'q' is not used
948 special-char-@@.y:3.7: %code qualifier 'q' is not used
949 ]])
950
951 AT_DATA([special-char-@:>@.y],
952 [[%code bad {}
953 %code q {}
954 %code q {}
955 %%
956 start: ;
957 ]])
958 AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [],
959 [[special-char-@:>@.y:1.7-9: %code qualifier 'bad' is not used
960 special-char-@:>@.y:2.7: %code qualifier 'q' is not used
961 special-char-@:>@.y:3.7: %code qualifier 'q' is not used
962 ]])
963
964 AT_CLEANUP
965
966
967 ## ---------------- ##
968 ## %define errors. ##
969 ## ---------------- ##
970
971 AT_SETUP([%define errors])
972
973 AT_DATA([input-redefined.y],
974 [[%define var "value1"
975 %define var "value1"
976 %define var "value2"
977 %define special1 "@:>@"
978 %define special2 "@<:@"
979 %%
980 start: ;
981 ]])
982
983 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
984 [[input-redefined.y:2.9-11: %define variable 'var' redefined
985 input-redefined.y:1.9-11: previous definition
986 input-redefined.y:3.10-12: %define variable 'var' redefined
987 input-redefined.y:2.9-11: previous definition
988 ]])
989
990 AT_DATA([input-unused.y],
991 [[%define var "value"
992 %%
993 start: ;
994 ]])
995
996 AT_BISON_CHECK([[input-unused.y]], [[1]], [],
997 [[input-unused.y:1.9-11: %define variable 'var' is not used
998 ]])
999
1000 AT_CLEANUP
1001
1002
1003 ## ----------------------------------- ##
1004 ## %define, --define, --force-define. ##
1005 ## ----------------------------------- ##
1006
1007 AT_SETUP([[%define, --define, --force-define]])
1008
1009 AT_DATA([[skel.c]],
1010 [[m4@&t@_divert_push(0)@
1011 @output(b4_parser_file_name@)@
1012 [var-dd: ]b4_percent_define_get([[var-dd]])[
1013 var-ff: ]b4_percent_define_get([[var-ff]])[
1014 var-dfg: ]b4_percent_define_get([[var-dfg]])[
1015 var-fd: ]b4_percent_define_get([[var-fd]])
1016 m4@&t@_divert_pop(0)
1017 ]])
1018 AT_DATA([[input.y]],
1019 [[%define var-dfg "gram"
1020 %%
1021 start: ;
1022 ]])
1023 AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \
1024 -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \
1025 -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \
1026 -Fvar-fd=cmd-f -Dvar-fd=cmd-d \
1027 --skeleton ./skel.c input.y]])
1028 AT_CHECK([[cat input.tab.c]], [[0]],
1029 [[var-dd: cmd-d2
1030 var-ff: cmd-f2
1031 var-dfg: cmd-f
1032 var-fd: cmd-d
1033 ]])
1034
1035 AT_DATA([[input-dg.y]],
1036 [[%define var "gram"
1037 %%
1038 start: ;
1039 ]])
1040 AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
1041 [[input-dg.y:1.9-11: %define variable 'var' redefined
1042 <command line>:2: previous definition
1043 ]])
1044
1045 AT_DATA([[input-unused.y]],
1046 [[%%
1047 start: ;
1048 ]])
1049 AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
1050 [[<command line>:2: %define variable 'unused-d' is not used
1051 <command line>:3: %define variable 'unused-f' is not used
1052 ]])
1053
1054 AT_CLEANUP
1055
1056 ## --------------------------- ##
1057 ## %define Boolean variables. ##
1058 ## --------------------------- ##
1059
1060 AT_SETUP([[%define Boolean variables]])
1061
1062 AT_DATA([Input.y],
1063 [[%language "Java"
1064 %define public "maybe"
1065 %define parser_class_name "Input"
1066 %%
1067 start: ;
1068 ]])
1069
1070 AT_BISON_CHECK([[Input.y]], [1], [],
1071 [[Input.y:2.9-14: invalid value for %define Boolean variable 'public'
1072 ]])
1073
1074 AT_CLEANUP
1075
1076 ## ------------------------ ##
1077 ## %define enum variables. ##
1078 ## ------------------------ ##
1079
1080 AT_SETUP([[%define enum variables]])
1081
1082 # Front-end.
1083 AT_DATA([[input.y]],
1084 [[%define lr.default-reductions bogus
1085 %%
1086 start: ;
1087 ]])
1088 AT_BISON_CHECK([[input.y]], [[1]], [[]],
1089 [[input.y:1.9-29: invalid value for %define variable 'lr.default-reductions': 'bogus'
1090 input.y:1.9-29: accepted value: 'most'
1091 input.y:1.9-29: accepted value: 'consistent'
1092 input.y:1.9-29: accepted value: 'accepting'
1093 ]])
1094
1095 # Back-end.
1096 AT_DATA([[input.y]],
1097 [[%define api.push-pull neither
1098 %%
1099 start: ;
1100 ]])
1101 AT_BISON_CHECK([[input.y]], [1], [],
1102 [[input.y:1.9-21: invalid value for %define variable 'api.push-pull': 'neither'
1103 input.y:1.9-21: accepted value: 'pull'
1104 input.y:1.9-21: accepted value: 'push'
1105 input.y:1.9-21: accepted value: 'both'
1106 ]])
1107
1108 AT_CLEANUP
1109
1110 ## -------------------------------- ##
1111 ## %define backward compatibility. ##
1112 ## -------------------------------- ##
1113
1114 AT_SETUP([[%define backward compatibility]])
1115
1116 # The error messages tell us whether underscores in these variables are
1117 # being converted to dashes.
1118
1119 AT_DATA([[input.y]],
1120 [[%define api.push_pull "neither"
1121 %%
1122 start: ;
1123 ]])
1124 AT_BISON_CHECK([[input.y]], [1], [],
1125 [[input.y:1.9-21: invalid value for %define variable 'api.push-pull': 'neither'
1126 input.y:1.9-21: accepted value: 'pull'
1127 input.y:1.9-21: accepted value: 'push'
1128 input.y:1.9-21: accepted value: 'both'
1129 ]])
1130
1131 AT_DATA([[input.y]],
1132 [[%define lr.keep_unreachable_states maybe
1133 %%
1134 start: ;
1135 ]])
1136 AT_BISON_CHECK([[input.y]], [1], [],
1137 [[input.y:1.9-34: invalid value for %define Boolean variable 'lr.keep-unreachable-states'
1138 ]])
1139
1140 AT_DATA([[input.y]],
1141 [[%define foo_bar "baz"
1142 %%
1143 start: ;
1144 ]])
1145 AT_BISON_CHECK([[input.y]], [[1]], [],
1146 [[input.y:1.9-15: %define variable 'foo_bar' is not used
1147 ]])
1148
1149 AT_CLEANUP
1150
1151 ## ------------------------- ##
1152 ## Unused %define api.pure. ##
1153 ## ------------------------- ##
1154
1155 AT_SETUP([[Unused %define api.pure]])
1156
1157 # AT_CHECK_API_PURE(DECLS, VALUE)
1158 # -------------------------------
1159 # Make sure Bison reports that `%define api.pure VALUE' is unused when DECLS
1160 # are specified.
1161 m4_define([AT_CHECK_API_PURE],
1162 [
1163 AT_DATA([[input.y]],
1164 [[%define api.pure ]$2[
1165 ]$1[
1166 %%
1167 start: ;
1168 ]])
1169
1170 AT_BISON_CHECK([[input.y]], [[1]], [],
1171 [[input.y:1.9-16: %define variable 'api.pure' is not used
1172 ]])
1173 ])
1174
1175 AT_CHECK_API_PURE([[%language "c++" %defines]], [[]])
1176 AT_CHECK_API_PURE([[%language "c++" %defines]], [[false]])
1177 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[""]])
1178 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[false]])
1179 AT_CHECK_API_PURE([[%language "java"]], [[true]])
1180 AT_CHECK_API_PURE([[%language "java"]], [[false]])
1181
1182 AT_CLEANUP
1183
1184 ## -------------------------------- ##
1185 ## C++ namespace reference errors. ##
1186 ## -------------------------------- ##
1187
1188 AT_SETUP([[C++ namespace reference errors]])
1189
1190 # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
1191 # -------------------------------------------------------------
1192 # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
1193 m4_define([AT_CHECK_NAMESPACE_ERROR],
1194 [
1195 AT_DATA([[input.y]],
1196 [[%language "C++"
1197 %defines
1198 %define namespace "]$1["
1199 %%
1200 start: ;
1201 ]])
1202
1203 AT_BISON_CHECK([[input.y]], [1], [],
1204 [m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
1205 [[input.y:3.9-17: ]b4_arg[
1206 ]])])
1207 ])
1208
1209 AT_CHECK_NAMESPACE_ERROR([[]],
1210 [[namespace reference is empty]])
1211 AT_CHECK_NAMESPACE_ERROR([[ ]],
1212 [[namespace reference is empty]])
1213 AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
1214 [[namespace reference has consecutive "::"]])
1215 AT_CHECK_NAMESPACE_ERROR([[foo:: ::bar]],
1216 [[namespace reference has consecutive "::"]])
1217 AT_CHECK_NAMESPACE_ERROR([[::::bar]],
1218 [[namespace reference has consecutive "::"]])
1219 AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
1220 [[namespace reference has consecutive "::"]])
1221 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ::]],
1222 [[namespace reference has consecutive "::"]],
1223 [[namespace reference has a trailing "::"]])
1224 AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
1225 [[namespace reference has a trailing "::"]])
1226 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ]],
1227 [[namespace reference has a trailing "::"]])
1228 AT_CHECK_NAMESPACE_ERROR([[::]],
1229 [[namespace reference has a trailing "::"]])
1230
1231 AT_CLEANUP
1232
1233 ## ------------------------ ##
1234 ## Bad character literals. ##
1235 ## ------------------------ ##
1236
1237 # Bison used to accept character literals that were empty or contained
1238 # too many characters.
1239
1240 # FIXME: AT_DATA or some variant of AT_DATA may eventually permit
1241 # the final newline to be omitted. See the threads starting at
1242 # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>.
1243
1244 AT_SETUP([[Bad character literals]])
1245
1246 AT_DATA([empty.y],
1247 [[%%
1248 start: '';
1249 start: '
1250 ]])
1251 AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
1252
1253 AT_BISON_CHECK([empty.y], [1], [],
1254 [[empty.y:2.8-9: warning: empty character literal
1255 empty.y:3.8-4.0: warning: empty character literal
1256 empty.y:3.8-4.0: missing "'" at end of line
1257 empty.y:4.8: warning: empty character literal
1258 empty.y:4.8: missing "'" at end of file
1259 ]])
1260
1261 AT_DATA([two.y],
1262 [[%%
1263 start: 'ab';
1264 start: 'ab
1265 ]])
1266 AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]])
1267
1268 AT_BISON_CHECK([two.y], [1], [],
1269 [[two.y:2.8-11: warning: extra characters in character literal
1270 two.y:3.8-4.0: warning: extra characters in character literal
1271 two.y:3.8-4.0: missing "'" at end of line
1272 two.y:4.8-10: warning: extra characters in character literal
1273 two.y:4.8-10: missing "'" at end of file
1274 ]])
1275
1276 AT_DATA([three.y],
1277 [[%%
1278 start: 'abc';
1279 start: 'abc
1280 ]])
1281 AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]])
1282
1283 AT_BISON_CHECK([three.y], [1], [],
1284 [[three.y:2.8-12: warning: extra characters in character literal
1285 three.y:3.8-4.0: warning: extra characters in character literal
1286 three.y:3.8-4.0: missing "'" at end of line
1287 three.y:4.8-11: warning: extra characters in character literal
1288 three.y:4.8-11: missing "'" at end of file
1289 ]])
1290
1291 AT_CLEANUP
1292
1293 ## ------------------------- ##
1294 ## Bad escapes in literals. ##
1295 ## ------------------------- ##
1296
1297 AT_SETUP([[Bad escapes in literals]])
1298
1299 AT_DATA([input.y],
1300 [[%%
1301 start: '\777' '\0' '\xfff' '\x0'
1302 '\uffff' '\u0000' '\Uffffffff' '\U00000000'
1303 '\ ' '\A';
1304 ]])
1305
1306 # It is not easy to create special characters, we cannot even trust tr.
1307 # Beside we cannot even expect "echo '\0'" to output two characters
1308 # (well three with \n): at least Bash 3.2 converts the two-character
1309 # sequence "\0" into a single NUL character.
1310 AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
1311 || exit 77]])
1312
1313 AT_BISON_CHECK([input.y], [1], [],
1314 [[input.y:2.9-12: invalid number after \-escape: 777
1315 input.y:2.8-13: warning: empty character literal
1316 input.y:2.16-17: invalid number after \-escape: 0
1317 input.y:2.15-18: warning: empty character literal
1318 input.y:2.21-25: invalid number after \-escape: xfff
1319 input.y:2.20-26: warning: empty character literal
1320 input.y:2.29-31: invalid number after \-escape: x0
1321 input.y:2.28-32: warning: empty character literal
1322 input.y:3.9-14: invalid number after \-escape: uffff
1323 input.y:3.8-15: warning: empty character literal
1324 input.y:3.18-23: invalid number after \-escape: u0000
1325 input.y:3.17-24: warning: empty character literal
1326 input.y:3.27-36: invalid number after \-escape: Uffffffff
1327 input.y:3.26-37: warning: empty character literal
1328 input.y:3.40-49: invalid number after \-escape: U00000000
1329 input.y:3.39-50: warning: empty character literal
1330 input.y:4.9-10: invalid character after \-escape: ' '
1331 input.y:4.8-11: warning: empty character literal
1332 input.y:4.14-15: invalid character after \-escape: A
1333 input.y:4.13-16: warning: empty character literal
1334 input.y:5.9-16: invalid character after \-escape: \t
1335 input.y:5.17: invalid character after \-escape: \f
1336 input.y:5.18: invalid character after \-escape: \0
1337 input.y:5.19: invalid character after \-escape: \001
1338 ]])
1339
1340 AT_CLEANUP
1341
1342 ## ------------------------- ##
1343 ## LAC: Errors for %define. ##
1344 ## ------------------------- ##
1345
1346 AT_SETUP([[LAC: Errors for %define]])
1347
1348 AT_DATA([[input.y]],
1349 [[%%
1350 start: ;
1351 ]])
1352
1353 # parse.lac.* options are useless if LAC isn't actually activated.
1354 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
1355 [[1]], [],
1356 [[<command line>:2: %define variable 'parse.lac.es-capacity-initial' is not used
1357 ]])
1358 AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
1359 [[1]], [],
1360 [[<command line>:2: %define variable 'parse.lac.memory-trace' is not used
1361 ]])
1362
1363 AT_CLEANUP
1364
1365 ## --------------------------------------------- ##
1366 ## -Werror is not affected by -Wnone and -Wall. ##
1367 ## --------------------------------------------- ##
1368
1369 AT_SETUP([[-Werror is not affected by -Wnone and -Wall]])
1370
1371 AT_DATA([[input.y]],
1372 [[%%
1373 foo-bar: ;
1374 ]])
1375
1376 # -Werror is not enabled by -Wall or equivalent.
1377 AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
1378 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1379 ]])
1380 AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
1381 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1382 ]])
1383 AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
1384 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1385 ]])
1386
1387 # -Werror is not disabled by -Wnone or equivalent.
1388 AT_BISON_CHECK([[-Werror,none,yacc input.y]], [[1]], [[]], [[stderr]])
1389 AT_CHECK([[sed 's/^.*bison:/bison:/' stderr]], [[0]],
1390 [[bison: warnings being treated as errors
1391 input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1392 ]])
1393 [mv stderr experr]
1394 AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]])
1395
1396 AT_CLEANUP
1397
1398
1399 ## ------------------------------------------------------ ##
1400 ## %name-prefix and %define api.prefix are incompatible. ##
1401 ## ------------------------------------------------------ ##
1402
1403 AT_SETUP([[%name-prefix and %define api.prefix are incompatible]])
1404
1405 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
1406 # --------------------------------------------
1407 m4_pushdef([AT_TEST],
1408 [AT_DATA([[input.y]],
1409 [[$1
1410 %%
1411 exp:;
1412 ]])
1413 AT_BISON_CHECK([[$2 input.y]], [[1]], [[]],
1414 [[$3: '%name-prefix' and '%define api.prefix' cannot be used together
1415 ]])
1416 ])
1417
1418 AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18])
1419 AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:2])
1420 AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:2])
1421 AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18])
1422
1423 m4_popdef([AT_TEST])
1424
1425 AT_CLEANUP
1426
1427
1428 ## -------------- ##
1429 ## Stray $ or @. ##
1430 ## -------------- ##
1431
1432 AT_SETUP([[Stray $ or @]])
1433
1434 # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
1435 # check that the warnings are reported once, not three times.
1436
1437 AT_DATA_GRAMMAR([[input.y]],
1438 [[%token TOK
1439 %destructor { $%; @%; } <*> exp TOK;
1440 %initial-action { $%; @%; };
1441 %printer { $%; @%; } <*> exp TOK;
1442 %%
1443 exp: TOK { $%; @%; $$ = $1; };
1444 ]])
1445
1446 AT_BISON_CHECK([[input.y]], 0, [],
1447 [[input.y:10.19: warning: stray '$'
1448 input.y:10.23: warning: stray '@'
1449 input.y:11.19: warning: stray '$'
1450 input.y:11.23: warning: stray '@'
1451 input.y:12.19: warning: stray '$'
1452 input.y:12.23: warning: stray '@'
1453 input.y:14.19: warning: stray '$'
1454 input.y:14.23: warning: stray '@'
1455 ]])
1456
1457 AT_CLEANUP
1458
1459
1460
1461 ## ---------------- ##
1462 ## Code injection. ##
1463 ## ---------------- ##
1464
1465
1466 AT_SETUP([[Code injection]])
1467
1468 m4_pattern_allow([^m4_errprintn$])
1469
1470 # AT_TEST([MACRO])
1471 # ----------------
1472 # Try to have MACRO be run by bison.
1473 m4_pushdef([AT_TEST],
1474 [AT_DATA([[input.y]],
1475 [[%type <$1(DEAD %type)> exp
1476 %token <$1(DEAD %token)> a
1477 %initial-action
1478 {
1479 $$;
1480 $<$1(DEAD %initial-action)>$
1481 };
1482 %printer
1483 {
1484 $$
1485 $<$1(DEAD %printer)>$
1486 } <> <*>;
1487 %lex-param
1488 {
1489 $1(DEAD %lex-param)
1490 };
1491 %parse-param
1492 {
1493 $1(DEAD %parse-param)
1494 };
1495 %%
1496 exp:
1497 a a[last]
1498 {
1499 $$;
1500 $][1;
1501 $<$1(DEAD action 1)>$
1502 $<$1(DEAD action 2)>1
1503 $<$1(DEAD action 3)>last
1504 $<$1(DEAD action 4)>0
1505 ;
1506 };
1507 ]])
1508
1509 # FIXME: Provide a means to iterate over all the skeletons.
1510 AT_BISON_CHECK([[-d input.y]])
1511 AT_BISON_CHECK([[-d -S glr.c input.y]])
1512 AT_BISON_CHECK([[-d -S lalr1.cc input.y]])
1513 AT_BISON_CHECK([[-d -S glr.cc input.y]])
1514 AT_BISON_CHECK([[ -S lalr1.java input.y]])
1515 ])
1516
1517 AT_TEST([m4_errprintn])
1518 AT_TEST([@:>@m4_errprintn])
1519
1520 m4_popdef([AT_TEST])
1521
1522 AT_CLEANUP