texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Distinguish input text macro context and input te


From: Patrice Dumas
Subject: branch master updated: Distinguish input text macro context and input text macro expansion
Date: Sat, 15 Jul 2023 06:03:07 -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 fd581ca402 Distinguish input text macro context and input text macro 
expansion
fd581ca402 is described below

commit fd581ca40266f094b87cfdf5ce4bb33b49ef5d17
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Jul 15 12:02:57 2023 +0200

    Distinguish input text macro context and input text macro expansion
    
    * tp/Texinfo/ParserNonXS.pm (_input_push_text, _next_text)
    (_process_remaining_on_line), tp/Texinfo/XS/parsetexi/input.c
    (next_text, input_push_text), tp/Texinfo/XS/parsetexi/parser.c
    (process_remaining_on_line): the macro name passed to
    input_push_text means that the text comes from macro expansion.
    The input stack is used to determine if alreay in macro context.
---
 ChangeLog                        | 11 +++++++++++
 tp/Texinfo/ParserNonXS.pm        | 28 ++++++++++++++++++++--------
 tp/Texinfo/XS/parsetexi/input.c  | 38 +++++++++++++++++++++++++++++---------
 tp/Texinfo/XS/parsetexi/input.h  |  2 +-
 tp/Texinfo/XS/parsetexi/parser.c |  6 ++----
 tp/t/70value_and_macro.t         |  1 +
 6 files changed, 64 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1b2f211cb0..0c35d5263b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2023-07-15  Patrice Dumas  <pertusus@free.fr>
+
+       Distinguish input text macro context and input text macro expansion
+
+       * tp/Texinfo/ParserNonXS.pm (_input_push_text, _next_text)
+       (_process_remaining_on_line), tp/Texinfo/XS/parsetexi/input.c
+       (next_text, input_push_text), tp/Texinfo/XS/parsetexi/parser.c
+       (process_remaining_on_line): the macro name passed to
+       input_push_text means that the text comes from macro expansion.
+       The input stack is used to determine if alreay in macro context.
+
 2023-07-14  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/ParserNonXS.pm (_parse_macro_command_line)
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 558f1a6a10..9e1474d6d6 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -686,6 +686,13 @@ sub _new_text_input($$)
           'input_source_info' => $input_source_info};
 }
 
+# Store $TEXT as a source for Texinfo content.
+# $MACRO_name is the name of the macro expanded as text.  It should only
+# be given if this is the text corresponds to a new macro expansion.
+# If already within a macro expansion, but not from a macro expansion
+# (from a value expansion, for instance), the macro name will be taken
+# from the input stack.
+# $VALUE_FLAG is the name of the value flag expanded as text.
 sub _input_push_text($$$;$$)
 {
   my ($self, $text, $line_nr, $macro_name, $value_name) = @_;
@@ -698,16 +705,23 @@ sub _input_push_text($$$;$$)
   if (scalar(@{$self->{'input'}})) {
     $input_source_info->{'file_name'}
       = $self->{'input'}->[0]->{'input_source_info'}->{'file_name'};
+    # context macro expansion
+    $input_source_info->{'macro'}
+      = $self->{'input'}->[0]->{'input_source_info'}->{'macro'};
   }
   if (defined($macro_name) and $macro_name ne '') {
+    # new macro expansion
     $input_source_info->{'macro'} = $macro_name;
-  } elsif (not defined($value_name)) {
+  }
+  if (not defined($value_name) and $input_source_info->{'macro'} eq '') {
     # this counteracts the increment that would follow from the next
     # call to _next_text.
     $input_source_info->{'line_nr'} -= 1;
   }
   my $text_input = _new_text_input($text, $input_source_info);
   $text_input->{'value_flag'} = $value_name if (defined($value_name));
+  # only set for new macro expansion
+  $text_input->{'macro_name'} = $macro_name if (defined($macro_name));
   unshift @{$self->{'input'}}, $text_input;
 }
 
@@ -2397,10 +2411,10 @@ sub _next_text($;$)
         warn "BUG? close text reference failed: $error_message\n";
       }
       delete $input->{'th'};
-      if ($input->{'input_source_info'}->{'macro'} ne '') {
-        $self->{'macro_expansion_nr'}--;
-      } elsif (defined($input->{'value_flag'})) {
+      if (defined($input->{'value_flag'})) {
         $self->{'value_expansion_nr'}--;
+      } elsif (defined($input->{'macro_name'})) {
+        $self->{'macro_expansion_nr'}--;
       }
     } elsif ($input->{'fh'}) {
       # Don't close STDIN
@@ -6653,11 +6667,9 @@ sub _process_remaining_on_line($$$$)
             # goto funexit;  # used in XS code
           }
           $self->{'value_expansion_nr'}++;
