texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Wed, 15 May 2024 14:30:48 -0400 (EDT)

branch: master
commit a55e8f14f4cf54bfff115de15b4177b9997a4bf9
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed May 15 20:30:31 2024 +0200

    * tp/Texinfo/ParserNonXS.pm (parser), tp/Texinfo/Translations.pm
    (_replace_convert_substrings), tp/Texinfo/XS/parsetexi/Parsetexi.pm:
    if restricted is set, do the initialization as in simple_parser.
    Remove simple_parser, a parser with restricted set is equivalent.
    Update _replace_convert_substrings to call parser and set restricted.
---
 ChangeLog                                         |   8 ++
 tp/Texinfo/ParserNonXS.pm                         | 104 +++++++---------------
 tp/Texinfo/Translations.pm                        |   6 +-
 tp/Texinfo/XS/parsetexi/Parsetexi.pm              |  11 ---
 tp/t/init/translation_in_parser_in_translation.pm |   2 +-
 5 files changed, 46 insertions(+), 85 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 82c93d77f6..4bf255ef70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-05-15  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (parser), tp/Texinfo/Translations.pm
+       (_replace_convert_substrings), tp/Texinfo/XS/parsetexi/Parsetexi.pm:
+       if restricted is set, do the initialization as in simple_parser.
+       Remove simple_parser, a parser with restricted set is equivalent.
+       Update _replace_convert_substrings to call parser and set restricted.
+
 2024-05-14  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/ParserNonXS.pm (parse_texi_piece, parse_texi_line)
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index f3172473ec..66c1f381bf 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -575,79 +575,40 @@ sub parser(;$$)
   print STDERR "!!!!!!!!!!!!!!!! RESETTING THE PARSER !!!!!!!!!!!!!!!!!!!!!\n"
     if ($parser->{'DEBUG'});
 
