texinfo-commits
[Top][All Lists]
Advanced

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

[7500] delay node name normalization


From: gavinsmith0123
Subject: [7500] delay node name normalization
Date: Wed, 9 Nov 2016 00:29:28 +0000 (UTC)

Revision: 7500
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7500
Author:   gavin
Date:     2016-11-09 00:29:28 +0000 (Wed, 09 Nov 2016)
Log Message:
-----------
delay node name normalization

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tp/Texinfo/Common.pm
    trunk/tp/Texinfo/Convert/HTML.pm
    trunk/tp/Texinfo/Parser.pm
    trunk/tp/Texinfo/Structuring.pm
    trunk/tp/Texinfo/Transformations.pm
    trunk/tp/t/automatic_nodes.t

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2016-11-07 20:29:49 UTC (rev 7499)
+++ trunk/ChangeLog     2016-11-09 00:29:28 UTC (rev 7500)
@@ -1,3 +1,37 @@
+2016-11-08  Gavin Smith  <address@hidden>
+
+       Delay node name normalization until after parser is finished.
+
+       * tp/Texinfo/Common.pm (parse_node_manual): Do not record 
+       'normalized' value in return value.
+       (%default_parser_state_configuration): Add array value 'targets'.
+
+       * tp/Texinfo/Convert/HTML.pm (_parse_node_and_warn_external):
+       Call 'normalize_node' and set 'normalized' value on return value.
+
+       * tp/Texinfo/Parser.pm
+       (_register_label): Store target in 'targets' array, instead
+       of in 'labels' hash.  Don't do any error checking.
+       (labels_information): If 'labels' hash is not already set on 
+       parser object, generate it from the 'targets' array.  Check for 
+       empty and duplicate node names.  Create 'nodes' array.
+       (_check_empty_node): Remove check for empty node name after
+       expansion.
+
+       (_end_line) <@float, @node>: Always call _register_label, with
+       less error checking.  Do not record node in 'nodes' array.
+
+       * tp/Texinfo/Transformations.pm (_new_node): Set 'normalized'
+       for the new node that is being created, and store it in the
+       'labels' hash.
+       * tp/Texinfo/Structuring.pm (nodes_tree)
+       (associate_internal_references, new_node_menu_entry): Set 
+       'normalized' values on tree elements.
+
+       * tp/t/automatic_nodes.t: Add several calls to 
+       'associate_internal_references'.
+       (index entry reassociated duplicate node ignored): Disable test.
+
 2016-11-07  Gavin Smith  <address@hidden>
 
        * info/indices.c (create_virtual_index): Split function out from

Modified: trunk/tp/Texinfo/Common.pm
===================================================================
--- trunk/tp/Texinfo/Common.pm  2016-11-07 20:29:49 UTC (rev 7499)
+++ trunk/tp/Texinfo/Common.pm  2016-11-09 00:29:28 UTC (rev 7500)
@@ -122,6 +122,7 @@
   'labels'          => {},    # keys are normalized label names, as described
                               # in the `HTML Xref' node.  Value should be
                               # a node/anchor or float in the tree.
+  'targets' => [],            # array of elements used to build 'labels'
   'macros' => {},             # the key is the user-defined macro name.  The 
                               # value is the reference on a macro element 
                               # as obtained by parsing the @macro
@@ -1404,14 +1405,12 @@
   return $braces_count;
 }
 
-# $NODE->{'contents'} is the Texinfo fo the specification of a node.
-# Returned object is a hash with three fields:
+# $NODE->{'contents'} is the Texinfo for the specification of a node.
+# Returned object is a hash with two fields:
 #
 #     manual_content - Texinfo tree for a manual name extracted from the
 #                      node specification.
 #     node_content - Texinfo tree for the node name on its own
-#     normalized - a string with the node name after HTML node name
-#                  normalization is applied
 #
 # retrieve a leading manual name in parentheses, if there is one.
 sub parse_node_manual($)
