texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Wed, 22 Feb 2023 03:52:52 -0500 (EST)

branch: master
commit b0b3c5494fde05fa25779c029a51fdbfec8115c5
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Feb 22 09:52:38 2023 +0100

    * tp/Texinfo/ParserNonXS.pm (_next_text, _parse_texi)
    (_process_remaining_on_line): adapt to input stack not being empty
    even after last input has been fetched.  Remove completly the empty
    input from the input stack at the end of _parse_texi.
    
    * tp/Texinfo/ParserNonXS.pm (_process_remaining_on_line),
    tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line): in case
    of an unclosed raw output ignored block, exit to get to end line
    processing in parse_texi instead of setting the line to an empty
    string.
---
 ChangeLog                                          | 13 +++++
 tp/Texinfo/ParserNonXS.pm                          | 61 +++++++++++++++-------
 tp/Texinfo/XS/parsetexi/parser.c                   |  4 +-
 .../conditionals/false_format_not_closed.pl        |  4 --
 .../command_in_end_ignored_raw_in_command.pl       |  4 --
 ...d_in_end_ignored_raw_one_char_before_command.pl |  4 --
 ...d_in_end_ignored_raw_one_char_not_in_command.pl |  4 --
 ...d_in_end_ignored_raw_two_char_before_command.pl |  4 --
 ...d_in_end_ignored_raw_two_char_not_in_command.pl |  4 --
 9 files changed, 57 insertions(+), 45 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 101044c710..66147ac874 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2023-02-22  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_next_text, _parse_texi)
