texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: No export of perl tree at parsing time with XS


From: Patrice Dumas
Subject: branch master updated: No export of perl tree at parsing time with XS
Date: Sun, 29 Oct 2023 10:03:25 -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 7f1b750038 No export of perl tree at parsing time with XS
7f1b750038 is described below

commit 7f1b750038f13a58bbd513a6f2f07dda5e87ad3f
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Oct 29 15:03:27 2023 +0100

    No export of perl tree at parsing time with XS
    
    * tp/Texinfo/Common.pm (informative_command_value)
    (get_global_document_command, set_global_document_command),
    tp/Texinfo/XS/main/utils.c (informative_command_value)
    (set_global_document_command, get_global_document_command):
    make informative_command_value public.  Split retrieval of global
    element out of set_global_document_command to a new
    get_global_document_command function that is called by
    set_global_document_command.
    
    * tp/Texinfo/Common.pm (relate_index_entries_to_table_items_in_tree),
    tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs
    (relate_index_entries_to_table_items_in_tree): use document as
    argument of relate_index_entries_to_table_items_in_tree.  Update
    callers.
    
    * tp/Texinfo/ParserNonXS.pm (get_parser_info),
    tp/Texinfo/XS/main/build_perl_info.c (build_global_info): add
    novalidate and documentlanguage information in global info,
    duplicating information from global commands, in order not to depend
    on global commands being present for structuring and transformations.
    
    * tp/Texinfo/XS/main/build_perl_info.c (build_global_info)
    (build_global_info_tree_info, get_document, build_document),
    tp/Texinfo/XS/parsetexi/Parsetexi.pm (_get_parser_info)
    (parse_texi_file, parse_texi_piece, parse_texi_text, parse_texi_line),
    tp/Texinfo/XS/parsetexi/Parsetexi.xs (get_document),
    tp/t/test_utils.pl (test), tp/texi2any.pl: add $no_build argument to
    XS parse perl functions. If set, the document is returned by
    get_document and contains only minimal information built from XS that
    is needed before rebuild_document call.  For that,
    build_global_info_tree_info is split out of build_global_info as it
    needs a built tree.  In texi2any.pl and test_utils.pl set the
    $no_build argument to $with_XS, such as not to built a tree if XS is
    used.
---
 ChangeLog                                          | 39 ++++++++++
 tp/Texinfo/Common.pm                               | 45 ++++++++----
 tp/Texinfo/Convert/Plaintext.pm                    |  2 +-
 tp/Texinfo/ParserNonXS.pm                          | 12 +++
 tp/Texinfo/Translations.pm                         |  2 +-
 tp/Texinfo/XS/main/build_perl_info.c               | 85 ++++++++++++++++++++--
 tp/Texinfo/XS/main/build_perl_info.h               |  4 +-
 tp/Texinfo/XS/main/utils.c                         | 36 +++++----
 tp/Texinfo/XS/main/utils.h                         |  4 +
 tp/Texinfo/XS/parsetexi/Parsetexi.pm               | 35 +++++----
 tp/Texinfo/XS/parsetexi/Parsetexi.xs               |  3 +
 .../XS/structuring_transfo/StructuringTransfo.xs   |  9 +--
 tp/t/test_utils.pl                                 | 14 ++--
 tp/texi2any.pl                                     | 18 ++---
 14 files changed, 235 insertions(+), 73 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a7050c7e24..714be79ef3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2023-10-29  Patrice Dumas  <pertusus@free.fr>