@@ -1464,8 +1463,6 @@
   }
   if (@contents) {
     $result->{'node_content'} = address@hidden;
-    $result->{'normalized'} =
-      Texinfo::Convert::NodeNameNormalization::normalize_node({'contents' => 
address@hidden);
   }
   return $result;
 }

Modified: trunk/tp/Texinfo/Convert/HTML.pm
===================================================================
--- trunk/tp/Texinfo/Convert/HTML.pm    2016-11-07 20:29:49 UTC (rev 7499)
+++ trunk/tp/Texinfo/Convert/HTML.pm    2016-11-09 00:29:28 UTC (rev 7500)
@@ -7232,6 +7232,11 @@
          $node_texi), $line_nr);
 
     } else {
+      if ($node_normalized_result->{'node_content'}) {
+        $node_normalized_result->{'normalized'} =
+          Texinfo::Convert::NodeNameNormalization::normalize_node(
+            {'contents' => $node_normalized_result->{'node_content'}});
+      }
       return $node_normalized_result;
     }
   }

Modified: trunk/tp/Texinfo/Parser.pm
===================================================================
--- trunk/tp/Texinfo/Parser.pm  2016-11-07 20:29:49 UTC (rev 7499)
+++ trunk/tp/Texinfo/Parser.pm  2016-11-09 00:29:28 UTC (rev 7500)
@@ -989,9 +989,70 @@
   return $self->{'info'};
 }
 
