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