[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Tue, 14 May 2024 07:46:29 -0400 (EDT) |
branch: master
commit eff3c78e51400db56f7db6b235de3ef181e117f1
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue May 14 13:46:14 2024 +0200
* tp/Texinfo/ParserNonXS.pm (parse_texi_piece, parse_texi_line)
(parse_texi_text, parse_texi_file),
tp/Texinfo/XS/parsetexi/Parsetexi.pm (parse_texi_file)
(parse_texi_piece, parse_texi_text, parse_texi_line): require a parser
in argument of parse_texi_* instead of creating one if undef. Do not
export any function explicitly.
* Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm,
Pod-Simple-Texinfo/pod2texi.pl, tp/t/accents.t,
tp/t/automatic_nodes.t, tp/t/index_before_item.t,
tp/t/protect_character_in_texinfo.t, tp/t/test_brace_count.t,
tp/t/test_fill_gaps_in_sectioning.t, tp/t/test_is_content_empty.t,
tp/t/test_protect_contents.t, tp/t/test_sort.t: update for need of
parser in parse_texi_*.
---
ChangeLog | 17 ++++++++++++
Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm | 22 +++++++++------
Pod-Simple-Texinfo/pod2texi.pl | 4 +--
tp/Texinfo/ParserNonXS.pm | 40 ++++++++--------------------
tp/Texinfo/XS/parsetexi/Parsetexi.pm | 27 ++++---------------
tp/t/accents.t | 5 ++--
tp/t/automatic_nodes.t | 3 ++-
tp/t/index_before_item.t | 5 ++--
tp/t/protect_character_in_texinfo.t | 8 +++---
tp/t/test_brace_count.t | 5 ++--
tp/t/test_fill_gaps_in_sectioning.t | 5 ++--
tp/t/test_is_content_empty.t | 10 ++++---
tp/t/test_protect_contents.t | 5 ++--
tp/t/test_sort.t | 5 ++--
14 files changed, 81 insertions(+), 80 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 04c193b6c7..82c93d77f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2024-05-14 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/ParserNonXS.pm (parse_texi_piece, parse_texi_line)
+ (parse_texi_text, parse_texi_file),
+ tp/Texinfo/XS/parsetexi/Parsetexi.pm (parse_texi_file)
+ (parse_texi_piece, parse_texi_text, parse_texi_line): require a parser
+ in argument of parse_texi_* instead of creating one if undef. Do not
+ export any function explicitly.
+
+ * Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm,
+ Pod-Simple-Texinfo/pod2texi.pl, tp/t/accents.t,
+ tp/t/automatic_nodes.t, tp/t/index_before_item.t,
+ tp/t/protect_character_in_texinfo.t, tp/t/test_brace_count.t,
+ tp/t/test_fill_gaps_in_sectioning.t, tp/t/test_is_content_empty.t,
+ tp/t/test_protect_contents.t, tp/t/test_sort.t: update for need of
+ parser in parse_texi_*.
+
2024-05-14 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/parsetexi/api.c (parser_set_debug),
diff --git a/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm
b/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm
index 95b9d086b5..fddf693f56 100644
--- a/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm
+++ b/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm
@@ -54,7 +54,7 @@ use Pod::Simple::PullParser ();
#use Pod::ParseLink;
use Texinfo::Convert::NodeNameNormalization qw(convert_to_identifier);
-use Texinfo::Parser qw(parse_texi_line parse_texi_piece);
+use Texinfo::Parser;
use Texinfo::Convert::Texinfo;
use Texinfo::Convert::TextContent;
use Texinfo::Document;
@@ -361,7 +361,8 @@ sub pod_title_to_file_name($)
sub _protect_comma($)
{
my $texinfo = shift;
- my $tree = parse_texi_line(undef, $texinfo);
+ my $parser = Texinfo::Parser::parser();
+ my $tree = $parser->parse_texi_line($texinfo);
Texinfo::ManipulateTree::protect_comma_in_tree($tree);
$tree = Texinfo::Document::rebuild_tree($tree);
return Texinfo::Convert::Texinfo::convert_to_texinfo($tree);
@@ -370,7 +371,8 @@ sub _protect_comma($)
sub _protect_colon($)
{
my $texinfo = shift;
- my $tree = parse_texi_line(undef, $texinfo);
+ my $parser = Texinfo::Parser::parser();
+ my $tree = $parser->parse_texi_line($texinfo);
Texinfo::ManipulateTree::protect_colon_in_tree($tree);
$tree = Texinfo::Document::rebuild_tree($tree);
return Texinfo::Convert::Texinfo::convert_to_texinfo($tree);
@@ -381,7 +383,8 @@ sub _protect_hashchar($)
my $texinfo = shift;
# protect # first in line
if ($texinfo =~ /#/) {
- my $document = parse_texi_piece(undef, $texinfo);
+ my $parser = Texinfo::Parser::parser();
+ my $document = $parser->parse_texi_piece($texinfo);
my $tree = $document->tree();
Texinfo::Transformations::protect_hashchar_at_line_beginning($tree);
# rebuild the tree
@@ -395,7 +398,8 @@ sub _protect_hashchar($)
sub _reference_to_text_in_texi($)
{
my $texinfo = shift;
- my $document = parse_texi_piece(undef, $texinfo);
+ my $parser = Texinfo::Parser::parser();
+ my $document = $parser->parse_texi_piece($texinfo);
my $tree = $document->tree();
Texinfo::Transformations::reference_to_arg_in_tree($tree);
# rebuild the tree
@@ -533,7 +537,8 @@ sub _prepare_anchor($$)
return '';
}
# Now we know that we have something.
- my $node_tree = parse_texi_line(undef, $node);
+ my $parser = Texinfo::Parser::parser();
+ my $node_tree = $parser->parse_texi_line($node);
my $normalized_base = convert_to_identifier($node_tree);
my $normalized = $normalized_base;
my $number_appended = 0;
@@ -544,7 +549,7 @@ sub _prepare_anchor($$)
my $node_name;
if ($number_appended) {
$texinfo_node_name = "$node $number_appended";
- $node_tree = parse_texi_line(undef, $texinfo_node_name);
+ $node_tree = $parser->parse_texi_line($texinfo_node_name);
}
Texinfo::ManipulateTree::protect_comma_in_tree($node_tree);
Texinfo::ManipulateTree::protect_colon_in_tree($node_tree);
@@ -900,7 +905,8 @@ sub _texinfo_handle_element_end($$$)
if ($result =~ /\S/
and (!defined($command_argument) or $command_argument !~ /\S/)) {
# use some raw text if the expansion lead to empty Texinfo code
- my $tree = parse_texi_line(undef, $result);
+ my $parser = Texinfo::Parser::parse();
+ my $tree = $parser->parse_texi_line($result);
my $converter = Texinfo::Convert::TextContent->converter();
$command_argument = protect_text($converter->convert_tree($tree));
}
diff --git a/Pod-Simple-Texinfo/pod2texi.pl b/Pod-Simple-Texinfo/pod2texi.pl
index 26594f7d7f..e19174a7fb 100755
--- a/Pod-Simple-Texinfo/pod2texi.pl
+++ b/Pod-Simple-Texinfo/pod2texi.pl
@@ -337,8 +337,8 @@ sub _parsed_manual_tree($$$$$)
if ($self->texinfo_sectioning_base_level() > 0) {
my $manual_texi = Pod::Simple::Texinfo::protect_text(
$self->texinfo_short_title(), 1, 1);
- $commands_heading_content
- = Texinfo::Parser::parse_texi_line(undef, $manual_texi);
+ my $parser = Texinfo::Parser::parser();
+ $commands_heading_content = $parser->parse_texi_line($manual_texi);
}
Texinfo::Transformations::fill_gaps_in_sectioning($tree,
$commands_heading_content);
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index d5ba5e819b..bf25011d47 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -94,7 +94,6 @@ use Texinfo::Convert::NodeNameNormalization;
use Texinfo::Translations;
require Exporter;
-our @ISA = qw(Exporter);
our $module_loaded = 0;
sub import {
@@ -109,14 +108,6 @@ sub import {
goto &Exporter::import;
}
-our @EXPORT_OK = qw(
- parser
- parse_texi_file
- parse_texi_line
- parse_texi_piece
- parse_texi_text
-);
-
our $VERSION = '7.1dev';
@@ -760,12 +751,10 @@ sub parse_texi_piece($$;$)
{
my ($self, $text, $line_nr) = @_;
- return undef if (!defined($text));
+ return undef if (!defined($text) or !defined($self));
$line_nr = 1 if (not defined($line_nr));
- $self = parser() if (!defined($self));
-
_input_push_text($self, $text, $line_nr);
my ($document_root, $before_node_section)
@@ -781,12 +770,10 @@ sub parse_texi_line($$;$)
{
my ($self, $text, $line_nr) = @_;
- return undef if (!defined($text));
+ return undef if (!defined($text) or !defined($self));
$line_nr = 1 if (not defined($line_nr));
- $self = parser() if (!defined($self));
-
_input_push_text($self, $text, $line_nr);
my $root = {'type' => 'root_line'};
@@ -799,12 +786,10 @@ sub parse_texi_text($$;$)
{
my ($self, $text, $line_nr) = @_;
- return undef if (!defined($text));
+ return undef if (!defined($text) or !defined($self));
$line_nr = 1 if (not defined($line_nr));
- $self = parser() if (!defined($self));
-
_input_push_text($self, $text, $line_nr);
my $document = $self->_parse_texi_document();
@@ -911,6 +896,8 @@ sub parse_texi_file($$)
{
my ($self, $input_file_path) = @_;
+ return undef if (!defined($self));
+
my ($status, $file_name, $directories, $error_message)
= _input_push_file($self, $input_file_path);
if (!$status) {
@@ -925,8 +912,6 @@ sub parse_texi_file($$)
return undef;
}
- $self = parser() if (!defined($self));
-
my $document = $self->_parse_texi_document();
get_parser_info($self);
$self->{'global_info'}->{'input_file_name'} = $file_name;
@@ -8156,11 +8141,8 @@ Same as values set by C<@set>.
Different methods may be called to parse some Texinfo code:
C<parse_texi_line> for a line, C<parse_texi_piece> for a fragment of
Texinfo, C<parse_texi_text> for a string corresponding to a full document
-and C<parse_texi_file> for a file.
-
-For all those functions, if the I<$parser> argument is undef, a new
-parser object is generated to parse the line. Otherwise the parser given
-as an argument is used to parse into a tree.
+and C<parse_texi_file> for a file. The first argument of these functions
+is a parser.
When C<parse_texi_line> is used, the resulting tree is rooted at
a C<root_line> type container. Otherwise, the resulting tree should be
@@ -8168,7 +8150,7 @@ rooted at a C<document_root> type container.
=over
-=item $tree = parse_texi_line($parser, $text, $first_line_number)
+=item $tree = $parser->parse_texi_line($text, $first_line_number)
X<C<parse_texi_line>>
This function is used to parse a short fragment of Texinfo code.
@@ -8176,7 +8158,7 @@ This function is used to parse a short fragment of
Texinfo code.
I<$text> is the string containing the texinfo line. I<$first_line_number> is
the line number of the line, if undef, it will be set to 1.
-=item $document = parse_texi_piece($parser, $text, $first_line_number)
+=item $document = $parser->parse_texi_piece($text, $first_line_number)
X<C<parse_texi_piece>>
This function is used to parse Texinfo fragments.
@@ -8184,7 +8166,7 @@ This function is used to parse Texinfo fragments.
I<$text> is the string containing the texinfo text. I<$first_line_number> is
the line number of the first text line, if undef, it will be set to 1.
-=item $document = parse_texi_text($parser, $text, $first_line_number)
+=item $document = $parser->parse_texi_text($text, $first_line_number)
X<C<parse_texi_text>>
This function is used to parse a text as a whole document.
@@ -8192,7 +8174,7 @@ This function is used to parse a text as a whole document.
I<$text> is the string containing the texinfo text. I<$first_line_number> is
the line number of the first text line, if undef, it will be set to 1.
-=item $document = parse_texi_file($parser, $file_name)
+=item $document = $parser->parse_texi_file($file_name)
X<C<parse_texi_file>>
The file with name I<$file_name> is considered to be a Texinfo file and
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index f531dd20c6..f3f8d3b806 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -50,19 +50,6 @@ use Texinfo::Translations;
# to return a resulting document
use Texinfo::Document;
-require Exporter;
-
-our @ISA = qw(Exporter);
-our %EXPORT_TAGS = ( 'all' => [ qw(
- parser
- parse_texi_file
- parse_texi_line
- parse_texi_piece
- parse_texi_text
-) ] );
-
-our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
-
my %parser_default_configuration =
(%Texinfo::Common::default_parser_customization_values);
@@ -236,6 +223,8 @@ sub parse_texi_file ($$)
my $input_file_path = shift;
my $tree_stream;
+ return undef if (!defined($self));
+
# the file is already a byte string, taken as is from the command
# line. The encoding was detected as COMMAND_LINE_ENCODING, but
# it is not useful for the XS parser.
@@ -268,12 +257,10 @@ sub parse_texi_piece($$;$$)
{
my ($self, $text, $line_nr, $no_store) = @_;
- return undef if (!defined($text));
+ return undef if (!defined($text) or !defined($self));
$line_nr = 1 if (not defined($line_nr));
- $self = parser() if (!defined($self));
-
# pass a binary UTF-8 encoded string to C code
my $utf8_bytes = Encode::encode('utf-8', $text);
my $document_descriptor = parse_piece($utf8_bytes, $line_nr);
@@ -288,12 +275,10 @@ sub parse_texi_text($$;$)
{
my ($self, $text, $line_nr) = @_;
- return undef if (!defined($text));
+ return undef if (!defined($text) or !defined($self));
$line_nr = 1 if (not defined($line_nr));
- $self = parser() if (!defined($self));
-
# pass a binary UTF-8 encoded string to C code
my $utf8_bytes = Encode::encode('utf-8', $text);
my $document_descriptor = parse_text($utf8_bytes, $line_nr);
@@ -307,12 +292,10 @@ sub parse_texi_line($$;$$)
{
my ($self, $text, $line_nr, $no_store) = @_;
- return undef if (!defined($text));
+ return undef if (!defined($text) or !defined($self));
$line_nr = 1 if (not defined($line_nr));
- $self = parser() if (!defined($self));
-
# pass a binary UTF-8 encoded string to C code
my $utf8_bytes = Encode::encode('utf-8', $text);
my $document_descriptor = parse_string($utf8_bytes, $line_nr);
diff --git a/tp/t/accents.t b/tp/t/accents.t
index e4bd21a3d7..c00c8b5800 100644
--- a/tp/t/accents.t
+++ b/tp/t/accents.t
@@ -197,11 +197,12 @@ foreach my $test (
test_enable_encoding($test);
}
-my $res_e = Texinfo::Parser::parse_texi_line(undef, '@^e');
+my $parser = Texinfo::Parser::parser();
+my $res_e = $parser->parse_texi_line('@^e');
my $result = Texinfo::Convert::Text::convert_to_text($res_e,
{'enabled_encoding' => 'utf-8'});
is ($result, "\x{00EA}", 'enable encoding @^e');
-my $res_aa = Texinfo::Parser::parse_texi_line(undef, '@aa{}');
+my $res_aa = $parser->parse_texi_line('@aa{}');
$result = Texinfo::Convert::Text::convert_to_text($res_aa, {'enabled_encoding'
=> 'utf-8'});
is ($result, "\x{00E5}", 'enable encoding @aa{}');
diff --git a/tp/t/automatic_nodes.t b/tp/t/automatic_nodes.t
index 0ed63dfa11..3c8594aa87 100644
--- a/tp/t/automatic_nodes.t
+++ b/tp/t/automatic_nodes.t
@@ -87,7 +87,8 @@ my $parser = Texinfo::Parser::parser();
my $document = $parser->parse_texi_text('@node a node
');
my $tree = $document->tree();
-my $line_tree = Texinfo::Parser::parse_texi_line (undef, 'a node');
+my $line_parser = Texinfo::Parser::parser();
+my $line_tree = $line_parser->parse_texi_line ('a node');
SKIP:
{
diff --git a/tp/t/index_before_item.t b/tp/t/index_before_item.t
index 26aef75be3..8bfef44a9f 100644
--- a/tp/t/index_before_item.t
+++ b/tp/t/index_before_item.t
@@ -7,7 +7,7 @@ use Test::More;
BEGIN { plan tests => 6; }
-use Texinfo::Parser qw(parse_texi_piece);
+use Texinfo::Parser;
use Texinfo::Convert::Texinfo;
use Texinfo::Document;
use Texinfo::ManipulateTree;
@@ -21,7 +21,8 @@ sub run_test($$$)
my $out = shift;
my $name = shift;
- my $document = parse_texi_piece(undef, $in);
+ my $parser = Texinfo::Parser::parser();
+ my $document = $parser->parse_texi_piece($in);
my $tree = $document->tree();
#print STDERR Texinfo::DebugTree::convert_tree(undef, $tree)."\n";
diff --git a/tp/t/protect_character_in_texinfo.t
b/tp/t/protect_character_in_texinfo.t
index caef11dca9..397496e14d 100644
--- a/tp/t/protect_character_in_texinfo.t
+++ b/tp/t/protect_character_in_texinfo.t
@@ -7,7 +7,7 @@ use Test::More;
BEGIN { plan tests => 7; }
-use Texinfo::Parser qw(parse_texi_line parse_texi_piece);
+use Texinfo::Parser;
use Texinfo::Convert::Texinfo;
use Texinfo::Document;
use Texinfo::ManipulateTree;
@@ -37,10 +37,12 @@ sub run_test($$$$)
$reference_as_line = $reference_as_text if not defined($reference_as_line);
}
- my $document = parse_texi_piece(undef, $in);
+ my $parser = Texinfo::Parser::parser();
+ my $document = $parser->parse_texi_piece($in);
my $tree_as_text = $document->tree();
- my $tree_as_line = parse_texi_line(undef, $in);
+ my $line_parser = Texinfo::Parser::parser();
+ my $tree_as_line = $line_parser->parse_texi_line($in);
foreach my $tree ($tree_as_text, $tree_as_line) {
if ($do->{'protect_comma'}) {
diff --git a/tp/t/test_brace_count.t b/tp/t/test_brace_count.t
index 56264bd565..45466e2b5d 100644
--- a/tp/t/test_brace_count.t
+++ b/tp/t/test_brace_count.t
@@ -7,7 +7,7 @@ use Test::More;
BEGIN { plan tests => 13; }
-use Texinfo::Parser qw(parse_texi_line);
+use Texinfo::Parser;
use Texinfo::Common;
ok(1, "modules loading");
@@ -58,7 +58,8 @@ sub run_test($$$$)
my $ref_braces_count = shift;
my $name = shift;
- my $tree = parse_texi_line(undef, $in);
+ my $parser = Texinfo::Parser::parser();
+ my $tree = $parser->parse_texi_line($in);
my $text_element = _find_text($tree);
my $braces_count
diff --git a/tp/t/test_fill_gaps_in_sectioning.t
b/tp/t/test_fill_gaps_in_sectioning.t
index 4fffc8c266..fcbdc82648 100644
--- a/tp/t/test_fill_gaps_in_sectioning.t
+++ b/tp/t/test_fill_gaps_in_sectioning.t
@@ -8,7 +8,7 @@ use Test::More;
BEGIN { plan tests => 6; }
use Texinfo::Transformations;
-use Texinfo::Parser qw(parse_texi_text);
+use Texinfo::Parser;
use Texinfo::Convert::Texinfo;
use Texinfo::Document;
@@ -22,7 +22,8 @@ sub test_correction($$$;$)
# if set, test _correct_level instead of fill_gaps_in_sectioning
my $test_correct_level = shift;
- my $document = parse_texi_text(undef, $in);
+ my $parser = Texinfo::Parser::parser();
+ my $document = $parser->parse_texi_text($in);
my $tree = $document->tree();
if (! defined($test_correct_level)) {
diff --git a/tp/t/test_is_content_empty.t b/tp/t/test_is_content_empty.t
index 98ff566589..ee16995170 100644
--- a/tp/t/test_is_content_empty.t
+++ b/tp/t/test_is_content_empty.t
@@ -7,7 +7,7 @@ use Test::More;
BEGIN { plan tests => 23; }
-use Texinfo::Parser qw(parse_texi_piece parse_texi_line);
+use Texinfo::Parser;
#use Texinfo::Convert::Texinfo;
use Texinfo::Common;
use Data::Dumper;
@@ -20,9 +20,13 @@ sub test_is_empty($$$;$)
my $is_empty = shift;
my $in = shift;
my $do_not_ignore_index_entries = shift;
- my $document = parse_texi_piece(undef, $in);
+
+ my $parser = Texinfo::Parser::parser();
+ my $document = $parser->parse_texi_piece($in);
my $tree_as_text = $document->tree();
- my $tree_as_line = parse_texi_line(undef, $in);
+
+ my $line_parser = Texinfo::Parser::parser();
+ my $tree_as_line = $line_parser->parse_texi_line($in);
my $result_as_text = Texinfo::Common::is_content_empty($tree_as_text,
$do_not_ignore_index_entries);
my $result_as_line = Texinfo::Common::is_content_empty($tree_as_line,
diff --git a/tp/t/test_protect_contents.t b/tp/t/test_protect_contents.t
index b10572a8f7..6538673e75 100644
--- a/tp/t/test_protect_contents.t
+++ b/tp/t/test_protect_contents.t
@@ -7,7 +7,7 @@ use Test::More;
BEGIN { plan tests => 2; }
-use Texinfo::Parser qw(parse_texi_line parse_texi_piece);
+use Texinfo::Parser;
use Texinfo::Convert::Texinfo;
use Texinfo::Document;
use Texinfo::Transformations;
@@ -21,7 +21,8 @@ sub run_test($$$$)
my $out = shift;
my $name = shift;
- my $document = parse_texi_piece(undef, $in);
+ my $parser = Texinfo::Parser::parser();
+ my $document = $parser->parse_texi_piece($in);
my $tree = $document->tree();
my $texi_result;
diff --git a/tp/t/test_sort.t b/tp/t/test_sort.t
index c64e8e1485..5754b0f996 100644
--- a/tp/t/test_sort.t
+++ b/tp/t/test_sort.t
@@ -16,7 +16,8 @@ use Texinfo::Config;
ok(1, "modules loading");
-my $tree = Texinfo::Parser::parse_texi_line(undef, '@copyright{}
@quotedblbase{}');
+my $parser = Texinfo::Parser::parser();
+my $tree = $parser->parse_texi_line('@copyright{} @quotedblbase{}');
my $result = Texinfo::Convert::Text::convert_to_text($tree, {'sort_string' =>
1});
is ($result, 'C ,,', 'sort no encoding');
@@ -30,7 +31,7 @@ $result = Texinfo::Convert::Text::convert_to_text($tree,
{'sort_string' => 1,
is ($result, "\x{00A9} ,,", 'sort iso-8859-1');
-my $parser = Texinfo::Parser::parser();
+$parser = Texinfo::Parser::parser();
my $document = $parser->parse_texi_text('@node Top
@cindex !