From 31b850d2d433aff80a6cc31fef79ada95dab0153 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 18 Jun 2009 10:00:36 +0200 Subject: [PATCH] variables: parse.error Implement, document, and test the replacement of %error-verbose by %define parse.error "verbose". * data/bison.m4 (b4_error_verbose_if): Reimplement to track the values of the parse.error variable. Make "simple" its default value. Check the valid values. * src/parse-gram.y: Use %define parse.error. (PERCENT_ERROR_VERBOSE): New token. Support it. * src/scan-gram.l: Support %error-verbose. * doc/bison.texinfo (Decl Summary): Replace the documentation of %define error-verbose by that of %define parse.error. * NEWS: Document it. * tests/actions.at, tests/calc.at: Use parse.error instead of %error-verbose. --- ChangeLog | 22 +++++++++++++++++ NEWS | 6 +++++ data/bison.m4 | 14 +++++++++-- doc/bison.texinfo | 63 ++++++++++++++++++++++++++++------------------- src/parse-gram.y | 8 +++++- src/scan-gram.l | 2 +- tests/actions.at | 12 ++++----- tests/calc.at | 54 ++++++++++++++++++++-------------------- 8 files changed, 119 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2293e62a..797a4932 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2009-06-29 Akim Demaille + + variables: parse.error + + Implement, document, and test the replacement of %error-verbose + by %define parse.error "verbose". + * data/bison.m4 (b4_error_verbose_if): Reimplement to track the + values of the parse.error variable. + Make "simple" its default value. + Check the valid values. + * src/parse-gram.y: Use %define parse.error. + (PERCENT_ERROR_VERBOSE): New token. + Support it. + * src/scan-gram.l: Support %error-verbose. + + * doc/bison.texinfo (Decl Summary): Replace the documentation of + %define error-verbose by that of %define parse.error. + * NEWS: Document it. + + * tests/actions.at, tests/calc.at: Use parse.error instead of + %error-verbose. + 2009-06-27 Alex Rozenman Implement support for named symbol references. diff --git a/NEWS b/NEWS index d5e40d55..aa8c7ea2 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,12 @@ Bison News The "namespace" variable is renamed "api.namespace". Backward compatibility is ensured, but upgrading is recommended. +** Variable parse.error + + The variable error controls the verbosity of error messages. The + use of the %error-verbose directive is deprecated in favor of + %define parse.error "verbose". + * Changes in version 2.5 (????-??-??): ** IELR(1) and Canonical LR(1) Support diff --git a/data/bison.m4 b/data/bison.m4 index 56610570..c8d08528 100644 --- a/data/bison.m4 +++ b/data/bison.m4 @@ -718,11 +718,9 @@ b4_percent_define_if_define_([$1], $[1], $[2])]) # b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT]) # b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT]) -# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT]) # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT]) # b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT]) # ---------------------------------------------- -b4_percent_define_if_define([error-verbose]) b4_percent_define_if_define([lex_symbol]) b4_percent_define_if_define([locations]) # Whether locations are tracked. b4_percent_define_if_define([parse.assert]) @@ -730,6 +728,18 @@ b4_percent_define_if_define([parse.trace]) b4_percent_define_if_define([variant]) +# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT]) +# ------------------------------------------------------ +# Map %define parse.error "(simple|verbose)" to b4_error_verbose_if and +# b4_error_verbose_flag. +b4_percent_define_default([[parse.error]], [[simple]]) +b4_percent_define_check_values([[[[parse.error]], + [[simple]], [[verbose]]]]) +m4_case(b4_percent_define_get([[parse.error]]), + [simple], [m4_define([b4_error_verbose_flag], [[0]])], + [verbose], [m4_define([b4_error_verbose_flag], [[1]])]) +b4_define_flag_if([error_verbose]) + # b4_percent_define_check_values(VALUES) # -------------------------------------- diff --git a/doc/bison.texinfo b/doc/bison.texinfo index f0541814..6ed33668 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -4998,23 +4998,6 @@ empty @c api.tokens.prefix -@item error-verbose -@findex %define error-verbose -@itemize -@item Languages(s): -all. -@item Purpose: -Enable the generation of more verbose error messages than a instead of -just plain @w{@code{"syntax error"}}. @xref{Error Reporting, ,The Error -Reporting Function @code{yyerror}}. -@item Accepted Values: -Boolean -@item Default Value: -@code{false} -@end itemize -@c error-verbose - - @item lr.default-reductions @cindex default reductions @findex %define lr.default-reductions @@ -5209,6 +5192,8 @@ facilitate the development of a grammar. Obsoleted by @code{api.namespace} @c namespace + +@c ================================================== parse.assert @item parse.assert @findex %define parse.assert @@ -5225,6 +5210,34 @@ destroyed properly. This option checks these constraints. @end itemize @c parse.assert + +@c ================================================== parse.error +@item parse.error +@findex %define parse.error +@itemize +@item Languages(s): +all. +@item Purpose: +Control the kind of error messages passed to the error reporting +function. @xref{Error Reporting, ,The Error Reporting Function +@code{yyerror}}. +@item Accepted Values: +@itemize +@item @code{"simple"} +Error messages passed to @code{yyerror} are simply @w{@code{"syntax +error"}}. +@item @code{"verbose"} +Error messages report the unexpected token, and possibly the expected +ones. +@end itemize + +@item Default Value: +@code{simple} +@end itemize +@c parse.error + + +@c ================================================== parse.trace @item parse.trace @findex %define parse.trace @@ -5884,7 +5897,7 @@ int yyparse (int *nastiness, int *randomness); @cindex parse error @cindex syntax error -The Bison parser detects a @dfn{syntax error} or @dfn{parse error} +The Bison parser detects a @dfn{syntax error} (or @dfn{parse error}) whenever it reads a token which cannot satisfy any syntax rule. An action in the grammar can also explicitly proclaim an error, using the macro @code{YYERROR} (@pxref{Action Features, ,Special Features for Use @@ -5896,8 +5909,8 @@ called by @code{yyparse} whenever a syntax error is found, and it receives one argument. For a syntax error, the string is normally @w{@code{"syntax error"}}. -@findex %define error-verbose -If you invoke the directive @samp{%define error-verbose} in the Bison +@findex %define parse.error +If you invoke @samp{%define parse.error "verbose"} in the Bison declarations section (@pxref{Bison Declarations, ,The Bison Declarations Section}), then Bison provides a more verbose and specific error message string instead of just plain @w{@code{"syntax error"}}. @@ -8821,7 +8834,7 @@ error messages. @comment file: calc++-parser.yy @example %define parse.trace -%define error-verbose +%define parse.error "verbose" @end example @noindent @@ -9309,7 +9322,7 @@ Run the syntactic analysis, and return @code{true} on success, @deftypemethod {YYParser} {boolean} getErrorVerbose () @deftypemethodx {YYParser} {void} setErrorVerbose (boolean @var{verbose}) Get or set the option to produce verbose error messages. These are only -available with the @samp{%define error-verbose} directive, which also turn on +available with @samp{%define parse.error "verbose"}, which also turns on verbose error messages. @end deftypemethod @@ -10238,7 +10251,7 @@ token is reset to the token that originally caused the violation. @end deffn @deffn {Directive} %error-verbose -An obsolete directive standing for @samp{%define error-verbose}. +An obsolete directive standing for @samp{%define parse.error "verbose"}. @end deffn @deffn {Directive} %file-prefix "@var{prefix}" @@ -10444,8 +10457,8 @@ An obsolete macro used in the @file{yacc.c} skeleton, that you define with @code{#define} in the prologue to request verbose, specific error message strings when @code{yyerror} is called. It doesn't matter what definition you use for @code{YYERROR_VERBOSE}, just whether you define -it. Using @samp{%define error-verbose} is preferred (@pxref{Error -Reporting, ,The Error Reporting Function @code{yyerror}}). +it. Using @samp{%define parse.error "verbose"} is preferred +(@pxref{Error Reporting, ,The Error Reporting Function @code{yyerror}}). @end deffn @deffn {Macro} YYINITDEPTH diff --git a/src/parse-gram.y b/src/parse-gram.y index 0fbb8cbd..a10c32ed 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -78,7 +78,7 @@ static int current_prec = 0; %defines %locations %pure-parser -%error-verbose +%define parse.error "verbose" %name-prefix="gram_" %expect 0 @@ -134,6 +134,7 @@ static int current_prec = 0; PERCENT_DEFAULT_PREC "%default-prec" PERCENT_DEFINE "%define" PERCENT_DEFINES "%defines" + PERCENT_ERROR_VERBOSE "%error-verbose" PERCENT_EXPECT "%expect" PERCENT_EXPECT_RR "%expect-rr" PERCENT_FLAG "%" @@ -243,6 +244,11 @@ prologue_declaration: defines_flag = true; spec_defines_file = xstrdup ($2); } +| "%error-verbose" + { + muscle_percent_define_insert ("parse.error", @1, "verbose", + MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); + } | "%expect" INT { expected_sr_conflicts = $2; } | "%expect-rr" INT { expected_rr_conflicts = $2; } | "%file-prefix" STRING { spec_file_prefix = $2; } diff --git a/src/scan-gram.l b/src/scan-gram.l index f71409ed..279bba97 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -194,7 +194,7 @@ splice (\\[ \f\t\v]*\n)* "%defines" return PERCENT_DEFINES; "%destructor" return PERCENT_DESTRUCTOR; "%dprec" return PERCENT_DPREC; - "%error"[-_]"verbose" RETURN_PERCENT_FLAG("error-verbose"); + "%error"[-_]"verbose" return PERCENT_ERROR_VERBOSE; "%expect" return PERCENT_EXPECT; "%expect"[-_]"rr" return PERCENT_EXPECT_RR; "%file-prefix" return PERCENT_FILE_PREFIX; diff --git a/tests/actions.at b/tests/actions.at index 371cf84f..be52791c 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -29,7 +29,7 @@ AT_SETUP([Mid-rule actions]) # action. AT_DATA_GRAMMAR([[input.y]], -[[%define error-verbose +[[%define parse.error "verbose" %debug %{ # include @@ -93,7 +93,7 @@ AT_CLEANUP AT_SETUP([Exotic Dollars]) AT_DATA_GRAMMAR([[input.y]], -[[%define error-verbose +[[%define parse.error "verbose" %debug %{ # include @@ -557,7 +557,7 @@ m4_define([AT_CHECK_PRINTER_AND_DESTRUCTOR], $3 _AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4], -[%define error-verbose +[%define parse.error "verbose" %debug %verbose %locations @@ -588,7 +588,7 @@ AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union]) AT_SETUP([Default tagless %printer and %destructor]) AT_DATA_GRAMMAR([[input.y]], -[[%define error-verbose +[[%define parse.error "verbose" %debug %locations %initial-action { @@ -706,7 +706,7 @@ AT_CLEANUP AT_SETUP([Default tagged and per-type %printer and %destructor]) AT_DATA_GRAMMAR([[input.y]], -[[%define error-verbose +[[%define parse.error "verbose" %debug %{ @@ -850,7 +850,7 @@ m4_define([_AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN], [m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])]) AT_DATA_GRAMMAR([[input]]$1[[.y]], -[[%define error-verbose +[[%define parse.error "verbose" %debug %locations %initial-action { diff --git a/tests/calc.at b/tests/calc.at index 24a50800..9eee68d6 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -401,7 +401,7 @@ AT_PARSER_CHECK([./calc input], 0, [], [stderr]) # If BISON-OPTIONS contains `%location', then make sure the ERROR-LOCATION # is correctly output on stderr. # -# If BISON-OPTIONS contains `%error-verbose', then make sure the +# If BISON-OPTIONS contains `%define parse.error "verbose"', then make sure the # IF-YYERROR-VERBOSE message is properly output after `syntax error, ' # on STDERR. # @@ -443,7 +443,7 @@ 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], [%error-verbose], [], +m4_bmatch([$1], [%define parse.error "verbose"], [], [[sed 's/syntax error, .*$/syntax error/' expout >at-expout mv at-expout expout]]) # 5. Check @@ -572,22 +572,22 @@ AT_CHECK_CALC_LALR([%locations]) AT_CHECK_CALC_LALR([%name-prefix="calc"]) dnl test deprecated `=' AT_CHECK_CALC_LALR([%verbose]) AT_CHECK_CALC_LALR([%yacc]) -AT_CHECK_CALC_LALR([%error-verbose]) +AT_CHECK_CALC_LALR([%define parse.error "verbose"]) AT_CHECK_CALC_LALR([%define api.pure %locations]) AT_CHECK_CALC_LALR([%define api.push-pull "both" %define api.pure %locations]) -AT_CHECK_CALC_LALR([%error-verbose %locations]) +AT_CHECK_CALC_LALR([%define parse.error "verbose" %locations]) -AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc]) +AT_CHECK_CALC_LALR([%define parse.error "verbose" %locations %defines %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_LALR([%define parse.error "verbose" %locations %defines %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc]) AT_CHECK_CALC_LALR([%debug]) -AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_LALR([%define parse.error "verbose" %debug %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_LALR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_LALR([%define api.push-pull "both" %define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_LALR([%define api.pure %define parse.error "verbose" %debug %locations %defines %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_LALR([%define api.push-pull "both" %define api.pure %define parse.error "verbose" %debug %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_LALR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) +AT_CHECK_CALC_LALR([%define api.pure %define parse.error "verbose" %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) # ----------------------- # @@ -611,20 +611,20 @@ AT_CHECK_CALC_GLR([%locations]) AT_CHECK_CALC_GLR([%name-prefix "calc"]) AT_CHECK_CALC_GLR([%verbose]) AT_CHECK_CALC_GLR([%yacc]) -AT_CHECK_CALC_GLR([%error-verbose]) +AT_CHECK_CALC_GLR([%define parse.error "verbose"]) AT_CHECK_CALC_GLR([%define api.pure %locations]) -AT_CHECK_CALC_GLR([%error-verbose %locations]) +AT_CHECK_CALC_GLR([%define parse.error "verbose" %locations]) -AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_GLR([%define parse.error "verbose" %locations %defines %name-prefix "calc" %verbose %yacc]) AT_CHECK_CALC_GLR([%debug]) -AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc]) +AT_CHECK_CALC_GLR([%define parse.error "verbose" %debug %locations %defines %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_GLR([%define parse.error "verbose" %debug %locations %defines %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc]) -AT_CHECK_CALC_GLR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_GLR([%define api.pure %define parse.error "verbose" %debug %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_GLR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) +AT_CHECK_CALC_GLR([%define api.pure %define parse.error "verbose" %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) # ----------------------------- # @@ -645,14 +645,14 @@ m4_define([AT_CHECK_CALC_LALR1_CC], AT_CHECK_CALC_LALR1_CC([]) AT_CHECK_CALC_LALR1_CC([%locations]) -AT_CHECK_CALC_LALR1_CC([%locations %error-verbose %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_LALR1_CC([%locations %define parse.error "verbose" %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_LALR1_CC([%locations %error-verbose %debug %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_LALR1_CC([%locations %define parse.error "verbose" %debug %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %error-verbose %debug %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc]) +AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error "verbose" %debug %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error "verbose" %debug %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc]) -AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) +AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error "verbose" %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) @@ -673,12 +673,12 @@ m4_define([AT_CHECK_CALC_GLR_CC], [AT_CHECK_CALC([%language "C++" %glr-parser %defines %locations] $@)]) AT_CHECK_CALC_GLR_CC([]) -AT_CHECK_CALC_GLR_CC([%error-verbose %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_GLR_CC([%define parse.error "verbose" %name-prefix "calc" %verbose %yacc]) AT_CHECK_CALC_GLR_CC([%debug]) -AT_CHECK_CALC_GLR_CC([%error-verbose %debug %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_GLR_CC([%define parse.error "verbose" %debug %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_GLR_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_GLR_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc]) +AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error "verbose" %debug %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error "verbose" %debug %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc]) -AT_CHECK_CALC_GLR_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) +AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error "verbose" %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) -- 2.45.2