texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Handle indicatric command on table line before un


From: Patrice Dumas
Subject: branch master updated: Handle indicatric command on table line before unknown command
Date: Sun, 28 Aug 2022 12:45:36 -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 dfc14cabdf Handle indicatric command on table line before unknown 
command
dfc14cabdf is described below

commit dfc14cabdfb13c2c431fb3dacfd714e663f1fba6
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 28 18:44:06 2022 +0200

    Handle indicatric command on table line before unknown command
    
    * tp/Texinfo/ParserNonXS.pm (_parse_texi),
    tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line):
    associate indicatric command to the @*table before handling
    unknown command.
---
 ChangeLog                        |   9 +++
 tp/TODO                          |   2 +
 tp/Texinfo/ParserNonXS.pm        | 100 +++++++++++++-----------
 tp/Texinfo/XS/parsetexi/parser.c |  73 ++++++++++--------
 tp/t/02coverage.t                |   4 +
 tp/t/results/coverage/table.pl   | 162 ++++++++++++++++++++++++++++++++++++++-
 6 files changed, 276 insertions(+), 74 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ba12482533..2f58a309c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,15 @@
 
        * doc/texinfo.tex [e-TeX]: Set \lastlinefit to 500.
 
+2022-08-28  Patrice Dumas  <pertusus@free.fr>
+
+       Handle indicatric command on table line before unknown command
+
+       * tp/Texinfo/ParserNonXS.pm (_parse_texi),
+       tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line):
+       associate indicatric command to the @*table before handling
+       unknown command.
+
 2022-08-28  Patrice Dumas  <pertusus@free.fr>
 
        Expand @value before processing the remaining of the line
diff --git a/tp/TODO b/tp/TODO
index 4a85dbb023..e45239526b 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -15,6 +15,8 @@ Bugs
 
 form feeds results
 
+@' @unknown a
+
 HTML API
 ========
 
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index a08cf41570..38df6a910e 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -4093,24 +4093,6 @@ sub _parse_texi($$$)
         $at_command_length = length($at_command) + 1;
         $command = $at_command;
 
-        # handle unknown @-command
-        if (!$all_commands{$command}
-            and !$self->{'macros'}->{$command}
-            and !$self->{'definfoenclose'}->{$command}
-            and !$self->{'aliases'}->{$command}
-            and !$self->{'command_index'}->{$command}
-            # @txiinternalvalue is invalid unless accept_internalvalue is set
-            and !($command eq 'txiinternalvalue'
-                  and $self->{'accept_internalvalue'})) {
-          $self->_line_error(sprintf(__("unknown command `%s'"),
-                                      $command), $source_info);
-          substr($line, 0, $at_command_length) = '';
-          _abort_empty_line($self, $current);
-          my $paragraph = _begin_paragraph($self, $current, $source_info);
-          $current = $paragraph if ($paragraph);
-          next;
-        }
-
         my $alias_command;
         if (exists($self->{'aliases'}->{$command})) {
           $alias_command = $command;
@@ -4219,6 +4201,46 @@ sub _parse_texi($$$)
             }
           }
         }
