texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/ParserNonXS.pm (_place_source_mark)


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_place_source_mark) (_process_remaining_on_line), tp/Texinfo/XS/parsetexi/close.c, tp/Texinfo/XS/parsetexi/end_line.c, tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line), tp/Texinfo/XS/parsetexi/separator.c, tp/Texinfo/XS/parsetexi/source_marks.c (place_source_mark): put text element for spaces appearing after a brace @-command name before the opening brace directly in info spaces_after_cmd_before_arg instead of using the brace command contents. Ther [...]
Date: Tue, 24 Dec 2024 09:19:34 -0500

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new b2a1391be0 * tp/Texinfo/ParserNonXS.pm (_place_source_mark) 
(_process_remaining_on_line), tp/Texinfo/XS/parsetexi/close.c, 
tp/Texinfo/XS/parsetexi/end_line.c, tp/Texinfo/XS/parsetexi/parser.c 
(process_remaining_on_line), tp/Texinfo/XS/parsetexi/separator.c, 
tp/Texinfo/XS/parsetexi/source_marks.c (place_source_mark): put text element 
for spaces appearing after a brace @-command name before the opening brace 
directly in info spaces_after_cmd_before_arg instead of using the brace co [...]
b2a1391be0 is described below

commit b2a1391be0b267cc52e29d557b095f32e765eab8
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Nov 9 23:16:02 2024 +0100

    * tp/Texinfo/ParserNonXS.pm (_place_source_mark)
    (_process_remaining_on_line), tp/Texinfo/XS/parsetexi/close.c,
    tp/Texinfo/XS/parsetexi/end_line.c, tp/Texinfo/XS/parsetexi/parser.c
    (process_remaining_on_line), tp/Texinfo/XS/parsetexi/separator.c,
    tp/Texinfo/XS/parsetexi/source_marks.c (place_source_mark): put text
    element for spaces appearing after a brace @-command name before the
    opening brace directly in info spaces_after_cmd_before_arg instead of
    using the brace command contents.  There is no need for
    _gather_spaces_after_cmd_before_arg annymore, remove, update callers.
---
 ChangeLog                              | 12 +++++
 tp/Texinfo/ParserNonXS.pm              | 93 ++++++++++------------------------
 tp/Texinfo/XS/parsetexi/close.c        |  2 -
 tp/Texinfo/XS/parsetexi/end_line.c     |  2 -
 tp/Texinfo/XS/parsetexi/parser.c       | 58 +++++++--------------
 tp/Texinfo/XS/parsetexi/separator.c    |  5 --
 tp/Texinfo/XS/parsetexi/source_marks.c | 17 +++++++
 7 files changed, 74 insertions(+), 115 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 20765561e2..ae6bce4d85 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-11-09  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_place_source_mark)
+       (_process_remaining_on_line), tp/Texinfo/XS/parsetexi/close.c,
+       tp/Texinfo/XS/parsetexi/end_line.c, tp/Texinfo/XS/parsetexi/parser.c
+       (process_remaining_on_line), tp/Texinfo/XS/parsetexi/separator.c,
+       tp/Texinfo/XS/parsetexi/source_marks.c (place_source_mark): put text
+       element for spaces appearing after a brace @-command name before the
+       opening brace directly in info spaces_after_cmd_before_arg instead of
+       using the brace command contents.  There is no need for
+       _gather_spaces_after_cmd_before_arg annymore, remove, update callers.
+
 2024-12-24  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/LaTeX.pm (convert_math_to_images): always use
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index d906b6eaa9..16215530e9 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -1250,6 +1250,18 @@ sub _place_source_mark
     if (defined($current->{'text'}) and $current->{'text'} ne '') {
       $source_mark->{'position'} = length($current->{'text'});
     }
