texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Common.pm (%commands_args_number): m


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Common.pm (%commands_args_number): merge %brace_commands_args_number and %block_commands_args_number in %commands_args_number, and add the number of arguments of node too, matching the XS parser.
Date: Tue, 27 Sep 2022 06:44:16 -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 f6c3e57209 * tp/Texinfo/Common.pm (%commands_args_number): merge 
%brace_commands_args_number and %block_commands_args_number in 
%commands_args_number, and add the number of arguments of node too, matching 
the XS parser.
f6c3e57209 is described below

commit f6c3e572093141fe893fe64110ea9ade3ac77f87
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Sep 27 12:44:07 2022 +0200

    * tp/Texinfo/Common.pm (%commands_args_number): merge
    %brace_commands_args_number and %block_commands_args_number in
    %commands_args_number, and add the number of arguments of node too,
    matching the XS parser.
    
    * tp/Texinfo/Common.pm (_process_remaining_on_line),
    tp/Texinfo/XS/parsetexi/handle_commands.c (handle_line_command):
    Use the number of arguments of node more like other commands
    both in the perl and the XS parser.
---
 ChangeLog                                 | 12 ++++++
 tp/Texinfo/Common.pm                      | 62 ++++++++++++++++++-------------
 tp/Texinfo/ParserNonXS.pm                 | 36 +++++++++---------
 tp/Texinfo/XS/parsetexi/handle_commands.c | 16 ++++----
 4 files changed, 77 insertions(+), 49 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6a69447d78..7e644fdc0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2022-09-27  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Common.pm (%commands_args_number): merge
+       %brace_commands_args_number and %block_commands_args_number in
+       %commands_args_number, and add the number of arguments of node too,
+       matching the XS parser.
+
+       * tp/Texinfo/Common.pm (_process_remaining_on_line),
+       tp/Texinfo/XS/parsetexi/handle_commands.c (handle_line_command):
+       Use the number of arguments of node more like other commands
+       both in the perl and the XS parser.
+
 2022-09-27  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Common.pm (%heading_spec_commands),
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index f92f40b086..5d80b43625 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -494,6 +494,13 @@ our %nobrace_commands;             # commands never taking 
braces
            '\\', '\\',  # should only appear in math
 );
 
+# @-commands max number of arguments.  Not set for all commands,
+# in general it only matters if > 1, as commands with 0 args
+# are in specific categories, and default handling of commands
+# ignore commas as argument delimiter, which corresponds to commands
+# with 1 argument.  Only used in Parser.
+our %commands_args_number;
+
 # commands taking a line as argument or no argument.
 # sectioning commands and def* commands are added below.
 # index commands are added dynamically.
@@ -610,6 +617,8 @@ our %line_commands = (
   'subentry'          => 'line',
 );
 
+$commands_args_number{'node'} = 4;
+
 # commands that do not take the whole line as argument
 #
 # skipspace:   no argument, following spaces are skipped.
