texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/ParserNonXS.pm (_expand_macro_argume


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_expand_macro_arguments), tp/Texinfo/XS/parsetexi/macro.c (expand_macro_arguments): only remove last empty argument in macro call arguments, an empty argument in the middle is significant.
Date: Fri, 10 Feb 2023 16:44:05 -0500

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 a695cfb241 * tp/Texinfo/ParserNonXS.pm (_expand_macro_arguments), 
tp/Texinfo/XS/parsetexi/macro.c (expand_macro_arguments): only remove last 
empty argument in macro call arguments, an empty argument in the middle is 
significant.
a695cfb241 is described below

commit a695cfb24117338ecf03bdf743928ba4c0a66cbf
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Feb 10 22:43:56 2023 +0100

    * tp/Texinfo/ParserNonXS.pm (_expand_macro_arguments),
    tp/Texinfo/XS/parsetexi/macro.c (expand_macro_arguments): only remove
    last empty argument in macro call arguments, an empty argument in the
    middle is significant.
    
    * tp/Makefile.tres, tp/t/60macro.t: new test
    macro_call_empty_middle_arg with an empty middle argument in a macro
    call.
---
 ChangeLog                                         |  11 +
 tp/Makefile.tres                                  |   1 +
 tp/Texinfo/ParserNonXS.pm                         |   6 +-
 tp/Texinfo/XS/parsetexi/macro.c                   |   9 +-
 tp/t/60macro.t                                    |  13 +
 tp/t/results/macro/macro_call_empty_middle_arg.pl | 368 ++++++++++++++++++++++
 6 files changed, 402 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 026ad51663..dbc1d0ad62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2023-02-10  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_expand_macro_arguments),
+       tp/Texinfo/XS/parsetexi/macro.c (expand_macro_arguments): only remove
+       last empty argument in macro call arguments, an empty argument in the
+       middle is significant.
+
+       * tp/Makefile.tres, tp/t/60macro.t: new test
+       macro_call_empty_middle_arg with an empty middle argument in a macro
+       call.
+
 2023-02-10  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/ParserNonXS.pm (_remove_empty_arg)
diff --git a/tp/Makefile.tres b/tp/Makefile.tres
index a8d4da3ded..b8614acb61 100644
--- a/tp/Makefile.tres
+++ b/tp/Makefile.tres
@@ -1201,6 +1201,7 @@ test_files_generated_list = 
$(test_tap_files_generated_list) \
   t/results/macro/line_after_recursive_call.pl \
   t/results/macro/macro_after_paragraph.pl \
   t/results/macro/macro_before_specific_line_command_args.pl \