-  # Initialize command hash that are dynamically modified, notably
-  # those for index commands, and definoenclose, based on defaults
-  $parser->{'line_commands'} = dclone(\%line_commands);
-  $parser->{'brace_commands'} = dclone(\%brace_commands);
-  $parser->{'valid_nestings'} = dclone(\%default_valid_nestings);
-  $parser->{'no_paragraph_commands'} = {%no_paragraph_commands};
-  $parser->{'index_names'} = dclone(\%index_names);
-  $parser->{'command_index'} = {%command_index};
-  $parser->{'index_entry_commands'} = {%index_entry_command_commands};
-  $parser->{'close_paragraph_commands'} = {%close_paragraph_commands};
-  $parser->{'close_preformatted_commands'} = {%close_preformatted_commands};
-  $parser->{'basic_inline_commands'} = {%contain_basic_inline_commands};
-
-  # following is common with simple_parser
-  # other initializations
-  $parser->{'definfoenclose'} = {};
-  $parser->{'source_mark_counters'} = {};
-  $parser->{'nesting_context'} = {%nesting_context_init};
-  $parser->{'nesting_context'}->{'basic_inline_stack'} = [];
-  $parser->{'nesting_context'}->{'basic_inline_stack_on_line'} = [];
-  $parser->{'nesting_context'}->{'basic_inline_stack_block'} = [];
-  $parser->{'nesting_context'}->{'regions_stack'} = [];
-
-  $parser->_init_context_stack();
-
-  # turn the array to a hash for speed.  Not sure it really matters for such
-  # a small array.
-  $parser->{'expanded_formats_hash'} = {};
-  foreach my $expanded_format(@{$parser->{'EXPANDED_FORMATS'}}) {
-    $parser->{'expanded_formats_hash'}->{$expanded_format} = 1;
-  }
-
-  if (not defined($parser->{'registrar'})) {
-    $parser->{'registrar'} = Texinfo::Report::new();
+  if (!$self->{'restricted'}) {
+    # Initialize command hash that are dynamically modified, notably
+    # those for index commands, and definoenclose, based on defaults
+    $parser->{'line_commands'} = dclone(\%line_commands);
+    $parser->{'brace_commands'} = dclone(\%brace_commands);
+    $parser->{'valid_nestings'} = dclone(\%default_valid_nestings);
+    $parser->{'no_paragraph_commands'} = {%no_paragraph_commands};
+    $parser->{'index_names'} = dclone(\%index_names);
+    $parser->{'command_index'} = {%command_index};
+    $parser->{'index_entry_commands'} = {%index_entry_command_commands};
+    $parser->{'close_paragraph_commands'} = {%close_paragraph_commands};
+    $parser->{'close_preformatted_commands'} = {%close_preformatted_commands};
+    $parser->{'basic_inline_commands'} = {%contain_basic_inline_commands};
+  } else {
+    # in a restricted parser, new commands are not defined (no user-defined
+    # macros, alias, no new index commands), and index entries are not set.
+    # Therefore, the default data can be used as it won't be modified and most
+    # indices information is not needed at all.  It is used in gdt() and this
+    # has a sizable effect on performance.
+
+    $parser->{'line_commands'} = \%line_commands;
+    $parser->{'brace_commands'} = \%brace_commands;
+    $parser->{'valid_nestings'} = \%default_valid_nestings;
+    $parser->{'no_paragraph_commands'} = \%no_paragraph_commands;
+    # not needed, but not undef because it is exported to document
+    $parser->{'index_names'} = {};
+    # not needed
+    #$parser->{'command_index'} = {};
+    $parser->{'index_entry_commands'} = \%index_entry_command_commands;
+    $parser->{'close_paragraph_commands'} = \%close_paragraph_commands;
+    $parser->{'close_preformatted_commands'} = \%close_preformatted_commands;
+    $parser->{'basic_inline_commands'} = \%contain_basic_inline_commands;
   }
 
-  return $parser;
-}
-
-# simple parser initialization.  A simple parser is a restricted parser,
-# in which new commands are not defined (no user-defined macros, alias,
-# no new index commands), and index entries are not set.  Therefore,
-# the default data can be used as it won't be modified and most
-# indices information is not needed at all.  It is used in gdt() and this
-# has a sizable effect on performance.
-sub simple_parser(;$)
-{
-  my $conf = shift;
-
-  my $parser = dclone(\%parser_default_configuration);
-  bless $parser;
-
-  # Flag to say that some parts of the parser should not be modified.
-  $parser->{'restricted'} = 1;
-
-  _setup_conf($parser, $conf);
-  # This is not very useful in perl, but mimics the XS parser
-  print STDERR "!!!!!!!!!!!!!!!! RESETTING THE PARSER !!!!!!!!!!!!!!!!!!!!!\n"
-    if ($parser->{'DEBUG'});
-
-  $parser->{'line_commands'} = \%line_commands;
-  $parser->{'brace_commands'} = \%brace_commands;
-  $parser->{'valid_nestings'} = \%default_valid_nestings;
-  $parser->{'no_paragraph_commands'} = \%no_paragraph_commands;
-  # not needed, but not undef because it is exported to document
-  $parser->{'index_names'} = {};
-  # not needed
-  #$parser->{'command_index'} = {};
-  $parser->{'index_entry_commands'} = \%index_entry_command_commands;
-  $parser->{'close_paragraph_commands'} = \%close_paragraph_commands;
-  $parser->{'close_preformatted_commands'} = \%close_preformatted_commands;
-  $parser->{'basic_inline_commands'} = \%contain_basic_inline_commands;
-
   # other initializations
   $parser->{'definfoenclose'} = {};
   $parser->{'source_mark_counters'} = {};
@@ -661,6 +622,7 @@ sub simple_parser(;$)
 
   # turn the array to a hash for speed.  Not sure it really matters for such
   # a small array.
+  $parser->{'expanded_formats_hash'} = {};
   foreach my $expanded_format(@{$parser->{'EXPANDED_FORMATS'}}) {
     $parser->{'expanded_formats_hash'}->{$expanded_format} = 1;
   }
diff --git a/tp/Texinfo/Translations.pm b/tp/Texinfo/Translations.pm
index 7e7f07c4d0..f30051e512 100644
--- a/tp/Texinfo/Translations.pm
+++ b/tp/Texinfo/Translations.pm
@@ -310,7 +310,9 @@ sub _replace_convert_substrings($;$$)
 
   # accept @txiinternalvalue as a valid Texinfo command, used to mark
   # location in tree of substituted brace enclosed strings.
-  my $parser_conf = {'accept_internalvalue' => 1};
+  my $parser_conf = {'accept_internalvalue' => 1,
+           # Flag to say that some parts of the parser should not be modified.
+                     'restricted' => 1};
 
   # set parser debug level to one less than $debug_level
   if (defined($debug_level)) {
@@ -320,7 +322,7 @@ sub _replace_convert_substrings($;$$)
     }
     $parser_conf->{'DEBUG'} = $parser_debug_level;
   }
-  my $parser = Texinfo::Parser::simple_parser($parser_conf);
+  my $parser = Texinfo::Parser::parser($parser_conf);
 
   if ($debug_level) {
     print STDERR "IN TR PARSER '$texinfo_line'\n";
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm 
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index f3f8d3b806..cf8b21cbd2 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -60,17 +60,6 @@ sub get_conf($$)
   return $self->{'conf'}->{$var};
 }
 
-sub simple_parser {
-  my $conf = shift;
-
-  my $new_conf = {'restricted' => 1};
-  if ($conf) {
-    %$new_conf = (%$new_conf, %$conf);
-  }
-
-  return parser($new_conf);
-}
-
 # Initialize the parser
 sub parser (;$$)
 {
diff --git a/tp/t/init/translation_in_parser_in_translation.pm 
b/tp/t/init/translation_in_parser_in_translation.pm
index 0cced69dbe..c698281026 100644
--- a/tp/t/init/translation_in_parser_in_translation.pm
+++ b/tp/t/init/translation_in_parser_in_translation.pm
@@ -10,7 +10,7 @@ use Texinfo::Convert::NodeNameNormalization;
 
 # a translation of the Next button for which there is a translation
 # by the parser of index of @def* commands like '{name} of {class}'.
-# also test commands in simple_parser restricted mode.
+# also test commands in parser restricted mode.
 my %translations = (
   'fr' => {
            'Next' => {'NodeNext direction string'



reply via email to

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