+
+       No export of perl tree at parsing time with XS
+
+       * tp/Texinfo/Common.pm (informative_command_value)
+       (get_global_document_command, set_global_document_command),
+       tp/Texinfo/XS/main/utils.c (informative_command_value)
+       (set_global_document_command, get_global_document_command):
+       make informative_command_value public.  Split retrieval of global
+       element out of set_global_document_command to a new
+       get_global_document_command function that is called by
+       set_global_document_command.
+
+       * tp/Texinfo/Common.pm (relate_index_entries_to_table_items_in_tree),
+       tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs
+       (relate_index_entries_to_table_items_in_tree): use document as
+       argument of relate_index_entries_to_table_items_in_tree.  Update
+       callers.
+
+       * tp/Texinfo/ParserNonXS.pm (get_parser_info),
+       tp/Texinfo/XS/main/build_perl_info.c (build_global_info): add
+       novalidate and documentlanguage information in global info,
+       duplicating information from global commands, in order not to depend
+       on global commands being present for structuring and transformations.
+
+       * tp/Texinfo/XS/main/build_perl_info.c (build_global_info)
+       (build_global_info_tree_info, get_document, build_document),
+       tp/Texinfo/XS/parsetexi/Parsetexi.pm (_get_parser_info)
+       (parse_texi_file, parse_texi_piece, parse_texi_text, parse_texi_line),
+       tp/Texinfo/XS/parsetexi/Parsetexi.xs (get_document),
+       tp/t/test_utils.pl (test), tp/texi2any.pl: add $no_build argument to
+       XS parse perl functions. If set, the document is returned by
+       get_document and contains only minimal information built from XS that
+       is needed before rebuild_document call.  For that,
+       build_global_info_tree_info is split out of build_global_info as it
+       needs a built tree.  In texi2any.pl and test_utils.pl set the
+       $no_build argument to $with_XS, such as not to built a tree if XS is
+       used.
+
 2023-10-29  Patrice Dumas  <pertusus@free.fr>
 
        * po/POTFILES.in: add tp/Texinfo/XS/structuring_transfo/structuring.c,
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 01c5c118eb..bc2c9e9d2d 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -1173,7 +1173,8 @@ sub locate_include_file($$)
   return $found_file;
 }
 
