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 (_register_command_as


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_register_command_as_argument) (_parent_of_command_as_argument, _process_remaining_on_line), tp/Texinfo/XS/parsetexi/parser.c (parent_of_command_as_argument) (register_command_as_argument, process_remaining_on_line), tp/Texinfo/XS/parsetexi/separator.c (handle_close_brace): use a function to register a command_as_argument. Rename command_with_command_as_argument as parent_of_command_as_argument.
Date: Sun, 18 Sep 2022 08:23:57 -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 4a53f77e41 * tp/Texinfo/ParserNonXS.pm (_register_command_as_argument) 
(_parent_of_command_as_argument, _process_remaining_on_line), 
tp/Texinfo/XS/parsetexi/parser.c (parent_of_command_as_argument) 
(register_command_as_argument, process_remaining_on_line), 
tp/Texinfo/XS/parsetexi/separator.c (handle_close_brace): use a function to 
register a command_as_argument.  Rename command_with_command_as_argument as 
parent_of_command_as_argument.
4a53f77e41 is described below

commit 4a53f77e410aa53d920c76fc9f65e3880128e529
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Sep 18 14:23:47 2022 +0200

    * tp/Texinfo/ParserNonXS.pm (_register_command_as_argument)
    (_parent_of_command_as_argument, _process_remaining_on_line),
    tp/Texinfo/XS/parsetexi/parser.c (parent_of_command_as_argument)
    (register_command_as_argument, process_remaining_on_line),
    tp/Texinfo/XS/parsetexi/separator.c (handle_close_brace):
    use a function to register a command_as_argument.  Rename
    command_with_command_as_argument as parent_of_command_as_argument.
    
    * tp/Texinfo/ParserNonXS.pm (_end_line): remove useless code and
    keys.
---
 ChangeLog                           | 13 +++++++
 tp/Texinfo/ParserNonXS.pm           | 74 +++++++++++++++++--------------------
 tp/Texinfo/XS/parsetexi/parser.c    | 40 ++++++++++++--------
 tp/Texinfo/XS/parsetexi/parser.h    |  3 +-
 tp/Texinfo/XS/parsetexi/separator.c | 13 +------
 5 files changed, 75 insertions(+), 68 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6a23481068..a19535dbe8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2022-09-18  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_register_command_as_argument)
+       (_parent_of_command_as_argument, _process_remaining_on_line),
+       tp/Texinfo/XS/parsetexi/parser.c (parent_of_command_as_argument)
+       (register_command_as_argument, process_remaining_on_line),
+       tp/Texinfo/XS/parsetexi/separator.c (handle_close_brace):
+       use a function to register a command_as_argument.  Rename
+       command_with_command_as_argument as parent_of_command_as_argument.
+
+       * tp/Texinfo/ParserNonXS.pm (_end_line): remove useless code and
+       keys.
+
 2022-09-18  Gavin Smith  <gavinsmith0123@gmail.com>
 
        * doc/texinfo.texi (Hardcopy with TeX, Generic Translator texi2any):
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index c9099da840..8e83716b7c 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -3030,11 +3030,8 @@ sub _end_line($$$)
         if ($content->{'type'} and $content->{'type'} eq 'bracketed') {
           my $bracketed_prototype
             = { 'type' => 'bracketed_multitable_prototype' };
-          if ($content->{'contents'}
-              and scalar(@{$content->{'contents'}}) > 0) {
-            # avoid empty content to match with XS parser.
-            $bracketed_prototype->{'contents'} = $content->{'contents'};
-          }
+          $bracketed_prototype->{'contents'} = $content->{'contents'}
+            if ($content->{'contents'});
           push @prototype_row, $bracketed_prototype;
         } elsif ($content->{'text'}) {
           # TODO: this should be a warning or an error - all prototypes
@@ -3070,11 +3067,6 @@ sub _end_line($$$)
     $current = $current->{'parent'};
     delete $current->{'remaining_args'};
 
-    # this is in particular to have the same output as the XS parser
-    if (scalar(@{$current->{'contents'}}) == 0) {
-      delete $current->{'contents'};
-    }
-
     # @float args
     if ($current->{'cmdname'} and $current->{'cmdname'} eq 'float') {
       $current->{'source_info'} = $source_info;
@@ -3092,6 +3084,7 @@ sub _end_line($$$)
         if (defined($self->{'current_section'}));
     }
 
+    # all the commands with @item
     if ($current->{'cmdname'}
           and $block_item_commands{$current->{'cmdname'}}) {
       if ($current->{'cmdname'} eq 'enumerate') {
@@ -3129,12 +3122,11 @@ sub _end_line($$$)
               $current->{'cmdname'});
           delete $current->{'extra'}->{'command_as_argument'};
         }
-      }
-      # This code checks that the command_as_argument of the @itemize
-      # is alone on the line, otherwise it is not a command_as_argument.
-      if ($current->{'extra'}
-          and $current->{'extra'}->{'command_as_argument'}
-          and $current->{'cmdname'} eq 'itemize') {
+      } elsif ($current->{'cmdname'} eq 'itemize'
+               and $current->{'extra'}
+               and $current->{'extra'}->{'command_as_argument'}) {
+        # This code checks that the command_as_argument of the @itemize
+        # is alone on the line, otherwise it is not a command_as_argument.
         my @args = @{$current->{'args'}->[0]->{'contents'}};
         while (@args) {
           my $arg = shift @args;
@@ -3196,7 +3188,7 @@ sub _end_line($$$)
         $current->{'extra'}->{'command_as_argument'} = $inserted;
       }
       push @{$current->{'contents'}}, { 'type' => 'before_item',
-         'contents' => [], 'parent', $current };
+                                        'parent', $current };
       $current = $current->{'contents'}->[-1];
     }
     if ($current->{'cmdname'} and $menu_commands{$current->{'cmdname'}}) {
@@ -3715,7 +3707,10 @@ sub _enter_menu_entry_node($$$)
   return $current;
 }
 
