texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sat, 28 Sep 2024 13:02:16 -0400 (EDT)

branch: master
commit 799c75cfc2ea3d5a214cf63e32dc34149573116d
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu May 30 08:14:35 2024 +0200

    * tp/Texinfo/ParserNonXS.pm (%parser_document_state_initialization)
    (_abort_empty_line, _start_empty_line_after_command, _handle_macro)
    (_handle_open_brace, _handle_comma): instead of putting the command
    associated to internal spaces in the extra information of the space,
    put it in the state as internal_space_holder.  Add the parser as
    _start_empty_line_after_command argument, update callers.
    Also reuse the internal space as the info spaces_before_argument
    of the command associated with the internal space in _abort_empty_line.
    
    * tp/Texinfo/ParserNonXS.pm (_isolate_last_space),
    tp/Texinfo/XS/parsetexi/parser.c (isolate_last_space): always isolate the
    last space independentely of its type and type of the current
    container.
    
    * tp/Texinfo/ParserNonXS.pm (_isolate_last_space),
    tp/Texinfo/XS/parsetexi/parser.c (isolate_last_space_internal): reuse
    the internal space as the info spaces_after_argument.
    
    * tp/Texinfo/XS/parsetexi/parser.c (begin_paragraph, merge_text):
    return 0 if the paragraph was not started.  Shortcut the code merging
    text if a paragraph was started in merge_text.
    
    * tp/Texinfo/XS/main/build_perl_info.c (element_to_perl_hash),
    tp/Texinfo/XS/main/element_types.txt,
    tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators),
    tp/Texinfo/XS/parsetexi/parser.c (merge_text, abort_empty_line),
    tp/Texinfo/XS/parsetexi/separator.c (handle_open_brace),
    tp/Texinfo/XS/parsetexi/source_marks.c (place_source_mark): add a text
    type, normal_text, used internally in XS parser for regular text,
    instead of using ET_NONE.
    
    * tp/Texinfo/XS/parsetexi/parser.c (isolate_last_space_internal): do
    not use an intermediate TEXT, directly set the new element text.  Add
    last_elt as argument to isolate_last_space_internal.
---
 ChangeLog                              | 56 ++++++++++++++++++++
 tp/Texinfo/ParserNonXS.pm              | 81 ++++++++++++++++-------------
 tp/Texinfo/XS/main/build_perl_info.c   |  2 +-
 tp/Texinfo/XS/main/element_types.c     |  1 +
 tp/Texinfo/XS/main/element_types.h     |  1 +
 tp/Texinfo/XS/main/element_types.txt   |  1 +
 tp/Texinfo/XS/parsetexi/menus.c        |  2 +-
 tp/Texinfo/XS/parsetexi/parser.c       | 93 ++++++++++++++++++----------------
 tp/Texinfo/XS/parsetexi/parser.h       |  1 -
 tp/Texinfo/XS/parsetexi/separator.c    |  2 +-
 tp/Texinfo/XS/parsetexi/source_marks.c |  4 +-
 11 files changed, 161 insertions(+), 83 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 35b3d66adc..1c1f66c862 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+2024-05-30  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (%parser_document_state_initialization)
+       (_abort_empty_line, _start_empty_line_after_command, _handle_macro)
+       (_handle_open_brace, _handle_comma): instead of putting the command
+       associated to internal spaces in the extra information of the space,
+       put it in the state as internal_space_holder.  Add the parser as
+       _start_empty_line_after_command argument, update callers.
+       Also reuse the internal space as the info spaces_before_argument
+       of the command associated with the internal space in _abort_empty_line.
+
+       * tp/Texinfo/ParserNonXS.pm (_isolate_last_space),
+       tp/Texinfo/XS/parsetexi/parser.c (isolate_last_space): always isolate 
the
+       last space independentely of its type and type of the current
+       container.
+
+       * tp/Texinfo/ParserNonXS.pm (_isolate_last_space),
+       tp/Texinfo/XS/parsetexi/parser.c (isolate_last_space_internal): reuse
+       the internal space as the info spaces_after_argument.
+
+       * tp/Texinfo/XS/parsetexi/parser.c (begin_paragraph, merge_text):
+       return 0 if the paragraph was not started.  Shortcut the code merging
+       text if a paragraph was started in merge_text.
+
+       * tp/Texinfo/XS/main/build_perl_info.c (element_to_perl_hash),
+       tp/Texinfo/XS/main/element_types.txt,
+       tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators),
+       tp/Texinfo/XS/parsetexi/parser.c (merge_text, abort_empty_line),
+       tp/Texinfo/XS/parsetexi/separator.c (handle_open_brace),
+       tp/Texinfo/XS/parsetexi/source_marks.c (place_source_mark): add a text
+       type, normal_text, used internally in XS parser for regular text,
+       instead of using ET_NONE.
+
+       * tp/Texinfo/XS/parsetexi/parser.c (isolate_last_space_internal): do
+       not use an intermediate TEXT, directly set the new element text.  Add
+       last_elt as argument to isolate_last_space_internal.
+
 2024-09-28  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/get_converter_perl_info.c: add missing
