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


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_close_ignored_block_conditional) (_close_current, _process_remaining_on_line), tp/Texinfo/XS/parsetexi/close.c (close_ignored_block_conditional), (close_current), tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line): add close_ignored_block_conditional to associated a source mark to a closed ignored conditional block, to do it in close_current in addition to process_remaining_on_line.
Date: Sun, 12 Feb 2023 16:21:02 -0500

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 14e2aaa5bd * tp/Texinfo/ParserNonXS.pm 
(_close_ignored_block_conditional) (_close_current, 
_process_remaining_on_line), tp/Texinfo/XS/parsetexi/close.c 
(close_ignored_block_conditional), (close_current), 
tp/Texinfo/XS/parsetexi/parser.c (process_remaining_on_line): add 
close_ignored_block_conditional to associated a source mark to a closed ignored 
conditional block, to do it in close_current in addition to 
process_remaining_on_line.
14e2aaa5bd is described below

commit 14e2aaa5bdf645ebe6172c7bb291525650ee7f7d
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Feb 12 22:14:22 2023 +0100

    * tp/Texinfo/ParserNonXS.pm (_close_ignored_block_conditional)
    (_close_current, _process_remaining_on_line),
    tp/Texinfo/XS/parsetexi/close.c (close_ignored_block_conditional),
    (close_current), tp/Texinfo/XS/parsetexi/parser.c
    (process_remaining_on_line): add close_ignored_block_conditional
    to associated a source mark to a closed ignored conditional block,
    to do it in close_current in addition to process_remaining_on_line.
---
 ChangeLog                                          | 10 +++
 tp/TODO                                            |  3 -
 tp/Texinfo/ParserNonXS.pm                          | 77 +++++++++++++++-------
 tp/Texinfo/XS/parsetexi/close.c                    | 37 ++++++-----
 tp/Texinfo/XS/parsetexi/parser.c                   |  8 +--
 tp/Texinfo/XS/parsetexi/parser.h                   |  1 +
 .../results/conditionals/conditional_not_closed.pl | 37 +++++++++++
 .../conditionals/empty_ifset_in_ifset_no_set.pl    | 60 +++++++++++++++++
 tp/t/results/invalid_nestings/ignored_text.pl      | 26 ++++++++
 tp/t/results/macro/ifset_and_end_isef_in_macro.pl  | 54 +++++++++++++++
 10 files changed, 264 insertions(+), 49 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ae083ca48b..f67384c090 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,16 @@
        Sometimes call 'length' on the string.  This makes a difference
        because string_width is now called from ParagraphNonXS.pm.
 
+2023-02-12  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_close_ignored_block_conditional)
+       (_close_current, _process_remaining_on_line),
+       tp/Texinfo/XS/parsetexi/close.c (close_ignored_block_conditional),
+       (close_current), tp/Texinfo/XS/parsetexi/parser.c
+       (process_remaining_on_line): add close_ignored_block_conditional
+       to associated a source mark to a closed ignored conditional block,
+       to do it in close_current in addition to process_remaining_on_line.
+
 2023-02-12  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/ParserNonXS.pm (_end_line_misc_line): avoid
diff --git a/tp/TODO b/tp/TODO
index 4c25cd930b..94d2f5851e 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -10,9 +10,6 @@ This is the todo list for texi2any
 Before next release
 ===================
 
-invalid_nestings ignored_text test does not have the @ifinfo ignored_block
-source mark.
-
 Add tests of source marks on ignored @if* blocks lines and in contents.
 
 Add @end in ignored @if* blocks lines source marks.
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 9898e825eb..b7d3e332cb 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -2075,6 +2075,18 @@ sub _pop_block_command_contexts($$$;$)
   }
 }
 
+sub _close_ignored_block_conditional($$)
+{
+  my $self = shift;
+  my $parent = shift;
+
+  my $conditional = _pop_element_from_contents($self, $parent);
+  delete $conditional->{'parent'};
+  my $source_mark = {'sourcemark_type' => 'ignored_conditional_block',
+                     'element' => $conditional};
+  _register_source_mark($self, $parent, $source_mark);
+}
+
 # close the current command, with error messages and give the parent.
 # If the last argument is given it is the command being closed if
 # hadn't there be an error, currently only block command, used for a
