texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp Texinfo/Structuring.pm Texinfo/Conve...


From: Patrice Dumas
Subject: texinfo/tp Texinfo/Structuring.pm Texinfo/Conve...
Date: Sat, 17 Sep 2011 20:28:19 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/09/17 20:28:19

Modified files:
        tp/Texinfo     : Structuring.pm 
        tp/Texinfo/Convert: XML.pm 
        tp/t           : 30sectioning.t 60macro.t test_utils.pl 
        tp/t/results/sectioning: part_node_chapter_after_top.pl 
                                 two_nodes_between_chapters.pl 
Added files:
        tp/t/results/macro: ifset_and_end_isef_in_macro.pl 

Log message:
        Output the end of a command at the end of an element, not when the
        next node appears.
        Delay outputing @bye after the output of the element command closing.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.83&r2=1.84
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/XML.pm?cvsroot=texinfo&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/30sectioning.t?cvsroot=texinfo&r1=1.56&r2=1.57
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/60macro.t?cvsroot=texinfo&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/test_utils.pl?cvsroot=texinfo&r1=1.99&r2=1.100
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/macro/ifset_and_end_isef_in_macro.pl?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/sectioning/part_node_chapter_after_top.pl?cvsroot=texinfo&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/sectioning/two_nodes_between_chapters.pl?cvsroot=texinfo&r1=1.1&r2=1.2

Patches:
Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -b -r1.83 -r1.84
--- Texinfo/Structuring.pm      17 Sep 2011 08:13:46 -0000      1.83
+++ Texinfo/Structuring.pm      17 Sep 2011 20:28:18 -0000      1.84
@@ -59,6 +59,12 @@
 
 $VERSION = '0.01';
 
+=head1 NAME
+
+Texinfo::Structuring - Set informations in Texinfo::Parser tree and rearrange
+
+=cut
+
 my %types_to_enter;
 foreach my $type_to_enter ('brace_command_arg', 'misc_line_arg',
     'paragraph') {
@@ -74,11 +80,6 @@
 # float printindex contents shortcontents
 # anchor
 
-# todo:
-# complete directions for nodes with automatic sectioning
-#     automatic sectioning: scalar(@{$node->{'extra'}->{'nodes_manuals'} != 1)
-# 
-
 # Not used for now
 sub _next_content($)
 {

Index: Texinfo/Convert/XML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/XML.pm,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- Texinfo/Convert/XML.pm      15 Sep 2011 22:16:44 -0000      1.34
+++ Texinfo/Convert/XML.pm      17 Sep 2011 20:28:19 -0000      1.35
@@ -315,15 +315,7 @@
   } else {
     $result .= $header;
   }
-  foreach my $content (@{$root->{'contents'}}) {
-    #print STDERR " --> $content\n";
-    my $output = $self->_convert($content);
-    if ($fh) {
-      print $fh $output;
-    } else {
-      $result .= $output;
-    }
-  }
+  $result .= $self->convert($root, $fh);
   my $footer = "</texinfo>\n";
   if ($fh) {
     print $fh $footer;
@@ -371,8 +363,25 @@
 {
   my $self = shift;
   my $root = shift;
+  my $fh = shift;
 
+  my $result = '';
+  my $elements = Texinfo::Structuring::split_by_section($root);
+  if ($elements) {
+    foreach my $element (@$elements) {
+      if ($fh) {
+        print $fh $self->_convert($element);
+      } else {
+        $result .= $self->_convert($element);
+      }
+    }
+    return $result;
+  } elsif ($fh) {
+    print $fh $self->_convert($root);
+    return '';
+  } else {
   return $self->_convert($root);
+  }
 }
 
 sub _convert($$;$);
@@ -429,7 +438,6 @@
         if ($root->{'args'} and $root->{'args'}->[0]);
       $result .= '</accent>';
       return $result;
-   # } elsif ($root->{'cmdname'} eq 'item' and 
     } elsif ($root->{'cmdname'} eq 'item' or $root->{'cmdname'} eq 'itemx'
              or $root->{'cmdname'} eq 'headitem' or $root->{'cmdname'} eq 
'tab') {
       if ($root->{'cmdname'} eq 'item'
@@ -593,6 +601,15 @@
           return "<$command${attribute}>$arg</$command>$end_line";
         }
       } elsif ($type eq 'skipline') {
+        # the command associated with an element is closed at the end of the
+        # element. @bye is withing the element, but we want it to appear after
+        # the comand closing.  So we delay the output of @bye, and store it.
+        if ($root->{'cmdname'} eq 'bye' and $root->{'parent'}
+            and $root->{'parent'}->{'type'}
+            and $root->{'parent'}->{'type'} eq 'element') {
+          $self->{'pending_bye'} = "<$command></$command>\n";
+          return '';
+        }
         return "<$command></$command>\n";
       } elsif ($type eq 'noarg') {
         return "<$command></$command>";
@@ -945,9 +962,20 @@
     if ($context_block_commands{$root->{'cmdname'}}) {
       pop @{$self->{'document_context'}};
     }
-  } elsif ($root->{'cmdname'} 
+  # The command is closed either when the corresponding tree element
+  # is done, and the command is not associated to an element, or when
+  # the element is closed.
+  } elsif (($root->{'type'} and $root->{'type'} eq 'element')
+           or ($root->{'cmdname'} 
            and $Texinfo::Common::root_commands{$root->{'cmdname'}}
-           and $root->{'cmdname'} ne 'node') {
+               and $root->{'cmdname'} ne 'node'
+               and !($root->{'parent'} and $root->{'parent'}->{'type'}
+                     and $root->{'parent'}->{'type'} eq 'element'
+                     and $root->{'parent'}->{'extra'} 
+                     and $root->{'parent'}->{'extra'}->{'element_command'} eq 
$root))) {
+    if ($root->{'type'} and $root->{'type'} eq 'element') {
+      $root = $root->{'extra'}->{'element_command'};
+    }
     my $command = $self->_level_corrected_section($root);
     if (!($root->{'section_childs'} and scalar(@{$root->{'section_childs'}}))
         or $command eq 'top') {
@@ -963,6 +991,10 @@
         $result .= '</'.$self->_level_corrected_section($current) .">\n";
       }
     }
+    if ($self->{'pending_bye'}) {
+      $result .= $self->{'pending_bye'};
+      delete $self->{'pending_bye'};
+    }
   }
   return $result;
 }

