texinfo-commits
[Top][All Lists]
Advanced

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

[7551] delay calling Texinfo::Report::gdt for index entries


From: gavinsmith0123
Subject: [7551] delay calling Texinfo::Report::gdt for index entries
Date: Sun, 11 Dec 2016 12:26:40 +0000 (UTC)

Revision: 7551
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7551
Author:   gavin
Date:     2016-12-11 12:26:40 +0000 (Sun, 11 Dec 2016)
Log Message:
-----------
delay calling Texinfo::Report::gdt for index entries

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tp/Texinfo/Parser.pm
    trunk/tp/Texinfo/Structuring.pm

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2016-12-11 11:18:26 UTC (rev 7550)
+++ trunk/ChangeLog     2016-12-11 12:26:40 UTC (rev 7551)
@@ -1,5 +1,21 @@
 2016-12-11  Gavin Smith  <address@hidden>
 
+       * tp/Texinfo/Parser.pm (_end_line): For some index commands
+       (e.g., @defcv), do not record the text of the index entry in
+       order to avoid needing to call Texinfo::Report::gdt, which
+       would be difficult to do in the XS rewrite.  Store
+       the current document language for the index entry.
+
+       * tp/Texinfo/Structuring.pm (do_index_keys): Fill in the text
+       of the index entries where missing.  Account for the $self 
+       argument being either a Texinfo::Parser object or a converter 
+       object.
+
+       * tp/Texinfo/Parser.pm, tp/Texinfo/Structuring.pm 
+       (_non_bracketed_contents): Move function to Structuring.pm.
+
+2016-12-11  Gavin Smith  <address@hidden>
+
        * tp/Texinfo/Structuring.pm (merge_indices): Remove some 
        commented-out statements for debugging.
 

Modified: trunk/tp/Texinfo/Parser.pm
===================================================================
--- trunk/tp/Texinfo/Parser.pm  2016-12-11 11:18:26 UTC (rev 7550)
+++ trunk/tp/Texinfo/Parser.pm  2016-12-11 12:26:40 UTC (rev 7551)
@@ -2514,19 +2514,6 @@
   return 1;
 }
 
-sub _non_bracketed_contents($)
-{
-  my $current = shift;
-  if ($current->{'type'} and $current->{'type'} eq 'bracketed') {
-    my $new = {};
-    $new->{'contents'} = $current->{'contents'} if ($current->{'parent'});
-    $new->{'parent'} = $current->{'parent'} if ($current->{'parent'});
-    return $new;
-  } else {
-    return $current;
-  }
-}
-
 # store an index entry.
 # $current is the command element.
 # $content holds the actual content.