@@ -2085,35 +2097,36 @@ sub _close_current($$$;$$)
       $interrupting_command) = @_;
   # Element is a command
   if ($current->{'cmdname'}) {
-    print STDERR "CLOSING(close_current) \@$current->{'cmdname'}\n"
+    my $command = $current->{'cmdname'};
+    print STDERR "CLOSING(close_current) \@$command\n"
          if ($self->{'DEBUG'});
-    if (exists($self->{'brace_commands'}->{$current->{'cmdname'}})) {
+    if (exists($self->{'brace_commands'}->{$command})) {
       $current = _close_brace_command($self, $current, $source_info,
                                       $closed_block_command,
                                       $interrupting_command, 1);
-    } elsif (exists($block_commands{$current->{'cmdname'}})) {
+    } elsif (exists($block_commands{$command})) {
       if (defined($closed_block_command)) {
         $self->_line_error(sprintf(__("`\@end' expected `%s', but saw `%s'"),
-                                   $current->{'cmdname'}, 
$closed_block_command),
+                                   $command, $closed_block_command),
                            $source_info);
       } elsif ($interrupting_command) {
         $self->_line_error(sprintf(__("\@%s seen before \@end %s"),
-                                  $interrupting_command, 
$current->{'cmdname'}),
+                                  $interrupting_command, $command),
                            $source_info);
       } else {
         $self->_line_error(sprintf(__("no matching `%cend %s'"),
-                                   ord('@'), $current->{'cmdname'}),
+                                   ord('@'), $command),
                            $source_info);
-        if ($block_commands{$current->{'cmdname'}} eq 'conditional') {
-          # In ignored conditional.
-          _pop_element_from_contents($self, $current->{'parent'});
-        }
       }
       _pop_block_command_contexts($self, $current, $source_info);
       # empty non-closed block commands at the end of the document
       delete $current->{'contents'}
         if ($current->{'contents'} and scalar(@{$current->{'contents'}}) == 0);
       $current = $current->{'parent'};
