texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Sun, 29 Sep 2024 06:54:29 -0400 (EDT)

branch: master
commit 4a3ea9851ecb4b139b0c4ee53a1cf09579e1f64e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Jun 21 23:21:20 2024 +0200

    * tp/Texinfo/XS/parsetexi/handle_commands.c (handle_block_command):
    minor changes.  avoid setting current twice.  use else if for
    conditions that are exclusive instead of series of if.
    
    * tp/Texinfo/ParserNonXS.pm (_handle_block_command): update to be more
    like C code.
---
 ChangeLog                                 |  9 ++++++
 tp/Texinfo/ParserNonXS.pm                 | 51 +++++++++++++++----------------
 tp/Texinfo/XS/parsetexi/handle_commands.c | 11 +++----
 3 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ef11983162..2e59207955 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-06-21  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/parsetexi/handle_commands.c (handle_block_command):
+       minor changes.  avoid setting current twice.  use else if for
+       conditions that are exclusive instead of series of if.
+
+       * tp/Texinfo/ParserNonXS.pm (_handle_block_command): update to be more
+       like C code.
+
 2024-06-21  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/ParserNonXS.pm (_handle_block_command)
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 41b60b0403..4c0fe3a1f3 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -5966,27 +5966,27 @@ sub _handle_block_command($$$$$)
                'cmdname' => $command,
                'contents' => [] };
     push @{$current->{'contents'}}, $block;
-    $current = $current->{'contents'}->[-1];
-    push @{$current->{'contents'}}, {
-                                      'type' => 'def_line',
-                                      'parent' => $current,
-                                      'source_info' => {%$source_info},
-                                      'extra' =>
-                                       {'def_command' => $command,
-                                        'original_def_cmdname' => $command,
-                                       },
-                                      };
+    my $def_line = {
+                     'type' => 'def_line',
+                     'parent' => $block,
+                     'source_info' => {%$source_info},
+                     'extra' =>
+                       {'def_command' => $command,
+                        'original_def_cmdname' => $command,
+                       },
+                    };
+    push @{$block->{'contents'}}, $def_line;
     if (defined($self->{'values'}->{'txidefnamenospace'})) {
-      $current->{'contents'}->[-1]->{'extra'}
-                                  ->{'omit_def_name_space'} = 1;
+      $def_line->{'extra'}->{'omit_def_name_space'} = 1;
     }
+    $current = $def_line;
   } else {
     $block = { 'cmdname' => $command,
                'parent' => $current,
              };
     push @{$current->{'contents'}}, $block;
+    $current = $block;
   }
-  $current = $current->{'contents'}->[-1];
 
   if ($preformatted_commands{$command}) {
     $self->_push_context('ct_preformatted', $command);
@@ -5994,10 +5994,10 @@ sub _handle_block_command($$$$$)
     $self->_push_context('ct_math', $command);
   } elsif ($block_commands{$command} eq 'format_raw') {
     $self->_push_context('ct_rawpreformatted', $command);
-  }
-  if ($block_commands{$command} eq 'region') {
+  } 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'}},
@@ -6022,14 +6022,11 @@ sub _handle_block_command($$$$$)
         }
       }
     }
-  }
+  } 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
-     if ($block_commands{$command}
-         and $block_commands{$command} eq 'item_container');
-
-  if ($command eq 'nodedescriptionblock') {
+    $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'};
@@ -6053,10 +6050,6 @@ sub _handle_block_command($$$$$)
     }
   }
 
-  $current->{'args'} = [ {
-     'type' => 'block_line_arg',
-     'parent' => $current } ];
-
   if ($commands_args_number{$command}) {
     if ($commands_args_number{$command} - 1 > 0) {
       $current->{'remaining_args'}
@@ -6065,7 +6058,13 @@ sub _handle_block_command($$$$$)
   } elsif ($variadic_commands{$command}) {
     $current->{'remaining_args'} = -1; # unlimited args
   }
-  $current = $current->{'args'}->[-1];
+  my $block_line_arg_element = {
+                 'type' => 'block_line_arg',
+                 'parent' => $current};
+  $current->{'args'} = [$block_line_arg_element];
+
+  $current = $block_line_arg_element;
+
   $self->_push_context('ct_line', $command)
     unless ($def_commands{$command});
   if ($self->{'basic_inline_commands'}->{$command}) {
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c 
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index ff1db90b6f..59398abf4b 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -1037,11 +1037,11 @@ handle_block_command (ELEMENT *current, const char 
**line_inout,
       block = new_command_element (ET_block_command, cmd);
       block->e.c->source_info = current_source_info;
       add_to_element_contents (current, block);
-      current = block;
 
       def_line = new_element (ET_def_line);
       def_line->e.c->source_info = current_source_info;
-      add_to_element_contents (current, def_line);
+      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,
@@ -1101,8 +1101,7 @@ handle_block_command (ELEMENT *current, const char 
**line_inout,
             }
         }
     }
-
-  if (cmd == CM_nodedescriptionblock)
+  else if (cmd == CM_nodedescriptionblock)
     {
       if (current_node)
         {
@@ -1127,10 +1126,8 @@ handle_block_command (ELEMENT *current, const char 
**line_inout,
         }
       else
         line_warn ("@nodedescriptionblock outside of any node");
-
     }
-
-  if (cmd == CM_itemize || cmd == CM_enumerate)
+  else if (cmd == CM_itemize || cmd == CM_enumerate)
     counter_push (&count_items, current, 0);
 
   bla = new_element (ET_block_line_arg);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]