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 (_parse_texi), tp/Tex


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_parse_texi), tp/Texinfo/XS/parsetexi/parser.c(process_remaining_on_line): avoid redundant code for brace commands and accent commands when not followed immediately by an opening brace.
Date: Sat, 27 Aug 2022 06:29:14 -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 e1d83beaaf * tp/Texinfo/ParserNonXS.pm (_parse_texi), 
tp/Texinfo/XS/parsetexi/parser.c(process_remaining_on_line): avoid redundant 
code for brace commands and accent commands when not followed immediately by an 
opening brace.
e1d83beaaf is described below

commit e1d83beaafd104ca56e5eb980c8420ecaa974bfb
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Aug 27 12:29:04 2022 +0200

    * tp/Texinfo/ParserNonXS.pm (_parse_texi),
    tp/Texinfo/XS/parsetexi/parser.c(process_remaining_on_line): avoid
    redundant code for brace commands and accent commands when not
    followed immediately by an opening brace.
---
 ChangeLog                        |   7 ++
 tp/Texinfo/ParserNonXS.pm        |  89 +++++++++-------------
 tp/Texinfo/XS/parsetexi/parser.c | 157 ++++++++++++++-------------------------
 3 files changed, 100 insertions(+), 153 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 042e4294b6..aa56ea048a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-08-27  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_parse_texi),
+       tp/Texinfo/XS/parsetexi/parser.c(process_remaining_on_line): avoid
+       redundant code for brace commands and accent commands when not
+       followed immediately by an opening brace.
+
 2022-08-27  Patrice Dumas  <pertusus@free.fr>
 
        No special warning for accent command needing braces
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 9acf263a1d..99f201ca84 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -4202,10 +4202,10 @@ sub _parse_texi($$$)
           next;
         }
       }
-      # Now handle all the cases that may lead to command closing
-      # or following character association with an @-command, especially
-      # accent command, that is handle @-command with braces that don't
-      # always need a brace.
+      # 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.
@@ -4225,59 +4225,42 @@ sub _parse_texi($$$)
             
$current->{'parent'}->{'parent'}->{'extra'}->{'command_as_argument_kbd_code'} = 
1;
           }
           $current = $current->{'parent'};