+          #substr($line, 0, $at_command_length) = '';
+      }
+
+      # special case for @-command as argument of @itemize or @*table.
+      # The normal case for those are to be identifier only, not a true command
+      # with argument, so can be followed by anything.  If followed by
+      # braces, will be handled as a normal brace command.
+      #
+      # Need to be done as early as possible such that no other condition
+      # prevail and lead to a missed command
+      if ($current->{'cmdname'}
+          and defined($brace_commands{$current->{'cmdname'}})
+          and !$open_brace
+          and _command_with_command_as_argument($current->{'parent'})) {
+        print STDERR "FOR PARENT 
\@$current->{'parent'}->{'parent'}->{'cmdname'} ".
+               "command_as_argument $current->{'cmdname'}\n" if 
($self->{'DEBUG'});
+        $current->{'type'} = 'command_as_argument' if (!$current->{'type'});
+        $current->{'parent'}->{'parent'}->{'extra'}->{'command_as_argument'}
+          = $current;
+        if ($current->{'cmdname'} eq 'kbd'
+            and _kbd_formatted_as_code($self, 
$current->{'parent'}->{'parent'})) {
+          
$current->{'parent'}->{'parent'}->{'extra'}->{'command_as_argument_kbd_code'} = 
1;
+        }
+        $current = $current->{'parent'};
+      }
+
+      # handle unknown @-command
+      if ($command and !$all_commands{$command}
+          and !$self->{'definfoenclose'}->{$command}
+          and !$self->{'command_index'}->{$command}
+          # @txiinternalvalue is invalid unless accept_internalvalue is set
+          and !($command eq 'txiinternalvalue'
+                and $self->{'accept_internalvalue'})) {
+        $self->_line_error(sprintf(__("unknown command `%s'"),
+                                      $command), $source_info);
+        substr($line, 0, $at_command_length) = '';
+        _abort_empty_line($self, $current);
+        my $paragraph = _begin_paragraph($self, $current, $source_info);
+        $current = $paragraph if ($paragraph);
+        next;
       }
 
       # this situation arises when after the $current->{'cmdname'}
@@ -4231,13 +4253,15 @@ sub _parse_texi($$$)
       # 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";
-      #}
+      # FIXME this is sort of a duplicate of what is happening later
+      # with the condition of !$open_brace.  It could allow for more
+      # precise error messages.
+      if ($command
+          and $current->{'cmdname'}
+          and defined($brace_commands{$current->{'cmdname'}})) {
+        $self->_line_error(sprintf(__("\@%s expected braces"),
+                           $current->{'cmdname'}), $source_info);
+        $current = $current->{'parent'};
 
       # Brace commands not followed immediately by a brace
       # opening.  In particular cases that may lead to "command closing"
@@ -4247,28 +4271,16 @@ sub _parse_texi($$$)
       # 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'}
+      } elsif ($current->{'cmdname'}
+      #if ($current->{'cmdname'}
             and defined($brace_commands{$current->{'cmdname'}})
             and !$open_brace) {
         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'})) {
-          print STDERR "FOR PARENT 
\@$current->{'parent'}->{'parent'}->{'cmdname'} ".
-                 "command_as_argument $current->{'cmdname'}\n" if 
($self->{'DEBUG'});
-          $current->{'type'} = 'command_as_argument' if (!$current->{'type'});
-          $current->{'parent'}->{'parent'}->{'extra'}->{'command_as_argument'}
-            = $current;
-          if ($current->{'cmdname'} eq 'kbd'
-              and _kbd_formatted_as_code($self, 
$current->{'parent'}->{'parent'})) {
-            
$current->{'parent'}->{'parent'}->{'extra'}->{'command_as_argument_kbd_code'} = 
1;
-          }
-          $current = $current->{'parent'};
         # Note that non ascii spaces do not count as spaces
-        } elsif ($line =~ /^(\s+)/
-                 and ($accent_commands{$current->{'cmdname'}}
-                      or $self->{'IGNORE_SPACE_AFTER_BRACED_COMMAND_NAME'})) {
+        if ($line =~ /^(\s+)/
+            and ($accent_commands{$current->{'cmdname'}}
+                 or $self->{'IGNORE_SPACE_AFTER_BRACED_COMMAND_NAME'})) {
           my $added_space = $1;
           my $additional_newline;
           if ($added_space =~ /\n/) {
@@ -4298,7 +4310,9 @@ sub _parse_texi($$$)
               if $self->{'DEBUG'};
           }
         # special case for accent commands, use following character except @
-        # as argument
+        # as argument.  Note that since we checked before that there isn't
+        # an @-command opening, there should not be an @ anyway.  The line
+        # may possibly be empty in some specific case, without end of line.
         } elsif ($accent_commands{$current->{'cmdname'}}
                  and $line =~ s/^([^@])//) {
           print STDERR "ACCENT following_arg \@$current->{'cmdname'}\n"
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 992f3f4050..8c7eb4add0 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1041,6 +1041,7 @@ process_remaining_on_line (ELEMENT **current_inout, char 
**line_inout)
   int retval = STILL_MORE_TO_PROCESS;
   enum command_id end_cmd;
   char *p;
+  int unknown_command = 0;
 
   enum command_id cmd = CM_NONE;
 
@@ -1368,23 +1369,12 @@ superfluous_arg:
           cmd = 0;
           if (command)
             {
-              ELEMENT *paragraph;
-
               cmd = lookup_command (command);
               if (!cmd)
                 {
                   line_error ("unknown command `%s'", command);
                   debug ("COMMAND (UNKNOWN) %s", command);
-                  free (command);
-
-                  abort_empty_line (&current, 0);
-                  paragraph = begin_paragraph (current);
-                  if (paragraph)
-                    current = paragraph;
-
-                  line = line_after_command;
-                  retval = STILL_MORE_TO_PROCESS;
-                  goto funexit;
+                  unknown_command = 1;
                 }
               free (command);
             }
@@ -1415,7 +1405,7 @@ superfluous_arg:
      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)
+  else if (cmd && cmd == CM_value)
     {
       char *expanded_line = line_after_command;
       if (conf.ignore_space_after_braced_command_name)
@@ -1449,6 +1439,45 @@ superfluous_arg:
         }
     }
 
