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