texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Common.pm (%def_alias_commands), tp


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Common.pm (%def_alias_commands), tp/Texinfo/ParserNonXS.pm (_parse_def): add %def_alias_commands and use for consistency with XS parser.
Date: Sun, 02 Oct 2022 06:31:17 -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 7acca3c042 * tp/Texinfo/Common.pm (%def_alias_commands), 
tp/Texinfo/ParserNonXS.pm (_parse_def): add %def_alias_commands and use for 
consistency with XS parser.
7acca3c042 is described below

commit 7acca3c042e6db2002f5cba0c29a77a3b258bed2
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Oct 2 12:29:30 2022 +0200

    * tp/Texinfo/Common.pm (%def_alias_commands),
    tp/Texinfo/ParserNonXS.pm (_parse_def): add %def_alias_commands
    and use for consistency with XS parser.
    
    * tp/Texinfo/Common.pm, tp/Texinfo/Convert/HTML.pm
    (%HTML_align_commands), tp/Texinfo/ParserNonXS.pm: remove
    %region_commands and %align_commands.  Set %HTML_align_commands in
    HTML.pm as the set of align commands choosen is not generic.
    
    * tp/Texinfo/Common.pm (%block_commands): set align and other
    block commands to type 'other'.
    
    * tp/Texinfo/XS/parsetexi/command_data.txt,
    tp/Texinfo/XS/parsetexi/commands.h: add BLOCK_def for consistency
    with perl parser.
    
    * tp/Texinfo/ParserNonXS.pm (_pop_block_command_contexts)
    (_close_brace_command, _close_all_style_commands, _end_paragraph)
    (_end_preformatted, _close_current, _close_commands),
    tp/Texinfo/XS/parsetexi/close.c (pop_block_command_contexts)
    (close_brace_command, close_all_style_commands, close_current)
    (close_commands), tp/Texinfo/XS/parsetexi/parser.c (end_paragraph)
    (end_preformatted): add pop_block_command_contexts to pop block
    commands context when closing block commands.  Change variable names
    to closed_block_command to show that the argument can only be a block
    command.
---
 ChangeLog                                |  29 ++++++++
 tp/Texinfo/Common.pm                     |  45 +++++-------
 tp/Texinfo/Convert/HTML.pm               |  17 +++--
 tp/Texinfo/ParserNonXS.pm                | 115 +++++++++++++++---------------
 tp/Texinfo/XS/parsetexi/close.c          | 117 ++++++++++++++-----------------
 tp/Texinfo/XS/parsetexi/command_data.txt |  40 +++++------
 tp/Texinfo/XS/parsetexi/commands.h       |   6 +-
 tp/Texinfo/XS/parsetexi/parser.c         |  12 ++--
 tp/Texinfo/XS/parsetexi/parser.h         |  10 +--
 9 files changed, 203 insertions(+), 188 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e65006694c..829cc1e6ed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,35 @@
        * tp/Texinfo/Convert/LaTeX.pm (_convert) <@\>: Output as \backslash{}
        in math context.
 