+  /* special case for @-command as argument of @itemize or @*table.
+     The normal case for those are to be identifier only, not a true command
+     with argument, so can be followed by anything.  If followed by
+     braces, will be handled as a normal brace command.
+
+     Need to be done as early as possible such that no other condition
+     prevail and lead to a missed command */
+  if (command_flags(current) & CF_brace && *line != '{'
+      && command_with_command_as_argument (current->parent))
+    {
+      debug ("FOR PARENT @%s command_as_argument @%s",
+             command_name(current->parent->parent->cmd),
+             command_name(current->cmd));
+      if (!current->type)
+        current->type = ET_command_as_argument;
+      add_extra_element (current->parent->parent,
+                             "command_as_argument", current);
+      if (current->cmd == CM_kbd
+          && kbd_formatted_as_code(current->parent->parent)) {
+        add_extra_integer (current->parent->parent,
+                           "command_as_argument_kbd_code", 1);
+      }
+      current = current->parent;
+    }
+
+  if (unknown_command)
+    {
+      ELEMENT *paragraph;
+
+      abort_empty_line (&current, 0);
+      paragraph = begin_paragraph (current);
+      if (paragraph)
+        current = paragraph;
+
+      line = line_after_command;
+      retval = STILL_MORE_TO_PROCESS;
+      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
@@ -1458,23 +1487,7 @@ superfluous_arg:
      command container. */
   if (command_flags(current) & CF_brace && *line != '{')
     {
-      if (command_with_command_as_argument (current->parent))
-        {
-          debug ("FOR PARENT @%s command_as_argument @%s",
-                 command_name(current->parent->parent->cmd),
-                 command_name(current->cmd));
-          if (!current->type)
-            current->type = ET_command_as_argument;
-          add_extra_element (current->parent->parent,
-                                 "command_as_argument", current);
-          if (current->cmd == CM_kbd
-              && kbd_formatted_as_code(current->parent->parent)) {
-            add_extra_integer (current->parent->parent,
-                               "command_as_argument_kbd_code", 1);
-          }
-          current = current->parent;
-        }
-      else if (strchr (whitespace_chars, *line)
+      if (strchr (whitespace_chars, *line)
                && ((command_flags(current) & CF_accent)
                    || conf.ignore_space_after_braced_command_name))
         {
diff --git a/tp/t/02coverage.t b/tp/t/02coverage.t
index 1766f56ec7..85acd90803 100644
--- a/tp/t/02coverage.t
+++ b/tp/t/02coverage.t
@@ -144,6 +144,10 @@ In table
 @itemx itemx vtable @comment comment in itemx line
 
 @end vtable
+
+@table @strong@unknown
+@item unknown command after indicating command
+@end table
 '],
 ['table_command_comment',
 '@table @code@c in comment
diff --git a/tp/t/results/coverage/table.pl b/tp/t/results/coverage/table.pl
index 266508fe85..401b90bc62 100644
--- a/tp/t/results/coverage/table.pl
+++ b/tp/t/results/coverage/table.pl
@@ -518,6 +518,121 @@ $result_trees{'table'} = {
             'line_nr' => 9,
             'macro' => ''
           }
+        },
+        {
+          'parent' => {},
+          'text' => '
+',
+          'type' => 'empty_line'
+        },
+        {
+          'args' => [
+            {
+              'contents' => [
+                {
+                  'cmdname' => 'strong',
+                  'contents' => [],
+                  'parent' => {},
+                  'source_info' => {
+                    'file_name' => '',
+                    'line_nr' => 20,
+                    'macro' => ''
+                  },
+                  'type' => 'command_as_argument'
+                }
+              ],
+              'extra' => {
+                'spaces_after_argument' => '
+'
+              },
+              'parent' => {},
+              'type' => 'block_line_arg'
+            }
+          ],
+          'cmdname' => 'table',
+          'contents' => [
+            {
+              'contents' => [
+                {
+                  'contents' => [
+                    {
+                      'args' => [
+                        {
+                          'contents' => [
+                            {
+                              'parent' => {},
+                              'text' => 'unknown command after indicating 
command'
+                            }
+                          ],
+                          'extra' => {
+                            'spaces_after_argument' => '
+'
+                          },
+                          'parent' => {},
+                          'type' => 'line_arg'
+                        }
+                      ],
+                      'cmdname' => 'item',
+                      'extra' => {
+                        'spaces_before_argument' => ' '
+                      },
+                      'parent' => {},
+                      'source_info' => {
+                        'file_name' => '',
+                        'line_nr' => 21,
+                        'macro' => ''
+                      }
+                    }
+                  ],
+                  'parent' => {},
+                  'type' => 'table_term'
+                }
+              ],
+              'parent' => {},
+              'type' => 'table_entry'
+            },
+            {
+              'args' => [
+                {
+                  'contents' => [
+                    {
+                      'parent' => {},
+                      'text' => 'table'
+                    }
+                  ],
+                  'extra' => {
+                    'spaces_after_argument' => '
+'
+                  },
+                  'parent' => {},
+                  'type' => 'line_arg'
+                }
+              ],
+              'cmdname' => 'end',
+              'extra' => {
+                'command_argument' => 'table',
+                'spaces_before_argument' => ' ',
+                'text_arg' => 'table'
+              },
+              'parent' => {},
+              'source_info' => {
+                'file_name' => '',
+                'line_nr' => 22,
+                'macro' => ''
+              }
+            }
+          ],
+          'extra' => {
+            'command_as_argument' => {},
+            'end_command' => {},
+            'spaces_before_argument' => ' '
+          },
+          'parent' => {},
+          'source_info' => {
+            'file_name' => '',
+            'line_nr' => 20,
+            'macro' => ''
+          }
         }
       ],
       'parent' => {},
@@ -595,6 +710,20 @@ 
$result_trees{'table'}{'contents'}[0]{'contents'}[3]{'contents'}[2]{'parent'} =
 
$result_trees{'table'}{'contents'}[0]{'contents'}[3]{'extra'}{'command_as_argument'}
 = 
$result_trees{'table'}{'contents'}[0]{'contents'}[3]{'args'}[0]{'contents'}[0];
 $result_trees{'table'}{'contents'}[0]{'contents'}[3]{'extra'}{'end_command'} = 
$result_trees{'table'}{'contents'}[0]{'contents'}[3]{'contents'}[2];
 $result_trees{'table'}{'contents'}[0]{'contents'}[3]{'parent'} = 
$result_trees{'table'}{'contents'}[0];
+$result_trees{'table'}{'contents'}[0]{'contents'}[4]{'parent'} = 
$result_trees{'table'}{'contents'}[0];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'args'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'table'}{'contents'}[0]{'contents'}[5]{'args'}[0];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'args'}[0]{'parent'} = 
$result_trees{'table'}{'contents'}[0]{'contents'}[5];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[0]{'contents'}[0]{'contents'}[0]{'args'}[0]{'contents'}[0]{'parent'}
 = 
$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[0]{'contents'}[0]{'contents'}[0]{'args'}[0];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[0]{'contents'}[0]{'contents'}[0]{'args'}[0]{'parent'}
 = 
$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[0]{'contents'}[0]{'contents'}[0];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[0]{'contents'}[0]{'contents'}[0]{'parent'}
 = 
$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[0]{'contents'}[0];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[0];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[0]{'parent'} 
= $result_trees{'table'}{'contents'}[0]{'contents'}[5];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[1]{'args'}[0]{'contents'}[0]{'parent'}
 = 
$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[1]{'args'}[0];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[1]{'args'}[0]{'parent'}
 = $result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[1];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[1]{'parent'} 
= $result_trees{'table'}{'contents'}[0]{'contents'}[5];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'extra'}{'command_as_argument'}
 = 
