texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Simplify context brace command closing


From: Gavin D. Smith
Subject: branch master updated: Simplify context brace command closing
Date: Wed, 25 Jan 2023 14:35:52 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 661642e449 Simplify context brace command closing
661642e449 is described below

commit 661642e449de02e68dac43aa787c1b092cea3382
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Wed Jan 25 19:35:43 2023 +0000

    Simplify context brace command closing
    
    * tp/Texinfo/XS/parsetexi/close.c (close_brace_command): Add
    argument to control printing of error messages and make non-static
    function.  Pop context stack for BRACE_context commands and
    decrement nesting context counters.
    (close_all_style_commands): Remove FIXME about nesting context.
    (close_current): Do not update context stack or context counters
    as it is now done in close_brace_command.
    * tp/Texinfo/XS/parsetexi/separator.c (handle_close_brace):
    Always call close_brace_command, so it is no longer just called for
    erroneous input.
    
    * tp/Texinfo/ParserNonXS.pm (_close_brace_command): Add
    argument to control printing of error messages.  Pop context stack
    for context brace commands and decrement nesting context counters.
    (_close_all_style_commands): Remove FIXME about nesting context.
    (_close_current): Do not update context stack or context counters
    as it is now done in close_brace_command.
    (_process_remaining_on_line) <close brace>:
    Always call _close_brace_command, so it is no longer just called for
    erroneous input.
---
 ChangeLog                           | 25 ++++++++++++++
 tp/Texinfo/ParserNonXS.pm           | 68 +++++++++++++++----------------------
 tp/Texinfo/XS/parsetexi/close.c     | 52 ++++++++++++++--------------
 tp/Texinfo/XS/parsetexi/parser.h    |  4 +++
 tp/Texinfo/XS/parsetexi/separator.c | 26 +++-----------
 5 files changed, 87 insertions(+), 88 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index feb1f7c11c..1faa0bc98d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2023-01-24  Gavin Smith <gavinsmith0123@gmail.com>
+
+       Simplify context brace command closing
+
+       * tp/Texinfo/XS/parsetexi/close.c (close_brace_command): Add
+       argument to control printing of error messages and make non-static
+       function.  Pop context stack for BRACE_context commands and
+       decrement nesting context counters.
+       (close_all_style_commands): Remove FIXME about nesting context.
+       (close_current): Do not update context stack or context counters
+       as it is now done in close_brace_command.
+       * tp/Texinfo/XS/parsetexi/separator.c (handle_close_brace):
+       Always call close_brace_command, so it is no longer just called for
+       erroneous input.
+
+       * tp/Texinfo/ParserNonXS.pm (_close_brace_command): Add
+       argument to control printing of error messages.  Pop context stack
+       for context brace commands and decrement nesting context counters.
+       (_close_all_style_commands): Remove FIXME about nesting context.
+       (_close_current): Do not update context stack or context counters
+       as it is now done in close_brace_command.
+       (_process_remaining_on_line) <close brace>:
+       Always call _close_brace_command, so it is no longer just called for
+       erroneous input.
+
 2023-01-25  Arsen Arsenović  <arsen@aarsen.me>
 
        ParserNonXS: Fix minor Perl error
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 11b4639816..d068688d44 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -1488,10 +1488,26 @@ sub _command_error($$$$;@)
 
 # register error messages, but otherwise doesn't do much more than
 # return $_[1]->{'parent'}
-sub _close_brace_command($$$;$$)
+sub _close_brace_command($$$;$$$)
 {
   my ($self, $current, $source_info, $closed_block_command,
-      $interrupting_command) = @_;
+      $interrupting_command, $missing_brace) = @_;
+
+  if ($self->{'brace_commands'}->{$current->{'cmdname'}} eq 'context') {
+    my $expected_context;
+    if ($math_commands{$current->{'cmdname'}}) {
+      $expected_context = 'ct_math';
+    } else {
+      $expected_context = 'ct_brace_command';
+    }
+    $self->_pop_context([$expected_context], $source_info, $current);
+
+    $self->{'nesting_context'}->{'footnote'} -= 1
+      if ($current->{'cmdname'} eq 'footnote');
+    $self->{'nesting_context'}->{'caption'} -= 1
+      if ($current->{'cmdname'} eq 'caption'
+        or $current->{'cmdname'} eq 'shortcaption');
+  }
 
   if ($current->{'cmdname'} ne 'verb'
       or $current->{'info'}->{'delimiter'} eq '') {
@@ -1503,11 +1519,11 @@ sub _close_brace_command($$$;$$)
       $self->_command_error($current, $source_info,
         __("\@%s seen before \@%s closing brace"),
                   $interrupting_command, $current->{'cmdname'});
-    } else {
+    } elsif ($missing_brace) {
       $self->_command_error($current, $source_info,
         __("%c%s missing closing brace"), ord('@'), $current->{'cmdname'});
     }
