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 (_end_preformatted, _


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_end_preformatted, _end_line), tp/Texinfo/XS/parsetexi/end_line.c (end_line_misc_line), tp/Texinfo/XS/parsetexi/parser.c (end_preformatted): only close preformatted type in end_preformatted(). Close all the empty types after an @end command.
Date: Thu, 30 Dec 2021 07:32:47 -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 e1f5d02060 * tp/Texinfo/ParserNonXS.pm (_end_preformatted, _end_line), 
tp/Texinfo/XS/parsetexi/end_line.c (end_line_misc_line), 
tp/Texinfo/XS/parsetexi/parser.c (end_preformatted): only close preformatted 
type in end_preformatted(). Close all the empty types after an @end command.
e1f5d02060 is described below

commit e1f5d0206066373204015c454efa4386c789de88
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Dec 30 13:32:35 2021 +0100

    * tp/Texinfo/ParserNonXS.pm (_end_preformatted, _end_line),
    tp/Texinfo/XS/parsetexi/end_line.c (end_line_misc_line),
    tp/Texinfo/XS/parsetexi/parser.c (end_preformatted):
    only close preformatted type in end_preformatted().
    Close all the empty types after an @end command.
    
    * tp/Texinfo/ParserNonXS.pm (_begin_preformatted, _merge_text)
    (_end_line): do not initialize 'contents' for preformatted to match with
    what is done in XS parser.
---
 ChangeLog                                          | 13 ++++++++
 tp/Texinfo/ParserNonXS.pm                          | 38 ++++++++++++++++------
 tp/Texinfo/XS/parsetexi/end_line.c                 | 11 +++++++
 tp/Texinfo/XS/parsetexi/parser.c                   |  7 ++--
 tp/t/results/invalid_nestings/raw_block_on_line.pl |  5 +++
 5 files changed, 59 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 97e3266712..92b38d6650 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2021-12-30  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_end_preformatted, _end_line),
+       tp/Texinfo/XS/parsetexi/end_line.c (end_line_misc_line),
+       tp/Texinfo/XS/parsetexi/parser.c (end_preformatted):
+       only close preformatted type in end_preformatted().
+       Close all the empty types after an @end command.
+
+       * tp/Texinfo/ParserNonXS.pm (_begin_preformatted, _merge_text)
+       (_end_line): do not initialize 'contents' for preformatted to match with
+       what is done in XS parser.
+
+
 2021-12-29  Patrice Dumas  <pertusus@free.fr>
 
        * doc/texinfo.texi (HTML Customization Variables),
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index cd5dd3ac8b..5478693f4f 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -510,6 +510,7 @@ foreach my $command (keys(%block_commands)) {
 }
 
 my @preformatted_contexts = ('preformatted', 'rawpreformatted');
