[Top][All Lists]
[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: |
Thu, 23 Sep 2010 17:26:41 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 10/09/23 17:26:41
Modified files:
tp/Texinfo : Parser.pm
tp/t : 05paragraph.t test_utils.pl
tp/t/results : columnfractions.pl
Added files:
tp/t/results : paragraph.pl
Log message:
Fix in splitting of the text feed to the parser.
Fix handling of command that don't begin a paragraph.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/05paragraph.t?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/test_utils.pl?cvsroot=texinfo&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/columnfractions.pl?cvsroot=texinfo&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/paragraph.pl?cvsroot=texinfo&rev=1.1
Patches:
Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- Texinfo/Parser.pm 22 Sep 2010 22:02:47 -0000 1.6
+++ Texinfo/Parser.pm 23 Sep 2010 17:26:41 -0000 1.7
@@ -466,7 +466,9 @@
my $text = shift;
my $lines_nr = shift;
if (!ref($text)) {
- $text = [ map {$_."\n"} split /\n/, $text ];
+ my $chomped = chomp($text);
+ $text = [ map {$_."\n"} split (/\n/, $text, -1) ];
+ chomp($text->[-1]) unless ($chomped);
}
if (defined($lines_nr) and !ref($lines_nr)) {
my $first_line = $lines_nr;
@@ -701,7 +703,7 @@
my $current = shift;
my $text = shift;
- my $paragraph = _begin_paragraph($self, $current);
+ my $paragraph = _begin_paragraph($self, $current) if ($text =~ /\S/);
if (!$paragraph and
$current->{'contents'} and @{$current->{'contents'}} and
@@ -709,10 +711,12 @@
# !$current->{'contents'}->[-1]->{'type'} and
$current->{'contents'}->[-1]->{'text'} !~ /\n/) {
$current->{'contents'}->[-1]->{'text'} .= $text;
+ print STDERR "MERGED TEXT: $text\n" if ($self->{'debug'});
}
else {
$current = $paragraph if ($paragraph);
push @{$current->{'contents'}}, { 'text' => $text, 'parent' => $current };
+ print STDERR "NEW TEXT: $text\n" if ($self->{'debug'});
}
return $current;
}
Index: t/05paragraph.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/05paragraph.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/05paragraph.t 22 Sep 2010 22:02:48 -0000 1.1
+++ t/05paragraph.t 23 Sep 2010 17:26:41 -0000 1.2
@@ -16,12 +16,14 @@
[ 'text space comment', ' text @c space comment' ],
[ 'text line', '
text
+
'],
[ 'comment between text', 'text
@c comment
end para' ],
[ 'two lines','text l 1
-text l 2'],
+text l 2
+'],
[ 'no paragraph commands', '@*
@titlefont{title font}
@image{aa,bb,cc,dd,ee}
Index: t/test_utils.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/test_utils.pl,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- t/test_utils.pl 22 Sep 2010 22:02:48 -0000 1.4
+++ t/test_utils.pl 23 Sep 2010 17:26:41 -0000 1.5
@@ -43,7 +43,8 @@
if ($self->{'generate'}) {
local $Data::Dumper::Purity = 1;
- $Data::Dumper::Sortkeys = 1;
+ local $Data::Dumper::Sortkeys = 1;
+ local $Data::Dumper::Indent = 1;
my $FH = $self->{'fh'};
print $FH "################ $test_name\n";
print $FH "".Data::Dumper->Dump([$result],
['$result_trees{\''.$test_name.'\'}']);
Index: t/results/columnfractions.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/results/columnfractions.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- t/results/columnfractions.pl 21 Sep 2010 21:55:25 -0000 1.3
+++ t/results/columnfractions.pl 23 Sep 2010 17:26:41 -0000 1.4
@@ -31,7 +31,7 @@
'parent' => {}
}
]
- };
+};
$result_trees{'good'}{'contents'}[0]{'args'}[0]{'args'}[0]{'parent'} =
$result_trees{'good'}{'contents'}[0]{'args'}[0];
$result_trees{'good'}{'contents'}[0]{'args'}[0]{'args'}[1]{'parent'} =
$result_trees{'good'}{'contents'}[0]{'args'}[0];
$result_trees{'good'}{'contents'}[0]{'args'}[0]{'args'}[2]{'parent'} =
$result_trees{'good'}{'contents'}[0]{'args'}[0];
@@ -88,7 +88,7 @@
'parent' => {}
}
]
- };
+};
$result_trees{'good_comment'}{'contents'}[0]{'args'}[0]{'args'}[0]{'parent'} =
$result_trees{'good_comment'}{'contents'}[0]{'args'}[0];
$result_trees{'good_comment'}{'contents'}[0]{'args'}[0]{'args'}[1]{'parent'} =
$result_trees{'good_comment'}{'contents'}[0]{'args'}[0];
$result_trees{'good_comment'}{'contents'}[0]{'args'}[0]{'args'}[2]{'parent'} =
$result_trees{'good_comment'}{'contents'}[0]{'args'}[0];
@@ -142,7 +142,7 @@
'parent' => {}
}
]
- };
+};
$result_trees{'good_space_comment'}{'contents'}[0]{'args'}[0]{'args'}[0]{'parent'}
= $result_trees{'good_space_comment'}{'contents'}[0]{'args'}[0];
$result_trees{'good_space_comment'}{'contents'}[0]{'args'}[0]{'args'}[1]{'parent'}
= $result_trees{'good_space_comment'}{'contents'}[0]{'args'}[0];
$result_trees{'good_space_comment'}{'contents'}[0]{'args'}[0]{'parent'} =
$result_trees{'good_space_comment'}{'contents'}[0];
@@ -171,7 +171,7 @@
'parent' => {}
}
]
- };
+};
$result_trees{'not_fraction'}{'contents'}[0]{'args'}[0]{'parent'} =
$result_trees{'not_fraction'}{'contents'}[0];
$result_trees{'not_fraction'}{'contents'}[0]{'parent'} =
$result_trees{'not_fraction'};
@@ -189,7 +189,7 @@
'text' => 'column fraction not a number:
aaa',
'type' => 'error'
}
- ];
+];
################ empty
@@ -206,7 +206,7 @@
'parent' => {}
}
]
- };
+};
$result_trees{'empty'}{'contents'}[0]{'args'}[0]{'parent'} =
$result_trees{'empty'}{'contents'}[0];
$result_trees{'empty'}{'contents'}[0]{'parent'} = $result_trees{'empty'};
@@ -224,7 +224,7 @@
'text' => 'Empty @columnfractions',
'type' => 'error'
}
- ];
+];
################ empty_comment
@@ -253,7 +253,7 @@
'parent' => {}
}
]
- };
+};
$result_trees{'empty_comment'}{'contents'}[0]{'args'}[0]{'parent'} =
$result_trees{'empty_comment'}{'contents'}[0];
$result_trees{'empty_comment'}{'contents'}[0]{'args'}[1]{'args'}[0]{'parent'}
= $result_trees{'empty_comment'}{'contents'}[0]{'args'}[1];
$result_trees{'empty_comment'}{'contents'}[0]{'args'}[1]{'parent'} =
$result_trees{'empty_comment'}{'contents'}[0];
@@ -273,7 +273,7 @@
'text' => '@columnfractions accepts only
fractions as argument',
'type' => 'error'
}
- ];
+];
################ wrong_command
@@ -312,7 +312,7 @@
'parent' => {}
}
]
- };
+};
$result_trees{'wrong_command'}{'contents'}[0]{'args'}[0]{'parent'} =
$result_trees{'wrong_command'}{'contents'}[0];
$result_trees{'wrong_command'}{'contents'}[0]{'args'}[1]{'args'}[0]{'contents'}[0]{'parent'}
= $result_trees{'wrong_command'}{'contents'}[0]{'args'}[1]{'args'}[0];
$result_trees{'wrong_command'}{'contents'}[0]{'args'}[1]{'args'}[0]{'parent'}
= $result_trees{'wrong_command'}{'contents'}[0]{'args'}[1];
@@ -334,7 +334,7 @@
'text' => '@columnfractions accepts only
fractions as argument',
'type' => 'error'
}
- ];
+];
Index: t/results/paragraph.pl
===================================================================
RCS file: t/results/paragraph.pl
diff -N t/results/paragraph.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/results/paragraph.pl 23 Sep 2010 17:26:41 -0000 1.1
@@ -0,0 +1,414 @@
+use vars qw(%result_texts %result_trees %result_errors);
+
+################ text
+$result_trees{'text'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'text'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ]
+};
+$result_trees{'text'}{'contents'}[0]{'contents'}[0]{'parent'} =
$result_trees{'text'}{'contents'}[0];
+$result_trees{'text'}{'contents'}[0]{'parent'} = $result_trees{'text'};
+
+$result_texts{'text'} = 'text';
+
+$result_errors{'text'} = [];
+
+
+################ text comment
+$result_trees{'text comment'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'text'
+ },
+ {
+ 'args' => [
+ {
+ 'parent' => {},
+ 'text' => ' comment',
+ 'type' => 'misc_arg'
+ }
+ ],
+ 'cmdname' => 'c',
+ 'parent' => {}
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ]
+};
+$result_trees{'text comment'}{'contents'}[0]{'contents'}[0]{'parent'} =
$result_trees{'text comment'}{'contents'}[0];
+$result_trees{'text
comment'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'parent'} =
$result_trees{'text comment'}{'contents'}[0]{'contents'}[1];
+$result_trees{'text comment'}{'contents'}[0]{'contents'}[1]{'parent'} =
$result_trees{'text comment'}{'contents'}[0];
+$result_trees{'text comment'}{'contents'}[0]{'parent'} = $result_trees{'text
comment'};
+
+$result_texts{'text comment'} = 'address@hidden comment';
+
+$result_errors{'text comment'} = [];
+
+
+################ text space comment
+$result_trees{'text space comment'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => ' text '
+ },
+ {
+ 'args' => [
+ {
+ 'parent' => {},
+ 'text' => ' space comment',
+ 'type' => 'misc_arg'
+ }
+ ],
+ 'cmdname' => 'c',
+ 'parent' => {}
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ]
+};
+$result_trees{'text space comment'}{'contents'}[0]{'contents'}[0]{'parent'} =
$result_trees{'text space comment'}{'contents'}[0];
+$result_trees{'text space
comment'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'parent'} =
$result_trees{'text space comment'}{'contents'}[0]{'contents'}[1];
+$result_trees{'text space comment'}{'contents'}[0]{'contents'}[1]{'parent'} =
$result_trees{'text space comment'}{'contents'}[0];
+$result_trees{'text space comment'}{'contents'}[0]{'parent'} =
$result_trees{'text space comment'};
+
+$result_texts{'text space comment'} = ' text @c space comment';
+
+$result_errors{'text space comment'} = [];
+
+
+################ text line
+$result_trees{'text line'} = {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'normal_line'
+ },
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'text
+'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'normal_line'
+ }
+ ]
+};
+$result_trees{'text line'}{'contents'}[0]{'parent'} = $result_trees{'text
line'};
+$result_trees{'text line'}{'contents'}[1]{'contents'}[0]{'parent'} =
$result_trees{'text line'}{'contents'}[1];
+$result_trees{'text line'}{'contents'}[1]{'parent'} = $result_trees{'text
line'};
+$result_trees{'text line'}{'contents'}[2]{'parent'} = $result_trees{'text
line'};
+
+$result_texts{'text line'} = '
+text
+
+';
+
+$result_errors{'text line'} = [];
+
+
+################ comment between text
+$result_trees{'comment between text'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'text
+'
+ },
+ {
+ 'args' => [
+ {
+ 'parent' => {},
+ 'text' => ' comment
+',
+ 'type' => 'misc_arg'
+ }
+ ],
+ 'cmdname' => 'c',
+ 'parent' => {}
+ },
+ {
+ 'parent' => {},
+ 'text' => 'end para'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ]
+};
+$result_trees{'comment between text'}{'contents'}[0]{'contents'}[0]{'parent'}
= $result_trees{'comment between text'}{'contents'}[0];
+$result_trees{'comment between
text'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'parent'} =
$result_trees{'comment between text'}{'contents'}[0]{'contents'}[1];
+$result_trees{'comment between text'}{'contents'}[0]{'contents'}[1]{'parent'}
= $result_trees{'comment between text'}{'contents'}[0];
+$result_trees{'comment between text'}{'contents'}[0]{'contents'}[2]{'parent'}
= $result_trees{'comment between text'}{'contents'}[0];
+$result_trees{'comment between text'}{'contents'}[0]{'parent'} =
$result_trees{'comment between text'};
+
+$result_texts{'comment between text'} = 'text
address@hidden comment
+end para';
+
+$result_errors{'comment between text'} = [];
+
+
+################ two lines
+$result_trees{'two lines'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'text l 1
+'
+ },
+ {
+ 'parent' => {},
+ 'text' => 'text l 2
+'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ]
+};
+$result_trees{'two lines'}{'contents'}[0]{'contents'}[0]{'parent'} =
$result_trees{'two lines'}{'contents'}[0];
+$result_trees{'two lines'}{'contents'}[0]{'contents'}[1]{'parent'} =
$result_trees{'two lines'}{'contents'}[0];
+$result_trees{'two lines'}{'contents'}[0]{'parent'} = $result_trees{'two
lines'};
+
+$result_texts{'two lines'} = 'text l 1
+text l 2
+';
+
+$result_errors{'two lines'} = [];
+
+
+################ no paragraph commands
+$result_trees{'no paragraph commands'} = {
+ 'contents' => [
+ {
+ 'cmdname' => '*',
+ 'parent' => {}
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+'
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'title font'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'titlefont',
+ 'parent' => {},
+ 'remaining_args' => 0
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+'
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'aa'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'brace_command_arg'
+ },
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'bb'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'brace_command_arg'
+ },
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'cc'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'brace_command_arg'
+ },
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'dd'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'brace_command_arg'
+ },
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'ee'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'image',
+ 'parent' => {},
+ 'remaining_args' => 0
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+'
+ }
+ ]
+};
+$result_trees{'no paragraph commands'}{'contents'}[0]{'parent'} =
$result_trees{'no paragraph commands'};
+$result_trees{'no paragraph commands'}{'contents'}[1]{'parent'} =
$result_trees{'no paragraph commands'};
+$result_trees{'no paragraph
commands'}{'contents'}[2]{'args'}[0]{'contents'}[0]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[2]{'args'}[0];
+$result_trees{'no paragraph commands'}{'contents'}[2]{'args'}[0]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[2];
+$result_trees{'no paragraph commands'}{'contents'}[2]{'parent'} =
$result_trees{'no paragraph commands'};
+$result_trees{'no paragraph commands'}{'contents'}[3]{'parent'} =
$result_trees{'no paragraph commands'};
+$result_trees{'no paragraph
commands'}{'contents'}[4]{'args'}[0]{'contents'}[0]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[4]{'args'}[0];
+$result_trees{'no paragraph commands'}{'contents'}[4]{'args'}[0]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[4];
+$result_trees{'no paragraph
commands'}{'contents'}[4]{'args'}[1]{'contents'}[0]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[4]{'args'}[1];
+$result_trees{'no paragraph commands'}{'contents'}[4]{'args'}[1]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[4];
+$result_trees{'no paragraph
commands'}{'contents'}[4]{'args'}[2]{'contents'}[0]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[4]{'args'}[2];
+$result_trees{'no paragraph commands'}{'contents'}[4]{'args'}[2]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[4];
+$result_trees{'no paragraph
commands'}{'contents'}[4]{'args'}[3]{'contents'}[0]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[4]{'args'}[3];
+$result_trees{'no paragraph commands'}{'contents'}[4]{'args'}[3]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[4];
+$result_trees{'no paragraph
commands'}{'contents'}[4]{'args'}[4]{'contents'}[0]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[4]{'args'}[4];
+$result_trees{'no paragraph commands'}{'contents'}[4]{'args'}[4]{'parent'} =
$result_trees{'no paragraph commands'}{'contents'}[4];
+$result_trees{'no paragraph commands'}{'contents'}[4]{'parent'} =
$result_trees{'no paragraph commands'};
+$result_trees{'no paragraph commands'}{'contents'}[5]{'parent'} =
$result_trees{'no paragraph commands'};
+
+$result_texts{'no paragraph commands'} = '@*
address@hidden font}
address@hidden, bb, cc, dd, ee}
+';
+
+$result_errors{'no paragraph commands'} = [];
+
+
+################ paragraph command
+$result_trees{'paragraph command'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'cmdname' => '@',
+ 'parent' => {}
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'normal_line'
+ },
+ {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'aaa'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'b',
+ 'parent' => {},
+ 'remaining_args' => 0
+ },
+ {
+ 'parent' => {},
+ 'text' => '.
+'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ]
+};
+$result_trees{'paragraph command'}{'contents'}[0]{'contents'}[0]{'parent'} =
$result_trees{'paragraph command'}{'contents'}[0];
+$result_trees{'paragraph command'}{'contents'}[0]{'contents'}[1]{'parent'} =
$result_trees{'paragraph command'}{'contents'}[0];
+$result_trees{'paragraph command'}{'contents'}[0]{'parent'} =
$result_trees{'paragraph command'};
+$result_trees{'paragraph command'}{'contents'}[1]{'parent'} =
$result_trees{'paragraph command'};
+$result_trees{'paragraph
command'}{'contents'}[2]{'contents'}[0]{'args'}[0]{'contents'}[0]{'parent'} =
$result_trees{'paragraph command'}{'contents'}[2]{'contents'}[0]{'args'}[0];
+$result_trees{'paragraph
command'}{'contents'}[2]{'contents'}[0]{'args'}[0]{'parent'} =
$result_trees{'paragraph command'}{'contents'}[2]{'contents'}[0];
+$result_trees{'paragraph command'}{'contents'}[2]{'contents'}[0]{'parent'} =
$result_trees{'paragraph command'}{'contents'}[2];
+$result_trees{'paragraph command'}{'contents'}[2]{'contents'}[1]{'parent'} =
$result_trees{'paragraph command'}{'contents'}[2];
+$result_trees{'paragraph command'}{'contents'}[2]{'parent'} =
$result_trees{'paragraph command'};
+
+$result_texts{'paragraph command'} = '@@
+
address@hidden
+';
+
+$result_errors{'paragraph command'} = [];
+
+
+
+1;
- texinfo/tp Texinfo/Parser.pm t/05paragraph.t t/...,
Patrice Dumas <=