[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/ParserNonXS.pm (parse_texi_file, _s
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/ParserNonXS.pm (parse_texi_file, _setup_text_root) (_parse_texi), tp/Texinfo/Structuring.pm (no_root_command_tree), tp/Texinfo/Transformations.pm: use a function to setup 'text_root' type in tp/Texinfo/ParserNonXS.pm. Prepare recognizing trees with text_root and @bye only as trees without root command in no_root_command_tree(). No functional change, aim is to reduce difference with future code changing the tree in ParserNonXS.pm. |
Date: |
Tue, 07 Sep 2021 16:33:22 -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 9436ea0 * tp/Texinfo/ParserNonXS.pm (parse_texi_file,
_setup_text_root) (_parse_texi), tp/Texinfo/Structuring.pm
(no_root_command_tree), tp/Texinfo/Transformations.pm: use a function to setup
'text_root' type in tp/Texinfo/ParserNonXS.pm. Prepare recognizing trees with
text_root and @bye only as trees without root command in
no_root_command_tree(). No functional change, aim is to reduce difference with
future code changing the tree in ParserNonXS.pm.
9436ea0 is described below
commit 9436ea007b15a63ab0066eb0483c488c0fc4f8f0
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Sep 7 22:33:12 2021 +0200
* tp/Texinfo/ParserNonXS.pm (parse_texi_file, _setup_text_root)
(_parse_texi), tp/Texinfo/Structuring.pm (no_root_command_tree),
tp/Texinfo/Transformations.pm: use a function to setup 'text_root'
type in tp/Texinfo/ParserNonXS.pm. Prepare recognizing trees
with text_root and @bye only as trees without root command in
no_root_command_tree().
No functional change, aim is to reduce difference with future code
changing the tree in ParserNonXS.pm.
---
ChangeLog | 11 +++++++++++
tp/Texinfo/ParserNonXS.pm | 44 +++++++++++++++++++++++++------------------
tp/Texinfo/Structuring.pm | 26 +++++++++++++++++++------
tp/Texinfo/Transformations.pm | 9 +++------
tp/t/accents.t | 15 +++++++++++++--
5 files changed, 73 insertions(+), 32 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 09b65ba..0d8039e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2021-09-07 Patrice Dumas <pertusus@free.fr>
+ * tp/Texinfo/ParserNonXS.pm (parse_texi_file, _setup_text_root)
+ (_parse_texi), tp/Texinfo/Structuring.pm (no_root_command_tree),
+ tp/Texinfo/Transformations.pm: use a function to setup 'text_root'
+ type in tp/Texinfo/ParserNonXS.pm. Prepare recognizing trees
+ with text_root and @bye only as trees without root command in
+ no_root_command_tree().
+ No functional change, aim is to reduce difference with future code
+ changing the tree in ParserNonXS.pm.
+
+2021-09-07 Patrice Dumas <pertusus@free.fr>
+
* tp/Texinfo/Convert/Converter.pm (determine_files_and_directory)
(_set_element_file, _top_node_filename, _set_pages_files)
(create_destination_directory), tp/DebugTexinfo/DebugTree.pm,
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 6fb387e..a72025a 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -933,15 +933,15 @@ sub parse_texi_file($$)
last;
}
}
- my $root = { 'contents' => [], 'type' => 'text_root' };
+ my ($document_root, $text_root) = _setup_text_root();
if (@first_lines) {
- push @{$root->{'contents'}}, { 'type' => 'preamble', 'contents' => [],
- 'parent' => $root };
+ push @{$text_root->{'contents'}}, { 'type' => 'preamble', 'contents' => [],
+ 'parent' => $text_root };
foreach my $line (@first_lines) {
- push @{$root->{'contents'}->[-1]->{'contents'}},
+ push @{$text_root->{'contents'}->[-1]->{'contents'}},
{ 'text' => $line,
'type' => 'preamble_text',
- 'parent' => $root->{'contents'}->[-1]
+ 'parent' => $text_root->{'contents'}->[-1]
};
}
}
@@ -958,18 +958,18 @@ sub parse_texi_file($$)
$self->{'info'}->{'input_file_name'} = $file_name;
$self->{'info'}->{'input_directory'} = $directories;
- my $tree = $self->_parse_texi($root);
-
- # Find 'text_root', which contains everything before first node/section.
- # if there are elements, 'text_root' is the first content, otherwise it
- # is the root.
- my $text_root;
- if ($tree->{'type'} eq 'text_root') {
- $text_root = $tree;
- } elsif ($tree->{'contents'} and $tree->{'contents'}->[0]
- and $tree->{'contents'}->[0]->{'type'} eq 'text_root') {
- $text_root = $tree->{'contents'}->[0];
- }
+ my $tree = $self->_parse_texi($document_root);
+
+ ## Find 'text_root', which contains everything before first node/section.
+ ## if there are elements, 'text_root' is the first content, otherwise it
+ ## is the root.
+ #my $text_root;
+ #if ($tree->{'type'} eq 'text_root') {
+ # $text_root = $tree;
+ #} elsif ($tree->{'contents'} and $tree->{'contents'}->[0]
+ # and $tree->{'contents'}->[0]->{'type'} eq 'text_root') {
+ # $text_root = $tree->{'contents'}->[0];
+ #}
# Put everything before @setfilename in a special type. This allows to
# ignore everything before @setfilename.
@@ -3618,13 +3618,20 @@ sub _check_valid_nesting {
}
}
+sub _setup_text_root()
+{
+ my $text_root = { 'contents' => [], 'type' => 'text_root' };
+ my $document_root = $text_root;
+ return ($document_root, $text_root);
+}
# the main subroutine
sub _parse_texi($;$)
{
my ($self, $root) = @_;
- $root = { 'contents' => [], 'type' => 'text_root' } if (!defined($root));
+ ($root) = _setup_text_root() if (!defined($root));
+
my $current = $root;
my $line_nr;
@@ -5444,6 +5451,7 @@ sub _parse_texi($;$)
}
# Misc text except end of line
} elsif (defined $misc_text) {
+ print STDERR "MISC TEXT: $misc_text\n" if ($self->{'DEBUG'});
my $new_text = $misc_text;
substr ($line, 0, length ($misc_text)) = '';
$current = _merge_text($self, $current, $new_text);
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index dfce63c..f24beef 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -114,6 +114,23 @@ sub section_level($)
}
+sub no_root_command_tree($)
+{
+ my $root = shift;
+ if (!$root->{'type'} or $root->{'type'} ne 'document_root'
+ or !$root->{'contents'}
+ or scalar(@{$root->{'contents'}}) == 0
+ or ($root->{'contents'}->[0]->{'type'}
+ and $root->{'contents'}->[0]->{'type'} eq 'text_root'
+ and (scalar(@{$root->{'contents'}}) == 1
+ or (scalar(@{$root->{'contents'}}) == 2
+ and $root->{'contents'}->[1]->{'cmdname'}
+ and $root->{'contents'}->[1]->{'cmdname'} eq 'bye')))) {
+ return 1;
+ }
+ return 0;
+}
+
# Go through the sectioning commands (e.g. @chapter, not @node), and
# set:
# 'number'
@@ -130,8 +147,7 @@ sub sectioning_structure($$$)
my $configuration_informations = shift;
my $root = shift;
- if (!$root->{'type'} or $root->{'type'} ne 'document_root'
- or !$root->{'contents'}) {
+ if (no_root_command_tree($root)) {
return undef;
}
@@ -819,8 +835,7 @@ sub nodes_tree($$$$$)
sub split_by_node($)
{
my $root = shift;
- if (!$root->{'type'} or $root->{'type'} ne 'document_root'
- or !$root->{'contents'} or !@{$root->{'contents'}}) {
+ if (no_root_command_tree($root)) {
return undef;
}
my $elements;
@@ -868,8 +883,7 @@ sub split_by_node($)
sub split_by_section($)
{
my $root = shift;
- if (!$root->{'type'} or $root->{'type'} ne 'document_root'
- or !$root->{'contents'} or !@{$root->{'contents'}}) {
+ if (no_root_command_tree($root)) {
return undef;
}
my $elements;
diff --git a/tp/Texinfo/Transformations.pm b/tp/Texinfo/Transformations.pm
index 72b8744..a25a6ea 100644
--- a/tp/Texinfo/Transformations.pm
+++ b/tp/Texinfo/Transformations.pm
@@ -73,8 +73,7 @@ sub _correct_level($$;$)
sub fill_gaps_in_sectioning($)
{
my $root = shift;
- if (!$root->{'type'} or $root->{'type'} ne 'document_root'
- or !$root->{'contents'}) {
+ if (Texinfo::Structuring::no_root_command_tree($root)) {
return undef;
}
my @sections_list;
@@ -323,8 +322,7 @@ sub insert_nodes_for_sectioning_commands($$$$)
my $targets_list = shift;
my $labels = shift;
- if (!$root->{'type'} or $root->{'type'} ne 'document_root'
- or !$root->{'contents'}) {
+ if (Texinfo::Structuring::no_root_command_tree($root)) {
return (undef, undef);
}
my @added_nodes;
@@ -457,8 +455,7 @@ sub _get_non_automatic_nodes_with_sections($)
{
my $root = shift;
- if (!$root->{'type'} or $root->{'type'} ne 'document_root'
- or !$root->{'contents'}) {
+ if (Texinfo::Structuring::no_root_command_tree($root)) {
return undef;
}
my @non_automatic_nodes;
diff --git a/tp/t/accents.t b/tp/t/accents.t
index 4fda0c4..d43e9a3 100644
--- a/tp/t/accents.t
+++ b/tp/t/accents.t
@@ -18,6 +18,17 @@ use Texinfo::Convert::HTML;
ok(1, "modules loading");
+sub _find_accent($)
+{
+ my $text_root = shift;
+ my $current = $text_root;
+ while ($current->{'type'} and ($current->{'type'} eq 'text_root'
+ or $current->{'type'} eq 'document_root'
+ or $current->{'type'} eq 'paragraph')) {
+ $current = $current->{'contents'}->[0];
+ }
+ return $current;
+}
sub test_accent_stack ($)
{
@@ -27,7 +38,7 @@ sub test_accent_stack ($)
my $reference = $test->[2];
my $parser = Texinfo::Parser::parser();
my $text_root = $parser->parse_texi_text($texi);
- my $tree = $text_root->{'contents'}->[0]->{'contents'}->[0];
+ my $tree = _find_accent($text_root);
my ($contents, $commands_stack) =
Texinfo::Convert::Utils::find_innermost_accent_contents($tree);
my $text = Texinfo::Convert::Text::convert_to_text({'contents' =>
$contents});
@@ -76,7 +87,7 @@ sub test_enable_encoding ($)
my $reference_unicode = $test->[5];
my $parser = Texinfo::Parser::parser();
my $text_root = $parser->parse_texi_text($texi);
- my $tree = $text_root->{'contents'}->[0]->{'contents'}->[0];
+ my $tree = _find_accent($text_root);
my ($contents, $commands_stack) =
Texinfo::Convert::Utils::find_innermost_accent_contents($tree);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/ParserNonXS.pm (parse_texi_file, _setup_text_root) (_parse_texi), tp/Texinfo/Structuring.pm (no_root_command_tree), tp/Texinfo/Transformations.pm: use a function to setup 'text_root' type in tp/Texinfo/ParserNonXS.pm. Prepare recognizing trees with text_root and @bye only as trees without root command in no_root_command_tree(). No functional change, aim is to reduce difference with future code changing the tree in ParserNonXS.pm.,
Patrice Dumas <=
- Prev by Date:
branch master updated: * tp/Texinfo/Convert/Converter.pm (determine_files_and_directory) (_set_element_file, _top_node_filename, _set_pages_files) (create_destination_directory), tp/DebugTexinfo/DebugTree.pm, tp/Texinfo/Convert/DocBook.pm, tp/Texinfo/Convert/HTML.pm (_set_html_pages_files, _prepare_elements, _prepare_special_elements) (_default_format_frame_files, _do_jslicenses_file), tp/Texinfo/Convert/IXIN.pm, tp/Texinfo/Convert/Info.pm, tp/Texinfo/Convert/LaTeX.pm, tp/Texinfo/Convert/TexinfoSXML.pm, tp/Texin [...]
- Next by Date:
branch master updated: * doc/texinfo.texi (@code{@@documentlanguage}): explain that in DocBook lang only sets the language in the following sections. Text from Gavin.
- Previous by thread:
branch master updated: * tp/Texinfo/Convert/Converter.pm (determine_files_and_directory) (_set_element_file, _top_node_filename, _set_pages_files) (create_destination_directory), tp/DebugTexinfo/DebugTree.pm, tp/Texinfo/Convert/DocBook.pm, tp/Texinfo/Convert/HTML.pm (_set_html_pages_files, _prepare_elements, _prepare_special_elements) (_default_format_frame_files, _do_jslicenses_file), tp/Texinfo/Convert/IXIN.pm, tp/Texinfo/Convert/Info.pm, tp/Texinfo/Convert/LaTeX.pm, tp/Texinfo/Convert/TexinfoSXML.pm, tp/Texin [...]
- Next by thread:
branch master updated: * doc/texinfo.texi (@code{@@documentlanguage}): explain that in DocBook lang only sets the language in the following sections. Text from Gavin.
- Index(es):