+#my @preformatted_contexts = ('preformatted');
 my %preformatted_contexts;
 foreach my $preformatted_context (@preformatted_contexts) {
   $preformatted_contexts{$preformatted_context} = 1;
@@ -518,7 +519,7 @@ foreach my $preformatted_context (@preformatted_contexts) {
 # contexts on the context_stack stack where empty line doesn't trigger
 # a paragraph
 my %no_paragraph_contexts;
-foreach my $no_paragraph_context ('math', @preformatted_contexts,
+foreach my $no_paragraph_context ('math', 'preformatted', 'rawpreformatted',
                                   'def', 'inlineraw') {
   $no_paragraph_contexts{$no_paragraph_context} = 1;
 };
@@ -1251,9 +1252,12 @@ sub _begin_preformatted($$)
 
   my $top_context = $self->_top_context();
   if ($preformatted_contexts{$top_context}) {
+  #if ($top_context eq 'rawpreformatted') {
+  #  cluck;
+  #}
     push @{$current->{'contents'}},
           { 'type' => $top_context,
-            'parent' => $current, 'contents' => [] };
+            'parent' => $current };
     $current = $current->{'contents'}->[-1];
     print STDERR "PREFORMATTED $top_context\n" if ($self->{'DEBUG'});
   }
@@ -1418,9 +1422,9 @@ sub _end_preformatted($$$;$$)
 
   $current = _close_all_style_commands($self, $current, $line_nr,
                                        $closed_command, $interrupting_command);
-  # TODO only preformatted
-  if ($current->{'type'} and $preformatted_contexts{$current->{'type'}}) {
-    print STDERR "CLOSE PREFORMATTED $current->{'type'}\n" if 
($self->{'DEBUG'});
+
+  if ($current->{'type'} and $current->{'type'} eq 'preformatted') {
+    print STDERR "CLOSE PREFORMATTED\n" if ($self->{'DEBUG'});
     # completly remove void preformatted contexts
     if (!@{$current->{'contents'}}) {
       my $removed = pop @{$current->{'parent'}->{'contents'}};
@@ -1887,9 +1891,13 @@ sub _merge_text {
   }
 
   if (!defined($current->{'contents'})) {
-    $self->_bug_message("No contents in _merge_text", 
-                            undef, $current);
-    die;
+    # this can happen for preformatted since they do not have an initialized
+    # contents to match better the XS parser
+    #$self->_bug_message("No contents in _merge_text",
+    #                        undef, $current);
+    #cluck;
+    #die;
+    $current->{'contents'} = [];
   }
 
   if (!$no_merge_with_following_text
@@ -3276,6 +3284,17 @@ sub _end_line($$$)
       print STDERR "END COMMAND $end_command\n" if ($self->{'DEBUG'});
       my $end = pop @{$current->{'contents'}};
       if ($block_commands{$end_command} ne 'conditional') {
+        # here close some empty types.  Typically empty preformatted
+        # that would have been closed anyway in _close_commands, but
+        # also other types (rawpreformatted, before_item), some which
+        # may also have been closed anyway.
+        if (not defined($current->{'cmdname'}) and $current->{'type'}
+            and !@{$current->{'contents'}} and $current->{'parent'}) {
+           my $removed = pop @{$current->{'parent'}->{'contents'}};
+           print STDERR "popping at end command $end_command: 
$removed->{'type'}\n"
+              if ($self->{'DEBUG'});
+           $current = $current->{'parent'};
+        }
         my $closed_command;
         ($closed_command, $current)
           = _close_commands($self, $current, $line_nr, $end_command);
@@ -3313,7 +3332,7 @@ sub _end_line($$$)
            and scalar(@{$self->{'input'}}) > 1)
       # TODO remove this condition if/when the XS parser has been updated
       # to output @include with type replaced when the file was found
-        or (scalar(@{$current->{'contents'}})
+        or ($current->{'contents'} and scalar(@{$current->{'contents'}})
              and exists($current->{'contents'}->[-1]->{'type'})
              and $current->{'contents'}->[-1]->{'type'} eq 'replaced')) {
       # TODO keep the information
@@ -4370,7 +4389,6 @@ sub _parse_texi($;$)
                             {'cell_number' => $row->{'cells_count'}} };
                       push @{$row->{'contents'}}, $misc;
                       $current = $row->{'contents'}->[-1];
-                      #$current = $self->_begin_preformatted($current);
                       print STDERR "TAB\n" if ($self->{'DEBUG'});
                     }
                   } else {
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c 
b/tp/Texinfo/XS/parsetexi/end_line.c
index 3226f97e68..e086836277 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -1764,6 +1764,17 @@ end_line_misc_line (ELEMENT *current)
       if (command_data(end_id).data != BLOCK_conditional)
         {
           ELEMENT *closed_command;
+          /* here close some empty types.  Typically empty preformatted
+             that would have been closed anyway in _close_commands, but
+             also other types (rawpreformatted, before_item), some which
+             may also have been closed anyway. */
+          if (!current->cmd && current->type != ET_NONE
+              && (current->contents.number == 0) && current->parent)
+             {
+               current = current->parent;
+               destroy_element (pop_element_from_contents (current));
+               debug ("popping at end command");
+             }
           /* This closes tree elements (e.g. paragraphs) until we reach
              end_command.  It can print an error if another block command
              is found first. */
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index b13d165c2f..24bea012bf 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -509,12 +509,9 @@ end_preformatted (ELEMENT *current,
 {
   current = close_all_style_commands (current,
                                       closed_command, interrupting_command);
-  if (current->type == ET_preformatted
-      || current->type == ET_rawpreformatted)
+  if (current->type == ET_preformatted)
     {
-      debug ("CLOSE PREFORMATTED %s",
-             current->type == ET_preformatted ? "preformatted"
-                                              : "rawpreformatted");
+      debug ("CLOSE PREFORMATTED");
       if (current->contents.number == 0)
         {
           current = current->parent;
diff --git a/tp/t/results/invalid_nestings/raw_block_on_line.pl 
b/tp/t/results/invalid_nestings/raw_block_on_line.pl
index ca1189a1e7..7a239e4fe1 100644
--- a/tp/t/results/invalid_nestings/raw_block_on_line.pl
+++ b/tp/t/results/invalid_nestings/raw_block_on_line.pl
@@ -22,6 +22,10 @@ $result_trees{'raw_block_on_line'} = {
                   'text' => '
 ',
                   'type' => 'empty_line_after_command'
+                },
+                {
+                  'parent' => {},
+                  'type' => 'rawpreformatted'
                 }
               ],
               'line_nr' => {
@@ -52,6 +56,7 @@ $result_trees{'raw_block_on_line'} = {
 };
 
$result_trees{'raw_block_on_line'}{'contents'}[0]{'args'}[0]{'contents'}[0]{'contents'}[0]{'extra'}{'command'}
 = $result_trees{'raw_block_on_line'}{'contents'}[0]{'args'}[0]{'contents'}[0];
 
$result_trees{'raw_block_on_line'}{'contents'}[0]{'args'}[0]{'contents'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'raw_block_on_line'}{'contents'}[0]{'args'}[0]{'contents'}[0];
+$result_trees{'raw_block_on_line'}{'contents'}[0]{'args'}[0]{'contents'}[0]{'contents'}[1]{'parent'}
 = $result_trees{'raw_block_on_line'}{'contents'}[0]{'args'}[0]{'contents'}[0];
 
$result_trees{'raw_block_on_line'}{'contents'}[0]{'args'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'raw_block_on_line'}{'contents'}[0]{'args'}[0];
 $result_trees{'raw_block_on_line'}{'contents'}[0]{'args'}[0]{'parent'} = 
$result_trees{'raw_block_on_line'}{'contents'}[0];
 $result_trees{'raw_block_on_line'}{'contents'}[0]{'parent'} = 
$result_trees{'raw_block_on_line'};



reply via email to

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