+       (_process_remaining_on_line): adapt to input stack not being empty
+       even after last input has been fetched.  Remove completly the empty
+       input from the input stack at the end of _parse_texi.
+
+       * tp/Texinfo/ParserNonXS.pm (_process_remaining_on_line),
+       tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line): in case
+       of an unclosed raw output ignored block, exit to get to end line
+       processing in parse_texi instead of setting the line to an empty
+       string.
+
 2023-02-22  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/Makefile.am (Parsetexi_la_SOURCES),
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index b1f0025fc9..4bdf6b27d7 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -2296,7 +2296,7 @@ sub _next_text($;$)
 {
   my ($self, $current) = @_;
 
-  while (@{$self->{'input'}}) {
+  while (1) {
     my $input = $self->{'input'}->[0];
     if (exists($input->{'th'})) {
       my $texthandle = $input->{'th'};
@@ -2345,13 +2345,18 @@ sub _next_text($;$)
         return ($line, { %{$input->{'input_source_info'}} });
       }
     } else {
-      # TODO currently possible if called for lines after @bye but
-      # there is nothing anymore
-      #$self->_bug_message("Unexpected input $input ("
-      #                                .scalar(@{$self->{'input'}}).")",
-      #                    $input->{'input_source_info'}, $current);
-      #Texinfo::Common::debug_hash($input);
-      #cluck();
+      # At the end of the input, when some text is demanded, for instance
+      # to get new input in case an @include added more input, but there
+      # is nothing, we get here.  Also macro arguments ending on the last
+      # line will lead to the consumption of the last text, then macro
+      # expansion can readd more text, and the end of input will be reached
+      # again.  With numerous macros expansions on the last line, this
+      # place can be reached more than twice.
+      $input->{'after_end_fetch_nr'}++;
+      if ($self->{'DEBUG'} and $input->{'after_end_fetch_nr'} > 1) {
+        print STDERR "AFTER END FETCHED INPUT NR: "
+                         .$input->{'after_end_fetch_nr'}."\n";
+      }
     }
     # Top input source failed.  Close, pop, and try the next one.
     if (exists($input->{'th'})) {
@@ -2417,19 +2422,20 @@ sub _next_text($;$)
                               $end_source_mark);
       } else {
         if ($self->{'DEBUG'}) {
-        #if (1) {
           print STDERR "INPUT MARK MISSED: "
             ._debug_show_source_mark($input->{'input_source_mark'})."\n";
           cluck();
         }
       }
+      delete $input->{'input_source_mark'};
     }
     # keep the first input level to have a permanent source for
     # source_info, even when nothing is returned and the first input
     # file is closed.
     if (scalar(@{$self->{'input'}}) == 1) {
       print STDERR "INPUT FINISHED\n" if ($self->{'DEBUG'});
-      #cluck();
+      $input->{'after_end_fetch_nr'} = 0
+         if (!defined($input->{'after_end_fetch_nr'}));
       return (undef, { %{$input->{'input_source_info'}} });
     } else {
       shift @{$self->{'input'}};
@@ -4977,10 +4983,13 @@ sub _process_remaining_on_line($$$$)
     while (1) {
     # A source mark here is tested in t/*macro.t macro_end_call_in_ignored_raw
       ($line, $source_info) = _new_line($self, $elided_rawpreformatted);
-      if (!$line) {
+      print STDERR "IGNORED RAW_PREFORMATTED $current->{'cmdname'}"
+        .(defined($line) ? ": $line" : "\n")
+          if ($self->{'DEBUG'});
+      if (!defined($line)) {
         # unclosed block
-        $line = '';
-        last;
+        return ($current, $line, $source_info, $retval);
+        # goto funexit;  # used in XS code
       } elsif ($line =~ /^\s*\@end\s+$current->{'cmdname'}/) {
         last;
       } else {
@@ -6614,11 +6623,9 @@ sub _process_remaining_on_line($$$$)
     if ($line =~ s/^(\n)//) {
       $current = _merge_text($self, $current, $1);
     } else {
-      if (scalar(@{$self->{'input'}})) {
-        $self->_bug_message("Text remaining without normal text but `$line'",
-                            $source_info, $current);
-        die;
-      }
+      $self->_bug_message("Should be at end of line but have `$line'",
+                          $source_info, $current);
+      die;
     }
     $current = _end_line($self, $current, $source_info);
     return ($current, $line, $source_info, $GET_A_NEW_LINE);
@@ -6716,7 +6723,13 @@ sub _parse_texi($$$)
                                                  if ($self->{'DEBUG'});
         $current = _end_line($self, $current, $source_info);
         # It may happen that there was an @include file on the line, it
-        # will be picked up at NEXT_LINE, beginning a new line
+        # was pushed to input in _end_line, its contents will be picked up at
+        # NEXT_LINE.  Normally, macro and value expansion cannot be triggered
+        # by _end_line, so cannot lead to more input being available after
+        # an undefined line.
+        # Because there can still be content with an include file expansion,
+        # need to go to NEXT_LINE, even though for any other situation
+        # there is no input anymore.
         last;
       }
     }
@@ -6759,6 +6772,16 @@ sub _parse_texi($$$)
     }
   }
 
