]> git.saurik.com Git - bison.git/blob - tests/c++.at
c++: revamp the support for variants
[bison.git] / tests / c++.at
1 # Checking the C++ Features. -*- Autotest -*-
2
3 # Copyright (C) 2004-2005, 2007-2013 Free Software Foundation, Inc.
4
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 AT_BANNER([[C++ Features.]])
19
20
21 ## --------------------------- ##
22 ## C++ Variant-based Symbols. ##
23 ## --------------------------- ##
24
25 AT_SETUP([C++ Variant-based Symbols])
26
27 AT_KEYWORDS([variant])
28
29 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc" %debug $1])
30 # Store strings and integers in a list of strings.
31 AT_DATA_GRAMMAR([list.yy],
32 [[%skeleton "lalr1.cc"
33 %define api.value.type variant
34 %define parse.assert
35 %debug
36
37 %code top
38 {
39 // Get access to stack_symbol_type for the tests.
40 # define private public
41 }
42 %code provides
43 {
44 ]AT_YYLEX_DECLARE[
45 }
46
47 %token <int> INT "int"
48 %type < std::list<int> > exp
49
50 %printer { yyo << $$; } <int>
51 %printer
52 {
53 for (std::list<int>::const_iterator i = $$.begin (); i != $$.end (); ++i)
54 {
55 if (i != $$.begin ())
56 yyo << ", ";
57 yyo << *i;
58 }
59 } < std::list<int> >
60
61 %code requires { #include <list> }
62 %code { int yylex (yy::parser::semantic_type* yylval); }
63
64 %%
65 exp: "int" { $$.push_back ($1); }
66 %%
67 ]AT_YYERROR_DEFINE[
68 ]AT_YYLEX_DEFINE[
69
70 int main()
71 {
72 {
73 yy::parser::symbol_type s = yy::parser::make_INT(12);
74 std::cerr << s.value.as<int>() << std::endl;
75 }
76
77 {
78 yy::parser::symbol_type s = yy::parser::make_INT(123);
79 yy::parser::stack_symbol_type ss(1, s);
80 std::cerr << ss.value.as<int>() << std::endl;
81 }
82
83 {
84 yy::parser::stack_type st;
85 for (int i = 0; i < 100; ++i)
86 {
87 yy::parser::symbol_type s(yy::parser::make_INT(i));
88 yy::parser::stack_symbol_type ss(1, s);
89 st.push(ss);
90 }
91 }
92 }
93 ]])
94
95 AT_BISON_CHECK([-o list.cc list.yy])
96 AT_COMPILE_CXX([list], [$NO_STRICT_ALIAS_CXXFLAGS list.cc])
97 AT_PARSER_CHECK([./list], 0, [],
98 [12
99 123
100 ])
101
102 AT_BISON_OPTION_POPDEFS
103 AT_CLEANUP
104
105
106 ## ---------- ##
107 ## Variants. ##
108 ## ---------- ##
109
110 # AT_TEST([DIRECTIVES])
111 # ---------------------
112 # Check the support of variants in C++, with the additional DIRECTIVES.
113 m4_pushdef([AT_TEST],
114 [AT_SETUP([Variants $1])
115
116 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc" $1])
117 # Store strings and integers in a list of strings.
118 AT_DATA_GRAMMAR([list.yy],
119 [[%debug
120 %skeleton "lalr1.cc"
121 %defines
122 %define api.value.type variant
123 ]m4_bpatsubst([$1], [\\n], [
124 ])[
125
126 %code requires // code for the .hh file
127 {
128 #include <list>
129 #include <string>
130 typedef std::list<std::string> strings_type;
131 }
132
133 %code // code for the .cc file
134 {
135 #include <cstdlib> // abort, getenv
136 #include <iostream>
137 #include <sstream>
138
139 namespace yy
140 {
141 static]AT_TOKEN_CTOR_IF([[
142 parser::symbol_type yylex ()]], [[
143 parser::token_type yylex (parser::semantic_type* yylval]AT_LOCATION_IF([,
144 parser::location_type* yylloc])[)]])[;
145 }
146
147 // Printing a list of strings (for %printer).
148 // Koening look up will look into std, since that's an std::list.
149 namespace std
150 {
151 std::ostream&
152 operator<<(std::ostream& o, const strings_type& s)
153 {
154 o << '(';
155 for (strings_type::const_iterator i = s.begin (); i != s.end (); ++i)
156 {
157 if (i != s.begin ())
158 o << ", ";
159 o << *i;
160 }
161 return o << ')';
162 }
163 }
164
165 // Conversion to string.
166 template <typename T>
167 inline
168 std::string
169 string_cast (const T& t)
170 {
171 std::ostringstream o;
172 o << t;
173 return o.str ();
174 }
175 }
176
177 %token <::std::string> TEXT;
178 %token <int> NUMBER;
179 %token END_OF_FILE 0;
180
181 %type <::std::string> item;
182 // Using the template type to exercize its parsing.
183 // Starting with :: to ensure we don't output "<::" which starts by the
184 // digraph for the left square bracket.
185 %type <::std::list<std::string>> list result;
186
187 %printer { yyo << $][$; }
188 <int> <::std::string> <::std::list<std::string>>;
189 %%
190
191 result:
192 list { std::cout << $][1 << std::endl; }
193 ;
194
195 list:
196 /* nothing */ { /* Generates an empty string list */ }
197 | list item { std::swap ($][$,$][1); $$.push_back ($][2); }
198 | list error { std::swap ($][$,$][1); }
199 ;
200
201 item:
202 TEXT { std::swap ($][$,$][1); }
203 | NUMBER { if ($][1 == 3) YYERROR; else $][$ = string_cast ($][1); }
204 ;
205 %%
206
207 #ifdef TWO_STAGE_BUILD
208 # define BUILD(Type, Value) build<Type> () = Value
209 #else
210 # define BUILD(Type, Value) build (Value)
211 #endif
212
213 #define STAGE_MAX 5
214 namespace yy
215 {
216 static]AT_TOKEN_CTOR_IF([[
217 parser::symbol_type yylex ()]], [[
218 parser::token_type yylex (parser::semantic_type* yylval]AT_LOCATION_IF([,
219 parser::location_type* yylloc])[)]])[
220 {]AT_LOCATION_IF([
221 typedef parser::location_type location;])[
222 static int stage = -1;
223 ++stage;
224 if (stage == STAGE_MAX)
225 {]AT_TOKEN_CTOR_IF([[
226 return parser::make_END_OF_FILE (]AT_LOCATION_IF([location ()])[);]],
227 [AT_LOCATION_IF([
228 *yylloc = location ();])[
229 return parser::token::END_OF_FILE;]])[
230 }
231 else if (stage % 2)
232 {]AT_TOKEN_CTOR_IF([[
233 return parser::make_NUMBER (stage]AT_LOCATION_IF([, location ()])[);]],
234 [[
235 yylval->BUILD (int, stage);]AT_LOCATION_IF([
236 *yylloc = location ();])[
237 return parser::token::NUMBER;]])[
238 }
239 else
240 {]AT_TOKEN_CTOR_IF([[
241 return parser::make_TEXT (string_cast (stage)]AT_LOCATION_IF([, location ()])[);]], [[
242 yylval->BUILD (std::string, string_cast (stage));]AT_LOCATION_IF([
243 *yylloc = location ();])[
244 return parser::token::TEXT;]])[
245 }
246 abort ();
247 }
248 }
249
250 ]AT_YYERROR_DEFINE[
251 ]AT_MAIN_DEFINE[
252 ]])
253
254 AT_BISON_CHECK([-o list.cc list.yy])
255 AT_COMPILE_CXX([list], [$NO_STRICT_ALIAS_CXXFLAGS list.cc])
256 AT_PARSER_CHECK([./list], 0,
257 [(0, 1, 2, 4)
258 ])
259
260 AT_BISON_OPTION_POPDEFS
261 AT_CLEANUP
262 ])
263
264 AT_TEST([])
265 AT_TEST([%define parse.assert])
266 AT_TEST([%locations %define parse.assert])
267 AT_TEST([[%define parse.assert %code {\n#define TWO_STAGE_BUILD\n}]])
268 AT_TEST([[%define parse.assert %define api.token.constructor]])
269 AT_TEST([[%define parse.assert %define api.token.constructor %define api.token.prefix "TOK_"]])
270 AT_TEST([[%locations %define parse.assert %define api.token.constructor %define api.token.prefix "TOK_"]])
271
272 m4_popdef([AT_TEST])
273
274
275 ## ----------------------- ##
276 ## Doxygen Documentation. ##
277 ## ----------------------- ##
278
279 m4_define([AT_CHECK_DOXYGEN],
280 [m4_case([$1],
281 [Public], [m4_pushdef([AT_DOXYGEN_PRIVATE], [NO])],
282 [Private], [m4_pushdef([AT_DOXYGEN_PRIVATE], [YES])],
283 [m4_fatal([invalid argument: $1])])
284 AT_SETUP([Doxygen $1 Documentation])
285
286 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
287 AT_DATA([input.yy],
288 [[%skeleton "lalr1.cc"
289 %locations
290 %debug
291 %defines
292 %%
293 exp: /* empty */;
294 %%
295 ]AT_YYERROR_DEFINE[
296 ]])
297
298 AT_BISON_CHECK([-o input.cc input.yy], 0)
299
300 AT_DATA([Doxyfile],
301 [# The PROJECT_NAME tag is a single word (or a sequence of words
302 # surrounded by quotes) that should identify the project.
303 PROJECT_NAME = "Bison C++ Parser"
304
305 # The QUIET tag can be used to turn on/off the messages that are
306 # generated by doxygen. Possible values are YES and NO. If left blank
307 # NO is used.
308 QUIET = YES
309
310 # The WARNINGS tag can be used to turn on/off the warning messages
311 # that are generated by doxygen. Possible values are YES and NO. If
312 # left blank NO is used.
313 WARNINGS = YES
314 # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate
315 # warnings for undocumented members. If EXTRACT_ALL is set to YES then
316 # this flag will automatically be disabled.
317 WARN_IF_UNDOCUMENTED = YES
318 # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings
319 # for potential errors in the documentation, such as not documenting
320 # some parameters in a documented function, or documenting parameters
321 # that don't exist or using markup commands wrongly.
322 WARN_IF_DOC_ERROR = YES
323 # The WARN_FORMAT tag determines the format of the warning messages
324 # that doxygen can produce. The string should contain the $file,
325 # $line, and $text tags, which will be replaced by the file and line
326 # number from which the warning originated and the warning text.
327 WARN_FORMAT = "$file:$line: $text"
328
329 # If the EXTRACT_ALL tag is set to YES doxygen will assume all
330 # entities in documentation are documented, even if no documentation
331 # was available. Private class members and static file members will
332 # be hidden unless the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set
333 # to YES
334 EXTRACT_ALL = YES
335
336 # If the EXTRACT_PRIVATE tag is set to YES all private members of a
337 # class will be included in the documentation.
338 EXTRACT_PRIVATE = AT_DOXYGEN_PRIVATE
339
340 # If the EXTRACT_STATIC tag is set to YES all static members of a file
341 # will be included in the documentation.
342 EXTRACT_STATIC = AT_DOXYGEN_PRIVATE
343 ])
344
345 AT_CHECK([doxygen --version || exit 77], 0, ignore)
346 AT_CHECK([doxygen], 0, [], [ignore])
347
348 AT_BISON_OPTION_POPDEFS
349 AT_CLEANUP
350
351 m4_popdef([AT_DOXYGEN_PRIVATE])
352 ])# AT_CHECK_DOXYGEN
353
354 AT_CHECK_DOXYGEN([Public])
355 AT_CHECK_DOXYGEN([Private])
356
357
358 ## ------------ ##
359 ## Namespaces. ##
360 ## ------------ ##
361
362 # AT_TEST(NAMESPACE-DECL, [COMPILE-ERROR])
363 # ----------------------------------------
364 # See if Bison can handle %define namespace "NAMESPACE-DECL". If COMPILE-ERROR
365 # is specified, then Bison should accept the input, but compilation will fail,
366 # so don't check compilation.
367 m4_pushdef([AT_TEST],
368 [AT_BISON_OPTION_PUSHDEFS([%language "C++" %define api.namespace "$1"])
369 AT_DATA_GRAMMAR([[input.y]],
370 [[%language "C++"
371 %defines
372 %define api.namespace "]$1["
373 %union { int i; }
374 %define global_tokens_and_yystype
375 %locations
376
377 %code {
378 // YYSTYPE contains a namespace reference.
379 int yylex (YYSTYPE *lval, const ]$1[::parser::location_type*) {
380 lval->i = 3;
381 return 0;
382 }
383 }
384
385 %%
386
387 start: ;
388
389 %%
390
391 void
392 ]$1[::parser::error (const ]$1[::parser::location_type &loc,
393 const std::string &msg)
394 {
395 std::cerr << "At " << loc << ": " << msg << std::endl;
396 }
397
398 ]AT_MAIN_DEFINE[
399 ]])
400
401 AT_BISON_CHECK([[-o input.cc input.y]])
402
403 m4_if([$#], [1],
404 [AT_COMPILE_CXX([[input]], [[input.cc]])
405 AT_PARSER_CHECK([[./input]])])
406 AT_BISON_OPTION_POPDEFS
407 ])
408
409 AT_SETUP([[Relative namespace references]])
410 AT_TEST([[foo]])
411 AT_TEST([[foo::bar]])
412 AT_TEST([[foo::bar::baz]])
413 AT_CLEANUP
414
415 AT_SETUP([[Absolute namespace references]])
416 AT_TEST([[::foo]])
417 AT_TEST([[::foo::bar]])
418 AT_TEST([[::foo::bar::baz]])
419 AT_TEST([[ ::foo]])
420 AT_TEST([[ ::foo::bar]])
421 AT_TEST([[ ::foo::bar::baz]])
422 AT_CLEANUP
423
424 AT_SETUP([[Syntactically invalid namespace references]])
425 AT_TEST([[:foo:bar]], [[-]])
426 AT_TEST([[foo: :bar]], [[-]])
427 # This one is interesting because `[3]' is encoded as `@<:@3@:>@', which
428 # contains single occurrences of `:'.
429 AT_TEST([[foo[3]::bar::baz]], [[-]])
430 AT_TEST([[foo::bar,baz]], [[-]])
431 AT_TEST([[foo::bar::(baz /* Pacify Emacs ) */]], [[-]])
432 AT_CLEANUP
433
434 m4_popdef([AT_TEST])
435
436 ## -------------------------------------- ##
437 ## Syntax error discarding no lookahead. ##
438 ## -------------------------------------- ##
439
440 # After a syntax error, lalr1.cc used to not check whether there
441 # actually is a lookahead before discarding the lookahead. As a result,
442 # it mistakenly invoked the destructor for the previous lookahead.
443
444 AT_SETUP([[Syntax error discarding no lookahead]])
445
446 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
447
448 AT_DATA_GRAMMAR([[input.yy]],
449 [[%skeleton "lalr1.cc"
450
451 %code {
452 #include <string>
453 int yylex (yy::parser::semantic_type *);
454 #define USE(Args)
455 }
456
457 %defines
458 %define parse.error verbose
459
460 %nonassoc 'a' ;
461
462 %destructor {
463 std::cerr << "Discarding 'a'." << std::endl;
464 } 'a'
465
466 %%
467
468 start: error-reduce consistent-error 'a' { USE ($3); };
469
470 error-reduce:
471 'a' 'a' consistent-error 'a' { USE (($1, $2, $4)); }
472 | 'a' error { std::cerr << "Reducing 'a'." << std::endl; USE ($1); }
473 ;
474
475 consistent-error:
476 'a'
477 | /*empty*/ %prec 'a'
478 ;
479
480 // Provide another context in which all rules are useful so that this
481 // test case looks a little more realistic.
482 start: 'b' consistent-error ;
483
484 %%
485
486 int
487 yylex (yy::parser::semantic_type *)
488 {
489 static char const *input = "aa";
490 return *input++;
491 }
492
493 void
494 yy::parser::error (const std::string &m)
495 {
496 std::cerr << m << std::endl;
497 }
498
499 ]AT_MAIN_DEFINE[
500 ]])
501
502 AT_BISON_CHECK([[-o input.cc input.yy]])
503 AT_COMPILE_CXX([[input]])
504 # This used to print "Discarding 'a'." again at the end.
505 AT_PARSER_CHECK([[./input]], [[1]], [[]],
506 [[syntax error
507 Discarding 'a'.
508 Reducing 'a'.
509 ]])
510
511 AT_BISON_OPTION_POPDEFS
512 AT_CLEANUP
513
514
515 ## --------------------------- ##
516 ## Syntax error as exception. ##
517 ## --------------------------- ##
518
519 AT_SETUP([[Syntax error as exception]])
520
521 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
522
523 AT_DATA_GRAMMAR([[input.yy]],
524 [[%skeleton "lalr1.cc"
525
526 %code
527 {
528 #include <cstdlib>
529 int yylex (yy::parser::semantic_type *);
530 }
531
532 %defines
533 %define api.value.type variant
534 %define parse.error verbose
535 %define parse.trace
536 %%
537
538 start:
539 thing
540 | start thing
541 ;
542
543 thing:
544 error { std::cerr << "caught error" << std::endl; }
545 | item
546 ;
547
548 item:
549 'a'
550 | 's'
551 {
552 throw yy::parser::syntax_error ("invalid expression");
553 }
554
555 %%
556
557 int
558 yylex (yy::parser::semantic_type *)
559 {
560 // 's': syntax error, 'l': lexical error.
561 static char const *input = "asal";
562 switch (int res = *input++)
563 {
564 case 'l':
565 throw yy::parser::syntax_error ("invalid character");
566 default:
567 return res;
568 }
569 }
570
571 void
572 yy::parser::error (const std::string &m)
573 {
574 std::cerr << "error: " << m << std::endl;
575 }
576 ]AT_MAIN_DEFINE[
577 ]])
578
579 AT_BISON_CHECK([[-o input.cc input.yy]])
580 AT_COMPILE_CXX([[input]])
581
582 AT_PARSER_CHECK([[./input]], [[0]], [[]],
583 [[error: invalid expression
584 caught error
585 error: invalid character
586 caught error
587 ]])
588
589 AT_BISON_OPTION_POPDEFS
590 AT_CLEANUP
591
592
593 ## ------------------ ##
594 ## Exception safety. ##
595 ## ------------------ ##
596
597 AT_SETUP([[Exception safety]])
598
599 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
600
601 AT_DATA_GRAMMAR([[input.yy]],
602 [[%skeleton "lalr1.cc"
603 %defines // FIXME: Mandated in 2.6.
604 %debug
605 %error-verbose
606
607 %code requires
608 {
609 #include <cassert>
610 #include <cstdlib> // size_t and getenv.
611 #include <iostream>
612 #include <list>
613
614 bool debug = false;
615
616 /// A class that counts its number of instances.
617 struct Object
618 {
619 typedef std::list<const Object*> objects;
620 static objects instances;
621 char val;
622
623 static bool
624 empty ()
625 {
626 return instances.empty();
627 }
628
629 static void
630 log (Object const *o, const std::string& msg)
631 {
632 if (debug)
633 {
634 if (o)
635 std::cerr << o << "->";
636 std::cerr << msg << " {";
637 const char* sep = " ";
638 for (objects::const_iterator i = instances.begin(),
639 i_end = instances.end();
640 i != i_end;
641 ++i)
642 {
643 std::cerr << sep << *i;
644 sep = ", ";
645 }
646 std::cerr << " }" << std::endl;
647 }
648 }
649
650 Object (char v)
651 : val (v)
652 {
653 instances.push_back(this);
654 log (this, "Object::Object");
655 }
656
657 ~Object ()
658 {
659 instances.remove(this);
660 log (this, "Object::~Object");
661 }
662 };
663 }
664
665 %code
666 {
667 #include <cassert>
668 #include <cstring> // strchr
669 #include <stdexcept>
670 int yylex (yy::parser::semantic_type *);
671 Object::objects Object::instances;
672 static char const *input;
673 }
674
675 %union
676 {
677 Object *obj;
678 }
679
680 %initial-action
681 {
682 if (strchr (input, 'i'))
683 throw std::runtime_error ("initial-action");
684 }
685
686 %destructor { delete $$; } <obj>;
687 %printer
688 {
689 yyo << $$ << " '" << $$->val << '\'';
690 if ($$->val == 'p')
691 throw std::runtime_error ("printer");
692 } <obj>;
693
694 %token <obj> 'a' 'E' 'e' 'p' 'R' 's' 'T'
695 %type <obj> list item
696
697 %%
698
699 start: list { delete $1; };
700
701 list:
702 item { $$ = $1; }
703 | item list { $$ = $1; delete $2; } // Right recursion to load the stack.
704 ;
705
706 item:
707 'a' { $$ = $1; }
708 | 'e' { YYUSE ($$); YYUSE($1); error ("syntax error"); }
709 // Not just 'E', otherwise we reduce when 'E' is the lookahead, and
710 // then the stack is emptied, defeating the point of the test.
711 | 'E' 'a' { YYUSE($1); $$ = $2; }
712 | 'R' { $$ = YY_NULL; delete $1; YYERROR; }
713 | 'p' { $$ = $1; }
714 | 's' { $$ = $1; throw std::runtime_error ("reduction"); }
715 | 'T' { $$ = YY_NULL; delete $1; YYABORT; }
716 | error { $$ = YY_NULL; yyerrok; }
717 ;
718 %%
719
720 int
721 yylex (yy::parser::semantic_type *lvalp)
722 {
723 // 'a': no error.
724 // 'e': user action calls error.
725 // 'E': syntax error, with yyerror that throws.
726 // 'i': initial action throws.
727 // 'l': yylex throws.
728 // 'R': call YYERROR in the action
729 // 's': reduction throws.
730 // 'T': call YYABORT in the action
731 switch (int res = *input++)
732 {
733 case 'l':
734 throw std::runtime_error ("yylex");
735 default:
736 lvalp->obj = new Object (res);
737 // Fall through.
738 case 0:
739 return res;
740 }
741 }
742
743 /* A C++ error reporting function. */
744 void
745 yy::parser::error (const std::string& m)
746 {
747 throw std::runtime_error (m);
748 }
749
750 int
751 main (int argc, const char *argv[])
752 {
753 switch (argc)
754 {
755 case 2:
756 input = argv[1];
757 break;
758 case 3:
759 assert (std::string(argv[1]) == "--debug");
760 debug = 1;
761 input = argv[2];
762 break;
763 default:
764 abort ();
765 }
766
767 yy::parser parser;
768 debug |= !!getenv ("YYDEBUG");
769 parser.set_debug_level (debug);
770 int res = 2;
771 try
772 {
773 res = parser.parse ();
774 }
775 catch (const std::exception& e)
776 {
777 std::cerr << "exception caught: " << e.what () << std::endl;
778 }
779 catch (...)
780 {
781 std::cerr << "unknown exception caught" << std::endl;
782 }
783 Object::log (YY_NULL, "end");
784 assert (Object::empty());
785 return res;
786 }
787 ]])
788 AT_BISON_CHECK([[-o input.cc --report=all input.yy]])
789 AT_COMPILE_CXX([[input]])
790
791 AT_PARSER_CHECK([[./input aaaas]], [[2]], [[]],
792 [[exception caught: reduction
793 ]])
794
795 AT_PARSER_CHECK([[./input aaaal]], [[2]], [[]],
796 [[exception caught: yylex
797 ]])
798
799 AT_PARSER_CHECK([[./input i]], [[2]], [[]],
800 [[exception caught: initial-action
801 ]])
802
803 AT_PARSER_CHECK([[./input aaaap]])
804
805 AT_PARSER_CHECK([[./input --debug aaaap]], [[2]], [[]], [[stderr]])
806 AT_CHECK([[grep '^exception caught: printer$' stderr]], [], [ignore])
807
808 AT_PARSER_CHECK([[./input aaaae]], [[2]], [[]],
809 [[exception caught: syntax error
810 ]])
811
812 AT_PARSER_CHECK([[./input aaaaE]], [[2]], [[]],
813 [[exception caught: syntax error, unexpected $end, expecting 'a'
814 ]])
815
816 AT_PARSER_CHECK([[./input aaaaT]], [[1]])
817
818 # There is error-recovery, so exit success.
819 AT_PARSER_CHECK([[./input aaaaR]], [[0]])
820
821 AT_BISON_OPTION_POPDEFS
822
823 AT_CLEANUP
824
825 ## ------------------------------------ ##
826 ## C++ GLR parser identifier shadowing ##
827 ## ------------------------------------ ##
828
829 AT_SETUP([[C++ GLR parser identifier shadowing]])
830
831 AT_DATA_GRAMMAR([input.yy], [
832 %skeleton "glr.cc"
833
834 %union
835 {
836 int ival;
837 }
838
839 %token <ival> ZERO;
840
841 %code
842 {
843 int yylex (yy::parser::semantic_type *yylval);
844 }
845
846 %%
847 exp: ZERO
848
849 %%
850
851 int yylex (yy::parser::semantic_type *yylval)
852 {
853 // Note: this argument is unused, but named on purpose. There used to be a
854 // bug with a macro that erroneously expanded this identifier to
855 // yystackp->yyval.
856 YYUSE (yylval);
857 return yy::parser::token::ZERO;
858 }
859
860 void yy::parser::error (std::string const&)
861 {}
862
863 int main()
864 {}
865 ])
866
867 AT_BISON_CHECK([[-o input.cc input.yy]])
868 AT_COMPILE_CXX([[input]])
869
870 AT_CLEANUP