+  t/results/macro/macro_call_empty_middle_arg.pl \
   t/results/macro/macro_expands_to_empty.pl \
   t/results/macro/macro_expansion.pl \
   t/results/macro/macro_for_dot_in_menu_not_separator.pl \
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 5b1e841f52..b3f2f01df9 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -2566,9 +2566,6 @@ sub _expand_macro_arguments($$$$$)
         }
       } elsif ($separator eq ',') {
         if ($braces_level == 1) {
-          if ($argument_content->{'text'} eq '') {
-            _remove_empty_arg($self, $argument);
-          }
           if (scalar(@{$current->{'args'}}) < $args_total) {
             $argument = {'type' => 'brace_command_arg',
                          'contents' => [],
@@ -2598,6 +2595,9 @@ sub _expand_macro_arguments($$$$$)
       } elsif ($separator eq '}') {
         $braces_level--;
         if ($braces_level == 0) {
+          # It is possible to remove the last argument if empty
+          # since not being expanded is the same as being expanded
+          # as an empty string.
           if ($argument_content->{'text'} eq '') {
             _remove_empty_arg($self, $argument);
           }
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index 7c4ad846b0..55258fd269 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -340,9 +340,6 @@ expand_macro_arguments (ELEMENT *macro, char **line_inout, 
enum command_id cmd,
           // check for too many args
           if (*sep == '}' || current->args.number < args_total)
             {
-              if (arg->end == 0)
-                remove_empty_arg (argument);
-
               debug ("MACRO NEW ARG");
               pline = sep + 1;
 
@@ -364,6 +361,12 @@ expand_macro_arguments (ELEMENT *macro, char **line_inout, 
enum command_id cmd,
                                             spaces_element);
                     }
                 }
+              else if (arg->end == 0)
+               /* It is possible to remove the last argument if empty
+                  since not being expanded is the same as being expanded
+                  as an empty string. */
+                remove_empty_arg (argument);
+
             }
           else
             {
diff --git a/tp/t/60macro.t b/tp/t/60macro.t
index c80f1d7be0..8c22c6bf42 100644
--- a/tp/t/60macro.t
+++ b/tp/t/60macro.t
@@ -219,6 +219,19 @@ Call macro2 with 2 args
 Macro
 @zero{}
 '],
+['macro_call_empty_middle_arg',
+'@macro threea {aa, bb, cc}
+first \aa\,
+second \bb\,
+third \cc\,
+@end macro
+
+@threea{j, k, l}
+
+@threea{m, , n}
+
+@threea{o,,p}
+'],
 ['protect_in_body',
 '@macro macroone { arg1 , arg2 }
 result: @emph{\arg1\} protected \\\\ -> \\\\arg1\\\\ @emph{\arg2\}
diff --git a/tp/t/results/macro/macro_call_empty_middle_arg.pl 
b/tp/t/results/macro/macro_call_empty_middle_arg.pl
new file mode 100644
index 0000000000..d702d3d1a2
--- /dev/null
+++ b/tp/t/results/macro/macro_call_empty_middle_arg.pl
@@ -0,0 +1,368 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors 
+   %result_indices %result_sectioning %result_nodes %result_menus
+   %result_floats %result_converted %result_converted_errors 
+   %result_elements %result_directions_text %result_indices_sort_strings);
+
+use utf8;
+
+$result_trees{'macro_call_empty_middle_arg'} = {
+  'contents' => [
+    {
+      'contents' => [
+        {
+          'args' => [
+            {
+              'text' => 'threea',
+              'type' => 'macro_name'
+            },
+            {
+              'text' => 'aa',
+              'type' => 'macro_arg'
+            },
+            {
+              'text' => 'bb',
+              'type' => 'macro_arg'
+            },
+            {
+              'text' => 'cc',
+              'type' => 'macro_arg'
+            }
+          ],
+          'cmdname' => 'macro',
+          'contents' => [
+            {
+              'text' => 'first \\aa\\,
+',
+              'type' => 'raw'
+            },
+            {
+              'text' => 'second \\bb\\,
+',
+              'type' => 'raw'
+            },
+            {
+              'text' => 'third \\cc\\,
+',
+              'type' => 'raw'
+            },
+            {
+              'args' => [
+                {
+                  'contents' => [
+                    {
+                      'text' => 'macro'
+                    }
+                  ],
+                  'info' => {
+                    'spaces_after_argument' => {
+                      'text' => '
+'
+                    }
+                  },
+                  'type' => 'line_arg'
+                }
+              ],
+              'cmdname' => 'end',
+              'extra' => {
+                'text_arg' => 'macro'
+              },
+              'info' => {
+                'spaces_before_argument' => {
+                  'text' => ' '
+                }
+              },
+              'source_info' => {
+                'file_name' => '',
+                'line_nr' => 5,
+                'macro' => ''
+              }
+            }
+          ],
+          'info' => {
+            'arg_line' => ' threea {aa, bb, cc}
+'
+          },
+          'source_info' => {
+            'file_name' => '',
+            'line_nr' => 1,
+            'macro' => ''
+          }
+        },
+        {
+          'source_marks' => [
+            {
+              'counter' => 1,
+              'element' => {
+                'args' => [
+                  {
+                    'contents' => [
+                      {
+                        'text' => 'j'
+                      }
+                    ],
+                    'type' => 'brace_command_arg'
+                  },
+                  {
+                    'contents' => [
+                      {
+                        'text' => 'k'
+                      }
+                    ],
+                    'info' => {
+                      'spaces_before_argument' => {
+                        'text' => ' '
+                      }
+                    },
+                    'type' => 'brace_command_arg'
+                  },
+                  {
+                    'contents' => [
+                      {
+                        'text' => 'l'
+                      }
+                    ],
+                    'info' => {
+                      'spaces_before_argument' => {
+                        'text' => ' '
+                      }
+                    },
+                    'type' => 'brace_command_arg'
+                  }
+                ],
+                'extra' => {
+                  'name' => 'threea'
+                },
+                'type' => 'macro_call'
+              },
+              'position' => 1,
+              'sourcemark_type' => 'macro_expansion',
+              'status' => 'start'
+            }
+          ],
+          'text' => '
+',
+          'type' => 'empty_line'
+        },
+        {
+          'contents' => [
+            {
+              'text' => 'first j,
+'
+            },
+            {
+              'text' => 'second k,
+'
+            },
+            {
+              'source_marks' => [
+                {
+                  'counter' => 1,
+                  'position' => 8,
+                  'sourcemark_type' => 'macro_expansion',
+                  'status' => 'end'
+                }
+              ],
+              'text' => 'third l,
+'
+            }
+          ],
+          'type' => 'paragraph'
+        },
+        {
+          'source_marks' => [
+            {
+              'counter' => 2,
+              'element' => {
+                'args' => [
+                  {
+                    'contents' => [
+                      {
+                        'text' => 'm'
+                      }
+                    ],
+                    'type' => 'brace_command_arg'
+                  },
+                  {
+                    'contents' => [
+                      {
+                        'text' => ''
+                      }
+                    ],
+                    'info' => {
+                      'spaces_before_argument' => {
+                        'text' => ' '
+                      }
+                    },
+                    'type' => 'brace_command_arg'
+                  },
+                  {
+                    'contents' => [
+                      {
+                        'text' => 'n'
+                      }
+                    ],
+                    'info' => {
+                      'spaces_before_argument' => {
+                        'text' => ' '
+                      }
+                    },
+                    'type' => 'brace_command_arg'
+                  }
+                ],
+                'extra' => {
+                  'name' => 'threea'
+                },
+                'type' => 'macro_call'
+              },
+              'position' => 1,
+              'sourcemark_type' => 'macro_expansion',
+              'status' => 'start'
+            }
+          ],
+          'text' => '
+',
+          'type' => 'empty_line'
+        },
+        {
+          'contents' => [
+            {
+              'text' => 'first m,
+'
+            },
+            {
+              'text' => 'second ,
+'
+            },
+            {
+              'source_marks' => [
+                {
+                  'counter' => 2,
+                  'position' => 8,
+                  'sourcemark_type' => 'macro_expansion',
+                  'status' => 'end'
+                }
+              ],
+              'text' => 'third n,
+'
+            }
+          ],
+          'type' => 'paragraph'
+        },
+        {
+          'source_marks' => [
+            {
+              'counter' => 3,
+              'element' => {
+                'args' => [
+                  {
+                    'contents' => [
+                      {
+                        'text' => 'o'
+                      }
+                    ],
+                    'type' => 'brace_command_arg'
+                  },
+                  {
+                    'contents' => [
+                      {
+                        'text' => ''
+                      }
+                    ],
+                    'type' => 'brace_command_arg'
+                  },
+                  {
+                    'contents' => [
+                      {
+                        'text' => 'p'
+                      }
+                    ],
+                    'type' => 'brace_command_arg'
+                  }
+                ],
+                'extra' => {
+                  'name' => 'threea'
+                },
+                'type' => 'macro_call'
+              },
+              'position' => 1,
+              'sourcemark_type' => 'macro_expansion',
+              'status' => 'start'
+            }
+          ],
+          'text' => '
+',
+          'type' => 'empty_line'
+        },
+        {
+          'contents' => [
+            {
+              'text' => 'first o,
+'
+            },
+            {
+              'text' => 'second ,
+'
+            },
+            {
+              'source_marks' => [
+                {
+                  'counter' => 3,
+                  'position' => 8,
+                  'sourcemark_type' => 'macro_expansion',
+                  'status' => 'end'
+                }
+              ],
+              'text' => 'third p,
+'
+            }
+          ],
+          'type' => 'paragraph'
+        }
+      ],
+      'type' => 'before_node_section'
+    }
+  ],
+  'type' => 'document_root'
+};
+
+$result_texis{'macro_call_empty_middle_arg'} = '@macro threea {aa, bb, cc}
+first \\aa\\,
+second \\bb\\,
+third \\cc\\,
+@end macro
+
+first j,
+second k,
+third l,
+
+first m,
+second ,
+third n,
+
+first o,
+second ,
+third p,
+';
+
+
+$result_texts{'macro_call_empty_middle_arg'} = '
+first j,
+second k,
+third l,
+
+first m,
+second ,
+third n,
+
+first o,
+second ,
+third p,
+';
+
+$result_errors{'macro_call_empty_middle_arg'} = [];
+
+
+$result_floats{'macro_call_empty_middle_arg'} = {};
+
+
+1;



reply via email to

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