+  # check that there is only one empty input remaining and remove
+  # it such that it is not re-used by following parser calls.
+  my $empty_last_input = shift(@{$self->{'input'}});
+  if ($empty_last_input->{'th'} or $empty_last_input->{'fh'}
+      or $empty_last_input->{'source_mark'}
+      or scalar(@{$self->{'input'}})) {
+    $self->_bug_message("Non empty last input at the end\n");
+    die;
+  }
+
   # Setup labels info and nodes list based on 'targets'
   Texinfo::Convert::NodeNameNormalization::set_nodes_list_labels($self,
                                               $self->{'registrar'}, $self);
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index ea741fba82..46a6bdf65c 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1573,8 +1573,8 @@ process_remaining_on_line (ELEMENT **current_inout, char 
**line_inout)
           line = new_line (e);
           if (!line)
             {
-              line = "";
-              break;
+              /* unclosed block */
+              goto funexit;
             }
           else
             {
diff --git a/tp/t/results/conditionals/false_format_not_closed.pl 
b/tp/t/results/conditionals/false_format_not_closed.pl
index 2e830f6fac..ab08a81a62 100644
--- a/tp/t/results/conditionals/false_format_not_closed.pl
+++ b/tp/t/results/conditionals/false_format_not_closed.pl
@@ -25,10 +25,6 @@ $result_trees{'false_format_not_closed'} = {
           'contents' => [
             {
               'type' => 'elided_rawpreformatted'
-            },
-            {
-              'text' => '',
-              'type' => 'empty_line'
             }
           ],
           'source_info' => {
diff --git a/tp/t/results/coverage/command_in_end_ignored_raw_in_command.pl 
b/tp/t/results/coverage/command_in_end_ignored_raw_in_command.pl
index fe82c58856..2fd057e102 100644
--- a/tp/t/results/coverage/command_in_end_ignored_raw_in_command.pl
+++ b/tp/t/results/coverage/command_in_end_ignored_raw_in_command.pl
@@ -32,10 +32,6 @@ $result_trees{'command_in_end_ignored_raw_in_command'} = {
                 }
               ],
               'type' => 'elided_rawpreformatted'
-            },
-            {
-              'text' => '',
-              'type' => 'empty_line'
             }
           ],
           'source_info' => {
diff --git 
a/tp/t/results/coverage/command_in_end_ignored_raw_one_char_before_command.pl 
b/tp/t/results/coverage/command_in_end_ignored_raw_one_char_before_command.pl
index 74f96c4273..59b9cb1a62 100644
--- 
a/tp/t/results/coverage/command_in_end_ignored_raw_one_char_before_command.pl
+++ 
b/tp/t/results/coverage/command_in_end_ignored_raw_one_char_before_command.pl
@@ -32,10 +32,6 @@ 
$result_trees{'command_in_end_ignored_raw_one_char_before_command'} = {
                 }
               ],
               'type' => 'elided_rawpreformatted'
-            },
-            {
-              'text' => '',
-              'type' => 'empty_line'
             }
           ],
           'source_info' => {
diff --git 
a/tp/t/results/coverage/command_in_end_ignored_raw_one_char_not_in_command.pl 
b/tp/t/results/coverage/command_in_end_ignored_raw_one_char_not_in_command.pl
index c1c5affce8..47d1ed71d6 100644
--- 
a/tp/t/results/coverage/command_in_end_ignored_raw_one_char_not_in_command.pl
+++ 
b/tp/t/results/coverage/command_in_end_ignored_raw_one_char_not_in_command.pl
@@ -32,10 +32,6 @@ 
$result_trees{'command_in_end_ignored_raw_one_char_not_in_command'} = {
                 }
               ],
               'type' => 'elided_rawpreformatted'
-            },
-            {
-              'text' => '',
-              'type' => 'empty_line'
             }
           ],
           'source_info' => {
diff --git 
a/tp/t/results/coverage/command_in_end_ignored_raw_two_char_before_command.pl 
b/tp/t/results/coverage/command_in_end_ignored_raw_two_char_before_command.pl
index fd604b79fa..82d8dee1fb 100644
--- 
a/tp/t/results/coverage/command_in_end_ignored_raw_two_char_before_command.pl
+++ 
b/tp/t/results/coverage/command_in_end_ignored_raw_two_char_before_command.pl
@@ -32,10 +32,6 @@ 
$result_trees{'command_in_end_ignored_raw_two_char_before_command'} = {
                 }
               ],
               'type' => 'elided_rawpreformatted'
-            },
-            {
-              'text' => '',
-              'type' => 'empty_line'
             }
           ],
           'source_info' => {
diff --git 
a/tp/t/results/coverage/command_in_end_ignored_raw_two_char_not_in_command.pl 
b/tp/t/results/coverage/command_in_end_ignored_raw_two_char_not_in_command.pl
index 09982e4fa5..51ae85d013 100644
--- 
a/tp/t/results/coverage/command_in_end_ignored_raw_two_char_not_in_command.pl
+++ 
b/tp/t/results/coverage/command_in_end_ignored_raw_two_char_not_in_command.pl
@@ -32,10 +32,6 @@ 
$result_trees{'command_in_end_ignored_raw_two_char_not_in_command'} = {
                 }
               ],
               'type' => 'elided_rawpreformatted'
-            },
-            {
-              'text' => '',
-              'type' => 'empty_line'
             }
           ],
           'source_info' => {



reply via email to

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