[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/ParserNonXS.pm (_handle_menu_entry_s
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/ParserNonXS.pm (_handle_menu_entry_separators), tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators): reuse the empty_line as the internal_menu_star element. Setup last_element at the beginning of the function. |
Date: |
Sun, 29 Sep 2024 06:27:45 -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 2efe336b54 * tp/Texinfo/ParserNonXS.pm
(_handle_menu_entry_separators), tp/Texinfo/XS/parsetexi/menus.c
(handle_menu_entry_separators): reuse the empty_line as the internal_menu_star
element. Setup last_element at the beginning of the function.
2efe336b54 is described below
commit 2efe336b54158d8a4573c3dd62e699531dbe59a2
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Jun 19 00:54:07 2024 +0200
* tp/Texinfo/ParserNonXS.pm (_handle_menu_entry_separators),
tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators): reuse
the empty_line as the internal_menu_star element. Setup last_element
at the beginning of the function.
---
ChangeLog | 7 ++
tp/Texinfo/ParserNonXS.pm | 39 ++++----
tp/Texinfo/XS/parsetexi/menus.c | 42 ++++----
tp/t/results/macro/macro_in_empty_menu_comment.pl | 51 +++++-----
tp/t/results/macro/macro_in_menu.pl | 115 ++++++++++------------
5 files changed, 124 insertions(+), 130 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 74e4add3e8..e99ad1a619 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-06-19 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/ParserNonXS.pm (_handle_menu_entry_separators),
+ tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators): reuse
+ the empty_line as the internal_menu_star element. Setup last_element
+ at the beginning of the function.
+
2024-06-19 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/ParserNonXS.pm (%parsing_state_initialization): call
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index fdee70894a..e0bec944f6 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -5256,6 +5256,11 @@ sub _handle_menu_entry_separators($$$$$$)
my $retval = 1;
+ my $last_element;
+ if ($current->{'contents'}) {
+ $last_element = $current->{'contents'}->[-1];
+ }
+
# maybe a menu entry beginning: a * at the beginning of a menu line
if ($current->{'type'}
and $current->{'type'} eq 'preformatted'
@@ -5263,24 +5268,22 @@ sub _handle_menu_entry_separators($$$$$$)
and ($current->{'parent'}->{'type'} eq 'menu_comment'
or $current->{'parent'}->{'type'} eq 'menu_entry_description')
and $asterisk
- and $current->{'contents'}
- and $current->{'contents'}->[-1]->{'type'}
- and $current->{'contents'}->[-1]->{'type'} eq 'empty_line'
- and $current->{'contents'}->[-1]->{'text'} eq '') {
+ and $last_element
+ and $last_element->{'type'}
+ and $last_element->{'type'} eq 'empty_line'
+ and $last_element->{'text'} eq '') {
print STDERR "MENU STAR\n" if ($self->{'conf'}->{'DEBUG'});
- _abort_empty_line($self, $current);
$$line_ref =~ s/^\*//;
- push @{$current->{'contents'}}, { 'parent' => $current,
- 'type' => 'internal_menu_star',
- 'text' => '*' };
+ $last_element->{'type'} = 'internal_menu_star';
+ $last_element->{'text'} = '*';
# a space after a * at the beginning of a menu line
- } elsif ($current->{'contents'} and @{$current->{'contents'}}
- and $current->{'contents'}->[-1]->{'type'}
- and $current->{'contents'}->[-1]->{'type'} eq 'internal_menu_star')
{
+ } elsif ($last_element
+ and $last_element->{'type'}
+ and $last_element->{'type'} eq 'internal_menu_star') {
if ($$line_ref !~ /^\s+/) {
print STDERR "ABORT MENU STAR before: "
._debug_protect_eol($$line_ref)."\n" if ($self->{'conf'}->{'DEBUG'});
- delete $current->{'contents'}->[-1]->{'type'};
+ delete $last_element->{'type'};
} else {
print STDERR "MENU ENTRY (certainly)\n" if ($self->{'conf'}->{'DEBUG'});
# this is the menu star collected previously
@@ -5343,15 +5346,15 @@ sub _handle_menu_entry_separators($$$$$$)
'text' => $menu_separator,
'parent' => $current };
# after a separator in menu
- } elsif ($current->{'contents'} and @{$current->{'contents'}}
- and $current->{'contents'}->[-1]->{'type'}
- and $current->{'contents'}->[-1]->{'type'} eq
'menu_entry_separator') {
- my $separator = $current->{'contents'}->[-1]->{'text'};
+ } elsif ($last_element
+ and $last_element->{'type'}
+ and $last_element->{'type'} eq 'menu_entry_separator') {
+ my $separator = $last_element->{'text'};
print STDERR "AFTER menu_entry_separator $separator\n"
if ($self->{'conf'}->{'DEBUG'});
# Separator is ::.
if ($separator eq ':' and $$line_ref =~ s/^(:)//) {
- $current->{'contents'}->[-1]->{'text'} .= $1;
+ $last_element->{'text'} .= $1;
# Whitespace following the :: is subsequently appended to
# the separator.
# a . not followed by a space. Not a separator.
@@ -5365,7 +5368,7 @@ sub _handle_menu_entry_separators($$$$$$)
# NOTE a trailing end of line could be considered to be part
# of the separator. Right now it is part of the description,
# since it is catched (in the next while) as one of the case below
- $current->{'contents'}->[-1]->{'text'} .= $1;
+ $last_element->{'text'} .= $1;
# :: after a menu entry name => change to a menu entry node
} elsif ($separator =~ /^::/) {
print STDERR "MENU NODE done (change from menu entry name) $separator\n"
diff --git a/tp/Texinfo/XS/parsetexi/menus.c b/tp/Texinfo/XS/parsetexi/menus.c
index 2d97542a61..8fc271fb7f 100644
--- a/tp/Texinfo/XS/parsetexi/menus.c
+++ b/tp/Texinfo/XS/parsetexi/menus.c
@@ -118,6 +118,7 @@ handle_menu_entry_separators (ELEMENT **current_inout,
const char **line_inout)
ELEMENT *current = *current_inout;
const char *line = *line_inout;
int retval = 1;
+ ELEMENT *last_element = last_contents_child (current);
/* A "*" at the start of a line beginning a menu entry. */
if (*line == '*'
@@ -125,25 +126,22 @@ handle_menu_entry_separators (ELEMENT **current_inout,
const char **line_inout)
&& (current->parent->type == ET_menu_comment
|| current->parent->type == ET_menu_entry_description)
&& current->e.c->contents.number > 0
- && last_contents_child (current)->type == ET_empty_line
- && last_contents_child (current)->e.text->end == 0)
+ && last_element->type == ET_empty_line
+ && last_element->e.text->end == 0)
{
- ELEMENT *star;
-
debug ("MENU STAR");
- abort_empty_line (current);
+
line++; /* Past the '*'. */
- star = new_text_element (ET_internal_menu_star);
- text_append (star->e.text, "*");
- add_to_element_contents (current, star);
+ last_element->type = ET_internal_menu_star;
+ text_append (last_element->e.text, "*");
/* The ET_internal_menu_star element won't appear in the final tree. */
}
/* A space after a "*" at the beginning of a line. */
else if (strchr (whitespace_chars, *line)
- && current->e.c->contents.number > 0
- && last_contents_child (current)->type == ET_internal_menu_star)
+ && last_element
+ && last_element->type == ET_internal_menu_star)
{
ELEMENT *menu_entry, *leading_text, *entry_name;
ELEMENT *menu_star_element;
@@ -191,13 +189,13 @@ handle_menu_entry_separators (ELEMENT **current_inout,
const char **line_inout)
line += leading_spaces;
}
/* A "*" followed by anything other than a space. */
- else if (current->e.c->contents.number > 0
- && last_contents_child (current)->type == ET_internal_menu_star)
+ else if (last_element
+ && last_element->type == ET_internal_menu_star)
{
debug_nonl ("ABORT MENU STAR before: ");
debug_print_protected_string (line); debug ("");
- last_contents_child (current)->type = ET_normal_text;
+ last_element->type = ET_normal_text;
}
/* After a separator in a menu, end of menu entry node or menu entry name
(. must be followed by a space to stop the node). */
@@ -219,21 +217,19 @@ handle_menu_entry_separators (ELEMENT **current_inout,
const char **line_inout)
done here below. */
}
/* After a separator in a menu */
- else if (current->e.c->contents.number > 0
- && last_contents_child (current)->type == ET_menu_entry_separator)
+ else if (last_element
+ && last_element->type == ET_menu_entry_separator)
{
- ELEMENT *last_child;
char *separator;
- last_child = last_contents_child (current);
- separator = last_child->e.text->text;
+ separator = last_element->e.text->text;
debug ("AFTER menu_entry_separator %s", separator);
/* Separator is "::". */
if (!strcmp (separator, ":") && *line == ':')
{
- text_append (last_child->e.text, ":");
+ text_append (last_element->e.text, ":");
line++;
/* Whitespace following the "::" is subsequently appended to
the separator element. */
@@ -243,9 +239,9 @@ handle_menu_entry_separators (ELEMENT **current_inout,
const char **line_inout)
{
pop_element_from_contents (current);
current = last_contents_child (current);
- merge_text (current, last_child->e.text->text,
- last_child->e.text->end, last_child);
- destroy_element (last_child);
+ merge_text (current, last_element->e.text->text,
+ last_element->e.text->end, last_element);
+ destroy_element (last_element);
}
/* here we collect spaces following separators. */
else if (strchr (whitespace_chars_except_newline, *line))
@@ -253,7 +249,7 @@ handle_menu_entry_separators (ELEMENT **current_inout,
const char **line_inout)
int n;
n = strspn (line, whitespace_chars_except_newline);
- text_append_n (last_child->e.text, line, n);
+ text_append_n (last_element->e.text, line, n);
line += n;
}
/* :: after a menu entry name => change to a menu entry node */
diff --git a/tp/t/results/macro/macro_in_empty_menu_comment.pl
b/tp/t/results/macro/macro_in_empty_menu_comment.pl
index 38c82e713c..3789982ffa 100644
--- a/tp/t/results/macro/macro_in_empty_menu_comment.pl
+++ b/tp/t/results/macro/macro_in_empty_menu_comment.pl
@@ -81,35 +81,32 @@ $result_trees{'macro_in_empty_menu_comment'} = {
],
'cmdname' => 'menu',
'contents' => [
- {
- 'source_marks' => [
- {
- 'counter' => 1,
- 'element' => {
- 'args' => [
- {
- 'type' => 'brace_arg'
- }
- ],
- 'info' => {
- 'command_name' => 'emptystring'
- },
- 'type' => 'macro_call'
- },
- 'sourcemark_type' => 'macro_expansion',
- 'status' => 'start'
- },
- {
- 'counter' => 1,
- 'sourcemark_type' => 'macro_expansion',
- 'status' => 'end'
- }
- ],
- 'type' => 'menu_comment'
- },
{
'contents' => [
{
+ 'source_marks' => [
+ {
+ 'counter' => 1,
+ 'element' => {
+ 'args' => [
+ {
+ 'type' => 'brace_arg'
+ }
+ ],
+ 'info' => {
+ 'command_name' => 'emptystring'
+ },
+ 'type' => 'macro_call'
+ },
+ 'sourcemark_type' => 'macro_expansion',
+ 'status' => 'start'
+ },
+ {
+ 'counter' => 1,
+ 'sourcemark_type' => 'macro_expansion',
+ 'status' => 'end'
+ }
+ ],
'text' => '* ',
'type' => 'menu_entry_leading_text'
},
@@ -194,7 +191,7 @@ $result_trees{'macro_in_empty_menu_comment'} = {
],
'type' => 'document_root'
};
-$result_trees{'macro_in_empty_menu_comment'}{'contents'}[0]{'contents'}[2]{'contents'}[1]{'contents'}[1]{'extra'}{'node_content'}{'contents'}[0]
=
$result_trees{'macro_in_empty_menu_comment'}{'contents'}[0]{'contents'}[2]{'contents'}[1]{'contents'}[1]{'contents'}[0];
+$result_trees{'macro_in_empty_menu_comment'}{'contents'}[0]{'contents'}[2]{'contents'}[0]{'contents'}[1]{'extra'}{'node_content'}{'contents'}[0]
=
$result_trees{'macro_in_empty_menu_comment'}{'contents'}[0]{'contents'}[2]{'contents'}[0]{'contents'}[1]{'contents'}[0];
$result_texis{'macro_in_empty_menu_comment'} = '@macro emptystring
diff --git a/tp/t/results/macro/macro_in_menu.pl
b/tp/t/results/macro/macro_in_menu.pl
index a0913cdd18..c20c970af9 100644
--- a/tp/t/results/macro/macro_in_menu.pl
+++ b/tp/t/results/macro/macro_in_menu.pl
@@ -376,30 +376,27 @@ $result_trees{'macro_in_menu'} = {
],
'cmdname' => 'menu',
'contents' => [
- {
- 'source_marks' => [
- {
- 'counter' => 1,
- 'element' => {
- 'args' => [
- {
- 'type' => 'brace_arg'
- }
- ],
- 'info' => {
- 'command_name' => 'starspaces'
- },
- 'type' => 'macro_call'
- },
- 'sourcemark_type' => 'macro_expansion',
- 'status' => 'start'
- }
- ],
- 'type' => 'menu_comment'
- },
{
'contents' => [
{
+ 'source_marks' => [
+ {
+ 'counter' => 1,
+ 'element' => {
+ 'args' => [
+ {
+ 'type' => 'brace_arg'
+ }
+ ],
+ 'info' => {
+ 'command_name' => 'starspaces'
+ },
+ 'type' => 'macro_call'
+ },
+ 'sourcemark_type' => 'macro_expansion',
+ 'status' => 'start'
+ }
+ ],
'text' => '* ',
'type' => 'menu_entry_leading_text'
},
@@ -509,25 +506,6 @@ $result_trees{'macro_in_menu'} = {
'type' => 'after_menu_description_line'
},
{
- 'source_marks' => [
- {
- 'counter' => 4,
- 'element' => {
- 'args' => [
- {
- 'type' => 'brace_arg'
- }
- ],
- 'info' => {
- 'command_name' => 'astar'
- },
- 'type' => 'macro_call'
- },
- 'position' => 13,
- 'sourcemark_type' => 'macro_expansion',
- 'status' => 'start'
- }
- ],
'text' => 'menu comment
'
}
@@ -541,6 +519,22 @@ $result_trees{'macro_in_menu'} = {
'contents' => [
{
'source_marks' => [
+ {
+ 'counter' => 4,
+ 'element' => {
+ 'args' => [
+ {
+ 'type' => 'brace_arg'
+ }
+ ],
+ 'info' => {
+ 'command_name' => 'astar'
+ },
+ 'type' => 'macro_call'
+ },
+ 'sourcemark_type' => 'macro_expansion',
+ 'status' => 'start'
+ },
{
'counter' => 4,
'position' => 1,
@@ -576,25 +570,6 @@ $result_trees{'macro_in_menu'} = {
{
'contents' => [
{
- 'source_marks' => [
- {
- 'counter' => 5,
- 'element' => {
- 'args' => [
- {
- 'type' => 'brace_arg'
- }
- ],
- 'info' => {
- 'command_name' => 'astar'
- },
- 'type' => 'macro_call'
- },
- 'position' => 1,
- 'sourcemark_type' => 'macro_expansion',
- 'status' => 'start'
- }
- ],
'text' => '
'
}
@@ -614,6 +589,22 @@ $result_trees{'macro_in_menu'} = {
'contents' => [
{
'source_marks' => [
+ {
+ 'counter' => 5,
+ 'element' => {
+ 'args' => [
+ {
+ 'type' => 'brace_arg'
+ }
+ ],
+ 'info' => {
+ 'command_name' => 'astar'
+ },
+ 'type' => 'macro_call'
+ },
+ 'sourcemark_type' => 'macro_expansion',
+ 'status' => 'start'
+ },
{
'counter' => 5,
'position' => 1,
@@ -931,11 +922,11 @@ $result_trees{'macro_in_menu'} = {
],
'type' => 'document_root'
};
-$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[1]{'contents'}[1]{'extra'}{'node_content'}{'contents'}[0]
=
$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[1]{'contents'}[1]{'contents'}[0];
+$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[0]{'contents'}[1]{'extra'}{'node_content'}{'contents'}[0]
=
$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[0]{'contents'}[1]{'contents'}[0];
+$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[2]{'contents'}[1]{'extra'}{'node_content'}{'contents'}[0]
=
$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[2]{'contents'}[1]{'contents'}[0];
$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[3]{'contents'}[1]{'extra'}{'node_content'}{'contents'}[0]
=
$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[3]{'contents'}[1]{'contents'}[0];
$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[4]{'contents'}[1]{'extra'}{'node_content'}{'contents'}[0]
=
$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[4]{'contents'}[1]{'contents'}[0];
-$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[5]{'contents'}[1]{'extra'}{'node_content'}{'contents'}[0]
=
$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[5]{'contents'}[1]{'contents'}[0];
-$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[6]{'contents'}[3]{'extra'}{'node_content'}{'contents'}[0]
=
$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[6]{'contents'}[3]{'contents'}[0];
+$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[5]{'contents'}[3]{'extra'}{'node_content'}{'contents'}[0]
=
$result_trees{'macro_in_menu'}{'contents'}[0]{'contents'}[13]{'contents'}[5]{'contents'}[3]{'contents'}[0];
$result_texis{'macro_in_menu'} = '
@macro astar
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/ParserNonXS.pm (_handle_menu_entry_separators), tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators): reuse the empty_line as the internal_menu_star element. Setup last_element at the beginning of the function.,
Patrice Dumas <=