[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp Texinfo/Parser.pm t/06columnfractions.t
From: |
Patrice Dumas |
Subject: |
texinfo/tp Texinfo/Parser.pm t/06columnfractions.t |
Date: |
Mon, 20 Sep 2010 19:57:47 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 10/09/20 19:57:46
Modified files:
tp/Texinfo : Parser.pm
tp/t : 06columnfractions.t
Log message:
More reformatting
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/06columnfractions.t?cvsroot=texinfo&r1=1.2&r2=1.3
Patches:
Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Texinfo/Parser.pm 20 Sep 2010 17:55:54 -0000 1.2
+++ Texinfo/Parser.pm 20 Sep 2010 19:57:44 -0000 1.3
@@ -64,7 +64,7 @@
}
my %default_configuration = (
- 'error' => 'generate',
+ 'error' => 'generate', #
'force' => 0,
'no_warn' => 0,
'error_limit' => 100,
@@ -490,20 +490,18 @@
my $text = shift;
chomp ($text);
my $line_number = shift;
- if (defined($line_number))
- {
+ if (defined($line_number)) {
my $file = $line_number->{'file_name'};
$file =~ s/^.*\/// if ($parser->{'test'});
my $macro_text = '';
- $macro_text = " (possibly involving address@hidden>{'macro'})" if
($line_number->{'macro'} ne '');
+ $macro_text = " (possibly involving address@hidden>{'macro'})"
+ if ($line_number->{'macro'} ne '');
my $error_text = "$file:$line_number->{'line_nr'}: $text$macro_text\n";
- if ($parser->{'error'} eq 'generate')
- {
+ if ($parser->{'error'} eq 'generate') {
warn "$error_text";
return 1 unless ($parser->{'force'});
}
- else
- {
+ else {
return $error_text unless ($parser->{'force'});
}
}
@@ -515,13 +513,15 @@
my $line = shift;
my $parent = shift;
my $macro;
- if ($line =~ /^\s+(\w[\w-]*)\s*(.*)/)
- {
+ if ($line =~ /^\s+(\w[\w-]*)\s*(.*)/) {
my $macro_arg_name = $1;
my $macro_arg_args = $2;
$macro = { 'cmdname' => 'macro', 'parent' => $parent, 'contents' => [] };
- $macro->{'args'} = [ { 'type' => 'macro_arg_name', 'text' =>
$macro_arg_name, 'parent' => $macro },
- { 'type' => 'macro_arg_args', 'text' =>
$macro_arg_args, 'parent' => $macro} ];
+ $macro->{'args'} = [
+ { 'type' => 'macro_arg_name', 'text' => $macro_arg_name,
+ 'parent' => $macro },
+ { 'type' => 'macro_arg_args', 'text' => $macro_arg_args,
+ 'parent' => $macro} ];
}
return $macro;
}
@@ -596,18 +596,15 @@
$new_line = '';
$line_index++;
- if ($self->{'debug'})
- {
+ if ($self->{'debug'}) {
print STDERR "NEW LINE; $line";
print STDERR "".Data::Dumper->Dump([$root], ['$root']);
}
# to determine if it is a menu entry, check ^*, and if set, add
# : to the separators list.
- if ($in_menu)
- {
- if ($line =~ s/^(\*\s+)//)
- {
+ if ($in_menu) {
+ if ($line =~ s/^(\*\s+)//) {
my $leading_text = $1;
$maybe_menu_entry = ':';
#push @separators, ':';
@@ -619,48 +616,48 @@
}
}
- while (1)
- {
- if ($current->{'cmdname'} and $block_commands{$current->{'cmdname'}}
and ($block_commands{$current->{'cmdname'}} eq 'raw'))
- {
+ while (1) {
+ if ($current->{'cmdname'} and
+ $block_commands{$current->{'cmdname'}} and
+ ($block_commands{$current->{'cmdname'}} eq 'raw')) {
# special case for macro that may be nested
my $macro;
- if ($current->{'cmdname'} eq 'macro' and $line =~ /address@hidden/)
- {
+ if ($current->{'cmdname'} eq 'macro' and $line =~ /address@hidden/) {
my $mline = $line;
$mline =~ s/address@hidden//;
$macro = _parse_macro_command ($mline, $current);
}
- if ($macro)
- {
+ if ($macro) {
push @{$current->{'contents'}}, $macro;
$current = $current->{'contents'}->[-1];
last;
}
- elsif ($line =~ /^(.*?)address@hidden([a-zA-Z][\w-]*)/o and ($2 eq
$current->{'cmdname'}))
- {
+ elsif ($line =~ /^(.*?)address@hidden([a-zA-Z][\w-]*)/o and ($2 eq
$current->{'cmdname'})) {
$line =~ s/^(.*?)(address@hidden>{'cmdname'})//;
- push @{$current->{'contents'}}, { 'text' => $1, 'type' =>
'raw', 'parent' => $current } if ($1 ne '');
+ push @{$current->{'contents'}},
+ { 'text' => $1, 'type' => 'raw', 'parent' => $current }
+ if ($1 ne '');
$current = $current->{'parent'};
last unless ($line =~ /\S/);
}
- else
- {
+ else {
push @{$current->{'contents'}}, { 'text' => $line, 'type' =>
'raw', 'parent' => $current };
last;
}
}
- elsif ($current->{'type'} and $current->{'parent'}->{'cmdname'} and
$current->{'parent'}->{'cmdname'} eq 'verb')
- { # type should be 'brace_command_arg'
+ elsif ($current->{'type'} and $current->{'parent'}->{'cmdname'} and
+ $current->{'parent'}->{'cmdname'} eq 'verb') {
+ # type should be 'brace_command_arg'
my $char = quotemeta($current->{'type'});
- if ($line =~ s/^(.*?)$char\}/\}/)
- {
- push @{$current->{'contents'}}, { 'text' => $1, 'type' =>
'raw', 'parent' => $current } if ($1 ne '');
+ if ($line =~ s/^(.*?)$char\}/\}/) {
+ push @{$current->{'contents'}},
+ { 'text' => $1, 'type' => 'raw', 'parent' => $current }
+ if ($1 ne '');
}
- else
- {
- push @{$current->{'contents'}}, { 'text' => $line, 'type' =>
'raw', 'parent' => $current };
+ else {
+ push @{$current->{'contents'}},
+ { 'text' => $line, 'type' => 'raw', 'parent' => $current };
last;
}
}
@@ -668,8 +665,7 @@
_merge_text ($current, $1) if ($1 ne '');
# separators: $maybe_menu_entry$command_comma$maybe_menu_name
- if ($line =~ s/address@hidden([a-zA-Z][\w-]*)//)
- {
+ if ($line =~ s/address@hidden([a-zA-Z][\w-]*)//) {
my $end_command = $1;
print STDERR "END COMMAND $end_command\n" if ($self->{'debug'});
# close paragraph
@@ -680,104 +676,106 @@
$current = $current->{'parent'};
last unless ($line =~ /\S/);
}
- elsif ($line =~ s/^\@(["'address@hidden,\.!\?\s\*\-\^`=:\|\/\\])//o or
$line =~ s/^\@([a-zA-Z][\w-]*)//o)
- {
+ elsif ($line =~ s/^\@(["'address@hidden,\.!\?\s\*\-\^`=:\|\/\\])//o
+ or $line =~ s/^\@([a-zA-Z][\w-]*)//o) {
my $command = $1;
- $command = $self->{'aliases'}->{$command} if
(exists($self->{'aliases'}->{$command}));
+ $command = $self->{'aliases'}->{$command}
+ if (exists($self->{'aliases'}->{$command}));
print STDERR "COMMAND $command\n" if ($self->{'debug'});
- if (defined($deprecated_commands{$command}))
- {
- if ($deprecated_commands{$command} eq '')
- {
- _line_warn($self, sprintf($self->__("%c%s is obsolete."),
ord('@'), $command), $line_nr);
+ if (defined($deprecated_commands{$command})) {
+ if ($deprecated_commands{$command} eq '') {
+ _line_warn($self, sprintf($self->__("%c%s is obsolete."),
+ ord('@'), $command), $line_nr);
}
- else
- {
- _line_warn($self, sprintf($self->__("%c%s is obsolete;
%s"),ord('@'), $command, $self->__($deprecated_commands{$command})), $line_nr);
+ else {
+ _line_warn($self, sprintf($self->__("%c%s is obsolete; %s"),
+ ord('@'), $command,
+ $self->__($deprecated_commands{$command})), $line_nr);
}
}
- if (defined($self->{'misc_commands'}->{$command}))
- {
+ if (defined($self->{'misc_commands'}->{$command})) {
my ($args, $line_arg, $error);
- ($line, $args, $line_arg, $error) =
$self->_parse_misc_command($line, $command, $line_nr);
+ ($line, $args, $line_arg, $error)
+ = $self->_parse_misc_command($line, $command, $line_nr);
return $error if ($error);
- push @{$current->{'contents'}}, { 'cmdname' => $command,
'parent' => $current };
+ push @{$current->{'contents'}},
+ { 'cmdname' => $command, 'parent' => $current };
- foreach my $arg (@$args)
- {
+ foreach my $arg (@$args) {
push @{$current->{'contents'}->[-1]->{'args'}},
- { 'type' => 'misc_arg', 'text' => $arg, 'parent' =>
$current->{'contents'}->[-1] };
+ { 'type' => 'misc_arg', 'text' => $arg,
+ 'parent' => $current->{'contents'}->[-1] };
}
- if (defined($line_arg))
- {
+ if (defined($line_arg)) {
$line = $line_arg;
$current = $current->{'contents'}->[-1];
- $current->{'args'} = [ { 'type' => 'misc_line_arg',
'contents' => [], 'parent' => $current } ];
+ $current->{'args'} = [ { 'type' => 'misc_line_arg',
+ 'contents' => [],
+ 'parent' => $current } ];
# @node is the only misc command with args separated with
comma
+ # FIXME a 4 lingering here deep into the code may not
+ # be very wise...
$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}))
- {
+ elsif (exists($block_commands{$command})) {
my $macro;
- if ($command eq 'macro')
- {
+ if ($command eq 'macro') {
$macro = _parse_macro_command ($line, $current);
}
- if ($macro)
- {
+ if ($macro) {
push @{$current->{'contents'}}, $macro;
$current = $current->{'contents'}->[-1];
last;
}
- else
- {
+ else {
$line =~ s/\s*//;
- push @{$current->{'contents'}}, { 'cmdname' => $command,
'parent' => $current };
+ push @{$current->{'contents'}}, { 'cmdname' => $command,
+ 'parent' => $current };
$current = $current->{'contents'}->[-1];
- if ($block_commands{$command} and $block_commands{$command}
=~ /^\d+$/) {
+ if ($block_commands{$command} and
+ $block_commands{$command} =~ /^\d+$/) {
$current->{'args'} = [ { 'type' => 'block_line_arg',
'contents' => [], 'parent' => $current } ];
$current->{'remaining_args'} = $block_commands{$command}
-1;
$current = $current->{'args'}->[-1];
}
elsif ($command eq 'multitable') {
- if ($line =~ s/address@hidden//)
- { # both a cmdname and block_line_arg
- $current->{'args'} = [ { 'cmdname' =>
'columnfractions', 'type' => 'block_line_arg', 'parent' => $current, 'contents'
=> [] } ];
+ if ($line =~ s/address@hidden//) {
+ # both a cmdname and block_line_arg
+ $current->{'args'} = [ { 'cmdname' => 'columnfractions',
+ 'type' => 'block_line_arg',
+ 'parent' => $current,
+ 'contents' => [] } ];
$current = $current->{'args'}->[-1];
}
}
- else
- {
+ else {
last unless ($line =~ /\S/);
}
}
# FIXME multitable and deff*
}
- elsif ($line =~ s/^{// and (defined($brace_commands{$command}) or
defined($accent_commands{$command})))
- {
- push @{$current->{'contents'}}, { 'cmdname' => $command,
'parent' => $current };
+ elsif ($line =~ s/^{// and (defined($brace_commands{$command}) or
defined($accent_commands{$command}))) {
+ push @{$current->{'contents'}}, { 'cmdname' => $command,
+ 'parent' => $current };
$current = $current->{'contents'}->[-1];
- if ($command eq 'verb')
- {
- if ($line =~ /^$/)
- {
+ if ($command eq 'verb') {
+ if ($line =~ /^$/) {
my $error = _line_error ($self,
sprintf($self->__("address@hidden without associated character"), $command),
$line_nr);
return $error if ($error);
}
- else
- {
+ else {
$line =~ s/^(.)//;
$current->{'type'} = $1;
}
}
- if ($brace_commands{$command} or $accent_commands{$command})
- {
- $current->{'args'} = [ { 'type' => 'brace_command_arg',
'parent' => $current, 'contents' => [] } ];
- if ($brace_commands{$command})
- {
+ if ($brace_commands{$command} or $accent_commands{$command}) {
+ $current->{'args'} = [ { 'type' => 'brace_command_arg',
+ 'parent' => $current,
+ 'contents' => [] } ];
+ if ($brace_commands{$command}) {
$current->{'remaining_args'} = $brace_commands{$command}
-1;
}
$current = $current->{'args'}->[-1];
@@ -801,59 +799,48 @@
}
else { # The accent is at end of line
# FIXME warn? And test case? Maybe this is catched
- # above, by "Accent command address@hidden' must not be
followed by whitespace"
- # for commands with letter.
+ # above, by "Accent command address@hidden' must not be followed by
+ # whitespace for commands with letter.
push @{$current->{'contents'}}, { 'text' => $command, 'parent'
=> $current };
}
}
- elsif ($no_brace_commands{$command})
- {
+ elsif ($no_brace_commands{$command}) {
push @{$current->{'contents'}}, { 'cmdname' => $command,
'parent' => $current };
}
- else
- {
+ else {
# unknown
}
}
- elsif ($line =~ s/^([{}@,])//)
- {
+ elsif ($line =~ s/^([{}@,])//) {
my $separator = $1;
print STDERR "SEPARATOR: $separator\n" if ($self->{'debug'});
- if ($separator eq '@')
- {
+ if ($separator eq '@') {
my $error = _line_error ($self, $self->__("Unexpected \@"),
$line_nr);
return $error if ($error);
}
- elsif ($separator eq '{')
- {
- if ($current->{'cmdname'} and
($block_commands{$current->{'cmdname'}} eq 'multitable' or
$block_commands{$current->{'cmdname'}} eq 'bracketed'))
- {
+ elsif ($separator eq '{') {
+ if ($current->{'cmdname'} and
+ ($block_commands{$current->{'cmdname'}} eq 'multitable' or
$block_commands{$current->{'cmdname'}} eq 'bracketed')) {
push @{$current->{'args'}}, { 'type' => 'bracketed',
'contents' => [], 'parent' => $current };
$current = $current->{'args'}->[-1];
}
- else
- {
+ else {
my $error = _line_error ($self, sprintf($self->__("Misplaced
%c"), ord('{')), $line_nr);
return $error if ($error);
}
}
- elsif ($separator eq '}')
- {
+ elsif ($separator eq '}') {
# FIXME use parents
- if ($current->{'type'} and ($current->{'type'} eq 'bracketed' or
$current->{'type'} eq 'brace_command_arg'))
- {
+ if ($current->{'type'} and ($current->{'type'} eq 'bracketed' or
$current->{'type'} eq 'brace_command_arg')) {
$current = $current->{'parent'};
}
- else
- {
+ else {
my $error = _line_error ($self, sprintf($self->__("Misplaced
%c"), ord('}')), $line_nr);
return $error if ($error);
}
}
- elsif ($separator eq ',')
- {
- if ($current->{'parent'}->{'remaining_args'})
- {
+ elsif ($separator eq ',') {
+ if ($current->{'parent'}->{'remaining_args'}) {
$line =~ s/^\s*//;
my $type = $current->{'type'};
$current = $current->{'parent'};
@@ -866,63 +853,48 @@
}
}
}
- else
- {
- {
- #local $Data::Dumper::Maxdepth = 5;
- #local $Data::Dumper::Indent= 1;
- #local $Data::Dumper::Terse = 1;
- #print STDERR "END LINE: ".Data::Dumper->Dump([$current]) if
($self->{'debug'})
- if ($self->{'debug'})
- {
+ else {
+ if ($self->{'debug'}) {
print STDERR "END LINE: ";
print STDERR "type : $current->{'type'}, " if
($current->{'type'});
print STDERR "cmdname : $current->{'cmdname'}, " if
($current->{'cmdname'});
print STDERR "\n";
}
- }
- if ($line ne '')
- {
+ if ($line ne '') {
die "Remaining line: $line\n";
}
- if ($current->{'type'} and ($current->{'type'} eq 'block_line_arg'
or $current->{'type'} eq 'misc_line_arg'))
- {
- if ($current->{'cmdname'} and $current->{'cmdname'} eq
'columnfractions')
- { # the columnfraction content should be text only, maybe
followed by a comment
+ if ($current->{'type'} and ($current->{'type'} eq 'block_line_arg' or
$current->{'type'} eq 'misc_line_arg')) {
+ if ($current->{'cmdname'} and $current->{'cmdname'} eq
'columnfractions') {
+ # the columnfraction content should be text only, maybe followed
by a comment
#print STDERR "COLUMNFRACTIONS:
".Data::Dumper->Dump([$current], ['$columnfractions']) if ($self->{'debug'});
my @fractions;
my $other_contents;
- if (address@hidden>{'contents'}})
- {
+ if (address@hidden>{'contents'}}) {
my $error = _line_error ($self, sprintf($self->__("Empty
address@hidden"), $current->{'cmdname'}), $line_nr);
return $error if ($error);
}
- elsif (!defined($current->{'contents'}->[0]->{'text'}))
- {
+ elsif (!defined($current->{'contents'}->[0]->{'text'})) {
my $error = _line_error ($self,
sprintf($self->__("address@hidden accepts only fractions as argument"),
$current->{'cmdname'}), $line_nr);
return $error if ($error);
$other_contents = $current->{'contents'};
}
- else
- {
+ else {
my $fraction_argument = shift @{$current->{'contents'}};
# verify that the only remaining argument is a comment
if (@{$current->{'contents'}} and
(!$current->{'contents'}->[0]->{'cmdname'}
- or ($current->{'contents'}->[0]->{'cmdname'} ne 'c' and
$current->{'contents'}->[0]->{'cmdname'} ne 'comment')))
- {
- _line_warn ($self, sprintf($self->__("Unexpected argument
on address@hidden line: %s"), $current->{'cmdname'}, tree_to_texi( {
$current->{'contents'} })), $line_nr);
+ or ($current->{'contents'}->[0]->{'cmdname'} ne 'c' and
$current->{'contents'}->[0]->{'cmdname'} ne 'comment'))) {
+ _line_warn ($self, sprintf($self->__("Unexpected argument on
address@hidden line: %s"),
+ $current->{'cmdname'},
+ tree_to_texi( { $current->{'contents'} })),
$line_nr);
}
$other_contents = $current->{'contents'};
# now parse the fractions
my @possible_fractions = split /\s+/,
$fraction_argument->{'text'};
- foreach my $fraction (@possible_fractions)
- {
- if ($fraction =~ /^(\d*\.\d+)|(\d+)\.?$/)
- {
+ foreach my $fraction (@possible_fractions) {
+ if ($fraction =~ /^(\d*\.\d+)|(\d+)\.?$/) {
push @fractions, $fraction;
}
- else
- {
+ else {
my $error = _line_error ($self,
sprintf($self->__("column fraction not a number: %s"), $fraction), $line_nr);
return $error if ($error);
}
@@ -930,14 +902,12 @@
}
$current = $current->{'parent'};
$current->{'args'} = [ { 'cmdname' => 'columnfractions',
'parent' => $current } ];
- foreach my $content (@$other_contents)
- {
+ foreach my $content (@$other_contents) {
$content->{'parent'} = $current;
push @{$current->{'args'}}, $content;
}
$current = $current->{'args'}->[0];
- foreach my $fraction (@fractions)
- {
+ foreach my $fraction (@fractions) {
push @{$current->{'args'}}, { 'type' => 'fraction', 'text'
=> $fraction, 'parent' => $current };
}
}
Index: t/06columnfractions.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/06columnfractions.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- t/06columnfractions.t 20 Sep 2010 17:55:57 -0000 1.2
+++ t/06columnfractions.t 20 Sep 2010 19:57:46 -0000 1.3
@@ -35,7 +35,7 @@
print STDERR "--> $test_name\n".tree_to_texi($result)."\n";
}
else {
- ok (Data::Compare::Compare($result, $check), $test_name);
+ ok (Data::Compare::Compare($result, $check, { 'ignore_hash_keys' =>
[qw(parent)] }), $test_name);
}
#exit;
}