From: Joel E. Denny Date: Fri, 24 Apr 2009 05:42:58 +0000 (-0400) Subject: List accepted values for a %define enum variable with an invalid value. X-Git-Tag: v2.7.90~884 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/f49097730eb04fdb52bc1a625b93df26437bbefb List accepted values for a %define enum variable with an invalid value. Suggested by Akim Demaille at . * data/bison.m4 (_b4_percent_define_check_values): Implement. * src/muscle-tab.c (muscle_percent_define_check_values): Implement. * tests/input.at (%define lr.default_reductions invalid values): Merge into... (%define enum variables): ... here, and update output. (cherry picked from commit 25029e164a3b2385ae6d95ca4cd19bad36550c92) --- diff --git a/ChangeLog b/ChangeLog index 13193edd..d1c6c8af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-04-24 Joel E. Denny + + List accepted values for a %define enum variable with an invalid value. + Suggested by Akim Demaille at + . + * data/bison.m4 (_b4_percent_define_check_values): Implement. + * src/muscle-tab.c (muscle_percent_define_check_values): Implement. + * tests/input.at (%define lr.default_reductions invalid values): Merge + into... + (%define enum variables): ... here, and update output. + 2009-04-23 Joel E. Denny Rename "default rule" to "default reduction". diff --git a/data/bison.m4 b/data/bison.m4 index 3c68c4c1..9f88b6a6 100644 --- a/data/bison.m4 +++ b/data/bison.m4 @@ -724,7 +724,11 @@ m4_define([_b4_percent_define_check_values], [b4_complain_at(b4_percent_define_get_loc([$1]), [[invalid value for %%define variable `%s': `%s']], [$1], - m4_dquote(m4_indir([b4_percent_define(]$1[)])))])dnl + m4_dquote(m4_indir([b4_percent_define(]$1[)]))) + m4_foreach([b4_value], m4_dquote(m4_shift($@)), + [b4_complain_at(b4_percent_define_get_loc([$1]), + [[accepted value: `%s']], + m4_dquote(b4_value))])])dnl m4_popdef([b4_good_value])], [b4_fatal([[undefined %%define variable `%s' passed to b4_percent_define_check_values]], [$1])])]) diff --git a/src/muscle-tab.c b/src/muscle-tab.c index 9ed80148..90f1c3d7 100644 --- a/src/muscle-tab.c +++ b/src/muscle-tab.c @@ -575,35 +575,40 @@ muscle_percent_define_check_values (char const * const *values) { for (; *values; ++values) { - char const *variable = *values; + char const * const *variablep = values; char const *name; char *value; - MUSCLE_USER_NAME_CONVERT (name, "percent_define(", variable, ")"); + MUSCLE_USER_NAME_CONVERT (name, "percent_define(", *variablep, ")"); value = muscle_string_decode (name); if (value) { - bool valid = false; for (++values; *values; ++values) { if (0 == strcmp (value, *values)) - { - valid = true; - while (*values) - ++values; - break; - } + break; + } + if (!*values) + { + location loc = muscle_percent_define_get_loc (*variablep); + complain_at(loc, + _("invalid value for %%define variable `%s': `%s'"), + *variablep, value); + for (values = variablep + 1; *values; ++values) + complain_at (loc, _("accepted value: `%s'"), *values); + } + else + { + while (*values) + ++values; } - if (!valid) - complain_at(muscle_percent_define_get_loc (variable), - _("invalid value for %%define variable `%s': `%s'"), - variable, value); free (value); } else - fatal(_("undefined %%define variable `%s' passed to muscle_percent_define_check_values"), - variable); + fatal(_("undefined %%define variable `%s' passed to" + " muscle_percent_define_check_values"), + *variablep); } } diff --git a/tests/input.at b/tests/input.at index c19b8c1e..db3f3234 100644 --- a/tests/input.at +++ b/tests/input.at @@ -921,38 +921,36 @@ AT_BISON_CHECK([[Input.y]], [1], [], AT_CLEANUP -## ---------------------------------------------- ## -## %define lr.default_reductions invalid values. ## -## ---------------------------------------------- ## +## ------------------------ ## +## %define enum variables. ## +## ------------------------ ## -AT_SETUP([[%define lr.default_reductions invalid values]]) +AT_SETUP([[%define enum variables]]) +# Front-end. AT_DATA([[input.y]], [[%define lr.default_reductions "bogus" %% start: ; ]]) - AT_BISON_CHECK([[input.y]], [[1]], [[]], [[input.y:1.9-29: invalid value for %define variable `lr.default_reductions': `bogus' +input.y:1.9-29: accepted value: `all' +input.y:1.9-29: accepted value: `consistent' +input.y:1.9-29: accepted value: `accepting' ]]) -AT_CLEANUP - -## ------------------------ ## -## %define enum variables. ## -## ------------------------ ## - -AT_SETUP([[%define enum variables]]) - +# Back-end. AT_DATA([[input.y]], [[%define api.push_pull "neither" %% start: ; ]]) - AT_BISON_CHECK([[input.y]], [1], [], [[input.y:1.9-21: invalid value for %define variable `api.push_pull': `neither' +input.y:1.9-21: accepted value: `pull' +input.y:1.9-21: accepted value: `push' +input.y:1.9-21: accepted value: `both' ]]) AT_CLEANUP