[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sun, 3 Mar 2024 14:33:45 -0500 (EST) |
branch: master
commit c5b74c50ab260532c760b144cf92f73cc153ca9f
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Mar 3 15:05:25 2024 +0100
Separate Parser and Document errors and registrars
* tp/Texinfo/Document.pm (register),
tp/Texinfo/XS/main/build_perl_info.c (get_document, fill_document_hv),
tp/Texinfo/XS/main/document.c (register_document)
(clear_document_parser_errors), tp/Texinfo/XS/main/document_types.h
(DOCUMENT), tp/Texinfo/XS/parsetexi/Parsetexi.pm (_get_parser_info),
tp/t/test_parser_registrar.t, tp/t/test_utils.pl (test),
tp/texi2any.pl: add a separate Texinfo::Report error registrar in
perl, and separate parser_error_messages ERROR_MESSAGE_LIST in C.
Merge parser and document errors in texi2any.pl and test_utils.pl.
Remove handle_document_errors in texi2any.pl as the code is inlined
for the merging of errors in the main loop.
---
ChangeLog | 16 ++++++++++++++++
tp/Texinfo/Document.pm | 11 +++++++++--
tp/Texinfo/XS/main/build_perl_info.c | 16 ++++++++++++++++
tp/Texinfo/XS/main/document.c | 14 ++++++++++++--
tp/Texinfo/XS/main/document.h | 3 ++-
tp/Texinfo/XS/main/document_types.h | 1 +
tp/Texinfo/XS/parsetexi/Parsetexi.pm | 12 ++++++------
tp/Texinfo/XS/parsetexi/Parsetexi.xs | 3 +++
tp/t/test_parser_registrar.t | 2 +-
tp/t/test_utils.pl | 5 +++--
tp/texi2any.pl | 29 +++++++++++------------------
11 files changed, 80 insertions(+), 32 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0e579d9588..79add020e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-03-03 Patrice Dumas <pertusus@free.fr>
+
+ Separate Parser and Document errors and registrars
+
+ * tp/Texinfo/Document.pm (register),
+ tp/Texinfo/XS/main/build_perl_info.c (get_document, fill_document_hv),
+ tp/Texinfo/XS/main/document.c (register_document)
+ (clear_document_parser_errors), tp/Texinfo/XS/main/document_types.h
+ (DOCUMENT), tp/Texinfo/XS/parsetexi/Parsetexi.pm (_get_parser_info),
+ tp/t/test_parser_registrar.t, tp/t/test_utils.pl (test),
+ tp/texi2any.pl: add a separate Texinfo::Report error registrar in
+ perl, and separate parser_error_messages ERROR_MESSAGE_LIST in C.
+ Merge parser and document errors in texi2any.pl and test_utils.pl.
+ Remove handle_document_errors in texi2any.pl as the code is inlined
+ for the merging of errors in the main loop.
+
2024-03-03 Gavin Smith <gavinsmith0123@gmail.com>
Remove some perl_only_* wrappers
diff --git a/tp/Texinfo/Document.pm b/tp/Texinfo/Document.pm
index a9858cb0f0..5115827ca0 100644
--- a/tp/Texinfo/Document.pm
+++ b/tp/Texinfo/Document.pm
@@ -32,6 +32,8 @@ use Texinfo::XSLoader;
use Texinfo::Common;
+use Texinfo::Report;
+
our $VERSION = '7.1dev';
my $XS_parser = ((not defined($ENV{TEXINFO_XS})
@@ -93,7 +95,7 @@ sub register
my $global_commands_information = shift;
my $identifier_target = shift;
my $labels_list = shift;
- my $registrar = shift;
+ my $parser_registrar = shift;
my $document = {
'tree' => $tree,
@@ -104,7 +106,9 @@ sub register
'global_info' => $global_information,
'identifiers_target' => $identifier_target,
'labels_list' => $labels_list,
- 'registrar' => $registrar,
+ 'parser_registrar' => $parser_registrar,
+ # New error registrar for the document
+ 'registrar' => Texinfo::Report::new(),
};
bless $document;
@@ -428,6 +432,9 @@ sub clear_document_errors($)
{
}
+# NOTE could also add a parser_errors method to get the parser_registrar
+# errors. Something along those lines is done in XS, with a direct access
+# to document internal information.
sub errors($)
{
my $document = shift;
diff --git a/tp/Texinfo/XS/main/build_perl_info.c
b/tp/Texinfo/XS/main/build_perl_info.c
index 7e2c7f3444..1c5f039a06 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1218,6 +1218,7 @@ get_document (size_t document_descriptor)
HV *hv_tree;
HV *hv_info;
AV *av_errors_list;
+ AV *av_parser_errors_list;
dTHX;
@@ -1231,10 +1232,16 @@ get_document (size_t document_descriptor)
av_errors_list = build_errors (document->error_messages->list,
document->error_messages->number);
+ av_parser_errors_list
+ = build_errors (document->parser_error_messages->list,
+ document->parser_error_messages->number);
+
+
#define STORE(key, value) hv_store (hv, key, strlen (key), newRV_inc ((SV *)
value), 0)
STORE("tree", hv_tree);
STORE("global_info", hv_info);
STORE("errors", av_errors_list);
+ STORE("parser_errors", av_parser_errors_list);
#undef STORE
hv_store (hv, "document_descriptor", strlen ("document_descriptor"),
@@ -1264,6 +1271,7 @@ fill_document_hv (HV *hv, size_t document_descriptor, int
no_store)
HV *hv_identifiers_target;
AV *av_labels_list;
AV *av_errors_list;
+ AV *av_parser_errors_list;
AV *av_nodes_list = 0;
AV *av_sections_list = 0;
@@ -1301,6 +1309,10 @@ fill_document_hv (HV *hv, size_t document_descriptor,
int no_store)
av_errors_list = build_errors (document->error_messages->list,
document->error_messages->number);
+ av_parser_errors_list
+ = build_errors (document->parser_error_messages->list,
+ document->parser_error_messages->number);
+
if (document->nodes_list)
av_nodes_list = build_elements_list (document->nodes_list);
@@ -1325,6 +1337,7 @@ fill_document_hv (HV *hv, size_t document_descriptor, int
no_store)
STORE("identifiers_target", hv_identifiers_target);
STORE("labels_list", av_labels_list);
STORE("errors", av_errors_list);
+ STORE("parser_errors", av_parser_errors_list);
if (av_nodes_list)
STORE("nodes_list", av_nodes_list);
@@ -1388,6 +1401,9 @@ rebuild_document (SV *document_in, int no_store)
document_descriptor_sv = hv_fetch (hv, descriptor_key,
strlen (descriptor_key), 0);
+ /* Note that we could also keep the parser_registrar, however at that
+ point it should not be useful anymore, so it is better to let it
+ be cleared */
SV **registrar_svp, *registrar_sv = 0;
registrar_svp = hv_fetch (hv, registrar_key, strlen (registrar_key), 0);
if (registrar_svp)
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index d8c8dbc932..2e1679c9d9 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -60,7 +60,7 @@ register_document (ELEMENT *root, INDEX **index_names,
GLOBAL_INFO *global_info,
GLOBAL_COMMANDS *global_commands,
STRING_LIST *small_strings,
- ERROR_MESSAGE_LIST *error_messages)
+ ERROR_MESSAGE_LIST *parser_error_messages)
{
size_t document_index;
int slot_found = 0;
@@ -104,7 +104,9 @@ register_document (ELEMENT *root, INDEX **index_names,
document->global_info = global_info;
document->global_commands = global_commands;
document->small_strings = small_strings;
- document->error_messages = error_messages;
+ document->parser_error_messages = parser_error_messages;
+ document->error_messages = malloc (sizeof (ERROR_MESSAGE_LIST));
+ memset (document->error_messages, 0, sizeof (ERROR_MESSAGE_LIST));
document->listoffloats = float_list_to_listoffloats_list (floats_list);
@@ -545,3 +547,11 @@ clear_document_errors (int document_descriptor)
if (document)
wipe_error_message_list (document->error_messages);
}
+
+void
+clear_document_parser_errors (int document_descriptor)
+{
+ DOCUMENT *document = retrieve_document (document_descriptor);
+ if (document)
+ wipe_error_message_list (document->parser_error_messages);
+}
diff --git a/tp/Texinfo/XS/main/document.h b/tp/Texinfo/XS/main/document.h
index ac68d84c2c..49612e5878 100644
--- a/tp/Texinfo/XS/main/document.h
+++ b/tp/Texinfo/XS/main/document.h
@@ -21,7 +21,7 @@ size_t register_document (ELEMENT *root, INDEX **index_names,
GLOBAL_INFO *global_info,
GLOBAL_COMMANDS *global_commands,
STRING_LIST *small_strings,
- ERROR_MESSAGE_LIST *error_messages);
+ ERROR_MESSAGE_LIST *parser_error_messages);
void register_document_nodes_list (DOCUMENT *document,
ELEMENT_LIST *nodes_list);
void register_document_sections_list (DOCUMENT *document,
@@ -50,6 +50,7 @@ INDEX_SORTED_BY_LETTER *sorted_indices_by_letter (DOCUMENT
*document,
void remove_document_descriptor (int document_descriptor);
ELEMENT *unregister_document_merge_with_document (int document_descriptor,
DOCUMENT *document);
+void clear_document_parser_errors (int document_descriptor);
void clear_document_errors (int document_descriptor);
#endif
diff --git a/tp/Texinfo/XS/main/document_types.h
b/tp/Texinfo/XS/main/document_types.h
index 3ca7b488d8..ffba2aef84 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -173,6 +173,7 @@ typedef struct DOCUMENT {
ELEMENT_LIST *nodes_list;
ELEMENT_LIST *sections_list;
ERROR_MESSAGE_LIST *error_messages;
+ ERROR_MESSAGE_LIST *parser_error_messages;
struct OPTIONS *options; /* for options used in structuring */
struct TEXT_OPTIONS *convert_index_text_options; /* for index
sorting without converter */
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index 3640d14e6b..203825881d 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -213,15 +213,15 @@ sub _get_parser_info($$;$$) {
#Texinfo::Translations::complete_indices ($self,
# $document->indices_information());
- # Copy the errors into the error list in Texinfo::Report.
- foreach my $error (@{$document->{'errors'}}) {
+ # Copy the errors into the error list in parser Texinfo::Report.
+ foreach my $error (@{$document->{'parser_errors'}}) {
$registrar->add_formatted_message($error);
}
- @{$document->{'errors'}} = ();
- clear_document_errors($document_descriptor);
+ @{$document->{'parser_errors'}} = ();
+ clear_document_parser_errors($document_descriptor);
- # Reference the same Texinfo::Report object
- $document->{'registrar'} = $registrar;
+ # New error registrar for document
+ $document->{'registrar'} = Texinfo::Report::new();
# additional info relevant in perl only.
my $perl_encoding
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index f98a62e131..ae8d6f4dd3 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -105,6 +105,9 @@ get_document (int document_descriptor)
void
clear_document_errors (int document_descriptor)
+void
+clear_document_parser_errors (int document_descriptor)
+
void
parser_store_value (name, value)
char *name = (char *)SvPVbyte_nolen($arg);
diff --git a/tp/t/test_parser_registrar.t b/tp/t/test_parser_registrar.t
index f43867e8e0..f605c8cc98 100644
--- a/tp/t/test_parser_registrar.t
+++ b/tp/t/test_parser_registrar.t
@@ -30,7 +30,7 @@ my $document = $parser->parse_texi_piece("\@end format\n");
my $parser_registrar = $parser->registered_errors();
ok ($parser_registrar eq $registrar, 'reused registrar');
-my ($error_warnings_list, $error_count) = $document->errors();
+my ($error_warnings_list, $error_count) = $parser_registrar->errors();
ok ($error_count == 2, 'error count');
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 7e068ae9da..9d37284c6c 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -1044,6 +1044,7 @@ sub test($$)
if ($error_message->{'type'} eq 'error');
}
}
+ my ($errors, $error_nrs) = $registrar->errors();
if ($tree_transformations{'fill_gaps_in_sectioning'}) {
Texinfo::Transformations::fill_gaps_in_sectioning($tree);
@@ -1143,7 +1144,8 @@ sub test($$)
# should not actually be useful, as the same element should be reused.
$tree = $document->tree();
- my ($errors, $error_nrs) = $document->errors();
+ my ($document_errors, $document_error_nrs) = $document->errors();
+ push @$errors, @$document_errors;
my $indices_information = $document->indices_information();
# FIXME maybe it would be good to compare $merged_index_entries?
my $merged_index_entries = $document->merged_indices();
@@ -1192,7 +1194,6 @@ sub test($$)
}
}
-
# use the parser expanded formats to be similar to the main program,
# and also to avoid having @inline* and raw output format @-commands
# with elided contents especially parsed because they are ignored
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index bb809ad511..3700e37d4b 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1229,22 +1229,6 @@ sub _exit($$)
or $error_count > get_conf('ERROR_LIMIT')));
}
-sub handle_document_errors($$$)
-{
- my $document = shift;
- my $error_count = shift;
- my $opened_files = shift;
-
- die if ref($document) ne 'Texinfo::Document';
-
- my ($errors, $new_error_count) = $document->errors();
- $error_count += $new_error_count if ($new_error_count);
- _handle_errors($errors);
-
- _exit($error_count, $opened_files);
- return $error_count;
-}
-
sub handle_errors($$$)
{
my $self = shift;
@@ -1699,8 +1683,17 @@ while(@input_files) {
}
Texinfo::Document::rebuild_document($document);
- $error_count = handle_document_errors($document,
- $error_count, \@opened_files);
+
+ # parser errors
+ my ($errors, $new_error_count) = $registrar->errors();
+ $error_count += $new_error_count if ($new_error_count);
+ # document/structuring errors
+ my ($document_errors, $document_error_count) = $document->errors();
+ $error_count += $document_error_count if ($document_error_count);
+ push @$errors, @$document_errors;
+
+ _handle_errors($errors);
+ _exit($error_count, \@opened_files);
if ($format eq 'structure') {
goto NEXT;