@@ -683,9 +692,6 @@ foreach my $index_name (keys (%index_names)) {
 
 # commands with braces.
 our %brace_commands;
-# max number of arguments
-our %brace_commands_args_number;
-
 our %letter_no_arg_commands;
 foreach my $letter_no_arg_command ('aa','AA','ae','oe','AE','OE','o','O',
                                    'ss','l','L','DH','dh','TH','th') {
@@ -743,7 +749,7 @@ foreach my $command ('code', 'command', 'env', 'file', 
'kbd', 'option',
 foreach my $one_arg_command ('U', 'dmn', 'key', 'hyphenation', 'indicateurl',
     'titlefont', 'anchor', 'errormsg', 'sortas', 'seeentry', 'seealso') {
   $brace_commands{$one_arg_command} = 'arguments';
-  $brace_commands_args_number{$one_arg_command} = 1;
+  $commands_args_number{$one_arg_command} = 1;
 }
 
 # commands in other keep their leading and trailing spaces in main text
@@ -781,7 +787,7 @@ our %explained_commands;
 foreach my $explained_command ('abbr', 'acronym') {
   $explained_commands{$explained_command} = 1;
   $brace_commands{$explained_command} = 'arguments';
-  $brace_commands_args_number{$explained_command} = 2;
+  $commands_args_number{$explained_command} = 2;
 }
 
 our %inline_format_commands;
@@ -789,33 +795,33 @@ our %inline_commands;
 foreach my $inline_format_command ('inlineraw', 'inlinefmt',
         'inlinefmtifelse') {
   $inline_format_commands{$inline_format_command} = 1;
-  $brace_commands_args_number{$inline_format_command} = 2;
+  $commands_args_number{$inline_format_command} = 2;
   $brace_commands{$inline_format_command} = 'arguments';
   $inline_commands{$inline_format_command} = 1;
 }
 
-$brace_commands_args_number{'inlinefmtifelse'} = 3;
+$commands_args_number{'inlinefmtifelse'} = 3;
 
 our %inline_conditional_commands;
 foreach my $inline_conditional_command ('inlineifclear', 'inlineifset') {
   $inline_conditional_commands{$inline_conditional_command} = 1;
-  $brace_commands_args_number{$inline_conditional_command} = 2;
+  $commands_args_number{$inline_conditional_command} = 2;
   $brace_commands{$inline_conditional_command} = 'arguments';
   $inline_commands{$inline_conditional_command} = 1;
 }
 
 foreach my $two_arg_command('email') {
-  $brace_commands_args_number{$two_arg_command} = 2;
+  $commands_args_number{$two_arg_command} = 2;
   $brace_commands{$two_arg_command} = 'arguments';
 }
 
 foreach my $three_arg_command('uref','url','inforef') {
-  $brace_commands_args_number{$three_arg_command} = 3;
+  $commands_args_number{$three_arg_command} = 3;
   $brace_commands{$three_arg_command} = 'arguments';
 }
 
 foreach my $five_arg_command('xref','ref','pxref','image') {
-  $brace_commands_args_number{$five_arg_command} = 5;
+  $commands_args_number{$five_arg_command} = 5;
   $brace_commands{$five_arg_command} = 'arguments';
 }
 
@@ -836,8 +842,6 @@ foreach my $unformatted_brace_command ('anchor', 
'shortcaption',
 # commands delimiting blocks, with an @end.
 # Type of command, 'raw', 'def', 'conditional', 'multitable'...
 our %block_commands;
-# Number of arguments on the line separated by commas
-our %block_commands_args_number;
 
 # commands that have a possible content before an item
 our %blockitem_commands;
@@ -945,7 +949,7 @@ foreach my $preformatted_command(
   $preformatted_commands{$preformatted_command} = 1;
   $preformatted_code_commands{$preformatted_command} = 1;
 }
-$block_commands_args_number{'example'} = 'variadic'; # unlimited arguments
+$commands_args_number{'example'} = 'variadic'; # unlimited arguments
 
 foreach my $preformatted_command(
     'display', 'smalldisplay', 'format', 'smallformat') {
@@ -986,23 +990,23 @@ $block_commands{'ifcommandnotdefined'} = 'conditional';
 
 foreach my $item_container_command ('itemize', 'enumerate') {
   $block_commands{$item_container_command} = 'item_container';
-  $block_commands_args_number{$item_container_command} = 1;
+  $commands_args_number{$item_container_command} = 1;
   $blockitem_commands{$item_container_command} = 1;
 }
 
 foreach my $item_line_command ('table', 'ftable', 'vtable') {
   $block_commands{$item_line_command} = 'item_line';
-  $block_commands_args_number{$item_line_command} = 1;
+  $commands_args_number{$item_line_command} = 1;
   $blockitem_commands{$item_line_command} = 1;
 }
 
 foreach my $block_command_one_arg('quotation', 'smallquotation') {
   $block_commands{$block_command_one_arg} = 'quotation';
-  $block_commands_args_number{$block_command_one_arg} = 1;
+  $commands_args_number{$block_command_one_arg} = 1;
 }
 
 $block_commands{'float'} = 'float';
-$block_commands_args_number{'float'} = 2;
+$commands_args_number{'float'} = 2;
 
 # commands that forces closing an opened paragraph.
 our %close_paragraph_commands;
@@ -2985,18 +2989,26 @@ of @-commands in their bodies (C<@macro>, C<@verbatim> 
and C<@ignore>);
 
 Other values for other block line commands.
 
-=item %block_commands_args_number
-X<C<%block_commands_args_number>>
+=item %commands_args_number
+X<C<%commands_args_number>>
+
+Set to the number of arguments separated by commas that may appear in braces or
+on the @-command line, or to I<variadic> if there is an unlimited number of
+arguments.  That means 0 or unset in most block command cases, 1 for
+C<@quotation>, 2 for C<@float> and C<variadic> for C<@example>, 1 for most
+brace commands, 2 for C<@email> or C<@abbr>, 5 for C<@image> of C<@ref>.
 
-Set to the number of arguments separated by commas that may appear on the
-@-command line, or to I<variadic> if there is an unlimited number of arguments.
-That means 0 or unset in most cases, 1 for C<@quotation>, 2 for C<@float> and
-C<variadic> for C<@example>.
+Values are not necessarily set for all the commands, as commands are
+also classified by type of command, some type of commands implying a
+number of arguments, and the number of arguments may not be set if it
+coorresponds to the default (0 for block commands, 1 for other commands).
 
 =item %brace_commands
 X<C<%brace_commands>>
 
-The commands that take braces.
+The commands that take braces. Value is I<noarg> for brace commands without
+argument such as C<@AA>, C<@TeX>, or C<@equiv>.  Other values include
+I<accent>, I<arguments>, I<context> and other values.
 
 =item %brace_code_commands
 X<C<%brace_code_commands>>
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 451e8ee705..bd3085d561 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -261,11 +261,10 @@ my %nobrace_commands         = 
%Texinfo::Common::nobrace_commands;
 my %line_commands             = %Texinfo::Common::line_commands;
 my %other_commands            = %Texinfo::Common::other_commands;
 my %brace_commands            = %Texinfo::Common::brace_commands;
-my %brace_commands_args_number = %Texinfo::Common::brace_commands_args_number;
+my %commands_args_number      = %Texinfo::Common::commands_args_number;
 my %accent_commands           = %Texinfo::Common::accent_commands;
 my %context_brace_commands    = %Texinfo::Common::context_brace_commands;
 my %block_commands            = %Texinfo::Common::block_commands;
-my %block_commands_args_number = %Texinfo::Common::block_commands_args_number;
 my %blockitem_commands        = %Texinfo::Common::blockitem_commands;
 my %close_paragraph_commands  = %Texinfo::Common::close_paragraph_commands;
 my %def_map                   = %Texinfo::Common::def_map;
@@ -4853,13 +4852,16 @@ sub _process_remaining_on_line($$$$)
         $current = $current->{'contents'}->[-1];
         $current->{'args'} = [{ 'type' => 'line_arg',
                                 'parent' => $current }];
-        # @node is the only misc command with args separated with comma
-        # FIXME a 3 lingering here deep into the code may not
-        # be very wise...  However having a hash only for one @-command
-        # is not very appealing either...
-        if ($command eq 'node') {
-          $current->{'remaining_args'} = 3;
-        } elsif ($command eq 'author') {
+
+        # 'specific' commands arguments are handled in a specific way.
+        # The only other line commands that have more than one argument is
+        # node, so the following condition only applies to node
+        if ($self->{'line_commands'}->{$command} ne 'specific'
+            and $commands_args_number{$command}
+            and $commands_args_number{$command} > 1) {
+          $current->{'remaining_args'} = $commands_args_number{$command} - 1;
+        }
+        if ($command eq 'author') {
           my $parent = $current;
           my $found;
           while ($parent->{'parent'}) {
@@ -5087,13 +5089,13 @@ sub _process_remaining_on_line($$$$)
            'contents' => [],
            'parent' => $current } ];
 
-        if ($block_commands_args_number{$command}) {
-          if ($block_commands_args_number{$command} =~ /^\d+$/) {
-            if ($block_commands_args_number{$command} - 1 > 0) {
+        if ($commands_args_number{$command}) {
+          if ($commands_args_number{$command} =~ /^\d+$/) {
+            if ($commands_args_number{$command} - 1 > 0) {
               $current->{'remaining_args'}
-                = $block_commands_args_number{$command} - 1;
+                = $commands_args_number{$command} - 1;
             }
-          } elsif ($block_commands_args_number{$command} eq 'variadic') {
+          } elsif ($commands_args_number{$command} eq 'variadic') {
             $current->{'remaining_args'} = -1; # unlimited args
           }
         }
@@ -5159,10 +5161,10 @@ sub _process_remaining_on_line($$$$)
         my $command = $current->{'cmdname'};
         $current->{'args'} = [ { 'parent' => $current } ];
 
-        if (defined($brace_commands_args_number{$command})
-            and $brace_commands_args_number{$command} > 1) {
+        if (defined($commands_args_number{$command})
+            and $commands_args_number{$command} > 1) {
           $current->{'remaining_args'}
-              = $brace_commands_args_number{$command} - 1;
+              = $commands_args_number{$command} - 1;
         }
 
         $current = $current->{'args'}->[-1];
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c 
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index ef844a44c7..cbff82e6d8 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -587,15 +587,17 @@ handle_line_command (ELEMENT *current, char **line_inout,
       arg = new_element (ET_line_arg);
       add_to_element_args (current, arg);
 
-      if (cmd == CM_node)
+      /* LINE_specific commands arguments are handled in a specific way.
+         The only other line commands that have more than one argument is
+         node, so the following condition only applies to node */
+      if (command_data (current->cmd).data != LINE_specific
+          && command_data (current->cmd).args_number > 1)
         {
-          /* At most three comma-separated arguments to @node.  This
-             is the only (non-block) line command taking comma-separated
-             arguments.  Its arguments will be gathered the same as
-             those of some block line commands and brace commands. */
-          counter_push (&count_remaining_args, current, 3);
+          counter_push (&count_remaining_args,
+                        current,
+                        command_data (current->cmd).args_number - 1);
         }
-      else if (cmd == CM_author)
+      if (cmd == CM_author)
         {
           ELEMENT *parent = current;
           int found = 0;



reply via email to

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