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 (%default_index_commands,


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Common.pm (%default_index_commands, %command_index), tp/Texinfo/ParserNonXS.pm (%default_no_paragraph_commands) (%default_valid_nestings): put two letter default @*index commands in hashes in Texinfo::Common and in the ParserNonXS.
Date: Sat, 15 Jan 2022 11:40:47 -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 eb2d374bee * tp/Texinfo/Common.pm (%default_index_commands, 
%command_index), tp/Texinfo/ParserNonXS.pm (%default_no_paragraph_commands) 
(%default_valid_nestings): put two letter default @*index commands in hashes in 
Texinfo::Common and in the ParserNonXS.
eb2d374bee is described below

commit eb2d374bee72b06c6300e2742eca902e0ae2dfa4
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Jan 15 17:40:36 2022 +0100

    * tp/Texinfo/Common.pm (%default_index_commands, %command_index),
    tp/Texinfo/ParserNonXS.pm (%default_no_paragraph_commands)
    (%default_valid_nestings): put two letter default @*index commands
    in hashes in Texinfo::Common and in the ParserNonXS.
    
    * tp/Texinfo/ParserNonXS.pm (parser, simple_parser)
    (_register_global_command): no dynamic 'global_commands', use directly
    %global_multiple_commands.
    
    * tp/Texinfo/ParserNonXS.pm (parser): ignore code setting user defined
    information, as it cannot happen now that the configuration keys are
    not in %parser_state_configuration anymore, and also because there is
    no such configuration possible in the XS parser.
---
 ChangeLog                 |  16 ++++++
 tp/Texinfo/Common.pm      |  23 ++++----
 tp/Texinfo/ParserNonXS.pm | 130 +++++++++++++++++++++++++---------------------
 3 files changed, 99 insertions(+), 70 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ad9b1aa785..e843e00dc2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2022-01-15  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Common.pm (%default_index_commands, %command_index),
+       tp/Texinfo/ParserNonXS.pm (%default_no_paragraph_commands)
+       (%default_valid_nestings): put two letter default @*index commands
+       in hashes in Texinfo::Common and in the ParserNonXS.
+
+       * tp/Texinfo/ParserNonXS.pm (parser, simple_parser)
+       (_register_global_command): no dynamic 'global_commands', use directly
+       %global_multiple_commands.
+
+       * tp/Texinfo/ParserNonXS.pm (parser): ignore code setting user defined
+       information, as it cannot happen now that the configuration keys are
+       not in %parser_state_configuration anymore, and also because there is
+       no such configuration possible in the XS parser.
+
 2022-01-15  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/ParserNonXS.pm (%parser_state_initialization, parser)
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index ee1bd21db7..7a5350c5ba 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -623,6 +623,12 @@ foreach my $in_index_command ('sortas', 'seeentry', 
'seealso', 'subentry') {
 }
 
 
+# Keys are commmands, values are names of indices.
+our %command_index;
+
+$command_index{'vtable'} = 'vr';
+$command_index{'ftable'} = 'fn';
+
 our %index_names = (
  'cp' => {'in_code' => 0},
  'fn' => {'in_code' => 1},
@@ -638,13 +644,12 @@ foreach my $index (keys(%index_names)) {
 }
 
 our %default_index_commands;
-# all the commands are readded dynamically in the Parser.
 foreach my $index_name (keys (%index_names)) {
-  if ($index_name =~ /^(.).$/) {
-    my $index_prefix = $1;
-    # only put the one letter versions in the hash.
-    $line_commands{$index_prefix.'index'} = 'line';
-    $default_index_commands{$index_prefix.'index'} = 1;
+  my $one_letter_prefix = substr($index_name, 0, 1);
+  foreach my $prefix ($index_name, $one_letter_prefix) {
+    $line_commands{$prefix.'index'} = 'line';
+    $default_index_commands{$prefix.'index'} = 1;
+    $command_index{$prefix.'index'} = $index_name;
   }
 }
 
@@ -839,12 +844,6 @@ my %index_type_def = (
  'tp' => ['deftp']
 );
 
-# Keys are commmands, values are names of indices.
-our %command_index;
-
-$command_index{'vtable'} = 'vr';
-$command_index{'ftable'} = 'fn';
-
 foreach my $index_type (keys %index_type_def) {
   foreach my $def (@{$index_type_def{$index_type}}) {
     $command_index{$def} = $index_type;
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index dca04b3d02..8c3a6390b4 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -322,23 +322,6 @@ foreach my $global_unique_command (
   $global_unique_commands{$global_unique_command} = 1;
 }
 
-my %index_names = %Texinfo::Common::index_names;
-
-# index names that cannot be set by the user.
-my %forbidden_index_name = ();
-
-foreach my $name (keys(%index_names)) {
-  $forbidden_index_name{$name} = 1;
-  if ($name =~ /^(.).$/) {
-    $forbidden_index_name{$1} = 1;
-  }
-}
-
-foreach my $other_forbidden_index_name ('info','ps','pdf','htm',
-   'html', 'log','aux','dvi','texi','txi','texinfo','tex','bib') {
-  $forbidden_index_name{$other_forbidden_index_name} = 1;
-}
-
 # @-commands that do not start a paragraph
 my %default_no_paragraph_commands;
 # @-commands that should be at the beginning of a line
@@ -528,6 +511,32 @@ foreach my $command (keys(%block_commands)) {
   }
 }
 
+# default indices
+my %index_names = %Texinfo::Common::index_names;
+
+# index names that cannot be set by the user.
+my %forbidden_index_name = ();
+
+foreach my $name (keys(%index_names)) {
+  $forbidden_index_name{$name} = 1;
+  if ($name =~ /^(.).$/) {
+    $forbidden_index_name{$1} = 1;
+  }
+}
+
+foreach my $index (keys(%index_names)) {
+  my $one_letter_prefix = substr($index, 0, 1);
+  foreach my $prefix ($index, $one_letter_prefix) {
+    $default_no_paragraph_commands{$prefix.'index'} = 1;
+    $default_valid_nestings{$prefix.'index'} = \%in_simple_text_commands;
+  }
+}
+
+foreach my $other_forbidden_index_name ('info','ps','pdf','htm',
+   'html', 'log','aux','dvi','texi','txi','texinfo','tex','bib') {
+  $forbidden_index_name{$other_forbidden_index_name} = 1;
+}
+
 # contexts on the context_stack stack where empty line doesn't trigger
 # a paragraph
 my %no_paragraph_contexts;
@@ -704,43 +713,49 @@ sub parser(;$$)
   $parser->{'close_paragraph_commands'} = {%close_paragraph_commands};
   $parser->{'close_preformatted_commands'} = {%close_preformatted_commands};
 
-  $parser->{'global_commands'} = {%global_multiple_commands};
-
+  
   # handle user provided state.
-  # REMARK the following code will not be used for user defined state
-  # if the corresponding key is ignored in _setup_conf() which is currently
-  # the case for the user provided informations in codes below.
-  #
-  # a hash is simply concatenated.  It should be like %index_names.
-  if (ref($parser->{'indices'}) eq 'HASH') {
-    %{$parser->{'index_names'}} = (%{$parser->{'index_names'}}, 
-                                   %{$parser->{'indices'}});
-  } else { # an array holds index names defined with @defindex
-    foreach my $name (@{$parser->{'indices'}}) {
-      $parser->{'index_names'}->{$name} = {'in_code' => 0};
-    }
-  }
-  foreach my $index (keys (%{$parser->{'index_names'}})) {
-    if (!exists($parser->{'index_names'}->{$index}->{'name'})) {
-      $parser->{'index_names'}->{$index}->{'name'} = $index;
-    }
-    if (!exists($parser->{'index_names'}->{$index}->{'contained_indices'})) {
-      $parser->{'index_names'}->{$index}->{'contained_indices'}->{$index} = 1;
+
+  # Currently not done, as none of the user provided configuration
+  # keys of interest are in %parser_state_configuration.  If this
+  # changes, the if (0) could be removed.  However, this setting of
+  # configuration is also not handled by the XS parser, which is
+  # again in favor of keeping the code ignored.
+  if (0) {
+    # REMARK the following code will not be used for user defined state
+    # if the corresponding key is ignored in _setup_conf()
+    #
+    # a hash is simply concatenated.  It should be like %index_names.
+    if (ref($parser->{'indices'}) eq 'HASH') {
+      %{$parser->{'index_names'}} = (%{$parser->{'index_names'}},
+                                     %{$parser->{'indices'}});
+    } else { # an array holds index names defined with @defindex
+      foreach my $name (@{$parser->{'indices'}}) {
+        $parser->{'index_names'}->{$name} = {'in_code' => 0};
+      }
     }
-    foreach my $prefix ($index, substr($index, 0, 1)) {
-      $parser->{'line_commands'}->{$prefix.'index'} = 'line';
-      $parser->{'no_paragraph_commands'}->{$prefix.'index'} = 1;
-      $parser->{'valid_nestings'}->{$prefix.'index'} = 
\%in_simple_text_commands;
-      $parser->{'command_index'}->{$prefix.'index'} = $index;
+    foreach my $index (keys (%{$parser->{'index_names'}})) {
+      if (!exists($parser->{'index_names'}->{$index}->{'name'})) {
+        $parser->{'index_names'}->{$index}->{'name'} = $index;
+      }
+      if (!exists($parser->{'index_names'}->{$index}->{'contained_indices'})) {
+        $parser->{'index_names'}->{$index}->{'contained_indices'}->{$index} = 
1;
+      }
+      foreach my $prefix ($index, substr($index, 0, 1)) {
+        $parser->{'line_commands'}->{$prefix.'index'} = 'line';
+        $parser->{'no_paragraph_commands'}->{$prefix.'index'} = 1;
+        $parser->{'valid_nestings'}->{$prefix.'index'} = 
\%in_simple_text_commands;
+        $parser->{'command_index'}->{$prefix.'index'} = $index;
+      }
     }
-  }
-  if ($parser->{'merged_indices'}) {
-    foreach my $index_from (keys (%{$parser->{'merged_indices'}})) {
-      my $index_to = $parser->{'merged_indices'}->{$index_from};
-      if (defined($parser->{'index_names'}->{$index_from})
-          and defined($parser->{'index_names'}->{$index_to})) {
-        $parser->{'index_names'}->{$index_from}->{'merged_in'} = $index_to;
-        
$parser->{'index_names'}->{$index_to}->{'contained_indices'}->{$index_from} = 1;
+    if ($parser->{'merged_indices'}) {
+      foreach my $index_from (keys (%{$parser->{'merged_indices'}})) {
+        my $index_to = $parser->{'merged_indices'}->{$index_from};
+        if (defined($parser->{'index_names'}->{$index_from})
+            and defined($parser->{'index_names'}->{$index_to})) {
+          $parser->{'index_names'}->{$index_from}->{'merged_in'} = $index_to;
+          
$parser->{'index_names'}->{$index_to}->{'contained_indices'}->{$index_from} = 1;
+        }
       }
     }
   }
@@ -761,9 +776,10 @@ sub parser(;$$)
   return $parser;
 }
 
-# simple parser initialization, fit for strings of Texinfo, not whole 
-# documents, targetting speed.
-# all the simple_parsers share the dynamic informations
+# simple parser initialization.  The only difference with a regular parser
+# is that the dynamical @-commands groups and indices informations that are
+# initialized in each regular parser are initialized once for all and shared
+# among simple parsers.
 my $simple_parser_line_commands = dclone(\%line_commands);
 my $simple_parser_valid_nestings = dclone(\%default_valid_nestings);
 my $simple_parser_no_paragraph_commands = { %default_no_paragraph_commands };
@@ -788,8 +804,6 @@ sub simple_parser(;$)
   $parser->{'close_paragraph_commands'} = 
$simple_parser_close_paragraph_commands;
   $parser->{'close_preformatted_commands'} = 
$simple_parser_close_preformatted_commands;
 
-  %{$parser->{'global_commands'}} = ();
-
   $parser->_init_context_stack();
 
   # turn the array to a hash for speed.  Not sure it really matters for such
@@ -1073,7 +1087,7 @@ sub registered_errors($)
 
 # Following are the internal subroutines.  The most important are
 # _parse_texi:  the main parser loop.
-# _end_line:    called at an end of line.  Handling of @include lines is 
+# _end_line:    called at an end of line.  Handling of @include lines is
 #               done here.
 # _next_text:   present the next text fragment, from pending text or line,
 #               as described above.
@@ -1125,7 +1139,7 @@ sub _register_global_command {
   if ($command eq 'summarycontents') {
     $command = 'shortcontents';
   }
-  if ($self->{'global_commands'}->{$command}) {
+  if ($global_multiple_commands{$command}) {
     push @{$self->{'commands_info'}->{$command}}, $current;
     $current->{'line_nr'} = $line_nr if (!$current->{'line_nr'});
     return 1;



reply via email to

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