texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp TODO Texinfo/Parser.pm Texinfo/Struc...


From: Patrice Dumas
Subject: texinfo/tp TODO Texinfo/Parser.pm Texinfo/Struc...
Date: Sat, 25 Feb 2012 22:34:58 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        12/02/25 22:34:58

Modified files:
        tp             : TODO 
        tp/Texinfo     : Parser.pm Structuring.pm 
        tp/t           : automatic_nodes.t 
Added files:
        tp/t           : automatic_menus.t 

Log message:
        Add complete_tree_nodes_menus() to complete menus.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/TODO?cvsroot=texinfo&r1=1.269&r2=1.270
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.364&r2=1.365
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.117&r2=1.118
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/automatic_nodes.t?cvsroot=texinfo&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/automatic_menus.t?cvsroot=texinfo&rev=1.1

Patches:
Index: TODO
===================================================================
RCS file: /sources/texinfo/texinfo/tp/TODO,v
retrieving revision 1.269
retrieving revision 1.270
diff -u -b -r1.269 -r1.270
--- TODO        23 Feb 2012 22:14:42 -0000      1.269
+++ TODO        25 Feb 2012 22:34:58 -0000      1.270
@@ -7,6 +7,9 @@
 
 Document TEXTCONTENT_COMMENT.
 
+Document insert_nodes_for_sectioning_commands complete_tree_nodes_menus
+in Texinfo::Structuring.
+
 
 Bugs
 ====

Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.364
retrieving revision 1.365
diff -u -b -r1.364 -r1.365
--- Texinfo/Parser.pm   24 Feb 2012 00:02:41 -0000      1.364
+++ Texinfo/Parser.pm   25 Feb 2012 22:34:58 -0000      1.365
@@ -3286,15 +3286,12 @@
   return _check_empty_node($self, $parsed_node, $command, $line_nr);
 }
 
