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 (_handle_macro) (_pro


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_handle_macro) (_process_remaining_on_line), tp/Texinfo/XS/parsetexi/macro.c (handle_macro), tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line): return an error status from handle_macro for macro expansion error. Do not get next text and instead return the remaining of the line if there was a macro expansion error.
Date: Wed, 22 Feb 2023 16:42:23 -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 fb3c64135f * tp/Texinfo/ParserNonXS.pm (_handle_macro) 
(_process_remaining_on_line), tp/Texinfo/XS/parsetexi/macro.c (handle_macro), 
tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line): return an error 
status from handle_macro for macro expansion error.  Do not get next text and 
instead return the remaining of the line if there was a macro expansion error.
fb3c64135f is described below

commit fb3c64135fe5de497e4181ca477d8d5a23d39b67
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Feb 22 22:38:11 2023 +0100

    * tp/Texinfo/ParserNonXS.pm (_handle_macro)
    (_process_remaining_on_line), tp/Texinfo/XS/parsetexi/macro.c
    (handle_macro), tp/Texinfo/XS/parsetexi/parser.c
    (process_remaining_on_line): return an error status from handle_macro for 
macro
    expansion error.  Do not get next text and instead return the
    remaining of the line if there was a macro expansion error.
    
    * tp/Texinfo/ParserNonXS.pm (_handle_macro),
    tp/Texinfo/XS/parsetexi/macro.c (handle_macro): rename current element
    for line_args line arguments parsing as arg_elt.
    
    * tp/Texinfo/ParserNonXS.pm (_handle_macro),
    tp/Texinfo/XS/parsetexi/macro.c (handle_macro): expand macro body only
    if there is no expansion error.
---
 ChangeLog                                       | 17 ++++++
 tp/Texinfo/ParserNonXS.pm                       | 69 ++++++++++++++-----------
 tp/Texinfo/XS/parsetexi/macro.c                 | 37 ++++++-------
 tp/Texinfo/XS/parsetexi/macro.h                 |  4 +-
 tp/Texinfo/XS/parsetexi/parser.c                | 13 +++--
 tp/t/results/macro/glossary.pl                  |  6 ++-
 tp/t/results/macro/line_after_recursive_call.pl |  6 +++
 7 files changed, 96 insertions(+), 56 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 19af3464cf..c6cd2074c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,23 @@
        (brace_no_arg_command): Check ASCII_GLYPH setting rather than
        that of ASCII_PUNCTUATION.
 
+2023-02-22  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_handle_macro)
+       (_process_remaining_on_line), tp/Texinfo/XS/parsetexi/macro.c
+       (handle_macro), tp/Texinfo/XS/parsetexi/parser.c
+       (process_remaining_on_line): return an error status from handle_macro 
for macro
+       expansion error.  Do not get next text and instead return the
+       remaining of the line if there was a macro expansion error.
+
+       * tp/Texinfo/ParserNonXS.pm (_handle_macro),
+       tp/Texinfo/XS/parsetexi/macro.c (handle_macro): rename current element
+       for line_args line arguments parsing as arg_elt.
+
+       * tp/Texinfo/ParserNonXS.pm (_handle_macro),
+       tp/Texinfo/XS/parsetexi/macro.c (handle_macro): expand macro body only
+       if there is no expansion error.
+
 2023-02-22  Patrice Dumas  <pertusus@free.fr>
 
        * p/Texinfo/ParserNonXS.pm (_process_remaining_on_line),
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index f1636dd080..c33237bd3d 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -2582,8 +2582,8 @@ sub _expand_macro_arguments($$$$$)
                "macro `%s' declared without argument called with an argument"),
                                 $name), $source_info);
   }
-  print STDERR "END MACRO ARGS EXPANSION(".scalar(@{$current->{'args'}})."): "
-                 ."|\n" if ($self->{'DEBUG'});
+  print STDERR "END MACRO ARGS EXPANSION(".scalar(@{$current->{'args'}}).") "
+                 ."line: '$line'\n" if ($self->{'DEBUG'});
   return ($line, $source_info);
 }
 
@@ -4711,6 +4711,8 @@ sub _handle_macro($$$$$)
   my $source_info = shift;
   my $command = shift;
 
