texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Tue, 31 Aug 2021 04:30:00 -0400 (EDT)

branch: master
commit ac04776b689b6309cbd9f6de6b7843007fefd84e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Aug 31 10:29:50 2021 +0200

    * tp/Texinfo/Report.pm (new, gdt),
    tp/Texinfo/ParserNonXS.pm (_line_warn, _line_error)
    (_setup_parser, simple_parser, parse_texi_file, registered_errors),
    tp/Texinfo/XS/parsetexi/Parsetexi.pm (parser, _get_errors)
    (registered_errors), texi2any.pl: do not initialize parsers
    as Texinfo::Report objects, instead create a new Texinfo::Report
    object in Texinfo::Report::new, and pass it from the parsers
    using registered_errors().
    
    * tp/Texinfo/XS/parsetexi/Parsetexi.pm (@ISA): do not inherit
    DynaLoader.
---
 ChangeLog                                      | 14 ++++++++
 tp/TODO                                        |  1 -
 tp/Texinfo/ParserNonXS.pm                      | 48 +++++++++++++++++++++-----
 tp/Texinfo/Report.pm                           | 28 ++++++++-------
 tp/Texinfo/XS/parsetexi/Parsetexi.pm           | 22 ++++++++----
 tp/t/test_protect_hashchar_at_line_beginning.t |  6 ++--
 tp/t/test_utils.pl                             | 19 +++++-----
 tp/texi2any.pl                                 | 30 +++++++++-------
 8 files changed, 117 insertions(+), 51 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a6c2d4e..9230243 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2021-08-31  Patrice Dumas  <pertusus@free.fr>
 
+       * tp/Texinfo/Report.pm (new, gdt),
+       tp/Texinfo/ParserNonXS.pm (_line_warn, _line_error)
+       (_setup_parser, simple_parser, parse_texi_file, registered_errors),
+       tp/Texinfo/XS/parsetexi/Parsetexi.pm (parser, _get_errors)
+       (registered_errors), texi2any.pl: do not initialize parsers
+       as Texinfo::Report objects, instead create a new Texinfo::Report
+       object in Texinfo::Report::new, and pass it from the parsers
+       using registered_errors().
+
+       * tp/Texinfo/XS/parsetexi/Parsetexi.pm (@ISA): do not inherit
+       DynaLoader.
+
+2021-08-31  Patrice Dumas  <pertusus@free.fr>
+
        * tp/Texinfo/XSLoader.pm (init): pass warnings and die if
        the require of perl module associated with XS parser failed.
 
diff --git a/tp/TODO b/tp/TODO
index 65ec19e..f311877 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -13,7 +13,6 @@ xmllint --nonet --noout --valid commands.xml
 Before next release
 ===================
 
-document_warn document_error file_line_warn  file_line_error
 
 Bugs
 ====
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 3535c90..1504b8e 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -580,14 +580,14 @@ sub _top_context_command($)
 sub _line_warn
 {
   my $self = shift;
-  my $registrar = $self;
+  my $registrar = $self->{'registrar'};
   $registrar->line_warn($self, @_);
 }
 
 sub _line_error
 {
   my $self = shift;
-  my $registrar = $self;
+  my $registrar = $self->{'registrar'};
   $registrar->line_error($self, @_);
 }
 
@@ -731,7 +731,9 @@ sub _setup_parser {
 
   %{$parser->{'global_commands'}} = %global_multiple_commands;
 
-  $parser->Texinfo::Report::new;
+  if (not defined($parser->{'registrar'})) {
+    $parser->{'registrar'} = Texinfo::Report::new();
+  }
 
   return $parser;
 }
@@ -781,7 +783,9 @@ sub simple_parser(;$)
 
   %{$parser->{'global_commands'}} = ();
 
-  $parser->Texinfo::Report::new;
+  if (not defined($parser->{'registrar'})) {
+    $parser->{'registrar'} = Texinfo::Report::new();
+  }
 
   return $parser;
 }
