texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Expand @value before processing the remaining of


From: Patrice Dumas
Subject: branch master updated: Expand @value before processing the remaining of the line
Date: Sun, 28 Aug 2022 09:26:52 -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 4c95e752da Expand @value before processing the remaining of the line
4c95e752da is described below

commit 4c95e752da9aea9c18fa8e1452d49d3c9cbffbed
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 28 15:16:41 2022 +0200

    Expand @value before processing the remaining of the line
    
    * tp/Texinfo/ParserNonXS.pm (_parse_texi),
    tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line):
    expand @value that is actually expanded earlier, where macros are
    expanded as it may modify the line.
---
 ChangeLog                                |  9 +++++
 tp/Texinfo/ParserNonXS.pm                | 63 +++++++++++++++++++++++++++-----
 tp/Texinfo/XS/parsetexi/parser.c         | 58 ++++++++++++++++++++++++-----
 tp/t/results/value/value_after_accent.pl | 60 ++++++++++++++++--------------
 4 files changed, 142 insertions(+), 48 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6031f61140..8098585640 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2022-08-28  Patrice Dumas  <pertusus@free.fr>
+
+       Expand @value before processing the remaining of the line
+
+       * tp/Texinfo/ParserNonXS.pm (_parse_texi),
+       tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line):
+       expand @value that is actually expanded earlier, where macros are
+       expanded as it may modify the line.
+
 2022-08-28  Gavin Smith  <gavinsmith0123@gmail.com>
 
        * doc/texinfo.texi (@group): Revise.  Remove or comment out
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index f472b2b645..a08cf41570 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -4083,7 +4083,7 @@ sub _parse_texi($$$)
       my @line_parsing = _parse_texi_regex($line);
       my ($at_command, $open_brace, $asterisk, $single_letter_command,
         $separator_match, $misc_text) = @line_parsing;
-      print STDERR "PARSED: ".join(', ', map {!defined($_) ? 'UNDEF' : $_} 
@line_parsing)."\n"
+      print STDERR "PARSED: ".join(', ', map {!defined($_) ? 'UNDEF' : "'$_'"} 
@line_parsing)."\n"
         if ($self->{'DEBUG'});
 
       my $command;
@@ -4201,18 +4201,57 @@ sub _parse_texi($$$)
           unshift @{$self->{'input'}->[0]->{'pending'}}, @$new_lines;
           next;
         }
