gnulib: use new features of the argmatch module

It can now generate the usage message.

* src/complain.h (feature_fixit_parsable): Rename as...
(feature_fixit): this, for column economy.
Adjust dependencies.
(warning_usage): New.
Use it.
* src/complain.h, src/complain.c, src/getargs.h, src/getargs.c:
Use ARGMATCH_DEFINE_GROUP instead of the older interface.
This commit is contained in:
Akim Demaille
2019-06-21 18:41:13 +02:00
parent 1161649446
commit 6d35340556
6 changed files with 201 additions and 145 deletions

2
gnulib

Submodule gnulib updated: 962862267a...65b3308bb6

View File

@@ -144,6 +144,56 @@ static const warnings warnings_types[] =
ARGMATCH_VERIFY (warnings_args, warnings_types); ARGMATCH_VERIFY (warnings_args, warnings_types);
ARGMATCH_DEFINE_GROUP(warning, warnings);
static const argmatch_warning_doc argmatch_warning_docs[] =
{
{ "conflicts-sr", N_("S/R conflicts (enabled by default)") },
{ "conflicts-rr", N_("R/R conflicts (enabled by default)") },
{ "deprecated", N_("obsolete constructs") },
{ "empty-rule", N_("empty rules without %empty") },
{ "midrule-values", N_("unset or unused midrule values") },
{ "precedence", N_("useless precedence and associativity") },
{ "yacc", N_("incompatibilities with POSIX Yacc") },
{ "other", N_("all other warnings (enabled by default)") },
{ "all", N_("all the warnings except 'yacc'") },
{ "no-CATEGORY", N_("turn off warnings in CATEGORY") },
{ "none", N_("turn off all the warnings") },
{ "error[=CATEGORY]", N_("treat warnings as errors") },
{ NULL, NULL }
};
static const argmatch_warning_arg argmatch_warning_args[] =
{
{ "none", Wnone },
{ "midrule-values", Wmidrule_values },
{ "yacc", Wyacc },
{ "conflicts-sr", Wconflicts_sr },
{ "conflicts-rr", Wconflicts_rr },
{ "deprecated", Wdeprecated },
{ "empty-rule", Wempty_rule },
{ "precedence", Wprecedence },
{ "other", Wother },
{ "all", Wall },
{ "error", Werror },
{ "everything", Weverything },
{ NULL, Wnone }
};
const argmatch_warning_group_type argmatch_warning_group =
{
argmatch_warning_args,
argmatch_warning_docs,
N_("Warning categories include:"),
NULL
};
void
warning_usage (FILE *out)
{
argmatch_warning_usage (out);
}
void void
warning_argmatch (char const *arg, size_t no, size_t err) warning_argmatch (char const *arg, size_t no, size_t err)
{ {
@@ -187,7 +237,14 @@ warning_argmatch (char const *arg, size_t no, size_t err)
void void
warnings_argmatch (char *args) warnings_argmatch (char *args)
{ {
if (args) if (!args)
warning_argmatch ("all", 0, 0);
else if (STREQ (args, "help"))
{
warning_usage (stdout);
exit (EXIT_SUCCESS);
}
else
for (args = strtok (args, ","); args; args = strtok (NULL, ",")) for (args = strtok (args, ","); args; args = strtok (NULL, ","))
if (STREQ (args, "error")) if (STREQ (args, "error"))
warnings_are_errors = true; warnings_are_errors = true;
@@ -203,8 +260,6 @@ warnings_argmatch (char *args)
warning_argmatch (args, no, err); warning_argmatch (args, no, err);
} }
else
warning_argmatch ("all", 0, 0);
} }
static const char* static const char*

View File