@@ -852,6 +889,7 @@
        is likely stopping IFS from being reset correctly, leading
        to subsequent errors.
 
+
 2024-08-21  Patrice Dumas  <pertusus@free.fr>
 
        * doc/texinfo.texi: modify, reassociate and comment out
@@ -948,6 +986,7 @@
        * autogen.sh: Run autoreconf under tp/Texinfo/XS/ with
        AUTOPOINT=true.  From Bruno.
 
+
 2024-08-10  Patrice Dumas  <pertusus@free.fr>
 
        Update man/pod2texi.1, po*/*.po and gnulib generated gperf files
@@ -1095,6 +1134,23 @@
        version as the top-level configure.ac. Add comments about use
        of autopoint.
 
+2024-08-04  Gavin Smith <gavinsmith0123@gmail.com>
+
+       * README-hacking: Remove out-of-date information about running
+       "make" before "make dist".
+
+2024-08-04  Patrice Dumas  <pertusus@free.fr>
+
+       * doc/tp_api/Makefile.am (tp/Texinfo/ModulePath.pm):
+       Add rule to allow running "make dist" without running "make"
+       first.  Report from Bruno Haible.
+
+2024-08-04  Patrice Dumas  <pertusus@free.fr>
+
+       * info/Makefile.am (../gnulib/lib/libgnu.a):
+       Add rule to allow running "make dist" without running "make"
+       first.  Report from Bruno Haible.
+
 2024-07-27  Patrice Dumas  <pertusus@free.fr>
 
        * t/init_files_tests.t
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index a6bfab8014..487cb4016d 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -161,6 +161,21 @@ my %parser_document_state_initialization = (
   'current_node'    => undef,     # last seen node.
   'current_section' => undef,     # last seen section.
   'current_part'    => undef,     # last seen part.
+  'internal_space_holder' => undef,
+   # the element associated with the last internal spaces element added.
+   # We know that there can only be one at a time as a non space
+   # character should always lead to abort_empty_line or another
+   # function being called and the internal space element being
+   # removed or put in the internal_space_holder info.
+
+   # NOTE internal_space_holder is already unset in abort_empty_line
+   # if the internal space element is put in the internal_space_holder.
+   # It would be cleaner to unset internal_space_holder in all the
+   # cases where the internal space element is removed too, such that
+   # when internal_space_holder is set the previous value is undef and not
+   # the previous internal_space_holder, which is now irrelevant as
+   # its associated space has disappeared.
+
   'sections_level_modifier' => 0, # modified by raise/lowersections
 
   'input_file_encoding' => 'utf-8', # perl encoding name used for the input
@@ -2262,15 +2277,19 @@ sub _merge_text {
     }
 
     $paragraph = _begin_paragraph($self, $current);
-    $current = $paragraph if ($paragraph);
+    if ($paragraph) {
+      $current = $paragraph;
+    }
   }
 
   if (!defined($current->{'contents'})) {
-    # this can happen at least for preformatted.
+    # this can happen at least for preformatted, with a new
+    # paragraph and if the first text element was removed in _abort_empty_line.
     $current->{'contents'} = [];
   }
 
-  if (!$no_merge_with_following_text
+  if (!$paragraph
+      and !$no_merge_with_following_text
       and scalar(@{$current->{'contents'}})
       and exists($current->{'contents'}->[-1]->{'text'})
       and $current->{'contents'}->[-1]->{'text'} !~ /\n/) {
@@ -3008,15 +3027,14 @@ sub _abort_empty_line {
              or $spaces_element->{'type'} eq 
'internal_spaces_before_argument') {
       # Remove element from main tree. It will still be referenced in
       # the 'info' hash as 'spaces_before_argument'.
-      _pop_element_from_contents($self, $current);
-      my $owning_element
-        = $spaces_element->{'extra'}->{'spaces_associated_command'};
-      #$owning_element->{'info'} = {} if (! $owning_element->{'info'});
-      my $new_space_element = {'text' => $spaces_element->{'text'},};
-      _transfer_source_marks($spaces_element, $new_space_element);
+      my $spaces_before_argument = _pop_element_from_contents($self, $current);
+      delete $spaces_before_argument->{'type'};
+      delete $spaces_before_argument->{'parent'};
+      my $owning_element = $self->{'internal_space_holder'};
       $owning_element->{'info'} = {} if (!exists($owning_element->{'info'}));
       $owning_element->{'info'}->{'spaces_before_argument'}
-        = $new_space_element;
+        = $spaces_before_argument;
+      $self->{'internal_space_holder'} = undef;
     }
 
     return 1;
@@ -3074,13 +3092,9 @@ sub _isolate_last_space
   }
 
   if (!$current->{'contents'}
-            or !scalar(@{$current->{'contents'}})
-            or !defined($current->{'contents'}->[-1]->{'text'})
-            or ($current->{'contents'}->[-1]->{'type'}
-                  and (!$current->{'type'}
-                        or ($current->{'type'} ne 'line_arg'
-                            and $current->{'type'} ne 'block_line_arg')))
-            or $current->{'contents'}->[-1]->{'text'} !~ /\s+$/) {
+      or !scalar(@{$current->{'contents'}})
+      or !defined($current->{'contents'}->[-1]->{'text'})
+      or $current->{'contents'}->[-1]->{'text'} !~ /\s+$/) {
     print STDERR "NOT ISOLATING $debug_str\n"
        if ($self->{'conf'}->{'DEBUG'});
     return;
@@ -3098,11 +3112,11 @@ sub _isolate_last_space
     #$current->{'info'} = {} if (!$current->{'info'});
     if ($last_element->{'text'} !~ /\S/) {
       my $spaces_after_argument = _pop_element_from_contents($self, $current);
-      my $new_space_element = {'text' => $spaces_after_argument->{'text'},};
-      _transfer_source_marks($spaces_after_argument, $new_space_element);
+      delete $spaces_after_argument->{'parent'};
+      delete $spaces_after_argument->{'type'};
       $current->{'info'} = {} if (!exists($current->{'info'}));
       $current->{'info'}->{'spaces_after_argument'}
-                 = $new_space_element;
+                 = $spaces_after_argument;
     } else {
       $last_element->{'text'} =~ s/(\s+)$//;
       my $new_space_element = {'text' => $1,};
@@ -4661,8 +4675,8 @@ sub _end_line($$$)
 
 # $command may be undef if we are after a wrong other command such as
 # a buggy @tab.
-sub _start_empty_line_after_command($$$) {
-  my ($line, $current, $command) = @_;
+sub _start_empty_line_after_command($$$$) {
+  my ($self, $line, $current, $command) = @_;
 
   # based on whitespace_chars_except_newline in XS parser
   $line =~ s/^([ \t\cK\f]*)//;
@@ -4672,9 +4686,8 @@ sub _start_empty_line_after_command($$$) {
                              };
   push @{$current->{'contents'}}, $spaces_after_command;
   if (defined($command)) {
-    $spaces_after_command->{'extra'}
-      = {'spaces_associated_command' => $command};
     $spaces_after_command->{'type'} = 'internal_spaces_after_command';
+    $self->{'internal_space_holder'} = $command;
   }
   return $line;
 }
@@ -5138,9 +5151,8 @@ sub _handle_macro($$$$$)
           if (not $arg_elt->{'contents'} and $line =~ s/^([ \t\cK\f]+)//) {
             my $internal_space = {'type' => 'internal_spaces_before_argument',
                                   'text' => $1,
-                                  'parent' => $arg_elt,
-                                  'extra' => {'spaces_associated_command'
-                                                => $macro_call_element}};
+                                  'parent' => $arg_elt};
+            $self->{'internal_space_holder'} = $macro_call_element;
             push @{$arg_elt->{'contents'}}, $internal_space;
           } else {
             if ($line !~ /\n/) {
@@ -5534,7 +5546,7 @@ sub _handle_other_command($$$$$)
                           $source_info);
       }
     }
-    $line = _start_empty_line_after_command($line, $current, undef);
+    $line = _start_empty_line_after_command($self, $line, $current, undef);
   }
   return ($current, $line, $retval, $command_e);
 }
@@ -5874,7 +5886,7 @@ sub _handle_line_command($$$$$$)
     $current = $current->{'args'}->[-1];
     $self->_push_context('ct_line', $command)
       unless ($def_commands{$data_cmdname});
-    $line = _start_empty_line_after_command($line, $current, $command_e);
+    $line = _start_empty_line_after_command($self, $line, $current, 
$command_e);
   }
   _register_global_command($self, $command_e, $source_info)
     if $command_e;
@@ -6042,7 +6054,7 @@ sub _handle_block_command($$$$$)
     }
     $block->{'source_info'} = {%$source_info};
     _register_global_command($self, $block, $source_info);
-    $line = _start_empty_line_after_command($line, $current, $block);
+    $line = _start_empty_line_after_command($self, $line, $current, $block);
   }
   return ($current, $line, $retval, $block);
 }
@@ -6185,8 +6197,8 @@ sub _handle_open_brace($$$$)
         'type' => 'internal_spaces_before_argument',
         'text' => $1,
         'parent' => $current,
-        'extra' => {'spaces_associated_command' => $current->{'parent'}}
       };
+      $self->{'internal_space_holder'} = $current->{'parent'};
     } else {
       $current->{'type'} = 'brace_command_arg';
       # Commands that disregard leading whitespace.
@@ -6199,8 +6211,8 @@ sub _handle_open_brace($$$$)
                     'type' => 'internal_spaces_before_argument',
                     'text' => '',
                     'parent' => $current,
-                    'extra' => {'spaces_associated_command' => $current}
                   };
+        $self->{'internal_space_holder'} = $current;
       }
       $self->_push_context('ct_inlineraw', $command)
         if ($command eq 'inlineraw');
@@ -6229,8 +6241,9 @@ sub _handle_open_brace($$$$)
         {'type' => 'internal_spaces_before_argument',
          'text' => '',
          'parent' => $current,
-         'extra' => {'spaces_associated_command' => $current}
        };
+    $self->{'internal_space_holder'} = $current;
+
     print STDERR "BRACKETED in def/multitable\n"
                              if ($self->{'conf'}->{'DEBUG'});
   # lone braces accepted right in a rawpreformatted
@@ -6706,8 +6719,8 @@ sub _handle_comma($$$$)
   # which should end up in info spaces_before_argument.
   my $space_before = {'type' => 'internal_spaces_before_argument',
                       'text' => '', 'parent' => $current,
-                      'extra' => {'spaces_associated_command' => $current}
                      };
+  $self->{'internal_space_holder'} = $current;
   push @{$current->{'contents'}}, $space_before;
 
   return ($current, $line, $source_info);
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 871fb53c1b..d3708de57b 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -609,7 +609,7 @@ element_to_perl_hash (ELEMENT *e, int avoid_recursion)
       hv_store (e->hv, "parent", strlen ("parent"), sv, HSH_parent);
     }
 
-  if (e->type)
+  if (e->type && e->type != ET_normal_text)
     {
       sv = newSVpv (element_type_names[e->type], 0);
       hv_store (e->hv, "type", strlen ("type"), sv, HSH_type);
diff --git a/tp/Texinfo/XS/main/element_types.c 
b/tp/Texinfo/XS/main/element_types.c
index d4dd08f109..0cbaeb3862 100644
--- a/tp/Texinfo/XS/main/element_types.c
+++ b/tp/Texinfo/XS/main/element_types.c
@@ -16,6 +16,7 @@ char *element_type_names[] = {
 "space_at_end_menu_node",
 "after_menu_description_line",
 "spaces_after_cmd_before_arg",
+"normal_text",
 "document_root",
 "root_line",
 "before_node_section",
diff --git a/tp/Texinfo/XS/main/element_types.h 
b/tp/Texinfo/XS/main/element_types.h
index fd6df90130..bb5893e03b 100644
--- a/tp/Texinfo/XS/main/element_types.h
+++ b/tp/Texinfo/XS/main/element_types.h
@@ -19,6 +19,7 @@ ET_text_before_beginning,
 ET_space_at_end_menu_node,
 ET_after_menu_description_line,
 ET_spaces_after_cmd_before_arg,
+ET_normal_text,
 ET_document_root,
 ET_root_line,
 ET_before_node_section,
diff --git a/tp/Texinfo/XS/main/element_types.txt 
b/tp/Texinfo/XS/main/element_types.txt
index fd3f6a7781..dcd4fd506b 100644
--- a/tp/Texinfo/XS/main/element_types.txt
+++ b/tp/Texinfo/XS/main/element_types.txt
@@ -34,6 +34,7 @@ text_before_beginning
 space_at_end_menu_node
 after_menu_description_line
 spaces_after_cmd_before_arg
+normal_text
 
 # Other special types
 document_root
diff --git a/tp/Texinfo/XS/parsetexi/menus.c b/tp/Texinfo/XS/parsetexi/menus.c
index c1a3fab496..27263eca8b 100644
--- a/tp/Texinfo/XS/parsetexi/menus.c
+++ b/tp/Texinfo/XS/parsetexi/menus.c
@@ -197,7 +197,7 @@ handle_menu_entry_separators (ELEMENT **current_inout, 
const char **line_inout)
       debug_nonl ("ABORT MENU STAR before: ");
       debug_print_protected_string (line); debug ("");
 
-      last_contents_child (current)->type = ET_NONE;
+      last_contents_child (current)->type = ET_normal_text;
     }
   /* After a separator in a menu, end of menu entry node or menu entry name
    (. must be followed by a space to stop the node). */
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 07b472a1e8..4168eb7915 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -549,7 +549,7 @@ parse_texi_document (void)
 }
 
 
