texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp Texinfo/Parser.pm t/test_utils.pl t/...


From: Patrice Dumas
Subject: texinfo/tp Texinfo/Parser.pm t/test_utils.pl t/...
Date: Sat, 25 Sep 2010 13:58:21 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        10/09/25 13:58:21

Modified files:
        tp/Texinfo     : Parser.pm 
        tp/t           : test_utils.pl 
        tp/t/results/columnfractions: empty.pl empty_comment.pl good.pl 
                                      good_comment.pl 
                                      good_space_comment.pl 
                                      not_fraction.pl wrong_command.pl 

Log message:
        Handle *item* and tab.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/test_utils.pl?cvsroot=texinfo&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/columnfractions/empty.pl?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/columnfractions/empty_comment.pl?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/columnfractions/good.pl?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/columnfractions/good_comment.pl?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/columnfractions/good_space_comment.pl?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/columnfractions/not_fraction.pl?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/columnfractions/wrong_command.pl?cvsroot=texinfo&r1=1.1&r2=1.2

Patches:
Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- Texinfo/Parser.pm   25 Sep 2010 10:01:32 -0000      1.13
+++ Texinfo/Parser.pm   25 Sep 2010 13:58:21 -0000      1.14
@@ -757,7 +757,7 @@
   return $current;
 }
 