-          _input_push_text($self, $remaining_line, $source_info->{'line_nr'},
-                           $source_info->{'macro'});
+          _input_push_text($self, $remaining_line, $source_info->{'line_nr'});
           _input_push_text($self, $self->{'values'}->{$value},
-                           $source_info->{'line_nr'},
-                           $source_info->{'macro'}, $value);
+                           $source_info->{'line_nr'}, undef, $value);
           my $sm_value_element = _new_value_element($command, $value);
           my $value_source_mark = {'sourcemark_type' => 'value_expansion',
                                    'status' => 'start',
diff --git a/tp/Texinfo/XS/parsetexi/input.c b/tp/Texinfo/XS/parsetexi/input.c
index 11d510584c..2b44549be0 100644
--- a/tp/Texinfo/XS/parsetexi/input.c
+++ b/tp/Texinfo/XS/parsetexi/input.c
@@ -53,6 +53,8 @@ typedef struct {
                     into lines. */
     char *value_flag; /* value flag if the input text is a @value
                          expansion */
+    char *macro_name; /* macro name if the input text is a user-defined
+                        macro expansion */
     SOURCE_MARK *input_source_mark;
 } INPUT;
 
@@ -517,8 +519,10 @@ next_text (ELEMENT *current)
               value_expansion_nr--;
               free (input->value_flag);
             }
-          else if (input->source_info.macro)
-            macro_expansion_nr--;
+          else if (input->macro_name)
+            {
+              macro_expansion_nr--;
+            }
         }
 
       if (input->input_source_mark)
@@ -551,11 +555,20 @@ next_text (ELEMENT *current)
 
 /* Store TEXT as a source for Texinfo content.  TEXT should be a UTF-8
    string.  TEXT will be later free'd and must be allocated on the heap.
-   MACRO is the name of a macro that the text came from. */
+   MACRO_NAME is the name of the macro expanded as text.  It should only be
+   given if this is the text corresponds to a new macro expansion.
+   If already within a macro expansion, but not from a macro expansion
+   (from a value expansion, for instance), the macro name will be taken
+   from the input stack.
+   VALUE_FLAG is the name of the value flag expanded as text.
+   VALUE_FLAG will be later free'd, but not MACRO_NAME.
+ */
 void
-input_push_text (char *text, int line_number, char *macro, char *value_flag)
+input_push_text (char *text, int line_number, char *macro_name,
+                 char *value_flag)
 {
   char *filename = 0;
+  char *in_macro = 0;
 
   if (!text)
     return;
@@ -574,17 +587,24 @@ input_push_text (char *text, int line_number, char 
*macro, char *value_flag)
   input_stack[input_number].text = text;
   input_stack[input_number].ptext = text;
 
-  if (!macro && !value_flag)
-    line_number--;
-  input_stack[input_number].source_info.line_nr = line_number;
   if (input_number > 0)
     {
       filename = input_stack[input_number - 1].source_info.file_name;
+      /* context macro expansion */
+      in_macro = input_stack[input_number - 1].source_info.macro;
     }
+  if (macro_name) {
+    /* new macro expansion */
+    in_macro = macro_name;
+  }
+  if (!in_macro && !value_flag)
+    line_number--;
+  input_stack[input_number].source_info.line_nr = line_number;
   input_stack[input_number].source_info.file_name = save_string (filename);
-  input_stack[input_number].source_info.macro = save_string (macro);
-  input_stack[input_number].input_source_mark = 0;
+  input_stack[input_number].source_info.macro = save_string (in_macro);
+  input_stack[input_number].macro_name = save_string (macro_name);
   input_stack[input_number].value_flag = value_flag;
+  input_stack[input_number].input_source_mark = 0;
   input_number++;
 }
 
diff --git a/tp/Texinfo/XS/parsetexi/input.h b/tp/Texinfo/XS/parsetexi/input.h
index c56a900c86..1749660e3a 100644
--- a/tp/Texinfo/XS/parsetexi/input.h
+++ b/tp/Texinfo/XS/parsetexi/input.h
@@ -9,7 +9,7 @@ char *next_text (ELEMENT *current);
 
 void save_line_directive (int line_nr, char *filename);
 
-void input_push_text (char *text, int line_number, char *macro,
+void input_push_text (char *text, int line_number, char *macro_name,
                       char *value_flag);
 int input_push_file (char *filename);
 void input_pushback (char *line);
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index f54216bab8..938dff77a7 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1808,11 +1808,9 @@ process_remaining_on_line (ELEMENT **current_inout, char 
**line_inout)
                         }
 
                       input_push_text (strdup (remaining_line),
-                                       current_source_info.line_nr,
-                                       current_source_info.macro, 0);
+                                       current_source_info.line_nr, 0, 0);
                       input_push_text (strdup (value),
-                                       current_source_info.line_nr,
-                                       current_source_info.macro,
+                                       current_source_info.line_nr, 0,
                                        strdup (flag));
 
                       value_source_mark
diff --git a/tp/t/70value_and_macro.t b/tp/t/70value_and_macro.t
index 1a8560e532..d530646a46 100644
--- a/tp/t/70value_and_macro.t
+++ b/tp/t/70value_and_macro.t
@@ -17,6 +17,7 @@ b
 
 flagab: @value{flagab}
 '],
+# NOTE this tests more generally value in macro argument, not in any other test
 ['comma_value_in_macro_arg',
 '@set comma ,
 



reply via email to

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