texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp Texinfo/Parser.pm t/05paragraph.t t/...


From: Patrice Dumas
Subject: texinfo/tp Texinfo/Parser.pm t/05paragraph.t t/...
Date: Sun, 26 Sep 2010 07:43:25 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        10/09/26 07:43:25

Modified files:
        tp/Texinfo     : Parser.pm 
        tp/t           : 05paragraph.t 
Added files:
        tp/t/results/paragraph: close_paragraph_command.pl 

Log message:
        Handle @-commands that stop paragraphs.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/05paragraph.t?cvsroot=texinfo&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/paragraph/close_paragraph_command.pl?cvsroot=texinfo&rev=1.1

Patches:
Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- Texinfo/Parser.pm   25 Sep 2010 21:12:13 -0000      1.18
+++ Texinfo/Parser.pm   26 Sep 2010 07:43:25 -0000      1.19
@@ -413,6 +413,13 @@
   $default_no_paragraph_commands{'end '.$block_command} = 1;
 }
 
+my %close_paragraph_commands;
+foreach my $close_paragraph_command ('titlefont', 'insertcopying', 'sp',
+  'verbatiminclude', 'page', 'item', 'itemx', 'tab', 'headitem', 
+  'printindex', 'listoffloats') {
+  $close_paragraph_commands{$close_paragraph_command} = 1;
+}
+
 
 # deep copy of a structure
 sub _deep_copy ($)
@@ -985,10 +992,6 @@
         $command = $self->{'aliases'}->{$command} 
            if (exists($self->{'aliases'}->{$command}));
         print STDERR "COMMAND $command\n" if ($self->{'debug'});
-        unless ($self->{'no_paragraph_commands'}->{$command}) {
-          my $paragraph = _begin_paragraph($self, $current);
-          $current = $paragraph if ($paragraph);
-        }
         if (defined($deprecated_commands{$command})) {
           if ($deprecated_commands{$command} eq '') {
             _line_warn($self, sprintf($self->__("%c%s is obsolete."), 
@@ -999,12 +1002,27 @@
                    $self->__($deprecated_commands{$command})), $line_nr);
           }
         }
+
+        last if ($self->{'context'}->[-1] eq 'def' and $command eq "\n");
+
+        unless ($self->{'no_paragraph_commands'}->{$command}) {
+          my $paragraph = _begin_paragraph($self, $current);
+          $current = $paragraph if ($paragraph);
+        }
+
+        if ($close_paragraph_commands{$command}) {
+          my $error;
+          ($current, $error) = _end_paragraph($self, $current, $line_nr);
+          return undef if ($error);
+        }
+
         if (defined($self->{'misc_commands'}->{$command})) {
           if ($root_commands{$command}) {
             my $error;
             ($current, $error) = _end_block_command($self, $current, $line_nr);
             return undef if ($error);
           }
+            
           my ($args, $line_arg, $error);
           ($line, $args, $line_arg, $error) 
              = $self->_parse_misc_command($line, $command, $line_nr);
@@ -1012,9 +1030,6 @@
 
           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)) {
@@ -1133,14 +1148,14 @@
                 # both an argument and an @-command
                 $current->{'cmdname'} = 'columnfractions';
               }
-              #push @{$self->{'context'}}, 'def' if ($block_commands{$command} 
eq 'def');
+              push @{$self->{'context'}}, 'def' 
+                  if ($block_commands{$command} eq 'def');
             } else {
               push @{$self->{'context'}}, 'preformatted' 
                 if ($preformatted_commands{$command});
               last unless ($line =~ /\S/);
             }
           }