-int
+static int
 begin_paragraph_p (ELEMENT *current)
 {
   return (current->type == ET_NONE /* "True for @-commands" */
@@ -561,8 +561,8 @@ begin_paragraph_p (ELEMENT *current)
 }
 
 /* If in a context where paragraphs are to be started, start a new
-   paragraph. */
-ELEMENT *
+   paragraph and return it.  Else return 0 */
+static ELEMENT *
 begin_paragraph (ELEMENT *current)
 {
   if (begin_paragraph_p (current))
@@ -591,7 +591,6 @@ begin_paragraph (ELEMENT *current)
                 }
               i--;
             }
-
         }
 
       e = new_element (ET_paragraph);
@@ -599,11 +598,11 @@ begin_paragraph (ELEMENT *current)
         add_extra_integer (e, indent == CM_indent ? "indent" : "noindent",
                               1);
       add_to_element_contents (current, e);
-      current = e;
+      return e;
 
       debug ("PARAGRAPH");
     }
-  return current;
+  return 0;
 }
 
 /* Begin a preformatted element if in a preformatted context. */
@@ -657,9 +656,9 @@ end_preformatted (ELEMENT *current,
    function being called and the internal space element being
    removed or put in the internal_space_holder info.
 
-   NOTE internal_space_holder is already set to 0 in abort_empty_line
+   NOTE internal_space_holder is already unset in abort_empty_line
    if the internal space element is put in the internal_space_holder.
-   It would be cleaner to set internal_space_holder to 0 in all the
+   It would be cleaner to unset internal_space_holder in all the
    cases where the internal space element is removed too, such that
    when internal_space_holder is set the previous value is 0 and not
    the previous internal_space_holder, which is now irrelevant as
@@ -689,6 +688,7 @@ merge_text (ELEMENT *current, const char *text, size_t 
len_text,
   /* Is there a non-whitespace character in the line? */
   if (leading_spaces < len_text)
     {
+      ELEMENT *paragraph;
       if (last_child
           && (last_child->type == ET_ignorable_spaces_after_command
               || last_child->type == ET_internal_spaces_after_command
@@ -704,20 +704,38 @@ merge_text (ELEMENT *current, const char *text, size_t 
len_text,
           len_text -= leading_spaces;
         }
 
-      current = begin_paragraph (current);
+      paragraph = begin_paragraph (current);
+      if (paragraph)
+        {
+          current = paragraph;
+          /* shortcut the case with text as last content child as
+             it cannot happen if a new paragraph is started */
+          goto new_text;
+        }
     }
 
+  /* need to retrieve the last child in case the one obtained above was
+     removed in abort_empty_line */
   last_child = last_contents_child (current);
-  if (last_child
+  if (!no_merge_with_following_text
+      && last_child
       /* There is a difference between the text being defined and empty,
          and not defined at all.  The latter is true for 'brace_command_arg'
          elements.  We need either to make sure that we initialize all elements
          with text_append (&e->text, "") where we want merging with following
          text, or treat as a special case here. */
       && (last_child->text.space > 0
-            && !strchr (last_child->text.text, '\n'))
-      && !no_merge_with_following_text)
-    {
+            && !strchr (last_child->text.text, '\n')))
+    {
+      /*
+      if (last_child->type != ET_normal_text && last_child->type != 
ET_empty_line
+          && last_child->type != ET_ignorable_spaces_after_command
+          && last_child->type != ET_internal_spaces_after_command
+          && last_child->type != ET_internal_spaces_before_argument
+          && last_child->type != ET_spaces_after_close_brace)
+        fprintf (stderr, "EEE %s '%s'\n", element_type_names[last_child->type],
+                         last_child->text.text);
+       */
       /* Transfer source marks */
       if (transfer_marks_element
           && transfer_marks_element->source_mark_list.number > 0)
@@ -751,7 +769,8 @@ merge_text (ELEMENT *current, const char *text, size_t 
len_text,
     }
   else
     {
-      ELEMENT *e = new_element (ET_NONE);
+     new_text:
+      ELEMENT *e = new_element (ET_normal_text);
       if (transfer_marks_element)
         transfer_source_marks (transfer_marks_element, e);
       text_append_n (&e->text, text, len_text);
@@ -828,7 +847,7 @@ abort_empty_line (ELEMENT **current_inout, const char 
*additional_spaces,
       else if (last_child->type == ET_empty_line)
         {
           last_child->type = begin_paragraph_p (current)
-                             ? ET_spaces_before_paragraph : ET_NONE;
+                             ? ET_spaces_before_paragraph : ET_normal_text;
         }
       else if (last_child->type == ET_internal_spaces_after_command
                || last_child->type == ET_internal_spaces_before_argument)
@@ -852,33 +871,27 @@ abort_empty_line (ELEMENT **current_inout, const char 
*additional_spaces,
 }
 
 static void
-isolate_last_space_internal (ELEMENT *current)
+isolate_last_space_internal (ELEMENT *current, ELEMENT *last_elt)
 {
-  ELEMENT *last_elt;
   char *text;
   int text_len;
-  ELEMENT *spaces_element = new_element (ET_NONE);
-
-  last_elt = last_contents_child (current);
-  text = element_text (last_elt);
 
+  text = last_elt->text.text;
   text_len = last_elt->text.end;
 
   /* If text all whitespace */
   if (text[strspn (text, whitespace_chars)] == '\0')
     {
-      text_append_n (&spaces_element->text, text, text_len);
-      transfer_source_marks (last_elt, spaces_element);
-      add_info_element_oot (current, "spaces_after_argument",
-                            spaces_element);
-      destroy_element (pop_element_from_contents (current));
+      /* e is last_elt */
+      ELEMENT *e = pop_element_from_contents (current);
+      e->parent = 0;
+      e->type = ET_NONE;
+      add_info_element_oot (current, "spaces_after_argument", e);
     }
   else
     {
       int i, trailing_spaces;
-      static TEXT t;
-
-      text_reset (&t);
+      ELEMENT *spaces_element = new_element (ET_NONE);
 
       trailing_spaces = 0;
       for (i = text_len - 1;
@@ -886,20 +899,18 @@ isolate_last_space_internal (ELEMENT *current)
            i--)
         trailing_spaces++;
 
-      text_append_n (&t,
-                     text + text_len - trailing_spaces,
+      text_append_n (&spaces_element->text, text + text_len - trailing_spaces,
                      trailing_spaces);
 
       text[text_len - trailing_spaces] = '\0';
       last_elt->text.end -= trailing_spaces;
 
-      text_append (&spaces_element->text, t.text);
-
       if (last_elt->source_mark_list.number > 0)
         {
           size_t begin_position = count_multibyte (text);
           relocate_source_marks (&(last_elt->source_mark_list), spaces_element,
-                                 begin_position, count_multibyte (t.text));
+                                 begin_position,
+                                 count_multibyte (spaces_element->text.text));
         }
 
       add_info_element_oot (current, "spaces_after_argument",
@@ -952,7 +963,6 @@ isolate_trailing_space (ELEMENT *current, enum element_type 
spaces_type)
 void
 isolate_last_space (ELEMENT *current)
 {
-  char *text;
   ELEMENT *last_elt = 0;
   int text_len;
 
@@ -973,16 +983,13 @@ isolate_last_space (ELEMENT *current)
     goto no_isolate_space;
 
   last_elt = last_contents_child (current);
-  text = element_text (last_elt);
-  if (!text || !*text
-      || (last_elt->type && (!current->type
-                             || (current->type != ET_line_arg
-                                 && current->type != ET_block_line_arg))))
-    goto no_isolate_space;
 
   text_len = last_elt->text.end;
+  if (text_len <= 0)
+    goto no_isolate_space;
+
   /* Does the text end in whitespace? */
-  if (!strchr (whitespace_chars, text[text_len - 1]))
+  if (!strchr (whitespace_chars, last_elt->text.text[text_len - 1]))
     goto no_isolate_space;
 
   debug_nonl ("ISOLATE SPACE p ");
@@ -993,7 +1000,7 @@ isolate_last_space (ELEMENT *current)
   if (current->type == ET_menu_entry_node)
     isolate_trailing_space (current, ET_space_at_end_menu_node);
   else
-    isolate_last_space_internal (current);
+    isolate_last_space_internal (current, last_elt);
 
   return;
 
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index c76ac3c9bc..2630d51032 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -92,7 +92,6 @@ ELEMENT *merge_text (ELEMENT *current, const char *text, 
size_t text_len,
                      ELEMENT *transfer_marks_element);
 void start_empty_line_after_command (ELEMENT *current, const char **line_inout,
                                      ELEMENT *command);
-ELEMENT *begin_paragraph (ELEMENT *current);
 int is_end_current_command (ELEMENT *current, const char **line,
                             enum command_id *end_cmd);
 int check_space_element (ELEMENT *e);
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index 2a346abb81..58f5c1b7a8 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -235,7 +235,7 @@ handle_open_brace (ELEMENT *current, const char 
**line_inout)
            || current_context () == ct_inlineraw)
     {
       ELEMENT *b = new_element (ET_balanced_braces);
-      ELEMENT *open_brace = new_element (ET_NONE);
+      ELEMENT *open_brace = new_element (ET_normal_text);
       abort_empty_line (&current, NULL, 0);
       b->source_info = current_source_info;
       add_to_element_contents (current, b);
diff --git a/tp/Texinfo/XS/parsetexi/source_marks.c 
b/tp/Texinfo/XS/parsetexi/source_marks.c
index b52d2d02be..34c7d76342 100644
--- a/tp/Texinfo/XS/parsetexi/source_marks.c
+++ b/tp/Texinfo/XS/parsetexi/source_marks.c
@@ -68,8 +68,8 @@ place_source_mark (ELEMENT *e, SOURCE_MARK *source_mark)
     }
   else
     {
-      /* add an empty element only used for source marks */
-      mark_element = new_element (ET_NONE);
+      /* add an empty element used for source marks */
+      mark_element = new_element (ET_normal_text);
       /* set empty text to have merge_text work as expected */
       text_append (&mark_element->text, "");
       add_to_element_contents (e, mark_element);



reply via email to

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