texinfo-commits
[Top][All Lists]
Advanced

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

[7748] _complete_indices


From: gavinsmith0123
Subject: [7748] _complete_indices
Date: Sun, 23 Apr 2017 08:07:59 -0400 (EDT)

Revision: 7748
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7748
Author:   gavin
Date:     2017-04-23 08:07:59 -0400 (Sun, 23 Apr 2017)
Log Message:
-----------
_complete_indices

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

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2017-04-23 10:52:50 UTC (rev 7747)
+++ trunk/ChangeLog     2017-04-23 12:07:59 UTC (rev 7748)
@@ -1,5 +1,20 @@
 2017-04-23  Gavin Smith  <address@hidden>
 
+       * tp/Texinfo/Parser.pm (_complete_indices): New function.
+       * tp/Texinfo/Structuring.pm (do_index_keys): Move code from
+       do_index_keys to _complete_indices to complete index entries for 
+       @defop and similar, and also code to set the 'in_code' value for 
+       index entries.
+       * tp/Texinfo/Parser.pm (_parse_texi): Call it after parsing
+       the whole input.
+       * tp/Texinfo/Structuring.pm, tp/Texinfo/Parser.pm
+       (_non_bracketed_contents): Move function to Parser.pm.
+
+       * tp/texi2any.pl: Do not call do_index_keys.  This avoids a 
+       duplicate error message for an empty index entry sort key.
+
+2017-04-23  Gavin Smith  <address@hidden>
+
        * tp/maintain/regenerate_cmd_tests.sh: In test scripts generated 
        in tp/tests/test_scripts directory, include a comment saying
        it is a generated file

Modified: trunk/tp/Texinfo/Parser.pm
===================================================================
--- trunk/tp/Texinfo/Parser.pm  2017-04-23 10:52:50 UTC (rev 7747)
+++ trunk/tp/Texinfo/Parser.pm  2017-04-23 12:07:59 UTC (rev 7748)
@@ -956,6 +956,84 @@
   return $tree;
 }
 
+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;
+  }
+}
+
+# In a handful of cases, we delay storing the contents of the
+# index entry until now to avoid needing Texinfo::Report::gdt
+# in the main code of Parser.pm.  Also set 'in_code' value on
+# index entries.
+sub _complete_indices {
+  my $self = shift;
+
+  my ($index_entry, $index_contents_normalized);
+    
+  my $save_lang = $self->get_conf('documentlanguage');
+
+  foreach my $index_name (keys(%{$self->{'index_names'}})) {
+    next if !defined $self->{'index_names'}->{$index_name}->{'index_entries'};
+    foreach my $entry 
(@{$self->{'index_names'}->{$index_name}->{'index_entries'}}) {
+      $entry->{'in_code'} = $self->{'index_names'}->{$index_name}->{'in_code'};
+      
+      if (!defined $entry->{'content'}) {
+        my $def_command = $entry->{'command'}->{'extra'}->{'def_command'};
+
+        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 ($def_command eq 'defop'
+              or $def_command eq 'deftypeop'
+              or $def_command eq 'defmethod'
+              or $def_command eq 'deftypemethod') {
+            $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 ($def_command eq 'defivar'
+                   or $def_command eq 'deftypeivar'
+                   or $def_command eq 'deftypecv') {
+            $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;
+        }
+      }
+    }
+  }
+  $self->{'documentlanguage'} = $save_lang;
+}
+
 # return indices informations
 sub indices_information($)
 {
@@ -5443,6 +5521,7 @@
 
   # Call 'labels_information' to initialize labels.
   my $labels = labels_information($self);
+  _complete_indices($self);
   return $root;
 }
 

Modified: trunk/tp/Texinfo/Structuring.pm
===================================================================
--- trunk/tp/Texinfo/Structuring.pm     2017-04-23 10:52:50 UTC (rev 7747)
+++ trunk/tp/Texinfo/Structuring.pm     2017-04-23 12:07:59 UTC (rev 7748)
@@ -1401,19 +1401,6 @@
   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($$)
@@ -1421,26 +1408,22 @@
   my $self = shift;
   my $index_names = shift;
   my $parser;
+  my $ignore_chars = '';
 
-  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;
-    }
+  # FIXME: sometimes $self is a converter object, sometimes it
+  # is Texinfo::Parser.  This is very confusing.
+  if (defined $self->{'parser'}) {
+    $parser = $self->{'parser'};
+    # '-' must come first to avoid e.g. [<address@hidden looking like a 
character range
+    $ignore_chars .= '-'
+      if defined $parser->{'values'}->{'txiindexhyphenignore'};
+    $ignore_chars .= '\\\\' # string with 2 \s, for escaping inside regex
+      if defined $parser->{'values'}->{'txiindexbackslashignore'};
+    $ignore_chars .= '<'
+      if defined $parser->{'values'}->{'txiindexlessthanignore'};
+    $ignore_chars .= '@'
+      if defined $parser->{'values'}->{'txiindexatsignignore'};
   }
-  my $ignore_chars = '';
-  # '-' must come first to avoid e.g. [<address@hidden looking like a 
character range
-  $ignore_chars .= '-'
-    if defined $parser->{'values'}->{'txiindexhyphenignore'};
-  $ignore_chars .= '\\\\' # string with 2 \s, for escaping inside regex
-    if defined $parser->{'values'}->{'txiindexbackslashignore'};
-  $ignore_chars .= '<'
-    if defined $parser->{'values'}->{'txiindexlessthanignore'};
-  $ignore_chars .= '@'
-    if defined $parser->{'values'}->{'txiindexatsignignore'};
 
   my $options = {'sort_string' => 1};
   if ($self->get_conf('ENABLE_ENCODING') 
@@ -1450,59 +1433,8 @@
   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'}) {
-        my $def_command = $entry->{'command'}->{'extra'}->{'def_command'};
-
-        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 ($def_command eq 'defop'
-              or $def_command eq 'deftypeop'
-              or $def_command eq 'defmethod'
-              or $def_command eq 'deftypemethod') {
-            $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 ($def_command eq 'defivar'
-                   or $def_command eq 'deftypeivar'
-                   or $def_command eq 'deftypecv') {
-            $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'};
       if (defined $entry->{'sortas'}) {
         $entry->{'key'} = $entry->{'sortas'};
@@ -1524,7 +1456,6 @@
       utf8::upgrade($entry->{'key'});
     }
   }
-  $self->{'documentlanguage'} = $save_lang;
 }
 
 sub sort_indices($$$)

Modified: trunk/tp/texi2any.pl
===================================================================
--- trunk/tp/texi2any.pl        2017-04-23 10:52:50 UTC (rev 7747)
+++ trunk/tp/texi2any.pl        2017-04-23 12:07:59 UTC (rev 7748)
@@ -1341,8 +1341,7 @@
   if ($formats_table{$format}->{'floats'}) {
     Texinfo::Structuring::number_floats($floats);
   }
-  Texinfo::Structuring::do_index_keys ($parser,
-                                       $parser->indices_information());
+
   $error_count = handle_errors($parser, $error_count, address@hidden);
 
   if ($format eq 'structure') {




reply via email to

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