+# Setup labels and nodes info and return labels
 sub labels_information($)
 {
   my $self = shift;
+  if (!%{$self->{'labels'}}
+       and defined $self->{'targets'}) {
+    my %labels = ();
+    for my $target (@{$self->{'targets'}}) {
+      if ($target->{'cmdname'} eq 'node') {
+        if ($target->{'extra'}->{'nodes_manuals'}) {
+          for my $node_manual (@{$target->{'extra'}{'nodes_manuals'}}) {
+            if (defined $node_manual
+                  and defined $node_manual->{'node_content'}) {
+              my $normalized = 
Texinfo::Convert::NodeNameNormalization::normalize_node({'contents' => 
$node_manual->{'node_content'}});
+              $node_manual->{'normalized'} = $normalized;
+            }
+          }
+        }
+      }
+      if (defined $target->{'extra'}->{'node_content'}) {
+        my $normalized = 
Texinfo::Convert::NodeNameNormalization::normalize_node({'contents' => 
$target->{'extra'}->{'node_content'}});
+
+        if ($normalized !~ /[^-]/) {
+          $self->line_error (sprintf($self->__("empty node name after 
expansion `%s'"),
+                Texinfo::Convert::Texinfo::convert({'contents' 
+                               => $target->{'extra'}->{'node_content'}})), 
+                $target->{'line_nr'});
+          delete $target->{'extra'}->{'node_content'};
+        } else {
+          if (defined $labels{$normalized}) {
+            $self->line_error(
+              sprintf($self->__("address@hidden `%s' previously defined"), 
+                         $target->{'cmdname'}, 
+                   Texinfo::Convert::Texinfo::convert({'contents' => 
+                       $target->{'extra'}->{'node_content'}})), 
+                           $target->{'line_nr'});
+            $self->line_error(
+              sprintf($self->__("here is the previous definition as 
address@hidden"),
+                               $labels{$normalized}->{'cmdname'}),
+                       $labels{$normalized}->{'line_nr'});
+            delete $target->{'extra'}->{'node_content'};
+          } else {
+            $labels{$normalized} = $target;
+            $target->{'extra'}->{'normalized'} = $normalized;
+            if ($target->{'cmdname'} eq 'node') {
+              if ($target->{'extra'}
+                  and $target->{'extra'}{'node_argument'}) {
+                $target->{'extra'}{'node_argument'}{'normalized'}
+                  = $normalized;
+              }
+              push @{$self->{'nodes'}}, $target;
+            }
+          }
+        }
+      } else {
+        if ($target->{'cmdname'} eq 'node') {
+          $self->line_error (sprintf($self->__("empty argument in 
address@hidden"),
+                  $target->{'cmdname'}), $target->{'line_nr'});
+          delete $target->{'extra'}->{'node_content'};
+        }
+      }
+    }
+    $self->{'labels'} = \%labels;
+  }
   return $self->{'labels'};
 }
 
@@ -2443,22 +2504,13 @@
   my $line_nr = shift;
   my $normalized = $label->{'normalized'};
 
-  if ($self->{'labels'}->{$normalized}) {
-    $self->line_error(sprintf($self->__("address@hidden `%s' previously 
defined"), 
-                         $current->{'cmdname'}, 
-                   Texinfo::Convert::Texinfo::convert({'contents' => 
-                                                $label->{'node_content'}})), 
-                           $line_nr);
-    $self->line_error(sprintf($self->__("here is the previous definition as 
address@hidden"),
-                               $self->{'labels'}->{$normalized}->{'cmdname'}),
-                       $self->{'labels'}->{$normalized}->{'line_nr'});
-    return 0;
-  } else {
-    $current->{'extra'}->{'normalized'} = $normalized;
+  if ($label->{'node_content'}) {
     $current->{'extra'}->{'node_content'} = $label->{'node_content'};
-    $self->{'labels'}->{$normalized} = $current;
-    return 1;
   }
+
+  push @{$self->{'targets'}}, $current;
+
+  return 1;
 }
 
 sub _non_bracketed_contents($)
@@ -2866,14 +2918,12 @@
       $float->{'line_nr'} = $line_nr;
       my $type = '';
       if (@{$float->{'args'}}) {
+        my $float_label;
         if ($float->{'args'}->[1]) {
-          my $float_label = _parse_node_manual($float->{'args'}->[1]);
+          $float_label = _parse_node_manual($float->{'args'}->[1]);
           _check_internal_node($self, $float_label, $line_nr);
-          if (defined($float_label) and $float_label->{'node_content'}
-             and $float_label->{'normalized'} =~ /[^-]/) {
-            _register_label($self, $float, $float_label, $line_nr);
-          }
         }
+        _register_label($self, $float, $float_label, $line_nr);
         _parse_float_type($float);
         $type = $float->{'extra'}->{'type'}->{'normalized'};
       }
@@ -3200,14 +3250,12 @@
         my $node = _parse_node_manual($arg);
         push @{$current->{'extra'}->{'nodes_manuals'}}, $node;
       }
-      if (_check_node_label($self, $current->{'extra'}->{'nodes_manuals'}->[0],
-                        $command, $line_nr)) {
-        if (_register_label($self, $current, 
-                    $current->{'extra'}->{'nodes_manuals'}->[0], $line_nr)) {
-          $self->{'current_node'} = $current;
-          push @{$self->{'nodes'}}, $current;
-        }
-      }
+      _check_internal_node($self,
+        $current->{'extra'}->{'nodes_manuals'}->[0],
+        $line_nr);
+     _register_label($self, $current, 
+                   $current->{'extra'}->{'nodes_manuals'}->[0], $line_nr);
+     $self->{'current_node'} = $current;
     } elsif ($command eq 'listoffloats') {
       _parse_float_type($current);
     # handle all the other 'line' commands.  Here just check that they 
@@ -3466,13 +3514,6 @@
     $self->line_error (sprintf($self->__("empty argument in address@hidden"),
                 $command), $line_nr);
     return 0;
-  } elsif (defined($parsed_node->{'normalized'})
-             and $parsed_node->{'normalized'} !~ /[^-]/) {
-    $self->line_error (sprintf($self->__("empty node name after expansion 
`%s'"),
-                Texinfo::Convert::Texinfo::convert({'contents' 
-                                        => $parsed_node->{'node_content'}})), 
-                $line_nr);
-    return 0;
   } else {
     return 1;
   }

Modified: trunk/tp/Texinfo/Structuring.pm
===================================================================
--- trunk/tp/Texinfo/Structuring.pm     2016-11-07 20:29:49 UTC (rev 7499)
+++ trunk/tp/Texinfo/Structuring.pm     2016-11-09 00:29:28 UTC (rev 7500)
@@ -402,6 +402,12 @@
         = {'type' => 'top_node_up',
            'extra' => Texinfo::Common::parse_node_manual(
                 {'contents' => $top_node_up_content_tree->{'contents'}})};
+      if ($top_node_up->{'extra'}->{'node_content'}) {
+        $top_node_up->{'extra'}->{'normalized'} =
+        Texinfo::Convert::NodeNameNormalization::normalize_node(
+         {'contents' => $top_node_up->{'extra'}->{'node_content'}}
+        );
+      }
     }
     if ($node->{'menus'}) {
       if ($self->{'SHOW_MENU'} and @{$node->{'menus'}} > 1) {
@@ -1173,8 +1179,7 @@
       my $normalized =
            Texinfo::Convert::NodeNameNormalization::normalize_node(
               {'contents' => $node_arg->{'node_content'} });
-      $node_arg->{'normalized'} = $normalized
-        if (defined $normalized and $normalized ne '');
+      $node_arg->{'normalized'} = $normalized;
     }
     if (!defined($labels->{$node_arg->{'normalized'}})) {
       if (!$self->{'info'}->{'novalidate'}) {
@@ -1271,6 +1276,12 @@
   }
   $entry->{'extra'}->{'menu_entry_node'} =
     Texinfo::Common::parse_node_manual($menu_entry_node);
+  my $content = $entry->{'extra'}->{'menu_entry_node'}->{'node_content'};
+  if ($content) {
+    $entry->{'extra'}->{'menu_entry_node'}->{'normalized'}
+     = Texinfo::Convert::NodeNameNormalization::normalize_node(
+         {'contents' => $content } );
+  }
 
   $entry->{'extra'}->{'menu_entry_description'} = $description;
 

Modified: trunk/tp/Texinfo/Transformations.pm
===================================================================
--- trunk/tp/Texinfo/Transformations.pm 2016-11-07 20:29:49 UTC (rev 7499)
+++ trunk/tp/Texinfo/Transformations.pm 2016-11-09 00:29:28 UTC (rev 7500)
@@ -234,6 +234,11 @@
       $content->{'parent'} = $node_arg;
     }
     $parsed_node = Texinfo::Parser::_parse_node_manual($node_arg);
+    if ($parsed_node and $parsed_node->{'node_content'}) {
+      $parsed_node->{'normalized'} =
+      Texinfo::Convert::NodeNameNormalization::normalize_node (
+        { 'contents' => $parsed_node->{'node_content'} });
+    }
     if (!defined($parsed_node) or !$parsed_node->{'node_content'}
         or $parsed_node->{'normalized'} !~ /[^-]/) {
       if ($appended_number) {
@@ -246,6 +251,10 @@
   }
 
   push @{$node->{'extra'}->{'nodes_manuals'}}, $parsed_node;
+  if ($parsed_node->{'normalized'} ne '') {
+    $self->{'labels'}->{$parsed_node->{'normalized'}} = $node;
+    $node->{'extra'}->{'normalized'} = $parsed_node->{'normalized'};
+  }
   if (!Texinfo::Parser::_register_label($self, $node, $parsed_node, undef)) {
     print STDERR "BUG: node unique, register failed:  
$parsed_node->{'normalized'}\n";
   }

Modified: trunk/tp/t/automatic_nodes.t
===================================================================
--- trunk/tp/t/automatic_nodes.t        2016-11-07 20:29:49 UTC (rev 7499)
+++ trunk/tp/t/automatic_nodes.t        2016-11-09 00:29:28 UTC (rev 7500)
@@ -2,7 +2,7 @@
 
 use Test::More;
 use File::Spec;
-BEGIN { plan tests => 25;
+BEGIN { plan tests => 24;
         if (defined($ENV{'top_srcdir'})) {
           unshift @INC, File::Spec->catdir($ENV{'top_srcdir'}, 'tp');
           my $lib_dir = File::Spec->catdir($ENV{'top_srcdir'}, 'tp', 
'maintain');
@@ -31,11 +31,13 @@
 
   my $parser = Texinfo::Parser::parser();
   my $line = $parser->parse_texi_line ($in);
+  Texinfo::Structuring::associate_internal_references($parser);
   my $node = Texinfo::Transformations::_new_node($parser, $line);
   
   my ($texi_result, $normalized);
   if (defined($node)) {
     $texi_result = Texinfo::Convert::Texinfo::convert($node);
+    Texinfo::Structuring::associate_internal_references($parser);
     $normalized = $node->{'extra'}->{'normalized'};
     my $labels = $parser->labels_information();
     my @labels = keys(%$labels);
@@ -72,6 +74,7 @@
 my $tree = $parser->parse_texi_text('@node a node
 ');
 my $line_tree = Texinfo::Parser::parse_texi_line (undef, 'a node');
+Texinfo::Structuring::associate_internal_references($parser);
 my $node = Texinfo::Transformations::_new_node($parser, $line_tree);
 is ('@node a node 1
 ',  Texinfo::Convert::Texinfo::convert($node), 'duplicate node added');
@@ -142,6 +145,7 @@
 
   $parser = Texinfo::Parser::parser();
   $tree = $parser->parse_texi_text ($sections_text);
+  Texinfo::Structuring::associate_internal_references($parser);
   my ($new_content, $added_nodes) = 
Texinfo::Transformations::insert_nodes_for_sectioning_commands($parser, $tree);
   $tree->{'contents'} = $new_content;
   my $result = Texinfo::Convert::Texinfo::convert($tree);
@@ -160,6 +164,7 @@
 * (some_manual)::
 @end menu
 ');
+Texinfo::Structuring::associate_internal_references($parser);
 ($new_content, $added_nodes)
    = Texinfo::Transformations::insert_nodes_for_sectioning_commands($parser, 
$tree);
 $tree->{'contents'} = $new_content;
@@ -178,22 +183,24 @@
   'index entry reassociated');
 #print STDERR Texinfo::Convert::Texinfo::convert($tree);
 
-$parser = Texinfo::Parser::parser();
-my $text_duplicate_nodes = 
-'@node NAME
address@hidden DESCRIPTION
+# 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_text ($text_duplicate_nodes);
+# # In fact, here we also check that there is no debugging message...
+# ($new_content, $added_nodes)
+#    = Texinfo::Transformations::insert_nodes_for_sectioning_commands($parser, 
$tree);
+# ($index_names, $merged_indices) = $parser->indices_information();
+# $labels = $parser->labels_information();
+# is ($labels->{'SEE-ALSO'}, 
$index_names->{'cp'}->{'index_entries'}->[0]->{'node'},
+#   'index entry reassociated duplicate node ignored');
 
address@hidden NAME
address@hidden SEE ALSO
-
address@hidden entry
-';
-$tree = $parser->parse_texi_text ($text_duplicate_nodes);
-# In fact, here we also check that there is no debugging message...
-($new_content, $added_nodes)
-   = Texinfo::Transformations::insert_nodes_for_sectioning_commands($parser, 
$tree);
-($index_names, $merged_indices) = $parser->indices_information();
-$labels = $parser->labels_information();
-is ($labels->{'SEE-ALSO'}, 
$index_names->{'cp'}->{'index_entries'}->[0]->{'node'},
-  'index entry reassociated duplicate node ignored');
-




reply via email to

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