Index: ChangeLog
from  Akim Demaille  <akim@lrde.epita.fr>

	Apply --prefix to C++ skeletons too: they change the namespace.
	The test suite already exercize these cases.
	* data/c++.m4 (b4_namespace): New.
	* data/lalr1.cc, data/glr.cc, data/location.cc: Use it instead of `yy'.
	* data/lalr1.cc (yytnameerr_): Move its definition into the namespace.
	* data/yacc.c, data/glr.c: Remove a useless `[]'.
	* doc/bison.texinfo: Document it.
	(Option Cross Key): Use @multitable in all formats.  It looks
	nicer, even in TeX outputs.
	(Rules): Use the same code whatever the output type is.
	* tests/local.at (_AT_BISON_OPTION_PUSHDEFS)
	(_AT_BISON_OPTION_POPDEFS): Support AT_NAME_PREFIX.
	* tests/calc.at: Use it, instead of hard coding `yy'.

Index: NEWS
===================================================================
RCS file: /cvsroot/bison/bison/NEWS,v
retrieving revision 1.144
diff -u -r1.144 NEWS
--- NEWS 18 Feb 2006 07:15:32 -0000 1.144
+++ NEWS 12 Mar 2006 14:43:06 -0000
@@ -3,7 +3,9 @@
 
 Changes in version 2.1b:
 
-* No user-visible changes.
+* %name-prefix changes the namespace name in C++ outputs.
+
+* The C++ parsers export their token_type.
 
 Changes in version 2.1a, 2006-02-13:
 
Index: data/c++.m4
===================================================================
RCS file: /cvsroot/bison/bison/data/c++.m4,v
retrieving revision 1.5
diff -u -r1.5 c++.m4
--- data/c++.m4 10 Mar 2006 13:30:19 -0000 1.5
+++ data/c++.m4 12 Mar 2006 14:43:06 -0000
@@ -29,7 +29,7 @@
 m4_define_default([b4_parser_class_name], [parser])
 m4_define_default([b4_location_type], [location])
 m4_define_default([b4_filename_type], [std::string])
-
+m4_define_default([b4_namespace], m4_defn([b4_prefix]))
 
 
 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
Index: data/glr.c
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.c,v
retrieving revision 1.169
diff -u -r1.169 glr.c
--- data/glr.c 7 Mar 2006 06:42:23 -0000 1.169
+++ data/glr.c 12 Mar 2006 14:43:07 -0000
@@ -150,7 +150,7 @@
 
 ]b4_identification
 
-m4_if(b4_prefix[], [yy], [],
+m4_if(b4_prefix, [yy], [],
 [/* Substitute the variable and function names.  */
 #define yyparse b4_prefix[]parse
 #define yylex   b4_prefix[]lex
Index: data/glr.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.cc,v
retrieving revision 1.13
diff -u -r1.13 glr.cc
--- data/glr.cc 10 Mar 2006 13:30:19 -0000 1.13
+++ data/glr.cc 12 Mar 2006 14:43:07 -0000
@@ -73,9 +73,9 @@
     [static void],
     [[FILE *],               []],
     [[int yytype],           [yytype]],
-    [[const yy::b4_parser_class_name::semantic_type *yyvaluep],
+    [[const b4_namespace::b4_parser_class_name::semantic_type *yyvaluep],
 			     [yyvaluep]],
-    [[const yy::b4_parser_class_name::location_type *yylocationp],
+    [[const b4_namespace::b4_parser_class_name::location_type *yylocationp],
 			     [yylocationp]],
     b4_parse_param)[
 {
@@ -92,7 +92,7 @@
 
 b4_c_ansi_function_decl([yyerror],
     [static void],
-    [[yy::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
+    [[b4_namespace::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
     b4_parse_param,
     [[const char* msg], [msg]])])
 
@@ -107,7 +107,7 @@
 
 ]b4_c_ansi_function_def([yyerror],
     [static void],
-    [[yy::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
+    [[b4_namespace::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
     b4_parse_param,
     [[const char* msg], [msg]])[
 {
@@ -116,7 +116,7 @@
 }
 
 
-namespace yy
+namespace ]b4_namespace[
 {
 ]dnl In this section, the parse param are the original parse_params.
 m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
@@ -195,7 +195,7 @@
 
 #endif /* ! YYDEBUG */
 ]m4_popdef([b4_parse_param])dnl
-[} // namespace yy
+[} // namespace ]b4_namespace[
 
 ]])
 
@@ -203,10 +203,10 @@
 # Let glr.c believe that the user arguments include the parser itself.
 m4_ifset([b4_parse_param],
 [m4_pushdef([b4_parse_param],
-	    m4_dquote([[[yy::b4_parser_class_name& yyparser], [[yyparser]]],]
+	    m4_dquote([[[b4_namespace::b4_parser_class_name& yyparser], [[yyparser]]],]
 m4_defn([b4_parse_param])))],
 [m4_pushdef([b4_parse_param],
-	    [[[[yy::b4_parser_class_name& yyparser], [[yyparser]]]]])
+	    [[[[b4_namespace::b4_parser_class_name& yyparser], [[yyparser]]]]])
 ])
 m4_include(b4_pkgdatadir/[glr.c])
 m4_popdef([b4_parse_param])
@@ -227,7 +227,7 @@
 /* Using locations.  */
 #define YYLSP_NEEDED ]b4_locations_flag[
 
-namespace yy
+namespace ]b4_namespace[
 {
   class position;
   class location;
@@ -287,7 +287,7 @@
     while (/*CONSTCOND*/ 0)
 #endif
 
-namespace yy
+namespace ]b4_namespace[
 {
   /// A Bison parser.
   class ]b4_parser_class_name[
@@ -384,10 +384,10 @@
 [b4_token_defines(b4_tokens)])
 [
 #ifndef YYSTYPE
-# define YYSTYPE yy::]b4_parser_class_name[::semantic_type
+# define YYSTYPE ]b4_namespace[::]b4_parser_class_name[::semantic_type
 #endif
 #ifndef YYLTYPE
-# define YYLTYPE yy::]b4_parser_class_name[::location_type
+# define YYLTYPE ]b4_namespace[::]b4_parser_class_name[::location_type
 #endif
 
 }
Index: data/lalr1.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/lalr1.cc,v
retrieving revision 1.124
diff -u -r1.124 lalr1.cc
--- data/lalr1.cc 10 Mar 2006 13:30:19 -0000 1.124
+++ data/lalr1.cc 12 Mar 2006 14:43:07 -0000
@@ -42,7 +42,7 @@
 #include <iostream>
 #include "stack.hh"
 
-namespace yy
+namespace ]b4_namespace[
 {
   class position;
   class location;
@@ -94,7 +94,7 @@
 } while (false)
 #endif
 
-namespace yy
+namespace ]b4_namespace[
 {
 
   /// A Bison parser.
@@ -291,7 +291,7 @@
 
 #ifndef YYSTYPE
  /* Redirection for backward compatibility.  */
-# define YYSTYPE yy::b4_parser_class_name::semantic_type
+# define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
 #endif
 ])[
 #endif /* ! defined PARSER_HEADER_H */]
@@ -299,7 +299,7 @@
 @output @output_parser_name@
 b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
 	     [2002, 2003, 2004, 2005, 2006])
-m4_if(b4_prefix[], [yy], [],
+m4_if(b4_prefix, [yy], [],
 [
 // Take the name prefix into account.
 #define yylex   b4_prefix[]lex])
@@ -370,49 +370,49 @@
 #define YYABORT		goto yyabortlab
 #define YYERROR		goto yyerrorlab
 
-#if YYERROR_VERBOSE
-
-/* Return YYSTR after stripping away unnecessary quotes and
-   backslashes, so that it's suitable for yyerror.  The heuristic is
-   that double-quoting is unnecessary unless the string contains an
-   apostrophe, a comma, or backslash (other than backslash-backslash).
-   YYSTR is taken from yytname.  */
-std::string
-yy::]b4_parser_class_name[::yytnamerr_ (const char *yystr)
+namespace ]b4_namespace[
 {
-  if (*yystr == '"')
-    {
-      std::string yyr = "";
-      char const *yyp = yystr;
-
-      for (;;)
-	switch (*++yyp)
-	  {
-	  case '\'':
-	  case ',':
-	    goto do_not_strip_quotes;
-
-	  case '\\':
-	    if (*++yyp != '\\')
-	      goto do_not_strip_quotes;
-	    /* Fall through.  */
-	  default:
-	    yyr += *yyp;
-	    break;
-
-	  case '"':
-	    return yyr;
-	  }
-    do_not_strip_quotes: ;
-    }
+#if YYERROR_VERBOSE
 
-  return yystr;
-}
+  /* Return YYSTR after stripping away unnecessary quotes and
+     backslashes, so that it's suitable for yyerror.  The heuristic is
+     that double-quoting is unnecessary unless the string contains an
+     apostrophe, a comma, or backslash (other than backslash-backslash).
+     YYSTR is taken from yytname.  */
+  std::string
+  ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
+  {
+    if (*yystr == '"')
+      {
+        std::string yyr = "";
+        char const *yyp = yystr;
+  
+        for (;;)
+          switch (*++yyp)
+            {
+            case '\'':
+            case ',':
+              goto do_not_strip_quotes;
+  
+            case '\\':
+              if (*++yyp != '\\')
+                goto do_not_strip_quotes;
+              /* Fall through.  */
+            default:
+              yyr += *yyp;
+              break;
+  
+            case '"':
+              return yyr;
+            }
+      do_not_strip_quotes: ;
+      }
+  
+    return yystr;
+  }
 
 #endif
 
-namespace yy
-{
   /// Build a parser object.
   ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)
     : yydebug_ (false),
@@ -1047,7 +1047,7 @@
   const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
   const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
 
-} // namespace yy
+} // namespace ]b4_namespace[
 
 ]b4_epilogue
 dnl
@@ -1060,7 +1060,7 @@
 
 #include <deque>
 
-namespace yy
+namespace ]b4_namespace[
 {
   template <class T, class S = std::deque<T> >
   class stack
Index: data/location.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/location.cc,v
retrieving revision 1.7
diff -u -r1.7 location.cc
--- data/location.cc 3 Jan 2006 19:12:55 -0000 1.7
+++ data/location.cc 12 Mar 2006 14:43:07 -0000
@@ -28,7 +28,7 @@
 
 /**
  ** \file position.hh
- ** Define the yy::position class.
+ ** Define the ]b4_namespace[::position class.
  */
 
 #ifndef BISON_POSITION_HH
@@ -37,7 +37,7 @@
 # include <iostream>
 # include <string>
 
-namespace yy
+namespace ]b4_namespace[
 {
   /// Abstract a position.
   class position
@@ -140,7 +140,7 @@
 
 /**
  ** \file location.hh
- ** Define the yy::location class.
+ ** Define the ]b4_namespace[::location class.
  */
 
 #ifndef BISON_LOCATION_HH
@@ -150,7 +150,7 @@
 # include <string>
 # include "position.hh"
 
-namespace yy
+namespace ]b4_namespace[
 {
 
   /// Abstract a location.
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.134
diff -u -r1.134 yacc.c
--- data/yacc.c 17 Feb 2006 00:08:17 -0000 1.134
+++ data/yacc.c 12 Mar 2006 14:43:08 -0000
@@ -154,7 +154,7 @@
    USER NAME SPACE" below.  */
 
 ]b4_identification
-m4_if(b4_prefix[], [yy], [],
+m4_if(b4_prefix, [yy], [],
 [/* Substitute the variable and function names.  */
 #define yyparse b4_prefix[]parse
 #define yylex   b4_prefix[]lex
Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.181
diff -u -r1.181 bison.texinfo
--- doc/bison.texinfo 10 Mar 2006 13:45:03 -0000 1.181
+++ doc/bison.texinfo 12 Mar 2006 14:43:11 -0000
@@ -515,8 +515,8 @@
 square (int x)  /* @r{identifier, open-paren, keyword `int',}
                    @r{identifier, close-paren} */
 @{               /* @r{open-brace} */
-  return x * x; /* @r{keyword `return', identifier, asterisk,
-                   identifier, semicolon} */
+  return x * x; /* @r{keyword `return', identifier, asterisk,}
+                   @r{identifier, semicolon} */
 @}               /* @r{close-brace} */
 @end example
 @end ifinfo
