texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Sun, 26 Mar 2023 11:06:55 -0400 (EDT)

branch: master
commit f012b7a67cc99db69115b9d988134162271164d4
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Mar 26 15:35:36 2023 +0200

    * tp/Texinfo/XS/parsetexi/def.c (DEF_MAP, def_maps, parse_def): pass
    the list of def commands arguments by using a list of arguments names
    as strings.  This is a first step to allow to generalize parse_def
    to be able to handle linemacro defined arguments with arbitrary names
    and is more similar to the perl parser.
---
 ChangeLog                     |  8 ++++++
 tp/Texinfo/XS/parsetexi/def.c | 66 ++++++++++++++++++++++++++++++-------------
 2 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 974d21e4b1..55577f37ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,14 @@
        * NEWS: add 7.0.3 news.
        * README-hacking: update
 
+2023-03-26  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/parsetexi/def.c (DEF_MAP, def_maps, parse_def): pass
+       the list of def commands arguments by using a list of arguments names
+       as strings.  This is a first step to allow to generalize parse_def
+       to be able to handle linemacro defined arguments with arbitrary names
+       and is more similar to the perl parser.
+
 2023-03-26  Patrice Dumas  <pertusus@free.fr>
 
        linemacro implementation for the perl Parser
diff --git a/tp/Texinfo/XS/parsetexi/def.c b/tp/Texinfo/XS/parsetexi/def.c
index b1317a6ac1..79e37aef7c 100644
--- a/tp/Texinfo/XS/parsetexi/def.c
+++ b/tp/Texinfo/XS/parsetexi/def.c
@@ -149,6 +149,34 @@ DEF_ALIAS def_aliases[] = {
   0, 0, 0
 };
 
+typedef struct {
+    enum command_id command;
+    char **arguments;
+} DEF_MAP;
+
+char *defline_arguments[] = {"category", "name", "arg", 0};
+char *defvr_arguments[] = {"category", "name", 0};
+char *deftypefn_arguments[] = {"category", "type", "name", "argtype", 0};
+char *deftypeop_arguments[] = {"category", "class" , "type", "name", 
"argtype", 0};
+char *deftypevr_arguments[] = {"category", "type", "name", 0};
+char *defcv_arguments[] = {"category", "class" , "name", 0};
+char *deftypecv_arguments[] = {"category", "class" , "type", "name", 0};
+char *defop_arguments[] = {"category", "class" , "name", "arg", 0};
+char *deftp_arguments[] = {"category", "name", "argtype", 0};
+
+DEF_MAP def_maps[] = {
+  CM_defline, defline_arguments,
+  CM_deffn, defline_arguments,
+  CM_defvr, defvr_arguments,
+  CM_deftypefn, deftypefn_arguments,
+  CM_deftypeop, deftypeop_arguments,
+  CM_deftypevr, deftypevr_arguments,
+  CM_defcv, defcv_arguments,
+  CM_deftypecv, deftypecv_arguments,
+  CM_defop, defop_arguments,
+  CM_deftp, deftp_arguments,
+};
+
 /* Split non-space text elements into strings without [ ] ( ) , and single
    character strings with one of them. */
 static void
@@ -292,7 +320,7 @@ parse_def (enum command_id command, ELEMENT *current)
   DEF_INFO *ret;
   int contents_idx = 0;
   int type, next_type;
-  int i;
+  int i, i_def;
   ELEMENT *e, *e1; 
 
   ret = malloc (sizeof (DEF_INFO));
@@ -346,30 +374,30 @@ parse_def (enum command_id command, ELEMENT *current)
      NAME - name of entity being documented
      ARGUMENTS - arguments to a function or macro                  */
 
-  /* CATEGORY */
-  ret->category = next_bracketed_or_word_agg (current, &contents_idx);
-
-  /* CLASS */
-  if (command == CM_deftypeop
-      || command == CM_defcv
-      || command == CM_deftypecv
-      || command == CM_defop)
+  for (i_def = 0; i_def < sizeof (def_maps) / sizeof (*def_maps); i_def++)
     {
-      ret->class = next_bracketed_or_word_agg (current, &contents_idx);
+      if (def_maps[i_def].command == command)
+        goto def_found;
     }
+  fatal ("no arguments for def command");
+ def_found:
 
-  /* TYPE */
-  if (command == CM_deftypefn
-      || command == CM_deftypeop
-      || command == CM_deftypevr
-      || command == CM_deftypecv)
+  i = 0;
+  while (def_maps[i_def].arguments[i])
     {
-      ret->type = next_bracketed_or_word_agg (current, &contents_idx);
+      char *arg_type_name = def_maps[i_def].arguments[i];
+
+      if (!strcmp (arg_type_name, "category"))
+        ret->category = next_bracketed_or_word_agg (current, &contents_idx);
+      else if (!strcmp (arg_type_name, "class"))
+        ret->class = next_bracketed_or_word_agg (current, &contents_idx);
+      else if (!strcmp (arg_type_name, "type"))
+        ret->type = next_bracketed_or_word_agg (current, &contents_idx);
+      else if (!strcmp (arg_type_name, "name"))
+        ret->name = next_bracketed_or_word_agg (current, &contents_idx);
+      i++;
     }
 
-  /* NAME */
-  ret->name = next_bracketed_or_word_agg (current, &contents_idx);
-
   if (ret->category)
     {
       add_extra_string_dup (ret->category, "def_role", "category");



reply via email to

[Prev in Thread] Current Thread [Next in Thread]