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): handle separately 'raw' verbatim, ignore, (r)macro commands and ignored block conditional.
Date: Sat, 10 Sep 2022 05:51:02 -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 df63d3e0e4 * tp/Texinfo/ParserNonXS.pm (_parse_texi), 
tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line): handle separately 
'raw' verbatim, ignore, (r)macro commands and ignored block conditional.
df63d3e0e4 is described below

commit df63d3e0e426e2b9bb1d0d3a076efbf63936f598
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Sep 10 11:50:50 2022 +0200

    * tp/Texinfo/ParserNonXS.pm (_parse_texi),
    tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line):
    handle separately 'raw' verbatim, ignore, (r)macro commands
    and ignored block conditional.
---
 ChangeLog                        |   7 ++
 tp/Texinfo/ParserNonXS.pm        | 137 ++++++++++++------------
 tp/Texinfo/XS/parsetexi/parser.c | 219 ++++++++++++++++++++-------------------
 3 files changed, 191 insertions(+), 172 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5ae7e8b989..690736a06f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-09-10  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_parse_texi),
+       tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line):
+       handle separately 'raw' verbatim, ignore, (r)macro commands
+       and ignored block conditional.
+
 2022-09-10  Patrice Dumas  <pertusus@free.fr>
 
        Handle @end macro, verbatim and ignore line like other block commands
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 4039a5c6de..ed68d2e7eb 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -3929,7 +3929,7 @@ sub _parse_texi($$$)
 
     if (not
         # all the format handled early that have specific containers
-        # 'raw' format or verb or ignored raw format
+        # 'raw' command or ignored conditional or verb or ignored raw format
           (($current->{'cmdname'}
            and $block_commands{$current->{'cmdname'}}
             and ($block_commands{$current->{'cmdname'}} eq 'raw'
@@ -3963,11 +3963,10 @@ sub _parse_texi($$$)
     }
 
     while (1) {
-      # in a 'raw' (verbatim, ignore, (r)macro) or ignored conditional block 
command
+      # in a 'raw' (verbatim, ignore, (r)macro)
       if ($current->{'cmdname'}
           and $block_commands{$current->{'cmdname'}}
-          and ($block_commands{$current->{'cmdname'}} eq 'raw'
-               or $block_commands{$current->{'cmdname'}} eq 'conditional')) {
+          and ($block_commands{$current->{'cmdname'}} eq 'raw')) {
         # r?macro may be nested
         if (($current->{'cmdname'} eq 'macro'
              or $current->{'cmdname'} eq 'rmacro')
@@ -3979,25 +3978,16 @@ sub _parse_texi($$$)
                                             'extra' => {'arg_line' => $line }};
           $current = $current->{'contents'}->[-1];
           last;
-        # ifclear/ifset may be nested
-        } elsif (($current->{'cmdname'} eq 'ifclear'
-                  or $current->{'cmdname'} eq 'ifset'
-                  or $current->{'cmdname'} eq 'ifcommanddefined'
-                  or $current->{'cmdname'} eq 'ifcommandnotdefined')
-                and $line =~ /^\s*\@$current->{'cmdname'}/) {
-          $line =~ s/\s*\@($current->{'cmdname'})//;
-          push @{$current->{'contents'}}, { 'cmdname' => $1,
-                                            'parent' => $current,
-                                            'contents' => [],
-                                            'extra' => {'line' => $line }};
-          $current = $current->{'contents'}->[-1];
-          last;
         } elsif ($line =~ /^(\s*?)\@end\s+([a-zA-Z][\w-]*)/
                  and ($2 eq $current->{'cmdname'})) {
-          my $end_command = $2;
-          my $spaces_before_end = $1;
-          $line =~ s/^\s*//;
-          if ($spaces_before_end eq '') {
+          if ($line =~ s/^(\s+)//) {
+            push @{$current->{'contents'}},
+              { 'text' => $1,
+                'type' => 'raw', 'parent' => $current };
+            $self->_line_warn(sprintf(
+                  __("\@end %s should only appear at the beginning of a line"),
+                                     $current->{'cmdname'}), $source_info);
+          } else {
             # FIXME exclude other formats, like @macro, @ifset, @ignore?
             if ($current->{'cmdname'} ne 'verbatim'
                 and @{$current->{'contents'}}
@@ -4008,16 +3998,9 @@ sub _parse_texi($$$)
                              'text' => $1, 'parent' => $current};
               }
             }
-          } else {
-            push @{$current->{'contents'}},
-              { 'text' => $spaces_before_end,
-                'type' => 'raw', 'parent' => $current };
-            $self->_line_warn(sprintf(
-                  __("\@end %s should only appear at the beginning of a line"),
-                                     $end_command), $source_info);
           }
           # store toplevel macro specification
-          if (($end_command eq 'macro' or $end_command eq 'rmacro')
+          if (($current->{'cmdname'} eq 'macro' or $current->{'cmdname'} eq 
'rmacro')
                and (! $current->{'parent'}
                     or !$current->{'parent'}->{'cmdname'}
                     or ($current->{'parent'}->{'cmdname'} ne 'macro'
@@ -4049,47 +4032,71 @@ sub _parse_texi($$$)
               }
             }
           }
-          if ($block_commands{$end_command} eq 'conditional') {
-            $current = $current->{'parent'};
-            # don't store ignored @if*
-            my $conditional = pop @{$current->{'contents'}};
-            if (!defined($conditional->{'cmdname'}
-                or $conditional->{'cmdname'} ne $end_command)) {
-              $self->_bug_message(
-                      "Ignored command is not the conditional $end_command",
-                                   $source_info, $conditional);
-              die;
-            }
-            $line =~ s/^(\@end(\s+)$end_command)//;
-            $self->_line_warn(sprintf(
-                 __("superfluous argument to \@%s %s: %s"), 'end', 
$end_command,
-                                    $line), $source_info)
-              if ($line =~ /\S/ and $line !~ /^\s*\@c(omment)?\b/);
-            # Ignore until end of line
-            if ($line !~ /\n/) {
-              ($line, $source_info) = _new_line($self, $source_info);
-              print STDERR "IGNORE CLOSE line: $line" if ($self->{'DEBUG'});
-            }
-            print STDERR "CLOSED conditional $end_command\n" if 
($self->{'DEBUG'});
-            last;
-          } else {
-            print STDERR "CLOSED raw $end_command\n" if ($self->{'DEBUG'});
-            # start a new line for the @end line (without the first spaces on
-            # the line that have already been put in a raw container).
-            # This is normally done at the beginning of a line, but not here,
-            # as we directly got the line.  As the @end is processed just 
below,
-            # an empty line will not appear in the output, but it is needed to
-            # avoid a duplicate warning on @end not appearing at the beginning
-            # of the line
-            push @{$current->{'contents'}}, { 'type' => 'empty_line',
-                                              'text' => '',
-                                              'parent' => $current };
-          }
+          print STDERR "CLOSED raw $current->{'cmdname'}\n" if 
($self->{'DEBUG'});
+          # start a new line for the @end line (without the first spaces on
+          # the line that have already been put in a raw container).
+          # This is normally done at the beginning of a line, but not here,
+          # as we directly got the line.  As the @end is processed just below,
+          # an empty line will not appear in the output, but it is needed to
+          # avoid a duplicate warning on @end not appearing at the beginning
+          # of the line
+          push @{$current->{'contents'}}, { 'type' => 'empty_line',
+                                            'text' => '',
+                                            'parent' => $current };
         } else {
           push @{$current->{'contents'}},
             { 'text' => $line, 'type' => 'raw', 'parent' => $current };
           last;
         }
+      # in ignored conditional block command
+      } elsif ($current->{'cmdname'}
+          and $block_commands{$current->{'cmdname'}}
+          and ($block_commands{$current->{'cmdname'}} eq 'conditional')) {
+        # check for nested @ifset (so that @end ifset doesn't end the
+        # outermost @ifset).  It is discarded when the outermost is.
+        if (($current->{'cmdname'} eq 'ifclear'
+                  or $current->{'cmdname'} eq 'ifset'
+                  or $current->{'cmdname'} eq 'ifcommanddefined'
+                  or $current->{'cmdname'} eq 'ifcommandnotdefined')
+                and $line =~ /^\s*\@$current->{'cmdname'}/) {
+          push @{$current->{'contents'}}, { 'cmdname' => $current->{'cmdname'},
+                                            'parent' => $current,
+                                            'contents' => [],
+                                          };
+          $current = $current->{'contents'}->[-1];
+        } elsif ($line =~ /^(\s*?)\@end\s+([a-zA-Z][\w-]*)/
+                 and ($2 eq $current->{'cmdname'})) {
+          my $end_command = $current->{'cmdname'};
+          $line =~ s/^(\s*?)\@end\s+$end_command//;
+          if ($1 ne '') {
+            $self->_line_warn(sprintf(
+                  __("\@end %s should only appear at the beginning of a line"),
+                                     $end_command), $source_info);
+          }
+          $self->_line_warn(sprintf(
+               __("superfluous argument to \@%s %s: %s"), 'end', $end_command,
+                                  $line), $source_info)
+            if ($line =~ /\S/ and $line !~ /^\s*\@c(omment)?\b/);
+          $current = $current->{'parent'};
+          # don't store ignored @if*
+          my $conditional = pop @{$current->{'contents'}};
+          if (!defined($conditional->{'cmdname'}
+              or $conditional->{'cmdname'} ne $end_command)) {
+            $self->_bug_message(
+                    "Ignored command is not the conditional $end_command",
+                                 $source_info, $conditional);
+            die;
+          }
+          print STDERR "CLOSED conditional $end_command\n" if 
($self->{'DEBUG'});
+          # Ignore until end of line
+          # FIXME this is not the same as for other commands.  Change?
+          if ($line !~ /\n/) {
+            ($line, $source_info) = _new_line($self, $source_info);
+            print STDERR "IGNORE CLOSE line: $line" if ($self->{'DEBUG'});
+          }
+        }
+        # anything remaining on the line and any other line is ignored here
+        last;
       # in @verb. type should be 'brace_command_arg'
       } elsif ($current->{'parent'} and $current->{'parent'}->{'cmdname'}
              and $current->{'parent'}->{'cmdname'} eq 'verb') {
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index a25e6a5ab6..e15d1f43ef 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -850,6 +850,7 @@ command_with_command_as_argument (ELEMENT *current)
 
 /* Check if line is "@end ..." for current command.  If so, advance LINE. */
 /* the caller should free *spaces if the function returns 1 */
+/* FIXME **spaces is not used anywhere anymore, could be removed */
 int
 is_end_current_command (ELEMENT *current, char **line, char **spaces,
                         enum command_id *end_cmd)
@@ -1081,18 +1082,16 @@ process_remaining_on_line (ELEMENT **current_inout, 
char **line_inout)
   /* remains set only if command is unknown, otherwise cmd is used */
   char *command;
 
-  /********* BLOCK_raw or (ignored) BLOCK_conditional ******************/
-  /* If in raw block, or ignored conditional block. */
+  /********* BLOCK_raw ******************/
   if (command_flags(current) & CF_block
-      && (command_data(current->cmd).data == BLOCK_raw
-          || command_data(current->cmd).data == BLOCK_conditional))
+      && (command_data(current->cmd).data == BLOCK_raw))
     {
       char *spaces_after_end;
+      char *p = line;
       /* Check if we are using a macro within a macro. */
       if (current->cmd == CM_macro || current->cmd == CM_rmacro)
         {
           enum command_id cmd = 0;
-          char *p = line;
           p += strspn (p, whitespace_chars);
           if (!strncmp (p, "@macro", strlen ("@macro")))
             {
@@ -1116,65 +1115,39 @@ process_remaining_on_line (ELEMENT **current_inout, 
char **line_inout)
               goto funexit;
             }
         }
-
-      /* Else check for nested @ifset (so that @end ifset doesn't
-         end the outermost @ifset). */
-      if (current->cmd == CM_ifclear || current->cmd == CM_ifset
-          || current->cmd == CM_ifcommanddefined
-          || current->cmd == CM_ifcommandnotdefined)
-        {
-          ELEMENT *e;
-          char *p = line;
-          p += strspn (p, whitespace_chars);
-          if (*p == '@'
-              && !strncmp (p + 1, command_name(current->cmd),
-                           strlen (command_name(current->cmd))))
-            {
-              line = p + 1;
-              p += strlen (command_name(current->cmd));
-              e = new_element (ET_NONE);
-              e->cmd = current->cmd;
-              add_extra_string (e, "line", strdup (line));
-              add_to_element_contents (current, e);
-              current = e;
-              retval = GET_A_NEW_LINE;
-              goto funexit;
-            }
-        }
-
       /* Else check if line is "@end ..." for current command. */
-      p = line;
-      if (is_end_current_command (current, &line, &spaces_after_end, &end_cmd))
+      if (is_end_current_command (current, &p, &spaces_after_end, &end_cmd))
         {
-          ELEMENT *last_child;
-          char *tmp = 0;
-
-          last_child = last_contents_child (current);
+          ELEMENT *e;
 
-          /* collect whitespaces at the beginning of the line and advance p */
-          if (strchr (whitespace_chars, *p))
+          free (spaces_after_end);
+          if (strchr (whitespace_chars, *line))
             {
               ELEMENT *e;
-              int n = strspn (p, whitespace_chars);
+              int n = strspn (line, whitespace_chars);
               e = new_element (ET_raw);
-              text_append_n (&e->text, p, n);
+              text_append_n (&e->text, line, n);
               add_to_element_contents (current, e);
-              p += n;
+              line += n;
               line_warn ("@end %s should only appear at the "
                          "beginning of a line", command_name(end_cmd));
             }
-          else if (last_child
+          else
+            {
+              ELEMENT *last_child = last_contents_child (current);
+              if (last_child
                    && last_child->type == ET_raw
                    && current->cmd != CM_verbatim)
-            {
-              if (last_child->text.end > 0
-                  && last_child->text.text[last_child->text.end - 1] == '\n')
                 {
-                  ELEMENT *lrn;
-                  last_child->text.text[--last_child->text.end] = '\0';
-                  lrn = new_element (ET_last_raw_newline);
-                  text_append (&lrn->text, "\n");
-                  add_to_element_contents (current, lrn);
+                  if (last_child->text.end > 0
+                      && last_child->text.text[last_child->text.end - 1] == 
'\n')
+                    {
+                      ELEMENT *lrn;
+                      last_child->text.text[--last_child->text.end] = '\0';
+                      lrn = new_element (ET_last_raw_newline);
+                      text_append (&lrn->text, "\n");
+                      add_to_element_contents (current, lrn);
+                    }
                 }
             }
 
@@ -1218,57 +1191,7 @@ process_remaining_on_line (ELEMENT **current_inout, char 
**line_inout)
             }
 
 
-          /* Check for conditionals. */
-          if (command_data(end_cmd).flags & CF_block
-              && command_data(end_cmd).data == BLOCK_conditional)
-            {
-              current = current->parent;
-              /* Remove an ignored block. */
-              ELEMENT *popped;
-              popped = pop_element_from_contents (current);
-              if (popped->cmd != end_cmd)
-                fatal ("command mismatch for ignored block");
-
-              /* 'line' is now advanced past the "@end ...".  Check if
-                 there's anything after it. */
-              p = line + strspn (line, whitespace_chars);
-              if (*p && *p != '@')
-                goto superfluous_arg;
-              if (*p)
-                {
-                  p++;
-                  tmp = read_command_name (&p);
-                  if (tmp && (!strcmp (tmp, "c") || !strcmp (tmp, "comment")))
-                    {
-                   }
-                  else if (*p && p[strspn (p, whitespace_chars)])
-                    {
-superfluous_arg:
-                      line_warn ("superfluous argument to @end %s: %s",
-                                 command_name(end_cmd), line);
-                    }
-                  free (tmp);
-                }
-
-              /* Ignore until end of line */
-              if (!strchr (line, '\n'))
-                {
-                  line = new_line ();
-                  debug ("IGNORE CLOSE LINE");
-                }
-              destroy_element_and_children (popped);
-
-              debug ("CLOSED conditional %s", command_name(end_cmd));
-              retval = GET_A_NEW_LINE;
-              goto funexit;
-            }
-          else
-            {
-              ELEMENT *e;
-
-              /* go back to the position of the @end */
-              line = p;
-              debug ("CLOSED raw %s", command_name(end_cmd));
+          debug ("CLOSED raw %s", command_name(end_cmd));
          /* start a new line for the @end line (without the first spaces on
             the line that have already been put in a raw container).
             This is normally done at the beginning of a line, but not here,
@@ -1276,10 +1199,8 @@ superfluous_arg:
             an empty line will not appear in the output, but it is needed to
             avoid a duplicate warning on @end not appearing at the beginning
             of the line */
-              e = new_element (ET_empty_line);
-              add_to_element_contents (current, e);
-            }
-          free (spaces_after_end);
+          e = new_element (ET_empty_line);
+          add_to_element_contents (current, e);
         }
       else /* save the line verbatim */
         {
@@ -1291,7 +1212,91 @@ superfluous_arg:
           retval = GET_A_NEW_LINE;
           goto funexit;
         }
-    } /********* BLOCK_raw or (ignored) BLOCK_conditional *************/
+    } /********* BLOCK_raw *************/
+  /********* (ignored) BLOCK_conditional ******************/
+  else if (command_flags(current) & CF_block
+      && (command_data(current->cmd).data == BLOCK_conditional))
+    {
+      char *spaces_after_end;
+      char *p = line;
+
+      /* check for nested @ifset (so that @end ifset doesn't end the
+         the outermost @ifset).  It is discarded when the outermost is.*/
+      if (current->cmd == CM_ifclear || current->cmd == CM_ifset
+          || current->cmd == CM_ifcommanddefined
+          || current->cmd == CM_ifcommandnotdefined)
+        {
+          ELEMENT *e;
+          p += strspn (p, whitespace_chars);
+          if (*p == '@'
+              && !strncmp (p + 1, command_name(current->cmd),
+                           strlen (command_name(current->cmd))))
+            {
+              e = new_element (ET_NONE);
+              e->cmd = current->cmd;
+              add_to_element_contents (current, e);
+              current = e;
+              retval = GET_A_NEW_LINE;
+              goto funexit;
+            }
+        }
+
+      /* Else check if line is "@end ..." for current command. */
+      if (is_end_current_command (current, &line, &spaces_after_end, &end_cmd))
+        {
+          char *tmp = 0;
+
+          free (spaces_after_end);
+          /* check whitespaces at the beginning of the line */
+          if (strchr (whitespace_chars, *p))
+            {
+              ELEMENT *e;
+              line_warn ("@end %s should only appear at the "
+                         "beginning of a line", command_name(end_cmd));
+            }
+
+          current = current->parent;
+          /* Remove an ignored block. */
+          ELEMENT *popped;
+          popped = pop_element_from_contents (current);
+          if (popped->cmd != end_cmd)
+            fatal ("command mismatch for ignored block");
+
+          /* 'line' is now advanced past the "@end ...".  Check if
+             there's anything after it. */
+          p = line + strspn (line, whitespace_chars);
+          if (*p && *p != '@')
+            goto superfluous_arg;
+          if (*p)
+            {
+              p++;
+              tmp = read_command_name (&p);
+              if (tmp && (!strcmp (tmp, "c") || !strcmp (tmp, "comment")))
+                {
+                }
+              else if (*p && p[strspn (p, whitespace_chars)])
+                {
+superfluous_arg:
+                  line_warn ("superfluous argument to @end %s: %s",
+                             command_name(end_cmd), line);
+                }
+              free (tmp);
+            }
+
+          /* Ignore until end of line */
+          if (!strchr (line, '\n'))
+            {
+              line = new_line ();
+              debug ("IGNORE CLOSE LINE");
+            }
+          destroy_element_and_children (popped);
+
+          debug ("CLOSED conditional %s", command_name(end_cmd));
+        }
+      /* anything remaining on the line and any other line is ignored here */
+      retval = GET_A_NEW_LINE;
+      goto funexit;
+    } /********* (ignored) BLOCK_conditional *************/
 
   /* Check if parent element is 'verb' */
   else if (current->parent && current->parent->cmd == CM_verb)



reply via email to

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