@@ -2801,37 +2788,24 @@
       if (defined($index_entry)) {
         my $index_contents_normalized;
         if ($def_parsed_hash->{'class'}) {
-          if ($command_index{$def_command} eq 'fn') {
-            $index_entry = $self->gdt('{name} on {class}', 
-                                  {'name' => $def_parsed_hash->{'name'},
-                                   'class' => $def_parsed_hash->{'class'}});
-           $index_contents_normalized
-             = [_non_bracketed_contents($def_parsed_hash->{'name'}),
-                { 'text' => ' on '},
-                _non_bracketed_contents($def_parsed_hash->{'class'})];
-          } elsif ($command_index{$def_command} eq 'vr'
+          # Delay getting the text until Texinfo::Structuring::sort_index_keys
+          # in order to avoid using gdt.
+          # We need to store the language as well in case there are multiple
+          # languages in the document.
+          if ($command_index{$def_command} eq 'fn'
+              or $command_index{$def_command} eq 'vr'
                   and $def_command ne 'defcv') {
-            $index_entry = $self->gdt('{name} of {class}', 
-                                     {'name' => $def_parsed_hash->{'name'},
-                                     'class' => $def_parsed_hash->{'class'}});
-            $index_contents_normalized
-              = [_non_bracketed_contents($def_parsed_hash->{'name'}),
-                 { 'text' => ' of '},
-                 _non_bracketed_contents($def_parsed_hash->{'class'})];
+            undef $index_entry;
+            $current->{'parent'}->{'extra'}->{'documentlanguage'}
+                     = $self->{'documentlanguage'};
           }
         }
-        $index_contents_normalized = [$index_entry]
-          if (!defined($index_contents_normalized));
         my $index_contents;
-        # 'root_line' is the container returned by gdt.
-        if ($index_entry->{'type'} and $index_entry->{'type'} eq 'root_line') {
-          $index_contents = $index_entry->{'contents'};
-          for my $child (@$index_contents) {
-            delete $child->{'parent'};
-          }
-        } else {
+        if ($index_entry) {
+          $index_contents_normalized = [$index_entry];
           $index_contents = [$index_entry];
         }
+
         _enter_index_entry($self, 
           $current->{'parent'}->{'extra'}->{'def_command'},
           $current->{'parent'}->{'extra'}->{'original_def_cmdname'},

Modified: trunk/tp/Texinfo/Structuring.pm
===================================================================
--- trunk/tp/Texinfo/Structuring.pm     2016-12-11 11:18:26 UTC (rev 7550)
+++ trunk/tp/Texinfo/Structuring.pm     2016-12-11 12:26:40 UTC (rev 7551)
@@ -1401,12 +1401,26 @@
   return $res;
 }
 
+sub _non_bracketed_contents($)
+{
+  my $current = shift;
+  if ($current->{'type'} and $current->{'type'} eq 'bracketed') {
+    my $new = {};
+    $new->{'contents'} = $current->{'contents'} if ($current->{'parent'});
+    $new->{'parent'} = $current->{'parent'} if ($current->{'parent'});
+    return $new;
+  } else {
+    return $current;
+  }
+}
+
 # Go through all the index entries and set 'key', the sort key, on
 # each one.
 sub do_index_keys($$)
 {
   my $self = shift;
   my $index_names = shift;
+  my $parser;
 
   my $options = {'sort_string' => 1};
   if ($self->get_conf('ENABLE_ENCODING') 
@@ -1415,8 +1429,65 @@
   }
   my %convert_text_options = Texinfo::Common::_convert_text_options($self);
   $options = {%$options, %convert_text_options};
+
+  my ($index_entry, $index_contents_normalized);
+    
+  my $save_lang = $self->get_conf('documentlanguage');
   foreach my $index_name (keys(%$index_names)) {
     foreach my $entry (@{$index_names->{$index_name}->{'index_entries'}}) {
+     # In a handful of cases, we delay storing the contents of the
+      # index entry until now to avoid needing Texinfo::Report::gdt
+      # in Parser.pm.
+      if (!defined $entry->{'content'}) {
+        if (!defined $parser) {
+          # FIXME: sometimes $self is a converter object, sometimes it
+          # is Texinfo::Parser.  This is very confusing.
+          if (defined $self->{'parser'}) {
+            $parser = $self->{'parser'};
+          } else {
+            $parser = $self;
+          }
+        }
+        my $def_command = $entry->{'command'}->{'extra'}->{'def_command'};
+        my $command_index = $parser->{'command_index'};
+
+        my $def_parsed_hash = 
$entry->{'command'}->{'extra'}->{'def_parsed_hash'}; 
+        if ($def_parsed_hash and $def_parsed_hash->{'class'}
+            and $def_command) {
+          # Use the document language that was current when the command was
+          # used for getting the translation.
+          $self->{'documentlanguage'} = 
$entry->{'command'}->{'extra'}->{'documentlanguage'};
+          delete $entry->{'command'}->{'extra'}->{'documentlanguage'};
+          if ($command_index->{$def_command} eq 'fn') {
+            $index_entry = $self->gdt('{name} on {class}',
+                                  {'name' => $def_parsed_hash->{'name'},
+                                   'class' => $def_parsed_hash->{'class'}});
+           $index_contents_normalized
+             = [_non_bracketed_contents($def_parsed_hash->{'name'}),
+                { 'text' => ' on '},
+                _non_bracketed_contents($def_parsed_hash->{'class'})];
+          } elsif ($command_index->{$def_command} eq 'vr'
+                  and $def_command ne 'defcv') {
+            $index_entry = $self->gdt('{name} of {class}',
+                                     {'name' => $def_parsed_hash->{'name'},
+                                     'class' => $def_parsed_hash->{'class'}});
+            $index_contents_normalized
+              = [_non_bracketed_contents($def_parsed_hash->{'name'}),
+                 { 'text' => ' of '},
+                 _non_bracketed_contents($def_parsed_hash->{'class'})];
+          }
+        }
+        # 'root_line' is the container returned by gdt.
+        if ($index_entry->{'type'} and $index_entry->{'type'} eq 'root_line') {
+          for my $child (@{$index_entry->{'contents'}}) {
+            delete $child->{'parent'};
+          }
+        }
+        if ($index_entry->{'contents'}) {
+          $entry->{'content'} = address@hidden>{'contents'}}];
+          $entry->{'content_normalized'} = $index_contents_normalized;
+        }
+      }
       $entry->{'in_code'} = 
$index_names->{$entry->{'index_name'}}->{'in_code'};
       $options->{'code'} = $entry->{'in_code'};
       $entry->{'key'} = Texinfo::Convert::Text::convert(
@@ -1432,6 +1503,7 @@
       utf8::upgrade($entry->{'key'});
     }
   }
+  $self->{'documentlanguage'} = $save_lang;
 }
 
 sub sort_indices($$$)




reply via email to

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