texinfo-commits
[Top][All Lists]
Advanced

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

[8181] parsetexi update


From: gavinsmith0123
Subject: [8181] parsetexi update
Date: Wed, 19 Sep 2018 15:43:06 -0400 (EDT)

Revision: 8181
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=8181
Author:   gavin
Date:     2018-09-19 15:43:06 -0400 (Wed, 19 Sep 2018)
Log Message:
-----------
parsetexi update

Modified Paths:
--------------
    trunk/tp/Texinfo/XS/parsetexi/def.c
    trunk/tp/Texinfo/XS/parsetexi/end_line.c
    trunk/tp/Texinfo/XS/parsetexi/menus.c
    trunk/tp/Texinfo/XS/parsetexi/parser.c
    trunk/tp/Texinfo/XS/parsetexi/parser.h
    trunk/tp/Texinfo/XS/parsetexi/separator.c

Modified: trunk/tp/Texinfo/XS/parsetexi/def.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/def.c 2018-09-16 10:19:41 UTC (rev 8180)
+++ trunk/tp/Texinfo/XS/parsetexi/def.c 2018-09-19 19:43:06 UTC (rev 8181)
@@ -227,7 +227,7 @@
       int len;
       if (e->type == ET_bracketed)
         {
-          isolate_last_space (e, 0);
+          isolate_last_space (e);
           e->type = ET_bracketed_def_content;
           continue;
         }

Modified: trunk/tp/Texinfo/XS/parsetexi/end_line.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/end_line.c    2018-09-16 10:19:41 UTC (rev 
8180)
+++ trunk/tp/Texinfo/XS/parsetexi/end_line.c    2018-09-19 19:43:06 UTC (rev 
8181)
@@ -1132,8 +1132,7 @@
     }
   else
     {
-      isolate_last_space (current, ET_space_at_end_block_command); // 2939
-      register_command_arg (current, "block_command_line_contents");
+      isolate_last_space (current); // 2939
     }
 
   if (current->parent->cmd == CM_float) // 2943
@@ -1189,7 +1188,6 @@
       insert_into_contents (current, e, 0);
       destroy_element (pop_element_from_args (current));
     }
