* tp/Texinfo/ParserNonXS.pm (simple_parser): Add 'restricted'
flag on parser.
(_enter_index_entry): Do nothing if flag is set.  This prevents
index information leaking among simple_parser objects.
(simple_parser): Re-use indices information.

* tp/t/init/translation_in_parser_in_translation.pm:
Do not access index information from translation parser, as it
isn't there.
---
 ChangeLog                                     | 14 +++++++
 tp/Texinfo/ParserNonXS.pm                     |  9 ++++-
 .../translation_in_parser_in_translation.pm   | 39 -------------------
 .../res_html/chap.html                        |  2 +-
 .../res_html/index.html                       |  8 ++--
 5 files changed, 26 insertions(+), 46 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b50d9056e8..fec8ab7980 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2023-11-25  Gavin Smith <gavinsmith0...@gmail.com>
+
+       Parser 'restricted' flag
+
+       * tp/Texinfo/ParserNonXS.pm (simple_parser): Add 'restricted'
+       flag on parser.
+       (_enter_index_entry): Do nothing if flag is set.  This prevents
+       index information leaking among simple_parser objects.
+       (simple_parser): Re-use indices information.
+
+       * tp/t/init/translation_in_parser_in_translation.pm:
+       Do not access index information from translation parser, as it
+       isn't there.
+
 2023-11-25  Gavin Smith <gavinsmith0...@gmail.com>
 
        Re-add simple_parser
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 6a1a7ac2df..1c5bac1320 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -635,6 +635,10 @@ sub simple_parser(;$)
   my $parser = dclone(\%parser_default_configuration);
   bless $parser;
 
+  # Flag to say that some parts of the parser should not be modified,
+  # as they are reused among all parsers returned from this function.
+  $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"
@@ -644,8 +648,7 @@ sub simple_parser(;$)
   $parser->{'brace_commands'} = $simple_parser_brace_commands;
   $parser->{'valid_nestings'} = $simple_parser_valid_nestings;
   $parser->{'no_paragraph_commands'} = $simple_parser_no_paragraph_commands;
-  #$parser->{'index_names'} = $simple_parser_index_names;
-  $parser->{'index_names'} = dclone(\%index_names);
+  $parser->{'index_names'} = $simple_parser_index_names;
   $parser->{'command_index'} = $simple_parser_command_index;
   $parser->{'close_paragraph_commands'} = 
$simple_parser_close_paragraph_commands;
   $parser->{'close_preformatted_commands'} = 