@@ -1368,11 +1368,8 @@
 desk-top calculator.
 
 These examples are simple, but Bison grammars for real programming
-languages are written the same way.
-@ifinfo
-You can copy these examples out of the Info file and into a source file
-to try them.
-@end ifinfo
+languages are written the same way.  You can copy these examples into a
+source file to try them.
 
 @menu
 * RPN Calc::          Reverse polish notation calculator;
@@ -2936,15 +2933,6 @@
 Multiple rules for the same @var{result} can be written separately or can
 be joined with the vertical-bar character @samp{|} as follows:
 
-@ifinfo
-@example
-@var{result}:   @var{rule1-components}@dots{}
-        | @var{rule2-components}@dots{}
-        @dots{}
-        ;
-@end example
-@end ifinfo
-@iftex
 @example
 @group
 @var{result}:    @var{rule1-components}@dots{}
@@ -2953,7 +2941,6 @@
         ;
 @end group
 @end example
-@end iftex
 
 @noindent
 They are still considered distinct rules even when joined in this way.
@@ -4244,12 +4231,14 @@
 @deffn {Directive} %name-prefix="@var{prefix}"
 Rename the external symbols used in the parser so that they start with
 @var{prefix} instead of @samp{yy}.  The precise list of symbols renamed
+in C parsers
 is @code{yyparse}, @code{yylex}, @code{yyerror}, @code{yynerrs},
 @code{yylval}, @code{yylloc}, @code{yychar}, @code{yydebug}, and
 possible @code{yylloc}.  For example, if you use
 @samp{%name-prefix="c_"}, the names become @code{c_parse}, @code{c_lex},