@@ -60,6 +60,8 @@ typedef enum
/** Whether -Werror was set. */ /** Whether -Werror was set. */
extern bool warnings_are_errors; extern bool warnings_are_errors;
void warning_usage (FILE *out);
/** Decode a single argument from -W. /** Decode a single argument from -W.
* *
* \param arg the subarguments to decode. * \param arg the subarguments to decode.

View File

@@ -91,7 +91,7 @@ fixits_register (location const *loc, char const* fix)
true); true);
fixit *f = fixit_new (loc, fix); fixit *f = fixit_new (loc, fix);
gl_sortedlist_add (fixits, (gl_listelement_compar_fn) fixit_cmp, f); gl_sortedlist_add (fixits, (gl_listelement_compar_fn) fixit_cmp, f);
if (feature_flag & feature_fixit_parsable) if (feature_flag & feature_fixit)
fixit_print (f, stderr); fixit_print (f, stderr);
} }

View File

@@ -68,28 +68,28 @@ const char *skeleton = NULL;
int language_prio = default_prio; int language_prio = default_prio;
struct bison_language const *language = &valid_languages[0]; struct bison_language const *language = &valid_languages[0];
typedef int* (xargmatch_fn) (const char *context, const char *arg);
/** Decode an option's key. /** Decode an option's key.
* *
* \param opt option being decoded. * \param opt option being decoded.
* \param keys array of valid subarguments. * \param xargmatch matching function.
* \param values array of corresponding (int) values. * \param all the value of the argument 'all'.
* \param all the all value. * \param flags the flags to update
* \param flags the flags to update * \param arg the subarguments to decode.
* \param arg the subarguments to decode. * If null, then activate all the flags.
* If null, then activate all the flags. * \param no length of the potential "no-" prefix.
* \param no length of the potential "no-" prefix. * Can be 0 or 3. If 3, negate the action of the subargument.
* Can be 0 or 3. If 3, negate the action of the subargument.
* *
* If VALUE != 0 then KEY sets flags and no-KEY clears them. * If VALUE != 0 then KEY sets flags and no-KEY clears them.
* If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all * If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all
* flags from \c all. Thus no-none = all and no-all = none. * flags from \c all. Thus no-none = all and no-all = none.
*/ */
static void static void
flag_argmatch (const char *opt, flag_argmatch (const char *opt, xargmatch_fn xargmatch,
const char *const keys[], const int values[],
int all, int *flags, char *arg, size_t no) int all, int *flags, char *arg, size_t no)
{ {
int value = XARGMATCH (opt, arg + no, keys, values); int value = *xargmatch (opt, arg + no);
/* -rnone == -rno-all, and -rno-none == -rall. */ /* -rnone == -rno-all, and -rno-none == -rall. */
if (!value) if (!value)
@@ -104,30 +104,37 @@ flag_argmatch (const char *opt,
*flags |= value; *flags |= value;
} }
typedef void (usage_fn) (FILE *out);
/** Decode an option's set of keys. /** Decode an option's set of keys.
* *
* \param opt option being decoded (e.g., --report). * \param opt option being decoded (e.g., --report).
* \param keys array of valid subarguments. * \param xargmatch matching function.
* \param values array of corresponding (int) values. * \param all the value of the argument 'all'.
* \param all the all value. * \param flags the flags to update
* \param flags the flags to update * \param args comma separated list of effective subarguments to decode.
* \param args comma separated list of effective subarguments to decode. * If 0, then activate all the flags.
* If 0, then activate all the flags.
*/ */
static void static void
flags_argmatch (const char *opt, flags_argmatch (const char *opt,
const char * const keys[], const int values[], xargmatch_fn xargmatch,
usage_fn usage,
int all, int *flags, char *args) int all, int *flags, char *args)
{ {
if (args) if (!args)
*flags |= all;
else if (STREQ (args, "help"))
{
usage (stdout);
exit (EXIT_SUCCESS);
}
else
for (args = strtok (args, ","); args; args = strtok (NULL, ",")) for (args = strtok (args, ","); args; args = strtok (NULL, ","))
{ {
size_t no = STRPREFIX_LIT ("no-", args) ? 3 : 0; size_t no = STRPREFIX_LIT ("no-", args) ? 3 : 0;
flag_argmatch (opt, keys, flag_argmatch (opt, xargmatch,
values, all, flags, args, no); all, flags, args, no);
} }
else
*flags |= all;
} }
@@ -142,116 +149,142 @@ flags_argmatch (const char *opt,
* \arg FlagName_flag the flag to update. * \arg FlagName_flag the flag to update.
*/ */
#define FLAGS_ARGMATCH(FlagName, Args, All) \ #define FLAGS_ARGMATCH(FlagName, Args, All) \
flags_argmatch ("--" #FlagName, FlagName ## _args, FlagName ## _types, \ flags_argmatch ("--" #FlagName, \
(xargmatch_fn*) argmatch_## FlagName ## _value, \
argmatch_## FlagName ## _usage, \
All, &FlagName ## _flag, Args) All, &FlagName ## _flag, Args)
/*----------------------. /*----------------------.
| --report's handling. | | --report's handling. |
`----------------------*/ `----------------------*/
static const char * const report_args[] = ARGMATCH_DEFINE_GROUP(report, enum report);
static const argmatch_report_doc argmatch_report_docs[] =
{ {
/* In a series of synonyms, present the most meaningful first, so { "states", N_("describe the states") },
that argmatch_valid be more readable. */ { "itemsets", N_("complete the core item sets with their closure") },
"none", { "lookaheads", N_("explicitly associate lookahead tokens to items") },
"state", "states", { "solved", N_("describe shift/reduce conflicts solving") },
"itemset", "itemsets", { "all", N_("include all the above information") },
"lookahead", "lookaheads", "look-ahead", { "none", N_("disable the report") },
"solved", { NULL, NULL },
"all",
0
}; };
static const int report_types[] = static const argmatch_report_arg argmatch_report_args[] =
{ {
report_none, { "none", report_none },
report_states, report_states, { "states", report_states },
report_states | report_itemsets, report_states | report_itemsets, { "itemsets", report_states | report_itemsets },
report_states | report_lookahead_tokens, { "lookaheads", report_states | report_lookahead_tokens },
report_states | report_lookahead_tokens, { "look-ahead", report_states | report_lookahead_tokens },
report_states | report_lookahead_tokens, { "solved", report_states | report_solved_conflicts },
report_states | report_solved_conflicts, { "all", report_all },
report_all { NULL, report_none },
}; };
ARGMATCH_VERIFY (report_args, report_types); const argmatch_report_group_type argmatch_report_group =
{
argmatch_report_args,
argmatch_report_docs,
N_("THINGS is a list of comma separated words that can include:"),
NULL
};
/*---------------------. /*---------------------.
| --trace's handling. | | --trace's handling. |
`---------------------*/ `---------------------*/
static const char * const trace_args[] = ARGMATCH_DEFINE_GROUP(trace, enum trace);
static const argmatch_trace_doc argmatch_trace_docs[] =
{ {
"none - no traces", /* Meant for developers only, don't translate them. */
"locations - full display of the locations", { "none", "no traces" },
"scan - grammar scanner traces", { "locations", "full display of the locations" },
"parse - grammar parser traces", { "scan", "grammar scanner traces" },
"automaton - construction of the automaton", { "parse", "grammar parser traces" },
"bitsets - use of bitsets", { "automaton", "construction of the automaton" },
"closure - input/output of closure", { "bitsets", "use of bitsets" },
"grammar - reading, reducing the grammar", { "closure", "input/output of closure" },
"resource - memory consumption (where available)", { "grammar", "reading, reducing the grammar" },
"sets - grammar sets: firsts, nullable etc.", { "resource", "memory consumption (where available)" },
"muscles - m4 definitions passed to the skeleton", { "sets", "grammar sets: firsts, nullable etc." },
"tools - m4 invocation", { "muscles", "m4 definitions passed to the skeleton" },
"m4 - m4 traces", { "tools", "m4 invocation" },
"skeleton - skeleton postprocessing", { "m4", "m4 traces" },
"time - time consumption", { "skeleton", "skeleton postprocessing" },
"ielr - IELR conversion", { "time", "time consumption" },
"all - all of the above", { "ielr", "IELR conversion" },
0 { "all", "all of the above" },
{ NULL, NULL},
}; };
static const int trace_types[] = static const argmatch_trace_arg argmatch_trace_args[] =
{ {
trace_none, { "none", trace_none },
trace_locations, { "locations", trace_locations },
trace_scan, { "scan", trace_scan },
trace_parse, { "parse", trace_parse },
trace_automaton, { "automaton", trace_automaton },
trace_bitsets, { "bitsets", trace_bitsets },
trace_closure, { "closure", trace_closure },
trace_grammar, { "grammar", trace_grammar },
trace_resource, { "resource", trace_resource },
trace_sets, { "sets", trace_sets },
trace_muscles, { "muscles", trace_muscles },
trace_tools, { "tools", trace_tools },
trace_m4, { "m4", trace_m4 },
trace_skeleton, { "skeleton", trace_skeleton },
trace_time, { "time", trace_time },
trace_ielr, { "ielr", trace_ielr },
trace_all { "all", trace_all },
{ NULL, trace_none},
}; };
ARGMATCH_VERIFY (trace_args, trace_types); const argmatch_trace_group_type argmatch_trace_group =
{
argmatch_trace_args,
argmatch_trace_docs,
N_("TRACES is a list of comma separated words that can include:"),
NULL
};
/*-----------------------. /*-----------------------.
| --feature's handling. | | --feature's handling. |
`-----------------------*/ `-----------------------*/
static const char * const feature_args[] = ARGMATCH_DEFINE_GROUP(feature, enum feature);
static const argmatch_feature_doc argmatch_feature_docs[] =
{ {
"none", { "caret", N_("show errors with carets") },
"caret", "diagnostics-show-caret", { "fixit", N_("show machine-readable fixes") },
"fixit", "diagnostics-parseable-fixits", { "syntax-only", N_("do not generate any file") },
"syntax-only", { "all", N_("all of the above") },
"all", { "none", N_("disable all of the above") },
0 { NULL, NULL }
}; };
static const int feature_types[] = static const argmatch_feature_arg argmatch_feature_args[] =
{ {
feature_none, { "none", feature_none },
feature_caret, feature_caret, { "caret", feature_caret },
feature_fixit_parsable, feature_fixit_parsable, { "diagnostics-show-caret", feature_caret },
feature_syntax_only, { "fixit", feature_fixit },
feature_all { "diagnostics-parseable-fixits", feature_fixit },
{ "syntax-only", feature_syntax_only },
{ "all", feature_all },
{ NULL, feature_none}
}; };
ARGMATCH_VERIFY (feature_args, feature_types); const argmatch_feature_group_type argmatch_feature_group =
{
argmatch_feature_args,
argmatch_feature_docs,
N_("FEATURES is a list of comma separated words that can include:"),
NULL
};
/*-------------------------------------------. /*-------------------------------------------.
| Display the help message and exit STATUS. | | Display the help message and exit STATUS. |
@@ -334,49 +367,15 @@ Output:\n\
"), stdout); "), stdout);
putc ('\n', stdout); putc ('\n', stdout);
fputs (_("\ warning_usage (stdout);
Warning categories include:\n\
'conflicts-sr' S/R conflicts (enabled by default)\n\
'conflicts-rr' R/R conflicts (enabled by default)\n\
'deprecated' obsolete constructs\n\
'empty-rule' empty rules without %empty\n\
'midrule-values' unset or unused midrule values\n\
'precedence' useless precedence and associativity\n\
'yacc' incompatibilities with POSIX Yacc\n\
'other' all other warnings (enabled by default)\n\
'all' all the warnings except 'yacc'\n\
'no-CATEGORY' turn off warnings in CATEGORY\n\
'none' turn off all the warnings\n\
'error[=CATEGORY]' treat warnings as errors\n\
"), stdout);
putc ('\n', stdout); putc ('\n', stdout);
fputs (_("\ argmatch_report_usage (stdout);
THINGS is a list of comma separated words that can include:\n\
'state' describe the states\n\
'itemset' complete the core item sets with their closure\n\
'lookahead' explicitly associate lookahead tokens to items\n\
'solved' describe shift/reduce conflicts solving\n\
'all' include all the above information\n\
'none' disable the report\n\
"), stdout);
putc ('\n', stdout); putc ('\n', stdout);
fputs (_("\ argmatch_feature_usage (stdout);
FEATURES is a list of comma separated words that can include:\n\
'caret', 'diagnostics-show-caret'\n\
show errors with carets\n\
'fixit', 'diagnostics-parseable-fixits'\n\
show machine-readable fixes\n\
'syntax-only'\n\
do not generate any file\n\
'all'\n\
all of the above\n\
'none'\n\
disable all of the above\n\
"), stdout);
putc ('\n', stdout); putc ('\n', stdout);
printf (_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT); printf (_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
printf (_("%s home page: <%s>.\n"), PACKAGE_NAME, PACKAGE_URL); printf (_("%s home page: <%s>.\n"), PACKAGE_NAME, PACKAGE_URL);
fputs (_("General help using GNU software: " fputs (_("General help using GNU software: "

View File

@@ -118,7 +118,7 @@ enum feature
{ {
feature_none = 0, /**< No additional feature. */ feature_none = 0, /**< No additional feature. */
feature_caret = 1 << 0, /**< Output errors with carets. */ feature_caret = 1 << 0, /**< Output errors with carets. */
feature_fixit_parsable = 1 << 1, /**< Issue instructions to fix the sources. */ feature_fixit = 1 << 1, /**< Issue instructions to fix the sources. */
feature_syntax_only = 1 << 2, /**< Don't generate output. */ feature_syntax_only = 1 << 2, /**< Don't generate output. */
feature_all = ~0 /**< All above features. */ feature_all = ~0 /**< All above features. */
}; };