[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp texi2any.pl Texinfo/Parser.pm t/60ma...
From: |
Patrice Dumas |
Subject: |
texinfo/tp texi2any.pl Texinfo/Parser.pm t/60ma... |
Date: |
Wed, 23 Feb 2011 22:12:29 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 11/02/23 22:12:29
Modified files:
tp : texi2any.pl
tp/Texinfo : Parser.pm
tp/t : 60macro.t
Added files:
tp/t/results/macro: double_recursive_macro_call.pl
recursive_call_in_argument.pl
recursive_call_in_macro.pl
Log message:
Handle better the texi2any.pl options.
@macro cannot be recursive.
Ignore macros call if nested too deep, customized with
MAX_NESTED_MACROS.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/texi2any.pl?cvsroot=texinfo&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.206&r2=1.207
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/60macro.t?cvsroot=texinfo&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/macro/double_recursive_macro_call.pl?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/macro/recursive_call_in_argument.pl?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/macro/recursive_call_in_macro.pl?cvsroot=texinfo&rev=1.1
Patches:
Index: texi2any.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/texi2any.pl,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- texi2any.pl 20 Feb 2011 12:18:32 -0000 1.17
+++ texi2any.pl 23 Feb 2011 22:12:29 -0000 1.18
@@ -218,7 +218,7 @@
'PROGRAM_NAME_IN_FOOTER', 'NODE_FILENAMES', 'DEFAULT_ENCODING',
'OUT_ENCODING', 'ENCODING_NAME', 'EXTERNAL_CROSSREF_SPLIT', 'BODYTEXT',
'CSS_LINES', 'RENAMED_NODES_REDIRECTIONS', 'RENAMED_NODES_FILE',
- 'TEXI2DVI', 'DUMP_TREE');
+ 'TEXI2DVI', 'DUMP_TREE', 'MAX_NESTED_MACROS');
my %valid_options;
foreach my $var (@document_settable_at_commands, @document_global_at_commands,
@@ -349,7 +349,9 @@
my $converter_default_options = {'ERROR_LIMIT' => 100};
-my $parser_default_options = {'expanded_formats' => [], 'values' => {}};
+#Â options for all the files
+my $parser_default_options = {'expanded_formats' => [], 'values' => {},
+ 'gettext' => \&__};
Texinfo::Config::_load_config($converter_default_options);
@@ -548,6 +550,16 @@
#set_from_cmdline('FRAMES', 0);
}
+foreach my $format (@{$default_expanded_format}) {
+ push @{$parser_default_options->{'expanded_formats'}}, $format
+ unless (grep {$_ eq $format}
@{$parser_default_options->{'expanded_formats'}});
+}
+
+$parser_default_options->{'MAX_NESTED_MACROS'} = get_conf('MAX_NESTED_MACROS')
+ if (defined(get_conf('MAX_NESTED_MACROS')));
+
+
+
# Main processing, process all the files given on the command line
my $failure_text = sprintf(__("Try `%s --help' for more information.\n"),
@@ -591,8 +603,6 @@
@prependended_include_directories;
unshift @{$parser_options->{'include_directories'}}, @prepend_dirs;
- $parser_options->{'gettext'} = \&__;
-
my $parser = Texinfo::Parser::parser($parser_options);
my $tree = $parser->parse_texi_file($input_file_name);
Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.206
retrieving revision 1.207
diff -u -b -r1.206 -r1.207
--- Texinfo/Parser.pm 23 Feb 2011 00:29:12 -0000 1.206
+++ Texinfo/Parser.pm 23 Feb 2011 22:12:29 -0000 1.207
@@ -222,8 +222,8 @@
# this is the initial context. It is put at the bottom of the
# 'context_stack'
'context' => '_root',
- #Â the stack of the macros being expanded
- 'macro_stack' => [''],
+ #Â the stack of the macros being expanded (more recent are first)
+ 'macro_stack' => [],
# these are the user-added indices. May be an array reference on names
# or an hash reference in the same format than %index_names below
'indices' => [],
@@ -246,7 +246,8 @@
'documentlanguage' => undef,
# Current documentlanguage set by
# @documentlanguage
- 'ENABLE_ENCODING' => 1 # corresponds to --enable-encoding.
+ 'ENABLE_ENCODING' => 1, # corresponds to --enable-encoding.
+ 'MAX_NESTED_MACROS' => 100000, # max number of nested macro calls
);
# The commands in initialization_overrides are not set in the document if
@@ -1380,8 +1381,8 @@
my $new_text = shift @{$current->{'pending'}};
if ($new_text->[1] and $new_text->[1]->{'end_macro'}) {
delete $new_text->[1]->{'end_macro'};
- my $top_macro = pop @{$self->{'macro_stack'}};
- print STDERR "POP MACRO_STACK(@{$self->{'macro_stack'}}):
$top_macro->{'args'}->[0]->{'text'}\n"
+ my $top_macro = shift @{$self->{'macro_stack'}};
+ print STDERR "SHIFT MACRO_STACK(@{$self->{'macro_stack'}}):
$top_macro->{'args'}->[0]->{'text'}\n"
if ($self->{'DEBUG'});
}
return ($new_text->[0], $new_text->[1]);
@@ -2827,8 +2828,27 @@
if ($expanded eq '') {
next;
}
- push @{$self->{'macro_stack'}}, $expanded_macro;
- print STDERR "PUSH MACRO_STACK:
$expanded_macro->{'args'}->[0]->{'text'}\n"
+ if ($self->{'MAX_NESTED_MACROS'}
+ and scalar(@{$self->{'macro_stack'}}) >
$self->{'MAX_NESTED_MACROS'}) {
+ $self->line_warn (sprintf($self->
+ __("Too many nested macro call (if correct, set
MAX_NESTED_MACROS, now set to %d)"), $self->{'MAX_NESTED_MACROS'}), $line_nr);
+ next;
+ }
+ if ($expanded_macro->{'cmdname'} eq 'macro') {
+ my $found = 0;
+ foreach my $macro (@{$self->{'macro_stack'}}) {
+ if ($macro->{'args'}->[0]->{'text'} eq $command) {
+ $self->line_error(sprintf($self->
+ __("Recursive call of macro %s is not allowed; use
address@hidden if needed"), $command), $line_nr);
+ $found = 1;
+ last;
+ }
+ }
+ next if ($found);
+ }
+
+ unshift @{$self->{'macro_stack'}}, $expanded_macro;
+ print STDERR "UNSHIFT MACRO_STACK:
$expanded_macro->{'args'}->[0]->{'text'}\n"
if ($self->{'DEBUG'});
my $expanded_lines = _text_to_lines($expanded);
chomp ($expanded_lines->[-1]);
Index: t/60macro.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/60macro.t,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- t/60macro.t 20 Feb 2011 14:47:07 -0000 1.29
+++ t/60macro.t 23 Feb 2011 22:12:29 -0000 1.30
@@ -872,7 +872,35 @@
@end macro
@bye-macro{}
+'],
+#Â this does not lead to a recursive call with the current implementation
+['recursive_call_in_argument',
+'@macro norecurse{arg}
+a
address@hidden macro
+
address@hidden@norecurse{}}
+'],
+['recursive_call_in_macro',
+'@macro norecurse{arg}
address@hidden
address@hidden macro
+
address@hidden
+'],
+['double_recursive_macro_call',
+'
address@hidden mac1 {arg}
address@hidden
address@hidden macro
+
address@hidden mac2{arg}
address@hidden
address@hidden macro
+
address@hidden
']
+
);
my @todo =(
Index: t/results/macro/double_recursive_macro_call.pl
===================================================================
RCS file: t/results/macro/double_recursive_macro_call.pl
diff -N t/results/macro/double_recursive_macro_call.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/results/macro/double_recursive_macro_call.pl 23 Feb 2011 22:12:29
-0000 1.1
@@ -0,0 +1,169 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors
+ %result_indices %result_sectioning %result_nodes %result_menus
+ %result_floats %result_converted %result_converted_errors);
+
+$result_trees{'double_recursive_macro_call'} = {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'args' => [
+ {
+ 'parent' => {},
+ 'text' => 'mac1',
+ 'type' => 'macro_name'
+ },
+ {
+ 'parent' => {},
+ 'text' => 'arg',
+ 'type' => 'macro_arg'
+ }
+ ],
+ 'cmdname' => 'macro',
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => '@mac2{}
+',
+ 'type' => 'raw'
+ }
+ ],
+ 'extra' => {
+ 'arg_line' => ' mac1 {arg}
+',
+ 'args_index' => {
+ 'arg' => 0
+ },
+ 'macrobody' => '@mac2{}
+'
+ },
+ 'line_nr' => {
+ 'file_name' => '',
+ 'line_nr' => 2,
+ 'macro' => ''
+ },
+ 'parent' => {}
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line_after_command'
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'args' => [
+ {
+ 'parent' => {},
+ 'text' => 'mac2',
+ 'type' => 'macro_name'
+ },
+ {
+ 'parent' => {},
+ 'text' => 'arg',
+ 'type' => 'macro_arg'
+ }
+ ],
+ 'cmdname' => 'macro',
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => '@mac1{}
+',
+ 'type' => 'raw'
+ }
+ ],
+ 'extra' => {
+ 'arg_line' => ' mac2{arg}
+',
+ 'args_index' => {
+ 'arg' => 0
+ },
+ 'macrobody' => '@mac1{}
+'
+ },
+ 'line_nr' => {
+ 'file_name' => '',
+ 'line_nr' => 6,
+ 'macro' => ''
+ },
+ 'parent' => {}
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line_after_command'
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ }
+ ],
+ 'type' => 'text_root'
+};
+$result_trees{'double_recursive_macro_call'}{'contents'}[0]{'parent'} =
$result_trees{'double_recursive_macro_call'};
+$result_trees{'double_recursive_macro_call'}{'contents'}[1]{'args'}[0]{'parent'}
= $result_trees{'double_recursive_macro_call'}{'contents'}[1];
+$result_trees{'double_recursive_macro_call'}{'contents'}[1]{'args'}[1]{'parent'}
= $result_trees{'double_recursive_macro_call'}{'contents'}[1];
+$result_trees{'double_recursive_macro_call'}{'contents'}[1]{'contents'}[0]{'parent'}
= $result_trees{'double_recursive_macro_call'}{'contents'}[1];
+$result_trees{'double_recursive_macro_call'}{'contents'}[1]{'parent'} =
$result_trees{'double_recursive_macro_call'};
+$result_trees{'double_recursive_macro_call'}{'contents'}[2]{'parent'} =
$result_trees{'double_recursive_macro_call'};
+$result_trees{'double_recursive_macro_call'}{'contents'}[3]{'parent'} =
$result_trees{'double_recursive_macro_call'};
+$result_trees{'double_recursive_macro_call'}{'contents'}[4]{'args'}[0]{'parent'}
= $result_trees{'double_recursive_macro_call'}{'contents'}[4];
+$result_trees{'double_recursive_macro_call'}{'contents'}[4]{'args'}[1]{'parent'}
= $result_trees{'double_recursive_macro_call'}{'contents'}[4];
+$result_trees{'double_recursive_macro_call'}{'contents'}[4]{'contents'}[0]{'parent'}
= $result_trees{'double_recursive_macro_call'}{'contents'}[4];
+$result_trees{'double_recursive_macro_call'}{'contents'}[4]{'parent'} =
$result_trees{'double_recursive_macro_call'};
+$result_trees{'double_recursive_macro_call'}{'contents'}[5]{'parent'} =
$result_trees{'double_recursive_macro_call'};
+$result_trees{'double_recursive_macro_call'}{'contents'}[6]{'parent'} =
$result_trees{'double_recursive_macro_call'};
+$result_trees{'double_recursive_macro_call'}{'contents'}[7]{'parent'} =
$result_trees{'double_recursive_macro_call'};
+
+$result_texis{'double_recursive_macro_call'} = '
address@hidden mac1 {arg}
address@hidden
address@hidden macro
+
address@hidden mac2{arg}
address@hidden
address@hidden macro
+
+
+';
+
+
+$result_texts{'double_recursive_macro_call'} = '
+
+
+
+';
+
+$result_errors{'double_recursive_macro_call'} = [
+ {
+ 'error_line' => ':10: Recursive call of macro mac2 is not allowed; use
@rmacro if needed (possibly involving @mac1)
+',
+ 'file_name' => '',
+ 'line_nr' => 10,
+ 'macro' => 'mac1',
+ 'text' => 'Recursive call of macro mac2 is not allowed; use @rmacro if
needed',
+ 'type' => 'error'
+ }
+];
+
+
+1;
Index: t/results/macro/recursive_call_in_argument.pl
===================================================================
RCS file: t/results/macro/recursive_call_in_argument.pl
diff -N t/results/macro/recursive_call_in_argument.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/results/macro/recursive_call_in_argument.pl 23 Feb 2011 22:12:29
-0000 1.1
@@ -0,0 +1,95 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors
+ %result_indices %result_sectioning %result_nodes %result_menus
+ %result_floats %result_converted %result_converted_errors);
+
+$result_trees{'recursive_call_in_argument'} = {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'parent' => {},
+ 'text' => 'norecurse',
+ 'type' => 'macro_name'
+ },
+ {
+ 'parent' => {},
+ 'text' => 'arg',
+ 'type' => 'macro_arg'
+ }
+ ],
+ 'cmdname' => 'macro',
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'a
+',
+ 'type' => 'raw'
+ }
+ ],
+ 'extra' => {
+ 'arg_line' => ' norecurse{arg}
+',
+ 'args_index' => {
+ 'arg' => 0
+ },
+ 'macrobody' => 'a
+'
+ },
+ 'line_nr' => {
+ 'file_name' => '',
+ 'line_nr' => 1,
+ 'macro' => ''
+ },
+ 'parent' => {}
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line_after_command'
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'a
+'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ],
+ 'type' => 'text_root'
+};
+$result_trees{'recursive_call_in_argument'}{'contents'}[0]{'args'}[0]{'parent'}
= $result_trees{'recursive_call_in_argument'}{'contents'}[0];
+$result_trees{'recursive_call_in_argument'}{'contents'}[0]{'args'}[1]{'parent'}
= $result_trees{'recursive_call_in_argument'}{'contents'}[0];
+$result_trees{'recursive_call_in_argument'}{'contents'}[0]{'contents'}[0]{'parent'}
= $result_trees{'recursive_call_in_argument'}{'contents'}[0];
+$result_trees{'recursive_call_in_argument'}{'contents'}[0]{'parent'} =
$result_trees{'recursive_call_in_argument'};
+$result_trees{'recursive_call_in_argument'}{'contents'}[1]{'parent'} =
$result_trees{'recursive_call_in_argument'};
+$result_trees{'recursive_call_in_argument'}{'contents'}[2]{'parent'} =
$result_trees{'recursive_call_in_argument'};
+$result_trees{'recursive_call_in_argument'}{'contents'}[3]{'contents'}[0]{'parent'}
= $result_trees{'recursive_call_in_argument'}{'contents'}[3];
+$result_trees{'recursive_call_in_argument'}{'contents'}[3]{'parent'} =
$result_trees{'recursive_call_in_argument'};
+
+$result_texis{'recursive_call_in_argument'} = '@macro norecurse{arg}
+a
address@hidden macro
+
+a
+';
+
+
+$result_texts{'recursive_call_in_argument'} = '
+a
+';
+
+$result_errors{'recursive_call_in_argument'} = [];
+
+
+1;
Index: t/results/macro/recursive_call_in_macro.pl
===================================================================
RCS file: t/results/macro/recursive_call_in_macro.pl
diff -N t/results/macro/recursive_call_in_macro.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/results/macro/recursive_call_in_macro.pl 23 Feb 2011 22:12:29 -0000
1.1
@@ -0,0 +1,99 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors
+ %result_indices %result_sectioning %result_nodes %result_menus
+ %result_floats %result_converted %result_converted_errors);
+
+$result_trees{'recursive_call_in_macro'} = {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'parent' => {},
+ 'text' => 'norecurse',
+ 'type' => 'macro_name'
+ },
+ {
+ 'parent' => {},
+ 'text' => 'arg',
+ 'type' => 'macro_arg'
+ }
+ ],
+ 'cmdname' => 'macro',
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => '@norecurse{arg}
+',
+ 'type' => 'raw'
+ }
+ ],
+ 'extra' => {
+ 'arg_line' => ' norecurse{arg}
+',
+ 'args_index' => {
+ 'arg' => 0
+ },
+ 'macrobody' => '@norecurse{arg}
+'
+ },
+ 'line_nr' => {
+ 'file_name' => '',
+ 'line_nr' => 1,
+ 'macro' => ''
+ },
+ 'parent' => {}
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line_after_command'
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'parent' => {},
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ }
+ ],
+ 'type' => 'text_root'
+};
+$result_trees{'recursive_call_in_macro'}{'contents'}[0]{'args'}[0]{'parent'} =
$result_trees{'recursive_call_in_macro'}{'contents'}[0];
+$result_trees{'recursive_call_in_macro'}{'contents'}[0]{'args'}[1]{'parent'} =
$result_trees{'recursive_call_in_macro'}{'contents'}[0];
+$result_trees{'recursive_call_in_macro'}{'contents'}[0]{'contents'}[0]{'parent'}
= $result_trees{'recursive_call_in_macro'}{'contents'}[0];
+$result_trees{'recursive_call_in_macro'}{'contents'}[0]{'parent'} =
$result_trees{'recursive_call_in_macro'};
+$result_trees{'recursive_call_in_macro'}{'contents'}[1]{'parent'} =
$result_trees{'recursive_call_in_macro'};
+$result_trees{'recursive_call_in_macro'}{'contents'}[2]{'parent'} =
$result_trees{'recursive_call_in_macro'};
+$result_trees{'recursive_call_in_macro'}{'contents'}[3]{'parent'} =
$result_trees{'recursive_call_in_macro'};
+
+$result_texis{'recursive_call_in_macro'} = '@macro norecurse{arg}
address@hidden
address@hidden macro
+
+
+';
+
+
+$result_texts{'recursive_call_in_macro'} = '
+
+';
+
+$result_errors{'recursive_call_in_macro'} = [
+ {
+ 'error_line' => ':5: Recursive call of macro norecurse is not allowed; use
@rmacro if needed (possibly involving @norecurse)
+',
+ 'file_name' => '',
+ 'line_nr' => 5,
+ 'macro' => 'norecurse',
+ 'text' => 'Recursive call of macro norecurse is not allowed; use @rmacro
if needed',
+ 'type' => 'error'
+ }
+];
+
+
+1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp texi2any.pl Texinfo/Parser.pm t/60ma...,
Patrice Dumas <=