+2022-10-02  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Common.pm (%def_alias_commands),
+       tp/Texinfo/ParserNonXS.pm (_parse_def): add %def_alias_commands
+       and use for consistency with XS parser.
+
+       * tp/Texinfo/Common.pm, tp/Texinfo/Convert/HTML.pm
+       (%HTML_align_commands), tp/Texinfo/ParserNonXS.pm: remove
+       %region_commands and %align_commands.  Set %HTML_align_commands in
+       HTML.pm as the set of align commands choosen is not generic.
+
+       * tp/Texinfo/Common.pm (%block_commands): set align and other
+       block commands to type 'other'.
+
+       * tp/Texinfo/XS/parsetexi/command_data.txt,
+       tp/Texinfo/XS/parsetexi/commands.h: add BLOCK_def for consistency
+       with perl parser.
+
+       * tp/Texinfo/ParserNonXS.pm (_pop_block_command_contexts)
+       (_close_brace_command, _close_all_style_commands, _end_paragraph)
+       (_end_preformatted, _close_current, _close_commands),
+       tp/Texinfo/XS/parsetexi/close.c (pop_block_command_contexts)
+       (close_brace_command, close_all_style_commands, close_current)
+       (close_commands), tp/Texinfo/XS/parsetexi/parser.c (end_paragraph)
+       (end_preformatted): add pop_block_command_contexts to pop block
+       commands context when closing block commands.  Change variable names
+       to closed_block_command to show that the argument can only be a block
+       command.
+
 2022-10-02  Patrice Dumas  <pertusus@free.fr>
 
        Warn if @| appears out of a heading specification
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index b0d0144fae..2e880958ee 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -902,6 +902,8 @@ foreach my $index_type (keys %index_type_def) {
 
 our %def_commands;
 our %def_aliases;
+# consistent with XS parser flag
+our %def_alias_commands;
 # Argument not metasyntactic variables only.
 our %def_no_var_arg_commands;
 foreach my $def_command(keys %def_map) {
@@ -910,6 +912,7 @@ foreach my $def_command(keys %def_map) {
     $command_index{$def_command} = $command_index{$real_command};
     $def_aliases{$def_command} = $real_command;
     $def_aliases{$def_command.'x'} = $real_command.'x';
+    $def_alias_commands{$def_command} = 1;
   }
   $block_commands{$def_command} = 'def';
   $line_commands{$def_command.'x'} = 'line';
@@ -927,25 +930,14 @@ foreach my $menu_command ('menu', 'detailmenu', 
'direntry') {
   $block_commands{$menu_command} = 'menu';
 };
 
-our %align_commands;
-foreach my $align_command('raggedright', 'flushleft', 'flushright') {
-  $block_commands{$align_command} = 'align';
-  $align_commands{$align_command} = 1;
+foreach my $align_command('raggedright', 'flushleft', 'flushright',
+   'indentedblock', 'smallindentedblock',
+   'cartouche', 'group') {
+  $block_commands{$align_command} = 'other';
 }
-$align_commands{'center'} = 1;
 
-foreach my $block_command('indentedblock', 'smallindentedblock') {
-  $block_commands{$block_command} = 'align';
-}
-
-foreach my $block_command('cartouche', 'group') {
-  $block_commands{$block_command} = 'other';
-}
-
-our %region_commands;
 foreach my $block_command('titlepage', 'copying', 'documentdescription') {
   $block_commands{$block_command} = 'region';
-  $region_commands{$block_command} = 1;
 }
 
 our %preformatted_commands;
@@ -1192,11 +1184,11 @@ foreach my $command (
 our %preamble_commands;
 foreach my $preamble_command ('direnty', 'hyphenation', 'errormsg',
        'inlineraw', '*', keys(%document_settable_at_commands),
-       (grep {$block_commands{$_} eq 'format_raw'} keys(%block_commands)),
+       (grep {$block_commands{$_} eq 'format_raw'
+              or $block_commands{$_} eq 'region'} keys(%block_commands)),
        keys(%inline_format_commands), keys(%inline_conditional_commands),
        keys(%unformatted_block_commands), keys(%line_commands),
-       keys(%nobrace_commands),
-       keys(%region_commands)) {
+       keys(%nobrace_commands)) {
   $preamble_commands{$preamble_command} = 1;
 }
 
@@ -2096,7 +2088,8 @@ sub find_parent_root_command($$)
     if ($current->{'cmdname'}) {
       if ($root_commands{$current->{'cmdname'}}) {
         return $current;
-      } elsif ($region_commands{$current->{'cmdname'}}) {
+      } elsif ($block_commands{$current->{'cmdname'}}
+               and $block_commands{$current->{'cmdname'}} eq 'region') {
         if ($current->{'cmdname'} eq 'copying' and $self
             and $self->{'global_commands'}
             and $self->{'global_commands'}->{'insertcopying'}) {
@@ -2983,11 +2976,6 @@ X<C<%accent_commands>>
 Accent @-commands taking an argument, like C<@'> or C<@ringaccent>,
 including C<@dotless> and C<@tieaccent>.
 
-=item %align_commands
-X<C<%align_commands>>
-
-@-commands related with alignement of text.
-
 =item %block_commands
 X<C<%block_commands>>
 
@@ -3025,6 +3013,10 @@ and C<@direntry>;
 
 C<@multitable>;
 
+=item I<other>
+
+The remaining block commands.
+
 =item I<raw>
 
 @-commands that have no expansion
@@ -3171,11 +3163,6 @@ X<C<%ref_commands>>
 
 Cross reference @-command referencing nodes, like C<@xref>.
 
-=item %region_commands
-X<C<%region_commands>>
-
-Block @-commands that enclose full text regions, like C<@titlepage>.
-
 =item %root_commands
 X<C<%root_commands>>
 
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 60526549b9..33f01ac1fe 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -114,8 +114,6 @@ my %inline_format_commands = 
%Texinfo::Common::inline_format_commands;
 my %brace_code_commands       = %Texinfo::Common::brace_code_commands;
 my %preformatted_code_commands = %Texinfo::Common::preformatted_code_commands;
 my %default_index_commands = %Texinfo::Common::default_index_commands;
-my %align_commands = %Texinfo::Common::align_commands;
-my %region_commands = %Texinfo::Common::region_commands;
 my %context_brace_commands = %Texinfo::Common::context_brace_commands;
 my %letter_no_arg_commands = %Texinfo::Common::letter_no_arg_commands;
 my %small_block_associated_command = 
%Texinfo::Common::small_block_associated_command;
@@ -131,8 +129,13 @@ foreach my $misc_context_command('tab', 'item', 'itemx', 
'headitem') {
   $format_context_commands{$misc_context_command} = 1;
 }
 
+my %HTML_align_commands;
+foreach my $align_command('raggedright', 'flushleft', 'flushright', 'center') {
+  $HTML_align_commands{$align_command} = 1;
+}
+
 my %composition_context_commands = (%preformatted_commands, %root_commands,
-  %align_commands);
+  %HTML_align_commands);
 $composition_context_commands{'float'} = 1;
 my %format_raw_commands;
 foreach my $block_command (keys(%block_commands)) {
@@ -145,6 +148,7 @@ foreach my $block_command (keys(%block_commands)) {
 # FIXME allow customization? (also in DocBook)
 my %upper_case_commands = ( 'sc' => 1 );
 
+
 # API for html formatting
 
 sub _collect_css_element_class($$)
@@ -581,7 +585,7 @@ sub in_align($)
   my $self = shift;
   my $context
        = $self->{'document_context'}->[-1]->{'composition_context'}->[-1];
-  if ($align_commands{$context}) {
+  if ($HTML_align_commands{$context}) {
     return $context;
   } else {
     return undef;
@@ -5407,7 +5411,7 @@ sub _convert_paragraph_type($$$$)
 
   if ($content =~ /\S/) {
     my $align = $self->in_align();
-    if ($align and $align_commands{$align}) {
+    if ($align and $HTML_align_commands{$align}) {
       return $self->html_attribute_class('p', [$align.'-paragraph']).">"
                              .$content."</p>";
     } else {
@@ -7642,7 +7646,8 @@ sub _html_get_tree_root_element($$;$)
         $root_command = $current;
         #print STDERR "CMD ROOT $current->{'cmdname'}\n" if ($debug);
         return ($root_element, $root_command) if defined($root_element);
-      } elsif ($region_commands{$current->{'cmdname'}}) {
+      } elsif ($block_commands{$current->{'cmdname'}}
+               and $block_commands{$current->{'cmdname'}} eq 'region') {
         if ($current->{'cmdname'} eq 'copying'
             and $self->{'global_commands'}
             and $self->{'global_commands'}->{'insertcopying'}) {
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 843c10ad76..b187939adb 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -147,7 +147,8 @@ my %parser_state_initialization = (
                               # as obtained by parsing the @macro
   'macro_stack' => [],        # stack of macros being expanded (more recent 
first)
   'merged_indices' => {},     # the key is merged in the value
-  'regions_stack' => [],      # a stack of regions commands elements (in 
%region_commands)
+  'regions_stack' => [],      # a stack of regions commands elements (block
+                              # region commands)
   'sections_level' => 0,      # modified by raise/lowersections
   'targets' => [],            # array of elements used to build 'labels'
   # initialization of information returned by global_information()
@@ -273,6 +274,7 @@ my %close_paragraph_commands  = 
%Texinfo::Common::close_paragraph_commands;
 my %def_map                   = %Texinfo::Common::def_map;
 my %def_commands              = %Texinfo::Common::def_commands;
 my %def_aliases               = %Texinfo::Common::def_aliases;
+my %def_alias_commands        = %Texinfo::Common::def_alias_commands;
 my %preformatted_commands     = %Texinfo::Common::preformatted_commands;
 my %math_commands             = %Texinfo::Common::math_commands;
 my %deprecated_commands       = %Texinfo::Common::deprecated_commands;
@@ -280,7 +282,6 @@ my %root_commands             = 
%Texinfo::Common::root_commands;
 my %sectioning_heading_commands     = 
%Texinfo::Common::sectioning_heading_commands;
 my %command_index             = %Texinfo::Common::command_index;
 my %ref_commands              = %Texinfo::Common::ref_commands;
-my %region_commands           = %Texinfo::Common::region_commands;
 my %heading_spec_commands     = %Texinfo::Common::heading_spec_commands;
 my %in_heading_spec_commands  = %Texinfo::Common::in_heading_spec_commands;
 my %in_index_commands         = %Texinfo::Common::in_index_commands;
@@ -1346,19 +1347,19 @@ sub _command_error($$$$;@)
   }
 }
 
-# currently doesn't do much more than
+# register error messages, but otherwise doesn't do much more than
 # return $_[1]->{'parent'}
 sub _close_brace_command($$$;$$)
 {
-  my ($self, $current, $source_info, $closed_command,
+  my ($self, $current, $source_info, $closed_block_command,
       $interrupting_command) = @_;
 
   if ($current->{'cmdname'} ne 'verb'
       or $current->{'extra'}->{'delimiter'} eq '') {
-    if (defined($closed_command)) {
+    if (defined($closed_block_command)) {
       $self->_command_error($current, $source_info,
         __("\@end %s seen before \@%s closing brace"),
-                  $closed_command, $current->{'cmdname'});
+                  $closed_block_command, $current->{'cmdname'});
     } elsif (defined($interrupting_command)) {
       $self->_command_error($current, $source_info,
         __("\@%s seen before \@%s closing brace"),
@@ -1417,7 +1418,7 @@ sub _kbd_formatted_as_code($$)
 # close brace commands, that don't set a new context (ie @caption, @footnote)
 sub _close_all_style_commands($$$;$$)
 {
-  my ($self, $current, $source_info, $closed_command,
+  my ($self, $current, $source_info, $closed_block_command,
       $interrupting_command) = @_;
 
   while ($current->{'parent'} and $current->{'parent'}->{'cmdname'}
@@ -1426,7 +1427,7 @@ sub _close_all_style_commands($$$;$$)
     print STDERR "CLOSING(_close_all_style_commands) 
\@$current->{'parent'}->{'cmdname'}\n"
          if ($self->{'DEBUG'});
     $current = _close_brace_command($self, $current->{'parent'}, $source_info,
-                                    $closed_command, $interrupting_command);
+                                    $closed_block_command, 
$interrupting_command);
   }
   return $current;
 }
@@ -1434,11 +1435,11 @@ sub _close_all_style_commands($$$;$$)
 # close brace commands except for @caption, @footnote then the paragraph
 sub _end_paragraph($$$;$$)
 {
-  my ($self, $current, $source_info, $closed_command,
+  my ($self, $current, $source_info, $closed_block_command,
       $interrupting_command) = @_;
 
   $current = _close_all_style_commands($self, $current, $source_info,
-                                       $closed_command, $interrupting_command);
+                                       $closed_block_command, 
$interrupting_command);
   if ($current->{'type'} and $current->{'type'} eq 'paragraph') {
     print STDERR "CLOSE PARA\n" if ($self->{'DEBUG'});
     $current = $current->{'parent'};
@@ -1449,11 +1450,11 @@ sub _end_paragraph($$$;$$)
 # close brace commands except for @caption, @footnote then the preformatted
 sub _end_preformatted($$$;$$)
 {
-  my ($self, $current, $source_info, $closed_command,
+  my ($self, $current, $source_info, $closed_block_command,
       $interrupting_command) = @_;
 
   $current = _close_all_style_commands($self, $current, $source_info,
-                                       $closed_command, $interrupting_command);
+                                       $closed_block_command, 
$interrupting_command);
 
   if ($current->{'type'} and $current->{'type'} eq 'preformatted') {
     print STDERR "CLOSE PREFORMATTED\n" if ($self->{'DEBUG'});
@@ -1757,13 +1758,34 @@ sub _close_command_cleanup($$) {
   }
 }
 
+sub _pop_block_command_contexts($$$;$)
+{
+  my $self = shift;
+  my $current = shift;
+  my $source_info = shift;
+  my $context_string = shift;
+  if ($preformatted_commands{$current->{'cmdname'}}
+      or $block_commands{$current->{'cmdname'}} eq 'menu') {
+    $self->_pop_context(['ct_preformatted'], $source_info, $current,
+                        $context_string);
+  } elsif ($block_commands{$current->{'cmdname'}} eq 'format_raw') {
+    $self->_pop_context(['ct_rawpreformatted'], $source_info, $current,
+                        $context_string);
+  } elsif ($math_commands{$current->{'cmdname'}}) {
+    $self->_pop_context(['ct_math'], $source_info, $current,
+                        $context_string);
+  } elsif ($block_commands{$current->{'cmdname'}} eq 'region') {
+    pop @{$self->{'regions_stack'}};
+  }
+}
+
 # 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
 # better error message.
 sub _close_current($$$;$$)
 {
-  my ($self, $current, $source_info, $closed_command,
+  my ($self, $current, $source_info, $closed_block_command,
       $interrupting_command) = @_;
 
   if ($current->{'cmdname'}) {
@@ -1780,11 +1802,11 @@ sub _close_current($$$;$$)
         $self->_pop_context([$expected_context], $source_info, $current);
       }
       $current = _close_brace_command($self, $current, $source_info,
-                                      $closed_command, $interrupting_command);
+                                      $closed_block_command, 
$interrupting_command);
     } elsif (exists($block_commands{$current->{'cmdname'}})) {
-      if (defined($closed_command)) {
+      if (defined($closed_block_command)) {
         $self->_line_error(sprintf(__("`\@end' expected `%s', but saw `%s'"),
-                                   $current->{'cmdname'}, $closed_command),
+                                   $current->{'cmdname'}, 
$closed_block_command),
                            $source_info);
       } elsif ($interrupting_command) {
         $self->_line_error(sprintf(__("\@%s seen before \@end %s"),
@@ -1799,16 +1821,7 @@ sub _close_current($$$;$$)
           _pop_element_from_contents($current->{'parent'});
         }
       }
-      if ($preformatted_commands{$current->{'cmdname'}}
-          or $block_commands{$current->{'cmdname'}} eq 'menu') {
-        $self->_pop_context(['ct_preformatted'], $source_info, $current);
-      } elsif ($block_commands{$current->{'cmdname'}} eq 'format_raw') {
-        $self->_pop_context(['ct_rawpreformatted'], $source_info, $current);
-      } elsif ($math_commands{$current->{'cmdname'}}) {
-        $self->_pop_context(['ct_math'], $source_info, $current);
-      }
-      pop @{$self->{'regions_stack'}}
-         if ($region_commands{$current->{'cmdname'}});
+      _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);
@@ -1859,17 +1872,17 @@ sub _close_current($$$;$$)
 # is found.
 sub _close_commands($$$;$$)
 {
-  my ($self, $current, $source_info, $closed_command,
+  my ($self, $current, $source_info, $closed_block_command,
       $interrupting_command) = @_;
 
-  $current = _end_paragraph($self, $current, $source_info, $closed_command,
-                            $interrupting_command);
-  $current = _end_preformatted($self, $current, $source_info, $closed_command,
-                               $interrupting_command);
+  $current = _end_paragraph($self, $current, $source_info,
+                            $closed_block_command, $interrupting_command);
+  $current = _end_preformatted($self, $current, $source_info,
+                               $closed_block_command, $interrupting_command);
 
         # stop if the command is found
-  while (!($closed_command and $current->{'cmdname'}
-           and $current->{'cmdname'} eq $closed_command)
+  while (!($closed_block_command and $current->{'cmdname'}
+           and $current->{'cmdname'} eq $closed_block_command)
          # Stop if at the root
          and $current->{'parent'}
          # Stop if at a type at the root
@@ -1877,40 +1890,29 @@ sub _close_commands($$$;$$)
                   and $current->{'type'} eq 'before_node_section')
      # Stop if in a root command
      # or in a context_brace_commands and searching for a specific
-     # end block command (with $closed_command set).
+     # end block command (with $closed_block_command set).
      # This second condition means that a footnote is not closed when
      # looking for the end of a block command, but is closed when
      # completly closing the stack.
          and !($current->{'cmdname'}
                and ($root_commands{$current->{'cmdname'}}
-                    or ($closed_command and $current->{'parent'}->{'cmdname'}
+                    or ($closed_block_command and 
$current->{'parent'}->{'cmdname'}
                        and 
$context_brace_commands{$current->{'parent'}->{'cmdname'}})))){
     _close_command_cleanup($self, $current);
-    $current = _close_current($self, $current, $source_info, $closed_command,
+    $current = _close_current($self, $current, $source_info, 
$closed_block_command,
                               $interrupting_command);
   }
 
   my $closed_element;
-  if ($closed_command and $current->{'cmdname'}
-      and $current->{'cmdname'} eq $closed_command) {
-    if ($preformatted_commands{$current->{'cmdname'}}
-        or $block_commands{$current->{'cmdname'}} eq 'menu') {
-      $self->_pop_context(['ct_preformatted'], $source_info, $current,
-                          "for $closed_command");
-    } elsif ($block_commands{$current->{'cmdname'}} eq 'format_raw') {
-      $self->_pop_context(['ct_rawpreformatted'], $source_info, $current,
-                          "for $closed_command");
-    } elsif ($math_commands{$current->{'cmdname'}}) {
-      $self->_pop_context(['ct_math'], $source_info, $current,
-                          "for $closed_command");
-    }
-    pop @{$self->{'regions_stack'}}
-       if ($region_commands{$current->{'cmdname'}});
+  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'};
-  } elsif ($closed_command) {
+  } elsif ($closed_block_command) {
     $self->_line_error(sprintf(__("unmatched `%c%s'"),
-                       ord('@'), "end $closed_command"), $source_info);
+                       ord('@'), "end $closed_block_command"), $source_info);
   }
   return ($closed_element, $current);
 }
@@ -2537,7 +2539,8 @@ sub _parse_def($$$)
   my @new_contents;
   my @contents = @$contents;
 
-  if ($def_aliases{$command}) {
+  # could have used def_aliases, but use code more similar with the XS parser
+  if ($def_alias_commands{$command}) {
     my $real_command = $def_aliases{$command};
     my $prepended = $def_map{$command}->{$real_command};
 
@@ -5105,7 +5108,7 @@ sub _process_remaining_on_line($$$$)
         } elsif ($block_commands{$command} eq 'format_raw') {
           $self->_push_context('ct_rawpreformatted', $command);
         }
-        if ($region_commands{$command}) {
+        if ($block_commands{$command} eq 'region') {
           if (@{$self->{'regions_stack'}}) {
             $self->_line_error(
         sprintf(__("region %s inside region %s is not allowed"),
@@ -5711,7 +5714,7 @@ sub _process_remaining_on_line($$$$)
     } elsif ($separator eq "\f" and $current->{'type'}
              and $current->{'type'} eq 'paragraph') {
       # form feed stops and restart a paragraph.
-      $current = $self->_end_paragraph($current);
+      $current = _end_paragraph($self, $current, $source_info);
       push @{$current->{'contents'}}, {'text' => $separator,
                                        'type' => 'empty_line',
                                         'parent' => $current };
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 86e27aff14..08b2113a08 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -23,7 +23,7 @@
 /* Possibly print an error message, and return CURRENT->parent. */
 static ELEMENT *
 close_brace_command (ELEMENT *current,
-                     enum command_id closed_command,
+                     enum command_id closed_block_command,
                      enum command_id interrupting_command)
 {
 
@@ -37,10 +37,10 @@ close_brace_command (ELEMENT *current,
   if (0)
     {
 yes:
-      if (closed_command)
+      if (closed_block_command)
         command_error (current,
                         "@end %s seen before @%s closing brace",
-                        command_name(closed_command),
+                        command_name(closed_block_command),
                         command_name(current->cmd));
       else if (interrupting_command)
         command_error (current,
@@ -67,14 +67,14 @@ yes:
    paragraphs. */
 ELEMENT *
 close_all_style_commands (ELEMENT *current,
-                          enum command_id closed_command,
+                          enum command_id closed_block_command,
                           enum command_id interrupting_command)
 {
   while (current->parent
          && (command_flags(current->parent) & CF_brace)
          && !(command_data(current->parent->cmd).data == BRACE_context))
     current = close_brace_command (current->parent,
-                                   closed_command, interrupting_command);
+                                   closed_block_command, interrupting_command);
 
   return current;
 }
@@ -235,9 +235,34 @@ close_command_cleanup (ELEMENT *current)
     }
 }
 
+void
+pop_block_command_contexts (enum command_id cmd)
+{
+  if (command_data(cmd).flags & CF_preformatted
+       || command_data(cmd).data == BLOCK_menu)
+    {
+      if (pop_context () != ct_preformatted)
+        fatal ("preformatted context expected");
+    }
+  else if (command_data(cmd).data == BLOCK_format_raw)
+    {
+      if (pop_context () != ct_rawpreformatted)
+        fatal ("rawpreformatted context expected");
+    }
+  else if (cmd == CM_displaymath)
+    {
+      if (pop_context () != ct_math)
+        fatal ("math context expected");
+    }
+  else if (command_data(cmd).data == BLOCK_region)
+    {
+      pop_region ();
+    }
+}
+
 ELEMENT *
 close_current (ELEMENT *current,
-               enum command_id closed_command,
+               enum command_id closed_block_command,
                enum command_id interrupting_command)
 {
   /* Element is a command */
@@ -256,18 +281,18 @@ close_current (ELEMENT *current,
               else if (pop_context () != ct_brace_command)
                 fatal ("context brace command context expected");
             }
-          current = close_brace_command (current,
-                                         closed_command, interrupting_command);
+          current = close_brace_command (current, closed_block_command,
+                                         interrupting_command);
         }
       else if (command_flags(current) & CF_block)
         {
           enum command_id cmd = current->cmd;
           ELEMENT *parent = 0;
-          if (closed_command)
+          if (closed_block_command)
             {
               line_error ("`@end' expected `%s', but saw `%s'",
                           command_name(current->cmd),
-                          command_name(closed_command));
+                          command_name(closed_block_command));
             }
           else if (interrupting_command)
             {
@@ -288,27 +313,7 @@ close_current (ELEMENT *current,
                                                           (parent));
                 }
             }
-          if (command_data(cmd).flags & CF_preformatted
-               || command_data(cmd).data == BLOCK_menu)
-            {
-              if (pop_context () != ct_preformatted)
-                fatal ("preformatted context expected");
-            }
-          else if (command_data(cmd).data == BLOCK_format_raw)
-            {
-              if (pop_context () != ct_rawpreformatted)
-                fatal ("rawpreformatted context expected");
-            }
-          else if (cmd == CM_displaymath)
-            {
-              if (pop_context () != ct_math)
-                fatal ("math context expected");
-            }
-
-          if (command_data(cmd).data == BLOCK_region)
-            {
-              pop_region ();
-            }
+          pop_block_command_contexts (cmd);
           if (!parent)
             parent = current->parent;
           current = parent;
@@ -376,60 +381,42 @@ close_current (ELEMENT *current,
   return current;
 }
 
-/* Return lowest level ancestor of CURRENT containing a CLOSED_COMMAND
-   element.  Set CLOSED_ELEMENT to the element itself.  INTERRUPTING is used 
in 
+/* Return lowest level ancestor of CURRENT containing a CLOSED_BLOCK_COMMAND
+   element, or the lowest level ancestor if CLOSED_BLOCK_COMMAND is 0.
+   Set CLOSED_BLOCK_ELEMENT to the last closed element.  INTERRUPTING is used 
in 
    close_brace_command to display an error message.  Remove a context from 
-   context stack if it was added by this command. */
+   context stack if CLOSED_BLOCK_COMMAND is not 0 and a context was added
+   by the CLOSED_BLOCK_COMMAND.
+   CLOSED_BLOCK_COMMAND should be the id of a block command.
+ */
 ELEMENT *
-close_commands (ELEMENT *current, enum command_id closed_command,
+close_commands (ELEMENT *current, enum command_id closed_block_command,
                 ELEMENT **closed_element, enum command_id interrupting)
 {
   *closed_element = 0;
-  current = end_paragraph (current, closed_command, interrupting);
-  current = end_preformatted (current, closed_command, interrupting);
+  current = end_paragraph (current, closed_block_command, interrupting);
+  current = end_preformatted (current, closed_block_command, interrupting);
 
   while (current->parent
-         && (!closed_command || current->cmd != closed_command)
+         && (!closed_block_command || current->cmd != closed_block_command)
      /* Stop if in a root command. */
          && !(current->cmd && command_flags(current) & CF_root)
      /* Stop if at a type at the root */
          && !(current->type == ET_before_node_section))
     {
       close_command_cleanup (current);
-      current = close_current (current, closed_command, interrupting);
+      current = close_current (current, closed_block_command, interrupting);
     }
 
-  if (closed_command && current->cmd == closed_command)
+  if (closed_block_command && current->cmd == closed_block_command)
     {
-      if (command_data(current->cmd).flags & CF_preformatted
-          || (command_data(current->cmd).flags & CF_block
-              && command_data(current->cmd).data == BLOCK_menu))
-        {
-          if (pop_context () != ct_preformatted)
-            fatal ("preformatted context expected");
-        }
-      else if (command_data(current->cmd).flags & CF_block
-               && command_data(current->cmd).data == BLOCK_format_raw)
-        {
-          if (pop_context () != ct_rawpreformatted)
-            fatal ("rawpreformatted context expected");
-        }
-      else if (current->cmd == CM_math || current->cmd == CM_displaymath)
-        {
-          if (pop_context () != ct_math)
-            fatal ("math context expected");
-        }
-
-      if (command_data(current->cmd).flags & CF_block
-          && command_data(current->cmd).data == BLOCK_region)
-        pop_region ();
-
+      pop_block_command_contexts (current->cmd);
       *closed_element = current;
       current = current->parent;
     }
-  else if (closed_command)
+  else if (closed_block_command)
     {
-      line_error ("unmatched `@end %s'", command_name(closed_command));
+      line_error ("unmatched `@end %s'", command_name(closed_block_command));
     }
 
   return current;
diff --git a/tp/Texinfo/XS/parsetexi/command_data.txt 
b/tp/Texinfo/XS/parsetexi/command_data.txt
index 775194ad77..a183b6323e 100644
--- a/tp/Texinfo/XS/parsetexi/command_data.txt
+++ b/tp/Texinfo/XS/parsetexi/command_data.txt
@@ -353,27 +353,27 @@ image                   brace                           
BRACE_arguments     5
 ##########################################################
 
 # def* commands
-deffn                   block,def
-defvr                   block,def
-deftypefn               block,def
-deftypeop               block,def
-deftypevr               block,def
-defcv                   block,def
-deftypecv               block,def
-defop                   block,def
-deftp                   block,def
+deffn                   block,def                       BLOCK_def
+defvr                   block,def                       BLOCK_def
+deftypefn               block,def                       BLOCK_def
+deftypeop               block,def                       BLOCK_def
+deftypevr               block,def                       BLOCK_def
+defcv                   block,def                       BLOCK_def
+deftypecv               block,def                       BLOCK_def
+defop                   block,def                       BLOCK_def
+deftp                   block,def                       BLOCK_def
 #   shortcuts
-defun                   block,def,def_alias
-defmac                  block,def,def_alias
-defspec                 block,def,def_alias
-defvar                  block,def,def_alias
-defopt                  block,def,def_alias
-deftypefun              block,def,def_alias
-deftypevar              block,def,def_alias
-defivar                 block,def,def_alias
-deftypeivar             block,def,def_alias
-defmethod               block,def,def_alias
-deftypemethod           block,def,def_alias
+defun                   block,def,def_alias             BLOCK_def
+defmac                  block,def,def_alias             BLOCK_def
+defspec                 block,def,def_alias             BLOCK_def
+defvar                  block,def,def_alias             BLOCK_def
+defopt                  block,def,def_alias             BLOCK_def
+deftypefun              block,def,def_alias             BLOCK_def
+deftypevar              block,def,def_alias             BLOCK_def
+defivar                 block,def,def_alias             BLOCK_def
+deftypeivar             block,def,def_alias             BLOCK_def
+defmethod               block,def,def_alias             BLOCK_def
+deftypemethod           block,def,def_alias             BLOCK_def
 
 # def*x
 deffnx                  line,def                        LINE_line
diff --git a/tp/Texinfo/XS/parsetexi/commands.h 
b/tp/Texinfo/XS/parsetexi/commands.h
index 278ef6a155..e6a8615725 100644
--- a/tp/Texinfo/XS/parsetexi/commands.h
+++ b/tp/Texinfo/XS/parsetexi/commands.h
@@ -107,7 +107,7 @@ void wipe_user_commands (void);
 #define LINE_text -6
 #define LINE_line -7
 
-/* Types of command without brace nor on line (has CF_nobrace flag). */
+/* Types of command without brace nor argument on line (has CF_nobrace flag). 
*/
 #define NOBRACE_symbol 0
 #define NOBRACE_skipspace -1
 #define NOBRACE_other -2
@@ -118,11 +118,15 @@ void wipe_user_commands (void);
 #define BLOCK_multitable -3
 #define BLOCK_region -4
 #define BLOCK_item_line -5
+/* not used in code but consistent with type in perl hash */
 #define BLOCK_item_container -6
+/* not used in code but consistent with type in perl hash */
 #define BLOCK_quotation -7
 #define BLOCK_float -8
 #define BLOCK_menu -9
 #define BLOCK_format_raw -10
+/* not used in code but consistent with type in perl hash */
+#define BLOCK_def -11
 
 /* Types of brace command (CF_brace). */
 #define BRACE_arguments 1
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 34e7420e45..77a0e74a42 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -492,11 +492,11 @@ begin_preformatted (ELEMENT *current)
 
 ELEMENT *
 end_paragraph (ELEMENT *current,
-               enum command_id closed_command,
+               enum command_id closed_block_command,
                enum command_id interrupting_command)
 {
-  current = close_all_style_commands (current,
-                                      closed_command, interrupting_command);
+  current = close_all_style_commands (current, closed_block_command,
+                                      interrupting_command);
   if (current->type == ET_paragraph)
     {
       debug ("CLOSE PARA");
@@ -508,11 +508,11 @@ end_paragraph (ELEMENT *current,
 
 ELEMENT *
 end_preformatted (ELEMENT *current,
-                  enum command_id closed_command,
+                  enum command_id closed_block_command,
                   enum command_id interrupting_command)
 {
-  current = close_all_style_commands (current,
-                                      closed_command, interrupting_command);
+  current = close_all_style_commands (current, closed_block_command,
+                                      interrupting_command);
   if (current->type == ET_preformatted)
     {
       debug ("CLOSE PREFORMATTED");
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index 814b8e60aa..d01d495a05 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -107,13 +107,13 @@ typedef struct GLOBAL_INFO {
 
 /* In close.c */
 void close_command_cleanup (ELEMENT *current);
-ELEMENT *close_commands (ELEMENT *current, enum command_id closed_command,
+ELEMENT *close_commands (ELEMENT *current, enum command_id 
closed_block_command,
                          ELEMENT **closed_element, enum command_id);
 ELEMENT *close_all_style_commands (ELEMENT *current,
-                               enum command_id closed_command,
+                               enum command_id closed_block_command,
                                enum command_id interrupting_command);
 ELEMENT *close_current (ELEMENT *current,
-                        enum command_id closed_command,
+                        enum command_id closed_block_command,
                         enum command_id interrupting_command);
 
 /* In end_line.c */
@@ -149,7 +149,7 @@ extern size_t conditional_number;
 ELEMENT *parse_texi_document (void);
 int abort_empty_line (ELEMENT **current_inout, char *additional);
 ELEMENT *end_paragraph (ELEMENT *current,
-                        enum command_id closed_command,
+                        enum command_id closed_block_command,
                         enum command_id interrupting_command);
 void isolate_last_space (ELEMENT *current);
 int kbd_formatted_as_code (ELEMENT *current);
@@ -157,7 +157,7 @@ int parent_of_command_as_argument (ELEMENT *current);
 void register_command_as_argument (ELEMENT *cmd_as_arg);
 ELEMENT *begin_preformatted (ELEMENT *current);
 ELEMENT *end_preformatted (ELEMENT *current,
-                           enum command_id closed_command,
+                           enum command_id closed_block_command,
                            enum command_id interrupting_command);
 char *read_command_name (char **ptr);
 char *read_flag_name (char **ptr);



reply via email to

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