+  } elsif ($element->{'cmdname'}
+           and defined($self->{'brace_commands'}->{$element->{'cmdname'}})) {
+    # can only be before the opening brace
+    $element->{'info'} = {} if (!$element->{'info'});
+    if (!$element->{'info'}->{'spaces_after_cmd_before_arg'}) {
+      $element->{'info'}->{'spaces_after_cmd_before_arg'} = {'text' => ''};
+      $add_element_string = 'add';
+    } else {
+      $source_mark->{'position'}
+       = length($element->{'info'}->{'spaces_after_cmd_before_arg'}->{'text'});
+    }
+    $mark_element = $element->{'info'}->{'spaces_after_cmd_before_arg'};
   } else {
     # add an empty element only used for source marks
     # 'text' is here to have merge_text work as expected
@@ -2204,9 +2216,6 @@ sub _close_commands($$$;$$)
       and defined($self->{'brace_commands'}->{$current->{'cmdname'}})) {
     $self->_line_error(sprintf(__("\@%s expected braces"),
                        $current->{'cmdname'}), $source_info);
-    if ($current->{'contents'}) {
-      _gather_spaces_after_cmd_before_arg($self, $current);
-    }
     $current = $current->{'parent'};
   }
 
@@ -4745,9 +4754,6 @@ sub _end_line($$$)
       and defined($self->{'brace_commands'}->{$current->{'cmdname'}})) {
       $self->_line_error(sprintf(__("\@%s expected braces"),
                          $current->{'cmdname'}), $source_info);
-      if ($current->{'contents'}) {
-        _gather_spaces_after_cmd_before_arg($self, $current);
-      }
       $current = $current->{'parent'};
     }
 
@@ -5170,18 +5176,6 @@ sub _new_value_element($$;$$)
   return $value_elt;
 }
 
-sub _gather_spaces_after_cmd_before_arg($$)
-{
-  my $self = shift;
-  my $current = shift;
-  # it could be possible to check that there is no other content and that
-  # the type is the expected type.
-  my $spaces_element = _pop_element_from_contents($self, $current);
-  delete $spaces_element->{'type'};
-  $current->{'info'} = {} if (!$current->{'info'});
-  $current->{'info'}->{'spaces_after_cmd_before_arg'} = $spaces_element;
-}
-
 sub _handle_macro($$$$$)
 {
   my $self = shift;
@@ -6232,11 +6226,6 @@ sub _handle_open_brace($$$$)
        and defined($self->{'brace_commands'}->{$current->{'cmdname'}})) {
     my $command = $current->{'cmdname'};
 
-    # if there is already content it is for spaces_after_cmd_before_arg
-    if ($current->{'contents'}) {
-      _gather_spaces_after_cmd_before_arg($self, $current);
-    }
-
     if (defined($commands_args_number{$command})
         and $commands_args_number{$command} > 1) {
       $current->{'remaining_args'}
@@ -7227,21 +7216,17 @@ sub _process_remaining_on_line($$$$)
   # argument (an opening brace, or a character after spaces for
   # accent commands) was not found and there is already a new command.
   #
-  # NOTE the last element in the current command contents is an element that
-  # is transiently in the tree, and is put in the info hash by
-  # _gather_spaces_after_cmd_before_arg.  It could therefore be possible
-  # to accept an @comment here and put it in this element.  It would not
-  # necessarily be a good idea, as it would mean having an element
-  # in the info hash that holds something more complex than text and source
-  # marks.
+  # NOTE the ->{'info'}->{'spaces_after_cmd_before_arg'} element
+  # in the current command holds the spaces before the opening brace.
+  # It could be possible to accept an @comment here and put it in this
+  # element.  It would not necessarily be a good idea, as it would mean
+  # having an element in info that holds something more complex
+  # than text and source marks.
   if ($command
       and $current->{'cmdname'}
       and defined($self->{'brace_commands'}->{$current->{'cmdname'}})) {
     $self->_line_error(sprintf(__("\@%s expected braces"),
                        $current->{'cmdname'}), $source_info);
-    if ($current->{'contents'}) {
-      _gather_spaces_after_cmd_before_arg($self, $current);
-    }
     $current = $current->{'parent'};
   }
 
@@ -7295,16 +7280,8 @@ sub _process_remaining_on_line($$$$)
              and defined($self->{'context_command_stack'}->[-1]))
             or $top_context eq 'ct_def') {
           # do not consider the end of line to be possibly between
-          # the @-command and the argument if at the end of a
+          # the @-command and the opening brace if at the end of a
           # line or block @-command.
-          if ($current->{'contents'}) {
-            # this can only happen if the spaces gathered after the command
-            # before the braces were interrupted before the end of line, which
-            # can happen if there is a macro expansion that ends before the end
-            # of line.
-            # Tested in macro line_end_accent_command_macro_call
-            _gather_spaces_after_cmd_before_arg($self, $current);
-          }
           $current = $current->{'parent'};
           $current = _merge_text($self, $current, $added_space);
           _isolate_last_space($self, $current);
@@ -7314,22 +7291,13 @@ sub _process_remaining_on_line($$$$)
         }
         $additional_newline = 1;
       }
