texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Common.pm (lookup_index_entry) (_rel


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Common.pm (lookup_index_entry) (_relate_index_entries_to_table_items_in) (_relate_index_entries_to_table_items) (relate_index_entries_to_table_items_in_tree), tp/Texinfo/Convert/DocBook.pm (_index_entry), tp/Texinfo/Convert/LaTeX.pm (_index_entry), tp/Texinfo/Convert/TexinfoMarkup.pm (_index_entry, _convert), tp/t/test_utils.pl (test), tp/texi2any.pl: add the lookup_index_entry function, to find an index entry based on the extra index_entry key, that abstracts how the index en [...]
Date: Mon, 06 Mar 2023 16:34:42 -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 c9377f35f8 * tp/Texinfo/Common.pm (lookup_index_entry) 
(_relate_index_entries_to_table_items_in) 
(_relate_index_entries_to_table_items) 
(relate_index_entries_to_table_items_in_tree), tp/Texinfo/Convert/DocBook.pm 
(_index_entry), tp/Texinfo/Convert/LaTeX.pm (_index_entry), 
tp/Texinfo/Convert/TexinfoMarkup.pm (_index_entry, _convert), 
tp/t/test_utils.pl (test), tp/texi2any.pl: add the lookup_index_entry function, 
to find an index entry based on the extra index_entry key, that abstr [...]
c9377f35f8 is described below

commit c9377f35f807d0d4aa80e750346f203493d8624c
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Mar 6 22:34:32 2023 +0100

    * tp/Texinfo/Common.pm (lookup_index_entry)
    (_relate_index_entries_to_table_items_in)
    (_relate_index_entries_to_table_items)
    (relate_index_entries_to_table_items_in_tree),
    tp/Texinfo/Convert/DocBook.pm (_index_entry),
    tp/Texinfo/Convert/LaTeX.pm (_index_entry),
    tp/Texinfo/Convert/TexinfoMarkup.pm (_index_entry, _convert),
    tp/t/test_utils.pl (test), tp/texi2any.pl: add the lookup_index_entry
    function, to find an index entry based on the extra index_entry key,
    that abstracts how the index entry is found.  The function requires
    the indices information too.
    Pass the indices information to
    _relate_index_entries_to_table_items_in through
    relate_index_entries_to_table_items_in_tree.
    
    * tp/Texinfo/Structuring.pm (merge_indices), tp/t/automatic_nodes.t,
    tp/t/test_sort.t, tp/t/test_utils.pl (test): change name of
    $index_names to $indices_information.
    
    * tp/Texinfo/Convert/Plaintext.pm (_convert): use index_entry_command
    type to determine that the commmand is an index entry command instead
    of using the command name.
---
 ChangeLog                           | 25 +++++++++++++++++++++++
 tp/Texinfo/Common.pm                | 40 +++++++++++++++++++++++++++++++------
 tp/Texinfo/Convert/DocBook.pm       |  4 +++-
 tp/Texinfo/Convert/LaTeX.pm         |  4 +++-
 tp/Texinfo/Convert/Plaintext.pm     |  4 ++--
 tp/Texinfo/Convert/TexinfoMarkup.pm |  9 +++++++--
 tp/Texinfo/ParserNonXS.pm           |  4 ++--
 tp/Texinfo/Structuring.pm           | 16 +++++++--------
 tp/t/automatic_nodes.t              | 32 +++++------------------------
 tp/t/test_sort.t                    |  8 ++++----
 tp/t/test_utils.pl                  |  9 +++++----
 tp/texi2any.pl                      |  4 +++-
 12 files changed, 101 insertions(+), 58 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 33b020f92f..263b3cd108 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2023-03-06  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Common.pm (lookup_index_entry)
+       (_relate_index_entries_to_table_items_in)
+       (_relate_index_entries_to_table_items)
+       (relate_index_entries_to_table_items_in_tree),
+       tp/Texinfo/Convert/DocBook.pm (_index_entry),
+       tp/Texinfo/Convert/LaTeX.pm (_index_entry),
+       tp/Texinfo/Convert/TexinfoMarkup.pm (_index_entry, _convert),
+       tp/t/test_utils.pl (test), tp/texi2any.pl: add the lookup_index_entry
+       function, to find an index entry based on the extra index_entry key,
+       that abstracts how the index entry is found.  The function requires
+       the indices information too.
+       Pass the indices information to
+       _relate_index_entries_to_table_items_in through
+       relate_index_entries_to_table_items_in_tree.
+
+       * tp/Texinfo/Structuring.pm (merge_indices), tp/t/automatic_nodes.t,
+       tp/t/test_sort.t, tp/t/test_utils.pl (test): change name of
+       $index_names to $indices_information.
+
+       * tp/Texinfo/Convert/Plaintext.pm (_convert): use index_entry_command
+       type to determine that the commmand is an index entry command instead
+       of using the command name.
+
 2023-03-06  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Common.pm (_relate_index_entries_to_table_items_in),
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 8235404075..47fe6fc1d2 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -1424,6 +1424,25 @@ sub set_global_document_command($$$$)
   return $element;
 }
 