@@ -906,7 +910,7 @@ sub parse_texi_file($$)
 
   my $filehandle = do { local *FH };
   if (!_open_in($self, $filehandle, $file_name)) {
-    $self->document_error($self,
+    $self->{'registrar'}->document_error($self,
                  sprintf(__("could not open %s: %s"),
                                   $file_name, $!));
     return undef;
@@ -1052,6 +1056,12 @@ sub labels_information($)
   return $self->{'labels'}, $self->{'targets'}, $self->{'nodes'};
 }
 
+sub registered_errors($)
+{
+  my $self = shift;
+  return $self->{'registrar'};
+}
+
 # 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 
@@ -1965,7 +1975,7 @@ sub _next_text($$)
     # Don't close STDIN
     if ($previous_input->{'fh'} and $previous_input->{'name'} ne '-') {
       if (!close($previous_input->{'fh'})) {
-        $self->document_warn($self,
+        $self->{'registrar'}->document_warn($self,
                              sprintf(__("error on closing %s: %s"),
                                      $previous_input->{'name'}, $!));
       }
@@ -5464,7 +5474,7 @@ sub _parse_texi($;$)
   }
 
   # Setup labels info and nodes list based on 'targets'
-  Texinfo::Common::set_nodes_list_labels($self, $self, $self);
+  Texinfo::Common::set_nodes_list_labels($self, $self->{'registrar'}, $self);
   Texinfo::Common::complete_indices($self);
   return $root;
 }
@@ -5905,6 +5915,9 @@ Texinfo::Parser - Parse Texinfo code into a Perl tree
   # a hash reference on some document informations (encodings, 
   # input file name, dircategory and direntry list, for exampel).
   my $global_informations = $parser->global_informations();
+  # a Texinfo::Report object in which the errors and warnings
+  # encountered while parsing are registered.
+  my $registrar = $parser->registered_errors();
 
 =head1 DESCRIPTION
 
@@ -5970,6 +5983,10 @@ Maximal number of nested user-defined macro calls.  
Default is 100000.
 Possible values are 'nomenu', 'menu' and 'sectiontoc'.  Only report 
 menu-related errors for 'menu'. 
 
+=item registrar
+
+Texinfo::Report object reused by the parser to register errors.
+
 =begin :comment
 
 Used by Sectioning only
@@ -6053,10 +6070,23 @@ undef is returned if the file couldn't be read.
 
 =back
 
-The errors collected during the tree parsing are available through the
-C<errors> method.  This method comes from C<Texinfo::Report>, and is 
+The errors collected during the tree parsing are registered in a
+C<Texinfo::Report> object.  This object is available with
+C<registered_errors>.  The errors registered in the C<Texinfo::Report>
+object are available through the C<errors> method.  This method is
 described in L<errors|Texinfo::Report/($error_warnings_list, $error_count) = 
errors ($converter)>.
 
+=over
+
+=item $registrar = registered_errors($parser)
+
+C<$registrar> is a C<Texinfo::Report> object in which the errors
+and warnings encountered while parsing are registered.  If a C<registrar>
+option is pased to the parser initialization it is reused, otherwise
+a new one is created.
+
+=back
+
 =head2 Getting information on the document
 
 After parsing some information about the Texinfo code that was processed
diff --git a/tp/Texinfo/Report.pm b/tp/Texinfo/Report.pm
index bbc4730..0326af5 100644
--- a/tp/Texinfo/Report.pm
+++ b/tp/Texinfo/Report.pm
@@ -65,22 +65,28 @@ sub __p($$) {
 
 
 
-# return the errors and warnings
-sub errors($)
-{
-  my $self = shift;
-  return ($self->{'errors_warnings'}, $self->{'error_nrs'});
-}
-
-sub new($)
+sub new(;$)
 {
   my $self = shift;
+  # if there is no argument, setup a separate Texinfo::Report object,
+  # otherwise the structure is added to the converter, nothing is "blessed".
+  if (not defined($self)) {
+    $self = {};
+    bless $self;
+  }
   $self->{'errors_warnings'} = [];
   #print STDERR "REPORT NEW $self $self->{'errors_warnings'}\n";
   $self->{'errors_nrs'} = 0;
   return $self;
 }
 
+# return the errors and warnings
+sub errors($)
+{
+  my $self = shift;
+  return ($self->{'errors_warnings'}, $self->{'error_nrs'});
+}
+
 # format a line warning
 sub line_warn($$$$)
 {
@@ -387,16 +393,14 @@ sub gdt($$;$$)
     }
   }
   $parser_conf->{'accept_internalvalue'} = 1;
-  #my $parser = Texinfo::Parser::parser($parser_conf);
   my $parser = Texinfo::Parser::simple_parser($parser_conf);
   if ($parser->{'DEBUG'}) {
     print STDERR "GDT $translation_result\n";
   }
 
   my $tree = $parser->parse_texi_line($translation_result);
-  # FIXME if at some point it becomes possible to reuse a parser
-  # this could bring in all the parser errors
-  my ($errors, $errors_count) = $parser->errors();
+  my $registrar = $parser->registered_errors();
+  my ($errors, $errors_count) = $registrar->errors();
   if ($errors_count) {
     warn "translation $errors_count error(s)\n";
     warn "translated message: $translated_message\n";
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm 
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index 518f073..a1ba70e 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -28,7 +28,7 @@ use Texinfo::Encoding;
 use Texinfo::Convert::NodeNameNormalization;
 use Texinfo::Report;
 
-our @ISA = qw(Exporter DynaLoader Texinfo::Report);
+our @ISA = qw(Exporter Texinfo::Report);
 our %EXPORT_TAGS = ( 'all' => [ qw(
     parser
     parse_texi_text
@@ -121,6 +121,7 @@ sub parser (;$$)
         set_accept_internalvalue();
       } elsif ($key eq 'ENABLE_ENCODING'
                or $key eq 'novalidate'
+               or $key eq 'registrar'
                or 
defined($Texinfo::Common::default_structure_customization_values{$key})) {
         # no action needed
       } else {
@@ -131,8 +132,6 @@ sub parser (;$$)
 
   bless $parser;
 
-  $parser->Texinfo::Report::new;
-
   return $parser;
 }
 
@@ -205,7 +204,7 @@ sub get_parser_info {
   _get_errors ($self);
 
   # Setup labels info and nodes list based on 'targets'
-  Texinfo::Common::set_nodes_list_labels($self, $self, $self);
+  Texinfo::Common::set_nodes_list_labels($self, $self->{'registrar'}, $self);
   Texinfo::Common::complete_indices ($self);
 }
 
@@ -285,8 +284,12 @@ sub parse_texi_file ($$)
 sub _get_errors($)
 {
   my $self = shift;
-  my $registrar = $self;
+  if (not $self->{'registrar'}) {
+    $self->{'registrar'} = Texinfo::Report::new();
+  }
+  my $registrar = $self->{'registrar'};
   my $configuration_informations = $self;
+
   my $ERRORS;
   my $tree_stream = dump_errors();
   eval $tree_stream;
@@ -301,6 +304,7 @@ sub _get_errors($)
   }
 }
 
+
 # Replacement for Texinfo::Parser::parse_texi_text
 #
 # Used in tests under tp/t.
@@ -364,7 +368,7 @@ sub parse_texi_line($$;$$$$)
     $self->{'targets'} = $TARGETS;
 
     # Setup labels info and nodes list based on 'targets'
-    Texinfo::Common::set_nodes_list_labels($self, $self, $self);
+    Texinfo::Common::set_nodes_list_labels($self, $self->{'registrar'}, $self);
 
     return $tree;
 }
@@ -412,5 +416,11 @@ sub labels_information($)
   return $self->{'labels'}, $self->{'targets'}, $self->{'nodes'};
 }
 
+sub registered_errors($)
+{
+  my $self = shift;
+  return $self->{'registrar'};
+}
+
 1;
 __END__
diff --git a/tp/t/test_protect_hashchar_at_line_beginning.t 
b/tp/t/test_protect_hashchar_at_line_beginning.t
index 6219946..0a7bb97 100644
--- a/tp/t/test_protect_hashchar_at_line_beginning.t
+++ b/tp/t/test_protect_hashchar_at_line_beginning.t
@@ -25,11 +25,13 @@ sub run_test($$$;$)
   my $parser = Texinfo::Parser::parser();
   my $tree = $parser->parse_texi_text($in, 1);
 
+  my $registrar = $parser->registered_errors();
+
   my $corrected_tree = 
-    Texinfo::Common::protect_hashchar_at_line_beginning($parser, $parser, 
$tree);
+    Texinfo::Common::protect_hashchar_at_line_beginning($registrar, $parser, 
$tree);
 
   if (defined($error_message)) {
-    my ($errors, $errors_count) = $parser->errors();
+    my ($errors, $errors_count) = $registrar->errors();
     if (!$error_message) {
       if ($errors and scalar(@$errors)) {
         print STDERR " --error-> $errors->[0]->{'error_line'}";
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 0fcbdd2..11d44e5 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -858,36 +858,37 @@ sub test($$)
   } else {
     $result = $parser->parse_texi_file($test_file);
   }
+  my $registrar = $parser->registered_errors();
   my $parser_informations = $parser->global_informations();
   my ($labels, $targets_list, $nodes_list) = $parser->labels_information();
   my $refs = $parser->internal_references_information();
-  Texinfo::Structuring::associate_internal_references($parser, $parser,
+  Texinfo::Structuring::associate_internal_references($registrar, $parser,
                                         $parser_informations, $labels, $refs);
   my $floats = $parser->floats_information();
 
   my $global_commands = $parser->global_commands_information();
-  my $structure = Texinfo::Structuring::sectioning_structure($parser, $parser,
+  my $structure = Texinfo::Structuring::sectioning_structure($parser, 
$registrar,
                                                              $parser, $result);
   if ($structure) {
-    Texinfo::Structuring::warn_non_empty_parts($parser, $parser, 
$global_commands);
+    Texinfo::Structuring::warn_non_empty_parts($registrar, $parser, 
$global_commands);
   }
 
   Texinfo::Structuring::number_floats($floats);
 
-  Texinfo::Structuring::set_menus_node_directions($parser, $parser,
+  Texinfo::Structuring::set_menus_node_directions($registrar, $parser,
                   $parser_informations, $global_commands, $nodes_list, 
$labels);
-  my $top_node = Texinfo::Structuring::nodes_tree($parser, $parser, $parser,
+  my $top_node = Texinfo::Structuring::nodes_tree($parser, $registrar, $parser,
                                     $parser_informations, $nodes_list, 
$labels);
 
   if (defined($nodes_list)) {
-    Texinfo::Structuring::complete_node_tree_with_menus($parser, $parser,
+    Texinfo::Structuring::complete_node_tree_with_menus($registrar, $parser,
                                                         $nodes_list, 
$top_node);
-    Texinfo::Structuring::check_nodes_are_referenced($parser, $parser,
+    Texinfo::Structuring::check_nodes_are_referenced($registrar, $parser,
                                                      $nodes_list, $top_node,
                                                      $labels, $refs);
   }
 
-  my ($errors, $error_nrs) = $parser->errors();
+  my ($errors, $error_nrs) = $registrar->errors();
   my $index_names = $parser->indices_information();
   # FIXME maybe it would be good to compare $merged_index_entries?
   my $merged_index_entries 
@@ -903,7 +904,7 @@ sub test($$)
   my $sorted_index_entries;
   if ($merged_index_entries) {
     $sorted_index_entries 
-      = Texinfo::Structuring::sort_indices_by_letter($parser, $parser, $parser,
+      = Texinfo::Structuring::sort_indices_by_letter($parser, $registrar, 
$parser,
                                    $merged_index_entries, $index_names);
   }
   if ($simple_menus) {
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index 2a4a5cb..c57a8d2 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1224,8 +1224,10 @@ while(@input_files) {
     local $Data::Dumper::Indent = 1;
     print STDERR Data::Dumper->Dump([$tree]);
   }
+  # object registering errors and warnings
+  my $registrar = $parser->registered_errors();
   if (!defined($tree) or $format eq 'parse') {
-    handle_errors($parser, $error_count, \@opened_files);
+    handle_errors($registrar, $error_count, \@opened_files);
     next;
   }
 
@@ -1275,7 +1277,7 @@ while(@input_files) {
     }
   }
   if (get_conf('DUMP_TEXI') or $formats_table{$format}->{'texi2dvi_format'}) {
-    handle_errors($parser, $error_count, \@opened_files);
+    handle_errors($registrar, $error_count, \@opened_files);
     next;
   }
 
@@ -1291,7 +1293,9 @@ while(@input_files) {
 
   if ($tree_transformations{'insert_nodes_for_sectioning_commands'}) {
     my ($modified_contents, $added_nodes)
-     = Texinfo::Transformations::insert_nodes_for_sectioning_commands($parser, 
+     # the first argument is ultimately passed to Texinfo::Common::modify_tree
+     # functions, but they do not actually use this argument
+     = Texinfo::Transformations::insert_nodes_for_sectioning_commands(undef,
                               $tree, $nodes_list, $targets_list, $labels);
     if (!defined($modified_contents)) {
       document_warn(__(
@@ -1303,17 +1307,18 @@ while(@input_files) {
 
   my $refs = $parser->internal_references_information();
   my $parser_informations = $parser->global_informations();
-  Texinfo::Structuring::associate_internal_references($parser, $parser,
+  Texinfo::Structuring::associate_internal_references($registrar, $parser,
                                         $parser_informations, $labels, $refs);
   # every format needs the sectioning structure
-
-  my $structure = Texinfo::Structuring::sectioning_structure($parser, $parser,
+  # FIXME replace parser as first argument by a structure object
+  my $structure = Texinfo::Structuring::sectioning_structure($parser, 
$registrar,
                                                              $parser, $tree);
 
   my $global_commands = $parser->global_commands_information();
   if ($structure
       and !$formats_table{$format}->{'no_warn_non_empty_parts'}) {
-    Texinfo::Structuring::warn_non_empty_parts($parser, $parser, 
$global_commands);
+    Texinfo::Structuring::warn_non_empty_parts($registrar, $parser,
+                                               $global_commands);
   }
 
   if ($tree_transformations{'complete_tree_nodes_menus'}) {
@@ -1339,17 +1344,18 @@ while(@input_files) {
     # for instance if format is structure.
     if (not defined($parser_options->{'FORMAT_MENU'})
         or $parser_options->{'FORMAT_MENU'} eq 'menu') {
-      Texinfo::Structuring::set_menus_node_directions($parser, $parser,
+      Texinfo::Structuring::set_menus_node_directions($registrar, $parser,
                $parser_informations, $global_commands, $nodes_list, $labels);
     }
-    $top_node = Texinfo::Structuring::nodes_tree($parser, $parser, $parser,
+    # FIXME replace parser as first argument by a structure object
+    $top_node = Texinfo::Structuring::nodes_tree($parser, $registrar, $parser,
                                    $parser_informations, $nodes_list, $labels);
     if (not defined($parser_options->{'FORMAT_MENU'})
         or $parser_options->{'FORMAT_MENU'} eq 'menu') {
       if (defined($nodes_list)) {
-        Texinfo::Structuring::complete_node_tree_with_menus($parser, $parser,
+        Texinfo::Structuring::complete_node_tree_with_menus($registrar, 
$parser,
                                                        $nodes_list, $top_node);
-        Texinfo::Structuring::check_nodes_are_referenced($parser, $parser,
+        Texinfo::Structuring::check_nodes_are_referenced($registrar, $parser,
                                                      $nodes_list, $top_node,
                                                      $labels, $refs);
       }
@@ -1359,7 +1365,7 @@ while(@input_files) {
     Texinfo::Structuring::number_floats($floats);
   }
 
-  $error_count = handle_errors($parser, $error_count, \@opened_files);
+  $error_count = handle_errors($registrar, $error_count, \@opened_files);
 
   if ($format eq 'structure') {
     next;



reply via email to

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