texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp texi2any.pl Texinfo/Structuring.pm t...


From: Patrice Dumas
Subject: texinfo/tp texi2any.pl Texinfo/Structuring.pm t...
Date: Wed, 18 Apr 2012 21:10:24 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        12/04/18 21:10:24

Modified files:
        tp             : texi2any.pl 
        tp/Texinfo     : Structuring.pm 
        tp/t           : automatic_nodes.t 
                         test_fill_gaps_in_sectioning.t 

Log message:
        Return added nodes and sections.
        Better added section (with fill_gap_in_sectioning) tree.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/texi2any.pl?cvsroot=texinfo&r1=1.123&r2=1.124
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.129&r2=1.130
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/automatic_nodes.t?cvsroot=texinfo&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/test_fill_gaps_in_sectioning.t?cvsroot=texinfo&r1=1.1&r2=1.2

Patches:
Index: texi2any.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/texi2any.pl,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -b -r1.123 -r1.124
--- texi2any.pl 13 Apr 2012 16:56:53 -0000      1.123
+++ texi2any.pl 18 Apr 2012 21:10:23 -0000      1.124
@@ -1022,7 +1022,8 @@
   }
 
   if ($tree_transformations{'fill_gaps_in_sectioning'}) {
-    my $filled_contents = Texinfo::Structuring::fill_gaps_in_sectioning($tree);
+    my ($filled_contents, $added_sections) 
+      = Texinfo::Structuring::fill_gaps_in_sectioning($tree);
     if (!defined($filled_contents)) {
       document_warn (__("fill_gaps_in_sectioning transformation return no 
result. No section?"));
     } else {
@@ -1073,7 +1074,13 @@
   }
 
   if ($tree_transformations{'insert_nodes_for_sectioning_commands'}) {
-    Texinfo::Structuring::insert_nodes_for_sectioning_commands($parser, $tree);
+    my ($modified_contents, $added_nodes)
+     = Texinfo::Structuring::insert_nodes_for_sectioning_commands($parser, 
$tree);
+    if (!defined($modified_contents)) {
+      document_warn (__("insert_nodes_for_sectioning_commands transformation 
return no result. No section?"));
+    } else {
+      $tree->{'contents'} = $modified_contents;
+    }
   }
 
   Texinfo::Structuring::associate_internal_references($parser);

Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -b -r1.129 -r1.130
--- Texinfo/Structuring.pm      16 Apr 2012 22:19:23 -0000      1.129
+++ Texinfo/Structuring.pm      18 Apr 2012 21:10:23 -0000      1.130
@@ -216,11 +216,7 @@
         and $content->{'cmdname'} ne 'bye') {
       push @sections_list, $content;
       if ($content->{'cmdname'} eq 'top') {
-        if ($section_top) {
-      #    already warned as a unique command.
-      #    $self->line_error($self->__("address@hidden already exists"), 
-      #                                 $content->{'line_nr'});
-        } else {
+        if (! $section_top) {
           $section_top = $content;
         }
       }
@@ -321,7 +317,6 @@
       }
       if (!$unnumbered_commands{$content->{'cmdname'}}) {
         # construct the number, if not below an unnumbered
-        #if ($command_numbers[$number_top_level]) {
         if (!$command_unnumbered[$number_top_level]) {
           $content->{'number'} = $command_numbers[$number_top_level];
           for (my $i = $number_top_level+1; $i <= $content->{'level'}; $i++) {
@@ -364,6 +359,17 @@
   return $sec_root;
 }
 
+sub _print_sectioning_tree($);
+sub _print_sectioning_tree($)
+{
+  my $current = shift;
+  my $result = ' ' x $current->{'level'} . 
_print_root_command_texi($current)."\n";
+  foreach my $child (@{$current->{'section_childs'}}) {
+    $result .= _print_sectioning_tree($child);
+  }
+  return $result;
+}
+
 
 # Add raise/lowersections to be back at the normal level
 sub _correct_level ($$;$)
@@ -409,8 +415,9 @@
     }
   }
 
-  return undef if (!scalar(@sections_list));
+  return (undef, undef) if (!scalar(@sections_list));
 
+  my @added_sections;
   my @contents;
   my $previous_section;
   foreach my $content(@{$root->{'contents'}}) {
@@ -436,9 +443,11 @@
           $current_section_level++;
           my $new_section = {'cmdname' =>
             
$Texinfo::Common::level_to_structuring_command{'unnumbered'}->[$current_section_level],
-            'contents' => [],
             'parent' => $root,
           };
+          $new_section->{'contents'} = [{'type' => 'empty_line', 
+                                         'text' => "\n",
+                                         'parent' => $new_section}];
           $new_section->{'args'} = [{'type' => 'misc_line_arg',
                                      'parent' => $new_section}];
           $new_section->{'args'}->[0]->{'contents'} = [
@@ -458,7 +467,11 @@
              = [{'type' => 'brace_command_arg',
                  'contents' => [],
                  'parent' => $new_section->{'args'}->[0]->{'contents'}->[1]}];
+          my @misc_contents = @{$new_section->{'args'}->[0]->{'contents'}};
+          Texinfo::Common::trim_spaces_comment_from_content(address@hidden);
+          $new_section->{'extra'}->{'misc_content'} = address@hidden;
           push @contents, $new_section;
+          push @added_sections, $new_section;
           #print STDERR "  -> "._print_root_command_texi($new_section)."\n";
         }
         my @set_level_offset_commands = _correct_level($next_section,
@@ -469,7 +482,7 @@
       }
     }
   }
-  return address@hidden;
+  return (address@hidden, address@hidden);
 }
 
 my @node_directions = ('next', 'prev', 'up');
@@ -1420,8 +1433,9 @@
   my $root = shift;
   if (!$root->{'type'} or $root->{'type'} ne 'document_root'
       or !$root->{'contents'}) {
-    return undef;
+    return (undef, undef);
   }
+  my @added_nodes;
   my @contents;
   my $previous_node;
   foreach my $content (@{$root->{'contents'}}) {
@@ -1440,6 +1454,7 @@
       my $new_node = _new_node($self, $new_node_tree);
       if (defined($new_node)) {
         push @contents, $new_node;
+        push @added_nodes, $new_node;
         $new_node->{'extra'}->{'associated_section'} = $content;
         $content->{'extra'}->{'associated_node'} = $new_node;
         $new_node->{'parent'} = $content->{'parent'};
@@ -1455,7 +1470,7 @@
           and $content->{'extra'}->{'normalized'});
     push @contents, $content;
   }
-  return address@hidden;
+  return (address@hidden, address@hidden);
 }
 
 sub _copy_contents($)
@@ -2313,13 +2328,14 @@
 When simply sorting, the array of the sorted indes entries is associated
 with the index name.
 
-=item $root_content = fill_gaps_in_sectioning ($root)
+=item ($root_content, $added_sections) = fill_gaps_in_sectioning ($root)
 
 This function adds empty C<@unnumbered> and similar commands in a tree
 to fill gaps in sectioning.  This may be used, for example, when converting 
 from a format that can handle gaps in sectioning.  I<$root> is the tree
 root.  An array reference is returned, containing the root contents
-with added sectioning commands.
+with added sectioning commands, as well as an array reference containing 
+the added sectioning commands.
 
 If the sectioning commands are lowered or raised (with C<@raisesections>,
 C<@lowersection>) the tree may be modified with C<@raisesections> or
@@ -2337,9 +2353,12 @@
 container anymore, their content are merged directly in the menu in 
 I<preformatted> container.
 
-=item insert_nodes_for_sectioning_commands ($parser, $tree)
+=item ($root_content, $added_nodes) = insert_nodes_for_sectioning_commands 
($parser, $tree)
 
 Insert nodes for sectioning commands without node in C<$tree>.
+An array reference is returned, containing the root contents
+with added nodes, as well as an array reference containing the 
+added nodes.
 
 =item complete_tree_nodes_menus ($parser, $tree)
 

Index: t/automatic_nodes.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/automatic_nodes.t,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- t/automatic_nodes.t 15 Apr 2012 22:34:32 -0000      1.10
+++ t/automatic_nodes.t 18 Apr 2012 21:10:23 -0000      1.11
@@ -135,7 +135,7 @@
 
   $parser = Texinfo::Parser::parser();
   $tree = $parser->parse_texi_text ($sections_text);
-  my $new_content 
+  my ($new_content, $added_nodes)
    = Texinfo::Structuring::insert_nodes_for_sectioning_commands($parser, 
$tree);
   $tree->{'contents'} = $new_content;
   my $result = Texinfo::Convert::Texinfo::convert($tree);
@@ -154,7 +154,7 @@
 * (some_manual)::
 @end menu
 ');
-$new_content
+($new_content, $added_nodes)
    = Texinfo::Structuring::insert_nodes_for_sectioning_commands($parser, 
$tree);
 $tree->{'contents'} = $new_content;
 my ($index_names, $merged_indices, $index_entries) = 
$parser->indices_information();
@@ -184,7 +184,7 @@
 ';
 $tree = $parser->parse_texi_text ($text_duplicate_nodes);
 # In fact, here we also check that there is no debugging message...
-$new_content
+($new_content, $added_nodes)
    = Texinfo::Structuring::insert_nodes_for_sectioning_commands($parser, 
$tree);
 ($index_names, $merged_indices, $index_entries) = 
$parser->indices_information();
 $labels = $parser->labels_information();

Index: t/test_fill_gaps_in_sectioning.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/test_fill_gaps_in_sectioning.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/test_fill_gaps_in_sectioning.t    1 Feb 2012 00:41:10 -0000       1.1
+++ t/test_fill_gaps_in_sectioning.t    18 Apr 2012 21:10:23 -0000      1.2
@@ -42,7 +42,8 @@
   my $out = shift;
   my $name = shift;
   my $tree = parse_texi_text(undef, $in);
-  my $corrected_content = Texinfo::Structuring::fill_gaps_in_sectioning($tree);
+  my ($corrected_content, $added_sections) 
+      = Texinfo::Structuring::fill_gaps_in_sectioning($tree);
   $tree->{'contents'} = $corrected_content;
   {
   local $Data::Dumper::Purity = 1;
@@ -62,6 +63,7 @@
 @subsection sub
 ','@chapter chap
 @unnumberedsec @asis{}
+
 @subsection sub
 ', 'simple completed tree');
 
@@ -89,6 +91,7 @@
 @raisesection
 @raisesection
 @unnumberedsec @asis{}
+
 @lowersection
 @lowersection
 @chapter chap



reply via email to

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