[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Mon, 13 May 2024 13:50:46 -0400 (EDT) |
branch: master
commit d3bfb8d02abebe7d316a78e70221d2e9cccf18d7
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon May 13 12:30:15 2024 +0200
* tp/Texinfo/ParserNonXS.pm (_end_line_misc_line): use command names
instead of %command_index for @*table commands and @def* commands
with index entries names, for clearer a code, a code more similar to C
and to avoid using %command_index for something else that associating
an index to a command.
* tp/Texinfo/ParserNonXS.pm (_parse_line_command_args),
tp/Texinfo/XS/parsetexi/end_line.c (parse_line_command_args): do not
set synindex, syncodeindex and printindex arguments if in restricted
parser.
* tp/Texinfo/XS/main/translations.c (replace_convert_substrings): set
restricted on the parser used for translations to be in restricted
mode as if simple_parser had been called from Perl.
* tp/Texinfo/XS/main/build_perl_info.c (build_index_data),
tp/Texinfo/XS/parsetexi/indices.c (resolve_indices_merged_in)
(complete_indices): handle the case of no indices at all.
* tp/Texinfo/XS/parsetexi/api.c (reset_parser_except_conf),
tp/Texinfo/XS/parsetexi/parser.c (parse_texi):
* tp/Texinfo/XS/parsetexi/indices.c (init_index_commands)
(forget_indices): set num_index_commands and number_of_indices to 0 in
forget_indices only.
* tp/t/init/translation_in_parser_in_translation.pm: test more
index related functions in gdt/parse_texi_line.
---
ChangeLog | 31 +++++++++
tp/TODO | 7 ---
tp/Texinfo/ParserNonXS.pm | 73 +++++++++++++---------
tp/Texinfo/XS/main/build_perl_info.c | 10 ++-
tp/Texinfo/XS/main/translations.c | 1 +
tp/Texinfo/XS/parsetexi/api.c | 1 -
tp/Texinfo/XS/parsetexi/end_line.c | 9 +++
tp/Texinfo/XS/parsetexi/indices.c | 33 +++++++---
tp/Texinfo/XS/parsetexi/parser.c | 6 ++
tp/t/init/translation_in_parser_in_translation.pm | 17 +++++
.../res_html/index.html | 8 +++
11 files changed, 149 insertions(+), 47 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d081034647..c146a29bd5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+2024-05-13 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/ParserNonXS.pm (_end_line_misc_line): use command names
+ instead of %command_index for @*table commands and @def* commands
+ with index entries names, for clearer a code, a code more similar to C
+ and to avoid using %command_index for something else that associating
+ an index to a command.
+
+ * tp/Texinfo/ParserNonXS.pm (_parse_line_command_args),
+ tp/Texinfo/XS/parsetexi/end_line.c (parse_line_command_args): do not
+ set synindex, syncodeindex and printindex arguments if in restricted
+ parser.
+
+ * tp/Texinfo/XS/main/translations.c (replace_convert_substrings): set
+ restricted on the parser used for translations to be in restricted
+ mode as if simple_parser had been called from Perl.
+
+ * tp/Texinfo/XS/main/build_perl_info.c (build_index_data),
+ tp/Texinfo/XS/parsetexi/indices.c (resolve_indices_merged_in)
+ (complete_indices): handle the case of no indices at all.
+
+ * tp/Texinfo/XS/parsetexi/api.c (reset_parser_except_conf),
+ tp/Texinfo/XS/parsetexi/parser.c (parse_texi):
+
+ * tp/Texinfo/XS/parsetexi/indices.c (init_index_commands)
+ (forget_indices): set num_index_commands and number_of_indices to 0 in
+ forget_indices only.
+
+ * tp/t/init/translation_in_parser_in_translation.pm: test more
+ index related functions in gdt/parse_texi_line.
+
2024-05-11 Patrice Dumas <pertusus@free.fr>
Handle default index commands similarly to other @-commands
diff --git a/tp/TODO b/tp/TODO
index 2b5cd6b461..d637abfcaf 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -114,13 +114,6 @@ Could be interesting for find_string:
unique_target -> find_string
(and, though much less used output_files_open_out -> find_string)
-Other possibility for optimisation (small expected gain except may be for
-manuals with lots of translations, for instance lots of @def needing a
-translation), do something similar as in Perl with shared index information
-when parser is called from gdt/convert_substring, through simple_parser, to
-avoid the init_index_command call and instead share indices and only reset
-them.
-
Another possibility for optimization would be to call Perl less, as it
still uses about 40% of the time (for html) even though it should mainly be
for code called once (and not for Perl functions called from C).
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 979e5425bc..bbdac70e76 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -620,7 +620,11 @@ my $simple_parser_line_commands = dclone(\%line_commands);
my $simple_parser_brace_commands = dclone(\%brace_commands);
my $simple_parser_valid_nestings = dclone(\%default_valid_nestings);
my $simple_parser_no_paragraph_commands = {%no_paragraph_commands};
-my $simple_parser_index_names = dclone(\%index_names);
+#my $simple_parser_index_names = dclone(\%index_names);
+# Same as in XS, no indices, all the indices commands are ignored with
+# restricted.
+my $simple_parser_index_names = {};
+# FIXME make it empty as in the XS parser
my $simple_parser_command_index = {%command_index};
my $simple_parser_close_paragraph_commands = {%close_paragraph_commands};
my $simple_parser_close_preformatted_commands = {%close_preformatted_commands};
@@ -3794,7 +3798,8 @@ sub _end_line_misc_line($$$)
} else {
if (($command eq 'item' or $command eq 'itemx')
and $current->{'parent'}->{'cmdname'}
- and $self->{'command_index'}->{$current->{'parent'}->{'cmdname'}}) {
+ and ($current->{'parent'}->{'cmdname'} eq 'ftable'
+ or $current->{'parent'}->{'cmdname'} eq 'vtable') {
_enter_index_entry($self, $current->{'parent'}->{'cmdname'},
$current, $source_info);
} elsif ($self->{'command_index'}->{$current->{'cmdname'}}) {
@@ -3994,9 +3999,12 @@ sub _end_line_def_line($$$)
# in order to avoid calling gdt.
# We need to store the language as well in case there are multiple
# languages in the document.
- if ($command_index{$def_command} eq 'fn'
- or $command_index{$def_command} eq 'vr'
- and $def_command ne 'defcv') {
+ if ($def_command eq 'defop'
+ or $def_command eq 'defmethod'
+ or $def_command eq 'deftypemethod'
+ or $def_command eq 'defivar'
+ or $def_command eq 'deftypeivar'
+ or $def_command eq 'deftypecv') {
undef $index_entry;
if (defined($self->{'documentlanguage'})) {
$current->{'extra'}->{'documentlanguage'}
@@ -7861,30 +7869,35 @@ sub _parse_line_command_args($$$)
} elsif ($command eq 'synindex' || $command eq 'syncodeindex') {
# REMACRO
if ($line =~
/^([[:alnum:]][[:alnum:]\-]*)\s+([[:alnum:]][[:alnum:]\-]*)$/) {
- my $index_name_from = $1;
- my $index_name_to = $2;
- my $index_from = $self->{'index_names'}->{$index_name_from};
- my $index_to = $self->{'index_names'}->{$index_name_to};
- $self->_line_error(sprintf(__("unknown source index in \@%s: %s"),
- $command, $index_name_from), $source_info)
- unless $index_from;
- $self->_line_error(sprintf(__("unknown destination index in \@%s: %s"),
- $command, $index_name_to), $source_info)
- unless $index_to;
- if ($index_from and $index_to) {
- my $current_to =
Texinfo::Common::ultimate_index($self->{'index_names'},
+ if ($self->{'restricted'}) {
+ # do nothing
+ } else {
+ my $index_name_from = $1;
+ my $index_name_to = $2;
+ my $index_from = $self->{'index_names'}->{$index_name_from};
+ my $index_to = $self->{'index_names'}->{$index_name_to};
+ $self->_line_error(sprintf(__("unknown source index in \@%s: %s"),
+ $command, $index_name_from), $source_info)
+ unless $index_from;
+ $self->_line_error(sprintf(__("unknown destination index in \@%s: %s"),
+ $command, $index_name_to), $source_info)
+ unless $index_to;
+ if ($index_from and $index_to) {
+ my $current_to
+ = Texinfo::Common::ultimate_index($self->{'index_names'},
$index_to);
- # find the merged indices recursively avoiding loops
- if ($current_to->{'name'} ne $index_name_from) {
- my $in_code = 0;
- $in_code = 1 if ($command eq 'syncodeindex');
- $index_from->{'in_code'} = $in_code;
- $index_from->{'merged_in'} = $current_to->{'name'};
- $args = [$index_name_from, $index_name_to];
- } else {
- $self->_line_warn(sprintf(__(
- "\@%s leads to a merging of %s in itself, ignoring"),
- $command, $index_name_from), $source_info);
+ # find the merged indices recursively avoiding loops
+ if ($current_to->{'name'} ne $index_name_from) {
+ my $in_code = 0;
+ $in_code = 1 if ($command eq 'syncodeindex');
+ $index_from->{'in_code'} = $in_code;
+ $index_from->{'merged_in'} = $current_to->{'name'};
+ $args = [$index_name_from, $index_name_to];
+ } else {
+ $self->_line_warn(sprintf(__(
+ "\@%s leads to a merging of %s in itself,
ignoring"),
+ $command, $index_name_from), $source_info);
+ }
}
}
} else {
@@ -7892,8 +7905,10 @@ sub _parse_line_command_args($$$)
$command, $line), $source_info);
}
} elsif ($command eq 'printindex') {
+ if ($self->{'restricted'}) {
+ # do nothing
# REMACRO
- if ($line =~ /^([[:alnum:]][[:alnum:]\-]*)$/) {
+ } elsif ($line =~ /^([[:alnum:]][[:alnum:]\-]*)$/) {
my $name = $1;
if (!exists($self->{'index_names'}->{$name})) {
$self->_line_error(sprintf(__("unknown index `%s' in \@printindex"),
diff --git a/tp/Texinfo/XS/main/build_perl_info.c
b/tp/Texinfo/XS/main/build_perl_info.c
index f8dff7f7c0..021f6ce48e 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -942,10 +942,14 @@ build_index_data (INDEX **index_names_in)
hv = newHV ();
- for (i = index_names_in; (idx = *i); i++)
+ if (index_names_in)
{
- HV *hv2 = build_single_index_data (idx);
- hv_store (hv, idx->name, strlen (idx->name), newRV_noinc ((SV *)hv2), 0);
+ for (i = index_names_in; (idx = *i); i++)
+ {
+ HV *hv2 = build_single_index_data (idx);
+ hv_store (hv, idx->name, strlen (idx->name),
+ newRV_noinc ((SV *)hv2), 0);
+ }
}
return hv;
diff --git a/tp/Texinfo/XS/main/translations.c
b/tp/Texinfo/XS/main/translations.c
index 684858e683..c29e94d0a1 100644
--- a/tp/Texinfo/XS/main/translations.c
+++ b/tp/Texinfo/XS/main/translations.c
@@ -474,6 +474,7 @@ replace_convert_substrings (char *translated_string,
location in tree of substituted brace enclosed strings.
*/
parser_set_accept_internalvalue (1);
+ parser_set_restricted (1);
document_descriptor = parse_string (texinfo_line, 1);
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 4cddc45b78..76c95e6517 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -74,7 +74,6 @@ reset_parser_except_conf (void)
*/
wipe_index_names (index_names);
forget_indices ();
- init_index_commands ();
wipe_identifiers_target ();
reset_context_stack ();
reset_command_stack (&nesting_context.basic_inline_stack);
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c
b/tp/Texinfo/XS/parsetexi/end_line.c
index 33cef11882..189bff28da 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -401,6 +401,13 @@ parse_line_command_args (ELEMENT *line_command)
if (*p)
goto synindex_invalid; /* More at end of line. */
+ if (global_restricted)
+ {
+ free (index_name_from);
+ free (index_name_to);
+ break;
+ }
+
from_index = indices_info_index_by_name (index_names, index_name_from);
to_index = indices_info_index_by_name (index_names, index_name_to);
if (!from_index)
@@ -448,6 +455,8 @@ parse_line_command_args (ELEMENT *line_command)
arg = read_command_name (&p);
if (!arg || *p)
line_error ("bad argument to @printindex: %s", line);
+ else if (global_restricted)
+ {}
else
{
INDEX *idx = indices_info_index_by_name (index_names,arg);
diff --git a/tp/Texinfo/XS/parsetexi/indices.c
b/tp/Texinfo/XS/parsetexi/indices.c
index f2fccaf695..1d40aaeddf 100644
--- a/tp/Texinfo/XS/parsetexi/indices.c
+++ b/tp/Texinfo/XS/parsetexi/indices.c
@@ -192,8 +192,20 @@ init_index_commands (void)
};
#undef X
- number_of_indices = 0;
- num_index_commands = 0;
+ /* number_of_indices and num_index_commands
+ * should already be reset to 0 by forget_indices
+
+ if (number_of_indices != 0)
+ {
+ fprintf (stderr, "BUG: init_index_commands: number_of_indices != 0\n");
+ number_of_indices = 0;
+ }
+ if (num_index_commands != 0)
+ {
+ fprintf (stderr, "BUG: init_index_commands: num_index_commands != 0\n");
+ num_index_commands = 0;
+ }
+ */
for (p = default_indices; p->name; p++)
{
@@ -345,6 +357,7 @@ forget_indices (void)
index_names = 0;
number_of_indices = 0;
space_for_indices = 0;
+ num_index_commands = 0;
}
void
@@ -352,13 +365,16 @@ resolve_indices_merged_in (void)
{
INDEX **i, *idx;
- for (i = index_names; (idx = *i); i++)
+ if (index_names)
{
- if (idx->merged_in)
+ for (i = index_names; (idx = *i); i++)
{
- /* This index is merged in another one. */
- INDEX *ultimate = ultimate_index (idx);
- idx->merged_in = ultimate;
+ if (idx->merged_in)
+ {
+ /* This index is merged in another one. */
+ INDEX *ultimate = ultimate_index (idx);
+ idx->merged_in = ultimate;
+ }
}
}
}
@@ -378,6 +394,9 @@ complete_indices (int document_descriptor, int debug_level)
not after gdt call */
document = retrieve_document (document_descriptor);
+ if (!document->index_names)
+ return;
+
index_names = document->index_names;
for (i = index_names; (idx = *i); i++)
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 426079da08..3098251cc1 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -2630,6 +2630,12 @@ parse_texi (ELEMENT *root_elt, ELEMENT *current_elt)
char *line;
int status;
+ /* done here and not in reset_parser_except_conf as usually done
+ as restricted is set after reset_parser_except_conf and before
+ calling parsing functions */
+ if (!global_restricted)
+ init_index_commands ();
+
/* Read input file line-by-line. */
while (1)
{
diff --git a/tp/t/init/translation_in_parser_in_translation.pm
b/tp/t/init/translation_in_parser_in_translation.pm
index 737da26d4e..0cced69dbe 100644
--- a/tp/t/init/translation_in_parser_in_translation.pm
+++ b/tp/t/init/translation_in_parser_in_translation.pm
@@ -10,6 +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.
my %translations = (
'fr' => {
'Next' => {'NodeNext direction string'
@@ -23,6 +24,14 @@ AA
@deftypemethod g h i j k l
BB
@end deftypemethod
+
+@defcodeindex xx
+@xxindex entry
+
+@synindex fn xx
+
+@printindex fn
+@printindex xx
'},
# this is not used, as it is translated in the parser.
# To be used, should be in po/gmo file
@@ -36,6 +45,14 @@ CC
@deftypemethod s t u v w x
DD
@end deftypemethod
+
+@defcodeindex xx
+@xxindex entry
+
+@synindex fn xx
+
+@printindex fn
+@printindex xx
'},
});
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 6487d23992..e751013799 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
@@ -40,6 +40,10 @@ strong.def-name {font-family: monospace; font-weight: bold;
font-size: larger}
<dt class="deftypeop deftypemethod-alias-deftypeop"><span
class="category-def">Méthode de <code class="code">g</code> :
</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>
+
+ entry
+
+
: <a href="chap.html" accesskey="n" rel="next">Chap</a> </p>
</div>
<hr>
@@ -63,6 +67,10 @@ strong.def-name {font-family: monospace; font-weight: bold;
font-size: larger}
<dt class="deftypeop deftypemethod-alias-deftypeop"><span
class="category-def">Méthode de <code class="code">g</code> :
</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>
+
+ entry
+
+
: <a href="chap.html" accesskey="n" rel="next">Chap</a> </p>
</div>