[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sun, 29 Sep 2024 09:18:42 -0400 (EDT) |
branch: master
commit c7450d5f403b2e63e7a8fc43c22f9fee2020ccb1
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jun 30 11:06:44 2024 +0200
* tp/Texinfo/ParserNonXS.pm (_handle_block_command),
tp/Texinfo/XS/parsetexi/handle_commands.c (handle_block_command):
reorganize code, change variable names for clearer code, better
separation of def* and other block commands, and try to finish
modifying an element before registering it as an arg or content.
---
ChangeLog | 8 ++
tp/Texinfo/ParserNonXS.pm | 156 +++++++++++++--------------
tp/Texinfo/XS/parsetexi/handle_commands.c | 171 +++++++++++++++---------------
3 files changed, 173 insertions(+), 162 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index def11539ed..16acc20111 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-06-30 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/ParserNonXS.pm (_handle_block_command),
+ tp/Texinfo/XS/parsetexi/handle_commands.c (handle_block_command):
+ reorganize code, change variable names for clearer code, better
+ separation of def* and other block commands, and try to finish
+ modifying an element before registering it as an arg or content.
+
2024-06-29 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/main/build_perl_info.c (build_additional_info),
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index cdb42cbc85..2a077eed9c 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -6032,16 +6032,15 @@ sub _handle_block_command($$$$$)
}
my $block;
+ my $block_line_e;
# the def command holds a line_def* which corresponds with the
# definition line. This allows to have a treatement similar
# with def*x.
if ($def_commands{$command}) {
- $self->_push_context('ct_def', $command);
$block = { 'parent' => $current,
'cmdname' => $command,
'contents' => [] };
- push @{$current->{'contents'}}, $block;
my $def_line = {
'type' => 'def_line',
'parent' => $block,
@@ -6051,107 +6050,110 @@ sub _handle_block_command($$$$$)
'original_def_cmdname' => $command,
},
};
- push @{$block->{'contents'}}, $def_line;
if (defined($self->{'values'}->{'txidefnamenospace'})) {
$def_line->{'extra'}->{'omit_def_name_space'} = 1;
}
- $current = $def_line;
+ push @{$block->{'contents'}}, $def_line;
+ $block_line_e = $def_line;
+ $self->_push_context('ct_def', $command);
} else {
$block = { 'cmdname' => $command,
'parent' => $current,
};
- push @{$current->{'contents'}}, $block;
- $current = $block;
- }
-
- if ($preformatted_commands{$command}) {
- $self->_push_context('ct_preformatted', $command);
- } elsif ($math_commands{$command}) {
- $self->_push_context('ct_math', $command);
- } elsif ($block_commands{$command} eq 'format_raw') {
- $self->_push_context('ct_rawpreformatted', $command);
- } elsif ($block_commands{$command} eq 'region') {
- push @{$self->{'nesting_context'}->{'regions_stack'}}, $command;
- }
- if ($block_commands{$command} eq 'menu') {
- $self->_push_context('ct_preformatted', $command);
- push @{$self->{'document'}->{'commands_info'}->{'dircategory_direntry'}},
- $block if ($command eq 'direntry');
- if ($self->{'current_node'}) {
- if ($command eq 'direntry') {
- if ($self->{'conf'}->{'FORMAT_MENU'} eq 'menu') {
- $self->_line_warn(__("\@direntry after first node"),
- $source_info);
- }
- } elsif ($command eq 'menu') {
- if (!(defined $current->{'parent'}->{'cmdname'})
- or $root_commands{$current->{'parent'}->{'cmdname'}}) {
- $self->{'current_node'}->{'extra'} = {}
- if (!defined($self->{'current_node'}->{'extra'}));
- $self->{'current_node'}->{'extra'}->{'menus'} = []
- if (!defined($self->{'current_node'}->{'extra'}->{'menus'}));
- push @{$self->{'current_node'}->{'extra'}->{'menus'}}, $current;
- } else {
- $self->_line_warn(__("\@menu in invalid context"),
- $source_info);
+ if ($preformatted_commands{$command}) {
+ $self->_push_context('ct_preformatted', $command);
+ } elsif ($math_commands{$command}) {
+ $self->_push_context('ct_math', $command);
+ } elsif ($block_commands{$command} eq 'format_raw') {
+ $self->_push_context('ct_rawpreformatted', $command);
+ } elsif ($block_commands{$command} eq 'region') {
+ push @{$self->{'nesting_context'}->{'regions_stack'}}, $command;
+ } elsif ($block_commands{$command} eq 'menu') {
+ $self->_push_context('ct_preformatted', $command);
+ push @{$self->{'document'}->{'commands_info'}->{'dircategory_direntry'}},
+ $block if ($command eq 'direntry');
+ if ($self->{'current_node'}) {
+ if ($command eq 'direntry') {
+ if ($self->{'conf'}->{'FORMAT_MENU'} eq 'menu') {
+ $self->_line_warn(__("\@direntry after first node"),
+ $source_info);
+ }
+ } elsif ($command eq 'menu') {
+ if (!(defined $current->{'cmdname'})
+ or $root_commands{$current->{'cmdname'}}) {
+ $self->{'current_node'}->{'extra'} = {}
+ if (!defined($self->{'current_node'}->{'extra'}));
+ $self->{'current_node'}->{'extra'}->{'menus'} = []
+ if (!defined($self->{'current_node'}->{'extra'}->{'menus'}));
+ push @{$self->{'current_node'}->{'extra'}->{'menus'}}, $block;
+ } else {
+ $self->_line_warn(__("\@menu in invalid context"),
+ $source_info);
+ }
}
}
- }
- } elsif ($block_commands{$command} eq 'item_container') {
- # cleaner, and more similar to XS parser, but not required, would have
- # been initialized automatically.
- $current->{'items_count'} = 0;
- } elsif ($command eq 'nodedescriptionblock') {
- if ($self->{'current_node'}) {
- $block->{'extra'} = {} if (!defined($block->{'extra'}));
- $block->{'extra'}->{'element_node'} = $self->{'current_node'};
- if ($self->{'current_node'}->{'extra'}
- and $self->{'current_node'}->{'extra'}->{'node_long_description'}) {
- $self->_line_warn(__("multiple node \@nodedescriptionblock"),
- $source_info);
- } else {
- $self->{'current_node'}->{'extra'} = {}
- if (!$self->{'current_node'}->{'extra'});
- $self->{'current_node'}->{'extra'}->{'node_long_description'}
- = $block;
- if (!$self->{'current_node'}->{'extra'}->{'node_description'}) {
- $self->{'current_node'}->{'extra'}->{'node_description'}
+ } elsif ($block_commands{$command} eq 'item_container') {
+ # cleaner, and more similar to XS parser, but not required, would have
+ # been initialized automatically.
+ $block->{'items_count'} = 0;
+ } elsif ($command eq 'nodedescriptionblock') {
+ if ($self->{'current_node'}) {
+ $block->{'extra'} = {} if (!defined($block->{'extra'}));
+ $block->{'extra'}->{'element_node'} = $self->{'current_node'};
+ if ($self->{'current_node'}->{'extra'}
+ and $self->{'current_node'}->{'extra'}->{'node_long_description'})
{
+ $self->_line_warn(__("multiple node \@nodedescriptionblock"),
+ $source_info);
+ } else {
+ $self->{'current_node'}->{'extra'} = {}
+ if (!$self->{'current_node'}->{'extra'});
+ $self->{'current_node'}->{'extra'}->{'node_long_description'}
= $block;
+ if (!$self->{'current_node'}->{'extra'}->{'node_description'}) {
+ $self->{'current_node'}->{'extra'}->{'node_description'}
+ = $block;
+ }
}
+ } else {
+ $self->_line_warn(__("\@nodedescriptionblock outside of any node"),
+ $source_info);
}
- } else {
- $self->_line_warn(__("\@nodedescriptionblock outside of any node"),
- $source_info);
}
- }
- if ($commands_args_number{$command}) {
- if ($commands_args_number{$command} - 1 > 0) {
- $current->{'remaining_args'}
- = $commands_args_number{$command} - 1;
+ $block_line_e = $block;
+ my $remaining_args = 0;
+ if ($commands_args_number{$command}) {
+ if ($commands_args_number{$command} - 1 > 0) {
+ $remaining_args
+ = $commands_args_number{$command} - 1;
+ }
+ } elsif ($variadic_commands{$command}) {
+ $remaining_args = -1; # unlimited args
}
- } elsif ($variadic_commands{$command}) {
- $current->{'remaining_args'} = -1; # unlimited args
+ $block_line_e->{'remaining_args'} = $remaining_args
+ if ($remaining_args);
+
+ $self->_push_context('ct_line', $command)
}
- my $block_line_arg_element = {
+ $block->{'source_info'} = {%$source_info};
+ push @{$current->{'contents'}}, $block;
+
+ # bla = block line argument
+ my $bla_element = {
'type' => 'block_line_arg',
- 'parent' => $current};
- $current->{'args'} = [$block_line_arg_element];
+ 'parent' => $block_line_e};
- $current = $block_line_arg_element;
+ $block_line_e->{'args'} = [$bla_element];
- $self->_push_context('ct_line', $command)
- unless ($def_commands{$command});
if ($self->{'basic_inline_commands'}->{$command}) {
push @{$self->{'nesting_context'}->{'basic_inline_stack_block'}},
$command;
}
- $block->{'source_info'} = {%$source_info};
_register_global_command($self, $block, $source_info);
- $line = _start_empty_line_after_command($self, $line, $current, $block);
+ $line = _start_empty_line_after_command($self, $line, $bla_element, $block);
- return ($current, $line, $block);
+ return ($bla_element, $line, $block);
}
sub _handle_brace_command($$$$)
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index 8f680b7b63..5bc9ef323f 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -1008,6 +1008,7 @@ handle_block_command (ELEMENT *current, const char
**line_inout,
unsigned long flags = command_data(cmd).flags;
ELEMENT *block = 0;
ELEMENT *bla; /* block line arg element */
+ ELEMENT *block_line_e;
if (command_data(cmd).data == BLOCK_menu
&& (current->type == ET_menu_comment
@@ -1034,132 +1035,132 @@ handle_block_command (ELEMENT *current, const char
**line_inout,
{
ELEMENT *def_line;
char *val;
- push_context (ct_def, cmd);
block = new_command_element (ET_block_command, cmd);
block->e.c->source_info = current_source_info;
- add_to_element_contents (current, block);
def_line = new_element (ET_def_line);
def_line->e.c->source_info = current_source_info;
- add_to_element_contents (block, def_line);
- current = def_line;
- add_extra_string_dup (current, AI_key_def_command, command_name(cmd));
- add_extra_string_dup (current, AI_key_original_def_cmdname,
+ add_extra_string_dup (def_line, AI_key_def_command, command_name(cmd));
+ add_extra_string_dup (def_line, AI_key_original_def_cmdname,
command_name(cmd));
- current->flags |= EF_def_line;
+ def_line->flags |= EF_def_line;
/* Check txidefnamenospace flag */
val = fetch_value ("txidefnamenospace");
if (val)
- current->flags |= EF_omit_def_name_space;
+ def_line->flags |= EF_omit_def_name_space;
+
+ add_to_element_contents (block, def_line);
+ block_line_e = def_line;
+ push_context (ct_def, cmd);
}
else
{
block = new_command_element (ET_block_command, cmd);
- add_to_element_contents (current, block);
- current = block;
- }
- /* Check if 'block args command' */
- if (command_data(cmd).flags & CF_preformatted)
- push_context (ct_preformatted, cmd);
- else if (cmd == CM_displaymath)
- push_context (ct_math, cmd);
- else if (command_data(cmd).data == BLOCK_format_raw)
- {
- push_context (ct_rawpreformatted, cmd);
- }
- else if (command_data(cmd).data == BLOCK_region)
- {
- push_command (&nesting_context.regions_stack, cmd);
- }
-
- if (command_data(cmd).data == BLOCK_menu)
- {
- push_context (ct_preformatted, cmd);
+ if (command_data(cmd).data == BLOCK_preformatted)
+ push_context (ct_preformatted, cmd);
+ else if (cmd == CM_displaymath)
+ push_context (ct_math, cmd);
+ else if (command_data(cmd).data == BLOCK_format_raw)
+ {
+ push_context (ct_rawpreformatted, cmd);
+ }
+ else if (command_data(cmd).data == BLOCK_region)
+ {
+ push_command (&nesting_context.regions_stack, cmd);
+ }
+ else if (command_data(cmd).data == BLOCK_menu)
+ {
+ push_context (ct_preformatted, cmd);
- if (cmd == CM_direntry)
- add_to_element_list (&parsed_document->global_commands
+ if (cmd == CM_direntry)
+ add_to_element_list (&parsed_document->global_commands
.dircategory_direntry,
- block);
+ block);
- if (current_node)
- {
- if (cmd == CM_direntry && global_parser_conf.show_menu)
+ if (current_node)
{
- line_warn ("@direntry after first node");
- }
- else if (cmd == CM_menu)
- {
- if (!(command_flags(current->parent) & CF_root))
- line_warn ("@menu in invalid context");
- else
+ if (cmd == CM_direntry && global_parser_conf.show_menu)
+ {
+ line_warn ("@direntry after first node");
+ }
+ else if (cmd == CM_menu)
{
- CONST_ELEMENT_LIST *l
- = add_extra_contents (current_node, AI_key_menus, 0);
- add_to_const_element_list (l, block);
+ if (!(command_flags(current) & CF_root))
+ line_warn ("@menu in invalid context");
+ else
+ {
+ CONST_ELEMENT_LIST *l
+ = add_extra_contents (current_node, AI_key_menus, 0);
+ add_to_const_element_list (l, block);
+ }
}
}
}
- }
- else if (cmd == CM_nodedescriptionblock)
- {
- if (current_node)
+ /* BLOCK_item_container */
+ else if (cmd == CM_itemize || cmd == CM_enumerate)
+ counter_push (&count_items, block, 0);
+ /* BLOCK_other */
+ else if (cmd == CM_nodedescriptionblock)
{
- const ELEMENT *node_long_description
- = lookup_extra_element (current_node,
- AI_key_node_long_description);
- if (node_long_description)
- line_warn ("multiple node @nodedescriptionblock");
- else
+ if (current_node)
{
- const ELEMENT *node_description
- = lookup_extra_element (current_node, AI_key_node_description);
+ const ELEMENT *node_long_description
+ = lookup_extra_element (current_node,
+ AI_key_node_long_description);
+ if (node_long_description)
+ line_warn ("multiple node @nodedescriptionblock");
+ else
+ {
+ const ELEMENT *node_description
+ = lookup_extra_element (current_node,
+ AI_key_node_description);
- if (!node_description)
- add_extra_element (current_node, AI_key_node_description,
- block);
+ if (!node_description)
+ add_extra_element (current_node, AI_key_node_description,
+ block);
- add_extra_element (current_node, AI_key_node_long_description,
- block);
+ add_extra_element (current_node,
AI_key_node_long_description,
+ block);
+ }
+ add_extra_element (block, AI_key_element_node, current_node);
}
- add_extra_element (block, AI_key_element_node, current_node);
+ else
+ line_warn ("@nodedescriptionblock outside of any node");
}
- else
- line_warn ("@nodedescriptionblock outside of any node");
+
+ block_line_e = block;
+ if (command_data (block_line_e->e.c->cmd).args_number > 1)
+ {
+ counter_push (&count_remaining_args,
+ block_line_e,
+ command_data (block_line_e->e.c->cmd).args_number - 1);
+ }
+ else if (command_data (block_line_e->e.c->cmd).flags & CF_variadic)
+ {
+ /* Unlimited args */
+ counter_push (&count_remaining_args, block_line_e,
+ COUNTER_VARIADIC);
+ }
+ push_context (ct_line, cmd);
}
- else if (cmd == CM_itemize || cmd == CM_enumerate)
- counter_push (&count_items, current, 0);
+ block->e.c->source_info = current_source_info;
+ add_to_element_contents (current, block);
bla = new_element (ET_block_line_arg);
- add_to_element_args (current, bla);
+ add_to_element_args (block_line_e, bla);
- if (command_data (current->e.c->cmd).args_number > 1)
- {
- counter_push (&count_remaining_args,
- current,
- command_data (current->e.c->cmd).args_number - 1);
- }
- else if (command_data (current->e.c->cmd).flags & CF_variadic)
- {
- /* Unlimited args */
- counter_push (&count_remaining_args, current,
- COUNTER_VARIADIC);
- }
- current = bla;
- if (!(command_data(cmd).flags & CF_def))
- push_context (ct_line, cmd);
if (command_data(cmd).flags & CF_contain_basic_inline)
push_command (&nesting_context.basic_inline_stack_block, cmd);
- block->e.c->source_info = current_source_info;
register_global_command (block);
- start_empty_line_after_command (current, &line, block);
+ start_empty_line_after_command (bla, &line, block);
*line_inout = line;
*command_element = block;
- return current;
+ return bla;
}
/* in that case command_element always point to the returned current