Index: t/30sectioning.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/30sectioning.t,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -b -r1.56 -r1.57
--- t/30sectioning.t    17 Sep 2011 08:13:46 -0000      1.56
+++ t/30sectioning.t    17 Sep 2011 20:28:19 -0000      1.57
@@ -1467,7 +1467,7 @@
 
 my @xml_tests_converted_tests = ('section_before_part', 'chapter_before_part', 
   'part_before_top', 'double_part', 'section_in_unnumbered_plaintext',
-  'two_unnumbered_no_argument');
+  'two_unnumbered_no_argument', 'two_nodes_between_chapters');
 
 foreach my $test (@tests_converted) {
   push @{$test->[2]->{'test_formats'}}, 'plaintext';

Index: t/60macro.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/60macro.t,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- t/60macro.t 4 Sep 2011 20:43:07 -0000       1.33
+++ t/60macro.t 17 Sep 2011 20:28:19 -0000      1.34
@@ -548,6 +548,19 @@
 arg
 }
 ', {'values' => {'notes' => 1}}],
+['ifset_and_end_isef_in_macro',
+'@macro beginifset {}
address@hidden a
address@hidden macro
+
address@hidden endifset {}
address@hidden ifset
address@hidden macro
+
address@hidden
+in ifset
address@hidden
+'],
 # unmacro is required for C makeinfo to avoid a warning.
 # texi2dvi breaks.
 ['arg_body_expansion_order',

Index: t/test_utils.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/test_utils.pl,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -b -r1.99 -r1.100
--- t/test_utils.pl     13 Sep 2011 23:09:48 -0000      1.99
+++ t/test_utils.pl     17 Sep 2011 20:28:19 -0000      1.100
@@ -810,13 +810,26 @@
      unless (-d $dir);
   my $file = "${dir}$test_name.texi";
   open (OUTFILE, ">$file") or die ("Open $file: $!\n");
+  my $setfilename;
+  if ($test_text =~ /address@hidden/) {
+    $setfilename = ''
+  } else {
+    $setfilename = "address@hidden $test_name.info\n";
+  }
+  my $node_top;
+  my $top = '';
+  if ($test_text =~ /address@hidden +top *\@/i or $test_text =~ 
/address@hidden +top *$/i) {
+    $node_top = "address@hidden Top\n";
+    unless ($test_text =~ /address@hidden *\@/ or $test_text =~ 
/address@hidden *$/) {
+      $node_top .= "address@hidden $test_name\n";
+    }
+  } else {
+    $node_top = '';
+  }
   print OUTFILE "\\input texinfo address@hidden -*-texinfo-*-
 
address@hidden $test_name.info
-
address@hidden Top
-
address@hidden $test_name
+$setfilename
+$node_top
 
 $test_text
 

Index: t/results/sectioning/part_node_chapter_after_top.pl
===================================================================
RCS file: 
/sources/texinfo/texinfo/tp/t/results/sectioning/part_node_chapter_after_top.pl,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- t/results/sectioning/part_node_chapter_after_top.pl 10 Sep 2011 13:12:38 
-0000      1.21
+++ t/results/sectioning/part_node_chapter_after_top.pl 17 Sep 2011 20:28:19 
-0000      1.22
@@ -1137,11 +1137,11 @@
 
</pre></menudescription></menuentry><menuentry><menunode>chapter</menunode><menudescription><pre
 xml:space="preserve">
 </pre></menudescription></menuentry></menu>
 
-</top>
 <part><sectiontitle>part</sectiontitle>
 
 <node name="a-node-after-part"><nodename>a node after 
part</nodename><nodenext>chapter</nodenext><nodeprev>Top</nodeprev><nodeup>Top</nodeup></node><para>After
 a node after part
 </para>
+</top>
 <node name="chapter"><nodename>chapter</nodename><nodeprev automatic="on">a 
node after part</nodeprev><nodeup automatic="on">Top</nodeup></node>
 <chapter><sectiontitle>chapter </sectiontitle>
 </chapter>

Index: t/results/sectioning/two_nodes_between_chapters.pl
===================================================================
RCS file: 
/sources/texinfo/texinfo/tp/t/results/sectioning/two_nodes_between_chapters.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/sectioning/two_nodes_between_chapters.pl  30 Aug 2011 22:26:47 
-0000      1.1
+++ t/results/sectioning/two_nodes_between_chapters.pl  17 Sep 2011 20:28:19 
-0000      1.2
@@ -1331,4 +1331,25 @@
 </html>
 ';
 
+
+$result_converted{'xml'}->{'two_nodes_between_chapters'} = '<node 
name="Top"><nodename>Top</nodename><nodenext automatic="on">chapter 
1</nodenext><nodeup automatic="on">(dir)</nodeup></node>
+<top><sectiontitle>top</sectiontitle>
+
+<menu>
+<menuentry><menunode>chapter 1</menunode><menudescription><pre 
xml:space="preserve">
+</pre></menudescription></menuentry><menuentry><menunode>node between 
chapters</menunode><menudescription><pre xml:space="preserve">
+</pre></menudescription></menuentry><menuentry><menunode>chapter 
2</menunode><menudescription><pre xml:space="preserve">
+</pre></menudescription></menuentry></menu>
+
+</top>
+<node name="chapter-1"><nodename>chapter 
1</nodename><nodenext>Top</nodenext><nodeprev>node between 
chapters</nodeprev><nodeup>Top</nodeup></node><chapter><sectiontitle>chapter 
c1</sectiontitle>
+
+<node name="node-between-chapters"><nodename>node between 
chapters</nodename><nodenext automatic="on">chapter 2</nodenext><nodeprev 
automatic="on">chapter 1</nodeprev><nodeup automatic="on">Top</nodeup></node>
+
+</chapter>
+<node name="chapter-2"><nodename>chapter 2</nodename><nodeprev 
automatic="on">chapter 1</nodeprev><nodeup automatic="on">Top</nodeup></node>
+<chapter><sectiontitle>chapter c2</sectiontitle>
+</chapter>
+';
+
 1;

Index: t/results/macro/ifset_and_end_isef_in_macro.pl
===================================================================
RCS file: t/results/macro/ifset_and_end_isef_in_macro.pl
diff -N t/results/macro/ifset_and_end_isef_in_macro.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ t/results/macro/ifset_and_end_isef_in_macro.pl      17 Sep 2011 20:28:19 
-0000      1.1
@@ -0,0 +1,179 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors 
+   %result_indices %result_sectioning %result_nodes %result_menus
+   %result_floats %result_converted %result_converted_errors 
+   %result_elements %result_directions_text);
+
+use utf8;
+
+$result_trees{'ifset_and_end_isef_in_macro'} = {
+  'contents' => [
+    {
+      'args' => [
+        {
+          'parent' => {},
+          'text' => 'beginifset',
+          'type' => 'macro_name'
+        }
+      ],
+      'cmdname' => 'macro',
+      'contents' => [
+        {
+          'parent' => {},
+          'text' => '@ifset a
+',
+          'type' => 'raw'
+        }
+      ],
+      'extra' => {
+        'arg_line' => ' beginifset {}
+',
+        'macrobody' => '@ifset a
+'
+      },
+      'line_nr' => {
+        'file_name' => '',
+        'line_nr' => 1,
+        'macro' => ''
+      },
+      'parent' => {}
+    },
+    {
+      'extra' => {
+        'command' => {}
+      },
+      'parent' => {},
+      'text' => '
+',
+      'type' => 'empty_line_after_command'
+    },
+    {
+      'parent' => {},
+      'text' => '
+',
+      'type' => 'empty_line'
+    },
+    {
+      'args' => [
+        {
+          'parent' => {},
+          'text' => 'endifset',
+          'type' => 'macro_name'
+        }
+      ],
+      'cmdname' => 'macro',
+      'contents' => [
+        {
+          'parent' => {},
+          'text' => '@end ifset
+',
+          'type' => 'raw'
+        }
+      ],
+      'extra' => {
+        'arg_line' => ' endifset {}
+',
+        'macrobody' => '@end ifset
+'
+      },
+      'line_nr' => {
+        'file_name' => '',
+        'line_nr' => 5,
+        'macro' => ''
+      },
+      'parent' => {}
+    },
+    {
+      'extra' => {
+        'command' => {}
+      },
+      'parent' => {},
+      'text' => '
+',
+      'type' => 'empty_line_after_command'
+    },
+    {
+      'parent' => {},
+      'text' => '
+',
+      'type' => 'empty_line'
+    },
+    {
+      'cmdname' => 'ifset',
+      'contents' => [
+        {
+          'parent' => {},
+          'text' => '
+',
+          'type' => 'raw'
+        },
+        {
+          'parent' => {},
+          'text' => 'in ifset
+',
+          'type' => 'raw'
+        },
+        {
+          'parent' => {},
+          'text' => '@endifset
+',
+          'type' => 'raw'
+        }
+      ],
+      'parent' => {}
+    }
+  ],
+  'type' => 'text_root'
+};
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[0]{'args'}[0]{'parent'}
 = $result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[0];
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[0];
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[0]{'parent'} = 
$result_trees{'ifset_and_end_isef_in_macro'};
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[1]{'extra'}{'command'}
 = $result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[0];
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[1]{'parent'} = 
$result_trees{'ifset_and_end_isef_in_macro'};
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[2]{'parent'} = 
$result_trees{'ifset_and_end_isef_in_macro'};
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[3]{'args'}[0]{'parent'}
 = $result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[3];
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[3]{'contents'}[0]{'parent'}
 = $result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[3];
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[3]{'parent'} = 
$result_trees{'ifset_and_end_isef_in_macro'};
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[4]{'extra'}{'command'}
 = $result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[3];
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[4]{'parent'} = 
$result_trees{'ifset_and_end_isef_in_macro'};
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[5]{'parent'} = 
$result_trees{'ifset_and_end_isef_in_macro'};
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[6]{'contents'}[0]{'parent'}
 = $result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[6];
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[6]{'contents'}[1]{'parent'}
 = $result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[6];
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[6]{'contents'}[2]{'parent'}
 = $result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[6];
+$result_trees{'ifset_and_end_isef_in_macro'}{'contents'}[6]{'parent'} = 
$result_trees{'ifset_and_end_isef_in_macro'};
+
+$result_texis{'ifset_and_end_isef_in_macro'} = '@macro beginifset {}
address@hidden a
address@hidden macro
+
address@hidden endifset {}
address@hidden ifset
address@hidden macro
+
address@hidden
+in ifset
address@hidden
address@hidden ifset
+';
+
+
+$result_texts{'ifset_and_end_isef_in_macro'} = '
+
+
+in ifset
address@hidden
+';
+
+$result_errors{'ifset_and_end_isef_in_macro'} = [
+  {
+    'error_line' => ':11: No matching address@hidden ifset\'
+',
+    'file_name' => '',
+    'line_nr' => 11,
+    'macro' => '',
+    'text' => 'No matching address@hidden ifset\'',
+    'type' => 'error'
+  }
+];
+
+
+1;



reply via email to

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