texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp texi2any.pl Texinfo/Parser.pm Texinf...


From: Patrice Dumas
Subject: texinfo/tp texi2any.pl Texinfo/Parser.pm Texinf...
Date: Sat, 28 Jan 2012 17:51:35 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        12/01/28 17:51:35

Modified files:
        tp             : texi2any.pl 
        tp/Texinfo     : Parser.pm 
        tp/Texinfo/Convert: Texinfo.pm 
Added files:
        tp/t           : fix_texinfo.t 

Log message:
        Add an argument to the Texinfo to Texinfo converter to try to fix the
        input.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/texi2any.pl?cvsroot=texinfo&r1=1.107&r2=1.108
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.356&r2=1.357
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Texinfo.pm?cvsroot=texinfo&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/fix_texinfo.t?cvsroot=texinfo&rev=1.1

Patches:
Index: texi2any.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/texi2any.pl,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -b -r1.107 -r1.108
--- texi2any.pl 28 Jan 2012 12:41:35 -0000      1.107
+++ texi2any.pl 28 Jan 2012 17:51:34 -0000      1.108
@@ -963,7 +963,7 @@
   }
 
   if (defined(get_conf('MACRO_EXPAND'))) {
-    my $texinfo_text = Texinfo::Convert::Texinfo::convert ($tree);
+    my $texinfo_text = Texinfo::Convert::Texinfo::convert ($tree, 1);
     #print STDERR "$texinfo_text\n";
     my $macro_expand_file = get_conf('MACRO_EXPAND');
     my $macro_expand_fh = Texinfo::Common::open_out($parser, 

Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.356
retrieving revision 1.357
diff -u -b -r1.356 -r1.357
--- Texinfo/Parser.pm   26 Jan 2012 00:17:31 -0000      1.356
+++ Texinfo/Parser.pm   28 Jan 2012 17:51:34 -0000      1.357
@@ -652,7 +652,7 @@
 
 # entry point for text fragments.
 # Used in tests.
-# Note that it has not asociated root type a opposed to parse_texi_line
+# Note that it has no associated root type a opposed to parse_texi_line
 # and parse_texi_file.
 sub parse_texi_text($$;$$$$)
 {

Index: Texinfo/Convert/Texinfo.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Texinfo.pm,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- Texinfo/Convert/Texinfo.pm  28 Jan 2012 14:05:14 -0000      1.9
+++ Texinfo/Convert/Texinfo.pm  28 Jan 2012 17:51:34 -0000      1.10
@@ -53,14 +53,17 @@
 my %block_commands           = %Texinfo::Common::block_commands;    
 my %def_commands             = %Texinfo::Common::def_commands;    
 
-sub convert ($);
+sub convert ($;$);
 # Following subroutines deal with transforming a texinfo tree into texinfo
 # text.  Should give the text that was used parsed, except for a few cases.
+# Second argument is undocumented for now, as it may change, for instance
+# become a hash if more has to be given.
 
 # expand a tree to the corresponding texinfo.
-sub convert ($)
+sub convert ($;$)
 {
   my $root = shift;
+  my $fix = shift;
   die "convert: root undef\n" if (!defined($root));
   die "convert: bad root type (".ref($root).") $root\n" 
      if (ref($root) ne 'HASH');
@@ -71,12 +74,15 @@
   if (defined($root->{'text'})) {
     $result .= $root->{'text'};
   } else {
+    if ($fix and $root->{'extra'} and $root->{'extra'}->{'invalid_nesting'}) {
+      return '';
+    }
     if ($root->{'cmdname'} 
        or ($root->{'type'} and ($root->{'type'} eq 'def_line'
                                 or $root->{'type'} eq 'menu_entry'
                                 or $root->{'type'} eq 'menu_comment'))) {
       #print STDERR "cmd: $root->{'cmdname'}\n";
-      $result .= _expand_cmd_args_to_texi($root);
+      $result .= _expand_cmd_args_to_texi($root, $fix);
     }
     $result .= '{' if ($root->{'type'} and $root->{'type'} eq 'bracketed');
     #print STDERR "$root->{'contents'} @{$root->{'contents'}}\n" if 
(defined($root->{'contents'}));
@@ -84,13 +90,15 @@
       die "bad contents type(" . ref($root->{'contents'})
           . ") $root->{'contents'}\n" if (ref($root->{'contents'}) ne 'ARRAY');
       foreach my $child (@{$root->{'contents'}}) {
-        $result .= convert($child);
+        $result .= convert($child, $fix);
       }
     }
     $result .= '}' if ($root->{'type'} and $root->{'type'} eq 'bracketed');
     if ($root->{'cmdname'} and (defined($block_commands{$root->{'cmdname'}}))
-        and $block_commands{$root->{'cmdname'}} eq 'raw') {
+        and ($block_commands{$root->{'cmdname'}} eq 'raw' 
+          or ($fix and !($root->{'extra'} and 
$root->{'extra'}->{'end_command'})))) {
       $result .= '@end '.$root->{'cmdname'};
+      $result .= "\n" if ($block_commands{$root->{'cmdname'}} ne 'raw');
     }
   }
   #print STDERR "convert result: $result\n";
@@ -99,8 +107,9 @@
 
 
 # expand a command argument as texinfo.
-sub _expand_cmd_args_to_texi ($) {
+sub _expand_cmd_args_to_texi ($;$) {
   my $cmd = shift;
+  my $fix = shift;
   my $cmdname = $cmd->{'cmdname'};
   $cmdname = '' if (!$cmd->{'cmdname'}); 
   my $result = '';
@@ -118,7 +127,7 @@
               or $block_commands{$cmdname} eq 'multitable')
          and $cmd->{'args'}) {
      foreach my $arg (@{$cmd->{'args'}}) {
-        $result .= convert ($arg);
+        $result .= convert ($arg, $fix);
     }
   # for misc_commands with type special
   } elsif (($cmd->{'extra'} or $cmdname eq 'macro' or $cmdname eq 'rmacro') 
@@ -129,7 +138,7 @@
     die "bad args type (".ref($cmd->{'args'}).") $cmd->{'args'}\n"
       if (ref($cmd->{'args'}) ne 'ARRAY');
     foreach my $arg (@{$cmd->{'args'}}) {
-       $result .= convert ($arg) . ',';
+       $result .= convert ($arg, $fix) . ',';
     }
     $result =~ s/,$//;
   } elsif (defined($cmd->{'args'})) {
@@ -149,7 +158,7 @@
         $result .= ',' if ($arg_nr);
         $arg_nr++;
       }
-      $result .= convert ($arg);
+      $result .= convert ($arg, $fix);
     }
     if ($cmdname eq 'verb') {
       $result .= $cmd->{'type'};

Index: t/fix_texinfo.t
===================================================================
RCS file: t/fix_texinfo.t
diff -N t/fix_texinfo.t
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ t/fix_texinfo.t     28 Jan 2012 17:51:34 -0000      1.1
@@ -0,0 +1,36 @@
+use strict;
+
+use Test::More;
+BEGIN { plan tests => 3 };
+use Texinfo::Parser;
+use Texinfo::Convert::Texinfo;
+
+
+sub run_test($$$)
+{
+  my $in = shift;
+  my $out = shift;
+  my $name = shift;
+
+  my $tree = Texinfo::Parser::parse_texi_text (undef, $in);
+  my $result = Texinfo::Convert::Texinfo::convert($tree, 1);
+    if (defined($out)) {
+    is ($result, $out, $name);
+  } else {
+    print "$name:\n";
+    print STDERR $result;
+  }
+}
+
+run_test ('@deffn a b c d ', '@deffn a b c d @end deffn'."\n", 
+          'deffn line not closed');
+
+run_test ('address@hidden
address@hidden @asis
address@hidden it
address@hidden table
+}', 'address@hidden
+}', 'table in code');
+
+run_test ('@address@hidden', '@anchor{}', 'ref in anchor');
+



reply via email to

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