-  remove_empty_content_arguments (current);
 
   if (command_flags(current) & CF_blockitem) // 2981
     {
@@ -1396,7 +1394,7 @@
   enum command_id end_id;
   int included_file = 0;
 
-  isolate_last_space (current, 0);
+  isolate_last_space (current);
 
   current = current->parent;
   misc_cmd = current;

Modified: trunk/tp/Texinfo/XS/parsetexi/menus.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/menus.c       2018-09-16 10:19:41 UTC (rev 
8180)
+++ trunk/tp/Texinfo/XS/parsetexi/menus.c       2018-09-19 19:43:06 UTC (rev 
8181)
@@ -46,7 +46,7 @@
         {
           NODE_SPEC_EXTRA *parsed_entry_node;
 
-          isolate_last_space (arg, ET_space_at_end_menu_node);
+          isolate_last_space (arg);
 
           parsed_entry_node = parse_node_manual (arg);
           if (!parsed_entry_node)

Modified: trunk/tp/Texinfo/XS/parsetexi/parser.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/parser.c      2018-09-16 10:19:41 UTC (rev 
8180)
+++ trunk/tp/Texinfo/XS/parsetexi/parser.c      2018-09-19 19:43:06 UTC (rev 
8181)
@@ -521,111 +521,121 @@
   return retval;
 }
 
-/* 2149 */
-/* Split any trailing whitespace on the last contents child of CURRENT into
-   its own element, ET_spaces_at_end by default.
-  
-   This is used for the argument to a line command, and for the arguments to a 
-   brace command taking a given number of arguments.
+static void
+isolate_last_space_internal (ELEMENT *current)
+{
+  ELEMENT *last_elt;
 
-   This helps with argument parsing as there will be no leading or trailing 
-   spaces.
+  last_elt = last_contents_child (current);
+  char *text = element_text (last_elt);
+  if (!text || !*text)
+    return;
 
-   Also, "to help expansion disregard unuseful spaces".  Could that mean
-   macro expansion? */
-void
-isolate_last_space (ELEMENT *current, enum element_type element_type)
+  int text_len = strlen (text);
+  /* Does the text end in whitespace? */
+  if (strchr (whitespace_chars, text[text_len - 1]))
+    {
+      /* If text all whitespace */
+      if (text[strspn (text, whitespace_chars)] == '\0')
+        {
+          add_extra_string_dup (current, "spaces_after_argument",
+                                last_elt->text.text);
+          pop_element_from_contents (current);
+          /* FIXME: destroy_element? */
+        }
+      else
+        {
+          int i, trailing_spaces;
+          static TEXT t;
+
+          text_reset (&t);
+
+          trailing_spaces = 0;
+          for (i = strlen (text) - 1;
+               i > 0 && strchr (whitespace_chars, text[i]);
+               i--)
+            trailing_spaces++;
+
+          text_append_n (&t,
+                         text + text_len - trailing_spaces,
+                         trailing_spaces);
+
+          text[text_len - trailing_spaces] = '\0';
+          last_elt->text.end -= trailing_spaces;
+
+          add_extra_string_dup (current, "spaces_after_argument",
+                                t.text);
+        }
+    }
+}
+
+static void
+isolate_last_space_menu_entry_node (ELEMENT *current)
 {
-  ELEMENT *last = last_contents_child (current);
-  char *end_spaces;
+  ELEMENT *last_elt;
+  char *text;
+  int text_len;
 
-  if (!element_type)
-    element_type = ET_spaces_at_end;
+  last_elt = last_contents_child (current);
+  text = element_text (last_elt);
+  if (!text || !*text)
+    return;
 
-  if (last)
+  text_len = strlen (text);
+  /* Does the text end in whitespace? */
+  if (strchr (whitespace_chars, text[text_len - 1]))
     {
-      int index = -1;
-      ELEMENT *indexed_elt;
-
-      /* If a "misc" (i.e. line) command is last on line, isolate the space in 
-         the element before it.  This covers the case of a "@c" at the end
-         of a line. */
-      if (element_contents_number (current) > 1)
+      /* If text all whitespace */
+      if (text[strspn (text, whitespace_chars)] == '\0')
         {
-          if (last->cmd)
-            {
-              if (command_flags(last) & CF_misc)
-                index = -2;
-            }
+          last_elt->type = ET_space_at_end_menu_node;
         }
-
-      indexed_elt = contents_child_by_index (current, index);
-      if (indexed_elt)
+      else
         {
-          char *text = element_text (indexed_elt);
-          if (!text || !*text)
-            return;
+          ELEMENT *new_spaces;
+          int i, trailing_spaces;
 
-          if (indexed_elt->type == ET_NONE)
-            {
-              int text_len = strlen (text);
-              /* 2170 */
-              /* Does the text end in whitespace? */
-              if (strchr (whitespace_chars, text[text_len - 1]))
-                {
-                  /* If text all whitespace */
-                  if (text[strspn (text, whitespace_chars)] == '\0')
-                    {
-                      if (index == -1 && current->type == ET_brace_command_arg)
-                        {
-                          add_extra_string (current, "spaces_after_argument",
-                                            strdup (indexed_elt->text.text));
-                          pop_element_from_contents (current);
-                          /* FIXME: destroy_element? */
-                        }
-                      else
-                        indexed_elt->type = element_type;
-                    }
-                  else
-                    {
-                      /* 2173 */
-                      ELEMENT *new_spaces;
-                      int i, trailing_spaces;
+          trailing_spaces = 0;
+          for (i = strlen (text) - 1;
+               i > 0 && strchr (whitespace_chars, text[i]);
+               i--)
+            trailing_spaces++;
 
-                      /* "strrcspn" */
-                      trailing_spaces = 0;
-                      for (i = strlen (text) - 1;
-                           i > 0 && strchr (whitespace_chars, text[i]);
-                           i--)
-                        trailing_spaces++;
-                      
-                      new_spaces = new_element (element_type);
-                      text_append_n (&new_spaces->text,
-                                     text + text_len - trailing_spaces,
-                                     trailing_spaces);
-                      text[text_len - trailing_spaces] = '\0';
-                      indexed_elt->text.end -= trailing_spaces;
+          new_spaces = new_element (ET_space_at_end_menu_node);
+          text_append_n (&new_spaces->text,
+                         text + text_len - trailing_spaces,
+                         trailing_spaces);
+          text[text_len - trailing_spaces] = '\0';
+          last_elt->text.end -= trailing_spaces;
 
-                      if (index == -1
-                          && current->type == ET_brace_command_arg)
-                        {
-                          add_extra_string (current, "spaces_after_argument",
-                                            new_spaces->text.text);
-                          new_spaces->text.end = 0;
-                          new_spaces->text.text = 0;
-                          destroy_element (new_spaces);
-                        }
-                      else if (index == -1)
-                        add_to_element_contents (current, new_spaces);
-                      else
-                        insert_into_contents (current, new_spaces, -1);
-                    }
-                }
-            }
+          add_to_element_contents (current, new_spaces);
         }
     }
 }
 