$simple_parser_close_preformatted_commands;
@@ -3339,6 +3342,8 @@ sub _enter_index_entry($$$$)
 {
   my ($self, $command_container, $element, $source_info) = @_;
 
+  return if $self->{'restricted'};
+
   my $index_name = $self->{'command_index'}->{$command_container};
   my $index = $self->{'index_names'}->{$index_name};
 
diff --git a/tp/t/init/translation_in_parser_in_translation.pm 
b/tp/t/init/translation_in_parser_in_translation.pm
index 16b7d26a5a..737da26d4e 100644
--- a/tp/t/init/translation_in_parser_in_translation.pm
+++ b/tp/t/init/translation_in_parser_in_translation.pm
@@ -56,43 +56,4 @@ sub 
_texi2any_test_translation_in_parser_format_translate_message($$$;$)
 texinfo_register_formatting_function('format_translate_message',
        \&_texi2any_test_translation_in_parser_format_translate_message);
 
-# there are no indices id output for the @def* commands used in Next
-# button translation, as their index information is with the tree used
-# in gdt, not with the main tree.  Output an id in any case directly
-# when formatting the definition line to check if it is translated.
-sub _texi2any_tests_def_line_show_id($$$$)
-{
-  my $self = shift;
-  my $type = shift;
-  my $element = shift;
-  my $content = shift;
-
-  my $no_unidecode;
-  $no_unidecode = 1 if (defined($self->get_conf('USE_UNIDECODE'))
-                        and !$self->get_conf('USE_UNIDECODE'));
-
-
-  my $region = '';
-  $region = "$element->{'extra'}->{'element_region'}-"
-    if (defined($element->{'extra'}->{'element_region'}));
-
-  my $entry_reference_content_element
-        = Texinfo::Common::index_content_element($element);
-
-  my $normalized_index = '';
-  if ($entry_reference_content_element) {
-    $normalized_index =
-     Texinfo::Convert::NodeNameNormalization::normalize_transliterate_texinfo(
-        $entry_reference_content_element, $no_unidecode);
-  }
-  my $target_base = "index-" . $region .$normalized_index;
-
-
-  return "<strong>INDEXID could be: $target_base</strong>"
-       . &{$self->default_type_conversion($type)}($self, $type,
-                                                $element, $content);
-}
-
-texinfo_register_type_formatting('def_line', 
\&_texi2any_tests_def_line_show_id);
-
 1;
diff --git 
a/tp/t/results/init_files_tests/translation_in_parser_in_translation/res_html/chap.html
 
b/tp/t/results/init_files_tests/translation_in_parser_in_translation/res_html/chap.html
index cbd3b9843a..37ed412613 100644
--- 
a/tp/t/results/init_files_tests/translation_in_parser_in_translation/res_html/chap.html
+++ 
b/tp/t/results/init_files_tests/translation_in_parser_in_translation/res_html/chap.html
@@ -35,7 +35,7 @@ Pr&eacute;c&eacute;dent: <a href="index.html" accesskey="p" 
rel="prev">top</a>,
 <h2 class="chapter" id="Chap"><span>1 Chap<a class="copiable-link" 
href="#Chap"> &para;</a></span></h2>
 
 <dl class="first-deftypeop">
-<strong>INDEXID could be: index-dd-de-db</strong><dt class="deftypeop" 
id="index-dd-on-db"><span class="category-def">da de <code 
class="code">db</code>&nbsp;: </span><span><code class="def-type">dc</code> 
<strong class="def-name">dd</strong> <code 
class="def-code-arguments">de</code><a class="copiable-link" 
href="#index-dd-on-db"> &para;</a></span></dt>
+<dt class="deftypeop" id="index-dd-on-db"><span class="category-def">da de 
<code class="code">db</code>&nbsp;: </span><span><code 
class="def-type">dc</code> <strong class="def-name">dd</strong> <code 
class="def-code-arguments">de</code><a class="copiable-link" 
href="#index-dd-on-db"> &para;</a></span></dt>
 <dd><p>DOC
 </p></dd></dl>
 
diff --git 
a/tp/t/results/init_files_tests/translation_in_parser_in_translation/res_html/index.html
 
b/tp/t/results/init_files_tests/translation_in_parser_in_translation/res_html/index.html
index 8d59deda50..6487d23992 100644
--- 
a/tp/t/results/init_files_tests/translation_in_parser_in_translation/res_html/index.html
+++ 
b/tp/t/results/init_files_tests/translation_in_parser_in_translation/res_html/index.html
@@ -31,13 +31,13 @@ strong.def-name {font-family: monospace; font-weight: bold; 
font-size: larger}
 <p>
 
 <dl class="first-deftypeop">
-<strong>INDEXID could be: index-d-on-b</strong><dt class="deftypeop"><span 
class="category-def">a de <code class="code">b</code>&nbsp;: </span><code 
class="def-type">c</code> <strong class="def-name">d</strong> <code 
class="def-code-arguments">e f</code></dt>
+<dt class="deftypeop"><span class="category-def">a de <code 
class="code">b</code>&nbsp;: </span><code class="def-type">c</code> <strong 
class="def-name">d</strong> <code class="def-code-arguments">e f</code></dt>
 <dd><p>AA
 </p></dd></dl>
 
 
 <dl class="first-deftypeop first-deftypemethod-alias-first-deftypeop">
-<strong>INDEXID could be: index-i-de-g</strong><dt class="deftypeop 
deftypemethod-alias-deftypeop"><span class="category-def">M&eacute;thode de 
<code class="code">g</code>&nbsp;: </span><code class="def-type">h</code> 
<strong class="def-name">i</strong> <code class="def-code-arguments">j k 
l</code></dt>
+<dt class="deftypeop deftypemethod-alias-deftypeop"><span 
class="category-def">M&eacute;thode de <code class="code">g</code>&nbsp;: 
</span><code class="def-type">h</code> <strong class="def-name">i</strong> 
<code class="def-code-arguments">j k l</code></dt>
 <dd><p>BB
 </p></dd></dl>
 : <a href="chap.html" accesskey="n" rel="next">Chap</a> &nbsp; </p>
@@ -54,13 +54,13 @@ strong.def-name {font-family: monospace; font-weight: bold; 
font-size: larger}
 <p>
 
 <dl class="first-deftypeop">
-<strong>INDEXID could be: index-d-on-b</strong><dt class="deftypeop"><span 
class="category-def">a de <code class="code">b</code>&nbsp;: </span><code 
class="def-type">c</code> <strong class="def-name">d</strong> <code 
class="def-code-arguments">e f</code></dt>
+<dt class="deftypeop"><span class="category-def">a de <code 
class="code">b</code>&nbsp;: </span><code class="def-type">c</code> <strong 
class="def-name">d</strong> <code class="def-code-arguments">e f</code></dt>
 <dd><p>AA
 </p></dd></dl>
 
 
 <dl class="first-deftypeop first-deftypemethod-alias-first-deftypeop">
-<strong>INDEXID could be: index-i-de-g</strong><dt class="deftypeop 
deftypemethod-alias-deftypeop"><span class="category-def">M&eacute;thode de 
<code class="code">g</code>&nbsp;: </span><code class="def-type">h</code> 
<strong class="def-name">i</strong> <code class="def-code-arguments">j k 
l</code></dt>
+<dt class="deftypeop deftypemethod-alias-deftypeop"><span 
class="category-def">M&eacute;thode de <code class="code">g</code>&nbsp;: 
</span><code class="def-type">h</code> <strong class="def-name">i</strong> 
<code class="def-code-arguments">j k l</code></dt>
 <dd><p>BB
 </p></dd></dl>
 : <a href="chap.html" accesskey="n" rel="next">Chap</a> &nbsp; </p>
-- 
2.34.1


Reply via email to