$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'args'}[0]{'contents'}[0];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'extra'}{'end_command'} = 
$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'contents'}[1];
+$result_trees{'table'}{'contents'}[0]{'contents'}[5]{'parent'} = 
$result_trees{'table'}{'contents'}[0];
 $result_trees{'table'}{'contents'}[0]{'parent'} = $result_trees{'table'};
 
 $result_texis{'table'} = '
@@ -615,6 +744,10 @@ In table
 @itemx itemx vtable @comment comment in itemx line
 
 @end vtable
+
+@table @strong
+@item unknown command after indicating command
+@end table
 ';
 
 
@@ -628,6 +761,8 @@ In table
 vtable item
 itemx vtable
 
+
+unknown command after indicating command
 ';
 
 $result_errors{'table'} = [
@@ -666,6 +801,15 @@ $result_errors{'table'} = [
     'macro' => '',
     'text' => 'entry for index `vr\' outside of any node',
     'type' => 'warning'
+  },
+  {
+    'error_line' => 'unknown command `unknown\'
+',
+    'file_name' => '',
+    'line_nr' => 20,
+    'macro' => '',
+    'text' => 'unknown command `unknown\'',
+    'type' => 'error'
   }
 ];
 
@@ -696,6 +840,7 @@ table itemx
 ‘vtable item’
 ‘itemx vtable’
 