-        # now accent commands
-        } elsif ($accent_commands{$current->{'cmdname'}}) {
           # Note that non ascii spaces do not count as spaces
-          if ($line =~ s/^(\s+)//) {
-            my $added_space = $1;
-            $current->{'extra'}->{'spaces'} = ''
-              if (!defined($current->{'extra'}->{'spaces'}));
-            $current->{'extra'}->{'spaces'} .= $added_space;
-            if ($added_space =~ /\n/) {
-              $self->_line_warn(sprintf(
-                 __("command `\@%s' must not be followed by new line"),
-                 $current->{'cmdname'}), $source_info);
-            }
-          } elsif ($line =~ s/^([^@])//) {
-            print STDERR "ACCENT \@$current->{'cmdname'}\n"
-              if ($self->{'DEBUG'});
-            my $following_arg = {'type' => 'following_arg',
-                                 'parent' => $current};
-            $following_arg->{'contents'} = [{ 'text' => $1,
-                                             'parent' => $following_arg } ];
-            $current->{'args'} = [ $following_arg ];
-            if ($current->{'cmdname'} eq 'dotless' and $1 ne 'i' and $1 ne 
'j') {
-              $self->_line_error(sprintf(
-                 __("%c%s expects `i' or `j' as argument, not `%s'"),
-                                         ord('@'), $current->{'cmdname'}, $1),
-                                 $source_info);
-            }
-            $current = $current->{'parent'};
-          } else {
-            $self->_line_error(sprintf(__("\@%s expected braces"),
-                               $current->{'cmdname'}), $source_info);
-            $current = $current->{'parent'};
+        } elsif ($line =~ s/^(\s+)//
+                 and ($accent_commands{$current->{'cmdname'}}
+                      or $self->{'IGNORE_SPACE_AFTER_BRACED_COMMAND_NAME'})) {
+          my $added_space = $1;
+          $current->{'extra'}->{'spaces'} = ''
+            if (!defined($current->{'extra'}->{'spaces'}));
+          $current->{'extra'}->{'spaces'} .= $added_space;
+          if ($added_space =~ /\n/) {
+            $self->_line_warn(sprintf(
+               __("command `\@%s' must not be followed by new line"),
+               $current->{'cmdname'}), $source_info);
           }
-          next;
-        } else {
-          # ignore space after a braced @-command like TeX does
-          if ($self->{'IGNORE_SPACE_AFTER_BRACED_COMMAND_NAME'}
-              and $line =~ s/^(\s+)//) {
-            my $added_space = $1;
-            $current->{'extra'}->{'spaces'} = ''
-              if (!defined($current->{'extra'}->{'spaces'}));
-            $current->{'extra'}->{'spaces'} .= $added_space;
-            if ($added_space =~ /\n/) {
-              $self->_line_warn(sprintf(
-                 __("command `\@%s' must not be followed by new line"),
-                 $current->{'cmdname'}), $source_info);
-              # FIXME temporary hack to get the same output as XS parser
-              #$current->{'extra'}->{'spaces'} =~ s/\n\n/\n/;
-            }
-            next;
+          # FIXME temporary hack to get the same output as XS parser
+          #$current->{'extra'}->{'spaces'} =~ s/\n\n/\n/;
+        # 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"
+            if ($self->{'DEBUG'});
+          my $following_arg = {'type' => 'following_arg',
+                               'parent' => $current};
+          $following_arg->{'contents'} = [{ 'text' => $1,
+                                           'parent' => $following_arg } ];
+          $current->{'args'} = [ $following_arg ];
+          if ($current->{'cmdname'} eq 'dotless' and $1 ne 'i' and $1 ne 'j') {
+            $self->_line_error(sprintf(
+               __("%c%s expects `i' or `j' as argument, not `%s'"),
+                                       ord('@'), $current->{'cmdname'}, $1),
+                               $source_info);
           }
+          $current = $current->{'parent'};
+        } else {
           $self->_line_error(sprintf(__("\@%s expected braces"),
-                           $current->{'cmdname'}), $source_info);
+                             $current->{'cmdname'}), $source_info);
           $current = $current->{'parent'};
         }
       # maybe a menu entry beginning: a * at the beginning of a menu line
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 7b4520dfad..0463bd50ad 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1410,9 +1410,10 @@ superfluous_arg:
       line = allocated_line;
     }
 
-  /* Cases that may "lead to command closing": brace commands that don't 
-     need a brace: accent commands.
-     @definfoenclose. */
+  /* 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 
      command container. */
@@ -1434,112 +1435,68 @@ superfluous_arg:
           }
           current = current->parent;
         }