-sub _command_with_command_as_argument($)
+# If the container can hold a command as an argument, determined as
+# parent element taking a command as an argument, like
+# @itemize @bullet, and the command as argument being the only content.
+sub _parent_of_command_as_argument($)
 {
   my $current = shift;
   return ($current and $current->{'type'}
@@ -3727,6 +3722,22 @@ sub _command_with_command_as_argument($)
       and scalar(@{$current->{'contents'}}) == 1);
 }
 
+# register a command like @bullet with @itemize, or @asis with @table
+sub _register_command_as_argument($$)
+{
+  my $self = shift;
+  my $cmd_as_arg = shift;
+  print STDERR "FOR PARENT \@$cmd_as_arg->{'parent'}->{'parent'}->{'cmdname'} 
".
+         "command_as_argument $cmd_as_arg->{'cmdname'}\n" if 
($self->{'DEBUG'});
+  $cmd_as_arg->{'type'} = 'command_as_argument' if (!$cmd_as_arg->{'type'});
+  $cmd_as_arg->{'parent'}->{'parent'}->{'extra'}->{'command_as_argument'}
+    = $cmd_as_arg;
+  if ($cmd_as_arg->{'cmdname'} eq 'kbd'
+      and _kbd_formatted_as_code($self, $cmd_as_arg->{'parent'}->{'parent'})) {
+    
$cmd_as_arg->{'parent'}->{'parent'}->{'extra'}->{'command_as_argument_kbd_code'}
 = 1;
+  }
+}
+
 sub _is_index_element {
   my ($self, $element) = @_;
 
@@ -4184,16 +4195,8 @@ sub _process_remaining_on_line($$$$)
   if ($current->{'cmdname'}
       and defined($self->{'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;
-    }
+      and _parent_of_command_as_argument($current->{'parent'})) {
+    _register_command_as_argument($self, $current);
     $current = $current->{'parent'};
   }
 
@@ -5459,19 +5462,10 @@ sub _process_remaining_on_line($$$$)
                 $source_info);
             }
           }
