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