-[[input.y:8.48: warning: a `;' might be needed at the end of action code
-input.y:8.48: warning: future versions of Bison will not add the `;'
-input.y:9.48: warning: a `;' might be needed at the end of action code
-input.y:9.48: warning: future versions of Bison will not add the `;'
-input.y:10.48: warning: a `;' might be needed at the end of action code
-input.y:10.48: warning: future versions of Bison will not add the `;'
-input.y:11.48: warning: a `;' might be needed at the end of action code
-input.y:11.48: warning: future versions of Bison will not add the `;'
-input.y:12.48: warning: a `;' might be needed at the end of action code
-input.y:12.48: warning: future versions of Bison will not add the `;'
-input.y:13.48: warning: a `;' might be needed at the end of action code
-input.y:13.48: warning: future versions of Bison will not add the `;'
-input.y:20.1: warning: a `;' might be needed at the end of action code
-input.y:20.1: warning: future versions of Bison will not add the `;'
-input.y:21.1: warning: a `;' might be needed at the end of action code
-input.y:21.1: warning: future versions of Bison will not add the `;'
-input.y:22.1: warning: a `;' might be needed at the end of action code
-input.y:22.1: warning: future versions of Bison will not add the `;'
-input.y:23.1: warning: a `;' might be needed at the end of action code
-input.y:23.1: warning: future versions of Bison will not add the `;'
-input.y:24.1: warning: a `;' might be needed at the end of action code
-input.y:24.1: warning: future versions of Bison will not add the `;'
-input.y:25.1: warning: a `;' might be needed at the end of action code
-input.y:25.1: warning: future versions of Bison will not add the `;'
-input.y:31.1: warning: a `;' might be needed at the end of action code
-input.y:31.1: warning: future versions of Bison will not add the `;'
-input.y:32.1: warning: a `;' might be needed at the end of action code
-input.y:32.1: warning: future versions of Bison will not add the `;'
-input.y:33.1: warning: a `;' might be needed at the end of action code
-input.y:33.1: warning: future versions of Bison will not add the `;'
-input.y:34.1: warning: a `;' might be needed at the end of action code
-input.y:34.1: warning: future versions of Bison will not add the `;'
-input.y:35.1: warning: a `;' might be needed at the end of action code
-input.y:35.1: warning: future versions of Bison will not add the `;'
-input.y:36.1: warning: a `;' might be needed at the end of action code
-input.y:36.1: warning: future versions of Bison will not add the `;'
+[[input.y:8.48: warning: a ';' might be needed at the end of action code
+input.y:8.48: warning: future versions of Bison will not add the ';'
+input.y:9.48: warning: a ';' might be needed at the end of action code
+input.y:9.48: warning: future versions of Bison will not add the ';'
+input.y:10.48: warning: a ';' might be needed at the end of action code
+input.y:10.48: warning: future versions of Bison will not add the ';'
+input.y:11.48: warning: a ';' might be needed at the end of action code
+input.y:11.48: warning: future versions of Bison will not add the ';'
+input.y:12.48: warning: a ';' might be needed at the end of action code
+input.y:12.48: warning: future versions of Bison will not add the ';'
+input.y:13.48: warning: a ';' might be needed at the end of action code
+input.y:13.48: warning: future versions of Bison will not add the ';'
+input.y:20.1: warning: a ';' might be needed at the end of action code
+input.y:20.1: warning: future versions of Bison will not add the ';'
+input.y:21.1: warning: a ';' might be needed at the end of action code
+input.y:21.1: warning: future versions of Bison will not add the ';'
+input.y:22.1: warning: a ';' might be needed at the end of action code
+input.y:22.1: warning: future versions of Bison will not add the ';'
+input.y:23.1: warning: a ';' might be needed at the end of action code
+input.y:23.1: warning: future versions of Bison will not add the ';'
+input.y:24.1: warning: a ';' might be needed at the end of action code
+input.y:24.1: warning: future versions of Bison will not add the ';'
+input.y:25.1: warning: a ';' might be needed at the end of action code
+input.y:25.1: warning: future versions of Bison will not add the ';'
+input.y:31.1: warning: a ';' might be needed at the end of action code
+input.y:31.1: warning: future versions of Bison will not add the ';'
+input.y:32.1: warning: a ';' might be needed at the end of action code
+input.y:32.1: warning: future versions of Bison will not add the ';'
+input.y:33.1: warning: a ';' might be needed at the end of action code
+input.y:33.1: warning: future versions of Bison will not add the ';'
+input.y:34.1: warning: a ';' might be needed at the end of action code
+input.y:34.1: warning: future versions of Bison will not add the ';'
+input.y:35.1: warning: a ';' might be needed at the end of action code
+input.y:35.1: warning: future versions of Bison will not add the ';'
+input.y:36.1: warning: a ';' might be needed at the end of action code
+input.y:36.1: warning: future versions of Bison will not add the ';'
-AT_CHECK([[grep -c '/\* TEST:N:2 \*/ }$' input.c]], [0], [[3
-]])
-AT_CHECK([[grep -c '/\* TEST:Y:2 \*/ ;}$' input.c]], [0], [[6
+
+AT_MATCHES_CHECK([input.c], [[/\* TEST:N:2 \*/ \}$]], [[3]])
+AT_MATCHES_CHECK([input.c], [[/\* TEST:Y:2 \*/ ;\}$]], [[6]])
+AT_MATCHES_CHECK([input.c], [[// TEST:N:1 [;{}]*\n\}$]], [[6]])
+AT_MATCHES_CHECK([input.c], [[// TEST:Y:1 [;{}]*\n;\}$]], [[12]])
+AT_MATCHES_CHECK([input.c], [[#define TEST_MACRO_N \\\n\[\]"broken\\" \$ \@ \$\$ \@\$ \[\];\\\nstring;"\}]], [[2]])
+
+AT_CLEANUP
+
+
+## -------------------------------------------------- ##
+## Destroying lookahead assigned by semantic action. ##
+## -------------------------------------------------- ##
+
+AT_SETUP([[Destroying lookahead assigned by semantic action]])
+
+AT_BISON_OPTION_PUSHDEFS
+AT_DATA_GRAMMAR([input.y],
+[[
+%code {
+ #include <assert.h>
+ #include <stdio.h>
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
+ #define USE(Var)
+}
+
+%destructor { fprintf (stderr, "'a' destructor\n"); } 'a'
+%destructor { fprintf (stderr, "'b' destructor\n"); } 'b'
+
+%%
+
+// In a previous version of Bison, yychar assigned by the semantic
+// action below was not translated into yytoken before the lookahead was
+// discarded and thus before its destructor (selected according to
+// yytoken) was called in order to return from yyparse. This would
+// happen even if YYACCEPT was performed in a later semantic action as
+// long as only consistent states with default reductions were visited
+// in between. However, we leave YYACCEPT in the same semantic action
+// for this test in order to show that skeletons cannot simply translate
+// immediately after every semantic action because a semantic action
+// that has set yychar might not always return normally. Instead,
+// skeletons must translate before every use of yytoken.
+start: 'a' accept { USE($1); } ;
+accept: /*empty*/ {
+ assert (yychar == YYEMPTY);
+ yychar = 'b';
+ YYACCEPT;
+} ;
+
+%%
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([a])[
+int
+main (void)
+{
+ return yyparse ();
+}
-AT_CHECK([[sed -n '/TEST:Y:1/{N
-s/\n/<NL>/gp}' input.c | grep -c '// TEST:Y:1 [;{}]*<NL>;}$']], [0], [[12
+
+AT_CLEANUP
+
+## ---------- ##
+## YYBACKUP. ##
+## ---------- ##
+
+AT_SETUP([[YYBACKUP]])
+
+AT_BISON_OPTION_PUSHDEFS([%pure-parser])
+
+AT_DATA_GRAMMAR([input.y],
+[[
+%error-verbose
+%debug
+%pure-parser
+%code {
+# include <stdio.h>
+# include <stdlib.h>
+# include <assert.h>
+
+ ]AT_YYERROR_DECLARE[
+ static int yylex (YYSTYPE *yylval);
+}
+%%
+input:
+ exp exp {}
+;
+
+exp:
+ 'a' { printf ("a: %d\n", $1); }
+| 'b' { YYBACKUP('a', 123); }
+| 'c' 'd' { YYBACKUP('a', 456); }
+;
+
+%%
+]AT_YYERROR_DEFINE[
+static int
+yylex (YYSTYPE *yylval)
+{
+ static char const input[] = "bcd";
+ static size_t toknum;
+ assert (toknum < sizeof input);
+ *yylval = (toknum + 1) * 10;
+ return input[toknum++];
+}
+
+int
+main (void)
+{
+ yydebug = !!getenv("YYDEBUG");
+ return yyparse ();
+}