[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/ParserNonXS.pm (_end_line_starting_b
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/ParserNonXS.pm (_end_line_starting_block): check that the command_as_argument on @itemize line is alone without modifying an array, by looping over the contents as in C. |
Date: |
Sun, 29 Sep 2024 02:41:49 -0400 |
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 621b6c5bba * tp/Texinfo/ParserNonXS.pm (_end_line_starting_block):
check that the command_as_argument on @itemize line is alone without modifying
an array, by looping over the contents as in C.
621b6c5bba is described below
commit 621b6c5bba522c9d46e1ca832aeccb40b31d1173
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Jun 4 23:04:50 2024 +0200
* tp/Texinfo/ParserNonXS.pm (_end_line_starting_block): check
that the command_as_argument on @itemize line is alone without
modifying an array, by looping over the contents as in C.
* tp/Texinfo/ParserNonXS.pm (_end_line_starting_block),
tp/Texinfo/XS/parsetexi/end_line.c (end_line_starting_block): simplify
the code checking that the command as arg is brace noarg or has
braces.
* tp/Texinfo/ParserNonXS.pm (_handle_close_brace): simplify condition
on args and contents.
---
ChangeLog | 14 +++++++++++++
tp/Texinfo/ParserNonXS.pm | 43 ++++++++++++++++----------------------
tp/Texinfo/XS/parsetexi/end_line.c | 30 +++++++++++---------------
3 files changed, 44 insertions(+), 43 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7323560d87..e5551f104e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-06-04 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/ParserNonXS.pm (_end_line_starting_block): check
+ that the command_as_argument on @itemize line is alone without
+ modifying an array, by looping over the contents as in C.
+
+ * tp/Texinfo/ParserNonXS.pm (_end_line_starting_block),
+ tp/Texinfo/XS/parsetexi/end_line.c (end_line_starting_block): simplify
+ the code checking that the command as arg is brace noarg or has
+ braces.
+
+ * tp/Texinfo/ParserNonXS.pm (_handle_close_brace): simplify condition
+ on args and contents.
+
2024-06-04 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Convert/Converter.pm (table_item_content_tree): determine
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index dd9550215d..59915dff53 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -4242,14 +4242,17 @@ sub _end_line_starting_block($$$)
my $command_as_argument = $current->{'extra'}->{'command_as_argument'};
# This code checks that the command_as_argument of the @itemize
# is alone on the line, otherwise it is not a command_as_argument.
- # TODO rewrite without shifting
- my @args = @{$current->{'args'}->[0]->{'contents'}};
- while (@args) {
- my $arg = shift @args;
- last if ($arg eq $current->{'extra'}->{'command_as_argument'});
- }
- while (@args) {
- my $arg = shift @args;
+ my $i;
+ my $line_arg = $current->{'args'}->[0];
+ my $contents_nr = scalar(@{$line_arg->{'contents'}});
+ for ($i = 0; $i < $contents_nr; $i++) {
+ if ($line_arg->{'contents'}->[$i] eq $command_as_argument) {
+ $i++;
+ last;
+ }
+ }
+ for (; $i < $contents_nr; $i++) {
+ my $arg = $line_arg->{'contents'}->[$i];
if (!(($arg->{'cmdname'}
and ($arg->{'cmdname'} eq 'c'
or $arg->{'cmdname'} eq 'comment'))
@@ -4263,21 +4266,13 @@ sub _end_line_starting_block($$$)
}
}
# if the command as argument does not have braces but it is
- # a brace command and not a mark (noarg) command, warn
+ # not a mark (noarg) command, warn
if (defined($command_as_argument)
- and (!$command_as_argument->{'args'}
- or !scalar(@{$command_as_argument->{'args'}})
- or !$command_as_argument->{'args'}->[0]->{'type'}
- or ($command_as_argument->{'args'}->[0]->{'type'}
- ne 'brace_container'
- and $command_as_argument->{'args'}->[0]->{'type'}
- ne 'brace_arg'))) {
+ and !$command_as_argument->{'args'}
+ and $brace_commands{$command_as_argument->{'cmdname'}} ne 'noarg') {
my $cmdname = $command_as_argument->{'cmdname'};
- if (defined($brace_commands{$cmdname})
- and $brace_commands{$cmdname} ne 'noarg') {
- $self->_command_warn($current, __("\@%s expected braces"),
- $cmdname);
- }
+ $self->_command_warn($current, __("\@%s expected braces"),
+ $cmdname);
}
}
# Check if command_as_argument isn't an accent command
@@ -6464,10 +6459,8 @@ sub _handle_close_brace($$$)
' inlineraw');
}
}
- if (!@{$current_command->{'args'}}
- or !defined($current_command->{'args'}->[0])
- or !$current_command->{'args'}->[0]->{'contents'}
- or scalar(@{$current_command->{'args'}->[0]->{'contents'}}) == 0) {
+ if (!$current_command->{'args'}
+ or !$current_command->{'args'}->[0]->{'contents'}) {
$self->_line_warn(
sprintf(__("\@%s missing first argument"),
$current_command->{'cmdname'}), $source_info);
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c
b/tp/Texinfo/XS/parsetexi/end_line.c
index e105eddc84..f6f9bd726a 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -975,11 +975,11 @@ end_line_starting_block (ELEMENT *current)
{
int i;
ELEMENT *e = args_child_by_index (current, 0);
+ ELEMENT *command_as_arg_e = k_command_as_arg->k.element;
for (i = 0; i < e->c->contents.number; i++)
{
- if (contents_child_by_index (e, i)
- == k_command_as_arg->k.element)
+ if (contents_child_by_index (e, i) == command_as_arg_e)
{
i++;
break;
@@ -1001,25 +1001,19 @@ end_line_starting_block (ELEMENT *current)
break;
}
}
- }
/* if the command as argument does not have braces but it is
- a brace command and not a mark (noarg) command, warn */
- if (k_command_as_arg
- && (k_command_as_arg->k.element->c->args.number <= 0
- /* FIXME this condition looks strange, verify what could
be
- there if not brace_container/brace_arg */
- || (k_command_as_arg->k.element->c->args.list[0]->type
- != ET_brace_container)
- && k_command_as_arg->k.element->c->args.list[0]->type
- != ET_brace_arg))
- {
- enum command_id as_argument_cmd =
k_command_as_arg->k.element->cmd;
- if ((command_data(as_argument_cmd).flags & CF_brace)
- && command_data(as_argument_cmd).data != BRACE_noarg)
+ not a mark (noarg) command, warn */
+ if (k_command_as_arg
+ && command_as_arg_e->c->args.number <= 0
+ /* only brace commands are registered as command_as_argument
+ so we can assume that the following is true:
+ && command_data(command_as_arg_e->cmd).flags & CF_brace
+ */
+ && command_data(command_as_arg_e->cmd).data != BRACE_noarg)
{
- command_warn (current, "@%s expected braces",
- command_name(as_argument_cmd));
+ command_warn (current, "@%s expected braces",
+ command_name(command_as_arg_e->cmd));
}
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/ParserNonXS.pm (_end_line_starting_block): check that the command_as_argument on @itemize line is alone without modifying an array, by looping over the contents as in C.,
Patrice Dumas <=