+*unknown command after indicating command*
 ';
 
 
@@ -717,6 +862,10 @@ $result_converted{'html_text'}->{'table'} = '
 </dd>
 <dt id=\'index-itemx-vtable\'><span>&lsquo;<samp class="samp">itemx 
vtable</samp>&rsquo;<a class="copiable-link" href=\'#index-itemx-vtable\'> 
&para;</a></span></dt>
 </dl>
+
+<dl class="table">
+<dt><strong class="strong">unknown command after indicating 
command</strong></dt>
+</dl>
 ';
 
 
@@ -738,6 +887,10 @@ $result_converted{'xml'}->{'table'} = '
 <itemx spaces=" "><itemformat command="samp"><indexterm index="vr" 
number="2">itemx vtable</indexterm>itemx vtable </itemformat></itemx><!-- 
comment comment in itemx line -->
 </tableterm><tableitem>
 </tableitem></tableentry></vtable>
+
+<table commandarg="strong" spaces=" " endspaces=" ">
+<tableentry><tableterm><item spaces=" "><itemformat command="strong">unknown 
command after indicating command</itemformat></item>
+</tableterm></tableentry></table>
 ';
 
 
@@ -761,6 +914,11 @@ In table
 \\index[vr]{itemx vtable@\\texttt{itemx vtable}}%
 }}]
 
+\\end{description}
+
+\\begin{description}
+\\item[{\\parbox[b]{\\linewidth}{%
+\\textbf{unknown command after indicating command}}}]
 \\end{description}
 ';
 
@@ -779,6 +937,8 @@ $result_converted{'docbook'}->{'table'} = '
 <indexterm role="ky"><primary>key</primary></indexterm>
 <term><indexterm role="vr"><primary>itemx 
vtable</primary></indexterm>&#8216;<literal>itemx vtable</literal>&#8217;
 </term><listitem>
-</listitem></varlistentry></variablelist>';
+</listitem></varlistentry></variablelist>
+<variablelist><varlistentry><term><emphasis role="bold">unknown command after 
indicating command</emphasis>
+</term></varlistentry></variablelist>';
 
 1;



reply via email to

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