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 (_abort_empty_line):


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_abort_empty_line): define more variables and add separate if.
Date: Sun, 29 Sep 2024 08:02:32 -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 1014aab85a * tp/Texinfo/ParserNonXS.pm (_abort_empty_line): define 
more variables and add separate if.
1014aab85a is described below

commit 1014aab85abfdc136177d3d21b1a806178996f1d
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jun 23 09:41:34 2024 +0200

    * tp/Texinfo/ParserNonXS.pm (_abort_empty_line): define more variables
    and add separate if.
    
    * tp/Texinfo/ParserNonXS.pm (_merge_text, _abort_empty_line)
    (_end_line, _handle_open_brace), tp/Texinfo/XS/main/element_types.txt,
    tp/Texinfo/XS/parsetexi/end_line.c (end_line, do_abort_empty_line)
    (merge_text, abort_empty_line), tp/Texinfo/XS/parsetexi/separator.c
    (handle_open_brace): add a new internal text type,
    internal_spaces_before_context_argument, for context brace commands
    only, otherwise very similar with internal_spaces_before_argument.
---
 ChangeLog                            |  13 ++++
 tp/Texinfo/ParserNonXS.pm            | 140 ++++++++++++++++++-----------------
 tp/Texinfo/XS/main/element_types.c   |   1 +
 tp/Texinfo/XS/main/element_types.h   |   1 +
 tp/Texinfo/XS/main/element_types.txt |   1 +
 tp/Texinfo/XS/parsetexi/end_line.c   |   4 +-
 tp/Texinfo/XS/parsetexi/parser.c     |   6 +-
 tp/Texinfo/XS/parsetexi/separator.c  |  48 ++++++------
 8 files changed, 118 insertions(+), 96 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 47a9fde229..6b56fa0ba7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-06-23  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_abort_empty_line): define more variables
