bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: proposal: simplify prologue alternatives into %code


From: Joel E. Denny
Subject: Re: proposal: simplify prologue alternatives into %code
Date: Fri, 5 Jan 2007 03:15:12 -0500 (EST)

On Thu, 4 Jan 2007, Joel E. Denny wrote:

> Last month, Hans Aberg, Jeff Inman, and I discussed the prologue 
> alternative directives currently implemented in Bison CVS: %code, 
> %requires, %provides, and %code-top.  That discussion convinced me that 
> these directives could use another revision.  I'd like to implement the 
> following proposal, which I believe is close to what Hans proposed.  It 
> should simplify Bison internals, it should be more flexible when 
> developing new skeletons, and I think it should be a bit more intuitive 
> for the user.  Comments from anyone are welcome:

There may be some details left to iron out, but my conversation with Paolo 
has me convinced that this proposal is at least an improvement.  I 
committed the following to implement it.

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1647
diff -p -u -r1.1647 ChangeLog
--- ChangeLog   4 Jan 2007 04:51:21 -0000       1.1647
+++ ChangeLog   5 Jan 2007 08:06:03 -0000
@@ -1,3 +1,42 @@
+2007-01-04  Joel E. Denny  <address@hidden>
+
+       Consolidate the 4 prologue alternative directives (%code, %requires,
+       %provides, and %code-top) into a single %code directive with an
+       optional qualifier field.  Discussed at
+       <http://lists.gnu.org/archive/html/bison-patches/2007-01/msg00012.html>.
+       * NEWS (2.3a+): Rewrite the existing entry for the prologue
+       alternatives.
+       * doc/bison.texinfo (Prologue Alternatives): Update.
+       (Decl Summary): Update to %code "requires" and %code "provides".
+       (Calc++ Parser): Update to %code "requires".
+       (Bison Symbols): Remove entries for %requires, %provides, and
+       %code-top.  Rewrite %code entry, and add a %code "QUALIFIER" entry.
+       * data/bison.m4 (b4_user_provides, b4_user_requires): Remove as these
+       are replaced by b4_percent_code_provides and b4_percent_code_requires,
+       which are skeleton-specific.
+       (b4_check_percent_code_qualifiers): New.  A skeleton can use this to
+       declare what %code qualifiers it supports and to complain if any other
+       qualifiers were used in the grammar.
+       * data/glr.cc: Update to use b4_user_code([b4_percent_code_requires])
+       and b4_user_code([b4_percent_code_provides]) in place of
+       b4_user_requires and b4_user_provides.
+       * data/glr.c, data/lalr1.cc, data/push.c, data/yacc.c: Likewise.
+       Add b4_user_code([b4_percent_code_top]) and
+       b4_user_code([b4_percent_code]).
+       Invoke b4_check_percent_code_qualifiers.
+       * src/parse-gram.y (PERCENT_CODE_TOP, PERCENT_PROVIDES,
+       PERCENT_REQUIRES): Remove.
+       (grammar_declaration): Remove RHS's for %code-top, %provides, and
+       %requires.  Rewrite the %code RHS as the unqualified form defining the
+       muscle b4_percent_code.  Add another RHS for the qualified %code form,
+       which defines muscles of the form b4_percent_code_QUALIFIER and the
+       b4_used_percent_code_qualifiers muscle.
+       * src/scan-gram.l (PERCENT_CODE_TOP, PERCENT_PROVIDES,
+       PERCENT_REQUIRES): Remove.
+       * tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Update to use
+       %code "requires" and %code "provides".
+       * tests/input.at (Reject bad %code qualifiers): New.
+
 2007-01-03  Joel E. Denny  <address@hidden>
 
        Use the new code_props interface for destructors and printers.
Index: NEWS
===================================================================
RCS file: /sources/bison/bison/NEWS,v
retrieving revision 1.169
diff -p -u -r1.169 NEWS
--- NEWS        19 Dec 2006 00:34:36 -0000      1.169
+++ NEWS        5 Jan 2007 08:06:04 -0000
@@ -23,6 +23,25 @@ Changes in version 2.3a+ (????-??-??):
     %name-prefix "c_"
     %output "parser.c"
 
+* Bison 2.3a provided a new set of directives as a more flexible alternative to
+  the traditional Yacc prologue blocks.  Those have now been consolidated into
+  a single %code directive with an optional qualifier field, which identifies
+  the purpose of the code and thus the location(s) where Bison should generate
+  it:
+
+    1. `%code            {CODE}' replaces `%after-header  {CODE}'
+    2. `%code "requires" {CODE}' replaces `%start-header  {CODE}'
+    3. `%code "provides" {CODE}' replaces `%end-header    {CODE}'
+    4. `%code "top"      {CODE}' replaces `%before-header {CODE}'
+
+  See the %code entries in `Appendix A Bison Symbols' in the Bison manual for a
+  summary of the new functionality.  See the new section `Prologue
+  Alternatives' for a detailed discussion including the advantages of %code
+  over the traditional Yacc prologues.
+
+  The prologue alternatives are experimental.  More user feedback will help to
+  determine whether they should become permanent features.
+
 * Revised warning: unset or unused mid-rule values
 
   Since Bison 2.2, Bison has warned about mid-rule values that are set but not