-and so on.  @xref{Multiple Parsers, ,Multiple Parsers in the Same
-Program}.
+and so on.  In C++ parsers, it is only the surrounding namespace which is
+named @var{prefix} instead of @samp{yy}.
+@xref{Multiple Parsers, ,Multiple Parsers in the Same Program}.
 @end deffn
 
 @ifset defaultprec
@@ -6920,7 +6909,7 @@
 
 @item -b @var{file-prefix}
 @itemx --file-prefix=@var{prefix}
-Pretend that @code{%verbose} was specified, i.e, specify prefix to use
+Pretend that @code{%file-prefix} was specified, i.e, specify prefix to use
 for all Bison output file names.  @xref{Decl Summary}.
 
 @item -r @var{things}
@@ -6970,48 +6959,27 @@
 @node Option Cross Key
 @section Option Cross Key
 
+@c FIXME: How about putting the directives too?
 Here is a list of options, alphabetized by long option, to help you find
 the corresponding short option.
 
-@tex
-\def\leaderfill{\leaders\hbox to 1em{\hss.\hss}\hfill}
-
-{\tt
-\line{ --debug \leaderfill -t}
-\line{ --defines \leaderfill -d}
-\line{ --file-prefix \leaderfill -b}
-\line{ --graph \leaderfill -g}
-\line{ --help \leaderfill -h}
-\line{ --name-prefix \leaderfill -p}
-\line{ --no-lines \leaderfill -l}
-\line{ --no-parser \leaderfill -n}
-\line{ --output \leaderfill -o}
-\line{ --print-localedir}
-\line{ --token-table \leaderfill -k}
-\line{ --verbose \leaderfill -v}
-\line{ --version \leaderfill -V}
-\line{ --yacc \leaderfill -y}
-}
-@end tex
-
-@ifinfo
-@example
---debug                               -t
---defines=@var{defines-file}          -d
---file-prefix=@var{prefix}                  -b @var{file-prefix}
---graph=@var{graph-file}              -d
---help                                -h
---name-prefix=@var{prefix}                  -p @var{name-prefix}
---no-lines                            -l
---no-parser                           -n
---output=@var{outfile}                      -o @var{outfile}
---print-localedir
---token-table                         -k
---verbose                             -v
---version                             -V
---yacc                                -y
-@end example
-@end ifinfo
+@multitable {@option{--defines=@var{defines-file}}} {@option{-b @var{file-prefix}XXX}}
+@headitem Long Option @tab Short Option
+@item @option{--debug}                      @tab @option{-t}
+@item @option{--defines=@var{defines-file}} @tab @option{-d}
+@item @option{--file-prefix=@var{prefix}}   @tab @option{-b @var{file-prefix}}
+@item @option{--graph=@var{graph-file}}     @tab @option{-d}
+@item @option{--help}                       @tab @option{-h}
+@item @option{--name-prefix=@var{prefix}}   @tab @option{-p @var{name-prefix}}
+@item @option{--no-lines}                   @tab @option{-l}
+@item @option{--no-parser}                  @tab @option{-n}
+@item @option{--output=@var{outfile}}       @tab @option{-o @var{outfile}}
+@item @option{--print-localedir}            @tab
+@item @option{--token-table}                @tab @option{-k}
+@item @option{--verbose}                    @tab @option{-v}
+@item @option{--version}                    @tab @option{-V}
+@item @option{--yacc}                       @tab @option{-y}
+@end multitable
 
 @node Yacc Library
 @section Yacc Library