+void
+isolate_last_space (ELEMENT *current)
+{
+  if (current->contents.number == 0)
+    return;
+
+  if (last_contents_child(current)->cmd == CM_c
+      || last_contents_child(current)->cmd == CM_comment)
+    {
+      add_extra_element_oot (current->parent, "spaces_after_argument",
+                             pop_element_from_contents (current));
+    }
+
+  if (current->contents.number == 0)
+    return;
+
+  if (current->type == ET_menu_entry_node)
+    isolate_last_space_menu_entry_node (current);
+  else
+    isolate_last_space_internal (current);
+}
+
+
 // 5467, also in Common.pm 1334
 /* Return a new element whose contents are the same as those of ORIGINAL,
    but with some elements representing empty spaces removed.  Elements like 

Modified: trunk/tp/Texinfo/XS/parsetexi/parser.h
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/parser.h      2018-09-16 10:19:41 UTC (rev 
8180)
+++ trunk/tp/Texinfo/XS/parsetexi/parser.h      2018-09-19 19:43:06 UTC (rev 
8181)
@@ -43,10 +43,8 @@
 extern int debug_output;
 
 /* In separator.c */
-void register_command_arg (ELEMENT *current, char *key);
 ELEMENT *handle_separator (ELEMENT *current, char separator,
                            char **line_inout);
-void remove_empty_content_arguments (ELEMENT *current);
 
 /* In parser.c */
 ELEMENT *parse_texi (ELEMENT *root_elt);
@@ -58,7 +56,7 @@
 ELEMENT *end_paragraph (ELEMENT *current,
                         enum command_id closed_command,
                         enum command_id interrupting_command);
-void isolate_last_space (ELEMENT *current, enum element_type type);
+void isolate_last_space (ELEMENT *current);
 int command_with_command_as_argument (ELEMENT *current);
 void mark_and_warn_invalid (enum command_id command,
                             enum command_id invalid_parent,

Modified: trunk/tp/Texinfo/XS/parsetexi/separator.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/separator.c   2018-09-16 10:19:41 UTC (rev 
8180)
+++ trunk/tp/Texinfo/XS/parsetexi/separator.c   2018-09-19 19:43:06 UTC (rev 
8181)
@@ -319,8 +319,7 @@
           // 5033
           /* @inline* always have end spaces considered as normal text */
           if (!(command_flags(current->parent) & CF_inline))
-            isolate_last_space (current, 0);
-          remove_empty_content_arguments (current);
+            isolate_last_space (current);
         }
 
       closed_command = current->parent->cmd;
@@ -641,43 +640,7 @@
   return current;
 }
 
-// 2577
-/* Remove 'block_command_line_contents' extra value if empty.
-   TODO: If not empty, remove empty elements thereof. */
-void
-remove_empty_content_arguments (ELEMENT *current)
-{
-  KEY_PAIR *k;
 
-  k = lookup_extra (current, "block_command_line_contents");
-  if (!k)
-    return;
-
-  while (k->value->contents.number > 0
-         && !last_contents_child(k->value)) // ->contents.number == 0)
-    {
-      ELEMENT *array = pop_element_from_contents (k->value);
-      if (array)
-        {
-          int j;
-          for (j = 0 ; j < array->contents.number; j++)
-            {
-              if (array->contents.list[j])
-                destroy_element (array->contents.list[j]);
-            }
-          destroy_element (array);
-        }
-    }
-
-  if (k->value->contents.number == 0)
-    {
-      destroy_element (k->value);
-      k->key = "";
-      k->type = extra_deleted;
-    }
-}
-
-
 /* Handle a comma separating arguments to a Texinfo command. */
 /* 5228 */
 ELEMENT *
@@ -688,23 +651,8 @@
   ELEMENT *new_arg, *e;
 
   abort_empty_line (&current, NULL);
+  isolate_last_space (current);
 
-  if (command_flags(current->parent) & CF_brace
-      && command_data(current->parent->cmd).data > 0)
-    {
-      // 5033
-      isolate_last_space (current, 0);
-      remove_empty_content_arguments (current);
-    }
-  else
-    {
-      isolate_last_space (current, 0);
-      if (command_flags(current->parent) & CF_block)
-        {
-          register_command_arg (current, "block_command_line_contents");
-        }
-    }
-
   type = current->type;
   current = current->parent;
 




reply via email to

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