-sub _enter_menu_entry_node($$$)
+sub _register_extra_menu_entry_information($$;$)
 {
   my $self = shift;
   my $current = shift;
   my $line_nr = shift;
-  my $description = { 'type' => 'menu_entry_description',
-                      'contents' => [],
-                      'parent' => $current };
-  push @{$current->{'args'}}, $description;
+
   foreach my $arg (@{$current->{'args'}}) {
     if ($arg->{'type'} eq 'menu_entry_name') {
       $current->{'extra'}->{'menu_entry_name'} = $arg;
@@ -3310,6 +3307,18 @@
       $current->{'extra'}->{'menu_entry_description'} = $arg;
     }
   } 
+}
+
+sub _enter_menu_entry_node($$$)
+{
+  my $self = shift;
+  my $current = shift;
+  my $line_nr = shift;
+  my $description = { 'type' => 'menu_entry_description',
+                      'contents' => [],
+                      'parent' => $current };
+  push @{$current->{'args'}}, $description;
+  _register_extra_menu_entry_information($self, $current, $line_nr);
   $current->{'line_nr'} = $line_nr;
   $current = $description;
   push @{$current->{'contents'}}, {'type' => 'preformatted',

Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -b -r1.117 -r1.118
--- Texinfo/Structuring.pm      25 Feb 2012 13:13:04 -0000      1.117
+++ Texinfo/Structuring.pm      25 Feb 2012 22:34:58 -0000      1.118
@@ -44,8 +44,10 @@
 # will save memory.
 %EXPORT_TAGS = ( 'all' => [ qw(
   associate_internal_references
+  complete_tree_nodes_menus
   elements_directions
   elements_file_directions
+  insert_nodes_for_sectioning_commands
   merge_indices
   nodes_tree
   number_floats
@@ -1340,7 +1342,7 @@
   return ($current);
 }
 
-sub _insert_nodes_for_sectioning_commands($$)
+sub insert_nodes_for_sectioning_commands($$)
 {
   my $self = shift;
   my $root = shift;
@@ -1381,6 +1383,165 @@
   return address@hidden;
 }
 
+sub _new_node_menu_entry($$)
+{
+  my $self = shift;
+  my $node_contents = shift;
+
+  my $entry = {'type' => 'menu_entry'};
+
+  my $menu_entry_node = {'type' => 'menu_entry_node'};
+  $menu_entry_node->{'contents'}
+    = dclone ($node_contents);
+  foreach my $content (@{$menu_entry_node->{'contents'}}) {
+    $content->{'parent'} = $menu_entry_node;
+  }
+  Texinfo::Common::protect_colon_in_tree($menu_entry_node);
+
+  my $description = {'type' => 'menu_entry_description'};
+  $description->{'contents'}->[0] = {'type' => 'preformatted',
+                                     'parent' => $description};
+  $description->{'contents'}->[0]->{'contents'}->[0] = {'text' =>"\n",
+         'parent' => $description->{'contents'}->[0]};
+  $entry->{'args'} 
+   = [{'text' => '* ', 'type' => 'menu_entry_leading_text'},
+     $menu_entry_node, 
+     {'text' => '::', 'type' => 'menu_entry_separator'},
+     $description];
+  foreach my $arg(@{$entry->{'args'}}) {
+    $arg->{'parent'} = $entry;
+  }
+  $self->Texinfo::Parser::_register_extra_menu_entry_information($entry);
+  return $entry;
+}
+
+sub _new_menu($$)
+{
+  my $menu_entries = shift;
+  my $parent = shift;
+
+  my $end = {'cmdname' => 'end', 'extra' => 
+                 {'command_argument' => 'menu',
+                  'text_arg' => 'menu'}};
+  push @{$end->{'args'}},
+    {'type' => 'misc_line_arg', 'parent' => $end};
+  push @{$end->{'args'}->[0]->{'contents'}},
+          ({'type' => 'empty_spaces_after_command',
+           'text' => ' ',
+           'extra' => {'command' => $end},
+           'parent' => $end->{'args'}->[0]},
+          {'text' => 'menu', 'parent' => $end->{'args'}->[0]},
+          {'type' => 'spaces_at_end', 'text' => "\n", 
+           'parent' => $end->{'args'}->[0]});
+  my $new_menu = {'cmdname' => 'menu', 'parent' => $parent,
+                  'extra'=>{'end_command' => $end}};
+  $end->{'extra'}->{'command'} = $new_menu;
+  $new_menu->{'contents'} = [{'extra' => 
+                                     {'command' => $new_menu},
+                              'type' => 'empty_line_after_command',
+                              'text' => "\n"},
+                              @$menu_entries, $end];
+  foreach my $content (@{$new_menu->{'contents'}}) {
+    $content->{'parent'} = $new_menu;
+  }
+  return $new_menu;
+}
+
+sub complete_node_menu($$)
+{
+  my $self = shift;
+  my $node = shift;
+
+  my @node_childs;
+  foreach my $child 
(@{$node->{'extra'}->{'associated_section'}->{'section_childs'}}) {
+    if ($child->{'extra'} and $child->{'extra'}->{'associated_node'}) {
+      push @node_childs, $child->{'extra'}->{'associated_node'};
+    }
+  }
+  if (scalar(@node_childs)) {
+    my %existing_entries;
+    if ($node->{'menus'} and @{$node->{'menus'}}) {
+      foreach my $menu (@{$node->{'menus'}}) {
+        foreach my $entry (@{$menu->{'contents'}}) {
+          if ($entry->{'type'} and $entry->{'type'} eq 'menu_entry') {
+            my $entry_node = $entry->{'extra'}->{'menu_entry_node'};
+            if (! $entry_node->{'manual_content'}
+                and defined($entry_node->{'normalized'})) {
+              $existing_entries{$entry_node->{'normalized'}} 
+                = [$menu, $entry];
+            }
+          }
+        }
+      }
+    }
+    #print STDERR join('|', keys(%existing_entries))."\n";
+    my @pending;
+    my $current_menu;
+    foreach my $node_entry (@node_childs) {
+      if ($existing_entries{$node_entry->{'extra'}->{'normalized'}}) {
+        my $entry;
+        ($current_menu, $entry) 
+         = @{$existing_entries{$node_entry->{'extra'}->{'normalized'}}};
+        if (@pending) {
+          my $index;
+          for ($index = 0; $index < scalar(@{$current_menu->{'contents'}}); 
$index++) {
+            #print STDERR "$index, 
".scalar(@{$current_menu->{'contents'}})."\n";
+            last if ($current_menu->{'contents'}->[$index] eq $entry);
+          }
+          splice (@{$current_menu->{'contents'}}, $index, 0, @pending);
+          foreach my $entry (@pending) {
+            $entry->{'parent'} = $current_menu;
+          }
+          @pending = ();
+        }
+      } else {
+        my $entry = _new_node_menu_entry($self, 
+                              $node_entry->{'extra'}->{'node_content'});
+        push @pending, $entry;
+      }
+    }
+    if (scalar(@pending)) {
+      if (!$current_menu) {
+        my $section = $node->{'extra'}->{'associated_section'};
+        $current_menu = _new_menu (address@hidden, $section);
+        push @{$section->{'contents'}}, $current_menu;
+      } else {
+        foreach my $entry (@pending) {
+          $entry->{'parent'} = $current_menu;
+        }
+        my $end;
+        if ($current_menu->{'contents'}->[-1]->{'cmdname'}
+            and $current_menu->{'contents'}->[-1]->{'cmdname'} eq 'end') {
+          $end = pop @{$current_menu->{'contents'}};
+        }
+        push @{$current_menu->{'contents'}}, @pending;
+        push @{$current_menu->{'contents'}}, $end if ($end);
+      }
+    }
+  }
+}
+
+# This should be called after sectioning_structure
+sub complete_tree_nodes_menus($$)
+{
+  my $self = shift;
+  my $root = shift;
+  if (!$root->{'type'} or $root->{'type'} ne 'document_root'
+      or !$root->{'contents'}) {
+    return undef;
+  }
+  foreach my $content (@{$root->{'contents'}}) {
+    if ($content->{'cmdname'} and $content->{'cmdname'} eq 'node'
+        and (scalar(@{$content->{'extra'}->{'nodes_manuals'}}) == 1)
+        and $content->{'extra'} 
+        and $content->{'extra'}->{'associated_section'}
+        and $content->{'extra'}->{'associated_section'}->{'section_childs'}
+        and 
@{$content->{'extra'}->{'associated_section'}->{'section_childs'}}) {
+      complete_node_menu($self, $content);
+    }
+  }
+}
+
 sub _sort_string($$)
 {
   my $a = shift;

Index: t/automatic_nodes.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/automatic_nodes.t,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- t/automatic_nodes.t 25 Feb 2012 13:13:04 -0000      1.4
+++ t/automatic_nodes.t 25 Feb 2012 22:34:58 -0000      1.5
@@ -117,7 +117,7 @@
   $parser = Texinfo::Parser::parser();
   $tree = $parser->parse_texi_text ($sections_text);
   my $new_content 
-   = Texinfo::Structuring::_insert_nodes_for_sectioning_commands($parser, 
$tree);
+   = 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');
@@ -136,7 +136,7 @@
 @end menu
 ');
 $new_content
-   = Texinfo::Structuring::_insert_nodes_for_sectioning_commands($parser, 
$tree);
+   = Texinfo::Structuring::insert_nodes_for_sectioning_commands($parser, 
$tree);
 $tree->{'contents'} = $new_content;
 my ($index_names, $merged_indices, $index_entries) = 
$parser->indices_information();
 my $labels = $parser->labels_information();

Index: t/automatic_menus.t
===================================================================
RCS file: t/automatic_menus.t
diff -N t/automatic_menus.t
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ t/automatic_menus.t 25 Feb 2012 22:34:58 -0000      1.1
@@ -0,0 +1,107 @@
+use strict;
+
+use Test::More;
+BEGIN { plan tests => 4 };
+
+use lib 'maintain/lib/Unicode-EastAsianWidth/lib/';
+use lib 'maintain/lib/libintl-perl/lib/';
+use lib 'maintain/lib/Text-Unidecode/lib/';
+use Texinfo::Parser qw(parse_texi_text);
+use Texinfo::Structuring;
+use Texinfo::Convert::Texinfo;
+
+use Data::Dumper;
+
+ok(1);
+
+sub test($$$)
+{
+  my $in = shift;
+  my $out = shift;
+  my $name = shift;
+
+  my $parser = Texinfo::Parser::parser();
+  my $tree = $parser->parse_texi_text($in);
+  my $sectioning = $parser->Texinfo::Structuring::sectioning_structure($tree);
+  $parser->Texinfo::Structuring::complete_tree_nodes_menus($tree);
+  my $texi_result = Texinfo::Convert::Texinfo::convert($tree);
+
+  if (!defined($out)) {
+    print STDERR " --> $name:\n$texi_result";
+  } else {
+    is ($texi_result, $out, $name);
+  }
+}
+
+
+test('@node Top
address@hidden top
+
address@hidden chap
address@hidden chap
+', '@node Top
address@hidden top
+
address@hidden
+* chap::
address@hidden menu
address@hidden chap
address@hidden chap
+', 'simple');
+
+test('@node Top
address@hidden top
+
address@hidden
+* chap::
+* (manual)chap2::
address@hidden menu
+
address@hidden chap
address@hidden chap
+
address@hidden chap2
address@hidden chap2
+', '@node Top
address@hidden top
+
address@hidden
+* chap::
+* (manual)chap2::
+* chap2::
address@hidden menu
+
address@hidden chap
address@hidden chap
+
address@hidden chap2
address@hidden chap2
+', 'menu completed after');
+
+test('@node Top
address@hidden top
+
address@hidden
+* chap2::
address@hidden menu
+
address@hidden chap
address@hidden chap
+
address@hidden chap2
address@hidden chap2
+', '@node Top
address@hidden top
+
address@hidden
+* chap::
+* chap2::
address@hidden menu
+
address@hidden chap
address@hidden chap
+
address@hidden chap2
address@hidden chap2
+', 'menu completed before');
+



reply via email to

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