-          # FIXME multitable and deff*
         } elsif ($line =~ s/^{// and (defined($brace_commands{$command}))) {
           push @{$current->{'contents'}}, { 'cmdname' => $command, 
                                             'parent' => $current };
@@ -1370,20 +1385,20 @@
           } elsif ($current->{'parent'} and $current->{'parent'}->{'cmdname'}
                      and $current->{'parent'}->{'cmdname'} eq 'multitable') {
             my $line_arg = $current;
-            my @rows;
+            my @prototype_rows;
             my @other_contents;
             # rearrange the row specifications as args, which mostly 
             # implies splitting non-bracketed text and reparenting.
             foreach my $content (@{$current->{'contents'}}) {
               if ($content->{'type'} and $content->{'type'} eq 'bracketed') {
                 $content->{'parent'} = $current->{'parent'};
-                push @rows, $content;
+                push @prototype_rows, $content;
               } elsif ($content->{'text'}) {
                 if ($content->{'text'} =~ /\S/) {
-                  foreach my $raw_spec(split /\s+/, $content->{'text'}) {
-                    push @rows, { 'text' => $raw_spec, 
+                  foreach my $prototype(split /\s+/, $content->{'text'}) {
+                    push @prototype_rows, { 'text' => $prototype, 
                                   'parent' => $current->{'parent'},
-                                  'type' => 'row_specification' };
+                                  'type' => 'row_prototype' };
                   }
                 }
               } else {
@@ -1397,18 +1412,26 @@
                        and $content->{'cmdname'} eq 'comment') {
                   push @other_contents, $content;
                 } else {
-                  push @rows, $content;
+                  push @prototype_rows, $content;
                 }
                 $content->{'parent'} = $current->{'parent'};
               }
             }
             
             $current = $current->{'parent'};
-            $current->{'special'}->{'max_columns'} = scalar(@rows);
-            $current->{'args'} = address@hidden;
+            $current->{'special'}->{'max_columns'} = scalar(@prototype_rows);
+            if (!scalar(@prototype_rows)) {
+              $self->_line_warn ($self->__("empty multitable"), $line_nr);
+            }
+            $current->{'args'} = address@hidden;
             $current->{'contents'} = address@hidden;
             # this is in order to have $current->{'parent'} being the 
multitable
+            
             $current = $line_arg;
+          } elsif ($current->{'parent'} and $current->{'parent'}->{'cmdname'}
+                   and $brace_commands{$current->{'parent'}->{'cmdname'}}
+                   and $brace_commands{$current->{'parent'}->{'cmdname'}} eq 
'def') {
+            pop @{$self->{'context'}};
           }      
           $current = $current->{'parent'};
           if ($current->{'cmdname'} 
@@ -1521,10 +1544,16 @@
     #die "Shouldn't have args: $cmd->{'cmdname'}\n";
     $result .= '}' if ($braces);
   } elsif ($misc_commands{$cmd->{'cmdname'}}
-      and $misc_commands{$cmd->{'cmdname'}}->{'skip'}
-      and $misc_commands{$cmd->{'cmdname'}}->{'skip'} eq 'space') {
+      and $misc_commands{$cmd->{'cmdname'}}->{'skip'}) {
+    if ($misc_commands{$cmd->{'cmdname'}}->{'skip'} eq 'space') {
     $result .= ' ';
   }
+  }
+  if ($misc_commands{$cmd->{'cmdname'}}
+      and $misc_commands{$cmd->{'cmdname'}}->{'skip'}
+      and $misc_commands{$cmd->{'cmdname'}}->{'skip'} eq 'line') {
+    $result .="\n";
+  }
   if (defined($block_commands{$cmd->{'cmdname'}})) {
     # there is an end of line if there is a comment, for example
     chomp($result);
@@ -1610,7 +1639,7 @@
     $line = '';
 
   } elsif ($arg_spec) {
-    my $arg_nr = $misc_commands{$command}->{'arg'};
+    my $arg_nr = $arg_spec;
     while ($arg_nr) {
       if ($line =~ s/^(\s+)(\S*)//o) {
         my $argument = $2;

Index: t/05paragraph.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/05paragraph.t,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- t/05paragraph.t     25 Sep 2010 10:01:34 -0000      1.6
+++ t/05paragraph.t     26 Sep 2010 07:43:25 -0000      1.7
@@ -26,7 +26,13 @@
 [ 'paragraph_command','@@
 
 @b{aaa}.
-']
+'],
+['close_paragraph_command',
+'para @titlefont{in titlefont} after titlefont.
+
+p before sp
address@hidden 4
+inew p after sp']
 );
 
 our ($arg_test_case, $arg_generate, $arg_debug);

Index: t/results/paragraph/close_paragraph_command.pl
===================================================================
RCS file: t/results/paragraph/close_paragraph_command.pl
diff -N t/results/paragraph/close_paragraph_command.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ t/results/paragraph/close_paragraph_command.pl      26 Sep 2010 07:43:25 
-0000      1.1
@@ -0,0 +1,106 @@
+use vars qw(%result_texts %result_trees %result_errors);
+
+$result_trees{'close_paragraph_command'} = {
+  'contents' => [
+    {
+      'contents' => [
+        {
+          'parent' => {},
+          'text' => 'para '
+        }
+      ],
+      'parent' => {},
+      'type' => 'paragraph'
+    },
+    {
+      'args' => [
+        {
+          'contents' => [
+            {
+              'parent' => {},
+              'text' => 'in titlefont'
+            }
+          ],
+          'parent' => {},
+          'type' => 'brace_command_arg'
+        }
+      ],
+      'cmdname' => 'titlefont',
+      'parent' => {},
+      'remaining_args' => 0
+    },
+    {
+      'contents' => [
+        {
+          'parent' => {},
+          'text' => ' after titlefont.
+'
+        }
+      ],
+      'parent' => {},
+      'type' => 'paragraph'
+    },
+    {
+      'parent' => {},
+      'text' => '
+',
+      'type' => 'normal_line'
+    },
+    {
+      'contents' => [
+        {
+          'parent' => {},
+          'text' => 'p before sp
+'
+        }
+      ],
+      'parent' => {},
+      'type' => 'paragraph'
+    },
+    {
+      'args' => [
+        {
+          'parent' => {},
+          'text' => '4',
+          'type' => 'misc_arg'
+        }
+      ],
+      'cmdname' => 'sp',
+      'parent' => {}
+    },
+    {
+      'contents' => [
+        {
+          'parent' => {},
+          'text' => 'inew p after sp'
+        }
+      ],
+      'parent' => {},
+      'type' => 'paragraph'
+    }
+  ]
+};
+$result_trees{'close_paragraph_command'}{'contents'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'close_paragraph_command'}{'contents'}[0];
+$result_trees{'close_paragraph_command'}{'contents'}[0]{'parent'} = 
$result_trees{'close_paragraph_command'};
+$result_trees{'close_paragraph_command'}{'contents'}[1]{'args'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'close_paragraph_command'}{'contents'}[1]{'args'}[0];
+$result_trees{'close_paragraph_command'}{'contents'}[1]{'args'}[0]{'parent'} = 
$result_trees{'close_paragraph_command'}{'contents'}[1];
+$result_trees{'close_paragraph_command'}{'contents'}[1]{'parent'} = 
$result_trees{'close_paragraph_command'};
+$result_trees{'close_paragraph_command'}{'contents'}[2]{'contents'}[0]{'parent'}
 = $result_trees{'close_paragraph_command'}{'contents'}[2];
+$result_trees{'close_paragraph_command'}{'contents'}[2]{'parent'} = 
$result_trees{'close_paragraph_command'};
+$result_trees{'close_paragraph_command'}{'contents'}[3]{'parent'} = 
$result_trees{'close_paragraph_command'};
+$result_trees{'close_paragraph_command'}{'contents'}[4]{'contents'}[0]{'parent'}
 = $result_trees{'close_paragraph_command'}{'contents'}[4];
+$result_trees{'close_paragraph_command'}{'contents'}[4]{'parent'} = 
$result_trees{'close_paragraph_command'};
+$result_trees{'close_paragraph_command'}{'contents'}[5]{'args'}[0]{'parent'} = 
$result_trees{'close_paragraph_command'}{'contents'}[5];
+$result_trees{'close_paragraph_command'}{'contents'}[5]{'parent'} = 
$result_trees{'close_paragraph_command'};
+$result_trees{'close_paragraph_command'}{'contents'}[6]{'contents'}[0]{'parent'}
 = $result_trees{'close_paragraph_command'}{'contents'}[6];
+$result_trees{'close_paragraph_command'}{'contents'}[6]{'parent'} = 
$result_trees{'close_paragraph_command'};
+
+$result_texts{'close_paragraph_command'} = 'para @titlefont{in titlefont} 
after titlefont.
+
+p before sp
address@hidden 4
+inew p after sp';
+
+$result_errors{'close_paragraph_command'} = [];
+
+



reply via email to

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