+      if ($block_commands{$command} eq 'conditional') {
+        # In ignored conditional.
+        _close_ignored_block_conditional($self, $current);
+      }
     } else {
       # There @item and @tab commands are closed, and also line commands
       # with invalid content.
@@ -2190,10 +2203,19 @@ sub _close_commands($$$;$$)
   my $closed_element;
   if ($closed_block_command and $current->{'cmdname'}
       and $current->{'cmdname'} eq $closed_block_command) {
+
     _pop_block_command_contexts($self, $current, $source_info,
                                 "for $closed_block_command");
     $closed_element = $current;
     $current = $current->{'parent'};
+
+    # TODO close here instead of in _process_remaining_on_line
+    # when the end conditional is treated like any other command
+    #if ($block_commands{$current->{'cmdname'}} eq 'conditional') {
+    #  # In ignored conditional.
+    #  _close_ignored_block_conditional($self, $current);
+    #}
+
   } elsif ($closed_block_command) {
     $self->_line_error(sprintf(__("unmatched `%c%s'"),
                        ord('@'), "end $closed_block_command"), $source_info);
@@ -3633,6 +3655,9 @@ sub _end_line_misc_line($$$)
 
       $current = _begin_preformatted($self, $current)
         if ($close_preformatted_commands{$end_command});
+    } else {
+      # TODO add a source mark for the end of conditional
+      # case of a conditional not ignored
     }
   } else {
     # Ignore @setfilename in included file, as said in the manual.
@@ -4346,7 +4371,7 @@ sub _end_line($$$)
   # they are reprocessed here.
   my $top_context = $self->_top_context();
   if ($top_context eq 'ct_line' or $top_context eq 'ct_def') {
-    print STDERR "Still opened line command $top_context:"
+    print STDERR "Still opened line/block command $top_context:"
       ._print_current($current)
         if ($self->{'DEBUG'});
     if ($top_context eq 'ct_def') {
@@ -4934,9 +4959,19 @@ sub _process_remaining_on_line($$$$)
                                         'parent' => $current,
                                       };
       $current = $current->{'contents'}->[-1];
+      #return ($current, $line, $source_info, $GET_A_NEW_LINE);
     } elsif ($line =~ /^(\s*?)\@end\s+([a-zA-Z][\w-]*)/
              and ($2 eq $current->{'cmdname'})) {
       my $end_command = $current->{'cmdname'};
+      #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);
+      #}
+
       $line =~ s/^(\s*?)\@end\s+$end_command//;
       if ($1 ne '') {
         $self->_line_warn(sprintf(
@@ -4949,19 +4984,13 @@ sub _process_remaining_on_line($$$$)
         if ($line =~ /\S/ and $line !~ /^\s*\@c(omment)?\b/);
       $current = $current->{'parent'};
       # Remove an ignored block @if*
-      my $conditional = _pop_element_from_contents($self, $current);
-      delete $conditional->{'parent'};
-      my $source_mark = {'sourcemark_type' => 'ignored_conditional_block',
-                         'element' => $conditional};
-      _register_source_mark($self, $current, $source_mark);
-      if (!defined($conditional->{'cmdname'}
-          or $conditional->{'cmdname'} ne $end_command)) {
-        $self->_bug_message(
-                "command mismatch for ignored block $end_command",
-                             $source_info, $conditional);
-        die;
-      }
+      _close_ignored_block_conditional($self, $current);
+
       print STDERR "CLOSED conditional $end_command\n" if ($self->{'DEBUG'});
+      # see comment above for raw output formats
+      #push @{$current->{'contents'}}, { 'type' => 'empty_line',
+      #                                  'text' => '',
+      #                                  'parent' => $current };
       # Ignore until end of line
       # FIXME this is not the same as for other commands.  Change?
       # FIXME only done once, could be needed more time.  Add test for this
@@ -4970,9 +4999,11 @@ sub _process_remaining_on_line($$$$)
         ($line, $source_info) = _new_line($self, $current);
         print STDERR "IGNORE CLOSE line: $line" if ($self->{'DEBUG'});
       }
+      #return ($current, $line, $source_info, $GET_A_NEW_LINE);
     } else {
       push @{$current->{'contents'}}, { 'type' => 'raw', 'text' => $line,
                                         'parent' => $current, };
+      #return ($current, $line, $source_info, $GET_A_NEW_LINE);
     }
     return ($current, $line, $source_info, $GET_A_NEW_LINE);
     # goto funexit;  # used in XS code
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 9bc76f841e..0be27beffd 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -349,6 +349,18 @@ pop_block_command_contexts (enum command_id cmd)
     }
 }
 
+void
+close_ignored_block_conditional (ELEMENT *current)
+{
+  SOURCE_MARK *source_mark
+    = new_source_mark (SM_type_ignored_conditional_block);
+  ELEMENT *conditional = pop_element_from_contents (current);
+
+  conditional->parent = 0;
+  source_mark->element = conditional;
+  register_source_mark (current, source_mark);
+}
+
 ELEMENT *
 close_current (ELEMENT *current,
                enum command_id closed_block_command,
@@ -357,7 +369,8 @@ close_current (ELEMENT *current,
   /* Element is a command */
   if (current->cmd)
     {
-      debug ("CLOSING (close_current) %s", command_name(current->cmd));
+      enum command_id cmd = current->cmd;
+      debug ("CLOSING (close_current) %s", command_name(cmd));
       if (command_flags(current) & CF_brace)
         {
           current = close_brace_command (current, closed_block_command,
@@ -365,37 +378,29 @@ close_current (ELEMENT *current,
         }
       else if (command_flags(current) & CF_block)
         {
-          enum command_id cmd = current->cmd;
-          ELEMENT *parent = 0;
           if (closed_block_command)
             {
               line_error ("`@end' expected `%s', but saw `%s'",
-                          command_name(current->cmd),
+                          command_name(cmd),
                           command_name(closed_block_command));
             }
           else if (interrupting_command)
             {
               line_error ("@%s seen before @end %s",
                           command_name(interrupting_command),
-                          command_name(current->cmd));
+                          command_name(cmd));
             }
           else
             {
               line_error ("no matching `@end %s'",
-                          command_name(current->cmd));
+                          command_name(cmd));
 
-              /* In ignored conditional. */
-              if (command_data(current->cmd).data == BLOCK_conditional)
-                {
-                  parent = current->parent;
-                  destroy_element_and_children (pop_element_from_contents
-                                                          (parent));
-                }
             }
           pop_block_command_contexts (cmd);
-          if (!parent)
-            parent = current->parent;
-          current = parent;
+          current = current->parent;
+          /* In ignored conditional. */
+          if (command_data(cmd).data == BLOCK_conditional)
+            close_ignored_block_conditional (current);
         }
       else
         {
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 026c958327..dc8db4e3e8 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1449,13 +1449,7 @@ process_remaining_on_line (ELEMENT **current_inout, char 
**line_inout)
           current = current->parent;
 
           /* Remove an ignored block. */
-          popped = pop_element_from_contents (current);
-          if (popped->cmd != end_cmd)
-            fatal ("command mismatch for ignored block");
-          popped->parent = 0;
-          source_mark = new_source_mark (SM_type_ignored_conditional_block);
-          source_mark->element = popped;
-          register_source_mark (current, source_mark);
+          close_ignored_block_conditional (current);
 
           /* 'line' is now advanced past the "@end ...".  Check if
              there's anything after it. */
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index 95e4baeb12..c122976b0e 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -122,6 +122,7 @@ ELEMENT *close_brace_command (ELEMENT *current,
                               enum command_id closed_block_command,
                               enum command_id interrupting_command,
                               int missing_brace);
+void close_ignored_block_conditional (ELEMENT *current);
 
 /* In end_line.c */
 NODE_SPEC_EXTRA *parse_node_manual (ELEMENT *node);
diff --git a/tp/t/results/conditionals/conditional_not_closed.pl 
b/tp/t/results/conditionals/conditional_not_closed.pl
index 2554da24c7..3d89d27d41 100644
--- a/tp/t/results/conditionals/conditional_not_closed.pl
+++ b/tp/t/results/conditionals/conditional_not_closed.pl
@@ -8,6 +8,43 @@ use utf8;
 $result_trees{'conditional_not_closed'} = {
   'contents' => [
     {
+      'contents' => [
+        {
+          'source_marks' => [
+            {
+              'counter' => 1,
+              'element' => {
+                'args' => [
+                  {
+                    'info' => {
+                      'spaces_after_argument' => {
+                        'text' => '
+'
+                      }
+                    },
+                    'type' => 'block_line_arg'
+                  }
+                ],
+                'cmdname' => 'ifhtml',
+                'contents' => [
+                  {
+                    'text' => 'in ifhtml
+',
+                    'type' => 'raw'
+                  }
+                ],
+                'source_info' => {
+                  'file_name' => '',
+                  'line_nr' => 1,
+                  'macro' => ''
+                }
+              },
+              'sourcemark_type' => 'ignored_conditional_block'
+            }
+          ],
+          'text' => ''
+        }
+      ],
       'type' => 'before_node_section'
     }
   ],
diff --git a/tp/t/results/conditionals/empty_ifset_in_ifset_no_set.pl 
b/tp/t/results/conditionals/empty_ifset_in_ifset_no_set.pl
index a008a5f9f6..b32451c31f 100644
--- a/tp/t/results/conditionals/empty_ifset_in_ifset_no_set.pl
+++ b/tp/t/results/conditionals/empty_ifset_in_ifset_no_set.pl
@@ -10,6 +10,66 @@ $result_trees{'empty_ifset_in_ifset_no_set'} = {
     {
       'contents' => [
         {
+          'source_marks' => [
+            {
+              'counter' => 2,
+              'element' => {
+                'args' => [
+                  {
+                    'contents' => [
+                      {
+                        'text' => 'notset'
+                      }
+                    ],
+                    'info' => {
+                      'spaces_after_argument' => {
+                        'text' => '
+'
+                      }
+                    },
+                    'type' => 'block_line_arg'
+                  }
+                ],
+                'cmdname' => 'ifset',
+                'contents' => [
+                  {
+                    'source_marks' => [
+                      {
+                        'counter' => 1,
+                        'element' => {
+                          'cmdname' => 'ifset',
+                          'contents' => [
+                            {
+                              'text' => '@end verbatim
+',
+                              'type' => 'raw'
+                            }
+                          ]
+                        },
+                        'position' => 10,
+                        'sourcemark_type' => 'ignored_conditional_block'
+                      }
+                    ],
+                    'text' => '@verbatim
+',
+                    'type' => 'raw'
+                  }
+                ],
+                'info' => {
+                  'spaces_before_argument' => {
+                    'text' => ' '
+                  }
+                },
+                'source_info' => {
+                  'file_name' => '',
+                  'line_nr' => 2,
+                  'macro' => ''
+                }
+              },
+              'position' => 1,
+              'sourcemark_type' => 'ignored_conditional_block'
+            }
+          ],
           'text' => '
 ',
           'type' => 'empty_line'
diff --git a/tp/t/results/invalid_nestings/ignored_text.pl 
b/tp/t/results/invalid_nestings/ignored_text.pl
index baebe67e38..226047574d 100644
--- a/tp/t/results/invalid_nestings/ignored_text.pl
+++ b/tp/t/results/invalid_nestings/ignored_text.pl
@@ -20,6 +20,32 @@ $result_trees{'ignored_text'} = {
           ],
           'info' => {
             'spaces_after_argument' => {
+              'source_marks' => [
+                {
+                  'counter' => 1,
+                  'element' => {
+                    'args' => [
+                      {
+                        'info' => {
+                          'spaces_after_argument' => {
+                            'text' => '
+'
+                          }
+                        },
+                        'type' => 'block_line_arg'
+                      }
+                    ],
+                    'cmdname' => 'ifinfo',
+                    'source_info' => {
+                      'file_name' => '',
+                      'line_nr' => 1,
+                      'macro' => ''
+                    }
+                  },
+                  'position' => 1,
+                  'sourcemark_type' => 'ignored_conditional_block'
+                }
+              ],
               'text' => ' '
             }
           },
diff --git a/tp/t/results/macro/ifset_and_end_isef_in_macro.pl 
b/tp/t/results/macro/ifset_and_end_isef_in_macro.pl
index 27e363e04d..cac0411cb7 100644
--- a/tp/t/results/macro/ifset_and_end_isef_in_macro.pl
+++ b/tp/t/results/macro/ifset_and_end_isef_in_macro.pl
@@ -141,6 +141,60 @@ $result_trees{'ifset_and_end_isef_in_macro'} = {
               'position' => 1,
               'sourcemark_type' => 'macro_expansion',
               'status' => 'start'
+            },
+            {
+              'counter' => 1,
+              'element' => {
+                'args' => [
+                  {
+                    'contents' => [
+                      {
+                        'source_marks' => [
+                          {
+                            'counter' => 1,
+                            'position' => 1,
+                            'sourcemark_type' => 'macro_expansion',
+                            'status' => 'end'
+                          }
+                        ],
+                        'text' => 'a'
+                      }
+                    ],
+                    'info' => {
+                      'spaces_after_argument' => {
+                        'text' => '
+'
+                      }
+                    },
+                    'type' => 'block_line_arg'
+                  }
+                ],
+                'cmdname' => 'ifset',
+                'contents' => [
+                  {
+                    'text' => 'in ifset
+',
+                    'type' => 'raw'
+                  },
+                  {
+                    'text' => '@endifset
+',
+                    'type' => 'raw'
+                  }
+                ],
+                'info' => {
+                  'spaces_before_argument' => {
+                    'text' => ' '
+                  }
+                },
+                'source_info' => {
+                  'file_name' => '',
+                  'line_nr' => 9,
+                  'macro' => 'beginifset'
+                }
+              },
+              'position' => 1,
+              'sourcemark_type' => 'ignored_conditional_block'
             }
           ],
           'text' => '



reply via email to

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