-sub _item_container($)
+sub _item_container_parent($)
 {
   my $current = shift;
   if (($current->{'cmdname'} and $current->{'cmdname'} eq 'item' 
@@ -769,7 +769,7 @@
   return undef;
 }
 
-sub _item_line($)
+sub _item_line_parent($)
 {
   my $current = shift;
   if (($current->{'cmdname'} and $current->{'cmdname'} eq 'item'
@@ -782,7 +782,7 @@
   return undef;
 }
 
-sub _item_multitable($)
+sub _item_multitable_parent($)
 {
   my $current = shift;
   if (($current->{'cmdname'} and $current->{'cmdname'} eq 'headitem'
@@ -960,8 +960,7 @@
                                                 $end_command);
         return undef if ($error);
         last unless ($line =~ /\S/);
-      }
-      elsif ($line =~ s/^\@(["'address@hidden,\.!\?\s\*\-\^`=:\|\/\\])//o 
+      } elsif ($line =~ s/^\@(["'address@hidden,\.!\?\s\*\-\^`=:\|\/\\])//o 
                or $line =~ s/^\@([a-zA-Z][\w-]*)//o) {
         my $command = $1;
         $command = $self->{'aliases'}->{$command} 
@@ -975,8 +974,7 @@
           if ($deprecated_commands{$command} eq '') {
             _line_warn($self, sprintf($self->__("%c%s is obsolete."), 
                                 ord('@'), $command), $line_nr);
-          }
-          else {
+          } else {
             _line_warn($self, sprintf($self->__("%c%s is obsolete; %s"),
                    ord('@'), $command, 
                    $self->__($deprecated_commands{$command})), $line_nr);
@@ -992,6 +990,67 @@
           ($line, $args, $line_arg, $error) 
              = $self->_parse_misc_command($line, $command, $line_nr);
           return undef if ($error);
+
+          if ($command eq 'item' or $command eq 'itemx' 
+               or $command eq 'headitem' or $command eq 'tab') {
+            my $error;
+            ($current, $error) = _end_paragraph($self, $current, $line_nr);
+            return undef if ($error);
+            my $parent;
+            # itemize or enumerate
+            if ($parent = _item_container_parent($current)) {
+              if ($command eq 'item') {
+                push @{$parent->{'contents'}},
+                  { 'cmdname' => $command, 'parent' => $parent, 
+                    'contents' => [] };
+                $current = $parent->{'contents'}->[-1];
+              } else {
+                $self->_line_error (sprintf($self->__("address@hidden not 
meaningful inside address@hidden' block"), $command, $parent->{'cmdname'}), 
$line_nr);
+              }
+            # *table
+            } elsif ($parent = _item_line_parent($current)) {
+              if ($command eq 'item' or $command eq 'itemx') {
+                $line_arg = $line;
+              } else {
+                $self->_line_error (sprintf($self->__("address@hidden not 
meaningful inside address@hidden' block"), $command, $parent->{'cmdname'}), 
$line_nr);
+              }
+            # multitable
+            } elsif ($parent = _item_multitable_parent($current)) {
+              if ($command eq 'item' or $command eq 'headitem'
+                   or $command eq 'tab') {
+                if (!$parent->{'special'}->{'max_columns'}) {
+                  $self->_line_warn (sprintf($self->__("address@hidden in 
empty multitable"), $command), $line_nr);
+                } elsif ($command eq 'tab') {
+                  my $row = $parent->{'contents'}->[-1];
+                  die if (!$row->{'type'});
+                  if ($row->{'type'} eq 'container') {
+                    $self->_line_warn($self->__("address@hidden before 
address@hidden"), $line_nr);
+                  } elsif ($row->{'special'}->{'cell_number'} > 
$parent->{'special'}->{'max_columns'}) {
+                    return undef if $self->_line_error (sprintf($self->__("Too 
many columns in multitable item (max %d)"), 
$parent->{'special'}->{'max_columns'}), $line_nr);
+                  } else {
+                    $row->{'special'}->{'cell_number'}++;
+                    push @{$row->{'contents'}}, { 'cmdname' => $command,
+                                                'parent' => $row };
+                    $current = $row->{'contents'}->[-1];
+                  }
+                } else {
+                  my $row = { 'type' => 'row', 'contents' => [],
+                              'special' => { 'cell_number' => 1 },
+                              'parent' => $parent };
+                  push @{$parent->{'contents'}}, $row;
+                  push @{$row->{'contents'}}, { 'cmdname' => $command,
+                                                'parent' => $row };
+                  $current = $row->{'contents'}->[-1];
+                }
+              } else {
+                $self->_line_error (sprintf($self->__("address@hidden not 
meaningful inside address@hidden' block"), $command, $parent->{'cmdname'}), 
$line_nr);
+              }
+            } elsif ($command eq 'tab') {
+              $self->line_error($self->__("ignoring address@hidden outside of 
multitable"), $line_nr);
+            } else {
+              $self->line_error (sprintf($self->__("address@hidden outside of 
table or list"), $command), $line_nr);
+            }
+          } else {
           push @{$current->{'contents'}}, 
             { 'cmdname' => $command, 'parent' => $current };
               
@@ -1000,11 +1059,6 @@
               { 'type' => 'misc_arg', 'text' => $arg, 
                 'parent' => $current->{'contents'}->[-1] };
           }
-          if ($command eq 'item' or $command eq 'itemx' 
-               or $command eq 'headitem' or $command eq 'tab') {
-            my $error;
-            ($current, $error) = _end_paragraph($self, $current, $line_nr);
-            return undef if ($error);
           }
           if (defined($line_arg)) {
             $line = $line_arg;
@@ -1018,7 +1072,6 @@
             $current->{'remaining_args'} = 4 if ($command eq 'node');
             $current = $current->{'args'}->[-1];
           }
-          # FIXME @tab and @item, special case for @item(x) in @table...
         } elsif (exists($block_commands{$command})) {
           my $macro;
           if ($command eq 'macro') {
@@ -1044,8 +1097,7 @@
                  'parent' => $current } ];
               $current->{'remaining_args'} = $block_commands{$command} -1;
               $current = $current->{'args'}->[-1];
-            }
-            elsif ($command eq 'multitable') {
+            } elsif ($command eq 'multitable') {
               if ($line =~ s/address@hidden//) { 
                 # both a cmdname and block_line_arg
                 $current->{'args'} = [ { 'cmdname' => 'columnfractions', 
@@ -1053,15 +1105,25 @@
                                          'parent' => $current, 
                                          'contents' => [] } ];
                 $current = $current->{'args'}->[-1];
+              } else {
+                $current->{'sepcial'}->{'max_columns'} = 0;
+                $current->{'args'} = [ { 'type' => 'block_line_arg',
+                                         'parent' => $current, 
+                                         'contents' => [] } ];
+                $current = $current->{'args'}->[-1];
               }
-            }
-            else {
+            } elsif ($block_commands{$command} eq 'def') {
+                $current->{'args'} = [ { 'type' => 'block_line_arg',
+                                         'parent' => $current, 
+                                         'contents' => [] } ];
+                $current = $current->{'args'}->[-1];
+                #push @{$self->{'context'}}, 'def';
+            } else {
               last unless ($line =~ /\S/);
             }
           }
           # FIXME multitable and deff*
-        }
-        elsif ($line =~ s/^{// and (defined($brace_commands{$command}))) {
+        } elsif ($line =~ s/^{// and (defined($brace_commands{$command}))) {
           push @{$current->{'contents'}}, { 'cmdname' => $command, 
                                             'parent' => $current };
           $current = $current->{'contents'}->[-1];
@@ -1084,8 +1146,7 @@
           # that holds paragraphs
           if ($context_brace_commands{$command}) {
             push @{$self->{'context'}}, $command;
-          }
-          else {
+          } else {
             $current->{'type'} = 'brace_command_arg';
           }
           print STDERR "OPENED address@hidden>{'parent'}->{'cmdname'}, 
remaining $current->{'parent'}->{'remaining_args'} "
@@ -1267,6 +1328,7 @@
               }
             }
             $current = $current->{'parent'};
+            $current->{'special'}->{'max_columns'} = scalar(@fractions);
             $current->{'args'} = [ { 'cmdname' => 'columnfractions',
                                      'parent' => $current } ];
             foreach my $content (@$other_contents) {

Index: t/test_utils.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/test_utils.pl,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- t/test_utils.pl     25 Sep 2010 10:01:34 -0000      1.9
+++ t/test_utils.pl     25 Sep 2010 13:58:21 -0000      1.10
@@ -46,13 +46,17 @@
   $result = $parser->tree () if (!$result);
 
   my $file = "t/results/$self->{'name'}/$test_name.pl";
+  my $new_file = $file.'.new';
 
-  if ($self->{'generate'}) {
+  {
     local $Data::Dumper::Purity = 1;
     local $Data::Dumper::Sortkeys = 1;
     local $Data::Dumper::Indent = 1;
 
-    open (OUT, ">$file") or die "Open $file: $!\n";
+    my $out_file = $new_file;
+    $out_file = $file if ($self->{'generate'});
+
+    open (OUT, ">$out_file") or die "Open $out_file: $!\n";
     print OUT 'use vars qw(%result_texts %result_trees 
%result_errors);'."\n\n";
 
     my $out_result = "".Data::Dumper->Dump([$result], 
['$result_trees{\''.$test_name.'\'}']);
@@ -61,9 +65,9 @@
     print OUT $out_result;
     close (OUT);
     
-    print STDERR "--> $test_name\n".tree_to_texi($result)."\n";
+    print STDERR "--> $test_name\n".tree_to_texi($result)."\n" if 
($self->{'generate'});
   }
-  else {
+  if (!$self->{'generate'}) {
     require $file;
     ok (Data::Compare::Compare($result, $result_trees{$test_name}, { 
'ignore_hash_keys' => [qw(parent)] }), $test_name.' tree' );
     ok (Data::Compare::Compare($parser->errors(), $result_errors{$test_name}), 
$test_name.' errors' );

Index: t/results/columnfractions/empty.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/results/columnfractions/empty.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/columnfractions/empty.pl  25 Sep 2010 10:01:35 -0000      1.1
+++ t/results/columnfractions/empty.pl  25 Sep 2010 13:58:21 -0000      1.2
@@ -10,7 +10,10 @@
         }
       ],
       'cmdname' => 'multitable',
-      'parent' => {}
+      'parent' => {},
+      'special' => {
+        'max_columns' => 0
+      }
     }
   ]
 };

Index: t/results/columnfractions/empty_comment.pl
===================================================================
RCS file: 
/sources/texinfo/texinfo/tp/t/results/columnfractions/empty_comment.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/columnfractions/empty_comment.pl  25 Sep 2010 10:01:35 -0000      
1.1
+++ t/results/columnfractions/empty_comment.pl  25 Sep 2010 13:58:21 -0000      
1.2
@@ -22,7 +22,10 @@
         }
       ],
       'cmdname' => 'multitable',
-      'parent' => {}
+      'parent' => {},
+      'special' => {
+        'max_columns' => 0
+      }
     }
   ]
 };

Index: t/results/columnfractions/good.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/results/columnfractions/good.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/columnfractions/good.pl   25 Sep 2010 10:01:35 -0000      1.1
+++ t/results/columnfractions/good.pl   25 Sep 2010 13:58:21 -0000      1.2
@@ -27,7 +27,10 @@
         }
       ],
       'cmdname' => 'multitable',
-      'parent' => {}
+      'parent' => {},
+      'special' => {
+        'max_columns' => 3
+      }
     }
   ]
 };

Index: t/results/columnfractions/good_comment.pl
===================================================================
RCS file: 
/sources/texinfo/texinfo/tp/t/results/columnfractions/good_comment.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/columnfractions/good_comment.pl   25 Sep 2010 10:01:35 -0000      
1.1
+++ t/results/columnfractions/good_comment.pl   25 Sep 2010 13:58:21 -0000      
1.2
@@ -39,7 +39,10 @@
         }
       ],
       'cmdname' => 'multitable',
-      'parent' => {}
+      'parent' => {},
+      'special' => {
+        'max_columns' => 3
+      }
     }
   ]
 };

Index: t/results/columnfractions/good_space_comment.pl
===================================================================
RCS file: 
/sources/texinfo/texinfo/tp/t/results/columnfractions/good_space_comment.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/columnfractions/good_space_comment.pl     25 Sep 2010 10:01:35 
-0000      1.1
+++ t/results/columnfractions/good_space_comment.pl     25 Sep 2010 13:58:21 
-0000      1.2
@@ -34,7 +34,10 @@
         }
       ],
       'cmdname' => 'multitable',
-      'parent' => {}
+      'parent' => {},
+      'special' => {
+        'max_columns' => 2
+      }
     }
   ]
 };

Index: t/results/columnfractions/not_fraction.pl
===================================================================
RCS file: 
/sources/texinfo/texinfo/tp/t/results/columnfractions/not_fraction.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/columnfractions/not_fraction.pl   25 Sep 2010 10:01:35 -0000      
1.1
+++ t/results/columnfractions/not_fraction.pl   25 Sep 2010 13:58:21 -0000      
1.2
@@ -10,7 +10,10 @@
         }
       ],
       'cmdname' => 'multitable',
-      'parent' => {}
+      'parent' => {},
+      'special' => {
+        'max_columns' => 0
+      }
     }
   ]
 };

Index: t/results/columnfractions/wrong_command.pl
===================================================================
RCS file: 
/sources/texinfo/texinfo/tp/t/results/columnfractions/wrong_command.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/columnfractions/wrong_command.pl  25 Sep 2010 10:01:35 -0000      
1.1
+++ t/results/columnfractions/wrong_command.pl  25 Sep 2010 13:58:21 -0000      
1.2
@@ -32,7 +32,10 @@
         }
       ],
       'cmdname' => 'multitable',
-      'parent' => {}
+      'parent' => {},
+      'special' => {
+        'max_columns' => 0
+      }
     }
   ]
 };



reply via email to

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