[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Tue, 12 Dec 2023 06:29:58 -0500 (EST) |
branch: master
commit 22cf056dcccd59393fe99552020ff555c2e9709e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Dec 11 00:23:01 2023 +0100
* tp/Texinfo/Report.pm (format_line_message, line_warn, line_error)
(format_document_message, document_warn, document_error): split
formatting messages out of line_* and document_*, adding
format_line_message for line messages and format_document_message for
document messages, using only one function for both errors and
warnings, as in XS.
---
ChangeLog | 9 ++++
tp/Texinfo/Report.pm | 141 +++++++++++++++++++++++++++++----------------------
2 files changed, 88 insertions(+), 62 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 79c1fdaa3f..abe3658b2c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-12-10 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Report.pm (format_line_message, line_warn, line_error)
+ (format_document_message, document_warn, document_error): split
+ formatting messages out of line_* and document_*, adding
+ format_line_message for line messages and format_document_message for
+ document messages, using only one function for both errors and
+ warnings, as in XS.
+
2023-12-10 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/ParserNonXS.pm (_parse_texi): rename global
diff --git a/tp/Texinfo/Report.pm b/tp/Texinfo/Report.pm
index 82eba19818..2aa441efcc 100644
--- a/tp/Texinfo/Report.pm
+++ b/tp/Texinfo/Report.pm
@@ -80,46 +80,72 @@ sub add_formatted_message($$)
push @{$self->{'errors_warnings'}}, $message;
}
-# format a line warning
-sub line_warn($$$$;$$)
+sub format_line_message($$$$$;$$)
{
my $self = shift;
my $configuration_information = shift;
+ my $type = shift;
my $text = shift;
my $error_location_info = shift;
my $continuation = shift;
my $silent = shift;
+ # TODO actually a bug, add a bug message/cluck
return if (!defined($error_location_info));
- my $warn_line;
+ my $message_line;
if (defined($error_location_info->{'macro'})
and $error_location_info->{'macro'} ne '') {
- # TODO change the context to "Texinfo source file warning in a macro"
- # when nearing the release
- $warn_line = sprintf(__p("Texinfo source file warning",
- "warning: %s (possibly involving \@%s)")."\n",
+ if ($type eq 'warning') {
+ # TODO change the context to "Texinfo source file warning in a macro"
+ # when nearing the release
+ $message_line = sprintf(__p("Texinfo source file warning",
+ "warning: %s (possibly involving \@%s)")."\n",
+ $text, $error_location_info->{'macro'});
+ } else {
+ $message_line = sprintf(__p("Texinfo source file error in macro",
+ "%s (possibly involving \@%s)")."\n",
$text, $error_location_info->{'macro'});
+ }
} else {
- $warn_line = sprintf(__p("Texinfo source file warning",
- "warning: %s")."\n",
- $text);
+ if ($type eq 'warning') {
+ $message_line = sprintf(__p("Texinfo source file warning",
+ "warning: %s")."\n",
+ $text);
+ } else {
+ $message_line = $text."\n";
+ }
}
- warn $warn_line if (defined($configuration_information)
+ warn $message_line if (defined($configuration_information)
and $configuration_information->get_conf('DEBUG')
and not $silent);
my %location_info = %{$error_location_info};
delete $location_info{'file_name'} if (exists ($location_info{'file_name'})
and not
defined($location_info{'file_name'}));
- my $warning
- = { 'type' => 'warning', 'text' => $text, 'error_line' => $warn_line,
+ my $result
+ = { 'type' => $type, 'text' => $text, 'error_line' => $message_line,
%location_info };
- $warning->{'continuation'} = $continuation if ($continuation);
- push @{$self->{'errors_warnings'}}, $warning;
+ $result->{'continuation'} = $continuation if ($continuation);
+ return $result;
+}
+
+
+# format a line warning
+sub line_warn($$$$;$$)
+{
+ my $self = shift;
+ my $configuration_information = shift;
+ my $text = shift;
+ my $error_location_info = shift;
+ my $continuation = shift;
+ my $silent = shift;
+
+ my $warning = $self->format_line_message($configuration_information,
+ 'warning', $text, $error_location_info, $continuation, $silent);
+ $self->add_formatted_message($warning);
}
-# format a line error
sub line_error($$$$;$)
{
my $self = shift;
@@ -129,51 +155,53 @@ sub line_error($$$$;$)
my $continuation = shift;
my $silent = shift;
- if (defined($error_location_info)) {
- my $error_text;
- if ($error_location_info->{'macro'} ne '') {
- $error_text = sprintf(__p("Texinfo source file error in macro",
- "%s (possibly involving \@%s)")."\n",
- $text, $error_location_info->{'macro'});
- } else {
- $error_text = $text."\n";
- }
- warn $error_text if (defined($configuration_information)
- and $configuration_information->get_conf('DEBUG')
- and not $silent);
- my %location_info = %{$error_location_info};
- delete $location_info{'file_name'} if (exists ($location_info{'file_name'})
- and not
defined($location_info{'file_name'}));
- my $error = { 'type' => 'error', 'text' => $text,
- 'error_line' => $error_text,
- %{$error_location_info} };
- $error->{'continuation'} = $continuation if ($continuation);
- push @{$self->{'errors_warnings'}}, $error;
- }
- $self->{'error_nrs'}++ unless ($continuation);
+ my $error = $self->format_line_message($configuration_information, 'error',
+ $text, $error_location_info, $continuation, $silent);
+ $self->add_formatted_message($error);
}
-sub document_warn($$$;$)
+sub format_document_message($$$$;$)
{
my $self = shift;
my $configuration_information = shift;
+ my $type = shift;
my $text = shift;
my $continuation = shift;
- my $warn_line;
+ my $message_line;
if (defined($configuration_information)
and defined($configuration_information->get_conf('PROGRAM'))
and $configuration_information->get_conf('PROGRAM') ne '') {
- $warn_line = sprintf(__p("whole document warning", "%s: warning: %s")."\n",
- $configuration_information->get_conf('PROGRAM'), $text);
+ if ($type eq 'warning') {
+ $message_line = sprintf(__p("whole document warning", "%s: warning:
%s")."\n",
+ $configuration_information->get_conf('PROGRAM'), $text);
+ } else {
+ $message_line = sprintf("%s: %s\n",
+ $configuration_information->get_conf('PROGRAM'), $text);
+ }
} else {
- $warn_line = sprintf(__p("whole document warning", "warning: %s")."\n",
- $text);
+ if ($type eq 'warning') {
+ $message_line = sprintf(__p("whole document warning", "warning:
%s")."\n",
+ $text);
+ } else {
+ $message_line = "$text\n";
+ }
}
- my $warning = { 'type' => 'warning', 'text' => $text,
- 'error_line' => $warn_line };
- $warning->{'continuation'} = $continuation if ($continuation);
- push @{$self->{'errors_warnings'}}, $warning;
+ my $result = { 'type' => $type, 'text' => $text, 'error_line' =>
$message_line };
+ $result->{'continuation'} = $continuation if ($continuation);
+ return $result;
+}
+
+sub document_warn($$$;$)
+{
+ my $self = shift;
+ my $configuration_information = shift;
+ my $text = shift;
+ my $continuation = shift;
+
+ my $warning = $self->format_document_message($configuration_information,
+ 'warning', $text,
$continuation);
+ $self->add_formatted_message($warning);
}
sub document_error($$$;$)
@@ -183,20 +211,9 @@ sub document_error($$$;$)
my $text = shift;
my $continuation = shift;
- my $error_line;
- if (defined($configuration_information)
- and defined($configuration_information->get_conf('PROGRAM'))
- and $configuration_information->get_conf('PROGRAM') ne '') {
- $error_line = sprintf("%s: %s\n",
- $configuration_information->get_conf('PROGRAM'), $text);
- } else {
- $error_line = "$text\n";
- }
- my $error = { 'type' => 'error', 'text' => $text,
- 'error_line' => $error_line, };
- $error->{'continuation'} = $continuation if ($continuation);
- push @{$self->{'errors_warnings'}}, $error;
- $self->{'error_nrs'}++ unless ($continuation);
+ my $error = $self->format_document_message($configuration_information,
+ 'error', $text, $continuation);
+ $self->add_formatted_message($error);
}
1;