+        # expand value if it can change the line.  It considered again
+        # together with other commands below for all the other cases
+        # which may need a well formed tree, which is not needed here, and
+        # early value expansion may be needed to provide with an argument.
+        if ($command eq 'value') {
+          my $expanded_line = $line;
+          substr($expanded_line, 0, $at_command_length) = '';
+          $expanded_line =~ s/^\s*//
+             if ($self->{'IGNORE_SPACE_AFTER_BRACED_COMMAND_NAME'});
+          # REVALUE
+          if ($expanded_line =~ s/^{([\w\-][^\s{\\}~`\^+"<>|@]*)}//) {
+            my $value = $1;
+            if (exists($self->{'values'}->{$value})) {
+              $line = $self->{'values'}->{$value} . $expanded_line;
+              next;
+            }
+          }
+        }
       }
+
+      # this situation arises when after the $current->{'cmdname'}
+      # command but before an opening brace, otherwise $current
+      # would be an argument type and not the command, and a new
+      # @-command was found.  This means that the $current->{'cmdname'}
+      # argument (an opening brace, or a character after spaces for
+      # accent commands) was not found and there is already a new command.
+      #
+      # It would have been nice to allow for comments, but there is no
+      # container in the tree to put them when after command and before brace
+      # or argument for accent commands.
+      #
+      # TODO stop the brace command
+      #if ($command
+      #    and $current->{'cmdname'}
+      #    and defined($brace_commands{$current->{'cmdname'}})) {
+      #  #print STDERR "AAA \@$command \@$current->{'cmdname'}\n";
+      #}
+
       # Brace commands not followed immediately by a brace
       # opening.  In particular cases that may lead to "command closing"
       # or following character association with an @-command, for accent
       # commands.
 
-      # The condition below is only caught right after command opening,
-      # otherwise we are in the 'args' and not right in the command container.
+      # This condition can only happen immediately after the command opening,
+      # otherwise the current element is in the 'args' and not right in the
+      # command container.
+      # TODO add and !$command?
       if ($current->{'cmdname'}
             and defined($brace_commands{$current->{'cmdname'}})
             and !$open_brace) {
-        print STDERR "BRACE CMD \@$current->{'cmdname'}, no following brace\n"
+        print STDERR "BRACE CMD: no brace after \@$current->{'cmdname'}: $line"
           if $self->{'DEBUG'};
         # special case for @-command as argument of @itemize or @*table.
         if (_command_with_command_as_argument($current->{'parent'})) {
@@ -4238,27 +4277,31 @@ sub _parse_texi($$$)
                $current->{'cmdname'}), $source_info);
             $additional_newline = 1;
           }
-          print STDERR "BRACE CMD following command space ignored 
'$added_space'\n"
-            if $self->{'DEBUG'};
           if (!defined($current->{'extra'}->{'spaces'})) {
             $line =~ s/^(\s+)//;
             $current->{'extra'}->{'spaces'} = $added_space;
+            print STDERR "BRACE CMD before brace init spaces '$added_space'\n"
+              if $self->{'DEBUG'};
           # only ignore spaces and one newline, two newlines lead to
           # an empty line before the brace or argument which is incorrect.
           } elsif ($additional_newline
                    and $current->{'extra'}->{'spaces'} =~ /\n/) {
+            print STDERR "BRACE CMD before brace second newline stops spaces\n"
+              if $self->{'DEBUG'};
             $self->_line_error(sprintf(__("\@%s expected braces"),
                                $current->{'cmdname'}), $source_info);
             $current = $current->{'parent'};
           } else {
             $line =~ s/^(\s+)//;
             $current->{'extra'}->{'spaces'} .= $added_space;
+            print STDERR "BRACE CMD before brace add spaces '$added_space'\n"
+              if $self->{'DEBUG'};
           }
         # special case for accent commands, use following character except @
         # as argument
         } elsif ($accent_commands{$current->{'cmdname'}}
                  and $line =~ s/^([^@])//) {
-          print STDERR "ACCENT \@$current->{'cmdname'}\n"
+          print STDERR "ACCENT following_arg \@$current->{'cmdname'}\n"
             if ($self->{'DEBUG'});
           my $following_arg = {'type' => 'following_arg',
                                'parent' => $current};
@@ -4398,9 +4441,7 @@ sub _parse_texi($$$)
           if ($line =~ s/^{([\w\-][^\s{\\}~`\^+"<>|@]*)}//) {
             my $value = $1;
             if ($command eq 'value') {
-              if (exists($self->{'values'}->{$value})) {
-                $line = $self->{'values'}->{$value} . $line;
-              } else {
+              if (not exists($self->{'values'}->{$value})) {
                 _abort_empty_line($self, $current);
                 # caller should expand something along
                 # gdt('@{No value for `{value}\'@}', {'value' => $value}, 
{'keep_texi'=> 1});
@@ -4410,6 +4451,8 @@ sub _parse_texi($$$)
                                                   'parent' => $current };
                 $self->_line_warn(
                    sprintf(__("undefined flag: %s"), $value), $source_info);
+              # expansion of value already done above
+              #} else {
               }
             } else {
               # txiinternalvalue
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index c6839bf72f..992f3f4050 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1398,7 +1398,7 @@ superfluous_arg:
         cmd = command_data(cmd).data;
     }
 
-  /* Handle user-defined macros before anything else because their expansion 
+  /* Handle user-defined macros before anything else because their expansion
      may lead to changes in the line. */
   if (cmd && (command_data(cmd).flags & CF_MACRO))
     {
@@ -1408,16 +1408,55 @@ superfluous_arg:
       free (allocated_line);
       allocated_line = next_text ();
       line = allocated_line;
+      retval = STILL_MORE_TO_PROCESS;
+      goto funexit;
+    }
+  /* expand value if it actually expands and changes the line.  It is
+     considered again together with other commands below for all the other 
cases
+     which may need a well formed tree, which is not needed nor available here,
+     and early value expansion may be needed to provide with an argument. */
+  else if (cmd == CM_value)
+    {
+      char *expanded_line = line_after_command;
+      if (conf.ignore_space_after_braced_command_name)
+        expanded_line += strspn (expanded_line, whitespace_chars);
+      if (*expanded_line == '{')
+        {
+          char *flag;
+
+          expanded_line++;
+          flag = read_flag_name (&expanded_line);
+          if (flag)
+            {
+              if (*expanded_line == '}')
+                {
+                  char *value;
+                  value = fetch_value (flag);
+
+                  if (value)
+                    {
+                      expanded_line++; /* past '}' */
+                      input_push_text (strdup (expanded_line), 
current_source_info.macro);
+                      input_push_text (strdup (value), 
current_source_info.macro);
+                      line = expanded_line + strlen (expanded_line);
+                      retval = STILL_MORE_TO_PROCESS;
+                    }
+                  free (flag);
+                  if (value)
+                    goto funexit;
+                }
+            }
+        }
     }
 
   /* Brace commands not followed immediately by a brace
      opening.  In particular cases that may lead to "command closing"
      or following character association with an @-command, for accent
      commands */
-  /* This condition is only checked immediately after the command opening, 
-     otherwise the current element is in the 'args' and not right in the 
+  /* This condition can only happen immediately after the command opening,
+     otherwise the current element is in the 'args' and not right in the
      command container. */
-  else if (command_flags(current) & CF_brace && *line != '{')
+  if (command_flags(current) & CF_brace && *line != '{')
     {
       if (command_with_command_as_argument (current->parent))
         {
@@ -1535,7 +1574,8 @@ superfluous_arg:
         {
           char *arg_start;
           char *flag;
-          line += strspn (line, whitespace_chars);
+          if (conf.ignore_space_after_braced_command_name)
+            line += strspn (line, whitespace_chars);
           if (*line != '{')
             goto value_invalid;
 
@@ -1582,14 +1622,12 @@ value_valid:
                       line++; /* past '}' */
                       retval = STILL_MORE_TO_PROCESS;
                     }
+                   /* expansion of value already done above
                   else
                     {
-                      line++; /* past '}' */
-                      input_push_text (strdup (line), 
current_source_info.macro);
-                      input_push_text (strdup (value), 
current_source_info.macro);
-                      line += strlen (line);
-                      retval = STILL_MORE_TO_PROCESS;
+                      value is set
                     }
+                    */
                   free (flag);
                   goto funexit;
                 }
diff --git a/tp/t/results/value/value_after_accent.pl 
b/tp/t/results/value/value_after_accent.pl
index f509227585..0a1ab6ed03 100644
--- a/tp/t/results/value/value_after_accent.pl
+++ b/tp/t/results/value/value_after_accent.pl
@@ -36,6 +36,18 @@ $result_trees{'value_after_accent'} = {
         {
           'contents' => [
             {
+              'args' => [
+                {
+                  'contents' => [
+                    {
+                      'parent' => {},
+                      'text' => 'a'
+                    }
+                  ],
+                  'parent' => {},
+                  'type' => 'following_arg'
+                }
+              ],
               'cmdname' => 'ringaccent',
               'contents' => [],
               'extra' => {
@@ -50,10 +62,22 @@ $result_trees{'value_after_accent'} = {
             },
             {
               'parent' => {},
-              'text' => 'a
+              'text' => '
 '
             },
             {
+              'args' => [
+                {
+                  'contents' => [
+                    {
+                      'parent' => {},
+                      'text' => 'a'
+                    }
+                  ],
+                  'parent' => {},
+                  'type' => 'following_arg'
+                }
+              ],
               'cmdname' => '~',
               'contents' => [],
               'parent' => {},
@@ -62,10 +86,6 @@ $result_trees{'value_after_accent'} = {
                 'line_nr' => 3,
                 'macro' => ''
               }
-            },
-            {
-              'parent' => {},
-              'text' => 'a'
             }
           ],
           'parent' => {},
@@ -81,10 +101,13 @@ $result_trees{'value_after_accent'} = {
 
$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[0]{'args'}[0]{'parent'}
 = $result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[0];
 
$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[0]{'args'}[1]{'parent'}
 = $result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[0];
 $result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[0]{'parent'} = 
$result_trees{'value_after_accent'}{'contents'}[0];
+$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[0]{'args'}[0]{'contents'}[0]{'parent'}
 = 
$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[0]{'args'}[0];
+$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[0]{'args'}[0]{'parent'}
 = 
$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[0];
 
$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[0]{'parent'}
 = $result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1];
 
$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[1]{'parent'}
 = $result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1];
+$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[2]{'args'}[0]{'contents'}[0]{'parent'}
 = 
$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[2]{'args'}[0];
+$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[2]{'args'}[0]{'parent'}
 = 
$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[2];
 
$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[2]{'parent'}
 = $result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1];
-$result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'contents'}[3]{'parent'}
 = $result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1];
 $result_trees{'value_after_accent'}{'contents'}[0]{'contents'}[1]{'parent'} = 
$result_trees{'value_after_accent'}{'contents'}[0];
 $result_trees{'value_after_accent'}{'contents'}[0]{'parent'} = 
$result_trees{'value_after_accent'};
 
@@ -93,29 +116,10 @@ $result_texis{'value_after_accent'} = '@set a_letter a
 @~a';
 
 
-$result_texts{'value_after_accent'} = '*a
-~a';
+$result_texts{'value_after_accent'} = 'a*
+a~';
 
-$result_errors{'value_after_accent'} = [
-  {
-    'error_line' => '@ringaccent expected braces
-',
-    'file_name' => '',
-    'line_nr' => 2,
-    'macro' => '',
-    'text' => '@ringaccent expected braces',
-    'type' => 'error'
-  },
-  {
-    'error_line' => '@~ expected braces
-',
-    'file_name' => '',
-    'line_nr' => 3,
-    'macro' => '',
-    'text' => '@~ expected braces',
-    'type' => 'error'
-  }
-];
+$result_errors{'value_after_accent'} = [];
 
 
 $result_floats{'value_after_accent'} = {};



reply via email to

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