-sub _informative_command_value($)
+# TODO document?
+sub informative_command_value($)
 {
   my $element = shift;
 
@@ -1213,7 +1214,7 @@ sub set_informative_command_value($$)
   my $cmdname = $element->{'cmdname'};
   $cmdname = 'shortcontents' if ($cmdname eq 'summarycontents');
 
-  my $value = _informative_command_value($element);
+  my $value = informative_command_value($element);
 
   if (defined($value)) {
     return $self->set_conf($cmdname, $value);
@@ -1243,20 +1244,15 @@ sub _in_preamble($)
 # 'last' means setting to the last value for the command in the document.
 #
 # For unique command, the last may be considered to be the same as the first.
-#
-# Notice that the only effect is to use set_conf (directly or through
-# set_informative_command_value), no @-commands setting side effects are done
-# and associated customization variables are not set/reset either.
-sub set_global_document_command($$$$)
+sub get_global_document_command($$$)
 {
-  my $self = shift;
   my $global_commands_information = shift;
   my $global_command = shift;
   my $command_location = shift;
 
   if ($command_location ne 'last' and $command_location ne 'preamble_or_first'
       and $command_location ne 'preamble') {
-    warn "BUG: set_global_document_command: unknown command_location: 
$command_location";
+    warn "BUG: get_global_document_command: unknown command_location: 
$command_location";
   }
 
   my $element;
@@ -1265,18 +1261,15 @@ sub set_global_document_command($$$$)
       and ref($global_commands_information->{$global_command}) eq 'ARRAY') {
     if ($command_location eq 'last') {
       $element = $global_commands_information->{$global_command}->[-1];
-      set_informative_command_value($self, $element);
     } else {
       if ($command_location eq 'preamble_or_first'
           and not 
_in_preamble($global_commands_information->{$global_command}->[0])) {
         $element =
           $global_commands_information->{$global_command}->[0];
-        set_informative_command_value($self, $element);
       } else {
         foreach my $command_element 
(@{$global_commands_information->{$global_command}}) {
           if (_in_preamble($command_element)) {
             $element = $command_element;
-            set_informative_command_value($self, $element);
           } else {
             last;
           }
@@ -1287,6 +1280,24 @@ sub set_global_document_command($$$$)
            and defined($global_commands_information->{$global_command})) {
     # unique command, first, preamble and last are the same
     $element = $global_commands_information->{$global_command};
+  }
+  return $element;
+}
+
+# Notice that the only effect is to use set_conf (directly or through
+# set_informative_command_value), no @-commands setting side effects are done
+# and associated customization variables are not set/reset either.
+sub set_global_document_command($$$$)
+{
+  my $self = shift;
+  my $global_commands_information = shift;
+  my $global_command = shift;
+  my $command_location = shift;
+
+  my $element = get_global_document_command($global_commands_information,
+                                            $global_command, 
$command_location);
+
+  if ($element) {
     set_informative_command_value($self, $element);
   }
   return $element;
@@ -2495,10 +2506,12 @@ sub _relate_index_entries_to_table_items($$$)
   return undef;
 }
 
-sub relate_index_entries_to_table_items_in_tree($$)
+sub relate_index_entries_to_table_items_in_tree($)
 {
-  my $tree = shift;
-  my $indices_information = shift;
+  my $document = shift;
+
+  my $tree = $document->tree();
+  my $indices_information = $document->indices_information();
 
   modify_tree($tree, \&_relate_index_entries_to_table_items,
               $indices_information);
@@ -2964,7 +2977,7 @@ In C<@enumerate> and C<@itemize> from the tree, move 
index entries
 appearing just before C<@item> after the C<@item>.  Comment lines
 between index entries are moved too.
 
-=item relate_index_entries_to_table_items_in_tree($tree)
+=item relate_index_entries_to_table_items_in_tree($document)
 X<C<relate_index_entries_to_table_items_in_tree>>
 
 In tables, relate index entries preceding and following an
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index c9d0a75ed0..1e534d9dd8 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -2739,7 +2739,7 @@ sub _convert($$)
           or $command eq 'smallquotation') {
         if ($element->{'args'} and $element->{'args'}->[0]
             and $element->{'args'}->[0]->{'contents'}
-            and @{$element->{'args'}->[0]->{'contents'}}) {
+            and scalar(@{$element->{'args'}->[0]->{'contents'}})) {
           my $prepended = $self->gdt('@b{{quotation_arg}:} ',
              {'quotation_arg' => $element->{'args'}->[0]});
           $prepended->{'type'} = 'frenchspacing';
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 7aafb825e0..6cd7386f19 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -842,6 +842,18 @@ sub get_parser_info($)
   } else {
     $self->{'info'}->{'input_encoding_name'} = 'utf-8';
   }
+  my $global_commands = $self->{'commands_info'};
+  my $document_language
+    = Texinfo::Common::get_global_document_command($global_commands,
+                                                   'documentlanguage',
+                                                   'preamble');
+  if ($document_language) {
+    $self->{'info'}->{'documentlanguage'}
+      = Texinfo::Common::informative_command_value($document_language);
+  }
+  if ($global_commands->{'novalidate'}) {
+    $self->{'info'}->{'novalidate'} = 1;
+  }
 }
 
 # parse a texi file
diff --git a/tp/Texinfo/Translations.pm b/tp/Texinfo/Translations.pm
index 202529e26d..d4e06b7323 100644
--- a/tp/Texinfo/Translations.pm
+++ b/tp/Texinfo/Translations.pm
@@ -379,7 +379,7 @@ sub replace_convert_substrings($$;$)
     print STDERR "IN TR PARSER '$texinfo_line'\n";
   }
 
-  my $tree = $parser->parse_texi_line($texinfo_line, undef, 1);
+  my $tree = $parser->parse_texi_line($texinfo_line, undef, 0, 1);
   my $registrar = $parser->registered_errors();
   my ($errors, $errors_count) = $registrar->errors();
   if ($errors_count) {
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index d6719db920..e8d33c27b5 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -36,6 +36,7 @@
 
 #include "global_commands_types.h"
 #include "tree_types.h"
+#include "command_ids.h"
 #include "tree.h"
 #include "element_types.h"
 /* for GLOBAL_INFO ERROR_MESSAGE fatal output_unit_type_names CONVERTER */
@@ -838,12 +839,13 @@ build_index_data (INDEX **index_names_in)
 /* Return object to be used as 'info', retrievable with the
    'global_information' function. */
 HV *
-build_global_info (GLOBAL_INFO *global_info_ref)
+build_global_info (GLOBAL_INFO *global_info_ref,
+                   GLOBAL_COMMANDS *global_commands_ref)
 {
   HV *hv;
-  int i;
-  ELEMENT *e;
   GLOBAL_INFO global_info = *global_info_ref;
+  GLOBAL_COMMANDS global_commands = *global_commands_ref;
+  ELEMENT *document_language;
 
   dTHX;
 
@@ -857,6 +859,35 @@ build_global_info (GLOBAL_INFO *global_info_ref)
   if (global_info.input_directory)
     hv_store (hv, "input_directory", strlen ("input_directory"),
               newSVpv (global_info.input_directory, 0), 0);
+  /* duplicate information to avoid needing to use global_commands and build
+     tree elements */
+  if (global_commands.novalidate)
+    hv_store (hv, "novalidate", strlen ("novalidate"),
+              newSViv (1), 0);
+  document_language = get_global_document_command (global_commands_ref,
+                                       CM_documentlanguage, CL_preamble);
+
+  if (document_language)
+    {
+      char *language = informative_command_value (document_language);
+      hv_store (hv, "documentlanguage", strlen ("documentlanguage"),
+                newSVpv (language, 0), 0);
+    }
+
+  return hv;
+}
+
+/* global info that requires a built tree
+   FIXME remove, use the global commands information directly?
+   */
+void
+build_global_info_tree_info (HV *hv, GLOBAL_INFO *global_info_ref)
+{
+  int i;
+  ELEMENT *e;
+  GLOBAL_INFO global_info = *global_info_ref;
+
+  dTHX;
 
   if (global_info.dircategory_direntry.contents.number > 0)
     {
@@ -870,8 +901,6 @@ build_global_info (GLOBAL_INFO *global_info_ref)
             av_push (av, newRV_inc ((SV *) e->hv));
         }
     }
-
-  return hv;
 }
 
 /* Return object to be used as 'commands_info', which holds references
@@ -1046,6 +1075,48 @@ get_errors (ERROR_MESSAGE* error_list, size_t 
error_number)
 
 
 
+SV *
+get_document (size_t document_descriptor)
+{
+  HV *hv_stash;
+  HV *hv;
+  DOCUMENT *document;
+  SV *sv;
+  HV *hv_tree;
+  HV *hv_info;
+  AV *av_errors_list;
+
+  dTHX;
+
+  document = retrieve_document (document_descriptor);
+
+  hv = newHV ();
+  hv_tree = newHV ();
+
+  hv_info = build_global_info (document->global_info, 
document->global_commands);
+
+  av_errors_list = get_errors (document->error_messages->list,
+                               document->error_messages->number);
+
+#define STORE(key, value) hv_store (hv, key, strlen (key), newRV_inc ((SV *) 
value), 0)
+  STORE("tree", hv_tree);
+  STORE("info", hv_info);
+  STORE("errors", av_errors_list);
+#undef STORE
+
+  hv_store (hv, "document_descriptor", strlen ("document_descriptor"),
+            newSViv (document_descriptor), 0);
+
+  hv_store (hv_tree, "tree_document_descriptor",
+            strlen ("tree_document_descriptor"),
+            newSViv (document_descriptor), 0);
+
+  hv_stash = gv_stashpv ("Texinfo::Document", GV_ADD);
+  sv = newRV_noinc ((SV *) hv);
+  sv_bless (sv, hv_stash);
+  return sv;
+}
+
 /* Return Texinfo::Document perl object corresponding to the
    C document structure corresponding to DOCUMENT_DESCRIPTOR.
    If NO_STORE is set, destroy the C document.
@@ -1077,7 +1148,9 @@ build_document (size_t document_descriptor, int no_store)
 
   hv_tree = build_texinfo_tree (document->tree);
 
-  hv_info = build_global_info (document->global_info);
+  hv_info = build_global_info (document->global_info,
+                               document->global_commands);
+  build_global_info_tree_info (hv_info, document->global_info);
 
   hv_commands_info = build_global_commands (document->global_commands);
 
diff --git a/tp/Texinfo/XS/main/build_perl_info.h 
b/tp/Texinfo/XS/main/build_perl_info.h
index 6a6a72bd15..cac8446ecf 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -14,6 +14,7 @@ int init (int texinfo_uninstalled, char *srcdir_in);
 SV *newSVpv_utf8 (const char *str, STRLEN len);
 
 SV *build_document (size_t document_descriptor, int no_store);
+SV *get_document (size_t document_descriptor);
 
 HV *build_texinfo_tree (ELEMENT *root);
 AV *get_errors (ERROR_MESSAGE* error_list, size_t error_number);
@@ -24,7 +25,8 @@ AV *build_internal_xref_list (ELEMENT **internal_xref_list,
                               size_t internal_xref_number);
 HV *build_float_list (FLOAT_RECORD *floats_list, size_t floats_number);
 HV *build_index_data (INDEX **index_names_in);
-HV *build_global_info (GLOBAL_INFO *global_info_ref);
+HV *build_global_info (GLOBAL_INFO *global_info_ref,
+                       GLOBAL_COMMANDS *global_commands_ref);
 HV *build_global_commands (GLOBAL_COMMANDS *global_commands_ref);
 
 SV *build_output_units_list (size_t output_units_descriptor);
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 0e1a285c61..fc4a4f4a42 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -903,7 +903,7 @@ get_cmd_global_command (GLOBAL_COMMANDS 
*global_commands_ref,
    }
 }
 
-static char *
+char *
 informative_command_value (ELEMENT *element)
 {
   ELEMENT *misc_args;
@@ -1003,23 +1003,20 @@ in_preamble (ELEMENT *element)
   'last' means setting to the last value for the command in the document.
 
   For unique command, the last may be considered to be the same as the first.
-
-  Notice that the only effect is to use set_conf (directly or through
-  set_informative_command_value), no @-commands setting side effects are done
-  and associated customization variables are not set/reset either.
- */
+*/
 ELEMENT *
-set_global_document_command (CONVERTER *self, enum command_id cmd,
+get_global_document_command (GLOBAL_COMMANDS *global_commands,
+                             enum command_id cmd,
                              enum command_location command_location)
 {
   ELEMENT *element = 0;
   if (command_location != CL_last && command_location != CL_preamble_or_first
       && command_location != CL_preamble)
-    fprintf (stderr, "BUG: set_global_document_command: unknown CL: %d\n",
+    fprintf (stderr, "BUG: get_global_document_command: unknown CL: %d\n",
                      command_location);
 
   ELEMENT *command
-     = get_cmd_global_command (self->document->global_commands, cmd);
+     = get_cmd_global_command (global_commands, cmd);
   if (builtin_command_data[cmd].flags & CF_global)
     {
       if (command->contents.number)
@@ -1027,7 +1024,6 @@ set_global_document_command (CONVERTER *self, enum 
command_id cmd,
           if (command_location == CL_last)
             {
               element = command->contents.list[command->contents.number -1];
-              set_informative_command_value (self, element);
             }
           else
             {
@@ -1035,7 +1031,6 @@ set_global_document_command (CONVERTER *self, enum 
command_id cmd,
                    && !in_preamble (command->contents.list[0]))
                 {
                   element = command->contents.list[0];
-                  set_informative_command_value (self, element);
                 }
               else
                 {
@@ -1046,7 +1041,6 @@ set_global_document_command (CONVERTER *self, enum 
command_id cmd,
                       if (in_preamble (command_element))
                         {
                           element = command_element;
-                          set_informative_command_value (self, element);
                         }
                       else
                         break;
@@ -1058,11 +1052,27 @@ set_global_document_command (CONVERTER *self, enum 
command_id cmd,
   else if (command)
     {
       element = command;
-      set_informative_command_value (self, element);
     }
   return element;
 }
 
+/*
+  Notice that the only effect is to use set_conf (directly or through
+  set_informative_command_value), no @-commands setting side effects are done
+  and associated customization variables are not set/reset either.
+ */
+ELEMENT *
+set_global_document_command (CONVERTER *self, enum command_id cmd,
+                             enum command_location command_location)
+{
+  ELEMENT *element
+     = get_global_document_command (self->document->global_commands, cmd,
+                                    command_location);
+  if (element)
+    set_informative_command_value (self, element);
+  return element;
+}
+
 
 /* options and converters */
 OPTIONS *
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 647d0af50d..898c11a296 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -616,6 +616,10 @@ char *enumerate_item_representation (char *specification, 
int number);
 
 CONVERTER *new_converter (void);
 
+ELEMENT *get_global_document_command (GLOBAL_COMMANDS *global_commands,
+                                      enum command_id cmd,
+                                      enum command_location command_location);
+char *informative_command_value (ELEMENT *element);
 ELEMENT *set_global_document_command (CONVERTER *self, enum command_id cmd,
                                       enum command_location command_location);
 ELEMENT *get_cmd_global_command (GLOBAL_COMMANDS *global_commands_ref,
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm 
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index f64bb2c76f..1ced996e7a 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -184,15 +184,21 @@ sub _get_error_registrar($)
   return $registrar, $configuration_information;
 }
 
-sub _get_parser_info($$;$) {
+sub _get_parser_info($$;$$) {
   my $self = shift;
   my $document_descriptor = shift;
+  my $no_build = shift;
   my $no_store = shift;
 
   my ($registrar, $configuration_information)
      = _get_error_registrar($self);
 
-  my $document = build_document ($document_descriptor, $no_store);
+  my $document;
+  if ($no_build) {
+    $document = get_document ($document_descriptor);
+  } else {
+    $document = build_document ($document_descriptor, $no_store);
+  }
 
   #Texinfo::Translations::complete_indices ($self,
   #                                 $document->indices_information());
@@ -215,10 +221,11 @@ sub _get_parser_info($$;$) {
   return $document;
 }
 
-sub parse_texi_file ($$)
+sub parse_texi_file ($$;$)
 {
   my $self = shift;
   my $input_file_path = shift;
+  my $no_build = shift;
   my $tree_stream;
 
   # the file is already a byte string, taken as is from the command
@@ -241,16 +248,16 @@ sub parse_texi_file ($$)
     return undef;
   }
 
-  my $document = _get_parser_info($self, $document_descriptor);
+  my $document = _get_parser_info($self, $document_descriptor, $no_build);
 
   return $document;
 }
 
 
 # Used in tests under tp/t.
-sub parse_texi_piece($$;$$)
+sub parse_texi_piece($$;$$$)
 {
-  my ($self, $text, $line_nr, $no_store) = @_;
+  my ($self, $text, $line_nr, $no_build, $no_store) = @_;
 
   return undef if (!defined($text));
 
@@ -262,15 +269,16 @@ sub parse_texi_piece($$;$$)
   my $utf8_bytes = Encode::encode('utf-8', $text);
   my $document_descriptor = parse_piece($utf8_bytes, $line_nr);
 
-  my $document = _get_parser_info($self, $document_descriptor, $no_store);
+  my $document = _get_parser_info($self, $document_descriptor, $no_build,
+                                  $no_store);
 
   return $document;
 }
 
 # Used in tests under tp/t.
-sub parse_texi_text($$;$)
+sub parse_texi_text($$;$$)
 {
-  my ($self, $text, $line_nr) = @_;
+  my ($self, $text, $line_nr, $no_build) = @_;
 
   return undef if (!defined($text));
 
@@ -282,14 +290,14 @@ sub parse_texi_text($$;$)
   my $utf8_bytes = Encode::encode('utf-8', $text);
   my $document_descriptor = parse_text($utf8_bytes, $line_nr);
 
-  my $document = _get_parser_info($self, $document_descriptor);
+  my $document = _get_parser_info($self, $document_descriptor, $no_build);
 
   return $document;
 }
 
-sub parse_texi_line($$;$$)
+sub parse_texi_line($$;$$$)
 {
-  my ($self, $text, $line_nr, $no_store) = @_;
+  my ($self, $text, $line_nr, $no_build, $no_store) = @_;
 
   return undef if (!defined($text));
 
@@ -301,7 +309,8 @@ sub parse_texi_line($$;$$)
   my $utf8_bytes = Encode::encode('utf-8', $text);
   my $document_descriptor = parse_string($utf8_bytes, $line_nr);
 
-  my $document = _get_parser_info($self, $document_descriptor, $no_store);
+  my $document = _get_parser_info($self, $document_descriptor, $no_build,
+                                  $no_store);
 
   return $document->tree();
 }
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs 
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index 868544bbb0..dff91d6297 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -97,6 +97,9 @@ build_document (int document_descriptor, ...)
       OUTPUT:
         RETVAL
 
+SV *
+get_document (int document_descriptor)
+
 void
 clear_document_errors (int document_descriptor)
 
diff --git a/tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs 
b/tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs
index a152d1a6c1..59d6b68541 100644
--- a/tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs
+++ b/tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs
@@ -147,8 +147,7 @@ void
 remove_document_descriptor (int document_descriptor)
 
 void
-remove_document (document_in)
-        SV *document_in
+remove_document (SV *document_in)
     PREINIT:
         DOCUMENT *document = 0;
      CODE:
@@ -213,14 +212,12 @@ copy_tree (SV *tree_in, SV *parent_in=0)
     OUTPUT:
         RETVAL
 
-# $indices_information argument is ignored, it is found with the document
 void
-relate_index_entries_to_table_items_in_tree (SV *tree_in, ...)
-    PROTOTYPE: $$
+relate_index_entries_to_table_items_in_tree (SV *document_in)
     PREINIT:
         DOCUMENT *document;
      CODE:
-        document = get_sv_tree_document (tree_in,
+        document = get_sv_document_document (document_in,
                    "relate_index_entries_to_table_items_in_tree");
         if (document)
           {
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 6e367cfd0e..2e8db1158a 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -955,10 +955,10 @@ sub test($$)
   if (!$test_file) {
     if ($full_document) {
       print STDERR "  TEST FULL $test_name\n" if ($self->{'DEBUG'});
-      $document = $parser->parse_texi_text($test_text);
+      $document = $parser->parse_texi_text($test_text, undef, $with_XS);
     } else {
       print STDERR "  TEST $test_name\n" if ($self->{'DEBUG'});
-      $document = $parser->parse_texi_piece($test_text);
+      $document = $parser->parse_texi_piece($test_text, undef, $with_XS);
       if (defined($test_input_file_name)) {
         warn "ERROR: $self->{'name'}: $test_name: piece of texi with a file 
name\n";
       }
@@ -972,7 +972,7 @@ sub test($$)
     }
   } else {
     print STDERR "  TEST $test_name ($test_file)\n" if ($self->{'DEBUG'});
-    $document = $parser->parse_texi_file($test_file);
+    $document = $parser->parse_texi_file($test_file, $with_XS);
   }
   my $tree = $document->tree();
   my $registrar = $parser->registered_errors();
@@ -1000,7 +1000,7 @@ sub test($$)
                                         $document_information);
 
   my $global_commands = $document->global_commands_information();
-  if ($global_commands->{'novalidate'}) {
+  if ($document_information->{'novalidate'}) {
     $main_configuration->set_conf('novalidate', 1);
   }
 
@@ -1008,10 +1008,8 @@ sub test($$)
   # document XS
   $main_configuration->register_XS_document_main_configuration($document);
 
-  my $indices_information = $document->indices_information();
   if ($tree_transformations{'relate_index_entries_to_items'}) {
-    Texinfo::Common::relate_index_entries_to_table_items_in_tree($tree,
-                                                     $indices_information);
+    Texinfo::Common::relate_index_entries_to_table_items_in_tree($document);
   }
 
   if ($tree_transformations{'move_index_entries_after_items'}) {
@@ -1093,6 +1091,8 @@ sub test($$)
   }
 
   my ($errors, $error_nrs) = $registrar->errors();
+
+  my $indices_information = $document->indices_information();
   # FIXME maybe it would be good to compare $merged_index_entries?
   my $merged_index_entries
      = Texinfo::Structuring::merge_indices($indices_information);
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index 26cb16e2c0..c66a3cd630 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1449,7 +1449,7 @@ while(@input_files) {
           @prepended_include_directories;
 
   my $parser = Texinfo::Parser::parser($parser_file_options);
-  my $document = $parser->parse_texi_file($input_file_name);
+  my $document = $parser->parse_texi_file($input_file_name, $with_XS);
   my $tree;
   if (defined($document)) {
     $tree = $document->tree();
@@ -1495,13 +1495,13 @@ while(@input_files) {
   # encoding is needed for output files
   # encoding and documentlanguage are needed for gdt() in 
regenerate_master_menu
   Texinfo::Common::set_output_encodings($main_configuration, 
$document_information);
-  my $global_commands = $document->global_commands_information();
-  if (not defined($main_configuration->get_conf('documentlanguage'))) {
-    my $element = 
Texinfo::Common::set_global_document_command($main_configuration,
-       $global_commands, 'documentlanguage', 'preamble');
+  if (not defined($main_configuration->get_conf('documentlanguage'))
+      and defined ($document_information->{'documentlanguage'})) {
+    $main_configuration->set_conf('documentlanguage',
+                                  $document_information->{'documentlanguage'});
   }
   # relevant for many Structuring methods.
-  if ($global_commands->{'novalidate'}) {
+  if ($document_information->{'novalidate'}) {
     $main_configuration->set_conf('novalidate', 1);
   }
 
@@ -1511,6 +1511,8 @@ while(@input_files) {
 
   if (defined(get_conf('MACRO_EXPAND')) and $file_number == 0) {
     require Texinfo::Convert::Texinfo;
+    $document = Texinfo::Structuring::rebuild_document($document);
+    $tree = $document->tree();
     my $texinfo_text = Texinfo::Convert::Texinfo::convert_to_texinfo($tree);
     #print STDERR "$texinfo_text\n";
     my $encoded_macro_expand_file_name = get_conf('MACRO_EXPAND');
@@ -1555,9 +1557,7 @@ while(@input_files) {
 
   if 
($formats_table{$converted_format}->{'relate_index_entries_to_table_items'}
       or $tree_transformations{'relate_index_entries_to_table_items'}) {
-    my $indices_information = $document->indices_information();
-    Texinfo::Common::relate_index_entries_to_table_items_in_tree($tree,
-                                                          
$indices_information);
+    Texinfo::Common::relate_index_entries_to_table_items_in_tree($document);
   }
 
   if ($formats_table{$converted_format}->{'move_index_entries_after_items'}



reply via email to

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