@@ -66,76 +85,6 @@ Changes in version 2.3a+ (????-??-??):
   See the section `Freeing Discarded Symbols' in the Bison manual for further
   details.
 
-* The Yacc prologue alternatives from Bison 2.3a have been rewritten as the
-  following directives:
-
-    1. %code {CODE}
-
-       Other than semantic actions, this is probably the most common place you
-       should write verbatim code for the parser implementation.  It replaces
-       the traditional Yacc prologue, `%{CODE%}', for most purposes.  Compare
-       with:
-
-         - `%{CODE%}' appearing after the first `%union {CODE}' in a grammar
-          file.  While Bison will continue to support `%{CODE%}' for backward
-          compatibility, `%code {CODE}' is cleaner as its functionality does
-          not depend on its position in the grammar file relative to any
-          `%union {CODE}'.  Specifically, `%code {CODE}' always inserts your
-          CODE into the parser code file after the usual contents of the
-          parser header file.
-         - `%after-header {CODE}', which only Bison 2.3a supported.
-
-    2. %requires {CODE}
-
-       This is the right place to write dependency code for externally exposed
-       definitions required by Bison.  Such exposed definitions are those
-       usually appearing in the parser header file.  Thus, this is the right
-       place to define types referenced in `%union {CODE}' directives, and it
-       is the right place to override Bison's default YYSTYPE and YYLTYPE
-       definitions.  Compare with:
-
-         - `%{CODE%}' appearing before the first `%union {CODE}' in a grammar
-           file.  Unlike `%{CODE%}', `%requires {CODE}' inserts your CODE both
-           into the parser code file and into the parser header file since
-           Bison's required definitions should depend on it in both places.
-         - `%start-header {CODE}', which only Bison 2.3a supported.
-
-    3. %provides {CODE}
-
-       This is the right place to write additional definitions you would like
-       Bison to expose externally.  That is, this directive inserts your CODE
-       both into the parser header file and into the parser code file after
-       Bison's required definitions.  Compare with:
-
-         - `%end-header {CODE}', which only Bison 2.3a supported.
-
-    4. %code-top {CODE}
-
-       Occasionally it is desirable to insert code near the top of the parser
-       code file.  For example:
-
-         %code-top {
-           #define _GNU_SOURCE
-           #include <stdio.h>
-         }
-
-       Compare with:
-
-         - `%{CODE%}' appearing before the first `%union {CODE}' in a grammar
-           file.  `%code-top {CODE}' is cleaner as its functionality does not
-           depend on its position in the grammar file relative to any
-           `%union {CODE}'.
-         - `%before-header {CODE}', which only Bison 2.3a supported.
-
-  If you have multiple occurrences of any one of the above four directives,
-  Bison will concatenate the contents in the order they appear in the grammar
-  file.
-
-  The prologue alternatives are experimental.  More user feedback will help to
-  determine whether they should become permanent features.
-
-  Also see the new section `Prologue Alternatives' in the Bison manual.
-
 Changes in version 2.3a, 2006-09-13:
 
 * Instead of %union, you can define and use your own union type
