texinfo-commits
[Top][All Lists]
Advanced

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

[8006] parsetexi update


From: gavinsmith0123
Subject: [8006] parsetexi update
Date: Mon, 4 Jun 2018 15:51:36 -0400 (EDT)

Revision: 8006
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=8006
Author:   gavin
Date:     2018-06-04 15:51:36 -0400 (Mon, 04 Jun 2018)
Log Message:
-----------
parsetexi update

Modified Paths:
--------------
    trunk/tp/parsetexi/close.c
    trunk/tp/parsetexi/convert.c
    trunk/tp/parsetexi/parser.c
    trunk/tp/parsetexi/separator.c

Modified: trunk/tp/parsetexi/close.c
===================================================================
--- trunk/tp/parsetexi/close.c  2018-06-04 11:03:46 UTC (rev 8005)
+++ trunk/tp/parsetexi/close.c  2018-06-04 19:51:36 UTC (rev 8006)
@@ -319,7 +319,15 @@
         {
         case ET_bracketed:
           command_error (current, "misplaced {");
+          if (current->contents.number > 0
+              && current->contents.list[0]->type
+                 == ET_empty_spaces_before_argument)
+            {
+              /* remove spaces element from tree and update extra values */
+              abort_empty_line (&current, 0);
+           }
           current = current->parent;
+
           break;
         case ET_menu_comment:
         case ET_menu_entry_description:

Modified: trunk/tp/parsetexi/convert.c
===================================================================
--- trunk/tp/parsetexi/convert.c        2018-06-04 11:03:46 UTC (rev 8005)
+++ trunk/tp/parsetexi/convert.c        2018-06-04 19:51:36 UTC (rev 8006)
@@ -58,6 +58,7 @@
 expand_cmd_args_to_texi (ELEMENT *e, TEXT *result)
 {
   enum command_id cmd = e->cmd;
+  KEY_PAIR *k;
 
   if (cmd)
     {
@@ -111,7 +112,13 @@
                 ADD(",");
               arg_nr++;
             }
+          k = lookup_extra_key (e->args.list[i], "spaces_before_argument");
+          if (k)
+            ADD((char *)k->value);
           convert_to_texinfo_internal (e->args.list[i], result);
+          k = lookup_extra_key (e->args.list[i], "spaces_after_argument");
+          if (k)
+            ADD((char *)k->value);
         }
 
       if (e->cmd == CM_verb)
@@ -139,8 +146,15 @@
           expand_cmd_args_to_texi (e, result);
         }
 