-      if (!$current->{'contents'}) {
+      if (!$current->{'info'}
+          or !$current->{'info'}->{'spaces_after_cmd_before_arg'}) {
         $line =~ s/^(\s+)//;
         my $spaces_after_command = $1;
-        # The added element is only transiently present, it is removed
-        # by calls of gather_spaces_after_cmd_before_arg, which transfer
-        # the element to the info hash.  The contents allow to have source
-        # marks easily associated.
-        # The type name is not used anywhere but can be useful for
-        # debugging, in particular to check that the element does not
-        # appear anywhere in the tree.
-        # Note that contents is transiently set for brace commands, which in
-        # general only have args.
-        my $e_spaces_after_cmd_before_arg
-           = {'type' => 'internal_spaces_after_cmd_before_arg',
-              'text' => $spaces_after_command, 'parent' => $current};
-        $current->{'contents'} = [$e_spaces_after_cmd_before_arg];
+        $current->{'info'} = {} if (!$current->{'info'});
+        $current->{'info'}->{'spaces_after_cmd_before_arg'}
+          = {'text' => $spaces_after_command};
         if ($self->{'conf'}->{'DEBUG'}) {
           my $spaces_after_command_str = $spaces_after_command;
           $spaces_after_command_str =~ s/\n/\\n/g;
@@ -7339,18 +7307,19 @@ sub _process_remaining_on_line($$$$)
       } else {
         # contents, at this point can only be for spaces_after_cmd_before_arg
         if ($additional_newline
-            and $current->{'contents'}->[0]->{'text'} =~ /\n/) {
+            and $current->{'info'}
+                  ->{'spaces_after_cmd_before_arg'}->{'text'} =~ /\n/) {
           # only ignore spaces and one newline, two newlines lead to
           # an empty line before the brace or argument which is incorrect.
           print STDERR "BRACE CMD before brace second newline stops spaces\n"
             if $self->{'conf'}->{'DEBUG'};
           $self->_line_error(sprintf(__("\@%s expected braces"),
                              $current->{'cmdname'}), $source_info);
-          _gather_spaces_after_cmd_before_arg($self, $current);
           $current = $current->{'parent'};
         } else {
           $line =~ s/^(\s+)//;
-          $current->{'contents'}->[0]->{'text'} .= $added_space;
+          $current->{'info'}->{'spaces_after_cmd_before_arg'}->{'text'}
+               .= $added_space;
           print STDERR "BRACE CMD before brace add spaces '$added_space'\n"
             if $self->{'conf'}->{'DEBUG'};
         }
@@ -7364,9 +7333,6 @@ sub _process_remaining_on_line($$$$)
       my $arg_char = $1;
       print STDERR "ACCENT \@$current->{'cmdname'} following_arg: $arg_char\n"
         if ($self->{'conf'}->{'DEBUG'});
-      if ($current->{'contents'}) {
-        _gather_spaces_after_cmd_before_arg($self, $current);
-      }
       my $following_arg = {'type' => 'following_arg',
                            'parent' => $current};
       $current->{'args'} = [ $following_arg ];
@@ -7384,9 +7350,6 @@ sub _process_remaining_on_line($$$$)
     } else {
       $self->_line_error(sprintf(__("\@%s expected braces"),
                          $current->{'cmdname'}), $source_info);
-      if ($current->{'contents'}) {
-        _gather_spaces_after_cmd_before_arg($self, $current);
-      }
       $current = $current->{'parent'};
     }
   } elsif (_handle_menu_entry_separators($self, \@current_array_for_ref,
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 29daf24e4a..54041b1d7e 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -505,8 +505,6 @@ close_commands (ELEMENT *current, enum command_id 
closed_block_cmd,
     {
       line_error ("@%s expected braces",
                   command_name(current->e.c->cmd));
-      if (current->e.c->contents.number > 0)
-        gather_spaces_after_cmd_before_arg (current);
       current = current->parent;
     }
 
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c 
b/tp/Texinfo/XS/parsetexi/end_line.c
index 3b78fd9b76..a4a214a94e 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -1966,8 +1966,6 @@ end_line (ELEMENT *current)
         {
           line_error ("@%s expected braces",
                       command_name(current->e.c->cmd));
-          if (current->e.c->contents.number > 0)
-            gather_spaces_after_cmd_before_arg (current);
           current = current->parent;
         }
 
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 4db9c978f9..4c3f231ff3 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1175,15 +1175,6 @@ register_command_as_argument (ELEMENT *cmd_as_arg)
   }
 }
 
-void
-gather_spaces_after_cmd_before_arg (ELEMENT *current)
-{
-  ELEMENT *spaces_element = pop_element_from_contents (current);
-  spaces_element->type = ET_other_text;
-  current->elt_info[eit_spaces_after_cmd_before_arg]
-    = spaces_element;
-}
-
 static ELEMENT *
 new_value_element (enum command_id cmd, const char *flag,
                    int flag_len, ELEMENT *spaces_element)
@@ -2060,19 +2051,18 @@ process_remaining_on_line (ELEMENT **current_inout, 
const char **line_inout)
      argument (an opening brace, or a character after spaces for
      accent commands) was not found and there is already a new command.
 
-     NOTE the last element in the current command contents is an element that
-     is transiently in the tree, and is put in the info hash by
-     gather_spaces_after_cmd_before_arg.  It could therefore be possible
-     to accept an @comment here and put it in this element, but we do
-     not want to complicate the tree.
+     NOTE the ->{'info'}->{'spaces_after_cmd_before_arg'} element
+     in the current command holds the spaces before the opening brace.
+     It could be possible to accept an @comment here and put it in this
+     element.  It would not necessarily be a good idea, as it would mean
+     having an element in info that holds something more complex
+     than text and source marks.
    */
 
   if (command_flags(current) & CF_brace && (cmd || command))
     {
       line_error ("@%s expected braces",
                   command_name(current->e.c->cmd));
-      if (current->e.c->contents.number > 0)
-        gather_spaces_after_cmd_before_arg (current);
       current = current->parent;
     }
 
@@ -2146,10 +2136,8 @@ process_remaining_on_line (ELEMENT **current_inout, 
const char **line_inout)
                            && top_context_command () != CM_NONE))
                      {
                     /* do not consider the end of line to be possibly between
-                       the @-command and the argument if at the end of a
+                       the @-command and the opening brace if at the end of a
                        line or block @-command. */
-                       if (current->e.c->contents.number > 0)
-                         gather_spaces_after_cmd_before_arg (current);
                        current = current->parent;
                        current = merge_text (current, line, whitespaces_len, 
0);
                        line += whitespaces_len;
@@ -2163,23 +2151,14 @@ process_remaining_on_line (ELEMENT **current_inout, 
const char **line_inout)
                  }
              }
 
