[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/ParserNonXS.pm (_parse_macro_command
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/ParserNonXS.pm (_parse_macro_command_line) (_lookup_macro_parameter, _expand_macro_body, _parse_texi): Add _lookup_macro_parameter() to find the formal argument index by going through macro element args instead of adding 'args_index' in _parse_macro_command_line() and removing it later from the tree. Based on the C parser code. |
Date: |
Sun, 19 Dec 2021 08:54:35 -0500 |
This is an automated email from the git hooks/post-receive script.
pertusus pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new ade16e7 * tp/Texinfo/ParserNonXS.pm (_parse_macro_command_line)
(_lookup_macro_parameter, _expand_macro_body, _parse_texi): Add
_lookup_macro_parameter() to find the formal argument index by going through
macro element args instead of adding 'args_index' in
_parse_macro_command_line() and removing it later from the tree. Based on the C
parser code.
ade16e7 is described below
commit ade16e701e290fd4f08f64e22bc55c4148e5a4bd
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Dec 19 14:54:25 2021 +0100
* tp/Texinfo/ParserNonXS.pm (_parse_macro_command_line)
(_lookup_macro_parameter, _expand_macro_body, _parse_texi):
Add _lookup_macro_parameter() to find the formal argument index
by going through macro element args instead of adding 'args_index'
in _parse_macro_command_line() and removing it later from the tree.
Based on the C parser code.
---
ChangeLog | 10 +++++++++-
tp/Texinfo/ParserNonXS.pm | 41 +++++++++++++++++++++--------------------
2 files changed, 30 insertions(+), 21 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index be17528..0e4d385 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-12-19 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/ParserNonXS.pm (_parse_macro_command_line)
+ (_lookup_macro_parameter, _expand_macro_body, _parse_texi):
+ Add _lookup_macro_parameter() to find the formal argument index
+ by going through macro element args instead of adding 'args_index'
+ in _parse_macro_command_line() and removing it later from the tree.
+ Based on the C parser code.
+
2021-12-19 Gavin Smith <gavinsmith0123@gmail.com>
Parsetexi.pm clear list of include directories
@@ -6,7 +15,6 @@
New function to clear the path for finding @include files
* tp/Texinfo/XS/parsetexi/api.c (reset_parser): Call it.
-
2021-12-19 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Common.pm (@variable_string_settables),
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index d18bff1..9d1aab9 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -1158,7 +1158,6 @@ sub _parse_macro_command_line($$$$$;$)
$macro->{'args'} = [
{ 'type' => 'macro_name', 'text' => $macro_name,
'parent' => $macro } ];
- my $index = 0;
foreach my $formal_arg (@args) {
push @{$macro->{'args'}},
{ 'type' => 'macro_arg', 'text' => $formal_arg,
@@ -1168,8 +1167,6 @@ sub _parse_macro_command_line($$$$$;$)
$command, $formal_arg), $line_nr);
$macro->{'extra'}->{'invalid_syntax'} = 1;
}
- $macro->{'extra'}->{'args_index'}->{$formal_arg} = $index;
- $index++;
}
# accept an @-command after the arguments in case there is a @c or
# @comment
@@ -2070,18 +2067,29 @@ sub _expand_macro_arguments($$$$)
return ($arguments, $line, $line_nr);
}
+sub _lookup_macro_parameter($$) {
+ my $macro = shift;
+ my $name = shift;
+
+ my $args_total = scalar(@{$macro->{'element'}->{'args'}}) -1;
+ if ($args_total > 0) {
+ my $arg_index;
+ # the first argument is the macro name
+ for ($arg_index=1; $arg_index<=$args_total; $arg_index++) {
+ if (defined($macro->{'element'}->{'args'}->[$arg_index])
+ and $macro->{'element'}->{'args'}->[$arg_index]->{'text'} eq $name) {
+ return $arg_index - 1;
+ }
+ }
+ }
+ return undef
+}
+
# $MACRO is a member of $self->{'macros'}.
sub _expand_macro_body($$$$) {
my ($self, $macro, $args, $line_nr) = @_;
my $macrobody = $macro->{'macrobody'};
- my $args_total = scalar(@{$macro->{'element'}->{'args'}}) -1;
- my $args_index = $macro->{'args_index'};
-
- my $i;
- for ($i=0; $i<=$args_total; $i++) {
- $args->[$i] = "" unless (defined($args->[$i]));
- }
my $result = '';
while ($macrobody ne '') {
@@ -2091,8 +2099,9 @@ sub _expand_macro_body($$$$) {
$result .= '\\';
} elsif ($macrobody =~ s/^([^\\]*)\\//) {
my $arg = $1;
- if (defined($args_index->{$arg})) {
- $result .= $args->[$args_index->{$arg}];
+ my $formal_arg_index = _lookup_macro_parameter($macro, $arg);
+ if (defined($formal_arg_index)) {
+ $result .= $args->[$formal_arg_index];
} else {
$self->_line_error(sprintf(__(
"\\ in \@%s expansion followed `%s' instead of parameter name or
\\"),
@@ -3753,14 +3762,6 @@ sub _parse_texi($;$)
'element' => $current,
'macrobody' => $macrobody
};
- # Don't need 'args_index' in final tree.
- if (defined $current->{'extra'}->{'args_index'}) {
- $self->{'macros'}->{$name}->{'args_index'}
- = $current->{'extra'}->{'args_index'};
- delete $current->{'extra'}->{'args_index'};
- }
- } elsif (defined $current->{'extra'}->{'args_index'}) {
- delete $current->{'extra'}->{'args_index'};
}
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/ParserNonXS.pm (_parse_macro_command_line) (_lookup_macro_parameter, _expand_macro_body, _parse_texi): Add _lookup_macro_parameter() to find the formal argument index by going through macro element args instead of adding 'args_index' in _parse_macro_command_line() and removing it later from the tree. Based on the C parser code.,
Patrice Dumas <=