-
-        } elsif 
(_command_with_command_as_argument($current->{'parent'}->{'parent'})
+          # first parent is the brace command
+        } elsif 
(_parent_of_command_as_argument($current->{'parent'}->{'parent'})
              and !$current->{'contents'}) {
-           print STDERR "FOR PARENT 
\@$current->{'parent'}->{'parent'}->{'parent'}->{'cmdname'} command_as_argument 
braces $current->{'parent'}->{'cmdname'}\n" if ($self->{'DEBUG'});
-           $current->{'parent'}->{'type'} = 'command_as_argument'
-              if (!$current->{'parent'}->{'type'});
-           
$current->{'parent'}->{'parent'}->{'parent'}->{'extra'}->{'command_as_argument'}
-              = $current->{'parent'};
-           if ($current->{'parent'}->{'cmdname'} eq 'kbd'
-               and _kbd_formatted_as_code($self,
-                                          
$current->{'parent'}->{'parent'}->{'parent'})) {
-             
$current->{'parent'}->{'parent'}->{'parent'}->{'extra'}->{'command_as_argument_kbd_code'}
 = 1;
-           }
+          _register_command_as_argument($self, $current->{'parent'});
         } elsif ($in_index_commands{$current->{'parent'}->{'cmdname'}}) {
           my $command = $current->{'parent'}->{'cmdname'};
 
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 048fd83f32..8956369a12 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -824,10 +824,11 @@ kbd_formatted_as_code (ELEMENT *current)
 }
 
 
-/* If the parent element takes a command as an argument, like
-   @itemize @bullet. */
+/* If the container can hold a command as an argument, determined as
+   parent element taking a command as an argument, like
+   @itemize @bullet, and the command as argument being the only content. */
 int
-command_with_command_as_argument (ELEMENT *current)
+parent_of_command_as_argument (ELEMENT *current)
 {
   return current->type == ET_block_line_arg
     && (current->parent->cmd == CM_itemize
@@ -835,6 +836,24 @@ command_with_command_as_argument (ELEMENT *current)
     && (current->contents.number == 1);
 }
 
+/* register a command like @bullet with @itemize, or @asis with @table */
+void
+register_command_as_argument (ELEMENT *cmd_as_arg)
+{
+  debug ("FOR PARENT @%s command_as_argument @%s",
+         command_name(cmd_as_arg->parent->parent->cmd),
+         command_name(cmd_as_arg->cmd));
+  if (!cmd_as_arg->type)
+    cmd_as_arg->type = ET_command_as_argument;
+  add_extra_element (cmd_as_arg->parent->parent,
+                     "command_as_argument", cmd_as_arg);
+  if (cmd_as_arg->cmd == CM_kbd
+      && kbd_formatted_as_code(cmd_as_arg->parent->parent)) {
+    add_extra_integer (cmd_as_arg->parent->parent,
+                       "command_as_argument_kbd_code", 1);
+  }
+}
+
 /* Check if line is "@end ..." for current command.  If so, advance LINE. */
 int
 is_end_current_command (ELEMENT *current, char **line,
@@ -1479,20 +1498,9 @@ superfluous_arg:
      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))
+      && parent_of_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);
-      }
+      register_command_as_argument (current);
       current = current->parent;
     }
 
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index be6b05506e..6e9c6cd86e 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -152,7 +152,8 @@ ELEMENT *end_paragraph (ELEMENT *current,
                         enum command_id interrupting_command);
 void isolate_last_space (ELEMENT *current);
 int kbd_formatted_as_code (ELEMENT *current);
-int command_with_command_as_argument (ELEMENT *current);
+int parent_of_command_as_argument (ELEMENT *current);
+void register_command_as_argument (ELEMENT *cmd_as_arg);
 ELEMENT *begin_preformatted (ELEMENT *current);
 ELEMENT *end_preformatted (ELEMENT *current,
                            enum command_id closed_command,
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index 8153bef88f..a4256d9484 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -448,19 +448,10 @@ handle_close_brace (ELEMENT *current, char **line_inout)
 
             }
         }
-      else if (command_with_command_as_argument (current->parent->parent)
+      else if (parent_of_command_as_argument (current->parent->parent)
                && current->contents.number == 0)
         {
-          debug ("FOR PARENT ... command_as_argument_braces ...");
-          if (!current->parent->type)
-            current->parent->type = ET_command_as_argument;
-          add_extra_element (current->parent->parent->parent,
-                             "command_as_argument", current->parent);
-          if (current->parent->cmd == CM_kbd
-              && kbd_formatted_as_code(current->parent->parent->parent)) {
-            add_extra_integer (current->parent->parent->parent,
-                               "command_as_argument_kbd_code", 1);
-          }
+          register_command_as_argument (current->parent);
         }
       else if (current->parent->cmd == CM_sortas
                || current->parent->cmd == CM_seeentry



reply via email to

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