[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: argmatch: accept perfect matches in documented arglists
From: |
Akim Demaille |
Subject: |
Re: argmatch: accept perfect matches in documented arglists |
Date: |
Sat, 22 Jun 2019 08:46:01 +0200 |
Hi!
> Le 21 juin 2019 à 23:21, Bruno Haible <address@hidden> a écrit :
>
> Thanks. Still a bit surprising:
>
>> + /* All the features of an argmatch group. */ \
>> + typedef struct \
>> + { \
>> + const argmatch_##Name##_doc* docs; \
>> + const argmatch_##Name##_arg* args; \
>
> I would have expected this to be reordered like this:
>
> /* All the features of an argmatch group. */ \
> typedef struct \
> { \
> const argmatch_##Name##_arg* args; \
> const argmatch_##Name##_doc* docs; \
>
> Rationale:
> * So that all doc strings are close together in the struct.
> * You prefer to see the doc first, but in the .texi that you have written you
> let the programmer define first argmatch_backup_args and then - considering
> the "groups of synonyms" - the argmatch_backup_docs.
In the introduction to newcomers, I felt it was more natural this way,
but in code, I think it is way more human friendly to do the opposite.
The following:
static const argmatch_report_doc argmatch_report_docs[] =
{
{ "states", N_("describe the states") },
{ "itemsets", N_("complete the core item sets with their closure") },
{ "lookaheads", N_("explicitly associate lookahead tokens to items") },
{ "solved", N_("describe shift/reduce conflicts solving") },
{ "all", N_("include all the above information") },
{ "none", N_("disable the report") },
{ NULL, NULL },
};
static const argmatch_report_arg argmatch_report_args[] =
{
{ "none", report_none },
{ "states", report_states },
{ "itemsets", report_states | report_itemsets },
{ "lookaheads", report_states | report_lookahead_tokens },
{ "look-ahead", report_states | report_lookahead_tokens },
{ "solved", report_states | report_solved_conflicts },
{ "all", report_all },
{ NULL, report_none },
};
looks better to me than the converse.
I installed the following fix, thanks!
commit 962862267a52e608a7cbff5910d941c5479efa68
Author: Akim Demaille <address@hidden>
Date: Sat Jun 22 08:37:31 2019 +0200
argmatch: put all the docs member last.
Reported by Bruno Haible.
* lib/argmatch.h (argmatch_##Name##_group_type): Put the args
member before the docs done.
* doc/argmatch.texi, tests/test-argmatch.c: Adjust.
diff --git a/ChangeLog b/ChangeLog
index d0a6a22a1..cdc2b3d7a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-06-22 Akim Demaille <address@hidden>
+
+ argmatch: put all the docs member last.
+ Reported by Bruno Haible.
+ * lib/argmatch.h (argmatch_##Name##_group_type): Put the args
+ member before the docs done.
+ * doc/argmatch.texi, tests/test-argmatch.c: Adjust.
+
2019-06-21 Akim Demaille <address@hidden>
argmatch: add support to generate the usage message.
diff --git a/doc/argmatch.texi b/doc/argmatch.texi
index 922252070..94787fabf 100644
--- a/doc/argmatch.texi
+++ b/doc/argmatch.texi
@@ -92,8 +92,8 @@ Finally, define the argmatch group:
@example
const argmatch_backup_group_type argmatch_backup_group =
@{
- argmatch_backup_docs,
argmatch_backup_args,
+ argmatch_backup_docs,
N_("\
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\
The version control method may be selected via the --backup option or
through\n\
diff --git a/lib/argmatch.h b/lib/argmatch.h
index 6f641aff4..427d7179f 100644
--- a/lib/argmatch.h
+++ b/lib/argmatch.h
@@ -122,29 +122,29 @@ char const *argmatch_to_argument (void const *value,
argmatch_##Name##_size = sizeof (argmatch_##Name##_type) \
}; \
\
- /* Documentation of this group. */ \
+ /* Argument mapping of this group. */ \
typedef struct \
{ \
/* Argument (e.g., "simple"). */ \
const char const *arg; \
- /* Documentation (e.g., N_("always make simple backups")). */ \
- const char const *doc; \
- } argmatch_##Name##_doc; \
+ /* Value (e.g., simple_backups). */ \
+ const argmatch_##Name##_type val; \
+ } argmatch_##Name##_arg; \
\
- /* Argument mapping of this group. */ \
+ /* Documentation of this group. */ \
typedef struct \
{ \
/* Argument (e.g., "simple"). */ \
const char const *arg; \
- /* Value (e.g., simple_backups). */ \
- const argmatch_##Name##_type val; \
- } argmatch_##Name##_arg; \
+ /* Documentation (e.g., N_("always make simple backups")). */ \
+ const char const *doc; \
+ } argmatch_##Name##_doc; \
\
/* All the features of an argmatch group. */ \
typedef struct \
{ \
- const argmatch_##Name##_doc* docs; \
const argmatch_##Name##_arg* args; \
+ const argmatch_##Name##_doc* docs; \
\
/* Printed before the usage message. */ \
const char *doc_pre; \
diff --git a/tests/test-argmatch.c b/tests/test-argmatch.c
index 4c724f4cf..0d19e9795 100644
--- a/tests/test-argmatch.c
+++ b/tests/test-argmatch.c
@@ -89,8 +89,8 @@ static const argmatch_backup_arg argmatch_backup_args[] =
const argmatch_backup_group_type argmatch_backup_group =
{
- argmatch_backup_docs,
argmatch_backup_args,
+ argmatch_backup_docs,
N_("\
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\
The version control method may be selected via the --backup option or
through\n\