+       and add separate if.
+
+       * tp/Texinfo/ParserNonXS.pm (_merge_text, _abort_empty_line)
+       (_end_line, _handle_open_brace), tp/Texinfo/XS/main/element_types.txt,
+       tp/Texinfo/XS/parsetexi/end_line.c (end_line, do_abort_empty_line)
+       (merge_text, abort_empty_line), tp/Texinfo/XS/parsetexi/separator.c
+       (handle_open_brace): add a new internal text type,
+       internal_spaces_before_context_argument, for context brace commands
+       only, otherwise very similar with internal_spaces_before_argument.
+
 2024-06-23  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/convert_utils.c (find_innermost_accent_contents)
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 8345daf222..8616d05b26 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -2246,6 +2246,7 @@ sub _merge_text {
           or $last_element_type eq 'ignorable_spaces_after_command'
           or $last_element_type eq 'internal_spaces_after_command'
           or $last_element_type eq 'internal_spaces_before_argument'
+          or $last_element_type eq 'internal_spaces_before_context_argument'
           or $last_element_type eq 'spaces_after_close_brace') {
 
         if ($leading_spaces) {
@@ -2962,65 +2963,68 @@ sub _pop_element_from_contents($$)
 sub _abort_empty_line {
   my ($self, $current) = @_;
 
-  if ($current->{'contents'} and @{$current->{'contents'}}
-       and $current->{'contents'}->[-1]->{'type'}
-       and ($current->{'contents'}->[-1]->{'type'} eq 'empty_line'
-           or $current->{'contents'}->[-1]->{'type'} eq 
'ignorable_spaces_after_command'
-           or $current->{'contents'}->[-1]->{'type'} eq 
'internal_spaces_after_command'
-           or $current->{'contents'}->[-1]->{'type'} eq 
'internal_spaces_before_argument'
-           or $current->{'contents'}->[-1]->{'type'} eq 
'spaces_after_close_brace')) {
-
-    my $spaces_element = $current->{'contents'}->[-1];
+  if ($current->{'contents'}) {
+    my $last_element = $current->{'contents'}->[-1];
+    if ($last_element->{'type'}) {
+      my $type = $last_element->{'type'};
+      if ($type eq 'empty_line'
+          or $type eq 'ignorable_spaces_after_command'
+          or $type eq 'internal_spaces_after_command'
+          or $type eq 'internal_spaces_before_argument'
+          or $type eq 'internal_spaces_before_context_argument'
+          or $type eq 'spaces_after_close_brace') {
 
-    if ($self->{'conf'}->{'DEBUG'}) {
-      print STDERR "ABORT EMPTY in "
-         .Texinfo::Common::debug_print_element($current)
-          .": $spaces_element->{'type'}; |$spaces_element->{'text'}|\n";
-    }
+        if ($self->{'conf'}->{'DEBUG'}) {
+          print STDERR "ABORT EMPTY in "
+             .Texinfo::Common::debug_print_element($current)
+              .": $type; |$last_element->{'text'}|\n";
+        }
 
-    # remove empty 'empty*before'.  Happens in many situations.
-    if ($spaces_element->{'text'} eq '') {
-      my $popped_element = _pop_element_from_contents($self, $current);
-      # if first in parent and with source mark, placing a source mark
-      # should lead to readding an element for the source mark.  In that
-      # case, the type is not readded, such that it is actually relatively
-      # similar to the case of an empty line just below, except that an empty
-      # text string is left.
-      #
-      # Note that an empty text string first in parent does not happen often,
-      # as it cannot happen in paragraph, as there is some command or text that
-      # started the paragraph before, and being first in the main text out of
-      # paragraph does not happen often either.  The situation in which it
-      # happens is a macro expansion to an empty string right after an
-      # @-command opening (block or brace command).
-      foreach my $source_mark (@{$popped_element->{'source_marks'}}) {
-        _place_source_mark($self, $current, $source_mark);
-      }
-      delete $popped_element->{'source_marks'};
-    } elsif ($spaces_element->{'type'} eq 'empty_line') {
-      # exactly the same condition as to begin a paragraph
-      if ($begin_paragraph_contexts{$self->_top_context()}
-          and not ($current->{'type'}
-                  and $type_without_paragraph{$current->{'type'}})) {
-        $spaces_element->{'type'} = 'spaces_before_paragraph';
-      } else {
-        delete $spaces_element->{'type'};
-      }
-    } elsif ($spaces_element->{'type'} eq 'internal_spaces_after_command'
-             or $spaces_element->{'type'} eq 
'internal_spaces_before_argument') {
-      # Remove element from main tree. It will still be referenced in
-      # the 'info' hash as 'spaces_before_argument'.
-      my $spaces_before_argument = _pop_element_from_contents($self, $current);
-      delete $spaces_before_argument->{'type'};
-      delete $spaces_before_argument->{'parent'};
-      my $owning_element = $self->{'internal_space_holder'};
-      $owning_element->{'info'} = {} if (!exists($owning_element->{'info'}));
-      $owning_element->{'info'}->{'spaces_before_argument'}
-        = $spaces_before_argument;
-      $self->{'internal_space_holder'} = undef;
+        # remove empty 'empty*before'.  Happens in many situations.
+        if ($last_element->{'text'} eq '') {
+          my $popped_element = _pop_element_from_contents($self, $current);
+          # if first in parent and with source mark, placing a source mark
+          # should lead to readding an element for the source mark.  In that
+          # case, the type is not readded, such that it is actually relatively
+          # similar to the case of an empty line just below, except that an 
empty
+          # text string is left.
+          #
+          # Note that an empty text string first in parent does not happen 
often,
+          # as it cannot happen in paragraph, as there is some command or text 
that
+          # started the paragraph before, and being first in the main text out 
of
+          # paragraph does not happen often either.  The situation in which it
+          # happens is a macro expansion to an empty string right after an
+          # @-command opening (block or brace command).
+          foreach my $source_mark (@{$popped_element->{'source_marks'}}) {
+            _place_source_mark($self, $current, $source_mark);
+          }
+          delete $popped_element->{'source_marks'};
+        } elsif ($type eq 'empty_line') {
+          # exactly the same condition as to begin a paragraph
+          if ($begin_paragraph_contexts{$self->_top_context()}
+              and not ($current->{'type'}
+                      and $type_without_paragraph{$current->{'type'}})) {
+            $last_element->{'type'} = 'spaces_before_paragraph';
+          } else {
+            delete $last_element->{'type'};
+          }
+        } elsif ($type eq 'internal_spaces_after_command'
+                 or $type eq 'internal_spaces_before_argument'
+                 or $type eq 'internal_spaces_before_context_argument') {
+          # Remove element from main tree. It will still be referenced in
+          # the 'info' hash as 'spaces_before_argument'.
+          my $spaces_before_argument = _pop_element_from_contents($self, 
$current);
+          delete $spaces_before_argument->{'type'};
+          delete $spaces_before_argument->{'parent'};
+          my $owning_element = $self->{'internal_space_holder'};
+          $owning_element->{'info'} = {} if 
(!exists($owning_element->{'info'}));
+          $owning_element->{'info'}->{'spaces_before_argument'}
+            = $spaces_before_argument;
+          $self->{'internal_space_holder'} = undef;
+        }
+        return 1;
+      }
     }
-
-    return 1;
   }
   return 0;
 }
@@ -4628,7 +4632,9 @@ sub _end_line($$$)
   } elsif ($current->{'type'} and $current->{'type'} eq 'line_arg') {
     $current = _end_line_misc_line($self, $current, $source_info);
   } elsif (defined($prev_element_type)
-           and $prev_element_type eq 'internal_spaces_before_argument') {
+           and ($prev_element_type eq 'internal_spaces_before_argument'
+                or $prev_element_type
+                          eq 'internal_spaces_before_context_argument')) {
     # Empty spaces after brace or comma till the end of line.
     # Remove this element and update 'extra' values.
     _abort_empty_line($self, $current);
@@ -6155,6 +6161,7 @@ sub _handle_open_brace($$$$)
         $current->{'parent'}->{'info'}->{'delimiter'} = $1;
       }
     } elsif ($self->{'brace_commands'}->{$command} eq 'context') {
+      $current->{'type'} = 'brace_command_context';
       if ($command eq 'caption' or $command eq 'shortcaption') {
         my $float;
         $self->{'nesting_context'}->{'caption'} += 1;
@@ -6194,22 +6201,23 @@ sub _handle_open_brace($$$$)
       } elsif ($command eq 'footnote') {
         $self->{'nesting_context'}->{'footnote'} += 1;
       }
+
+      my $spaces_e = {'parent' => $current};
+      push @{$current->{'contents'}}, $spaces_e;
+
       if ($math_commands{$command}) {
+        # internal_spaces_before_argument is a transient internal type,
+        # which should end up in info spaces_before_argument.
+        $spaces_e->{'type'} = 'internal_spaces_before_argument';
         $self->_push_context('ct_math', $command);
       } else {
+        $spaces_e->{'type'} = 'internal_spaces_before_context_argument';
         $self->_push_context('ct_base', $command);
       }
+      $self->{'internal_space_holder'} = $current->{'parent'};
       # based on whitespace_chars_except_newline in XS parser
       $line =~ s/([ \t\cK\f]*)//;
-      $current->{'type'} = 'brace_command_context';
-      # internal_spaces_before_argument is a transient internal type,
-      # which should end up in info spaces_before_argument.
-      push @{$current->{'contents'}}, {
-        'type' => 'internal_spaces_before_argument',
-        'text' => $1,
-        'parent' => $current,
-      };
-      $self->{'internal_space_holder'} = $current->{'parent'};
+      $spaces_e->{'text'} = $1;
     } else {
       # Commands that disregard leading whitespace.
       if ($brace_commands{$command}
diff --git a/tp/Texinfo/XS/main/element_types.c 
b/tp/Texinfo/XS/main/element_types.c
index c7caf4571a..f9bd61dff0 100644
--- a/tp/Texinfo/XS/main/element_types.c
+++ b/tp/Texinfo/XS/main/element_types.c
@@ -55,6 +55,7 @@ TYPE_DATA type_data[] = {
 "internal_menu_star", TF_text, 0,
 "internal_spaces_after_command", TF_text, 0,
 "internal_spaces_before_argument", TF_text, 0,
+"internal_spaces_before_context_argument", TF_text, 0,
 "internal_spaces_before_brace_in_index", TF_text, 0,
 "internal_spaces_after_cmd_before_arg", TF_text, 0,
 "macro_name", TF_text, 0,
diff --git a/tp/Texinfo/XS/main/element_types.h 
b/tp/Texinfo/XS/main/element_types.h
index 97a510279d..09bb316165 100644
--- a/tp/Texinfo/XS/main/element_types.h
+++ b/tp/Texinfo/XS/main/element_types.h
@@ -54,6 +54,7 @@ ET_menu_comment,
 ET_internal_menu_star,
 ET_internal_spaces_after_command,
 ET_internal_spaces_before_argument,
+ET_internal_spaces_before_context_argument,
 ET_internal_spaces_before_brace_in_index,
 ET_internal_spaces_after_cmd_before_arg,
 ET_macro_name,
diff --git a/tp/Texinfo/XS/main/element_types.txt 
b/tp/Texinfo/XS/main/element_types.txt
index 1b1658f951..439aaad54b 100644
--- a/tp/Texinfo/XS/main/element_types.txt
+++ b/tp/Texinfo/XS/main/element_types.txt
@@ -88,6 +88,7 @@ internal_menu_star                         text
 internal_spaces_after_command              text
 # after opening brace or comma
 internal_spaces_before_argument            text
+internal_spaces_before_context_argument    text
 # on @*index commands line before brace specific @-command
 internal_spaces_before_brace_in_index      text
 internal_spaces_after_cmd_before_arg       text
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c 
b/tp/Texinfo/XS/parsetexi/end_line.c
index 72a8140e23..ff12fb3051 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -1931,8 +1931,8 @@ end_line (ELEMENT *current)
     {
       current = end_line_misc_line (current);
     }
-  else if (last_element_type
-              == ET_internal_spaces_before_argument)
+  else if (last_element_type == ET_internal_spaces_before_argument
+           || last_element_type == ET_internal_spaces_before_context_argument)
     {
       /* Empty spaces after brace or comma till the end of line.
          Remove this element and update 'extra' values. */
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 805f5bce20..6924e402cb 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -737,7 +737,8 @@ do_abort_empty_line (ELEMENT *current, ELEMENT *last_elt)
                          ? ET_spaces_before_paragraph : ET_normal_text;
     }
   else if (last_elt->type == ET_internal_spaces_after_command
-           || last_elt->type == ET_internal_spaces_before_argument)
+           || last_elt->type == ET_internal_spaces_before_argument
+           || last_elt->type == ET_internal_spaces_before_context_argument)
     {
       /* Remove element from main tree. It will still be referenced in
          the 'info' hash as 'spaces_before_argument'. */
@@ -783,6 +784,8 @@ merge_text (ELEMENT *current, const char *text, size_t 
len_text,
               || last_element->type == ET_ignorable_spaces_after_command
               || last_element->type == ET_internal_spaces_after_command
               || last_element->type == ET_internal_spaces_before_argument
+              || last_element->type
+                           == ET_internal_spaces_before_context_argument
               || last_element->type == ET_spaces_after_close_brace))
         {
           int no_merge_with_following_text
@@ -910,6 +913,7 @@ abort_empty_line (ELEMENT *current)
           || last_child->type == ET_ignorable_spaces_after_command
           || last_child->type == ET_internal_spaces_after_command
           || last_child->type == ET_internal_spaces_before_argument
+          || last_child->type == ET_internal_spaces_before_context_argument
           || last_child->type == ET_spaces_after_close_brace))
     {
       do_abort_empty_line (current, last_child);
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index 3e77f5334f..45afdf40a5 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -97,6 +97,9 @@ handle_open_brace (ELEMENT *current, const char **line_inout)
         }
       else if (command_data(cmd).data == BRACE_context)
         {
+          ELEMENT *space_e;
+          int n;
+
           arg = new_element (ET_brace_command_context);
           add_to_element_args (current, arg);
           current = arg;
@@ -151,36 +154,27 @@ handle_open_brace (ELEMENT *current, const char 
**line_inout)
               nesting_context.footnote++;
             }
 
-          /* Add to context stack. */
-          switch (cmd)
+          if (cmd == CM_math)
             {
-            case CM_footnote:
-              push_context (ct_base, cmd);
-              break;
-            case CM_caption:
-              push_context (ct_base, cmd);
-              break;
-            case CM_shortcaption:
-              push_context (ct_base, cmd);
-              break;
-            case CM_math:
               push_context (ct_math, cmd);
-              break;
-            default:
-              fatal ("no context for command");
+              space_e = new_text_element (ET_internal_spaces_before_argument);
             }
+          else
+            {
+              push_context (ct_base, cmd);
+              space_e
+                = new_text_element 
(ET_internal_spaces_before_context_argument);
+            }
+
+          add_to_element_contents (current, space_e);
+          internal_space_holder = current->parent;
 
-          {
-            ELEMENT *e;
-            int n;
-            n = strspn (line, whitespace_chars_except_newline);
-            e = new_text_element (ET_internal_spaces_before_argument);
-            text_append_n (e->e.text, line, n);
-            add_to_element_contents (current, e);
-            internal_space_holder = current->parent;
-
-            line += n;
-          }
+          n = strspn (line, whitespace_chars_except_newline);
+          if (n > 0)
+            {
+              text_append_n (space_e->e.text, line, n);
+              line += n;
+            }
         }
       else /* not context brace */
         {
@@ -188,8 +182,8 @@ handle_open_brace (ELEMENT *current, const char 
**line_inout)
           if (command_data(cmd).data == BRACE_arguments
               || command_data(cmd).data == BRACE_inline)
             {
-              arg = new_element (ET_brace_arg);
               ELEMENT *e;
+              arg = new_element (ET_brace_arg);
               e = new_text_element (ET_internal_spaces_before_argument);
               add_to_element_contents (arg, e);
               internal_space_holder = arg;



reply via email to

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