[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[7111] move _parse_node_manual
From: |
Gavin D. Smith |
Subject: |
[7111] move _parse_node_manual |
Date: |
Sat, 09 Apr 2016 15:42:19 +0000 |
Revision: 7111
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7111
Author: gavin
Date: 2016-04-09 15:42:18 +0000 (Sat, 09 Apr 2016)
Log Message:
-----------
move _parse_node_manual
Modified Paths:
--------------
trunk/ChangeLog
trunk/tp/Texinfo/Common.pm
trunk/tp/Texinfo/Parser.pm
trunk/tp/t/test_brace_count.t
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2016-04-09 13:30:57 UTC (rev 7110)
+++ trunk/ChangeLog 2016-04-09 15:42:18 UTC (rev 7111)
@@ -1,5 +1,10 @@
2016-04-09 Gavin Smith <address@hidden>
+ * tp/Texinfo/Parser.pm (_parse_node_manual): Move implementation
+ of function to tp/Texinfo/Common.pm.
+
+2016-04-09 Gavin Smith <address@hidden>
+
Reduce references to Texinfo::Parser module.
* tp/Texinfo/Parser.pm (_parse_def): Remove commented-out code.
Modified: trunk/tp/Texinfo/Common.pm
===================================================================
--- trunk/tp/Texinfo/Common.pm 2016-04-09 13:30:57 UTC (rev 7110)
+++ trunk/tp/Texinfo/Common.pm 2016-04-09 15:42:18 UTC (rev 7111)
@@ -1358,6 +1358,125 @@
}
}
+sub _find_end_brace($$)
+{
+ my $text = shift;
+ my $braces_count = shift;
+
+ my $before = '';
+ while ($braces_count > 0 and length($text)) {
+ if ($text =~ s/([^()]*)([()])//) {
+ $before .= $1.$2;
+ my $brace = $2;
+ if ($brace eq '(') {
+ $braces_count++;
+ } else {
+ $braces_count--;
+ if ($braces_count == 0) {
+ return ($before, $text, 0);
+ }
+ }
+ } else {
+ $before .= $text;
+ $text = '';
+ }
+ }
+ return ($before, undef, $braces_count);
+}
+
+# This only counts opening braces, and returns 0 once all the parentheses
+# are closed
+sub _count_opened_tree_braces($$);
+sub _count_opened_tree_braces($$)
+{
+ my $current = shift;
+ my $braces_count = shift;
+ if (defined($current->{'text'})) {
+ my ($before, $after);
+ ($before, $after, $braces_count) = _find_end_brace($current->{'text'},
+ $braces_count);
+ }
+ if ($current->{'args'}) {
+ foreach my $arg (@{$current->{'args'}}) {
+ $braces_count = _count_opened_tree_braces($arg, $braces_count);
+ return $braces_count if ($braces_count == 0);
+ }
+ }
+ if ($current->{'contents'}) {
+ foreach my $content (@{$current->{'contents'}}) {
+ $braces_count = _count_opened_tree_braces($content, $braces_count);
+ return $braces_count if ($braces_count == 0);
+ }
+ }
+ return $braces_count;
+}
+
+# $NODE->{'contents'} is the Texinfo fo the specification of a node.
+# Returned object is a hash with three fields:
+#
+# manual_content - Texinfo tree for a manual name extracted from the
+# node specification.
+# node_content - Texinfo tree for the node name on its own
+# normalized - a string with the node name after HTML node name
+# normalization is applied
+#
+# retrieve a leading manual name in parentheses, if there is one.
+sub parse_node_manual($)
+{
+ my $node = shift;
+ my @contents = @{$node->{'contents'}};
+ trim_spaces_comment_from_content(address@hidden);
+
+ my $manual;
+ my $result;
+#print STDERR "RRR $contents[0] and $contents[0]->{'text'} \n";
+ if ($contents[0] and $contents[0]->{'text'} and $contents[0]->{'text'} =~
/^\(/) {
+ my $braces_count = 1;
+ if ($contents[0]->{'text'} !~ /^\($/) {
+ my $brace = shift @contents;
+ my $brace_text = $brace->{'text'};
+ $brace_text =~ s/^\(//;
+ unshift @contents, { 'text' => $brace_text, 'type' => $brace->{'type'},
+ 'parent' => $brace->{'parent'} } if $brace_text ne
'';
+ } else {
+ shift @contents;
+ }
+ while(@contents) {
+ my $content = shift @contents;
+ if (!defined($content->{'text'}) or $content->{'text'} !~ /\)/) {
+ push @$manual, $content;
+ $braces_count = _count_opened_tree_braces($content, $braces_count);
+ # This is an error, braces were closed in a command
+ if ($braces_count == 0) {
+ last;
+ }
+ } else {
+ my ($before, $after);
+ ($before, $after, $braces_count) = _find_end_brace($content->{'text'},
+ $braces_count);
+ if ($braces_count == 0) {
+ $before =~ s/\)$//;
+ push @$manual, { 'text' => $before, 'parent' => $content->{'parent'}
}
+ if ($before ne '');
+ $after =~ s/^\s*//;
+ unshift @contents, { 'text' => $after, 'parent' =>
$content->{'parent'} }
+ if ($after ne '');
+ last;
+ } else {
+ push @$manual, $content;
+ }
+ }
+ }
+ $result->{'manual_content'} = $manual if (defined($manual));
+ }
+ if (@contents) {
+ $result->{'node_content'} = address@hidden;
+ $result->{'normalized'} =
+ Texinfo::Convert::NodeNameNormalization::normalize_node({'contents' =>
address@hidden);
+ }
+ return $result;
+}
+
sub float_name_caption($$)
{
my $self = shift;
Modified: trunk/tp/Texinfo/Parser.pm
===================================================================
--- trunk/tp/Texinfo/Parser.pm 2016-04-09 13:30:57 UTC (rev 7110)
+++ trunk/tp/Texinfo/Parser.pm 2016-04-09 15:42:18 UTC (rev 7111)
@@ -2266,59 +2266,6 @@
}
}
-sub _find_end_brace($$)
-{
- my $text = shift;
- my $braces_count = shift;
-
- my $before = '';
- while ($braces_count > 0 and length($text)) {
- if ($text =~ s/([^()]*)([()])//) {
- $before .= $1.$2;
- my $brace = $2;
- if ($brace eq '(') {
- $braces_count++;
- } else {
- $braces_count--;
- if ($braces_count == 0) {
- return ($before, $text, 0);
- }
- }
- } else {
- $before .= $text;
- $text = '';
- }
- }
- return ($before, undef, $braces_count);
-}
-
-# This only counts opening braces, and returns 0 once all the parentheses
-# are closed
-sub _count_opened_tree_braces($$);
-sub _count_opened_tree_braces($$)
-{
- my $current = shift;
- my $braces_count = shift;
- if (defined($current->{'text'})) {
- my ($before, $after);
- ($before, $after, $braces_count) = _find_end_brace($current->{'text'},
- $braces_count);
- }
- if ($current->{'args'}) {
- foreach my $arg (@{$current->{'args'}}) {
- $braces_count = _count_opened_tree_braces($arg, $braces_count);
- return $braces_count if ($braces_count == 0);
- }
- }
- if ($current->{'contents'}) {
- foreach my $content (@{$current->{'contents'}}) {
- $braces_count = _count_opened_tree_braces($content, $braces_count);
- return $braces_count if ($braces_count == 0);
- }
- }
- return $braces_count;
-}
-
# $NODE->{'contents'} is the Texinfo fo the specification of a node.
# Returned object is a hash with three fields:
#
@@ -2332,57 +2279,7 @@
sub _parse_node_manual($)
{
my $node = shift;
- my @contents = @{$node->{'contents'}};
- _trim_spaces_comment_from_content(address@hidden);
-
- my $manual;
- my $result;
-#print STDERR "RRR $contents[0] and $contents[0]->{'text'} \n";
- if ($contents[0] and $contents[0]->{'text'} and $contents[0]->{'text'} =~
/^\(/) {
- my $braces_count = 1;
- if ($contents[0]->{'text'} !~ /^\($/) {
- my $brace = shift @contents;
- my $brace_text = $brace->{'text'};
- $brace_text =~ s/^\(//;
- unshift @contents, { 'text' => $brace_text, 'type' => $brace->{'type'},
- 'parent' => $brace->{'parent'} } if $brace_text ne
'';
- } else {
- shift @contents;
- }
- while(@contents) {
- my $content = shift @contents;
- if (!defined($content->{'text'}) or $content->{'text'} !~ /\)/) {
- push @$manual, $content;
- $braces_count = _count_opened_tree_braces($content, $braces_count);
- # This is an error, braces were closed in a command
- if ($braces_count == 0) {
- last;
- }
- } else {
- my ($before, $after);
- ($before, $after, $braces_count) = _find_end_brace($content->{'text'},
- $braces_count);
- if ($braces_count == 0) {
- $before =~ s/\)$//;
- push @$manual, { 'text' => $before, 'parent' => $content->{'parent'}
}
- if ($before ne '');
- $after =~ s/^\s*//;
- unshift @contents, { 'text' => $after, 'parent' =>
$content->{'parent'} }
- if ($after ne '');
- last;
- } else {
- push @$manual, $content;
- }
- }
- }
- $result->{'manual_content'} = $manual if (defined($manual));
- }
- if (@contents) {
- $result->{'node_content'} = address@hidden;
- $result->{'normalized'} =
- Texinfo::Convert::NodeNameNormalization::normalize_node({'contents' =>
address@hidden);
- }
- return $result;
+ return Texinfo::Common::parse_node_manual ($node);
}
sub _parse_float_type($)
Modified: trunk/tp/t/test_brace_count.t
===================================================================
--- trunk/tp/t/test_brace_count.t 2016-04-09 13:30:57 UTC (rev 7110)
+++ trunk/tp/t/test_brace_count.t 2016-04-09 15:42:18 UTC (rev 7111)
@@ -15,27 +15,28 @@
use lib 'maintain/lib/libintl-perl/lib/';
use lib 'maintain/lib/Text-Unidecode/lib/';
use Texinfo::Parser qw(parse_texi_text);
+use Texinfo::Common;
ok(1, "modules loading");
my ($before, $after, $braces_count)
- = Texinfo::Parser::_find_end_brace(" aa (bbb ()ccc)(g))j (gg", 1);
+ = Texinfo::Common::_find_end_brace(" aa (bbb ()ccc)(g))j (gg", 1);
is ($before, " aa (bbb ()ccc)(g))", "before with brace closed");
is ($after, "j (gg", "after with brace closed");
ok ($braces_count == 0, "braces count 0 with brace closed");
my $string_no_close = " kjsdf ( k)lj(";
($before, $after, $braces_count)
- = Texinfo::Parser::_find_end_brace($string_no_close, 2);
+ = Texinfo::Common::_find_end_brace($string_no_close, 2);
ok (($braces_count == 3 and $before eq $string_no_close and !defined($after)),
"more braces opened");
my $string_no_brace = " other ";
($before, $after, $braces_count)
- = Texinfo::Parser::_find_end_brace($string_no_brace, 1);
+ = Texinfo::Common::_find_end_brace($string_no_brace, 1);
ok (($braces_count == 1 and $before eq $string_no_brace and !defined($after)),
"no brace in text");
my $string_open_brace_and_text = " (other ";
($before, $after, $braces_count)
- = Texinfo::Parser::_find_end_brace($string_open_brace_and_text, 1);
+ = Texinfo::Common::_find_end_brace($string_open_brace_and_text, 1);
ok (($braces_count == 2 and $before eq $string_open_brace_and_text
and !defined($after)), "more braces opened and text");
@@ -50,7 +51,7 @@
my $tree = parse_texi_text(undef, $in);
my $braces_count
- = Texinfo::Parser::_count_opened_tree_braces($tree, $initial_brace_count);
+ = Texinfo::Common::_count_opened_tree_braces($tree, $initial_brace_count);
if (!defined($ref_braces_count)) {
print STDERR " --> $name ($in): $braces_count\n";
} else {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [7111] move _parse_node_manual,
Gavin D. Smith <=