[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp Texinfo/Parser.pm t/03coverage_brace...
From: |
Patrice Dumas |
Subject: |
texinfo/tp Texinfo/Parser.pm t/03coverage_brace... |
Date: |
Thu, 23 Sep 2010 23:24:42 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 10/09/23 23:24:42
Modified files:
tp/Texinfo : Parser.pm
tp/t : 03coverage_braces.t
tp/t/results : coverage_braces.pl
Log message:
Better tracking of the context.
Sort out contexts with or without paragraphs.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/03coverage_braces.t?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/coverage_braces.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.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- Texinfo/Parser.pm 23 Sep 2010 19:14:03 -0000 1.9
+++ Texinfo/Parser.pm 23 Sep 2010 23:24:42 -0000 1.10
@@ -126,11 +126,16 @@
# Commands that enclose full texts
my %context_brace_commands;
foreach my $context_brace_command ('footnote', 'caption', 'shortcaption') {
- $context_brace_commands{$context_brace_command} = '';
+ $context_brace_commands{$context_brace_command} = $context_brace_command;
}
$context_brace_commands{'math'} = 'math';
+my %no_paragraph_contexts;
+foreach my $no_paragraph_context ('math', 'preformatted', 'menu') {
+ $no_paragraph_contexts{$no_paragraph_context} = 1;
+};
+
# commands delimiting blocks, typically with an @end.
# Value is either the number of arguments on the line separated by
# commas or the type of command, 'raw', 'def' or 'multitable'.
@@ -526,7 +531,7 @@
$args = "args(".scalar(@{$current->{'args'}}).')' if $current->{'args'};
$contents = "contents(".scalar(@{$current->{'contents'}}).')'
if $current->{'contents'};
- print STDERR "$cmd$type : $args $contents\n$parent_string";
+ return "$cmd$type : $args $contents\n$parent_string";
}
sub _line_warn($$$)
@@ -552,6 +557,7 @@
if ($parser->{'generate'}) {
warn $warn_line;
} else {
+ warn $warn_line if ($parser->{'debug'});
push @{$parser->{'errors_warnings'}},
{ 'type' => 'warning', 'text' => $text, 'error_line' => $warn_line,
%{$line_number} };
@@ -587,6 +593,7 @@
if ($parser->{'error'} eq 'generate') {
warn "$error_text";
} else {
+ warn "$error_text" if ($parser->{'debug'});
push @{$parser->{'errors_warnings'}},
{ 'type' => 'error', 'text' => $text, 'error_line' => $error_text,
%{$line_number} };
@@ -620,7 +627,7 @@
my $current = shift;
if ((!$current->{'type'} or $current->{'type'} eq 'container')
- and $self->{'context'}->[-1] eq '') {
+ and !$no_paragraph_contexts{$self->{'context'}->[-1]}) {
push @{$current->{'contents'}},
{ 'type' => 'paragraph', 'parent' => $current, 'contents' => [] };
$current = $current->{'contents'}->[-1];
@@ -686,13 +693,15 @@
# stop if at the root
and $current->{'parent'}
# stop if in a root command
- # or in a context_brace_commands and searching for a specific end block
command.
- # This second condition means that a footnote is not closed when looking
for
- # the end of a block command, but is closed when completly closing the
stack.
+ # or in a context_brace_commands and searching for a specific
+ # end block command.
+ # This second condition means that a footnote is not closed when
+ # looking for the end of a block command, but is closed when
+ # completly closing the stack.
and !($current->{'cmdname'}
and ($root_commands{$current->{'cmdname'}}
or ($command and $current->{'parent'}->{'cmdname'}
- and $current->{'parent'}->{'cmdname'} eq 'footnote')))){
+ and
$context_brace_commands{$current->{'parent'}->{'cmdname'}})))){
if ($current->{'cmdname'}
and exists($block_commands{$current->{'cmdname'}})) {
my $error = $self->_line_error(
@@ -734,12 +743,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'});
+ 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'});
+ print STDERR "NEW TEXT: $text|||\n" if ($self->{'debug'});
}
return $current;
}
@@ -771,7 +780,7 @@
{
my $self = shift;
my $text = shift;
- my $line_nr = shift;
+ my $lines_array = shift;
my $no_para = shift;
# FIXME find on the tree
@@ -781,11 +790,12 @@
my $root = { 'contents' => [] };
$self->{'tree'} = $root;
- $self->{'context'} = [ '' ];
+ $self->{'context'} = [ '_root' ];
my $current = $root;
# This holds the line number. Similar with line_nr, but simpler.
my $line_index = 1;
+ my $line_nr;
while (@$text) {
my $new_text = shift @$text;
@@ -793,7 +803,7 @@
#next if ($new_text = '');
$new_line .= $new_text;
- my $line_nr = shift @$line_nr;
+ $line_nr = shift @$lines_array;
my $chomped_text = $new_text;
if (@$text and !chomp($chomped_text)) {
@@ -805,8 +815,12 @@
$line_index++;
if ($self->{'debug'}) {
+ $current->{'HERE !!!!'} = 1;
+ local $Data::Dumper::Indent = 1;
+ local $Data::Dumper::Purity = 1;
print STDERR "".Data::Dumper->Dump([$root], ['$root']);
print STDERR "NEW LINE: $line";
+ delete $current->{'HERE !!!!'};
}
if ($line !~ /\S/ and not
@@ -820,7 +834,7 @@
and $current->{'parent'}->{'cmdname'} eq 'verb')
))
# not in math or preformatted
- and $self->{'context'}->[-1] eq '') {
+ and !$no_paragraph_contexts{$self->{'context'}->[-1]}) {
print STDERR "EMPTY LINE\n" if ($self->{'debug'});
my $error;
($current, $error) = _end_paragraph($self, $current, $line_nr);
@@ -955,8 +969,7 @@
$current = $current->{'args'}->[-1];
}
# FIXME @tab and @item, special case for @item(x) in @table...
- }
- elsif (exists($block_commands{$command})) {
+ } elsif (exists($block_commands{$command})) {
my $macro;
if ($command eq 'macro') {
$macro = _parse_macro_command ($line, $current);
@@ -965,8 +978,7 @@
push @{$current->{'contents'}}, $macro;
$current = $current->{'contents'}->[-1];
last;
- }
- else {
+ } else {
my $error;
($current, $error) = _end_paragraph($self, $current, $line_nr);
return undef if ($error);
@@ -1018,20 +1030,20 @@
if ($brace_commands{$command}) {
$current->{'args'} = [ { 'parent' => $current,
'contents' => [] } ];
- if ($brace_commands{$command}) {
$current->{'remaining_args'} = $brace_commands{$command} -1;
- }
$current = $current->{'args'}->[-1];
# no type for footnote, such that it appears as a container
# that holds paragraphs
- if (exists($context_brace_commands{$command})) {
- push @{$self->{'context'}}, $context_brace_commands{$command}
+ if ($context_brace_commands{$command}) {
+ push @{$self->{'context'}}, $command;
}
else {
$current->{'type'} = 'brace_command_arg';
}
+ print STDERR "OPENED address@hidden>{'parent'}->{'cmdname'},
remaining $current->{'parent'}->{'remaining_args'} "
+ .($current->{'type'} ? $current->{'type'} : '')."\n"
+ if ($self->{'debug'});
}
-
} elsif ($accent_commands{$command}) {
if ($command =~ /^[a-zA-Z]/) {
$line =~ s/^\s*//;
@@ -1098,10 +1110,25 @@
} elsif ($current->{'parent'}
and $current->{'parent'}->{'cmdname'}
and $brace_commands{$current->{'parent'}->{'cmdname'}}) {
- pop @{$self->{'context'}} if (exists
($context_brace_commands{$current->{'parent'}->{'cmdname'}}));
+ if ($context_brace_commands{$current->{'parent'}->{'cmdname'}}) {
+ pop @{$self->{'context'}};
+ }
# first is the arg.
+ print STDERR "CLOSING address@hidden>{'parent'}->{'cmdname'}\n"
if ($self->{'debug'});
$current = $current->{'parent'}->{'parent'};
-
+ } elsif ($context_brace_commands{$self->{'context'}->[-1]}) {
+ my $error;
+ ($current, $error) = _end_paragraph($self, $current, $line_nr);
+ return undef if ($error);
+ if ($current->{'parent'}
+ and $current->{'parent'}->{'cmdname'}
+ and $brace_commands{$current->{'parent'}->{'cmdname'}}
+ and
$context_brace_commands{$current->{'parent'}->{'cmdname'}}
+ and
$context_brace_commands{$current->{'parent'}->{'cmdname'}} eq
$self->{'context'}->[-1]) {
+ pop @{$self->{'context'}};
+ print STDERR "CLOSING address@hidden>{'parent'}->{'cmdname'}\n"
if ($self->{'debug'});
+ $current = $current->{'parent'}->{'parent'};
+ }
} else {
return undef
if _line_error ($self, sprintf($self->__("Misplaced %c"),
Index: t/03coverage_braces.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/03coverage_braces.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/03coverage_braces.t 23 Sep 2010 20:26:44 -0000 1.1
+++ t/03coverage_braces.t 23 Sep 2010 23:24:42 -0000 1.2
@@ -6,7 +6,10 @@
['simple', '@b{in b}.'],
['nested', 'type the characters @kbd{l o g o u t @key{RET}}.'],
['nested_args', '@xref{@@ @samp{in samp}, descr @b{in b}}'],
-['too much args', '@abbr{AZE, A truc Z b, E eep}']
+['too much args', '@abbr{AZE, A truc Z b, E eep}'],
+['footnote', 'address@hidden footnote.
+
address@hidden footnote r}. } after footnote.']
);
our ($arg_test_case, $arg_generate, $arg_debug);
Index: t/results/coverage_braces.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/results/coverage_braces.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/coverage_braces.pl 23 Sep 2010 20:26:44 -0000 1.1
+++ t/results/coverage_braces.pl 23 Sep 2010 23:24:42 -0000 1.2
@@ -256,5 +256,101 @@
$result_errors{'too much args'} = [];
+################ footnote
+$result_trees{'footnote'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'text'
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'in footnote.
+'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'normal_line'
+ },
+ {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'in footnote r'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'r',
+ 'parent' => {},
+ 'remaining_args' => 0
+ },
+ {
+ 'parent' => {},
+ 'text' => '. '
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ],
+ 'parent' => {}
+ }
+ ],
+ 'cmdname' => 'footnote',
+ 'parent' => {},
+ 'remaining_args' => 0
+ },
+ {
+ 'parent' => {},
+ 'text' => ' after footnote.'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ]
+};
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[0]{'parent'} =
$result_trees{'footnote'}{'contents'}[0];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[0]{'contents'}[0]{'parent'}
=
$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[0];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[0]{'parent'}
= $result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[1]{'parent'}
= $result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[2]{'contents'}[0]{'args'}[0]{'contents'}[0]{'parent'}
=
$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[2]{'contents'}[0]{'args'}[0];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[2]{'contents'}[0]{'args'}[0]{'parent'}
=
$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[2]{'contents'}[0];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[2]{'contents'}[0]{'parent'}
=
$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[2];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[2]{'contents'}[1]{'parent'}
=
$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[2];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'contents'}[2]{'parent'}
= $result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'args'}[0]{'parent'} =
$result_trees{'footnote'}{'contents'}[0]{'contents'}[1];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[1]{'parent'} =
$result_trees{'footnote'}{'contents'}[0];
+$result_trees{'footnote'}{'contents'}[0]{'contents'}[2]{'parent'} =
$result_trees{'footnote'}{'contents'}[0];
+$result_trees{'footnote'}{'contents'}[0]{'parent'} = $result_trees{'footnote'};
+
+$result_texts{'footnote'} = 'address@hidden footnote.
+
address@hidden footnote r}. } after footnote.';
+
+$result_errors{'footnote'} = [];
+
+
1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp Texinfo/Parser.pm t/03coverage_brace...,
Patrice Dumas <=