texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Transformations.pm (_protect_hashcha


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Transformations.pm (_protect_hashchar_at_line_beginning) (protect_hashchar_at_line_beginning): use a hash to mark elements that should be protected instead of modifying the tree by putting an temporary internal key in 'extra'.
Date: Wed, 28 Sep 2022 19:09:15 -0400

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 972bfbb637 * tp/Texinfo/Transformations.pm 
(_protect_hashchar_at_line_beginning) (protect_hashchar_at_line_beginning): use 
a hash to mark elements that should be protected instead of modifying the tree 
by putting an temporary internal key in 'extra'.
972bfbb637 is described below

commit 972bfbb63768929341a71f237e3ebf28dfebff38
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Sep 29 01:09:04 2022 +0200

    * tp/Texinfo/Transformations.pm (_protect_hashchar_at_line_beginning)
    (protect_hashchar_at_line_beginning): use a hash to mark elements that
    should be protected instead of modifying the tree by putting an
    temporary internal key in 'extra'.
    
    * tp/Texinfo/Transformations.pm (_print_down_menus): avoid unneeded
    autovivification.
---
 ChangeLog                     | 10 ++++++++++
 tp/Texinfo/Transformations.pm | 25 +++++++++++++++----------
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d73512ebf4..afa4da0a25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2022-09-28  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Transformations.pm (_protect_hashchar_at_line_beginning)
+       (protect_hashchar_at_line_beginning): use a hash to mark elements that
+       should be protected instead of modifying the tree by putting an
+       temporary internal key in 'extra'.
+
+       * tp/Texinfo/Transformations.pm (_print_down_menus): avoid unneeded
+       autovivification.
+
 2022-09-28   Charles Reilly  <git.2022@charlesreilly.com>  (tiny change)
 
        * info/indices (index_offset, info_index_search)
diff --git a/tp/Texinfo/Transformations.pm b/tp/Texinfo/Transformations.pm
index eda5b5e20f..d2234e2c9d 100644
--- a/tp/Texinfo/Transformations.pm
+++ b/tp/Texinfo/Transformations.pm
@@ -24,6 +24,10 @@ use 5.00405;
 
 use strict;
 
+# To check if there is no erroneous autovivification
+#no autovivification qw(fetch delete exists store strict);
+
+
 use Carp qw(cluck);
 
 use Texinfo::Common;
@@ -563,7 +567,7 @@ sub _print_down_menus($$)
       } else {
         $node_title_contents = 
Texinfo::Common::copy_contents($node->{'extra'}->{'node_content'});
       }
-      my $menu_comment = {'type' => 'menu_comment'};
+      my $menu_comment = {'type' => 'menu_comment', 'contents' => []};
       $menu_comment->{'contents'}->[0] = {'type' => 'preformatted',
                                           'parent' => $menu_comment};
     
@@ -806,13 +810,15 @@ sub _is_cpp_line($)
   return 0;
 }
 
+# An element can be marked to be protected, it will actually be protected
+# when it is processed later on by Texinfo::Common::modify_tree
 sub _protect_hashchar_at_line_beginning($$$)
 {
   my $type = shift;
   my $current = shift;
   my $argument = shift;
 
-  my ($registrar, $customization_information) = @$argument;
+  my ($registrar, $customization_information, $elements_to_protect) = 
@$argument;
 
   #print STDERR "$type $current ".debug_print_element($current)."\n";
   # if the next is a hash character at line beginning, mark it
@@ -825,7 +831,7 @@ sub _protect_hashchar_at_line_beginning($$$)
       if ($current_found) {
         #print STDERR "after $current: $content $content->{'text'}\n";
         if ($content->{'text'} and _is_cpp_line($content->{'text'})) {
-          $content->{'extra'}->{'_protect_hashchar'} = 1;
+          $elements_to_protect->{$content} = 1;
         }
         last;
       } elsif ($content eq $current) {
@@ -836,13 +842,11 @@ sub _protect_hashchar_at_line_beginning($$$)
 
   my $protect_hash = 0;
   # if marked, or first and a cpp_line protect a leading hash character
-  if ($current->{'extra'} and $current->{'extra'}->{'_protect_hashchar'}) {
-    delete $current->{'extra'}->{'_protect_hashchar'};
-    if (!scalar(keys(%{$current->{'extra'}}))) {
-      delete $current->{'extra'};
-    }
+  if ($elements_to_protect->{$current}) {
     $protect_hash = 1;
-  } elsif ($current->{'parent'} and $current->{'parent'}->{'contents'}
+    delete $elements_to_protect->{$current};
+  } elsif ($current->{'parent'}
+           and $current->{'parent'}->{'contents'}
            and $current->{'parent'}->{'contents'}->[0]
            and $current->{'parent'}->{'contents'}->[0] eq $current
            and $current->{'text'}
@@ -885,8 +889,9 @@ sub protect_hashchar_at_line_beginning($$$)
   my $customization_information = shift;
   my $tree = shift;
 
+  my $elements_to_protect = {};
   return Texinfo::Common::modify_tree($tree, 
\&_protect_hashchar_at_line_beginning,
-                                       [$registrar, 
$customization_information]);
+                      [$registrar, $customization_information, 
$elements_to_protect]);
 }
 
 1;



reply via email to

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