Index: data/bison.m4
===================================================================
RCS file: /sources/bison/bison/data/bison.m4,v
retrieving revision 1.4
diff -p -u -r1.4 bison.m4
--- data/bison.m4       2 Jan 2007 02:10:42 -0000       1.4
+++ data/bison.m4       5 Jan 2007 08:06:04 -0000
@@ -184,8 +184,6 @@ m4_define([b4_define_user_code],
 # b4_user_initial_action
 # b4_user_post_prologue
 # b4_user_pre_prologue
-# b4_user_provides
-# b4_user_requires
 # b4_user_stype
 # ----------------------
 # Macros that issue user code, ending with synclines.
@@ -193,8 +191,38 @@ b4_define_user_code([actions])
 b4_define_user_code([initial_action])
 b4_define_user_code([post_prologue])
 b4_define_user_code([pre_prologue])
-b4_define_user_code([provides])
-b4_define_user_code([requires])
 b4_define_user_code([stype])
 
-
+# b4_check_percent_code_qualifiers([VAILD_QUALIFIER], [VALID_QUALIFIER], ...)
+# ---------------------------------------------------------------------------
+# Complain if any %code qualifier used in the grammar is not a valid qualifier.
+#
+# b4_used_percent_code_qualifiers must expand to a comma-delimited list of the
+# %code qualifiers used in the grammar.  The list as a whole must be quoted,
+# but individual qualifiers in it must not be.  Qualifiers will not be
+# M4-expanded.  Whitespace will not be stripped from the qualifiers.  Any
+# qualifier that is the empty string will be correctly parsed as such.  If
+# b4_used_percent_code_qualifiers expands to the empty string, then the list
+# contains one qualifier that is the empty string.  If
+# b4_used_percent_code_qualifiers is undefined, then the list contains no
+# qualifiers.  Multiple occurrences of the same qualifier are fine.
+#
+# Each VALID_QUALIFIER will be M4-expanded once to define a valid qualifier.  A
+# VALID_QUALIFIER that expands to the empty string will correctly define the
+# empty string as a valid qualifier.  If b4_used_percent_code_qualifiers is
+# invoked with empty parens, then there is one valid qualifier and it is the
+# empty string.  To specify that there are no valid qualifiers, invoke
+# b4_check_percent_code_qualifiers without parens.  Multiple occurrences of the
+# same valid qualifier are fine.
+#
+# Qualifiers and valid qualifiers must not contain the characters `,' or `&'.
+m4_define([b4_check_percent_code_qualifiers],
+[m4_ifdef([b4_used_percent_code_qualifiers], [
+m4_foreach([b4_qualifier],
+           
m4_dquote(m4_substr(m4_split(m4_translit(m4_dquote([,]b4_used_percent_code_qualifiers),
 [,], [&]), [[&]]), 4)),
+           [m4_if(m4_index(m4_if($#, 0, [], [[,]m4_quote($*)[,]]),
+                           [,]m4_defn([b4_qualifier])[,]),
+                  [-1],
+                  [m4_fatal([`]m4_defn([b4_qualifier])[' is not a recognized 
%code qualifier.])])
+           ])
+])])
Index: data/glr.c
===================================================================
RCS file: /sources/bison/bison/data/glr.c,v
retrieving revision 1.194
diff -p -u -r1.194 glr.c
--- data/glr.c  19 Dec 2006 00:34:36 -0000      1.194
+++ data/glr.c  5 Jan 2007 08:06:05 -0000
@@ -20,6 +20,7 @@ m4_divert(-1)                           
 
 
 m4_include(b4_pkgdatadir/[c.m4])
+b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
 
 b4_push_if([
 m4_fatal([Non-deterministic push parsers are not yet supported])])
@@ -153,6 +154,9 @@ b4_copyright([Skeleton implementation fo
 
 ]b4_identification
 
+m4_ifdef([b4_percent_code_top],
+[[/* Copy the %code "top" blocks.  */
+]b4_user_code([b4_percent_code_top])])[]dnl
 m4_if(b4_prefix, [yy], [],
 [/* Substitute the variable and function names.  */
 #define yyparse b4_prefix[]parse
@@ -172,9 +176,9 @@ dnl # ----------------------
 dnl # Declaration that might either go into the header (if --defines)
 dnl # or open coded in the parser body.
 m4_define([b4_shared_declarations],
-[m4_ifdef([b4_requires],
-[[/* Copy the %requires blocks.  */
-]b4_user_requires])[]dnl
+[m4_ifdef([b4_percent_code_requires],
+[[/* Copy the %code "requires" blocks.  */
+]b4_user_code([b4_percent_code_requires])])[]dnl
 
 b4_token_enums(b4_tokens)
 
@@ -205,9 +209,9 @@ typedef struct YYLTYPE
 # define YYLTYPE_IS_TRIVIAL 1
 #endif
 
-]m4_ifdef([b4_provides],
-[[/* Copy the %provides blocks.  */
-]b4_user_provides])[]dnl
+]m4_ifdef([b4_percent_code_provides],
+[[/* Copy the %code "provides" blocks.  */
+]b4_user_code([b4_percent_code_provides])])[]dnl
 ])
 
 b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
@@ -239,9 +243,13 @@ b4_defines_if([[#include "@basename(]b4_
 static YYSTYPE yyval_default;
 
 /* Copy the second part of user declarations.  */
-]b4_user_post_prologue[
+]b4_user_post_prologue
+m4_ifdef([b4_percent_code],
+[[/* Copy the unqualified %code blocks.  */
+]b4_user_code([b4_percent_code])
+])[]dnl
 
-#include <stdio.h>
+[#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
Index: data/glr.cc
===================================================================
RCS file: /sources/bison/bison/data/glr.cc,v
retrieving revision 1.29
diff -p -u -r1.29 glr.cc
--- data/glr.cc 12 Dec 2006 06:47:39 -0000      1.29
+++ data/glr.cc 5 Jan 2007 08:06:05 -0000
@@ -225,9 +225,9 @@ b4_copyright([Skeleton interface for Bis
 #ifndef PARSER_HEADER_H
 # define PARSER_HEADER_H
 
-]m4_ifdef([b4_requires],
-[[/* Copy the %requires blocks.  */
-]b4_user_requires])[
+]m4_ifdef([b4_percent_code_requires],
+[[/* Copy the %code "requires" blocks.  */
+]b4_user_code([b4_percent_code_requires])])[
 
 #include <string>
 #include <iostream>
@@ -373,8 +373,8 @@ m4_ifset([b4_global_tokens_and_yystype],
 
 }
 
-]m4_ifdef([b4_provides],
-[[/* Copy the %provides blocks.  */
-]b4_user_provides])[]dnl
+]m4_ifdef([b4_percent_code_provides],
+[[/* Copy the %code "provides" blocks.  */
+]b4_user_code([b4_percent_code_provides])])[]dnl
 
 [#endif /* ! defined PARSER_HEADER_H */]
Index: data/lalr1.cc
===================================================================
RCS file: /sources/bison/bison/data/lalr1.cc,v
retrieving revision 1.146
diff -p -u -r1.146 lalr1.cc
--- data/lalr1.cc       12 Dec 2006 06:47:39 -0000      1.146
+++ data/lalr1.cc       5 Jan 2007 08:06:05 -0000
@@ -20,6 +20,7 @@ m4_divert(-1)
 # 02110-1301  USA
 
 m4_include(b4_pkgdatadir/[c++.m4])
+b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
 
 # The header is mandatory.
 b4_defines_if([],
@@ -43,9 +44,9 @@ dnl FIXME: This is wrong, we want comput
 #ifndef PARSER_HEADER_H
 # define PARSER_HEADER_H
 
-]m4_ifdef([b4_requires],
-[[/* Copy the %requires blocks.  */
-]b4_user_requires])[
+]m4_ifdef([b4_percent_code_requires],
+[[/* Copy the %code "requires" blocks.  */
+]b4_user_code([b4_percent_code_requires])])[
 
 #include <string>
 #include <iostream>
@@ -295,15 +296,18 @@ b4_error_verbose_if([, int tok])[);
 # define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
 #endif
 ])
-m4_ifdef([b4_provides],
-[[/* Copy the %provides blocks.  */
-]b4_user_provides])[]dnl
+m4_ifdef([b4_percent_code_provides],
+[[/* Copy the %code "provides" blocks.  */
+]b4_user_code([b4_percent_code_provides])])[]dnl
 
 [#endif /* ! defined PARSER_HEADER_H */]
 ])dnl
 @output b4_parser_file_name
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
   [2002, 2003, 2004, 2005, 2006])
+m4_ifdef([b4_percent_code_top],
+[[/* Copy the %code "top" blocks.  */
+]b4_user_code([b4_percent_code_top])])[]dnl
 m4_if(b4_prefix, [yy], [],
 [
 // Take the name prefix into account.
@@ -316,9 +320,13 @@ b4_defines_if([[
 #include "@basename(]b4_spec_defines_file[@)"]])[
 
 /* User implementation prologue.  */
-]b4_user_post_prologue[
+]b4_user_post_prologue
+m4_ifdef([b4_percent_code],
+[[/* Copy the unqualified %code blocks.  */
+]b4_user_code([b4_percent_code])
+])[]dnl
 
-#ifndef YY_
+[#ifndef YY_
 # if YYENABLE_NLS
 #  if ENABLE_NLS
 #   include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
Index: data/push.c
===================================================================
RCS file: /sources/bison/bison/data/push.c,v
retrieving revision 1.29
diff -p -u -r1.29 push.c
--- data/push.c 2 Jan 2007 02:10:42 -0000       1.29
+++ data/push.c 5 Jan 2007 08:06:05 -0000
@@ -33,6 +33,7 @@ b4_use_push_for_pull_if([
   ])])
 
 m4_include(b4_pkgdatadir/[c.m4])
+b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
 
 ## ---------------- ##
 ## Default values.  ##
@@ -160,6 +161,9 @@ b4_copyright([Skeleton implementation fo
    USER NAME SPACE" below.  */
 
 ]b4_identification
+m4_ifdef([b4_percent_code_top],
+[[/* Copy the %code "top" blocks.  */
+]b4_user_code([b4_percent_code_top])])[]dnl
 m4_if(b4_prefix, [yy], [],
 [[/* Substitute the variable and function names.  */
 ]b4_pull_if([[#define yyparse         ]b4_prefix[parse
@@ -197,9 +201,9 @@ m4_if(b4_prefix, [yy], [],
 # define YYTOKEN_TABLE ]b4_token_table[
 #endif
 
-]m4_ifdef([b4_requires],
-[[/* Copy the %requires blocks.  */
-]b4_user_requires])[]dnl
+]m4_ifdef([b4_percent_code_requires],
+[[/* Copy the %code "requires" blocks.  */
+]b4_user_code([b4_percent_code_requires])])[]dnl
 
 b4_token_enums_defines(b4_tokens)[
 
@@ -250,14 +254,18 @@ b4_c_function_decl([[yypstate_delete]], 
                    [[[yypstate *yyps]], [[yyps]]])[
 #endif
 ]])
-m4_ifdef([b4_provides],
-[[/* Copy the %provides blocks.  */
-]b4_user_provides])[]dnl
+m4_ifdef([b4_percent_code_provides],
+[[/* Copy the %code "provides" blocks.  */
+]b4_user_code([b4_percent_code_provides])])[]dnl
 
 [/* Copy the second part of user declarations.  */
-]b4_user_post_prologue[
+]b4_user_post_prologue
+m4_ifdef([b4_percent_code],
+[[/* Copy the unqualified %code blocks.  */
+]b4_user_code([b4_percent_code])
+])[]dnl
 
-#ifdef short
+[#ifdef short
 # undef short
 #endif
 
@@ -1655,9 +1663,9 @@ b4_defines_if(
 b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
   [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
 
-m4_ifdef([b4_requires],
-[[/* Copy the %requires blocks.  */
-]b4_user_requires])[]dnl
+m4_ifdef([b4_percent_code_requires],
+[[/* Copy the %code "requires" blocks.  */
+]b4_user_code([b4_percent_code_requires])])[]dnl
 
 b4_token_enums_defines(b4_tokens)
 
@@ -1714,7 +1722,7 @@ b4_c_function_decl([b4_prefix[pstate_del
                    [[b4_prefix[pstate *yyps]], [[yyps]]])[
 #endif
 ]])
-m4_ifdef([b4_provides],
-[[/* Copy the %provides blocks.  */
-]b4_user_provides])[]
+m4_ifdef([b4_percent_code_provides],
+[[/* Copy the %code "provides" blocks.  */
+]b4_user_code([b4_percent_code_provides])])[]
 ])dnl b4_defines_if
Index: data/yacc.c
===================================================================
RCS file: /sources/bison/bison/data/yacc.c,v
retrieving revision 1.157
diff -p -u -r1.157 yacc.c
--- data/yacc.c 2 Jan 2007 02:10:42 -0000       1.157
+++ data/yacc.c 5 Jan 2007 08:06:06 -0000
@@ -24,6 +24,7 @@ m4_divert(-1)                           
 b4_use_push_for_pull_if([m4_include(b4_pkgdatadir/[push.c])m4_exit])
 
 m4_include(b4_pkgdatadir/[c.m4])
+b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
 
 ## ---------------- ##
 ## Default values.  ##
@@ -152,6 +153,9 @@ b4_copyright([Skeleton implementation fo
    USER NAME SPACE" below.  */
 
 ]b4_identification
+m4_ifdef([b4_percent_code_top],
+[[/* Copy the %code "top" blocks.  */
+]b4_user_code([b4_percent_code_top])])[]dnl
 m4_if(b4_prefix, [yy], [],
 [/* Substitute the variable and function names.  */
 #define yyparse b4_prefix[]parse
@@ -184,9 +188,9 @@ b4_locations_if([#define yylloc b4_prefi
 # define YYTOKEN_TABLE ]b4_token_table[
 #endif
 
-]m4_ifdef([b4_requires],
-[[/* Copy the %requires blocks.  */
-]b4_user_requires])[]dnl
+]m4_ifdef([b4_percent_code_requires],
+[[/* Copy the %code "requires" blocks.  */
+]b4_user_code([b4_percent_code_requires])])[]dnl
 
 b4_token_enums_defines(b4_tokens)[
 
@@ -216,14 +220,18 @@ typedef struct YYLTYPE
 # define YYLTYPE_IS_TRIVIAL 1
 #endif])
 
-m4_ifdef([b4_provides],
-[[/* Copy the %provides blocks.  */
-]b4_user_provides])[]dnl
+m4_ifdef([b4_percent_code_provides],
+[[/* Copy the %code "provides" blocks.  */
+]b4_user_code([b4_percent_code_provides])])[]dnl
 
 [/* Copy the second part of user declarations.  */
-]b4_user_post_prologue[
+]b4_user_post_prologue
+m4_ifdef([b4_percent_code],
+[[/* Copy the unqualified %code blocks.  */
+]b4_user_code([b4_percent_code])
+])[]dnl
 
-#ifdef short
+[#ifdef short
 # undef short
 #endif
 
@@ -1492,9 +1500,9 @@ b4_defines_if(
 b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
   [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
 
-m4_ifdef([b4_requires],
-[[/* Copy the %requires blocks.  */
-]b4_user_requires])[]dnl
+m4_ifdef([b4_percent_code_requires],
+[[/* Copy the %code "requires" blocks.  */
+]b4_user_code([b4_percent_code_requires])])[]dnl
 
 b4_token_enums_defines(b4_tokens)
 
@@ -1532,7 +1540,7 @@ typedef struct YYLTYPE
           [extern YYLTYPE b4_prefix[]lloc;])
 )dnl b4_locations_if
 
-m4_ifdef([b4_provides],
-[[/* Copy the %provides blocks.  */
-]b4_user_provides])[]
+m4_ifdef([b4_percent_code_provides],
+[[/* Copy the %code "provides" blocks.  */
+]b4_user_code([b4_percent_code_provides])])[]
 ])dnl b4_defines_if
Index: doc/bison.texinfo
===================================================================
RCS file: /sources/bison/bison/doc/bison.texinfo,v
retrieving revision 1.217
diff -p -u -r1.217 bison.texinfo
--- doc/bison.texinfo   19 Dec 2006 07:52:02 -0000      1.217
+++ doc/bison.texinfo   5 Jan 2007 08:06:09 -0000
@@ -2681,17 +2681,20 @@ feature test macros can affect the behav
 @cindex Prologue Alternatives
 
 @findex %code
address@hidden %requires
address@hidden %provides
address@hidden %code-top
address@hidden %code "requires"
address@hidden %code "provides"
address@hidden %code "top"
 (The prologue alternatives described here are experimental.
 More user feedback will help to determine whether they should become permanent
 features.)
 
 The functionality of @var{Prologue} sections can often be subtle and
 inflexible.
-As an alternative, Bison provides a set of more explicit directives:
address@hidden, @code{%requires}, @code{%provides}, and @code{%code-top}.
+As an alternative, Bison provides a %code directive with an explicit qualifier
+field, which identifies the purpose of the code and thus the location(s) where
+Bison should generate it.
+For C/C++, the qualifier can be omitted for the default location, or it can be
+"requires", "provides", or "top".
 @xref{Table of Symbols,,Bison Symbols}.
 
 Look again at the example of the previous section:
@@ -2723,7 +2726,7 @@ For example, if you decide to override B
 @code{YYLTYPE}, in which @var{Prologue} section should you write your new
 definition?
 You should write it in the first since Bison will insert that code into the
-parser code file @emph{before} the default @code{YYLTYPE} definition.
+parser source code file @emph{before} the default @code{YYLTYPE} definition.
 In which @var{Prologue} section should you prototype an internal function,
 @code{trace_token}, that accepts @code{YYLTYPE} and @code{yytokentype} as
 arguments?
@@ -2739,16 +2742,19 @@ Second, what if there is no @code{%union
 In that case, the second kind of @var{Prologue} section is not available.
 This behavior is not intuitive.
 
-To avoid this subtle @code{%union} dependency, rewrite the example using
address@hidden and @code{%code}.
+To avoid this subtle @code{%union} dependency, rewrite the example using a
address@hidden "top"} and an unqualified @code{%code}.
 Let's go ahead and add the new @code{YYLTYPE} definition and the
 @code{trace_token} prototype at the same time:
 
 @smallexample
-%code-top @{
+%code "top" @{
   #define _GNU_SOURCE
   #include <stdio.h>
-  /* The following code really belongs in a %requires; see below.  */
+
+  /* WARNING: The following code really belongs
+   * in a %code "requires"; see below.  */
+
   #include "ptypes.h"
   #define YYLTYPE YYLTYPE
   typedef struct YYLTYPE
@@ -2776,33 +2782,34 @@ Let's go ahead and add the new @code{YYL
 @end smallexample
 
 @noindent
-In this way, @code{%code-top} and @code{%code} achieve the same functionality
-as the two kinds of @var{Prologue} sections, but it's always explicit which
-kind you intend.
+In this way, @code{%code "top"} and the unqualified @code{%code} achieve the
+same functionality as the two kinds of @var{Prologue} sections, but it's always
+explicit which kind you intend.
 Moreover, both kinds are always available even in the absence of @code{%union}.
 
-The @code{%code-top} block above logically contains two parts.
-The first two lines need to appear in the parser code file.
-The fourth line is required by @code{YYSTYPE} and thus also needs to appear in
-the parser code file.
+The @code{%code "top"} block above logically contains two parts.
+The first two lines before the warning need to appear near the top of the
+parser source code file.
+The first line after the warning is required by @code{YYSTYPE} and thus also
+needs to appear in the parser source code file.
 However, if you've instructed Bison to generate a parser header file
-(@pxref{Table of Symbols, ,%defines}), you probably want the fourth line to
-appear before the @code{YYSTYPE} definition in that header file as well.
-Also, the @code{YYLTYPE} definition should appear in the parser header file to
+(@pxref{Table of Symbols, ,%defines}), you probably want that line to appear
+before the @code{YYSTYPE} definition in that header file as well.
+The @code{YYLTYPE} definition should also appear in the parser header file to
 override the default @code{YYLTYPE} definition there.
 
-In other words, in the @code{%code-top} block above, all but the first two
-lines are dependency code for externally exposed definitions (@code{YYSTYPE}
-and @code{YYLTYPE}) required by Bison.
-Thus, they belong in one or more @code{%requires}:
+In other words, in the @code{%code "top"} block above, all but the first two
+lines are dependency code required by the @code{YYSTYPE} and @code{YYLTYPE}
+definitions.
+Thus, they belong in one or more @code{%code "requires"}:
 
 @smallexample
-%code-top @{
+%code "top" @{
   #define _GNU_SOURCE
   #include <stdio.h>
 @}
 
-%requires @{
+%code "requires" @{
   #include "ptypes.h"
 @}
 %union @{
@@ -2810,7 +2817,7 @@ Thus, they belong in one or more @code{%
   tree t;  /* @address@hidden is defined in @file{ptypes.h}.} */
 @}
 
-%requires @{
+%code "requires" @{
   #define YYLTYPE YYLTYPE
   typedef struct YYLTYPE
   @{
@@ -2834,40 +2841,41 @@ Thus, they belong in one or more @code{%
 @noindent
 Now Bison will insert @code{#include "ptypes.h"} and the new @code{YYLTYPE}
 definition before the Bison-generated @code{YYSTYPE} and @code{YYLTYPE}
-definitions in both the parser code file and the parser header file.
-(By the same reasoning, @code{%requires} would also be the appropriate place to
-write your own definition for @code{YYSTYPE}.)
+definitions in both the parser source code file and the parser header file.
+(By the same reasoning, @code{%code "requires"} would also be the appropriate
+place to write your own definition for @code{YYSTYPE}.)
 
 When you are writing dependency code for @code{YYSTYPE} and @code{YYLTYPE}, you
-should prefer @code{%requires} over @code{%code-top} regardless of whether you
-instruct Bison to generate a parser header file.
+should prefer @code{%code "requires"} over @code{%code "top"} regardless of
+whether you instruct Bison to generate a parser header file.
 When you are writing code that you need Bison to insert only into the parser
-code file and that has no special need to appear at the top of the code file,
-you should prefer @code{%code} over @code{%code-top}.
+source code file and that has no special need to appear at the top of that
+file, you should prefer the unqualified @code{%code} over @code{%code "top"}.
 These practices will make the purpose of each block of your code explicit to
 Bison and to other developers reading your grammar file.
-Following these practices, we expect @code{%code} and @code{%requires} to be
-the most important of the four @var{Prologue} alternative directives discussed
-in this section.
+Following these practices, we expect the unqualified @code{%code} and
address@hidden "requires"} to be the most important of the four @var{Prologue}
+alternatives discussed in this section.
 
 At some point while developing your parser, you might decide to provide
 @code{trace_token} to modules that are external to your parser.
 Thus, you might wish for Bison to insert the prototype into both the parser
-header file and the parser code file.
-Since this function is not a dependency of any Bison-required definition (such
-as @code{YYSTYPE}), it doesn't make sense to move its prototype to a
address@hidden
+header file and the parser source code file.
+Since this function is not a dependency required by @code{YYSTYPE} or
address@hidden, it doesn't make sense to move its prototype to a
address@hidden "requires"}.
 More importantly, since it depends upon @code{YYLTYPE} and @code{yytokentype},
address@hidden is not sufficient.
-Instead, move its prototype from the @code{%code} to a @code{%provides}:
address@hidden "requires"} is not sufficient.
+Instead, move its prototype from the unqualified @code{%code} to a
address@hidden "provides"}:
 
 @smallexample
-%code-top @{
+%code "top" @{
   #define _GNU_SOURCE
   #include <stdio.h>
 @}
 
-%requires @{
+%code "requires" @{
   #include "ptypes.h"
 @}
 %union @{
@@ -2875,7 +2883,7 @@ Instead, move its prototype from the @co
   tree t;  /* @address@hidden is defined in @file{ptypes.h}.} */
 @}
 
-%requires @{
+%code "requires" @{
   #define YYLTYPE YYLTYPE
   typedef struct YYLTYPE
   @{
@@ -2887,7 +2895,7 @@ Instead, move its prototype from the @co
   @} YYLTYPE;
 @}
 
-%provides @{
+%code "provides" @{
   void trace_token (enum yytokentype token, YYLTYPE loc);
 @}
 
@@ -2901,12 +2909,13 @@ Instead, move its prototype from the @co
 
 @noindent
 Bison will insert the @code{trace_token} prototype into both the parser header
-file and the parser code file after the definitions for @code{yytokentype},
address@hidden, and @code{YYSTYPE}.
+file and the parser source code file after the definitions for
address@hidden, @code{YYLTYPE}, and @code{YYSTYPE}.
 
 The above examples are careful to write directives in an order that reflects
-the layout of the generated parser code and header files:
address@hidden, @code{%requires}, @code{%provides}, and then @code{%code}.
+the layout of the generated parser source code and header files:
address@hidden "top"}, @code{%code "requires"}, @code{%code "provides"}, and 
then
address@hidden
 While your grammar files may generally be easier to read if you also follow
 this order, Bison does not require it.
 Instead, Bison lets you choose an organization that makes sense to you.
@@ -2922,12 +2931,12 @@ For example, you may organize semantic-t
 type:
 
 @smallexample
-%requires @{ #include "type1.h" @}
+%code "requires" @{ #include "type1.h" @}
 %union @{ type1 field1; @}
 %destructor @{ type1_free ($$); @} <field1>
 %printer @{ type1_print ($$); @} <field1>
 
-%requires @{ #include "type2.h" @}
+%code "requires" @{ #include "type2.h" @}
 %union @{ type2 field2; @}
 %destructor @{ type2_free ($$); @} <field2>
 %printer @{ type2_print ($$); @} <field2>
@@ -2943,13 +2952,14 @@ counter-intuitive manner just because it
 Such an organization is not possible using @var{Prologue} sections.
 
 This section has been concerned with explaining the advantages of the four
address@hidden alternative directives over the original Yacc @var{Prologue}.
address@hidden alternatives over the original Yacc @var{Prologue}.
 However, in most cases when using these directives, you shouldn't need to
 think about all the low-level ordering issues discussed here.
 Instead, you should simply use these directives to label each block of your
 code according to its purpose and let Bison handle the ordering.
 @code{%code} is the most generic label.
-Move code to @code{%requires}, @code{%provides}, or @code{%code-top} as needed.
+Move code to @code{%code "requires"}, @code{%code "provides"}, or
address@hidden "top"} as needed.
 
 @node Bison Declarations
 @subsection The Bison Declarations Section
@@ -4598,11 +4608,11 @@ typically needs to be able to refer to t
 and to the token type codes.  @xref{Token Values, ,Semantic Values of
 Tokens}.
 
address@hidden %requires
address@hidden %provides
-If you have declared @code{%requires} or @code{%provides}, the output
-header also contains their code.
address@hidden of Symbols, ,%requires}.
address@hidden %code "requires"
address@hidden %code "provides"
+If you have declared @code{%code "requires"} or @code{%code "provides"}, the
+output header also contains their code.
address@hidden of Symbols, ,%code}.
 @end deffn
 
 @deffn {Directive} %defines @var{defines-file}
@@ -7863,18 +7873,18 @@ the grammar for.
 @end example
 
 @noindent
address@hidden %requires
address@hidden %code "requires"
 Then come the declarations/inclusions needed to define the
 @code{%union}.  Because the parser uses the parsing driver and
 reciprocally, both cannot include the header of the other.  Because the
 driver's header needs detailed knowledge about the parser class (in
 particular its inner types), it is the parser's header which will simply
 use a forward declaration of the driver.
address@hidden of Symbols, ,%requires}.
address@hidden of Symbols, ,%code}.
 
 @comment file: calc++-parser.yy
 @example
-%requires @{
+%code "requires" @{
 # include <string>
 class calcxx_driver;
 @}
@@ -8634,63 +8644,109 @@ Start-Symbol}.  It cannot be used in the
 @end deffn
 
 @deffn {Directive} %code @address@hidden@}
-Other than semantic actions, this is probably the most common place you should
-write verbatim code for the parser implementation.
-It replaces the traditional Yacc prologue,
address@hidden For C/C++, it replaces the traditional Yacc prologue,
address@hidden@address@hidden@}}, for most purposes.
address@hidden For Java, it inserts code into the parser class.
address@hidden %code
+This is the unqualified form of the @code{%code} directive.
+It inserts @var{code} verbatim at the default location in the output.
+That default location is determined by the selected target language and/or
+parser skeleton.
 
 @cindex Prologue
address@hidden %union
-Compare with @address@hidden@address@hidden (@pxref{Prologue, ,The Prologue})
-appearing after the first @code{%union @address@hidden@}} in a C/C++ based 
grammar
-file.
-While Bison will continue to support @address@hidden@address@hidden for 
backward
-compatibility, @code{%code @address@hidden@}} is cleaner as its functionality 
does
-not depend on its position in the grammar file relative to any
address@hidden @address@hidden@}}.
-Specifically, @code{%code @address@hidden@}} always inserts your @var{code} 
into
-the parser code file after the usual contents of the parser header file.
+For the current C/C++ skeletons, the default location is the parser source code
+file after the usual contents of the parser header file.
+Thus, @code{%code} replaces the traditional Yacc prologue,
address@hidden@address@hidden@}}, for most purposes.
+For a detailed discussion, see @ref{Prologue Alternatives}.
+
address@hidden For Java, the default location is inside the parser class.
 
-(Like all the Yacc prologue alternative directives, this directive is
-experimental.
+(Like all the Yacc prologue alternatives, this directive is experimental.
 More user feedback will help to determine whether it should become a permanent
 feature.)
-
address@hidden Alternatives}.
 @end deffn
 
address@hidden {Directive} %code-top @address@hidden@}
-Occasionally it is desirable to insert code near the top of the
address@hidden Occasionally for C/C++ it is desirable to insert code near the 
top of the
-parser code file.
address@hidden {Directive} %code "@var{qualifier}" @address@hidden@}
+This is the qualified form of the @code{%code} directive.
+If you need to specify location-sensitive verbatim @var{code} that does not
+belong at the default location selected by the unqualified @code{%code} form,
+use this form instead.
+
address@hidden identifies the purpose of @var{code} and thus the location(s)
+where Bison should generate it.
+Not all values of @var{qualifier} are available for all target languages:
+
address@hidden @bullet
address@hidden %code "requires"
address@hidden "requires"
+
address@hidden @bullet
address@hidden Language(s): C, C++
+
address@hidden Purpose: This is the best place to write dependency code 
required for
address@hidden and @code{YYLTYPE}.
+In other words, it's the best place to define types referenced in @code{%union}
+directives, and it's the best place to override Bison's default @code{YYSTYPE}
+and @code{YYLTYPE} definitions.
+
address@hidden Location(s): The parser header file and the parser source code 
file
+before the Bison-generated @code{YYSTYPE} and @code{YYLTYPE} definitions.
address@hidden itemize
+
address@hidden "provides"
address@hidden %code "provides"
+
address@hidden @bullet
address@hidden Language(s): C, C++
+
address@hidden Purpose: This is the best place to write additional definitions 
and
+declarations that should be provided to other modules.
+
address@hidden Location(s): The parser header file and the parser source code 
file after
+the Bison-generated @code{YYSTYPE}, @code{YYLTYPE}, and token definitions.
address@hidden itemize
+
address@hidden "top"
address@hidden %code "top"
+
address@hidden @bullet
address@hidden Language(s): C, C++
+
address@hidden Purpose: The unqualified @code{%code} or @code{%code "requires"} 
should
+usually be more appropriate than @code{%code "top"}.
+However, occasionally it is necessary to insert code much nearer the top of the
+parser source code file.
 For example:
 
 @smallexample
-%code-top @{
+%code "top" @{
   #define _GNU_SOURCE
   #include <stdio.h>
 @}
 @end smallexample
 
address@hidden @noindent
address@hidden For Java, @code{%code-top @address@hidden@}} is currently unused.
address@hidden Location(s): Near the top of the parser source code file.
address@hidden itemize
address@hidden
address@hidden "imports"
address@hidden %code "imports"
 
address@hidden Prologue
address@hidden %union
-Compare with @address@hidden@address@hidden appearing before the first
address@hidden @address@hidden@}} in a C/C++ based grammar file.
address@hidden @address@hidden@}} is cleaner as its functionality does not 
depend
-on its position in the grammar file relative to any
address@hidden @address@hidden@}}.
address@hidden @bullet
address@hidden Language(s): Java
 
-(Like all the Yacc prologue alternative directives, this directive is
-experimental.
address@hidden Purpose: This is the best place to write Java import directives.
+
address@hidden Location(s): The parser Java file after any Java package 
directive and
+before any class definitions.
address@hidden itemize
address@hidden ignore
address@hidden itemize
+
+(Like all the Yacc prologue alternatives, this directive is experimental.
 More user feedback will help to determine whether it should become a permanent
 feature.)
 
address@hidden Alternatives}.
address@hidden Prologue
+For a detailed discussion of how to use @code{%code} in place of the
+traditional Yacc prologue for C/C++, see @ref{Prologue Alternatives}.
 @end deffn
 
 @deffn {Directive} %debug
@@ -8826,24 +8882,6 @@ Bison declaration to assign a precedence
 @xref{Contextual Precedence, ,Context-Dependent Precedence}.
 @end deffn
 
address@hidden {Directive} %provides @address@hidden@}
-This is the right place to write additional definitions you would like Bison to
-expose externally.
-That is, this directive inserts your @var{code} both into the parser header
address@hidden For C/C++, this directive inserts your @var{code} both into the 
parser header
-file (if generated; @pxref{Table of Symbols, ,%defines}) and into the parser
-code file after Bison's required definitions.
address@hidden For Java, it inserts your @var{code} into the parser java file 
after the parser
address@hidden class.
-
-(Like all the Yacc prologue alternative directives, this directive is
-experimental.
-More user feedback will help to determine whether it should become a permanent
-feature.)
-
address@hidden Alternatives}.
address@hidden deffn
-
 @deffn {Directive} %pure-parser
 Bison declaration to request a pure (reentrant) parser.
 @xref{Pure Decl, ,A Pure (Reentrant) Parser}.
@@ -8854,35 +8892,6 @@ Require version @var{version} or higher 
 Require a Version of Bison}.
 @end deffn
 
address@hidden {Directive} %requires @address@hidden@}
-This is the right place to write dependency code for externally exposed
-definitions required by Bison.
-Such exposed definitions are those usually appearing in the parser
address@hidden For C/C++, such exposed definitions are those usually appearing 
in the parser
-header file.
-Thus, this is the right place to define types referenced in
address@hidden @address@hidden@}} directives, and it is the right place to 
override
-Bison's default @code{YYSTYPE} and @code{YYLTYPE} definitions.
address@hidden For Java, this is the right place to write import directives.
-
address@hidden Prologue
address@hidden %union
-Compare with @address@hidden@address@hidden (@pxref{Prologue, ,The Prologue})
-appearing before the first @code{%union @address@hidden@}} in a C/C++ based
-grammar file.
-Unlike @address@hidden@address@hidden, @code{%requires @address@hidden@}} 
inserts your
address@hidden both into the parser code file and into the parser header file 
(if
-generated; @pxref{Table of Symbols, ,%defines}) since Bison's required
-definitions should depend on it in both places.
-
-(Like all the Yacc prologue alternative directives, this directive is
-experimental.
-More user feedback will help to determine whether it should become a permanent
-feature.)
-
address@hidden Alternatives}.
address@hidden deffn
-
 @deffn {Directive} %right
 Bison declaration to assign right associativity to token(s).
 @xref{Precedence Decl, ,Operator Precedence}.
Index: src/parse-gram.y
===================================================================
RCS file: /sources/bison/bison/src/parse-gram.y,v
retrieving revision 1.105
diff -p -u -r1.105 parse-gram.y
--- src/parse-gram.y    3 Jan 2007 05:14:57 -0000       1.105
+++ src/parse-gram.y    5 Jan 2007 08:06:10 -0000
@@ -133,7 +133,6 @@ static int current_prec = 0;
 
 %token
   PERCENT_CODE            "%code"
-  PERCENT_CODE_TOP        "%code-top"
   PERCENT_DEBUG           "%debug"
   PERCENT_DEFAULT_PREC    "%default-prec"
   PERCENT_DEFINE          "%define"
@@ -154,13 +153,11 @@ static int current_prec = 0;
                          "%nondeterministic-parser"
   PERCENT_OUTPUT          "%output"
   PERCENT_PARSE_PARAM     "%parse-param"
-  PERCENT_PROVIDES        "%provides"
   PERCENT_PURE_PARSER     "%pure-parser"
   PERCENT_PUSH_PARSER     "%push-parser"
   PERCENT_PUSH_PULL_PARSER
                           "%push-pull-parser"
   PERCENT_REQUIRE        "%require"
-  PERCENT_REQUIRES        "%requires"
   PERCENT_SKELETON        "%skeleton"
   PERCENT_START           "%start"
   PERCENT_TOKEN_TABLE     "%token-table"
@@ -312,10 +309,22 @@ grammar_declaration:
     {
       default_prec = false;
     }
-| "%code" braceless      { prologue_augment ($2, @2, true); }
-| "%code-top" braceless  { prologue_augment ($2, @2, false); }
-| "%provides" braceless  { muscle_code_grow ("provides", $2, @2); }
-| "%requires" braceless  { muscle_code_grow ("requires", $2, @2); }
+| "%code" braceless
+    {
+      muscle_code_grow ("percent_code", $2, @2);
+      code_scanner_last_string_free ();
+    }
+| "%code" STRING braceless
+    {
+      char const name_prefix[] = "percent_code_";
+      char *name = xmalloc (sizeof name_prefix + strlen ($2));
+      strcpy (name, name_prefix);
+      strcpy (name + sizeof name_prefix - 1, $2);
+      muscle_code_grow (uniqstr_new (name), $3, @3);
+      free (name);
+      code_scanner_last_string_free ();
+      muscle_grow ("used_percent_code_qualifiers", $2, ",");
+    }
 ;
 
 
Index: src/scan-gram.l
===================================================================
RCS file: /sources/bison/bison/src/scan-gram.l,v
retrieving revision 1.114
diff -p -u -r1.114 scan-gram.l
--- src/scan-gram.l     3 Jan 2007 05:14:57 -0000       1.114
+++ src/scan-gram.l     5 Jan 2007 08:06:11 -0000
@@ -159,7 +159,6 @@ splice       (\\[ \f\t\v]*\n)*
 {
   "%binary"                        return PERCENT_NONASSOC;
   "%code"                           return PERCENT_CODE;
-  "%code-top"                       return PERCENT_CODE_TOP;
   "%debug"                         return PERCENT_DEBUG;
   "%default"[-_]"prec"             return PERCENT_DEFAULT_PREC;
   "%define"                        return PERCENT_DEFINE;
@@ -188,12 +187,10 @@ splice     (\\[ \f\t\v]*\n)*
   "%parse-param"                   return PERCENT_PARSE_PARAM;
   "%prec"                          return PERCENT_PREC;
   "%printer"                       return PERCENT_PRINTER;
-  "%provides"                       return PERCENT_PROVIDES;
   "%pure"[-_]"parser"              return PERCENT_PURE_PARSER;
   "%push-parser"                   return PERCENT_PUSH_PARSER;
   "%push-pull-parser"              return PERCENT_PUSH_PULL_PARSER;
   "%require"                       return PERCENT_REQUIRE;
-  "%requires"                       return PERCENT_REQUIRES;
   "%right"                         return PERCENT_RIGHT;
   "%skeleton"                      return PERCENT_SKELETON;
   "%start"                         return PERCENT_START;
Index: tests/actions.at
===================================================================
RCS file: /sources/bison/bison/tests/actions.at,v
retrieving revision 1.76
diff -p -u -r1.76 actions.at
--- tests/actions.at    21 Nov 2006 07:07:35 -0000      1.76
+++ tests/actions.at    5 Jan 2007 08:06:11 -0000
@@ -178,7 +178,7 @@ m4_if([$1$2$3], $[1]$[2]$[3], [],
 # helping macros.  So don't put any directly in the Bison file.
 AT_BISON_OPTION_PUSHDEFS([$5])
 AT_DATA_GRAMMAR([[input.y]],
-[[%requires {
+[[%code "requires" {
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -197,7 +197,7 @@ m4_ifval([$6], [%union
   int ival;
 }])
 AT_LALR1_CC_IF([%define "global_tokens_and_yystype"])
-m4_ifval([$6], [[%provides {]], [[%code {]])
+m4_ifval([$6], [[%code "provides" {]], [[%code {]])
 AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])
 [static int yylex (]AT_LEX_FORMALS[);
 ]AT_LALR1_CC_IF([], [static void yyerror (const char *msg);])
Index: tests/input.at
===================================================================
RCS file: /sources/bison/bison/tests/input.at,v
retrieving revision 1.67
diff -p -u -r1.67 input.at
--- tests/input.at      1 Jan 2007 00:42:21 -0000       1.67
+++ tests/input.at      5 Jan 2007 08:06:11 -0000
@@ -701,3 +701,40 @@ AT_CHECK([bison input.y], [1], [],
 ]])
 
 AT_CLEANUP
+
+
+## ----------------------------- ##
+## Reject bad %code qualifiers.  ##
+## ----------------------------- ##
+
+AT_SETUP([Reject bad %code qualifiers])
+
+AT_DATA([input-c.y],
+[[%code "" {}
+%%
+start: ;
+]])
+AT_CHECK([[bison input-c.y 2>&1 | grep 'error: `'"' is not a recognized" > 
/dev/null]])
+
+AT_DATA([input-c-glr.y],
+[[%code "bad" {}
+%%
+start: ;
+]])
+AT_CHECK([[bison input-c-glr.y 2>&1 | grep 'error: `bad'"' is not a 
recognized" > /dev/null]])
+
+AT_DATA([input-c++.y],
+[[%code "bad" {}
+%%
+start: ;
+]])
+AT_CHECK([[bison input-c++.y 2>&1 | grep 'error: `bad'"' is not a recognized" 
> /dev/null]])
+
+AT_DATA([input-c++-glr.y],
+[[%code "bad" {}
+%%
+start: ;
+]])
+AT_CHECK([[bison input-c++-glr.y 2>&1 | grep 'error: `bad'"' is not a 
recognized" > /dev/null]])
+
+AT_CLEANUP




reply via email to

[Prev in Thread] Current Thread [Next in Thread]