+# TODO document
+sub lookup_index_entry($$)
+{
+  my $index_entry_info = shift;
+  my $indices_information = shift;
+
+  my $entry_index_name = $index_entry_info->{'index_name'};
+  my $entry_number = $index_entry_info->{'entry_number'};
+
+  if ($indices_information->{$entry_index_name}
+      and $indices_information->{$entry_index_name}->{'index_entries'}
+      and $indices_information->{$entry_index_name}
+                                    ->{'index_entries'}->[$entry_number-1]) {
+    return $indices_information->{$entry_index_name}
+                                    ->{'index_entries'}->[$entry_number-1];
+  }
+  return undef;
+}
+
 sub set_output_encodings($$)
 {
   my $customization_information = shift;
@@ -2375,9 +2394,10 @@ sub move_index_entries_after_items_in_tree($)
 
 # Locates all @tables in the tree, and relocates index entry groups to be
 # related to the @item that immediately follows them.
-sub _relate_index_entries_to_table_items_in($)
+sub _relate_index_entries_to_table_items_in($$)
 {
   my $table = shift;
+  my $indices_information = shift;
 
   return unless $table->{'contents'};
 
@@ -2396,7 +2416,11 @@ sub _relate_index_entries_to_table_items_in($)
     foreach my $content (@{$term->{'contents'}}) {
       if ($content->{'type'}
           and $content->{'type'} eq 'index_entry_command') {
-        $index = $content->{'extra'}->{'index_entry'} unless $index;
+        $index
+          = Texinfo::Common::lookup_index_entry(
+                          $content->{'extra'}->{'index_entry'},
+                          $indices_information)
+            unless $index;
       } elsif ($content->{'cmdname'} and $content->{'cmdname'} eq 'item') {
         $item = $content unless $item;
       }
@@ -2412,24 +2436,28 @@ sub _relate_index_entries_to_table_items_in($)
   }
 }
 
-sub _relate_index_entries_to_table_items($$)
+sub _relate_index_entries_to_table_items($$$)
 {
   my $type = shift;
   my $current = shift;
+  my $indices_information = shift;
 
   return $current unless $current->{'cmdname'};
 
   if ($current->{'cmdname'} eq 'table') {
-    _relate_index_entries_to_table_items_in($current);
+    _relate_index_entries_to_table_items_in($current, $indices_information);
   }
 
   return $current;
 }
 
-sub relate_index_entries_to_table_items_in_tree($)
+sub relate_index_entries_to_table_items_in_tree($$)
 {
   my $tree = shift;
-  return modify_tree($tree, \&_relate_index_entries_to_table_items);
+  my $indices_information = shift;
+
+  return modify_tree($tree, \&_relate_index_entries_to_table_items,
+                     $indices_information);
 }
 
 # Common to different module, but not meant to be used in user-defined
diff --git a/tp/Texinfo/Convert/DocBook.pm b/tp/Texinfo/Convert/DocBook.pm
index c9e934f080..d31c7e5a84 100644
--- a/tp/Texinfo/Convert/DocBook.pm
+++ b/tp/Texinfo/Convert/DocBook.pm
@@ -575,7 +575,9 @@ sub _index_entry($$)
   my $self = shift;
   my $element = shift;
   if ($element->{'extra'} and $element->{'extra'}->{'index_entry'}) {
-    my $index_entry = $element->{'extra'}->{'index_entry'};
+    my $index_entry
+     = 
Texinfo::Common::lookup_index_entry($element->{'extra'}->{'index_entry'},
+                                           $self->{'indices_information'});
     # FIXME DocBook 5 role->type
     my $result = "<indexterm role=\"$index_entry->{'index_name'}\">";
 
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index cb0e5b8894..470528259a 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -2409,7 +2409,9 @@ sub _index_entry($$)
   my $self = shift;
   my $element = shift;
   if ($element->{'extra'} and $element->{'extra'}->{'index_entry'}) {
-    my $entry = $element->{'extra'}->{'index_entry'};
+    my $entry
+     = 
Texinfo::Common::lookup_index_entry($element->{'extra'}->{'index_entry'},
+                                           $self->{'indices_information'});
     my $entry_index_name = $entry->{'index_name'};
     my $index_name = $entry_index_name;
     if ($self->{'indices_information'}->{$entry_index_name}->{'merged_in'}) {
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index a8ea928d7a..6d37dca520 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -1821,7 +1821,7 @@ sub _convert($$)
     my $location = $self->add_location($element);
     # remove a 'lines' from $location if at the very end of a node
     # since it will lead to the next node otherwise.
-    if ($command and $command =~ /index/) {
+    if ($element->{'type'} and $element->{'type'} eq 'index_entry_command') {
       my $following_not_empty;
       my @parents = @{$self->{'current_roots'}};
       my @parent_contents = @{$self->{'current_contents'}};
@@ -3004,7 +3004,7 @@ sub _convert($$)
     }
     if ($unknown_command
         and !($element->{'type'}
-                and ($element->{'type'} eq 'index_entry_command'))
+              and ($element->{'type'} eq 'index_entry_command'))
         # commands like def*x are not processed above, since only the def_line
         # associated is processed. If they have no name and no category they
         # are not considered as index entries either so they have a specific
diff --git a/tp/Texinfo/Convert/TexinfoMarkup.pm 
b/tp/Texinfo/Convert/TexinfoMarkup.pm
index ab4eeda3b5..8aeba3afea 100644
--- a/tp/Texinfo/Convert/TexinfoMarkup.pm
+++ b/tp/Texinfo/Convert/TexinfoMarkup.pm
@@ -368,7 +368,9 @@ sub _index_entry($$)
   my $self = shift;
   my $element = shift;
   if ($element->{'extra'} and $element->{'extra'}->{'index_entry'}) {
-    my $index_entry = $element->{'extra'}->{'index_entry'};
+    my $index_entry
+     = 
Texinfo::Common::lookup_index_entry($element->{'extra'}->{'index_entry'},
+                                           $self->{'indices_information'});
     my $attribute = [['index', $index_entry->{'index_name'}]];
     push @$attribute, ['number', $index_entry->{'entry_number'}]
         if (defined($index_entry->{'entry_number'}));
@@ -751,6 +753,9 @@ sub _convert($$;$)
       } # otherwise we have an incorrect construct, for instance
         # out of block commands @item, @itemx in enumerate or multitable...
     } elsif ($element->{'type'} and $element->{'type'} eq 
'index_entry_command') {
+      my $index_entry
+        = 
Texinfo::Common::lookup_index_entry($element->{'extra'}->{'index_entry'},
+                                              $self->{'indices_information'});
       my $format_element;
       my $attribute = [];
       if (exists $line_commands{$element->{'cmdname'}}) {
@@ -760,7 +765,7 @@ sub _convert($$;$)
         $attribute = [['command', $element->{'cmdname'}]];
       }
       push @$attribute, ['index',
-                         $element->{'extra'}->{'index_entry'}->{'index_name'}];
+                         $index_entry->{'index_name'}];
       push @$attribute, _leading_spaces_arg($element);
 
       # this is important to get the spaces before a @subentry
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index f5c2cef422..76e2fc89f6 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -7494,7 +7494,7 @@ Texinfo::Parser - Parse Texinfo code into a Perl tree
     warn $error_message->{'error_line'};
   }
 
-  my $index_names = $parser->indices_information();
+  my $indices_information = $parser->indices_information();
   my $float_types_arrays = $parser->floats_information();
   my $internal_references_array
     = $parser->internal_references_information();
@@ -7787,7 +7787,7 @@ also available through the C<indices_information> method.
 =item indices_information
 X<C<indices_information>>
 
-  $index_names = indices_information($parser);
+  $indices_information = indices_information($parser);
 
 The index names is a hash reference.  The keys are
 
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index 8dd947d1d2..3020fc2a29 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -2084,17 +2084,17 @@ sub sort_indices($$$;$$)
 
 sub merge_indices($)
 {
-  my $index_names = shift;
+  my $indices_information = shift;
 
   my $merged_index_entries;
-  foreach my $index_name (keys(%$index_names)) {
-    my $index_info = $index_names->{$index_name};
+  foreach my $index_name (keys(%$indices_information)) {
+    my $index_info = $indices_information->{$index_name};
     next if ($index_info->{'merged_in'});
     foreach my $contained_index (keys (%{$index_info->{'contained_indices'}})) 
{
-      if ($index_names->{$contained_index}->{'index_entries'}) {
+      if ($indices_information->{$contained_index}->{'index_entries'}) {
         $merged_index_entries = {} if (! $merged_index_entries);
         push @{$merged_index_entries->{$index_name}},
-          @{$index_names->{$contained_index}->{'index_entries'}};
+          @{$indices_information->{$contained_index}->{'index_entries'}};
       }
     }
   }
@@ -2144,9 +2144,9 @@ Texinfo::Structuring - information on Texinfo::Parser tree
   elements_directions($config, $labels, $tree_units);
   elements_file_directions($tree_units);
 
-  my $index_names = $parser->indices_information();
+  my $indices_information = $parser->indices_information();
   my $merged_index_entries
-     = merge_indices($index_names);
+     = merge_indices($indices_information);
   my $index_entries_sorted;
   if ($sort_by_letter) {
     $index_entries_sorted = sort_indices($registrar, $config,
@@ -2330,7 +2330,7 @@ I<$options> are options used for Texinfo to text 
conversion for
 the generation of the sort string, typically obtained from
 L<setup_index_entry_keys_formatting|/$option = 
setup_index_entry_keys_formatting($customization_information)>.
 
-=item $merged_entries = merge_indices($index_names)
+=item $merged_entries = merge_indices($indices_information)
 X<C<merge_indices>>
 
 Using information returned by L<Texinfo::Parser/indices_information>,
diff --git a/tp/t/automatic_nodes.t b/tp/t/automatic_nodes.t
index 8faf924de4..c714b0a177 100644
--- a/tp/t/automatic_nodes.t
+++ b/tp/t/automatic_nodes.t
@@ -193,7 +193,7 @@ 
Texinfo::Structuring::associate_internal_references($registrar, $parser,
    = Texinfo::Transformations::insert_nodes_for_sectioning_commands($tree,
                                         $nodes_list, $targets_list, $labels);
 $tree->{'contents'} = $new_content;
-my ($index_names, $merged_indices) = $parser->indices_information();
+my ($indices_information, $merged_indices) = $parser->indices_information();
 ok (($labels->{'chap'}->{'extra'}->{'menus'} and 
@{$labels->{'chap'}->{'extra'}->{'menus'}}
      and scalar(@{$labels->{'chap'}->{'extra'}->{'menus'}}) == 1
      and !exists($labels->{'Top'}->{'extra'}->{'menus'})), 'new node has a 
menu');
@@ -202,32 +202,10 @@ is 
(Texinfo::Convert::Texinfo::convert_to_texinfo($labels->{'chap'}->{'extra'}->
 * (some_manual)::
 @end menu
 ', 'reassociated menu is correct');
-#print STDERR join('|', keys(%{$index_names->{'cp'}->{'index_entries'}}))."\n";
-is ($labels->{'chap'}, $index_names->{'cp'}->{'index_entries'}->[0]
-                                
->{'entry_element'}->{'extra'}->{'element_node'},
+#print STDERR join('|',
+#               keys(%{$indices_information->{'cp'}->{'index_entries'}}))."\n";
+is ($labels->{'chap'}, $indices_information->{'cp'}->{'index_entries'}->[0]
+                              ->{'entry_element'}->{'extra'}->{'element_node'},
   'index entry reassociated');
 #print STDERR Texinfo::Convert::Texinfo::convert_to_texinfo($tree);
 
-# Note: this test doesn't pass anymore because we only notice duplicate
-# nodes at the end.
-# $parser = Texinfo::Parser::parser();
-# my $text_duplicate_nodes =
-# '@node NAME
-# @section DESCRIPTION
-# 
-# @node NAME
-# @section SEE ALSO
-# 
-# @cindex entry
-# ';
-# $tree = $parser->parse_texi_piece($text_duplicate_nodes);
-# # In fact, here we also check that there is no debugging message...
-# ($labels, $targets_list, $nodes_list) = $parser->labels_information();
-# ($new_content, $added_nodes)
-#    = Texinfo::Transformations::insert_nodes_for_sectioning_commands($tree,
-#                                       $nodes_list, $targets_list, $labels);
-# ($index_names, $merged_indices) = $parser->indices_information();
-# ($labels, $targets_list, $nodes_list) = $parser->labels_information();
-# is ($labels->{'SEE-ALSO'}, 
$index_names->{'cp'}->{'index_entries'}->[0]->{'entry_node'},
-#   'index entry reassociated duplicate node ignored');
-
diff --git a/tp/t/test_sort.t b/tp/t/test_sort.t
index 14eb506aa6..029c560a0b 100644
--- a/tp/t/test_sort.t
+++ b/tp/t/test_sort.t
@@ -43,8 +43,8 @@ $tree = $parser->parse_texi_text('@node Top
 ');
 
 my $registrar = $parser->registered_errors();
-my ($index_names, $merged_indices) = $parser->indices_information();
-my $index_entries = Texinfo::Structuring::merge_indices($index_names);
+my ($indices_information, $merged_indices) = $parser->indices_information();
+my $index_entries = Texinfo::Structuring::merge_indices($indices_information);
 my $parser_information = $parser->global_information();
 my $main_configuration = Texinfo::MainConfig::new({'ENABLE_ENCODING' => 1});
 Texinfo::Common::set_output_encodings($main_configuration, 
$parser_information);
@@ -120,8 +120,8 @@ $tree = $parser->parse_texi_text('@node Top
 ');
 
 $registrar = $parser->registered_errors();
-($index_names, $merged_indices) = $parser->indices_information();
-$index_entries = Texinfo::Structuring::merge_indices($index_names);
+($indices_information, $merged_indices) = $parser->indices_information();
+$index_entries = Texinfo::Structuring::merge_indices($indices_information);
 ($sorted_index_entries, $index_entries_sort_strings)
   = Texinfo::Structuring::sort_indices($registrar, $main_configuration,
                                        $index_entries);
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index e083effc69..f4cf47d942 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -1072,8 +1072,10 @@ sub test($$)
     $main_configuration->set_conf('novalidate', 1);
   }
 
+  my $indices_information = $parser->indices_information();
   if ($tree_transformations{'relate_index_entries_to_items'}) {
-    Texinfo::Common::relate_index_entries_to_table_items_in_tree($tree);
+    Texinfo::Common::relate_index_entries_to_table_items_in_tree($tree,
+                                                     $indices_information);
   }
 
   if ($tree_transformations{'move_index_entries_after_items'}) {
@@ -1144,15 +1146,14 @@ sub test($$)
   Texinfo::Structuring::number_floats($floats);
 
   my ($errors, $error_nrs) = $registrar->errors();
-  my $index_names = $parser->indices_information();
   # FIXME maybe it would be good to compare $merged_index_entries?
   my $merged_index_entries
-     = Texinfo::Structuring::merge_indices($index_names);
+     = Texinfo::Structuring::merge_indices($indices_information);
   
   # only print indices information if it differs from the default
   # indices
   my $indices;
-  my $trimmed_index_names = remove_keys($index_names, ['index_entries']);
+  my $trimmed_index_names = remove_keys($indices_information, 
['index_entries']);
   $indices = {'index_names' => $trimmed_index_names}
     unless (Data::Compare::Compare($trimmed_index_names, 
$initial_index_names));
 
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index 409c953b58..8d7af9554d 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1496,7 +1496,9 @@ while(@input_files) {
 
   if 
($formats_table{$converted_format}->{'relate_index_entries_to_table_items'}
       or $tree_transformations{'relate_index_entries_to_table_items'}) {
-    Texinfo::Common::relate_index_entries_to_table_items_in_tree($tree);
+    my $indices_information = $parser->indices_information();
+    Texinfo::Common::relate_index_entries_to_table_items_in_tree($tree,
+                                                          
$indices_information);
   }
 
   if ($formats_table{$converted_format}->{'move_index_entries_after_items'}



reply via email to

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