texinfo-commits
[Top][All Lists]
Advanced

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

[8141] parsetexi update


From: gavinsmith0123
Subject: [8141] parsetexi update
Date: Sat, 1 Sep 2018 11:43:30 -0400 (EDT)

Revision: 8141
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=8141
Author:   gavin
Date:     2018-09-01 11:43:30 -0400 (Sat, 01 Sep 2018)
Log Message:
-----------
parsetexi update

Modified Paths:
--------------
    trunk/tp/Texinfo/XS/parsetexi/def.c
    trunk/tp/Texinfo/XS/parsetexi/element_types.c
    trunk/tp/Texinfo/XS/parsetexi/element_types.h
    trunk/tp/Texinfo/XS/parsetexi/element_types.txt

Modified: trunk/tp/Texinfo/XS/parsetexi/def.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/def.c 2018-09-01 15:39:26 UTC (rev 8140)
+++ trunk/tp/Texinfo/XS/parsetexi/def.c 2018-09-01 15:43:30 UTC (rev 8141)
@@ -75,7 +75,9 @@
         return 0;
       if (current->contents.list[*i]->type != ET_spaces
           && current->contents.list[*i]->type != ET_spaces_inserted
-          && current->contents.list[*i]->type != ET_empty_spaces_after_command)
+          && current->contents.list[*i]->type != ET_spaces_at_end
+          && current->contents.list[*i]->type != ET_empty_spaces_after_command
+          && current->contents.list[*i]->type != ET_delimiter)
         break;
       (*i)++;
     }
@@ -103,6 +105,55 @@
   0, 0, 0
 };
 
+/* Split non-space text elements into strings without [ ] ( ) , and single
+   character strings with one of them.
+
+   TODO: also collect adjacent non-whitespace elements, e.g. 'address@hidden' 
into a 
+   single ET_def_aggregate element. */
+static void
+split_delimiters (ELEMENT *current, int starting_idx)
+{
+  int i;
+  static char *chars = "[](),";
+  for (i = starting_idx; i < current->contents.number; i++)
+    {
+      ELEMENT *e = current->contents.list[i];
+      int j;
+      char *p;
+      ELEMENT *new;
+      int len;
+
+      if (e->type != ET_NONE
+          || e->text.end == 0)
+        continue;
+      if (e->type == ET_empty_spaces_after_command)
+        continue;
+      p = e->text.text;
+
+      while (1)
+        {
+          if (strchr (chars, *p))
+            {
+              new = new_element (ET_delimiter);
+              text_append_n (&new->text, p, 1);
+              insert_into_contents (current, new, i++);
+              add_extra_string_dup (new, "def_role", "delimiter");
+              if (!*++p)
+                break;
+              continue;
+            }
+
+          len = strcspn (p, chars);
+          new = new_element (ET_NONE);
+          text_append_n (&new->text, p, len);
+          insert_into_contents (current, new, i++);
+          if (!*(p += len))
+            break;
+        }
+      destroy_element (remove_from_contents (current, i--));
+    }
+}
+
 /* Divide any text elements into separate elements, separating whitespace
    and non-whitespace. */
 static void
@@ -161,7 +212,9 @@
 {
   DEF_INFO *ret;
   int contents_idx;
+  int args_start;
   ELEMENT *arg;
+  int type, next_type;
   ELEMENT *e, *e1;
   enum command_id original_command = CM_NONE;
 
@@ -190,9 +243,14 @@
       original_command = command;
       command = def_aliases[i].command;
 
+      contents_idx = 0;
+      if (current->contents.number > 0
+          && current->contents.list[0]->type == ET_empty_spaces_after_command)
+        contents_idx++;
+
       /* Used when category text has a space in it. */
       e = new_element (ET_bracketed_inserted);
-      insert_into_contents (current, e, 0);
+      insert_into_contents (current, e, contents_idx++);
       e1 = new_element (ET_NONE);
       text_append_n (&e1->text, category, strlen (category));
       add_to_element_contents (e, e1);
@@ -205,7 +263,8 @@
 
       e = new_element (ET_spaces_inserted);
       text_append_n (&e->text, " ", 1);
-      insert_into_contents (current, e, 1);
+      add_extra_string_dup (e, "def_role", "spaces");
+      insert_into_contents (current, e, contents_idx);
     }
 
 
@@ -259,100 +318,25 @@
     {
       add_extra_string_dup (ret->name, "def_role", "name");
     }
-  /* TODO: process args */
 
-  return ret;
+  /* Process args */
+  args_start = contents_idx;
+  split_delimiters (current, contents_idx);
 
