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 (_process_remaining_o


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_process_remaining_on_line), tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line): remove code removing empty contents and trensferring source marks of accent command now that it is collected by gather_spaces_after_cmd_before_arg.
Date: Wed, 22 Feb 2023 11:08:26 -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 d85bddd186 * tp/Texinfo/ParserNonXS.pm (_process_remaining_on_line), 
tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line): remove code 
removing empty contents and trensferring source marks of accent command now 
that it is collected by gather_spaces_after_cmd_before_arg.
d85bddd186 is described below

commit d85bddd186729992a986e3f5fd3b696d3bd00909
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Feb 22 17:08:19 2023 +0100

    * tp/Texinfo/ParserNonXS.pm (_process_remaining_on_line),
    tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line):
    remove code removing empty contents and trensferring source
    marks of accent command now that it is collected by
    gather_spaces_after_cmd_before_arg.
    
    * tp/Texinfo/ParserNonXS.pm (_process_remaining_on_line): similar
    organization of code with XS parser.
---
 ChangeLog                        | 11 ++++++++
 tp/Texinfo/ParserNonXS.pm        | 55 ++++++++++++++++++++--------------------
 tp/Texinfo/XS/parsetexi/parser.c | 30 +++++++++-------------
 3 files changed, 51 insertions(+), 45 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e893a0beea..95b84a4d17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2023-02-22  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_process_remaining_on_line),
+       tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line):
+       remove code removing empty contents and trensferring source
+       marks of accent command now that it is collected by
+       gather_spaces_after_cmd_before_arg.
+
+       * tp/Texinfo/ParserNonXS.pm (_process_remaining_on_line): similar
+       organization of code with XS parser.
+
 2023-02-22  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/Texinfo.pm (_expand_cmd_args_to_texi),
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 9737dd8b7d..68f431f0d5 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -4695,6 +4695,8 @@ 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'});
@@ -5224,28 +5226,39 @@ sub _process_remaining_on_line($$$$)
       }
       if (!$current->{'contents'}) {
         $line =~ s/^(\s+)//;
+        # 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 usefull 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 $spaces_after_cmd_before_arg
            = {'type' => 'internal_spaces_after_cmd_before_arg',
               'text' => $1, 'parent' => $current};
         $current->{'contents'} = [$spaces_after_cmd_before_arg];
         print STDERR "BRACE CMD before brace init spaces '$added_space'\n"
           if $self->{'DEBUG'};
-      # only ignore spaces and one newline, two newlines lead to
-      # an empty line before the brace or argument which is incorrect.
-      } elsif ($additional_newline
-               and $current->{'contents'}
-               and $current->{'contents'}->[0]->{'text'} =~ /\n/) {
-        print STDERR "BRACE CMD before brace second newline stops spaces\n"
-          if $self->{'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;
-        print STDERR "BRACE CMD before brace add spaces '$added_space'\n"
-          if $self->{'DEBUG'};
+        # contents, at this point can only be for spaces_after_cmd_before_arg
+        if ($additional_newline
+            and $current->{'contents'}->[0]->{'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->{'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;
+          print STDERR "BRACE CMD before brace add spaces '$added_space'\n"
+            if $self->{'DEBUG'};
+        }
       }
     # special case for accent commands, use following character except @
     # as argument.  Note that since we checked before that there isn't
@@ -5269,18 +5282,6 @@ sub _process_remaining_on_line($$$$)
                                    ord('@'), $current->{'cmdname'}, $1),
                            $source_info);
       }
-      # FIXME this is like the XS parser, and it matters to have the contents
-      # removed here when there are source marks.  It is not clear why there
-      # are contents to begin with, nor what would be the best, remove them
-      # as is done here, or keep them as contents.  Also, in theory the
-      # elements may have text/args/contents, although never saw anything
-      # else than empty elements.
-      while ($current->{'contents'} and scalar(@{$current->{'contents'}})) {
-        # TODO not clear that it leads to a correct location of source marks
-        print STDERR "HHHHHHH 
".Texinfo::Common::debug_print_element($current->{'contents'}->[0], 1)."\n";
-        my $removed_element = _pop_element_from_contents($self, $current);
-        _transfer_source_marks($removed_element, $following_arg);
-      }
       $current = $current->{'parent'};
     } else {
       $self->_line_error(sprintf(__("\@%s expected braces"),
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index ec563c7c56..fd0ec7df00 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1869,6 +1869,16 @@ process_remaining_on_line (ELEMENT **current_inout, 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 usefull 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->contents.number == 0)
              {
                ELEMENT *spaces_after_cmd_before_arg
@@ -1880,6 +1890,7 @@ process_remaining_on_line (ELEMENT **current_inout, char 
**line_inout)
              }
            else
              {
+       /* contents, at this point can only be for spaces_after_cmd_before_arg 
*/
             /* 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->contents.list[0]->text.text;
@@ -1916,27 +1927,10 @@ process_remaining_on_line (ELEMENT **current_inout, 
char **line_inout)
           if (current->cmd == CM_dotless
               && *line != 'i' && *line != 'j')
             {
+              /* TODO may show a partial character if non-ascii */
               line_error ("@dotless expects `i' or `j' as argument, "
                           "not `%c'", *line);
             }
-          /* REMARK it happens in the test suite at least with macros
-             and accents, and requires source marks to be transmitted */
-          while (current->contents.number > 0)
-            {
-              ELEMENT *popped_element = pop_element_from_contents (current);
-              transfer_source_marks (popped_element, e);
-              /* current is the accent command.  So far only saw empty elements
-                 for the removed elements */
-              /*
-              debug_nonl ("REMOVE content. Accent: ");
-              debug_print_element (current, 1);
-              debug ("");
-              debug_nonl ("       removed: ");
-              debug_print_element (popped_element, 0);
-              debug ("");
-              */
-              destroy_element (popped_element);
-            }
           line++;
           current = current->parent;
         }



reply via email to

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