mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
rename parser_class_name as api.parser.class
The previous name was historical and inconsistent. * src/muscle-tab.c (define_directive): Use the proper value passing syntax, based on the muscle kind. (muscle_percent_variable_update): Use the right value passing syntax. Migrate from parser_class_name to api.parser.class. * data/skeletons: Migrate from parser_class_name to api.parser.class. * doc/bison.texi (%define Summary): Document both parser_class_name and api.parser.class. Promote the latter over the former.
This commit is contained in:
5
NEWS
5
NEWS
@@ -22,6 +22,11 @@ GNU Bison NEWS
|
||||
The use of the %error-verbose directive is deprecated in favor of "%define
|
||||
parse.error verbose" since Bison 3.0, but no warning was issued.
|
||||
|
||||
The following variables have been renamed for consistency. Backward
|
||||
compatibility is ensured, but upgrading is recommended.
|
||||
|
||||
parser_class_name -> api.parser.class
|
||||
|
||||
** New features
|
||||
|
||||
*** Bison is now relocatable
|
||||
|
||||
@@ -44,7 +44,7 @@ public interface Lexer
|
||||
- the following (non-standard) %defines are supported:
|
||||
|
||||
%define package "<package_name>"
|
||||
%define parser_class_name "my_class_name>"
|
||||
%define api.parser.class "my_class_name>"
|
||||
%define position_type "my_position_type"
|
||||
%define location_type "my_location_type"
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ b4_percent_define_ifdef([[api.value.union.name]],
|
||||
m4_include(b4_skeletonsdir/[c.m4])
|
||||
|
||||
b4_percent_define_check_kind([api.namespace], [code], [deprecated])
|
||||
b4_percent_define_check_kind([parser_class_name], [code], [deprecated])
|
||||
b4_percent_define_check_kind([api.parser.class], [code], [deprecated])
|
||||
|
||||
|
||||
## ----- ##
|
||||
@@ -94,7 +94,7 @@ m4_define([b4_cxx_portability],
|
||||
## Default values. ##
|
||||
## ---------------- ##
|
||||
|
||||
b4_percent_define_default([[parser_class_name]], [[parser]])
|
||||
b4_percent_define_default([[api.parser.class]], [[parser]])
|
||||
|
||||
# Don't do that so that we remember whether we're using a user
|
||||
# request, or the default value.
|
||||
|
||||
@@ -178,8 +178,8 @@ b4_percent_define_default([[stype]], [[YYSemanticType]])])
|
||||
# %name-prefix
|
||||
m4_define_default([b4_prefix], [[YY]])
|
||||
|
||||
b4_percent_define_default([[parser_class_name]], [b4_prefix[]YYParser])])
|
||||
m4_define([b4_parser_class], [b4_percent_define_get([[parser_class_name]])])
|
||||
b4_percent_define_default([[api.parser.class]], [b4_prefix[]YYParser])])
|
||||
m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])])
|
||||
|
||||
#b4_percent_define_default([[location_type]], [Location])])
|
||||
m4_define([b4_location_type], b4_percent_define_ifdef([[location_type]],[b4_percent_define_get([[location_type]])],[YYLocation]))
|
||||
|
||||
@@ -50,7 +50,7 @@ m4_include(b4_skeletonsdir/[c++.m4])
|
||||
b4_bison_locations_if([m4_include(b4_skeletonsdir/[location.cc])])
|
||||
|
||||
m4_define([b4_parser_class],
|
||||
[b4_percent_define_get([[parser_class_name]])])
|
||||
[b4_percent_define_get([[api.parser.class]])])
|
||||
|
||||
# Save the parse parameters.
|
||||
m4_define([b4_parse_param_orig], m4_defn([b4_parse_param]))
|
||||
|
||||
@@ -180,7 +180,7 @@ b4_percent_define_check_kind([[extends]], [code], [deprecated])
|
||||
b4_percent_define_check_kind([[implements]], [code], [deprecated])
|
||||
b4_percent_define_check_kind([[init_throws]], [code], [deprecated])
|
||||
b4_percent_define_check_kind([[lex_throws]], [code], [deprecated])
|
||||
b4_percent_define_check_kind([[parser_class_name]], [code], [deprecated])
|
||||
b4_percent_define_check_kind([[api.parser.class]], [code], [deprecated])
|
||||
b4_percent_define_check_kind([[throws]], [code], [deprecated])
|
||||
|
||||
|
||||
@@ -195,8 +195,8 @@ b4_percent_define_default([[api.value.type]], [[Object]])
|
||||
# %name-prefix
|
||||
m4_define_default([b4_prefix], [[YY]])
|
||||
|
||||
b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])
|
||||
m4_define([b4_parser_class], [b4_percent_define_get([[parser_class_name]])])
|
||||
b4_percent_define_default([[api.parser.class]], [b4_prefix[]Parser])
|
||||
m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])])
|
||||
|
||||
b4_percent_define_default([[lex_throws]], [[java.io.IOException]])
|
||||
m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
|
||||
|
||||
@@ -138,7 +138,7 @@ m4_pushdef([b4_copyright_years],
|
||||
[2002-2015, 2018])
|
||||
|
||||
m4_define([b4_parser_class],
|
||||
[b4_percent_define_get([[parser_class_name]])])
|
||||
[b4_percent_define_get([[api.parser.class]])])
|
||||
|
||||
b4_bison_locations_if([# Backward compatibility.
|
||||
m4_define([b4_location_constructors])
|
||||
|
||||
@@ -1807,10 +1807,10 @@ token type is an identifier, that identifier is defined by Bison as a C
|
||||
macro whose definition is the appropriate number. In this example,
|
||||
therefore, @code{NUM} becomes a macro for @code{yylex} to use.
|
||||
|
||||
The semantic value of the token (if it has one) is stored into the
|
||||
global variable @code{yylval}, which is where the Bison parser will look
|
||||
for it. (The C data type of @code{yylval} is @code{YYSTYPE}, whose value
|
||||
was defined at the beginning of the grammar via @samp{%define api.value.type
|
||||
The semantic value of the token (if it has one) is stored into the global
|
||||
variable @code{yylval}, which is where the Bison parser will look for it.
|
||||
(The C data type of @code{yylval} is @code{YYSTYPE}, whose value was defined
|
||||
at the beginning of the grammar via @samp{%define api.value.type
|
||||
@{double@}}; @pxref{Rpcalc Declarations,,Declarations for @code{rpcalc}}.)
|
||||
|
||||
A token type code of zero is returned if the end-of-input is encountered.
|
||||
@@ -5987,6 +5987,29 @@ Introduced in Bison 2.7 for C, C++ and Java. Introduced under the name
|
||||
@end itemize
|
||||
@end deffn
|
||||
|
||||
@c ================================================== api.parser.class
|
||||
@deffn Directive {%define api.parser.class} @{@var{name}@}
|
||||
@itemize @bullet
|
||||
@item Language(s):
|
||||
C++, Java
|
||||
|
||||
@item Purpose:
|
||||
The name of the parser class.
|
||||
|
||||
@item Accepted Values:
|
||||
Any valid identifier.
|
||||
|
||||
@item Default Value:
|
||||
In C++, @code{parser}. In Java, @code{YYParser} or
|
||||
@code{@var{name-prefix}Parser} (@pxref{Java Bison Interface}).
|
||||
|
||||
@item History:
|
||||
Introduced in Bison 3.3 to replace @code{parser_class_name}.
|
||||
@end itemize
|
||||
@end deffn
|
||||
@c api.parser.class
|
||||
|
||||
|
||||
@c ================================================== api.prefix
|
||||
@deffn {Directive} {%define api.prefix} @{@var{prefix}@}
|
||||
|
||||
@@ -6388,8 +6411,8 @@ LR(1) family. @xref{LR Table Construction}.
|
||||
@c ================================================== namespace
|
||||
@deffn Directive %define namespace @{@var{namespace}@}
|
||||
Obsoleted by @code{api.namespace}
|
||||
@c namespace
|
||||
@end deffn
|
||||
@c namespace
|
||||
|
||||
@c ================================================== parse.assert
|
||||
@deffn Directive {%define parse.assert}
|
||||
@@ -6472,6 +6495,17 @@ compiled.
|
||||
@end deffn
|
||||
@c parse.trace
|
||||
|
||||
@c ================================================== parser_class_name
|
||||
@deffn Directive %define parser_class_name @{@var{name}@}
|
||||
Obsoleted by @code{api.parser.class}
|
||||
@end deffn
|
||||
@c parser_class_name
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@node %code Summary
|
||||
@subsection %code Summary
|
||||
@findex %code
|
||||
@@ -10950,19 +10984,19 @@ complete and accurate documentation.
|
||||
|
||||
@node C++ Parser Interface
|
||||
@subsection C++ Parser Interface
|
||||
@c - define parser_class_name
|
||||
@c - define api.parser.class
|
||||
@c - Ctor
|
||||
@c - parse, error, set_debug_level, debug_level, set_debug_stream,
|
||||
@c debug_stream.
|
||||
@c - Reporting errors
|
||||
|
||||
The output files @file{@var{file}.hh} and @file{@var{file}.cc} declare
|
||||
and define the parser class in the namespace @code{yy}. The class name
|
||||
defaults to @code{parser}, but may be changed using @samp{%define
|
||||
parser_class_name @{@var{name}@}}. The interface of this class is detailed
|
||||
below. It can be extended using the @code{%parse-param} feature: its
|
||||
semantics is slightly changed since it describes an additional member of the
|
||||
parser class, and an additional argument for its constructor.
|
||||
The output files @file{@var{file}.hh} and @file{@var{file}.cc} declare and
|
||||
define the parser class in the namespace @code{yy}. The class name defaults
|
||||
to @code{parser}, but may be changed using @samp{%define api.parser.class
|
||||
@{@var{name}@}}. The interface of this class is detailed below. It can be
|
||||
extended using the @code{%parse-param} feature: its semantics is slightly
|
||||
changed since it describes an additional member of the parser class, and an
|
||||
additional argument for its constructor.
|
||||
|
||||
@defcv {Type} {parser} {semantic_type}
|
||||
The types for semantic values. @xref{C++ Semantic Values}.
|
||||
@@ -12330,17 +12364,17 @@ properly, the position class should override the @code{equals} and
|
||||
|
||||
@node Java Parser Interface
|
||||
@subsection Java Parser Interface
|
||||
@c - define parser_class_name
|
||||
@c - define api.parser.class
|
||||
@c - Ctor
|
||||
@c - parse, error, set_debug_level, debug_level, set_debug_stream,
|
||||
@c debug_stream.
|
||||
@c - Reporting errors
|
||||
|
||||
The name of the generated parser class defaults to @code{YYParser}. The
|
||||
@code{YY} prefix may be changed using the @code{%name-prefix} directive
|
||||
or the @option{-p}/@option{--name-prefix} option. Alternatively, use
|
||||
@samp{%define parser_class_name @{@var{name}@}} to give a custom name to
|
||||
the class. The interface of this class is detailed below.
|
||||
@code{YY} prefix may be changed using the @code{%name-prefix} directive or
|
||||
the @option{-p}/@option{--name-prefix} option. Alternatively, use
|
||||
@samp{%define api.parser.class @{@var{name}@}} to give a custom name to the
|
||||
class. The interface of this class is detailed below.
|
||||
|
||||
By default, the parser class has package visibility. A declaration
|
||||
@samp{%define public} will change to public visibility. Remember that,
|
||||
@@ -12719,7 +12753,7 @@ constructor that @emph{creates} a lexer. Default is none.
|
||||
|
||||
@deffn {Directive} %name-prefix "@var{prefix}"
|
||||
The prefix of the parser class name @code{@var{prefix}Parser} if
|
||||
@samp{%define parser_class_name} is not used. Default is @code{YY}.
|
||||
@samp{%define api.parser.class} is not used. Default is @code{YY}.
|
||||
@xref{Java Bison Interface}.
|
||||
@end deffn
|
||||
|
||||
@@ -12822,10 +12856,9 @@ The package to put the parser class in. Default is none.
|
||||
@xref{Java Bison Interface}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} {%define parser_class_name} @{@var{name}@}
|
||||
@deffn {Directive} {%define api.parser.class} @{@var{name}@}
|
||||
The name of the parser class. Default is @code{YYParser} or
|
||||
@code{@var{name-prefix}Parser}.
|
||||
@xref{Java Bison Interface}.
|
||||
@code{@var{name-prefix}Parser}. @xref{Java Bison Interface}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} {%define api.position.type} @{@var{class}@}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
%language "D"
|
||||
%name-prefix "Calc"
|
||||
%define parser_class_name {Calc}
|
||||
%define api.parser.class {Calc}
|
||||
%define public
|
||||
|
||||
%define parse.error verbose
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
%language "Java"
|
||||
%name-prefix "Calc"
|
||||
%define parser_class_name {Calc}
|
||||
%define api.parser.class {Calc}
|
||||
%define public
|
||||
|
||||
%define parse.error verbose %locations
|
||||
|
||||
@@ -407,10 +407,16 @@ muscle_user_name_list_grow (char const *key, char const *user_name,
|
||||
|
||||
static
|
||||
char *
|
||||
define_directive (char const *assignment, char const *value)
|
||||
define_directive (char const *assignment,
|
||||
muscle_kind kind,
|
||||
char const *value)
|
||||
{
|
||||
char *eq = strchr (assignment, '=');
|
||||
char const *fmt = !eq && value && *value ? "%%define %s %s" : "%%define %s";
|
||||
char const *fmt
|
||||
= eq || !value || !*value ? "%%define %s"
|
||||
: kind == muscle_code ? "%%define %s {%s}"
|
||||
: kind == muscle_string ? "%%define %s \"%s\""
|
||||
: "%%define %s %s";
|
||||
char *res = xmalloc (strlen (fmt) + strlen (assignment)
|
||||
+ (value ? strlen (value) : 0));
|
||||
sprintf (res, fmt, assignment, value);
|
||||
@@ -427,28 +433,31 @@ define_directive (char const *assignment, char const *value)
|
||||
static
|
||||
char *
|
||||
muscle_percent_variable_update (char const *variable, location variable_loc,
|
||||
muscle_kind kind,
|
||||
char const **value)
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
const char *obsolete;
|
||||
const char *updated;
|
||||
muscle_kind kind;
|
||||
} conversion_type;
|
||||
const conversion_type conversion[] =
|
||||
{
|
||||
{ "api.push_pull", "api.push-pull", },
|
||||
{ "api.tokens.prefix", "api.token.prefix", },
|
||||
{ "lex_symbol", "api.token.constructor", },
|
||||
{ "location_type", "api.location.type", },
|
||||
{ "lr.default-reductions", "lr.default-reduction", },
|
||||
{ "lr.keep-unreachable-states", "lr.keep-unreachable-state", },
|
||||
{ "lr.keep_unreachable_states", "lr.keep-unreachable-state", },
|
||||
{ "namespace", "api.namespace", },
|
||||
{ "stype", "api.value.type", },
|
||||
{ "variant=", "api.value.type=variant", },
|
||||
{ "variant=true", "api.value.type=variant", },
|
||||
{ NULL, NULL, }
|
||||
};
|
||||
{
|
||||
{ "api.push_pull", "api.push-pull", muscle_keyword },
|
||||
{ "api.tokens.prefix", "api.token.prefix", muscle_code },
|
||||
{ "lex_symbol", "api.token.constructor", -1 },
|
||||
{ "location_type", "api.location.type", muscle_code },
|
||||
{ "lr.default-reductions", "lr.default-reduction", muscle_keyword },
|
||||
{ "lr.keep-unreachable-states", "lr.keep-unreachable-state", muscle_keyword },
|
||||
{ "lr.keep_unreachable_states", "lr.keep-unreachable-state", muscle_keyword },
|
||||
{ "namespace", "api.namespace", muscle_code },
|
||||
{ "parser_class_name", "api.parser.class", muscle_code },
|
||||
{ "stype", "api.value.type", -1 },
|
||||
{ "variant=", "api.value.type=variant", -1 },
|
||||
{ "variant=true", "api.value.type=variant", -1 },
|
||||
{ NULL, NULL, -1, }
|
||||
};
|
||||
|
||||
for (conversion_type const *c = conversion; c->obsolete; ++c)
|
||||
{
|
||||
@@ -458,8 +467,8 @@ muscle_percent_variable_update (char const *variable, location variable_loc,
|
||||
&& STREQ (eq + 1, *value))
|
||||
: STREQ (c->obsolete, variable))
|
||||
{
|
||||
char *old = define_directive (c->obsolete, *value);
|
||||
char *upd = define_directive (c->updated, *value);
|
||||
char *old = define_directive (c->obsolete, kind, *value);
|
||||
char *upd = define_directive (c->updated, c->kind, *value);
|
||||
deprecated_directive (&variable_loc, old, upd);
|
||||
free (old);
|
||||
free (upd);
|
||||
@@ -483,7 +492,8 @@ muscle_percent_define_insert (char const *var, location variable_loc,
|
||||
muscle_percent_define_how how)
|
||||
{
|
||||
/* Backward compatibility. */
|
||||
char *variable = muscle_percent_variable_update (var, variable_loc, &value);
|
||||
char *variable
|
||||
= muscle_percent_variable_update (var, variable_loc, kind, &value);
|
||||
uniqstr name = muscle_name (variable, NULL);
|
||||
uniqstr loc_name = muscle_name (variable, "loc");
|
||||
uniqstr syncline_name = muscle_name (variable, "syncline");
|
||||
|
||||
@@ -1834,7 +1834,7 @@ AT_SETUP([["%define" Boolean variables]])
|
||||
AT_DATA([Input.y],
|
||||
[[%language "Java"
|
||||
%define public maybe
|
||||
%define parser_class_name {Input}
|
||||
%define api.parser.class {Input}
|
||||
%%
|
||||
start: %empty;
|
||||
]])
|
||||
@@ -1991,6 +1991,7 @@ AT_DATA([[input.y]],
|
||||
%define namespace "foo"
|
||||
%define api.namespace {foo}
|
||||
%define variant
|
||||
%define parser_class_name {parser}
|
||||
%%
|
||||
start: %empty;
|
||||
]])
|
||||
@@ -2001,7 +2002,7 @@ AT_BISON_CHECK([[-fcaret input.y]], [1], [],
|
||||
input.y:2.9-34: warning: deprecated directive, use '%define lr.keep-unreachable-state maybe' [-Wdeprecated]
|
||||
%define lr.keep_unreachable_states maybe
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
input.y:3.9-17: warning: deprecated directive, use '%define api.namespace foo' [-Wdeprecated]
|
||||
input.y:3.9-17: warning: deprecated directive, use '%define api.namespace {foo}' [-Wdeprecated]
|
||||
%define namespace "foo"
|
||||
^^^^^^^^^
|
||||
input.y:4.9-21: error: %define variable 'api.namespace' redefined
|
||||
@@ -2013,6 +2014,9 @@ input.y:3.9-17: previous definition
|
||||
input.y:5.9-15: warning: deprecated directive, use '%define api.value.type variant' [-Wdeprecated]
|
||||
%define variant
|
||||
^^^^^^^
|
||||
input.y:6.9-25: warning: deprecated directive, use '%define api.parser.class {parser}' [-Wdeprecated]
|
||||
%define parser_class_name {parser}
|
||||
^^^^^^^^^^^^^^^^^
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -37,7 +37,7 @@ AT_DATA([Calc.y],
|
||||
[[/* Infix notation calculator--calc */
|
||||
%language "Java"
|
||||
%name-prefix "Calc"
|
||||
%define parser_class_name {Calc}
|
||||
%define api.parser.class {Calc}
|
||||
%define public
|
||||
|
||||
]$4[
|
||||
@@ -463,7 +463,7 @@ AT_CHECK_JAVA_GREP([[class PrefixParser]])
|
||||
AT_CHECK_JAVA_MINIMAL([[%define api.token.prefix {TOK_}]])
|
||||
AT_CHECK_JAVA_GREP([[.*TOK_END.*]])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL([[%define parser_class_name {ParserClassName}]])
|
||||
AT_CHECK_JAVA_MINIMAL([[%define api.parser.class {ParserClassName}]])
|
||||
AT_CHECK_JAVA_GREP([[class ParserClassName]])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL([[%define package {user_java_package}]])
|
||||
|
||||
@@ -44,7 +44,7 @@ AT_BANNER([[Java Push Parsing Tests]])
|
||||
# This is missing main(), so two versions
|
||||
# are instantiated with different main() procedures.
|
||||
m4_define([AT_TRIVIAL_GRAMMAR],[
|
||||
%define parser_class_name {YYParser}
|
||||
%define api.parser.class {YYParser}
|
||||
%define parse.error verbose
|
||||
|
||||
%code imports {
|
||||
@@ -346,7 +346,7 @@ AT_DATA([input],[[1 + 2 * 3 = 7
|
||||
AT_DATA([Calc.y],[[/* Infix notation calculator--calc */
|
||||
%language "Java"
|
||||
%name-prefix "Calc"
|
||||
%define parser_class_name {Calc}
|
||||
%define api.parser.class {Calc}
|
||||
|
||||
%code {
|
||||
static class UserLexer implements Calc.Lexer
|
||||
@@ -620,7 +620,7 @@ AT_BISON_OPTION_PUSHDEFS
|
||||
AT_DATA([Calc.y],[[/* Infix notation calculator--calc. */
|
||||
%language "Java"
|
||||
%name-prefix "Calc"
|
||||
%define parser_class_name {Calc}
|
||||
%define api.parser.class {Calc}
|
||||
%lex-param { Reader rdr }
|
||||
%locations
|
||||
|
||||
|
||||
Reference in New Issue
Block a user