-}
+  /* For some commands, alternate between "arg" and "typearg". This matters for
+     the DocBook output. */
+  if (command == CM_deftypefn || command == CM_deftypeop
+          || command == CM_deftp)
+    next_type = -1;
+  else
+    next_type = 1;
 
-#if 0
-  /* ARGUMENTS */
-
-  args_start = def_args->nelements;
-  // 2441
-  while (arg_line->contents.number > 0)
+  type = 1;
+  while ((arg = next_bracketed_or_word (current, &contents_idx)))
     {
-      arg = next_bracketed_or_word (arg_line, &spaces, 0);
-      if (spaces)
-        add_to_def_args_extra (def_args, "spaces", spaces);
-      if (!arg)
-        goto finished;
-      if (arg->text.end > 0) // 2445
-        {
-          ELEMENT *e;
-          char *p = arg->text.text;
-          int len;
-          /* Split this argument into multiple arguments, separated by
-             separator characters. */
-          while (1)
-            {
-              /* Square and round brackets used for optional arguments
-                 and grouping.  Commas allowed as well? */
-              len = strcspn (p, "[](),");
-              if (len > 0)
-                {
-                  e = new_element (ET_NONE);
-                  e->parent_type = route_not_in_tree;
-                  text_append_n (&e->text, p, len);
-                  add_to_def_args_extra (def_args, "arg", e);
-                  p += len;
-                }
-              if (!*p)
-                break;
-              while (*p && strchr ("[](),", *p))
-                {
-                  e = new_element (ET_delimiter);
-                  e->parent_type = route_not_in_tree;
-                  text_append_n (&e->text, p++, 1);
-                  add_to_def_args_extra (def_args, "delimiter", e);
-                }
-              if (!*p)
-                break;
-            }
-          destroy_element (arg);
-        }
-      else
-        {
-          add_to_def_args_extra (def_args, "arg", arg);
-        }
-    }
+      add_extra_string_dup (arg, "def_role",
+                            (type *= next_type) == 1 ? "arg" : "typearg");
 
-finished:
-
-  // 2460 - argtype
-  /* Change some of the left sides to 'typearg'.  This matters for
-     the DocBook output. */
-  if (args_start > 0
-      && (command == CM_deftypefn || command == CM_deftypeop
-          || command == CM_deftp))
-    {
-      int i, next_is_type = 1;
-      for (i = args_start; i < def_args->nelements; i++)
-        {
-          if (!strcmp ("spaces", def_args->labels[i]))
-            {
-            }
-          else if (!strcmp ("delimiter", def_args->labels[i]))
-            {
-              next_is_type = 1;
-            }
-          else if (def_args->elements[i]->cmd
-                   && def_args->elements[i]->cmd != CM_code)
-            {
-              next_is_type = 1;
-            }
-          else if (next_is_type)
-            {
-              def_args->labels[i] = "typearg";
-              next_is_type = 0;
-            }
-          else
-            next_is_type = 1;
-        }
     }
-
-  destroy_element (arg_line);
-  return def_args;
+  return ret;
 }
-
-#endif

Modified: trunk/tp/Texinfo/XS/parsetexi/element_types.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/element_types.c       2018-09-01 15:39:26 UTC 
(rev 8140)
+++ trunk/tp/Texinfo/XS/parsetexi/element_types.c       2018-09-01 15:43:30 UTC 
(rev 8141)
@@ -57,6 +57,7 @@
 "row",
 "bracketed",
 "bracketed_def_content",
+"def_aggregate",
 "bracketed_inserted",
 "bracketed_multitable_prototype",
 "row_prototype",

Modified: trunk/tp/Texinfo/XS/parsetexi/element_types.h
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/element_types.h       2018-09-01 15:39:26 UTC 
(rev 8140)
+++ trunk/tp/Texinfo/XS/parsetexi/element_types.h       2018-09-01 15:43:30 UTC 
(rev 8141)
@@ -58,6 +58,7 @@
 ET_row,
 ET_bracketed,
 ET_bracketed_def_content,
+ET_def_aggregate,
 ET_bracketed_inserted,
 ET_bracketed_multitable_prototype,
 ET_row_prototype,

Modified: trunk/tp/Texinfo/XS/parsetexi/element_types.txt
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/element_types.txt     2018-09-01 15:39:26 UTC 
(rev 8140)
+++ trunk/tp/Texinfo/XS/parsetexi/element_types.txt     2018-09-01 15:43:30 UTC 
(rev 8141)
@@ -17,7 +17,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # Types for @-commands
-#def_line # duplicated below
 command_as_argument
 index_entry_command
 following_arg
@@ -82,6 +81,7 @@
 row
 bracketed
 bracketed_def_content
+def_aggregate
 bracketed_inserted
 bracketed_multitable_prototype
 row_prototype




reply via email to

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