+  my $error = 0;
+
   my $expanded_macro = $self->{'macros'}->{$command}->{'element'};
   my $args_number = scalar(@{$expanded_macro->{'args'}}) -1;
   my $arguments_container = {'type' => $expanded_macro->{'cmdname'}.'_call',
@@ -4733,31 +4735,31 @@ sub _handle_macro($$$$$)
                               $command), $source_info)
        if ($args_number >= 2);
   } else {
-    my $current = {'type' => 'line_arg',
+    my $arg_elt = {'type' => 'line_arg',
                    'parent' => $arguments_container};
-    push @{$arguments_container->{'args'}}, $current;
+    push @{$arguments_container->{'args'}}, $arg_elt;
     while (1) {
       if ($line eq '') {
-        ($line, $source_info) = _new_line($self, $current);
+        ($line, $source_info) = _new_line($self, $arg_elt);
         if (!defined($line)) {
           $line = '';
           last;
         }
       } else {
-        if (not $current->{'contents'} and $line =~ s/^([^\S\r\n]+)//) {
+        if (not $arg_elt->{'contents'} and $line =~ s/^([^\S\r\n]+)//) {
           my $internal_space = {'type' => 'internal_spaces_before_argument',
                                 'text' => $1,
-                                'parent' => $current,
+                                'parent' => $arg_elt,
                                 'extra' => {'spaces_associated_command'
                                               => $arguments_container}};
-          push @{$current->{'contents'}}, $internal_space;
+          push @{$arg_elt->{'contents'}}, $internal_space;
         } else {
           if ($line !~ /\n/) {
-            $current = _merge_text($self, $current, $line);
+            $arg_elt = _merge_text($self, $arg_elt, $line);
             $line = '';
           } else {
             my $has_end_of_line = chomp $line;
-            $current = _merge_text($self, $current, $line);
+            $arg_elt = _merge_text($self, $arg_elt, $line);
             $line = "\n" if ($has_end_of_line);
             last;
           }
@@ -4765,35 +4767,37 @@ sub _handle_macro($$$$$)
       }
     }
   }
-  my $expanded = _expand_macro_body($self,
-                            $self->{'macros'}->{$command},
-                            $arguments_container->{'args'}, $source_info);
-  print STDERR "MACROBODY: $expanded".'||||||'."\n"
-    if ($self->{'DEBUG'});
-  chomp($expanded);
-
   if ($self->{'MAX_MACRO_CALL_NESTING'}
       and scalar(@{$self->{'macro_stack'}}) >= 
$self->{'MAX_MACRO_CALL_NESTING'}) {
     $self->_line_warn(sprintf(__(
   "macro call nested too deeply (set MAX_MACRO_CALL_NESTING to override; 
current value %d)"),
                           $self->{'MAX_MACRO_CALL_NESTING'}), $source_info);
-    goto funexit;
+    $error = 1;
+    # goto funexit in XS parser
+    return ($error, $line, $source_info);
   }
 
   if ($expanded_macro->{'cmdname'} eq 'macro') {
-    my $found = 0;
     foreach my $macro (@{$self->{'macro_stack'}}) {
       if ($macro->{'args'}->[0]->{'text'} eq $command) {
         $self->_line_error(sprintf(__(
        "recursive call of macro %s is not allowed; use \@rmacro if needed"),
                                    $command), $source_info);
-        $found = 1;
-        last;
+        $error = 1;
+        # goto funexit in XS parser
+        return ($error, $line, $source_info);
       }
     }
-    goto funexit if ($found);
   }
 
+  my $expanded = _expand_macro_body($self,
+                            $self->{'macros'}->{$command},
+                            $arguments_container->{'args'}, $source_info);
+  print STDERR "MACROBODY: $expanded".'||||||'."\n"
+    if ($self->{'DEBUG'});
+
+  chomp($expanded);
+
   unshift @{$self->{'macro_stack'}}, $expanded_macro;
   print STDERR "UNSHIFT MACRO_STACK: 
$expanded_macro->{'args'}->[0]->{'text'}\n"
     if ($self->{'DEBUG'});
@@ -4811,9 +4815,11 @@ sub _handle_macro($$$$$)
   $macro_source_mark->{'element'} = $arguments_container;
   _register_source_mark($self, $current, $macro_source_mark);
   $self->{'input'}->[0]->{'input_source_mark'} = $macro_source_mark;
+  # not really important as line is ignored by the caller if there
+  # was no macro expansion error
   $line = '';
- funexit:
-  return ($line, $source_info);
+ #funexit:
+  return ($error, $line, $source_info);
 }
 
 my $STILL_MORE_TO_PROCESS = 0;
@@ -5074,14 +5080,15 @@ sub _process_remaining_on_line($$$$)
     if ($self->{'macros'}->{$command}) {
       substr($line, 0, $at_command_length) = '';
 
-      # TODO check that the $line here, which is discarded right after
-      # is necessarily empty
-      ($line, $source_info)
+      my $expansion_error;
+      ($expansion_error, $line, $source_info)
         = _handle_macro($self, $current, $line, $source_info, $command);
-      # FIXME this is the same as in the XS parser, and it gives somewhat 
better
-      # results in test cases, avoiding useless text.  But it is unclear why
-      # it is so and if it is not covering up some other bug.
-      ($line, $source_info) = _next_text($self, $current);
+      if (!$expansion_error) {
+        # FIXME this is the same as in the XS parser, and it gives somewhat 
better
+        # results in test cases, avoiding useless text.  But it is unclear why
+        # it is so and if it is not covering up some other bug.
+        ($line, $source_info) = _next_text($self, $current);
+      }
       return ($current, $line, $source_info, $retval);
       # goto funexit;  # used in XS code
     }
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index 06ed26e826..0dace8857c 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -517,7 +517,7 @@ wipe_macros (void)
 }
 
 /* Handle macro expansion.  CMD is the macro command. */
-ELEMENT *
+int
 handle_macro (ELEMENT *current, char **line_inout, enum command_id cmd)
 {
   char *line, *p;
@@ -528,6 +528,7 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
   int args_number;
   SOURCE_MARK *macro_source_mark;
   ELEMENT *arguments_container = new_element (ET_NONE);
+  int error = 0;
 
   line = *line_inout;
   text_init (&expanded);
@@ -574,8 +575,8 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
     }
   else
     {
-      ELEMENT *current = new_element (ET_line_arg);
-      add_to_element_args (arguments_container, current);
+      ELEMENT *arg_elt = new_element (ET_line_arg);
+      add_to_element_args (arguments_container, arg_elt);
 
       while (1)
         {
@@ -583,7 +584,7 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
             {
             /* If it takes a single line of input, and we don't have a
                full line of input already, call new_line. */
-              line = new_line (current);
+              line = new_line (arg_elt);
               if (!line)
                 {
                   line = "";
@@ -593,7 +594,7 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
           else
             {
               int leading_spaces_added = 0;
-              if (current->contents.number == 0)
+              if (arg_elt->contents.number == 0)
                 {
                   int leading_spaces_nr = strspn (line,
                                            whitespace_chars_except_newline);
@@ -606,7 +607,7 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
                       add_extra_element (internal_space,
                                          "spaces_associated_command",
                                          arguments_container);
-                      add_to_element_contents (current, internal_space);
+                      add_to_element_contents (arg_elt, internal_space);
 
                       line += leading_spaces_nr;
 
@@ -618,13 +619,13 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
                   char *p = strchr (line, '\n');
                   if (!p)
                     {
-                      current = merge_text (current, line, 0);
+                      arg_elt = merge_text (arg_elt, line, 0);
                       line += strlen(line);
                     }
                   else
                     {
                       *p = '\0';
-                      current = merge_text (current, line, 0);
+                      arg_elt = merge_text (arg_elt, line, 0);
                       line = "\n";
                       break;
                     }
@@ -633,12 +634,6 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
         }
     }
 
-  expand_macro_body (macro_record, arguments_container, &expanded);
-  debug ("MACROBODY: %s||||||", expanded.text);
-
-  if (expanded.end > 0 && expanded.text[expanded.end - 1] == '\n')
-    expanded.text[--expanded.end] = '\0';
-
   if (conf.max_macro_call_nesting
       && macro_expansion_nr >= conf.max_macro_call_nesting)
     {
@@ -646,6 +641,7 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
          "macro call nested too deeply "
          "(set MAX_MACRO_CALL_NESTING to override; current value %d)",
                 conf.max_macro_call_nesting);
+      error = 1;
       goto funexit;
     }
 
@@ -655,13 +651,16 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
         {
           line_error ("recursive call of macro %s is not allowed; "
                       "use @rmacro if needed", command_name(cmd));
-          expanded.text[0] = '\0';
-          expanded.end = 0;
+          error = 1;
           goto funexit;
         }
     }
 
-  // 3958 Pop macro stack
+  expand_macro_body (macro_record, arguments_container, &expanded);
+  debug ("MACROBODY: %s||||||", expanded.text);
+
+  if (expanded.end > 0 && expanded.text[expanded.end - 1] == '\n')
+    expanded.text[--expanded.end] = '\0';
 
   macro_source_mark = new_source_mark (SM_type_macro_expansion);
   macro_source_mark->status = SM_status_start;
@@ -672,6 +671,8 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
 
   /* Put expansion in front of the current line. */
   input_push_text (strdup (line), current_source_info.line_nr, 0, 0);
+  /* not really important as line is ignored by the caller if there
+     was no macro expansion error */
   line = strchr (line, '\0');
   if (expanded.text)
     expanded_macro_text = expanded.text;
@@ -685,7 +686,7 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
  funexit:
 
   *line_inout = line;
-  return current;
+  return error;
 }
 
 
diff --git a/tp/Texinfo/XS/parsetexi/macro.h b/tp/Texinfo/XS/parsetexi/macro.h
index 784a3ca497..67867d9991 100644
--- a/tp/Texinfo/XS/parsetexi/macro.h
+++ b/tp/Texinfo/XS/parsetexi/macro.h
@@ -34,8 +34,8 @@ typedef struct {
 void new_macro (char *name, ELEMENT *macro);
 ELEMENT *parse_macro_command_line (enum command_id, char **line_inout,
                                    ELEMENT *parent);
-ELEMENT *handle_macro (ELEMENT *current, char **line_inout,
-                       enum command_id cmd_id);
+int handle_macro (ELEMENT *current, char **line_inout,
+                  enum command_id cmd_id);
 void delete_macro (char *name);
 MACRO *lookup_macro (enum command_id cmd);
 void wipe_macros (void);
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index fd0ec7df00..211a4c2180 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1683,11 +1683,16 @@ process_remaining_on_line (ELEMENT **current_inout, 
char **line_inout)
   if (cmd && (command_data(cmd).flags & CF_MACRO))
     {
       static char *allocated_line;
+      int expansion_error;
+
       line = line_after_command;
-      current = handle_macro (current, &line, cmd);
-      free (allocated_line);
-      allocated_line = next_text (current);
-      line = allocated_line;
+      expansion_error = handle_macro (current, &line, cmd);
+      if (!expansion_error)
+        {
+          free (allocated_line);
+          allocated_line = next_text (current);
+          line = allocated_line;
+        }
       retval = STILL_MORE_TO_PROCESS;
       goto funexit;
     }
diff --git a/tp/t/results/macro/glossary.pl b/tp/t/results/macro/glossary.pl
index 456d9df84f..b6c61acd4c 100644
--- a/tp/t/results/macro/glossary.pl
+++ b/tp/t/results/macro/glossary.pl
@@ -1571,7 +1571,9 @@ $result_trees{'glossary'} = {
               'status' => 'start'
             }
           ],
-          'text' => ''
+          'text' => '
+',
+          'type' => 'empty_line'
         },
         {
           'text' => ' ',
@@ -1724,6 +1726,7 @@ text2
 
 @node glossary
 @chapter glossary
+
  name2 @anchor{id2}
 text2
 
@@ -1747,6 +1750,7 @@ id2
 
 1 glossary
 **********
+
 name2 text2
 
 
diff --git a/tp/t/results/macro/line_after_recursive_call.pl 
b/tp/t/results/macro/line_after_recursive_call.pl
index 6d3f36309a..569e79c6b0 100644
--- a/tp/t/results/macro/line_after_recursive_call.pl
+++ b/tp/t/results/macro/line_after_recursive_call.pl
@@ -93,6 +93,10 @@ $result_trees{'line_after_recursive_call'} = {
           'contents' => [
             {
               'text' => 'ggg
+'
+            },
+            {
+              'text' => ' xxx
 '
             },
             {
@@ -122,10 +126,12 @@ ggg
 fff
 @end macro
 ggg
+ xxx
 fff';
 
 
 $result_texts{'line_after_recursive_call'} = 'ggg
+ xxx
 fff';
 
 $result_errors{'line_after_recursive_call'} = [



reply via email to

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