texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp Texinfo/Structuring.pm t/automatic_n...


From: Patrice Dumas
Subject: texinfo/tp Texinfo/Structuring.pm t/automatic_n...
Date: Fri, 24 Feb 2012 23:21:50 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        12/02/24 23:21:50

Modified files:
        tp/Texinfo     : Structuring.pm 
        tp/t           : automatic_nodes.t 

Log message:
        Function to insert node whn there is no node associated to a sectioning 
        command.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.115&r2=1.116
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/automatic_nodes.t?cvsroot=texinfo&r1=1.2&r2=1.3

Patches:
Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -b -r1.115 -r1.116
--- Texinfo/Structuring.pm      24 Feb 2012 18:38:04 -0000      1.115
+++ Texinfo/Structuring.pm      24 Feb 2012 23:21:50 -0000      1.116
@@ -29,6 +29,8 @@
 # for error messages 
 use Texinfo::Convert::Texinfo;
 
+use Storable qw(dclone);
+
 require Exporter;
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 @ISA = qw(Exporter);
@@ -1286,14 +1288,50 @@
     $parsed_node = Texinfo::Parser::_parse_node_manual($node_arg);
     return undef if (!defined($parsed_node) or !$parsed_node->{'node_content'}
                      or $parsed_node->{'normalized'} !~ /[^-]/);
-    push @{$node->{'extra'}->{'nodes_manuals'}}, $parsed_node;
+    $appended_number++;
   }
 
+  push @{$node->{'extra'}->{'nodes_manuals'}}, $parsed_node;
   Texinfo::Parser::_register_label($self, $node, $parsed_node, undef);
   push @{$self->{'nodes'}}, $node;
   return $node;
 }
 
+sub _insert_nodes_for_sectioning_commands($$)
+{
+  my $self = shift;
+  my $root = shift;
+  if (!$root->{'type'} or $root->{'type'} ne 'document_root'
+      or !$root->{'contents'}) {
+    return undef;
+  }
+  my @contents;
+  foreach my $content (@{$root->{'contents'}}) {
+    if ($content->{'cmdname'} and $content->{'cmdname'} ne 'node'
+        and $content->{'cmdname'} ne 'bye'
+        and $content->{'cmdname'} ne 'part'
+        and not ($content->{'extra'} 
+                 and $content->{'extra'}->{'associated_node'})) {
+      my $new_node_tree;
+      if ($content->{'cmdname'} eq 'top') {
+        $new_node_tree = {'contents' => [{'text' => 'Top'}]};
+      } else {
+        $new_node_tree = dclone({'contents' 
+          => $content->{'extra'}->{'misc_content'}});
+      }
+      my $new_node = _new_node ($self, $new_node_tree);
+      if (defined($new_node)) {
+        push @contents, $new_node;
+        $new_node->{'extra'}->{'associated_section'} = $content;
+        $content->{'extra'}->{'associated_node'} = $new_node;
+        $new_node->{'parent'} = $content->{'parent'};
+        # FIXME set $index_entry->{'node'}
+      }
+    }
+    push @contents, $content;
+  }
+  return address@hidden;
+}
 
 sub _sort_string($$)
 {

Index: t/automatic_nodes.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/automatic_nodes.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- t/automatic_nodes.t 24 Feb 2012 18:38:04 -0000      1.2
+++ t/automatic_nodes.t 24 Feb 2012 23:21:50 -0000      1.3
@@ -1,7 +1,7 @@
 use strict;
 
 use Test::More;
-BEGIN { plan tests => 10 };
+BEGIN { plan tests => 12 };
 
 use lib 'maintain/lib/Unicode-EastAsianWidth/lib/';
 use lib 'maintain/lib/libintl-perl/lib/';
@@ -45,3 +45,81 @@
 test_new_node ('a ,, node @code{a,b,}', 'a-_002c_002c-node-a_002cb_002c',
 '@node a @address@hidden node @address@hidden@comma{}}
 ', 'with comma');
+
+my $parser = Texinfo::Parser::parser();
+my $tree = $parser->parse_texi_text('@node a node
+');
+my $line_tree = Texinfo::Parser::parse_texi_line (undef, 'a node');
+my $node = Texinfo::Structuring::_new_node($parser, $line_tree);
+is ('@node a node 1
+',  Texinfo::Convert::Texinfo::convert($node), 'duplicate node added');
+#print STDERR Texinfo::Convert::Texinfo::convert($node);
+
+
+my $sections_text = 
+'@top top section
+
address@hidden part
+
address@hidden chap, @code{a chap}
+
address@hidden a node
address@hidden section
+
address@hidden truc
address@hidden sub1
+
+Text.
+
address@hidden sub2 @c comment
+
address@hidden section
+
address@hidden section
+
address@hidden
+
address@hidden';
+
+my $reference = 
+'@node Top
address@hidden top section
+
address@hidden part
+
address@hidden address@hidden @code{a chap}
address@hidden chap, @code{a chap}
+
address@hidden a node
address@hidden section
+
address@hidden truc
address@hidden truc
address@hidden sub1
address@hidden sub1
+
+Text.
+
address@hidden sub2
address@hidden sub2 @c comment
+
address@hidden section
address@hidden section
+
address@hidden section 1
address@hidden section
+
address@hidden
+
address@hidden
+';
+
+  my $parser = Texinfo::Parser::parser();
+  my $tree = $parser->parse_texi_text ($sections_text);
+  my $new_content 
+   = Texinfo::Structuring::_insert_nodes_for_sectioning_commands($parser, 
$tree);
+  $tree->{'contents'} = $new_content;
+  my $result = Texinfo::Convert::Texinfo::convert($tree);
+  is ($reference, $result, 'add nodes');
+  #print STDERR "$result";
+  



reply via email to

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