-           /* The added element is only transiently present, it is removed
-              by calls of gather_spaces_after_cmd_before_arg, which transfer
-              the element to the info hash.  The contents allow to have source
-              marks easily associated.
-              The type name is not used anywhere but can be useful for
-              debugging, in particular to check that the element does not
-              appear anywhere in the tree.
-              Note that contents is transiently set for brace commands, which 
in
-              general only have args. */
-
-           if (current->e.c->contents.number == 0)
+           if (!current->elt_info[eit_spaces_after_cmd_before_arg])
              {
                ELEMENT *e_spaces_after_cmd_before_arg
-                 = new_text_element (ET_internal_spaces_after_cmd_before_arg);
+                 = new_text_element (ET_other_text);
                text_append_n (e_spaces_after_cmd_before_arg->e.text,
                               line, whitespaces_len);
-               add_to_element_contents (current, 
e_spaces_after_cmd_before_arg);
+               current->elt_info[eit_spaces_after_cmd_before_arg]
+                  = e_spaces_after_cmd_before_arg;
 
                debug_nonl ("BRACE CMD before brace init spaces '");
                debug_print_protected_string
@@ -2194,22 +2173,23 @@ process_remaining_on_line (ELEMENT **current_inout, 
const char **line_inout)
             /* only ignore spaces and one newline, two newlines lead to
                an empty line before the brace or argument which is incorrect. 
*/
                char *previous_value
-                  = current->e.c->contents.list[0]->e.text->text;
+                  = current->elt_info[eit_spaces_after_cmd_before_arg]
+                                                             ->e.text->text;
                if (additional_newline && strchr ("\n", *previous_value))
                  {
                    debug ("BRACE CMD before brace second newline stops 
spaces");
                    line_error ("@%s expected braces",
                                command_name(current->e.c->cmd));
-                   gather_spaces_after_cmd_before_arg (current);
                    current = current->parent;
                  }
                else
                  {
-                   text_append_n (current->e.c->contents.list[0]->e.text,
+                   text_append_n (current
+                        ->elt_info[eit_spaces_after_cmd_before_arg]->e.text,
                                   line, whitespaces_len);
                    debug ("BRACE CMD before brace add spaces '%s'",
-                          current->e.c->contents.list[0]->e.text->text
-                       + strlen (current->e.c->contents.list[0]->e.text->text)
+               current->elt_info[eit_spaces_after_cmd_before_arg]->e.text->text
+   + strlen (current->elt_info[eit_spaces_after_cmd_before_arg]->e.text->text)
                                                          - whitespaces_len);
                    line += whitespaces_len;
                  }
@@ -2223,8 +2203,6 @@ process_remaining_on_line (ELEMENT **current_inout, const 
char **line_inout)
           ELEMENT *e, *e2;
           int char_len;
 
-          if (current->e.c->contents.number > 0)
-            gather_spaces_after_cmd_before_arg (current);
           e = new_element (ET_following_arg);
           add_to_element_args (current, e);
 
@@ -2252,8 +2230,6 @@ process_remaining_on_line (ELEMENT **current_inout, const 
char **line_inout)
         {
           line_error ("@%s expected braces",
                       command_name(current->e.c->cmd));
-          if (current->e.c->contents.number > 0)
-            gather_spaces_after_cmd_before_arg (current);
           current = current->parent;
         }
     }
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index 290a14db52..840ef1690a 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -58,11 +58,6 @@ handle_open_brace (ELEMENT *current, const char **line_inout)
       enum command_id cmd = current->e.c->cmd;
       ELEMENT *arg;
 
-
-      /* if there is already content it is for spaces_after_cmd_before_arg */
-      if (current->e.c->contents.number > 0)
-        gather_spaces_after_cmd_before_arg (current);
-
       if (command_data(cmd).flags & CF_contain_basic_inline)
         push_command (&nesting_context.basic_inline_stack, cmd);
 
diff --git a/tp/Texinfo/XS/parsetexi/source_marks.c 
b/tp/Texinfo/XS/parsetexi/source_marks.c
index e061987a46..603ceca343 100644
--- a/tp/Texinfo/XS/parsetexi/source_marks.c
+++ b/tp/Texinfo/XS/parsetexi/source_marks.c
@@ -22,6 +22,8 @@
 #include "tree.h"
 /* for count_multibyte and other */
 #include "utils.h"
+#include "builtin_commands.h"
+#include "commands.h"
 /* for add_source_mark */
 #include "manipulate_tree.h"
 #include "debug_parser.h"
@@ -68,6 +70,21 @@ place_source_mark (ELEMENT *e, SOURCE_MARK *source_mark)
           && last_child->e.text->end > 0)
         source_mark->position = count_multibyte (last_child->e.text->text);
     }
+  else if (!(type_data[e->type].flags & TF_text)
+           && command_flags(e) & CF_brace)
+    {
+      /* can only be before the opening brace */
+      if (!e->elt_info[eit_spaces_after_cmd_before_arg])
+        {
+          e->elt_info[eit_spaces_after_cmd_before_arg]
+            = new_text_element (ET_other_text);
+          add_element_string = "add";
+        }
+      else
+        source_mark->position = count_multibyte (
+                e->elt_info[eit_spaces_after_cmd_before_arg]->e.text->text);
+      mark_element = e->elt_info[eit_spaces_after_cmd_before_arg];
+    }
   else
     {
       /* add an empty element used for source marks */



reply via email to

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