-      else if (command_flags(current) & CF_accent)
+      else if (strchr (whitespace_chars, *line)
+               && ((command_flags(current) & CF_accent)
+                   || conf.ignore_space_after_braced_command_name))
         {
-          if (strchr (whitespace_chars, *line))
-            {
-               char *p; char *s;
-               int whitespaces_len;
-               KEY_PAIR *k;
-               whitespaces_len = strspn (line, whitespace_chars);
-               p = line + whitespaces_len;
-               k = lookup_extra (current, "spaces");
-               if (!k)
-                 {
-                   xasprintf (&s, "%.*s", (int) (p - line), line);
-                   add_extra_string (current, "spaces", s);
-                 }
-               else
-                 {
-                   xasprintf (&s, "%s%.*s",
-                             (char *) k->value,
-                             (int) (p - line), p);
-                   free (k->value);
-                   k->value = (ELEMENT *) s;
-                 }
-               for (int i = 0; i < whitespaces_len; i++)
+           char *p; char *s;
+           int whitespaces_len;
+           KEY_PAIR *k;
+           whitespaces_len = strspn (line, whitespace_chars);
+           p = line + whitespaces_len;
+           k = lookup_extra (current, "spaces");
+           if (!k)
+             {
+               xasprintf (&s, "%.*s", (int) (p - line), line);
+               add_extra_string (current, "spaces", s);
+             }
+           else
+             {
+               xasprintf (&s, "%s%.*s",
+                         (char *) k->value,
+                         (int) (p - line), p);
+               free (k->value);
+               k->value = (ELEMENT *) s;
+             }
+           for (int i = 0; i < whitespaces_len; i++)
+             {
+               if (*(line + i) == '\n')
                  {
-                   if (*(line + i) == '\n')
-                     {
-                       line_warn ("command `@%s' must not be followed by new 
line",
-                                  command_name(current->cmd));
-                       break;
-                     }
+                   line_warn ("command `@%s' must not be followed by new line",
+                              command_name(current->cmd));
+                   break;
                  }
-               line = p;
-            }
-          else if (*line != '\0' && *line != '@')
-            {
-              ELEMENT *e, *e2;
-              debug ("ACCENT");
-              e = new_element (ET_following_arg);
-              add_to_element_args (current, e);
-              e2 = new_element (ET_NONE);
-              text_append_n (&e2->text, line, 1);
-              add_to_element_contents (e, e2);
-
-              if (current->cmd == CM_dotless
-                  && *line != 'i' && *line != 'j')
-                {
-                  line_error ("@dotless expects `i' or `j' as argument, "
-                              "not `%c'", *line);
-                }
-              while (current->contents.number > 0)
-                destroy_element (pop_element_from_contents (current));
-              line++;
-              current = current->parent;
-            }
-          else
+             }
+           line = p;
+        }
+    /* special case for accent commands, use following character except @
+     * as argument */
+      else if ((command_flags(current) & CF_accent)
+               && *line != '\0' && *line != '@')
+        {
+          ELEMENT *e, *e2;
+          debug ("ACCENT");
+          e = new_element (ET_following_arg);
+          add_to_element_args (current, e);
+          e2 = new_element (ET_NONE);
+          text_append_n (&e2->text, line, 1);
+          add_to_element_contents (e, e2);
+
+          if (current->cmd == CM_dotless
+              && *line != 'i' && *line != 'j')
             {
-              line_error ("@%s expected braces",
-                          command_name(current->cmd));
-              current = current->parent;
+              line_error ("@dotless expects `i' or `j' as argument, "
+                          "not `%c'", *line);
             }
-          goto funexit;
+          while (current->contents.number > 0)
+            destroy_element (pop_element_from_contents (current));
+          line++;
+          current = current->parent;
         }
       else
         {
-          if (conf.ignore_space_after_braced_command_name)
-            {
-              char *p;
-              int whitespaces_len;
-
-              whitespaces_len = strspn (line, whitespace_chars);
-              p = line + whitespaces_len;
-              if (p != line)
-                {
-                  char *s;
-                  KEY_PAIR *k;
-                  
-                  k = lookup_extra (current, "spaces");
-                  if (!k)
-                    {
-                      xasprintf (&s, "%.*s", (int) (p - line), line);
-                      add_extra_string (current, "spaces", s);
-                    }
-                  else
-                    {
-                      xasprintf (&s, "%s%.*s",
-                                (char *) k->value,
-                                (int) (p - line), p);
-                      free (k->value);
-                      k->value = (ELEMENT *) s;
-                    }
-                  for (int i = 0; i < whitespaces_len; i++)
-                    {
-                      if (*(line + i) == '\n')
-                        {
-                          line_warn ("command `@%s' must not be followed by 
new line",
-                                     command_name(current->cmd));
-                          break;
-                        }
-                    }
-                  line = p;
-                  goto funexit;
-                }
-            }
           line_error ("@%s expected braces",
-                       command_name(current->cmd));
+                      command_name(current->cmd));
           current = current->parent;
         }
     }



reply via email to

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