diff --git a/NEWS b/NEWS index b37517ca..c2a64bdf 100644 --- a/NEWS +++ b/NEWS @@ -19,8 +19,16 @@ GNU Bison NEWS ** Deprecated features - 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 %error-verbose directive is deprecated in favor of '%define + parse.error verbose' since Bison 3.0, but no warning was issued. + + The '%name-prefix "xx"' directive is deprecated in favor of '%define + api.prefix {xx}' since Bison 3.0, but no warning was issued. These + directives are slightly different, you might need to adjust your code. + %name-prefix renames only symbols with external linkage, while api.prefix + also renames types and macros, including @code{YYDEBUG}, + @code{YYTOKENTYPE}, @code{yytokentype}, @code{YYSTYPE}, @code{YYLTYPE}, + etc. The following variables have been renamed for consistency. Backward compatibility is ensured, but upgrading is recommended. diff --git a/doc/bison.texi b/doc/bison.texi index 2a65a7ca..859e78bf 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -5692,6 +5692,10 @@ it, using @samp{%locations} allows for more accurate syntax error messages. @end deffn @deffn {Directive} %name-prefix "@var{prefix}" +Obsoleted by @samp{%define api.prefix @{@var{prefix}@}}. @xref{Multiple +Parsers, ,Multiple Parsers in the Same Program}. For C++ parsers, see the +@samp{%define api.namespace} documentation in this section. + 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}, @@ -5700,9 +5704,11 @@ parsers is @code{yyparse}, @code{yylex}, @code{yyerror}, @code{yynerrs}, @code{yypull_parse}, @code{yypstate}, @code{yypstate_new} and @code{yypstate_delete} will also be renamed. For example, if you use @samp{%name-prefix "c_"}, the names become @code{c_parse}, @code{c_lex}, and -so on. For C++ parsers, see the @samp{%define api.namespace} documentation -in this section. @xref{Multiple Parsers, ,Multiple Parsers in the Same -Program}. +so on. + +Contrary to defining @code{api.prefix}, some symbols are @emph{not} renamed +by @code{%name-prefix}, for instance @code{YYDEBUG}, @code{YYTOKENTYPE}, +@code{yytokentype}, @code{YYSTYPE}, @code{YYLTYPE}. @end deffn @ifset defaultprec @@ -5880,21 +5886,8 @@ Any absolute or relative C++ namespace reference without a trailing @code{"::"}. For example, @code{"foo"} or @code{"::foo::bar"}. @item Default Value: -The value specified by @code{%name-prefix}, which defaults to @code{yy}. -This usage of @code{%name-prefix} is for backward compatibility and can be -confusing since @code{%name-prefix} also specifies the textual prefix for -the lexical analyzer function. Thus, if you specify @code{%name-prefix}, it -is best to also specify @samp{%define api.namespace} so that -@code{%name-prefix} @emph{only} affects the lexical analyzer function. For -example, if you specify: - -@example -%define api.namespace @{foo@} -%name-prefix "bar::" -@end example - -The parser namespace is @code{foo} and @code{yylex} is referenced as -@code{bar::lex}. +@code{yy}, unless you used the obsolete @samp{%name-prefix "@var{prefix}"} +directive. @end itemize @end deffn @c api.namespace @@ -5996,7 +5989,7 @@ Any valid identifier. @item Default Value: In C++, @code{parser}. In Java, @code{YYParser} or -@code{@var{name-prefix}Parser} (@pxref{Java Bison Interface}). +@code{@var{api.prefix}Parser} (@pxref{Java Bison Interface}). @item History: Introduced in Bison 3.3 to replace @code{parser_class_name}. @@ -6709,7 +6702,7 @@ extern int cdebug; Prior to Bison 2.6, a feature similar to @code{api.prefix} was provided by the obsolete directive @code{%name-prefix} (@pxref{Table of Symbols, ,Bison -Symbols}) and the option @code{--name-prefix} (@pxref{Bison Options}). +Symbols}) and the option @option{--name-prefix} (@pxref{Bison Options}). @node Interface @chapter Parser C-Language Interface @@ -12240,7 +12233,7 @@ single Java source file named @file{@var{basename}.java} containing the parser implementation. Using a grammar file without a @file{.y} suffix is currently broken. The basename of the parser implementation file can be changed by the @code{%file-prefix} directive or the -@option{-p}/@option{--name-prefix} option. The entire parser implementation +@option{-b}/@option{--file-prefix} option. The entire parser implementation file name can be changed by the @code{%output} directive or the @option{-o}/@option{--output} option. The parser implementation file contains a single class for the parser. @@ -12373,10 +12366,9 @@ properly, the position class should override the @code{equals} and @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 api.parser.class @{@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 @samp{%define api.prefix}. +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, @@ -12753,12 +12745,6 @@ constructor that @emph{creates} a lexer. Default is none. @xref{Java Scanner Interface}. @end deffn -@deffn {Directive} %name-prefix "@var{prefix}" -The prefix of the parser class name @code{@var{prefix}Parser} if -@samp{%define api.parser.class} is not used. Default is @code{YY}. -@xref{Java Bison Interface}. -@end deffn - @deffn {Directive} %parse-param @{@var{type} @var{name}@} A parameter for the parser class added as parameters to constructor(s) and as fields initialized by the constructor(s). Default is none. @@ -12807,6 +12793,12 @@ Not supported. Use @code{%code imports} instead. @xref{Java Differences}. @end deffn +@deffn {Directive} {%define api.prefix} @{@var{prefix}@} +The prefix of the parser class name @code{@var{prefix}Parser} if +@samp{%define api.parser.class} is not used. Default is @code{YY}. +@xref{Java Bison Interface}. +@end deffn + @deffn {Directive} {%define abstract} Whether the parser class is declared @code{abstract}. Default is false. @xref{Java Bison Interface}. @@ -12860,7 +12852,7 @@ The package to put the parser class in. Default is none. @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{api.prefix}Parser}. @xref{Java Bison Interface}. @end deffn @deffn {Directive} {%define api.position.type} @{@var{class}@} diff --git a/src/scan-gram.l b/src/scan-gram.l index 56276f01..61b7b7ae 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -237,7 +237,6 @@ eqopt ([[:space:]]*=)? "%lex-param" RETURN_PERCENT_PARAM (lex); "%locations" RETURN_PERCENT_FLAG ("locations"); "%merge" return BISON_DIRECTIVE (MERGE); - "%name-prefix" return BISON_DIRECTIVE (NAME_PREFIX); "%no-default-prec" return BISON_DIRECTIVE (NO_DEFAULT_PREC); "%no-lines" return BISON_DIRECTIVE (NO_LINES); "%nonassoc" return PERCENT_NONASSOC; @@ -266,13 +265,19 @@ eqopt ([[:space:]]*=)? issued only since Bison 3.3. */ "%error-verbose" DEPRECATED ("%define parse.error verbose"); + /* Deprecated since Bison 2.6 (2012-07-19), but the warning is + issued only since Bison 3.3. */ + "%name"[-_]"prefix"{eqopt} { + deprecated_directive (loc, yytext, "%define api.prefix"); + return BISON_DIRECTIVE (NAME_PREFIX); + } + /* Deprecated since Bison 2.7.90, 2012. */ "%default"[-_]"prec" DEPRECATED ("%default-prec"); "%error"[-_]"verbose" DEPRECATED ("%define parse.error verbose"); "%expect"[-_]"rr" DEPRECATED ("%expect-rr"); "%file-prefix"{eqopt} DEPRECATED ("%file-prefix"); "%fixed"[-_]"output"[-_]"files" DEPRECATED ("%fixed-output-files"); - "%name"[-_]"prefix"{eqopt} DEPRECATED ("%name-prefix"); "%no"[-_]"default"[-_]"prec" DEPRECATED ("%no-default-prec"); "%no"[-_]"lines" DEPRECATED ("%no-lines"); "%output"{eqopt} DEPRECATED ("%output"); diff --git a/tests/calc.at b/tests/calc.at index f5628c66..0820d7e8 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -445,18 +445,22 @@ sed '/^Starting/d / \$[[0-9$]]* = /d /^yydestructor:/d' stderr >at-stderr mv at-stderr stderr + # 2. Create the reference error message. AT_DATA([[expout]], [$5 ]) + # 3. If locations are not used, remove them. AT_YYERROR_SEES_LOC_IF([], [[sed 's/^[-0-9.]*: //' expout >at-expout mv at-expout expout]]) + # 4. If error-verbose is not used, strip the', unexpected....' part. m4_bmatch([$1], [%define parse.error verbose], [], [[sed 's/syntax error, .*$/syntax error/' expout >at-expout mv at-expout expout]]) + # 5. Check AT_CHECK([cat stderr], 0, [expout]) ]) @@ -494,7 +498,7 @@ AT_SETUP([Calculator $1 $2]) AT_BISON_OPTION_PUSHDEFS([$1]) AT_DATA_CALC_Y([$1]) -AT_FULL_COMPILE([calc], AT_DEFINES_IF([[lex], [main]]), [], [$2]) +AT_FULL_COMPILE([calc], AT_DEFINES_IF([[lex], [main]], [[], []]), [$2], [-Wno-deprecated]) AT_CHECK_SPACES([calc.AT_LANG_EXT AT_DEFINES_IF([calc.AT_LANG_HDR])]) # Test the priorities. diff --git a/tests/headers.at b/tests/headers.at index 31d45a8c..51365323 100644 --- a/tests/headers.at +++ b/tests/headers.at @@ -84,7 +84,9 @@ AT_DATA_GRAMMAR([input.y], exp: %empty; ]]) -AT_BISON_CHECK([--defines -o input.c input.y]) +AT_BISON_CHECK([--defines -o input.c input.y], [], [], +[[input.y:11.1-12: warning: deprecated directive: '%name-prefix', use '%define api.prefix' [-Wdeprecated] +]]) # YYLTYPE should be defined, and MY_LLOC declared. AT_DATA([caller.c], diff --git a/tests/input.at b/tests/input.at index 8ffb82c7..5f2dd58e 100644 --- a/tests/input.at +++ b/tests/input.at @@ -2310,7 +2310,7 @@ m4_pushdef([AT_TEST], %% exp: %empty; ]]) -AT_BISON_CHECK([[$2 input.y]], [[1]], [[]], +AT_BISON_CHECK([[$2 -Wno-deprecated input.y]], [[1]], [[]], [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together ]]) ]) @@ -2501,7 +2501,9 @@ AT_DATA_GRAMMAR([[input.y]], %token_table %error-verbose %glr-parser -%% exp : '0' +%name-prefix "bar" +%% +exp : '0' ]]) AT_BISON_CHECK([[input.y]], [[1]], [[]], @@ -2512,7 +2514,7 @@ input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-pre input.y:14.1-15.2: warning: deprecated directive: '%file-prefix\n =', use '%file-prefix' [-Wdeprecated] input.y:17.1-19: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated] input.y:18.1-19: warning: deprecated directive: '%fixed_output-files', use '%fixed-output-files' [-Wdeprecated] -input.y:20.1-13: warning: deprecated directive: '%name-prefix=', use '%name-prefix' [-Wdeprecated] +input.y:20.1-13: warning: deprecated directive: '%name-prefix=', use '%define api.prefix' [-Wdeprecated] input.y:21.1-16: warning: deprecated directive: '%no-default_prec', use '%no-default-prec' [-Wdeprecated] input.y:22.1-16: warning: deprecated directive: '%no_default-prec', use '%no-default-prec' [-Wdeprecated] input.y:23.1-9: warning: deprecated directive: '%no_lines', use '%no-lines' [-Wdeprecated] @@ -2522,6 +2524,7 @@ input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-tabl input.y:27.1-14: warning: deprecated directive: '%error-verbose', use '%define parse.error verbose' [-Wdeprecated] input.y:27-6: error: %define variable 'parse.error' redefined input.y:11-6: previous definition +input.y:29.1-12: warning: deprecated directive: '%name-prefix', use '%define api.prefix' [-Wdeprecated] ]]) AT_CLEANUP @@ -2581,7 +2584,6 @@ AT_DATA_GRAMMAR([[input.y]], %file-prefix "bar" %fixed-output-files -%name-prefix "foo" %no-default-prec %no-lines %output "foo" diff --git a/tests/java.at b/tests/java.at index 4ae00451..17693acb 100644 --- a/tests/java.at +++ b/tests/java.at @@ -263,7 +263,7 @@ AT_DATA_JAVA_CALC_Y([$1 $2 }]) -AT_BISON_CHECK([-o Calc.java Calc.y]) +AT_BISON_CHECK([-Wno-deprecated -o Calc.java Calc.y]) AT_JAVA_COMPILE([Calc.java]) # Test the priorities. @@ -401,7 +401,7 @@ start: END {$2}; %% class m4_default([$3], [Position]) {} ]) -AT_BISON_CHECK([[YYParser.y]]) +AT_BISON_CHECK([[-Wno-deprecated YYParser.y]]) AT_CHECK([[grep '[mb]4_' YYParser.y]], [1], [ignore]) AT_JAVA_COMPILE([[YYParser.java]]) ]) diff --git a/tests/javapush.at b/tests/javapush.at index e5573b0e..1e9509e4 100644 --- a/tests/javapush.at +++ b/tests/javapush.at @@ -345,7 +345,7 @@ AT_DATA([input],[[1 + 2 * 3 = 7 # Compose pieces to build the actual .y file. AT_DATA([Calc.y],[[/* Infix notation calculator--calc */ %language "Java" -%name-prefix "Calc" + %define api.parser.class {Calc} %code { @@ -619,7 +619,7 @@ AT_BISON_OPTION_PUSHDEFS AT_DATA([Calc.y],[[/* Infix notation calculator--calc. */ %language "Java" -%name-prefix "Calc" + %define api.parser.class {Calc} %lex-param { Reader rdr } %locations diff --git a/tests/local.at b/tests/local.at index 4ce9f825..b6f540e9 100644 --- a/tests/local.at +++ b/tests/local.at @@ -874,15 +874,16 @@ m4_define([AT_LANG_HDR(c)], [h]) m4_define([AT_LANG_HDR(c++)], [hh]) -# AT_FULL_COMPILE(OUTPUT, [OTHER1], [OTHER2], [EXTRA-COMPILER-FLAGS) -# ------------------------------------------------------------------ +# AT_FULL_COMPILE(OUTPUT, [OTHER1], [OTHER2], +# [$4: EXTRA-COMPILER-FLAGS, [$5: EXTRA-BISON-FLAGS]) +# ------------------------------------------------------------------- # Compile OUTPUT.y to OUTPUT.c, OUTPUT.cc, or OUTPUT.java, and then # compile it to OUTPUT or OUTPUT.class. If OTHER is specified, compile # OUTPUT-OTHER.c, OUTPUT-OTHER.cc, or OUTPUT-OTHER.java to OUTPUT or # OUTPUT.java along with it. Relies on AT_CXX_IF and # AT_JAVA_IF. m4_define([AT_FULL_COMPILE], -[AT_BISON_CHECK([-o $1.AT_LANG_EXT $1.y]) +[AT_BISON_CHECK([$5 -o $1.AT_LANG_EXT $1.y]) AT_LANG_COMPILE([$1], m4_join([ ], [$1.AT_LANG_EXT],