-      if (e->type == ET_bracketed)
-        ADD("{");
+      if (e->type == ET_bracketed
+          || e->type == ET_bracketed_def_content)
+        {
+          KEY_PAIR *k;
+          ADD("{");
+          k = lookup_extra_key (e, "spaces_before_argument");
+          if (k)
+            ADD((char *)k->value);
+        }
       if (e->contents.number > 0)
         {
           int i;

Modified: trunk/tp/parsetexi/parser.c
===================================================================
--- trunk/tp/parsetexi/parser.c 2018-06-04 11:03:46 UTC (rev 8005)
+++ trunk/tp/parsetexi/parser.c 2018-06-04 19:51:36 UTC (rev 8006)
@@ -398,7 +398,7 @@
 
 /* 2106 */
 int
-abort_empty_line (ELEMENT **current_inout, char *additional_text)
+abort_empty_line (ELEMENT **current_inout, char *additional_spaces)
 {
   ELEMENT *current = *current_inout;
   int retval;
@@ -405,8 +405,8 @@
 
   ELEMENT *last_child = last_contents_child (current);
 
-  if (!additional_text)
-    additional_text = "";
+  if (!additional_spaces)
+    additional_spaces = "";
 
   if (last_child
       && (last_child->type == ET_empty_line
@@ -414,61 +414,70 @@
           || last_child->type == ET_empty_spaces_before_argument
           || last_child->type == ET_empty_spaces_after_close_brace))
     {
+      ELEMENT *owning_element = 0, *e;
+      KEY_PAIR *owning_keypair = 0, *k;
+          
+      e = current;
+      if (current)
+        {
+          k = lookup_extra_key (current, "spaces_before_argument_elt");
+          if (k && k->value == last_contents_child (current))
+            goto owning_element_found;
+        }
+
+      e = current->parent;
+      if (current->parent)
+        {
+          k = lookup_extra_key (current->parent, 
+                                "spaces_before_argument_elt");
+          if (k && k->value == last_contents_child (current))
+            goto owning_element_found;
+        }
+
+      e = current;
+      if (current)
+        {
+          k = lookup_extra_key (current, "spaces_after_command");
+          if (k && k->value == last_contents_child (current))
+            goto owning_element_found;
+        }
+
+      e = current->parent;
+      if (current->parent)
+        {
+          k = lookup_extra_key (current->parent, "spaces_after_command");
+          if (k && k->value == last_contents_child (current))
+            goto owning_element_found;
+        }
+
+      if (0)
+        {
+owning_element_found:
+          owning_element = e;
+          owning_keypair = k;
+        }
+
       debug ("ABORT EMPTY %s additional text |%s| "
              "current |%s|",
              element_type_name(last_child),
-             additional_text,
+             additional_spaces,
              last_child->text.text);
-      text_append (&last_child->text, additional_text);
+      text_append (&last_child->text, additional_spaces);
 
       /* Remove element altogether if it's empty. */
       if (last_child->text.end == 0) //2121
         {
-          KEY_PAIR *k = 0; ELEMENT *e;
-          
-          /* Remove extra key from either from current or current->parent.  */
-          if (current)
-            k = lookup_extra_key (current, "spaces_before_argument");
-          if (k && k->value == last_contents_child (current))
-            {
-              k->key = "";
-              k->value = 0;
-              k->type = extra_deleted;
-            }
-          else if (current->parent)
-            {
-              k = lookup_extra_key (current->parent, "spaces_before_argument");
-              if (k && k->value == last_contents_child (current))
-                {
-                  k->key = "";
-                  k->value = 0;
-                  k->type = extra_deleted;
-                }
-            }
-
-          if (current)
-            k = lookup_extra_key (current, "spaces_after_command");
-          if (k && k->value == last_contents_child(current))
-            {
-              k->key = "";
-              k->value = 0;
-              k->type = extra_deleted;
-            }
-          else if (current->parent)
-            {
-              k = lookup_extra_key (current->parent, "spaces_after_command");
-              if (k && k->value == last_contents_child (current))
-                {
-                  k->key = "";
-                  k->value = 0;
-                  k->type = extra_deleted;
-                }
-            }
-
           e = pop_element_from_contents (current);
           e->parent = 0; e->parent_type = route_not_in_tree;
           destroy_element (e);
           /* TODO: Maybe we could avoid adding it in the first place? */
+
+          if (owning_keypair)
+            {
+              owning_keypair->key = "";
+              owning_keypair->value = 0;
+              owning_keypair->type = extra_deleted;
+            }
         }
       else if (last_child->type == ET_empty_line) //2132
         {
@@ -479,6 +488,23 @@
         {
           last_child->type = ET_empty_spaces_after_command;
         }
+      else if (last_child->type == ET_empty_spaces_before_argument)
+        {
+          /* Remove element from main tree. */
+          pop_element_from_contents (current);
+          /* FIXME: destroy_element? */
+          
+          if (owning_keypair)
+            {
+              /* Replace element reference with a simple string. */
+              add_extra_string (owning_element, "spaces_before_argument",
+                                owning_keypair->value->text.text);
+
+              owning_keypair->key = "";
+              owning_keypair->value = 0;
+              owning_keypair->type = extra_deleted;
+            }
+        }
       retval = 1;
     }
   else
@@ -504,6 +530,7 @@
 isolate_last_space (ELEMENT *current, enum element_type element_type)
 {
   ELEMENT *last = last_contents_child (current);
+  char *end_spaces;
 
   if (!element_type)
     element_type = ET_spaces_at_end;
@@ -541,7 +568,17 @@
                 {
                   /* If text all whitespace */
                   if (text[strspn (text, whitespace_chars)] == '\0')
-                    indexed_elt->type = element_type;
+                    {
+                      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 */
@@ -562,7 +599,16 @@
                       text[text_len - trailing_spaces] = '\0';
                       indexed_elt->text.end -= trailing_spaces;
 
-                      if (index == -1)
+                      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);
@@ -1215,6 +1261,8 @@
   else if (cmd)
     {
       enum command_id invalid_parent = 0;
+      int def_line_continuation;
+
       line = line_after_command;
       debug ("COMMAND %s", command_name(cmd));
 
@@ -1317,10 +1365,13 @@
              gettext is implemented */
         }
 
+      def_line_continuation = (current_context() == ct_def
+                               && cmd == CM_NEWLINE);
       /* warn on not appearing at line beginning 4226 */
       // begin line commands 315
       // TODO maybe have a command flag for this
-      if (!abort_empty_line (&current, NULL)
+      if (!def_line_continuation
+          && !abort_empty_line (&current, NULL)
           && ((cmd == CM_node || cmd == CM_bye)
               || (command_data(cmd).flags & CF_block)
               || ((command_data(cmd).flags & CF_misc)
@@ -1541,7 +1592,7 @@
         }
 
       /* 4274 */
-      if (current_context () == ct_def && cmd == CM_NEWLINE)
+      if (def_line_continuation)
         {
           retval = GET_A_NEW_LINE;
           goto funexit;
@@ -1760,6 +1811,15 @@
           int n;
           
           debug ("BEGIN LINE");
+
+          if (current->contents.number > 0
+              && last_contents_child(current)->type
+                 == ET_empty_spaces_before_argument)
+            {
+              /* Remove this element and update 'extra' values. */
+              abort_empty_line (&current, 0);
+            }
+
           e = new_element (ET_empty_line);
           add_to_element_contents (current, e);
 

Modified: trunk/tp/parsetexi/separator.c
===================================================================
--- trunk/tp/parsetexi/separator.c      2018-06-04 11:03:46 UTC (rev 8005)
+++ trunk/tp/parsetexi/separator.c      2018-06-04 19:51:36 UTC (rev 8006)
@@ -28,11 +28,8 @@
 // 3600
 /* Add the contents of CURRENT as an element to the extra value with
    key KEY, except that some "empty space" elements are removed.  Used for
-   'brace_command_contents' for the arguments to a brace command, and
    'block_command_line_contents' for the arguments to a block line command.
-
-   For a brace command $element, $element->{'args'} has pretty much the same 
-   information as $element->{'extra'}->{'brace_command_contents'}. */
+   */
 void
 register_command_arg (ELEMENT *current, char *key)
 {
@@ -166,7 +163,7 @@
             text_append_n (&e->text, line, n);
             add_to_element_contents (current, e);
             add_extra_element (current->parent,
-                                   "spaces_before_argument", e);
+                                   "spaces_before_argument_elt", e);
             line += n;
           }
           current->type = ET_brace_command_context;
@@ -178,9 +175,7 @@
           current->type = ET_brace_command_arg;
 
           /* Commands which are said to take a positive number of arguments
-             disregard leading and trailing whitespace.  In 
-             'handle_close_brace', the 'brace_command_contents' array
-             is set.  */
+             disregard leading and trailing whitespace. */
           if (command_data(command).data > 0)
             {
               ELEMENT *e;
@@ -188,8 +183,7 @@
               /* See comment in parser.c:merge_text */
               text_append (&e->text, "");
               add_to_element_contents (current, e);
-              add_extra_element (current->parent,
-                                     "spaces_before_argument", e);
+              add_extra_element (current, "spaces_before_argument_elt", e);
 
               if (command == CM_inlineraw)
                 push_context (ct_inlineraw);
@@ -216,7 +210,7 @@
       text_append (&e->text, ""); /* See comment in parser.c:merge_text */
       add_to_element_contents (current, e);
       debug ("BRACKETED in def/multitable");
-      add_extra_element (current, "spaces_before_argument", e);
+      add_extra_element (current, "spaces_before_argument_elt", e);
     }
   else if (current->type == ET_rawpreformatted)
     {
@@ -237,7 +231,15 @@
       debug ("BRACKETED in math");
     }
   else
-    line_error ("misplaced {");
+    {
+      line_error ("misplaced {");
+      if (current->contents.number > 0
+          && last_contents_child(current)->type
+               == ET_empty_spaces_before_argument)
+        {
+          remove_from_contents (current, 0);
+        }
+    }
 
   *line_inout = line;
   return current;
@@ -311,7 +313,6 @@
           /* @inline* always have end spaces considered as normal text */
           if (!(command_flags(current->parent) & CF_inline))
             isolate_last_space (current, 0);
-          register_command_arg (current, "brace_command_contents");
           remove_empty_content_arguments (current);
         }
 
@@ -339,24 +340,22 @@
         }
       else if (command_data(closed_command).flags & CF_ref) // 5062
         {
-          ELEMENT *ref = current->parent, *args;
+          ELEMENT *ref = current->parent;
           KEY_PAIR *k;
           if (ref->args.number > 0)
             {
-              k = lookup_extra_key (ref, "brace_command_contents");
-              args = k->value;
               if ((closed_command == CM_inforef
-                   && (args->contents.number <= 0
-                       || !args->contents.list[0])
-                   && (args->contents.number <= 2
-                       || !args->contents.list[2]))
+                   && (ref->args.number <= 0
+                       || ref->args.list[0]->contents.number == 0)
+                   && (ref->args.number <= 2
+                       || ref->args.list[2]->contents.number == 0))
                   || (closed_command != CM_inforef
-                       && (args->contents.number <= 0
-                           || !args->contents.list[0])
-                       && (args->contents.number <= 3
-                           || !args->contents.list[3])
-                       && (args->contents.number <= 4
-                           || !args->contents.list[4])))
+                       && (ref->args.number <= 0
+                           || ref->args.list[0]->contents.number == 0)
+                       && (ref->args.number <= 3
+                           || ref->args.list[3]->contents.number == 0)
+                       && (ref->args.number <= 4
+                           || ref->args.list[4]->contents.number == 0)))
                 {
                   line_warn ("command @%s missing a node or external manual "
                              "argument", command_name(closed_command));
@@ -370,11 +369,11 @@
                   else
                     free (nse);
                   if (closed_command != CM_inforef
-                      && (args->contents.number <= 3
-                          || args->contents.number <= 4
-                             && !contents_child_by_index(args, 3)
-                          || (!contents_child_by_index(args, 3)
-                               && !contents_child_by_index(args, 4)))
+                      && (ref->args.number <= 3
+                          || ref->args.number <= 4
+                             && ref->args.list[3]->contents.number == 0
+                          || (ref->args.list[3]->contents.number == 0
+                               && ref->args.list[4]->contents.number == 0))
                       && !nse->manual_content)
                     {
                       remember_internal_xref (ref);
@@ -381,31 +380,31 @@
                     }
                 }
 
-              if (args->contents.number > 1
-                  && args->contents.list[1])
+              if (ref->args.number > 1
+                  && ref->args.list[1]->contents.number > 0)
                 {
-                  if (check_empty_expansion (args->contents.list[1]))
+                  if (check_empty_expansion (ref->args.list[1]))
                     {
                       line_warn ("in @%s empty cross reference name "
                                  "after expansion `%s'",
                                  command_name(closed_command),
-                                 args->contents.list[1]
-                                 ? convert_to_texinfo (args->contents.list[1])
+                                 ref->args.list[1]
+                                 ? convert_to_texinfo (ref->args.list[1])
                                  : "");
                     }
                 }
 
               if (closed_command != CM_inforef
-                  && args->contents.number > 2
-                  && args->contents.list[2])
+                  && ref->args.number > 2
+                  && ref->args.list[2]->contents.number > 0)
                 {
-                  if (check_empty_expansion (args->contents.list[2]))
+                  if (check_empty_expansion (ref->args.list[2]))
                     {
                       line_warn ("in @%s empty cross reference title "
                                  "after expansion `%s'",
                                  command_name(closed_command),
-                                 args->contents.list[2]
-                                 ? convert_to_texinfo (args->contents.list[2])
+                                 ref->args.list[2]
+                                 ? convert_to_texinfo (ref->args.list[2])
                                  : "");
                     }
                 }
@@ -415,16 +414,9 @@
         {
           ELEMENT *image = current->parent;
           KEY_PAIR *k;
-          if (image->args.number == 0)
-            goto image_no_args;
-          k = lookup_extra_key (image, "brace_command_contents");
-          if (!k)
-            goto image_no_args;
-          if (!contents_child_by_index (k->value, 0))
-            goto image_no_args;
-          if (0)
+          if (image->args.number == 0
+              || image->args.list[0]->contents.number == 0)
             {
-          image_no_args:
               line_error ("@image missing filename argument");
             }
           if (global_info.input_perl_encoding)
@@ -447,7 +439,6 @@
                || closed_command == CM_abbr
                || closed_command == CM_acronym)
         { // 5129
-          KEY_PAIR *k;
           if (current->parent->cmd == CM_inlineraw)
             {
               if (ct_inlineraw != pop_context ())
@@ -454,10 +445,7 @@
                 abort ();
             }
           if (current->parent->args.number == 0
-              || !(k = lookup_extra_key (current->parent, 
-                                         "brace_command_contents"))
-              || !k->value || k->value->contents.number == 0
-              || !k->value->contents.list[0])
+              || current->parent->args.list[0]->contents.number == 0)
             {
               line_warn ("@%s missing first argument",
                          command_name(current->parent->cmd));
@@ -641,8 +629,7 @@
 }
 
 // 2577
-/* Remove 'brace_command_contents' or 'block_command_line_contents'
-   extra value if empty.
+/* Remove 'block_command_line_contents' extra value if empty.
    TODO: If not empty, remove empty elements thereof. */
 void
 remove_empty_content_arguments (ELEMENT *current)
@@ -651,8 +638,6 @@
 
   k = lookup_extra_key (current, "block_command_line_contents");
   if (!k)
-    k = lookup_extra_key (current, "brace_command_contents");
-  if (!k)
     return;
 
   while (k->value->contents.number > 0
@@ -678,14 +663,11 @@
 
   abort_empty_line (&current, NULL);
 
-  /* Register brace_command_contents or block_command_line_contents in extra 
-     key. */
   if (command_flags(current->parent) & CF_brace
       && command_data(current->parent->cmd).data > 0)
     {
       // 5033
       isolate_last_space (current, 0);
-      register_command_arg (current, "brace_command_contents");
       remove_empty_content_arguments (current);
     }
   else
@@ -709,21 +691,23 @@
       k = lookup_extra_key (current, "format");
       if (!k)
         {
-          KEY_PAIR *k;
           char *inline_type = 0;
-          k = lookup_extra_key (current, "brace_command_contents");
-          if (k)
+          if (current->args.number > 0
+              && current->args.list[0]->contents.number > 0)
             {
               ELEMENT *args = 0, *arg = 0;
               int i;
-              args = (ELEMENT *) k->value;
+              args = current->args.list[0];
+              /*
               if (!args)
                 goto inline_no_arg;
               if (args->contents.number == 0)
                 goto inline_no_arg;
+              */
               arg = args->contents.list[0];
               if (!arg)
                 goto inline_no_arg; /* Possible if registered as 'undef'. */
+
               /* Find text argument.
                  TODO: Should we use trim_spaces_comment_from_content instead?
                  Or use a function for this? */
@@ -791,7 +775,6 @@
               /* Add a dummy argument for the first argument. */
               e = new_element (ET_elided);
               add_to_element_args (current, e);
-              register_command_arg (e, "brace_command_contents");
 
               /* Scan forward to get the next argument. */
               while (brace_count > 0)
@@ -882,6 +865,7 @@
   e = new_element (ET_empty_spaces_before_argument);
   text_append (&e->text, ""); /* See comment in parser.c:merge_text */
   add_to_element_contents (current, e);
+  add_extra_element (current, "spaces_before_argument_elt", e);
   
 funexit:
   *line_inout = line;




reply via email to

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