[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp Texinfo/Parser.pm t/18itemize.t t/re...
From: |
Patrice Dumas |
Subject: |
texinfo/tp Texinfo/Parser.pm t/18itemize.t t/re... |
Date: |
Tue, 05 Oct 2010 22:41:40 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 10/10/05 22:41:40
Modified files:
tp/Texinfo : Parser.pm
tp/t : 18itemize.t
tp/t/results/macro: macro_in_macro_arg.pl
Added files:
tp/t/results/itemize: accent_argument.pl
Log message:
Handle user defined macros before anything else.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.46&r2=1.47
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/18itemize.t?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/itemize/accent_argument.pl?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/macro/macro_in_macro_arg.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.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- Texinfo/Parser.pm 4 Oct 2010 23:20:17 -0000 1.46
+++ Texinfo/Parser.pm 5 Oct 2010 22:41:39 -0000 1.47
@@ -1203,7 +1203,58 @@
}
}
- if ($current->{'cmdname'} and
+ # handle user defined macros before anything else since
+ # their expansion may lead to changes in the line
+ # REMACRO
+ if ($line =~ /^\@(\w[\w-]*)/
+ and ($self->{'macros'}->{$1}
+ or (exists $self->{'aliases'}->{$1} and
+ $self->{'macros'}->{$self->{'aliases'}->{$1}}))) {
+ $line =~ s/^\@(\w[\w-]*)//o;
+ my $command = $1;
+ $command = $self->{'aliases'}->{$command}
+ if (exists($self->{'aliases'}->{$command}));
+
+ my $expanded_macro = $self->{'macros'}->{$command};
+ my $args_number = scalar(@{$expanded_macro->{'args'}}) -1;
+ my $arguments = [];
+ if ($line =~ s/^\s*{\s*//) { # macro with args
+ ($arguments, $line, $line_nr) =
+ _expand_macro_arguments ($self, $expanded_macro, $line, $line_nr,
+ $text, $lines_array);
+ } elsif (($args_number >= 2) or ($args_number <1)) {
+ _line_warn($self, sprintf($self->__("address@hidden defined with
zero or more than one argument should be invoked with {}"), $command),
$line_nr);
+ } else {
+ if ($line !~ /\n/ and @$text) {
+ ($line, $line_nr) = _new_line($text, $lines_array);
+ }
+ $line =~ s/^\s*// if ($line =~ /\S/);
+ chomp $line;
+ $arguments = [$line];
+ $line = "\n";
+ }
+ my $expanded = _expand_macro_body ($self, $expanded_macro,
+ $arguments, $line_nr);
+ print STDERR "MACROBODY: $expanded".'||||||'."\n"
+ if ($self->{'debug'});
+ my $expanded_lines = _text_to_lines($expanded);
+ print STDERR "MACRO EXPANSION LINES: ".join('|', @$expanded_lines)
+ ."\nEND LINES\n" if ($self->{'debug'});
+ chomp ($expanded_lines->[-1]);
+ my $new_lines_nr = _complete_line_nr($expanded_lines,
+ $line_nr->{'line_nr'}, $line_nr->{'file_name'},
+ $expanded_macro->{'args'}->[0]->{'text'}, 1);
+ unshift @$text, $line;
+ unshift @$lines_array, $line_nr;
+ $line = shift @$expanded_lines;
+ $line_nr = shift @$new_lines_nr;
+ unshift @$text, @$expanded_lines;
+ unshift @$lines_array, @$new_lines_nr;
+ # REMACRO
+ # Now handle all the cases that may lead to command closing
+ # or following character association with an @-command, especially
+ # accent command.
+ } elsif ($current->{'cmdname'} and
(defined($brace_commands{$current->{'cmdname'}}) or
$self->{'definfoenclose'}->{$current->{'cmdname'}})
and $line !~ /^{/) {
@@ -1256,12 +1307,6 @@
$current->{'cmdname'}), $line_nr);
$current = $current->{'parent'};
}
- }
- if ($line =~ s/^([^{}@,:\t.]+)//) {
- my $new_text = $1;
- $current = _merge_text ($self, $current, $new_text);
-
- # REMACRO
} elsif ($line =~ s/^\@(["'address@hidden,\.!\?\s\*\-\^`=:\|\/\\])//o
or $line =~ s/^\@(\w[\w-]*)//o) {
my $command = $1;
@@ -1269,41 +1314,6 @@
if (exists($self->{'aliases'}->{$command}));
print STDERR "COMMAND $command\n" if ($self->{'debug'});
- if ($self->{'macros'}->{$command}) {
- my $expanded_macro = $self->{'macros'}->{$command};
- my $args_number = scalar(@{$expanded_macro->{'args'}}) -1;
- my $arguments = [];
- if ($line =~ s/^\s*{\s*//) { # macro with args
- ($arguments, $line, $line_nr) =
- _expand_macro_arguments ($self, $expanded_macro, $line, $line_nr,
- $text, $lines_array);
- } elsif (($args_number >= 2) or ($args_number <1)) {
- _line_warn($self, sprintf($self->__("address@hidden defined with
zero or more than one argument should be invoked with {}"), $command),
$line_nr);
- } else {
- $line =~ s/^\s*// if ($line =~ /\S/);
- chomp $line;
- $arguments = [$line];
- $line = "\n";
- }
- my $expanded = _expand_macro_body ($self, $expanded_macro,
- $arguments, $line_nr);
- print STDERR "MACROBODY: $expanded".'||||||'."\n"
- if ($self->{'debug'});
- my $expanded_lines = _text_to_lines($expanded);
- print STDERR "MACRO EXPANSION LINES: ".join('|', @$expanded_lines)
- ."\nEND LINES\n" if ($self->{'debug'});
- chomp ($expanded_lines->[-1]);
- my $new_lines_nr = _complete_line_nr($expanded_lines,
- $line_nr->{'line_nr'}, $line_nr->{'file_name'},
- $expanded_macro->{'args'}->[0]->{'text'}, 1);
- unshift @$text, $line;
- unshift @$lines_array, $line_nr;
- $line = shift @$expanded_lines;
- $line_nr = shift @$new_lines_nr;
- unshift @$text, @$expanded_lines;
- unshift @$lines_array, @$new_lines_nr;
- next;
- }
if ($command eq 'value') {
if ($line =~ s/^{([\w\-]+)}//) {
@@ -1734,12 +1744,28 @@
} else {
$current = _merge_text ($self, $current, $separator);
}
+ # Misc text
+ } elsif ($line =~ s/^([^{}@,:\t.\n]+)//) {
+ my $new_text = $1;
+ $current = _merge_text ($self, $current, $new_text);
} else {
if ($self->{'debug'}) {
print STDERR "END LINE: ". _print_current($current)."\n";
}
- if ($line ne '') {
- die "Remaining line: $line\n";
+ if ($line ne "\n"
+ and !($line eq '')) {
+ # and !($current->{'contents'} and @{$current->{'contents'}}
+ # and $current->{'contents'}->[-1]
+ # and $current->{'contents'}->[-1]->{'cmdname'}
+ # and $current->{'contents'}->[-1]->{'cmdname'} eq "\n"
+ # and $line eq ''
+ # )
+ # and !($line eq '' and !scalar(@$text))) {
+ _line_warn ($self, "BUG spurious suff on line. Remaining text:
@$text", $line_nr);
+ die "Remaining line: |$line|\n";
+ }
+ if ($line =~ s/^(\n)//) {
+ $current = _merge_text ($self, $current, $1);
}
if ($current->{'type'}
and ($current->{'type'} eq 'menu_entry_name'
Index: t/18itemize.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/18itemize.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/18itemize.t 30 Sep 2010 05:35:14 -0000 1.1
+++ t/18itemize.t 5 Oct 2010 22:41:39 -0000 1.2
@@ -10,6 +10,16 @@
@item @option{--build=} platform on which the program is compiled,
@item @option{--target=} target platform on which the program is processed.
@end itemize
+'],
+# unclear that these are valid constructs...
+['accent_argument',
+'@itemize @address@hidden
address@hidden item
address@hidden itemize
+
address@hidden @~
address@hidden item
address@hidden itemize
']
);
Index: t/results/macro/macro_in_macro_arg.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/results/macro/macro_in_macro_arg.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/macro/macro_in_macro_arg.pl 2 Oct 2010 17:22:52 -0000
1.1
+++ t/results/macro/macro_in_macro_arg.pl 5 Oct 2010 22:41:40 -0000
1.2
@@ -134,7 +134,7 @@
'contents' => [
{
'parent' => {},
- 'text' => 'a, hello after arg'
+ 'text' => 'a, hello text for macro2 after arg'
}
],
'parent' => {},
@@ -150,11 +150,6 @@
'contents' => [
{
'parent' => {},
- 'text' => 'text for macro2
-'
- },
- {
- 'parent' => {},
'text' => '&&&&
'
}
@@ -185,7 +180,6 @@
$result_trees{'macro_in_macro_arg'}{'contents'}[7]{'parent'} =
$result_trees{'macro_in_macro_arg'};
$result_trees{'macro_in_macro_arg'}{'contents'}[8]{'parent'} =
$result_trees{'macro_in_macro_arg'};
$result_trees{'macro_in_macro_arg'}{'contents'}[9]{'contents'}[0]{'parent'} =
$result_trees{'macro_in_macro_arg'}{'contents'}[9];
-$result_trees{'macro_in_macro_arg'}{'contents'}[9]{'contents'}[1]{'parent'} =
$result_trees{'macro_in_macro_arg'}{'contents'}[9];
$result_trees{'macro_in_macro_arg'}{'contents'}[9]{'parent'} =
$result_trees{'macro_in_macro_arg'};
$result_texts{'macro_in_macro_arg'} = '
@@ -202,8 +196,7 @@
&&&& \\arg\\
@end macro
-a, hello after arg
-text for macro2
+a, hello text for macro2 after arg
&&&&
';
Index: t/results/itemize/accent_argument.pl
===================================================================
RCS file: t/results/itemize/accent_argument.pl
diff -N t/results/itemize/accent_argument.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/results/itemize/accent_argument.pl 5 Oct 2010 22:41:40 -0000
1.1
@@ -0,0 +1,144 @@
+use vars qw(%result_texts %result_trees %result_errors);
+
+$result_trees{'accent_argument'} = {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'cmdname' => '~',
+ 'parent' => {},
+ 'type' => 'command_as_argument'
+ },
+ {
+ 'args' => [
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'misc_arg'
+ }
+ ],
+ 'cmdname' => 'comment',
+ 'parent' => {}
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'block_line_arg'
+ }
+ ],
+ 'cmdname' => 'itemize',
+ 'contents' => [
+ {
+ 'contents' => [],
+ 'parent' => {},
+ 'type' => 'before_item'
+ },
+ {
+ 'cmdname' => 'item',
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'item
+'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ],
+ 'parent' => {}
+ }
+ ],
+ 'parent' => {},
+ 'remaining_args' => 0
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'normal_line'
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'cmdname' => '~',
+ 'parent' => {},
+ 'type' => 'command_as_argument'
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'block_line_arg'
+ }
+ ],
+ 'cmdname' => 'itemize',
+ 'contents' => [
+ {
+ 'contents' => [],
+ 'parent' => {},
+ 'type' => 'before_item'
+ },
+ {
+ 'cmdname' => 'item',
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'item
+'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ],
+ 'parent' => {}
+ }
+ ],
+ 'parent' => {},
+ 'remaining_args' => 0
+ }
+ ]
+};
+$result_trees{'accent_argument'}{'contents'}[0]{'args'}[0]{'contents'}[0]{'parent'}
= $result_trees{'accent_argument'}{'contents'}[0]{'args'}[0];
+$result_trees{'accent_argument'}{'contents'}[0]{'args'}[0]{'contents'}[1]{'args'}[0]{'parent'}
= $result_trees{'accent_argument'}{'contents'}[0]{'args'}[0]{'contents'}[1];
+$result_trees{'accent_argument'}{'contents'}[0]{'args'}[0]{'contents'}[1]{'parent'}
= $result_trees{'accent_argument'}{'contents'}[0]{'args'}[0];
+$result_trees{'accent_argument'}{'contents'}[0]{'args'}[0]{'parent'} =
$result_trees{'accent_argument'}{'contents'}[0];
+$result_trees{'accent_argument'}{'contents'}[0]{'contents'}[0]{'parent'} =
$result_trees{'accent_argument'}{'contents'}[0];
+$result_trees{'accent_argument'}{'contents'}[0]{'contents'}[1]{'contents'}[0]{'contents'}[0]{'parent'}
=
$result_trees{'accent_argument'}{'contents'}[0]{'contents'}[1]{'contents'}[0];
+$result_trees{'accent_argument'}{'contents'}[0]{'contents'}[1]{'contents'}[0]{'parent'}
= $result_trees{'accent_argument'}{'contents'}[0]{'contents'}[1];
+$result_trees{'accent_argument'}{'contents'}[0]{'contents'}[1]{'parent'} =
$result_trees{'accent_argument'}{'contents'}[0];
+$result_trees{'accent_argument'}{'contents'}[0]{'parent'} =
$result_trees{'accent_argument'};
+$result_trees{'accent_argument'}{'contents'}[1]{'parent'} =
$result_trees{'accent_argument'};
+$result_trees{'accent_argument'}{'contents'}[2]{'args'}[0]{'contents'}[0]{'parent'}
= $result_trees{'accent_argument'}{'contents'}[2]{'args'}[0];
+$result_trees{'accent_argument'}{'contents'}[2]{'args'}[0]{'contents'}[1]{'parent'}
= $result_trees{'accent_argument'}{'contents'}[2]{'args'}[0];
+$result_trees{'accent_argument'}{'contents'}[2]{'args'}[0]{'parent'} =
$result_trees{'accent_argument'}{'contents'}[2];
+$result_trees{'accent_argument'}{'contents'}[2]{'contents'}[0]{'parent'} =
$result_trees{'accent_argument'}{'contents'}[2];
+$result_trees{'accent_argument'}{'contents'}[2]{'contents'}[1]{'contents'}[0]{'contents'}[0]{'parent'}
=
$result_trees{'accent_argument'}{'contents'}[2]{'contents'}[1]{'contents'}[0];
+$result_trees{'accent_argument'}{'contents'}[2]{'contents'}[1]{'contents'}[0]{'parent'}
= $result_trees{'accent_argument'}{'contents'}[2]{'contents'}[1];
+$result_trees{'accent_argument'}{'contents'}[2]{'contents'}[1]{'parent'} =
$result_trees{'accent_argument'}{'contents'}[2];
+$result_trees{'accent_argument'}{'contents'}[2]{'parent'} =
$result_trees{'accent_argument'};
+
+$result_texts{'accent_argument'} = '@itemize @address@hidden
address@hidden item
address@hidden itemize
+
address@hidden @~
address@hidden item
address@hidden itemize
+';
+
+$result_errors{'accent_argument'} = [];
+
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp Texinfo/Parser.pm t/18itemize.t t/re...,
Patrice Dumas <=