@@ -7066,11 +7034,14 @@
 @c - Always pure
 @c - initial action
 
-The C++ parser @acronym{LALR}(1) skeleton is named @file{lalr1.cc}.  To select
-it, you may either pass the option @option{--skeleton=lalr1.cc} to
-Bison, or include the directive @samp{%skeleton "lalr1.cc"} in the
+The C++ parser @acronym{LALR}(1) skeleton is named @file{lalr1.cc}.  To
+select it, you may either pass the option @option{--skeleton=lalr1.cc}
+to Bison, or include the directive @samp{%skeleton "lalr1.cc"} in the
 grammar preamble.  When run, @command{bison} will create several
-files:
+entities in the @samp{yy} namespace.  Use the @samp{%name-prefix}
+directive to change the namespace name, see @ref{Decl Summary}.  The
+various classes are generated in the following files:
+
 @table @file
 @item position.hh
 @itemx location.hh
Index: tests/calc.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/calc.at,v
retrieving revision 1.87
diff -u -r1.87 calc.at
--- tests/calc.at 19 Jan 2006 12:47:17 -0000 1.87
+++ tests/calc.at 12 Mar 2006 14:43:11 -0000
@@ -73,7 +73,7 @@
 static int power (int base, int exponent);
 ]AT_SKEL_CC_IF(
 [#ifndef YYLTYPE
-# define YYLTYPE yy::location
+[#] define YYLTYPE AT_NAME_PREFIX::location
 #endif
 #define first_line   begin.line
 #define first_column begin.column
@@ -152,7 +152,7 @@
 ]AT_SKEL_CC_IF(
 [/* A C++ error reporting function.  */
 void
-yy::parser::error (const location& l, const std::string& m)
+AT_NAME_PREFIX::parser::error (const location& l, const std::string& m)
 {
   (void) l;
   std::cerr << AT_LOCATION_IF([l << ": " << ])m << std::endl;
@@ -161,7 +161,7 @@
 int
 yyparse (AT_PARAM_IF([semantic_value *result, int *count]))
 {
-  yy::parser parser[]AT_PARAM_IF([ (result, count)]);
+  AT_NAME_PREFIX::parser parser[]AT_PARAM_IF([ (result, count)]);
   parser.set_debug_level (!!YYDEBUG);
   return parser.parse ();
 }
Index: tests/local.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/local.at,v
retrieving revision 1.14
diff -u -r1.14 local.at
--- tests/local.at 22 Jan 2006 07:38:49 -0000 1.14
+++ tests/local.at 12 Mar 2006 14:43:11 -0000
@@ -63,7 +63,8 @@
 	   [$1], [$2])])
 m4_pushdef([AT_GLR_OR_PARAM_IF],
 [m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])])
-
+m4_pushdef([AT_NAME_PREFIX],
+[m4_bregexp([$3], [name-prefix="\([^"]*\)"], [\1])])
 # yyerror receives the location if %location & %pure & (%glr or %parse-param).
 m4_pushdef([AT_YYERROR_ARG_LOC_IF],
 [AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])],
@@ -80,7 +81,7 @@
 # are using the C++ parsers.
 m4_pushdef([AT_PURE_LEX_IF],
 [AT_PURE_IF([$1],
-	    [AT_LALR1_CC_IF([$1], [$2])])])
+	    [AT_SKEL_CC_IF([$1], [$2])])])
 
 AT_PURE_LEX_IF(
 [m4_pushdef([AT_LOC], [(*llocp)])
@@ -120,6 +121,7 @@
 m4_popdef([AT_PURE_LEX_IF])
 m4_popdef([AT_YYERROR_SEES_LOC_IF])
 m4_popdef([AT_YYERROR_ARG_LOC_IF])
+m4_popdef([AT_NAME_PREFIX])
 m4_popdef([AT_GLR_OR_PARAM_IF])
 m4_popdef([AT_PURE_AND_LOC_IF])
 m4_popdef([AT_LOCATION_IF])