-  } else {
+  } elsif ($missing_brace) {
     $self->_command_error($current, $source_info,
        __("\@%s missing closing delimiter sequence: %s}"),
        $current->{'cmdname'}, $current->{'info'}->{'delimiter'});
@@ -1587,10 +1603,9 @@ sub _close_all_style_commands($$$;$$)
          if ($self->{'DEBUG'});
     $current = _close_brace_command($self, $current->{'parent'}, $source_info,
                                     $closed_block_command,
-                                    $interrupting_command);
+                                    $interrupting_command, 1);
   }
-  # FIXME: we don't touch nesting_context here which may lead to erroneous
-  # warnings.
+
   return $current;
 }
 
@@ -2002,24 +2017,9 @@ sub _close_current($$$;$$)
     print STDERR "CLOSING(close_current) \@$current->{'cmdname'}\n"
          if ($self->{'DEBUG'});
     if (exists($self->{'brace_commands'}->{$current->{'cmdname'}})) {
-      if ($self->{'brace_commands'}->{$current->{'cmdname'}} eq 'context') {
-        my $expected_context;
-        if ($math_commands{$current->{'cmdname'}}) {
-          $expected_context = 'ct_math';
-        } else {
-          $expected_context = 'ct_brace_command';
-        }
-        $self->_pop_context([$expected_context], $source_info, $current);
-
-        $self->{'nesting_context'}->{'footnote'} -= 1
-          if ($current->{'cmdname'} eq 'footnote');
-        $self->{'nesting_context'}->{'caption'} -= 1
-          if ($current->{'cmdname'} eq 'caption'
-            or $current->{'cmdname'} eq 'shortcaption');
-      }
       $current = _close_brace_command($self, $current, $source_info,
                                       $closed_block_command,
-                                      $interrupting_command);
+                                      $interrupting_command, 1);
     } elsif (exists($block_commands{$current->{'cmdname'}})) {
       if (defined($closed_block_command)) {
         $self->_line_error(sprintf(__("`\@end' expected `%s', but saw `%s'"),
@@ -5815,23 +5815,6 @@ sub _process_remaining_on_line($$$$)
           and $current->{'parent'}->{'cmdname'}
           and exists($self->{'brace_commands'}
                                      ->{$current->{'parent'}->{'cmdname'}})) {
-        if ($self->{'brace_commands'}
-                          ->{$current->{'parent'}->{'cmdname'}} eq 'context') {
-          print STDERR "CLOSING(context command) "
-                        ."\@$current->{'parent'}->{'cmdname'}\n"
-                           if ($self->{'DEBUG'});
-          my $command_context = 'ct_brace_command';
-          if ($math_commands{$current->{'parent'}->{'cmdname'}}) {
-            $command_context = 'ct_math';
-          }
-          $self->_pop_context([$command_context], $source_info, $current,
-                   "for brace command $current->{'parent'}->{'cmdname'}");
-          $self->{'nesting_context'}->{'footnote'} -= 1
-            if ($current->{'parent'}->{'cmdname'} eq 'footnote');
-          $self->{'nesting_context'}->{'caption'} -= 1
-            if ($current->{'parent'}->{'cmdname'} eq 'caption'
-                or $current->{'parent'}->{'cmdname'} eq 'shortcaption');
-        }
         # first is the arg.
         if ($brace_commands{$current->{'parent'}->{'cmdname'}}
             and $brace_commands{$current->{'parent'}{'cmdname'}} eq 'arguments'
@@ -6029,7 +6012,10 @@ sub _process_remaining_on_line($$$$)
               'parent' => $current->{'parent'}->{'parent'}
              };
         }
-        $current = $current->{'parent'}->{'parent'};
+
+        $current = _close_brace_command($self, $current->{'parent'},
+                                        $source_info);
+
         $current = _begin_preformatted($self, $current)
            if ($close_preformatted_commands{$closed_command});
       # lone braces accepted right in a rawpreformatted
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index f640eb24e0..346127a57b 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -1,4 +1,4 @@
-/* Copyright 2010-2019 Free Software Foundation, Inc.
+/* Copyright 2010-2023 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -20,15 +20,32 @@
 
 #include "parser.h"
 
-/* Possibly print an error message, and return CURRENT->parent. */
-static ELEMENT *
+/* Return CURRENT->parent.  The other arguments are used if an error message
+   should be printed. */
+ELEMENT *
 close_brace_command (ELEMENT *current,
                      enum command_id closed_block_command,
-                     enum command_id interrupting_command)
+                     enum command_id interrupting_command,
+                     int missing_brace)
 {
 
   KEY_PAIR *k;
 
+  if (command_data(current->cmd).data == BRACE_context)
+    {
+      if (current->cmd == CM_math)
+        {
+          if (pop_context () != ct_math)
+            fatal ("math context expected");
+        }
+      else if (pop_context () != ct_brace_command)
+        fatal ("context brace command context expected");
+      if (current->cmd == CM_footnote)
+        nesting_context.footnote--;
+      if (current->cmd == CM_caption || current->cmd == CM_shortcaption)
+        nesting_context.caption--;
+    }
+
   if (current->cmd != CM_verb)
     goto yes;
   k = lookup_info (current, "delimiter");
@@ -47,12 +64,12 @@ close_brace_command (ELEMENT *current,
                         "@%s seen before @%s closing brace",
                         command_name(interrupting_command),
                         command_name(current->cmd));
-      else
-        command_error (current,
+      else if (missing_brace)
+         command_error (current,
                         "@%s missing closing brace",
                         command_name(current->cmd));
     }
-  else
+  else if (missing_brace)
     {
       command_error (current,
                       "@%s missing closing delimiter sequence: %s}",
@@ -74,10 +91,8 @@ close_all_style_commands (ELEMENT *current,
          && (command_flags(current->parent) & CF_brace)
          && !(command_data(current->parent->cmd).data == BRACE_context))
     current = close_brace_command (current->parent,
-                                   closed_block_command, interrupting_command);
+                           closed_block_command, interrupting_command, 1);
 
-  /* FIXME: we don't touch nesting_context here which may lead to erroneous
-     warnings. */
   return current;
 }
 
@@ -273,23 +288,8 @@ close_current (ELEMENT *current,
       debug ("CLOSING (close_current) %s", command_name(current->cmd));
       if (command_flags(current) & CF_brace)
         {
-          if (command_data(current->cmd).data == BRACE_context)
-            {
-              if (current->cmd == CM_math)
-                {
-                  if (pop_context () != ct_math)
-                    fatal ("math context expected");
-                }
-              else if (pop_context () != ct_brace_command)
-                fatal ("context brace command context expected");
-              if (current->cmd == CM_footnote)
-                nesting_context.footnote--;
-              if (current->cmd == CM_caption || current->cmd == 
CM_shortcaption)
-                nesting_context.caption--;
-            }
-
           current = close_brace_command (current, closed_block_command,
-                                         interrupting_command);
+                                         interrupting_command, 1);
         }
       else if (command_flags(current) & CF_block)
         {
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index f4a128536f..ad191587c9 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -116,6 +116,10 @@ ELEMENT *close_all_style_commands (ELEMENT *current,
 ELEMENT *close_current (ELEMENT *current,
                         enum command_id closed_block_command,
                         enum command_id interrupting_command);
+ELEMENT *close_brace_command (ELEMENT *current,
+                              enum command_id closed_block_command,
+                              enum command_id interrupting_command,
+                              int missing_brace);
 
 /* In end_line.c */
 NODE_SPEC_EXTRA *parse_node_manual (ELEMENT *node);
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index 2918f4993b..30d2a64f32 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -253,27 +253,10 @@ handle_close_brace (ELEMENT *current, char **line_inout)
   else if (command_flags(current->parent) & CF_brace)
     {
       enum command_id closed_command;
-      if (command_data(current->parent->cmd).data == BRACE_context)
-        {
-          debug ("CLOSING(context command)");
-          if (current->parent->cmd == CM_math)
-            {
-              if (pop_context () != ct_math)
-                fatal ("math context expected");
-            }
-          else if (pop_context () != ct_brace_command)
-            fatal ("context brace command context expected");
-          if (current->parent->cmd == CM_footnote)
-            nesting_context.footnote--;
-          else if (current->parent->cmd == CM_caption
-                   || current->parent->cmd == CM_shortcaption)
-            nesting_context.caption--;
-        }
+
       /* determine if trailing spaces are ignored */
-      else if (command_data(current->parent->cmd).data == BRACE_arguments)
-        {
-          isolate_last_space (current);
-        }
+      if (command_data(current->parent->cmd).data == BRACE_arguments)
+        isolate_last_space (current);
 
       closed_command = current->parent->cmd;
       debug ("CLOSING(brace) %s", command_data(closed_command).cmdname);
@@ -520,7 +503,8 @@ handle_close_brace (ELEMENT *current, char **line_inout)
           add_to_element_contents (current->parent->parent, e);
         }
 
-      current = current->parent->parent;
+      current = close_brace_command (current->parent, 0, 0, 0);
+
       if (close_preformatted_command(closed_command))
         current = begin_preformatted (current);
     } /* CF_brace */



reply via email to

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