XSH2/Completion.pm

filter: Statementstmt 14.1% 33 / 233 Branchbran 0.0% 0 / 160 Conditioncond 0.0% 0 / 48 MC/DCmcdc 0.0% 0 / 29 Subroutinesub 28.5% 4 / 14 Podpod 0.0% 0 / 10 totaltotal 7.4% 37 / 494 CC 100 SCAR 68.8
CC
100
Cov
7%
xpath_complete_str
2162.0
cpl
272.0
xpath_complete
272.0
CRAP 974.5
« XSH2/Parser.pm ↑ Summary XSH2/Functions.pm »
1 # $Id: Completion.pm,v 2.7 2007-05-06 19:32:12 pajas Exp $
2  
3 package XML::XSH2::Completion;
4  
5 8 ▶use XML::XSH2::CompletionList;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use XML::XSH2::Functions qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 $VERSION='2.2.10'; # VERSION TEMPLATE
11  
12 8 our @PATH_HASH;
13 8 our $O=qr/:[[:alnum:]]|--[-_[:alnum:]]+/; # option
14 8 our $F=qr/(?:\s$O)*/o; # options
15 8 our $M=qr/(?:^|[;}]|\s+\&?{|:\s*[-+*\/x.\%]?=)\s*/o; # possible command-start
16 8 our $match_sv=qr/\$([a-zA-Z0-9_]*)$/o; # scalar variable completion
17 8 our $match_command=qr/${M}[^\!=\s]*$/o; # command completion
18 8 our $match_option=qr/\s(\:[[:alnum:]]?|--[-_[:alnum:]]*)$/o; # option completion
19 8 our $match_func=qr/$M(?:call|undef|undefine)\s+(\S*)$/o; # function name completion
20 8 our $match_nodetype=qr/${M}x?(?:insert|add)\s+(\S*)$/o; # node-type completion
21 8 our $match_help=qr/$M(?:\?|help)\s+(\S*)$/o; # help topic completion
22 8 our $match_filename=qr/$M(?:\.|include|open|save)$F\s+(\S*)$|^\s*!\s*\S+\s+/o;
23 8 our $match_dir=qr/$M(?:lcd)\s+(\S*)$/o;
24 8 our $match_path_filename=qr/$M(?:system\s|exec\s)\s*\S*$|^\s*\!\s*\S*$|\s\|\s*\S*$/o;
25  
26 8 our $NAMECHAR = '[-_.[:alnum:]]';
27 8 our $NNAMECHAR = '[-:_.[:alnum:]]';
28 8 our $NAME = "$NAMECHAR*$NNAMECHAR*[_.[:alpha:]]";
29  
30 8 our $WILDCARD = '\*(?!\*|$NAME|\)|\]|\.)';
31 8 our $OPER = qr/(?:[,=<>\+\|]|-(?!$NAME)|(?:vid|dom|dna|ro)(?=\s*\]|\s*\)|\s*[0-9]+(?!$NNAMECHAR)|\s+{$NAMECHAR}|\s+\*))/;
32  
33  
34 # PATH-completion: system, !, exec, |,
35  
36 8 our @nodetypes = qw(element attribute attributes text cdata pi comment chunk entity_reference);
37  
38 0 ▶sub complete_option {
Subroutine complete_option: not called CC=11 SCAR=48.8
Pod undocumented
39 0 my ($l)=@_;
40 0 ▶ if ($l=~/\s--encoding\s+$|\s:e\s+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\s--encoding\s+$|\s:e\s+$/) 0 0 0
41 }
42 0 ▶ if ($l=~/$M(\.|[a-zA-Z_][-a-zA-Z0-9_]*)$F\s+(:([[:alnum:]]?)|--([-_[:alnum:]]*))$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /$XML::XSH2::Completion::M(\.|[a-zA-Z_][-a-zA-Z0-9_]*)$XML::XSH2::Completion::F\s+(:([[:alnum:]]?)|--([-_[:alnum:]]*))$/) 0 0 0
43 0 ▶ my ($cmd,$o,$p)=($1,$2,$3||$4);
Condition0%0/3
$3 || $4
l!l&&r!l&&!r
000
MC/DC0%0/2
$3 || $4
$3 $4
Truth table0%0/3
A || B
A= $3B= $4
ABresult
1X1
011
000
44 0 my $c = $XML::XSH2::Functions::COMMANDS{$cmd};
45 0 ▶ $c = $XML::XSH2::Functions::COMMANDS{$c} if (defined($c) and !ref($c));
Branch: 1 branch
BranchTrueFalseTotal
if defined $c and not ref $c 0 0 0
Condition0%0/3
defined $c and not ref $c
!ll&&!rl&&r
000
MC/DC0%0/2
defined $c and not ref $c
defined $c not ref $c
Truth table0%0/3
A and not(B)
A= defined $cB= not ref $c
ABresult
0X0
100
111
46 0 ▶ if (defined($c) and defined($c->[3])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and defined $c->[3]) 0 0 0
Condition0%0/3
defined $c and defined $c->[3]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $c and defined $c->[3]
defined $c defined $c->[3]
Truth table0%0/3
A and B
A= defined $cB= defined $c->[3]
ABresult
0X0
100
111
47 0 ▶ if ($o =~ /^:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o =~ /^:/) { } 0 0 0
48 0 ▶ return map { ":".$_ } grep { length == 1 and /^\Q$p\E/ } keys %{$c->[3]};
Condition0%0/3
length $_ == 1 && /^\Q$p\E/
!ll&&!rl&&r
000
MC/DC0%0/2
length $_ == 1 && /^\Q$p\E/
length $_ == 1 /^\Q$p\E/
Truth table0%0/3
A && B
A= length $_ == 1B= /^\Q$p\E/
ABresult
0X0
100
111
49 } else {
50 0 ▶ return map { "--".$_ } grep { length > 1 and /^\Q$p\E/ } keys %{$c->[3]};
Condition0%0/3
length $_ > 1 && /^\Q$p\E/
!ll&&!rl&&r
000
MC/DC0%0/2
length $_ > 1 && /^\Q$p\E/
length $_ > 1 /^\Q$p\E/
Truth table0%0/3
A && B
A= length $_ > 1B= /^\Q$p\E/
ABresult
0X0
100
111
51 }
52 }
53 }
54 0 return ();
55 }
56  
57 0 ▶sub perl_complete {
Subroutine perl_complete: not called CC=1 SCAR=6.9
Pod undocumented
58 0 my($word,$line,$pos) = @_;
59 0 my $endpos=$pos+length($word);
60 0 cpl('perl',$word,$line,$pos,$endpos);
61 }
62  
63 0 ▶sub gnu_complete {
Subroutine gnu_complete: not called CC=5 SCAR=34.0
Pod undocumented
64 0 my($text, $line, $start, $endpos) = @_;
65 0 &main::_term()->Attribs->{completion_append_character} = ' ';
66 0 my @result=cpl('gnu',$text,$line,$start,$endpos);
67 # find longest common match. Can anybody show me how to persuade
68 # T::R::Gnu to do this automatically? Seems expensive.
69 0 ▶ return () unless @result;
Branch: 1 branch
BranchTrueFalseTotal
unless @result 0 0 0
70 0 my($newtext) = $text;
71 0 for (my $i = length($text)+1;;$i++) {
72 0 ▶ last unless length($result[0]) && length($result[0]) >= $i;
Branch: 1 branch
BranchTrueFalseTotal
unless length $result[0] and length $result[0] >= $i 0 0 0
Condition0%0/3
length $result[0] and length $result[0] >= $i
!ll&&!rl&&r
000
MC/DC0%0/2
length $result[0] and length $result[0] >= $i
length $result[0] length $result[0] >= $i
Truth table0%0/3
A and B
A= length $result[0]B= length $result[0] >= $i
ABresult
0X0
100
111
73 0 my $try = substr($result[0],0,$i);
74 0 my @tries = grep {substr($_,0,$i) eq $try} @result;
75 # warn "try[$try]tries[@tries]";
76 0 ▶ if (@tries == @result) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tries == @result) { } 0 0 0
77 0 $newtext = $try;
78 } else {
79 0 last;
80 }
81 }
82 0 ($newtext,@result);
83 }
84  
85 0 ▶sub complete_set_term_char {
Subroutine complete_set_term_char: not called CC=2 SCAR=17.9
Pod undocumented
86 0 my ($type,$char)=@_;
87 0 ▶ if ($type eq 'perl') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'perl') { } 0 0 0
88 0 $readline::rl_completer_terminator_character = $char;
89 } else {
90 0 &main::_term()->Attribs->{completion_append_character} = $char;
91 }
92 }
93  
94 0 ▶sub complete_filename {
Subroutine complete_filename: not called CC=2 SCAR=17.9
Pod undocumented
95 0 my ($type,$word)=@_;
96 0 ▶ if ($type eq 'perl') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'perl') { } 0 0 0
97 0 return eval { map { s:\@$::; $_ } readline::rl_filename_list($word); };
98 } else {
99 0 return eval { map { s:\@$::; $_ } Term::ReadLine::Gnu::XS::rl_filename_list($word) };
100 }
101 }
102  
103 0 ▶sub rehash_path_hash {
Subroutine rehash_path_hash: not called CC=6 SCAR=37.4
Pod undocumented
104 0 my %result;
105 my $dh;
106 0 ▶ my $pdelim= $^O eq 'MSWin32' ? '\\' : '/';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
107 0 ▶ my $delim=($^O eq 'MSWin32' ? ';' : ':');
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
108 0 my @path=grep /\S/,split($delim,$ENV{PATH});
109 0 foreach my $dir (@path) {
110 0 local *DIR;
111 0 ▶ if (opendir DIR, $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir DIR, $dir) 0 0 0
112 0 ▶ my @files=grep { -f "$dir$pdelim$_" and -x "$dir$pdelim$_" } readdir(DIR);
Condition0%0/3
-f "$dir$pdelim$_" && -x "$dir$pdelim$_"
!ll&&!rl&&r
000
MC/DC0%0/2
-f "$dir$pdelim$_" && -x "$dir$pdelim$_"
-f "$dir$pdelim$_" -x "$dir$pdelim$_"
Truth table0%0/3
A && B
A= -f "$dir$pdelim$_"B= -x "$dir$pdelim$_"
ABresult
0X0
100
111
113 0 @result{@files}=();
114 0 closedir DIR;
115 }
116 }
117 0 @PATH_HASH=sort keys %result;
118 }
119  
120 0 ▶sub complete_system_command {
Subroutine complete_system_command: not called CC=4 SCAR=30.0
Pod undocumented
121 0 my ($type,$word)=@_;
122 0 ▶ my $pdelim= $^O eq 'MSWin32' ? '\\' : '/';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
123 0 ▶ if (index($word,$pdelim)>=0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($word, $pdelim) != -1) 0 0 0
124 0 return grep -x,complete_filename($type,$word);
125 }
126 0 ▶ unless (@PATH_HASH) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@XML::XSH2::Completion::PATH_HASH) 0 0 0
127 0 rehash_path_hash();
128 }
129 0 return grep {index($_,$word)==0} @PATH_HASH;
130 }
131  
132 0 ▶sub cpl {
Subroutine cpl: not called CC=16 SCAR=56.1
Pod undocumented
133 0 my($type,$word,$line,$pos,$endpos) = @_;
134 0 my $part = substr($line,0,$endpos);
135 0 ▶ if ($part=~$match_sv) {
Branch: 9 branches
BranchTrueFalseTotal
if ($part =~ /$XML::XSH2::Completion::match_sv/) { } 0 0 0
elsif ($part =~ /$XML::XSH2::Completion::match_option/) { } 0 0 0
elsif ($part =~ /$XML::XSH2::Completion::match_func/) { } 0 0 0
elsif ($part =~ /$XML::XSH2::Completion::match_nodetype/) { } 0 0 0
elsif ($part =~ /$XML::XSH2::Completion::match_help/) { } 0 0 0
elsif ($part =~ /$XML::XSH2::Completion::match_command/) { } 0 0 0
elsif ($part =~ /$XML::XSH2::Completion::match_filename/) { } 0 0 0
elsif ($part =~ /$XML::XSH2::Completion::match_dir/) { } 0 0 0
elsif ($part =~ /$XML::XSH2::Completion::match_path_filename/) { } 0 0 0
136 0 return map {'$'.$_} grep { index($_,$1)==0 } XML::XSH2::Functions::string_vars;
137 } elsif ($part=~$match_option) {
138 0 return complete_option($part);
139 } elsif ($part=~$match_func) {
140 0 return grep { index($_,$1)==0 } XML::XSH2::Functions::defs;
141 } elsif ($part=~$match_nodetype) {
142 0 return grep { index($_,$1)==0 } @nodetypes;
143 } elsif ($part=~$match_help) {
144 0 return grep { index($_,$1)==0 } keys %XML::XSH2::Help::HELP;
145 } elsif ($part=~$match_command) {
146 0 return grep { index($_,$word)==0 } @XML::XSH2::CompletionList::XSH_COMMANDS,
147 XML::XSH2::Functions::defs();
148 } elsif ($part=~$match_filename) {
149 0 my @result=complete_filename($type,$word);
150 0 ▶ if (@result==1 and -d $result[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result == 1 and -d $result[0]) { } 0 0 0
Condition0%0/3
@result == 1 and -d $result[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@result == 1 and -d $result[0]
@result == 1 -d $result[0]
Truth table0%0/3
A and B
A= @result == 1B= -d $result[0]
ABresult
0X0
100
111
151 0 complete_set_term_char($type,'');
152 } else {
153 0 complete_set_term_char($type,' ');
154 }
155 0 return @result;
156 } elsif ($part=~$match_dir) {
157 0 my @result=grep -d, complete_filename($type,$word);
158 0 ▶ if (@result==1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result == 1) { } 0 0 0
159 0 complete_set_term_char($type,' ');
160 } else {
161 0 complete_set_term_char($type,'');
162 }
163 0 return @result;
164 } elsif ($part=~$match_path_filename) {
165 0 ▶ my $subst = ($word =~ s/^(\!)//) ? '!' : '';
Branch: 1 branch
BranchTrueFalseTotal
$word =~ s/^(\!)// ? : 0 0 0
166 0 my @result=map { $subst.$_ } complete_system_command($type,$word);
167 0 ▶ if (@result==1 and -d $result[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result == 1 and -d $result[0]) { } 0 0 0
Condition0%0/3
@result == 1 and -d $result[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@result == 1 and -d $result[0]
@result == 1 -d $result[0]
Truth table0%0/3
A and B
A= @result == 1B= -d $result[0]
ABresult
0X0
100
111
168 0 complete_set_term_char($type,'');
169 } else {
170 0 complete_set_term_char($type,' ');
171 }
172 0 return @result;
173 } else {
174 0 complete_set_term_char($type,'');
175 0 return xpath_complete($line,$word,$pos);
176 }
177 }
178  
179 0 ▶sub xpath_complete_str {
Subroutine xpath_complete_str: not called CC=46 SCAR=76.8
Pod undocumented
180 0 my $str = reverse($_[0]);
181 0 my $debug = $_[1];
182 0 my $result="";
183  
184 0 ▶ print "'$str'\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
185 0 my $localmatch;
186  
187 STEP0:
188 0 ▶ if ($str =~ /\G\s*[\]\)]/gsco) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G\s*[\]\)]/cogs) 0 0 0
189 0 ▶ print "No completions after ] or )\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
190 0 return;
191 }
192  
193 STEP1:
194 0 ▶ if ( $str =~ /\G($NAMECHAR+)?(?::($NAMECHAR+))?/gsco ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G($XML::XSH2::Completion::NAMECHAR+)?(?::($XML::XSH2::Completion::NAMECHAR+))?/cogs) { } 0 0 0
195 0 my $name = reverse($1);
196 0 my $prefix = reverse($2);
197 0 ▶ if ($prefix ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix ne '') { } 0 0 0
198 0 $localmatch=$prefix.":".$name;
199 # my $uri = get_registered_ns($prefix);
200 # my $base='';
201 # if ($uri ne "") {
202 # $base=$prefix.':*[namespace-uri()="'.$uri.'"]';
203 # } else {
204 # $base=$prefix.':*';
205 # }
206 0 ▶ if ($name ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($name ne '') { } 0 0 0
207 0 $result=$prefix.':*[starts-with(local-name(),"'.$name.'")]'.$result;
208 } else {
209 0 $result=$prefix.':*'.$result;
210 }
211 } else {
212 0 $localmatch=$name;
213 0 $result='*[namespace-uri()="" and starts-with(name(),"'.$localmatch.'")]'.$result;
214 }
215 } else {
216 0 $result='*'.$result;
217 }
218 0 ▶ if ($str =~ /\G\@/gsco) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G\@/cogs) 0 0 0
219 0 $result="@".$result;
220 }
221  
222 STEP2:
223 0 ▶ print "STEP2-LOCALMATCH: $localmatch\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
224 0 ▶ print "STEP2: $result\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
225 0 ▶ print "STEP2-STR: ".reverse(substr($str,pos($str)))."\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
226 0 ▶ while ($str =~ m/\G(::|:|\@|$NAME\$?|\/\/|\/|$WILDCARD|\)|\])/gsco) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ m<\G(::|:|\@|$XML::XSH2::Completion::NAME\$?|//|/|$XML::XSH2::Completion::WILDCARD|\)|\])>cogs) 0 0 0
227 0 ▶ print "STEP2-MATCH: '$1'\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
228 0 ▶ if ($1 eq ')' or $1 eq ']') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq ')' or $1 eq ']') { } 0 0 0
Condition0%0/3
$1 eq ")" or $1 eq "]"
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 eq ")" or $1 eq "]"
$1 eq ")" $1 eq "]"
Truth table0%0/3
A or B
A= $1 eq ")"B= $1 eq "]"
ABresult
1X1
011
000
229 # eat ballanced upto $1
230 0 ▶ my @ballance=(($1 eq ')' ? '(' : '['));
Branch: 1 branch
BranchTrueFalseTotal
$1 eq ')' ? : 0 0 0
231 0 $result=$1.$result;
232 0 ▶ print "STEP2: Ballanced $1\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
233 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
@ballance and do { do { $result = reverse($1) . $result if $str =~ /\G([^]["'()]+)/cogs; return $result, $localmatch unless $str =~ /\G(.)/cogs; if ($1 eq $ballance[$#ballance]) { pop @ballance; } elsif ($1 eq ")") { push @ballance, "("; } elsif ($1 eq "]") { push @ballance, "["; } elsif ($1 eq "\"") { push @ballance, "\""; } elsif ($1 eq "'") { push @ballance, "'"; } else { print STDERR "Error 2: lost in an expression on '$1' "; print STDERR reverse(substr($str, pos $_)) . "\n"; print "-> $result\n"; return undef; } ; $result = $1 . $result } } 0 0 0
234 0 ▶ $result=reverse($1).$result if $str =~ m/\G([^]["'()]+)/gsco; # skip normal characters
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /\G([^]["'()]+)/cogs 0 0 0
235 0 ▶ return ($result,$localmatch) unless $str =~ m/\G(.)/gsco;
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /\G(.)/cogs 0 0 0
236 0 ▶ if ($1 eq $ballance[$#ballance]) {
Branch: 5 branches
BranchTrueFalseTotal
if ($1 eq $ballance[$#ballance]) { } 0 0 0
elsif ($1 eq ')') { } 0 0 0
elsif ($1 eq ']') { } 0 0 0
elsif ($1 eq '"') { } 0 0 0
elsif ($1 eq q[']) { } 0 0 0
237 0 pop @ballance;
238 } elsif ($1 eq ')') {
239 0 push @ballance, '(';
240 } elsif ($1 eq ']') {
241 0 push @ballance, '[';
242 } elsif ($1 eq '"') {
243 0 push @ballance, '"';
244 } elsif ($1 eq "'") {
245 0 push @ballance, "'";
246 } else {
247 0 print STDERR "Error 2: lost in an expression on '$1' ";
248 0 print STDERR reverse(substr($str,pos()))."\n";
249 0 print "-> $result\n";
250 0 return undef;
251 }
252 0 $result=$1.$result;
253 } while (@ballance);
254 } else {
255 0 $result=reverse($1).$result;
256 }
257 }
258  
259 STEP3:
260 0 ▶ print "STEP3: $result\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
261 0 ▶ print "STEP3-STR: ".reverse(substr($str,pos($str)))."\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
262 0 ▶ if (substr($result,0,1) eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($result, 0, 1) eq '/') { } 0 0 0
263 0 ▶ if ($str =~ /\G['"]/gsco) {
Branch: 2 branches
BranchTrueFalseTotal
if ($str =~ /\G['"]/cogs) { } 0 0 0
elsif ($str =~ /\G(?:\s+['"]|\(|\[|$XML::XSH2::Completion::OPER)/cogs) { } 0 0 0
264 0 return undef;
265 } elsif ($str =~ /\G(?:\s+['"]|\(|\[|$OPER)/gsco) {
266 0 return ($result,$localmatch);
267 }
268 0 return ($result,$localmatch); # uncertain!!!
269 } else {
270 0 ▶ return ($result,$localmatch) if ($str=~/\G\s+(?=$OPER)/gsco);
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /\G\s+(?=$XML::XSH2::Completion::OPER)/cogs 0 0 0
271 }
272  
273 0 ▶ STEP4:
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
274 print "STEP4: $result\n" if $debug;
275 0 ▶ print "STEP4-STR: ".reverse(substr($str,pos($str)))."\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
276 0 my @ballance;
277 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
@ballance and do { do { $str =~ /\G([^]["'()]+)/cogs; print q[STEP4-MATCH '] . reverse($1) . "'\n" if $debug; return $result, $localmatch unless $str =~ /\G(.)/cogs; print "STEP4-BALLANCED '$1'\n" if $debug; if (@ballance and $1 eq $ballance[$#ballance]) { pop @ballance; } elsif ($1 eq ")") { push @ballance, "("; } elsif ($1 eq "]") { push @ballance, "["; } elsif ($1 eq "\"") { push @ballance, "\""; } elsif ($1 eq "'") { push @ballance, "'"; } elsif (not @ballance and $1 eq "[") { print "STEP4-PRED2STEP '$1'\n" if $debug; $result = '/' . $result; goto STEP2; } } } 0 0 0
278 0 $str =~ m/\G([^]["'()]+)/gsco; # skip normal characters
279 0 ▶ print "STEP4-MATCH '".reverse($1)."'\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
280 0 ▶ return ($result,$localmatch) unless $str =~ m/\G(.)/gsco;
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /\G(.)/cogs 0 0 0
281 0 ▶ print "STEP4-BALLANCED '$1'\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
282 0 ▶ if (@ballance and $1 eq $ballance[$#ballance]) {
Branch: 6 branches
BranchTrueFalseTotal
if (@ballance and $1 eq $ballance[$#ballance]) { } 0 0 0
elsif ($1 eq ')') { } 0 0 0
elsif ($1 eq ']') { } 0 0 0
elsif ($1 eq '"') { } 0 0 0
elsif ($1 eq q[']) { } 0 0 0
elsif (not @ballance and $1 eq '[') { } 0 0 0
Condition0%0/3
@ballance and $1 eq $ballance[$#ballance]
!ll&&!rl&&r
000
MC/DC0%0/2
@ballance and $1 eq $ballance[$#ballance]
@ballance $1 eq $ballance[$#ballance]
Truth table0%0/3
A and B
A= @ballanceB= $1 eq $ballance[$#ballance]
ABresult
0X0
100
111
283 0 pop @ballance;
284 } elsif ($1 eq ')') {
285 0 push @ballance, '(';
286 } elsif ($1 eq ']') {
287 0 push @ballance, '[';
288 } elsif ($1 eq '"') {
289 0 push @ballance, '"';
290 } elsif ($1 eq "'") {
291 0 push @ballance, "'";
292 ▶ } elsif (not(@ballance) and $1 eq '[') {
Condition0%0/3
not @ballance and $1 eq "["
!ll&&!rl&&r
000
MC/DC0%0/2
not @ballance and $1 eq "["
not @ballance $1 eq "["
Truth table0%0/3
not(A) and B
A= not @ballanceB= $1 eq "["
ABresult
0X0
100
111
293 0 ▶ print "STEP4-PRED2STEP '$1'\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
294 0 $result='/'.$result;
295 0 goto STEP2;
296 }
297 } while (@ballance);
298 0 goto STEP4;
299 }
300  
301 0 ▶sub xpath_complete {
Subroutine xpath_complete: not called CC=16 SCAR=56.1
Pod undocumented
302 0 my ($line, $word,$pos)=@_;
303 0 ▶ return () unless $XML::XSH2::Functions::XPATH_COMPLETION;
Branch: 1 branch
BranchTrueFalseTotal
unless $XML::XSH2::Functions::XPATH_COMPLETION 0 0 0
304 0 my $str=XML::XSH2::Functions::toUTF8($XML::XSH2::Functions::QUERY_ENCODING,
305 substr($line,0,$pos).$word);
306 0 my ($xp,$local) = xpath_complete_str($str,0);
307 # XML::XSH2::Functions::__debug("COMPLETING $_[0] local $local as $xp\n");
308 0 ▶ return () if $xp eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $xp eq "" 0 0 0
309 0 local $XML::XSH2::Functions::ERRORS;
310 0 local $XML::XSH2::Functions::WARNINGS;
311 0 my $ql= XML::XSH2::Functions::_ev_nodelist($xp);
312 0 ▶ return () if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
313  
314 0 my %names;
315 0 ▶ my $prefix = ($local=~/^($NAMECHAR+:)/) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$local =~ /^($XML::XSH2::Completion::NAMECHAR+:)/ ? : 0 0 0
316 @names{ map {
317 0 XML::XSH2::Functions::fromUTF8($XML::XSH2::Functions::QUERY_ENCODING,
318 substr(substr($str,0,
319 length($str)
320 -length($local)).
321 $prefix.$_->nodeName(),$pos))
322 } grep defined, @$ql}=();
323  
324 0 my @completions = sort { $a cmp $b } keys %names;
325 # print "completions so far: @completions\n";
326  
327 0 ▶ if (($XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq 'always' or
Branch: 1 branch
BranchTrueFalseTotal
if ($XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "always" || $XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "when-empty" && !@completions and $str =~ m<[ \n\t\r|([=<>+-/]([[:alpha:]][-:[:alnum:]]*)?$> and not $1 =~ /::/) 0 0 0
Condition0%0/12
$XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "always" || $XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "when-empty" && !@completions and $str =~ m<[ \n\t\r|([=<>+-/]([[:alpha:]][-:[:alnum:]]*)?$> and not $1 =~ /::/
!ll&&!rl&&r
000
$XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "always" || $XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "when-empty" && !@completions and $str =~ m<[ \n\t\r|([=<>+-/]([[:alpha:]][-:[:alnum:]]*)?$>
!ll&&!rl&&r
000
$XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "always" or $XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "when-empty" and not @completions
l!l&&r!l&&!r
000
$XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "when-empty" and not @completions
!ll&&!rl&&r
000
MC/DC0%0/5
$XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "always" || $XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "when-empty" && !@completions and $str =~ m<[ \n\t\r|([=<>+-/]([[:alpha:]][-:[:alnum:]]*)?$> and not $1 =~ /::/
$XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "always" $XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "when-empty" not @completions $str =~ m<[ \n\t\r|([=<>+-/]([[:alpha:]][-:[:alnum:]]*)?$> not $1 =~ /::/
Truth table0%0/8
A or B and not(C) and D and not(E)
A= $XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "always"B= $XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq "when-empty"C= not @completionsD= $str =~ m<[ \n\t\r|([=<>+-/]([[:alpha:]][-:[:alnum:]]*)?$>E= not $1 =~ /::/
ABCDEresult
00XXX0
010XX0
1XX0X0
0110X0
1XX100
011100
1XX111
011111
328 $XML::XSH2::Functions::XPATH_AXIS_COMPLETION eq 'when-empty' and !@completions)
329 and $str =~ /[ \n\t\r|([=<>+-\/]([[:alpha:]][-:[:alnum:]]*)?$/ and $1 !~ /::/) {
330 # complete XML axis
331 0 my ($pre,$axpart)=($word =~ /^(.*[^-:[:alnum:]])?([[:alpha:]][-[:alnum:]:]*)/);
332 # print "\nWORD: $word\nPRE: $pre\nPART: $axpart\nSTR:$str\n";
333 0 foreach my $axis (qw(following-sibling following preceding
334 preceding-sibling
335 parent ancestor ancestor-or-self descendant self
336 descendant-or-self child attribute namespace)) {
337 0 ▶ if ($axis =~ /^\Q$axpart\E/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($axis =~ /^\Q$axpart\E/) 0 0 0
338 0 push @completions, "${pre}${axis}::";
339 }
340 }
341  
342 0 ▶ unless ($pre=~m{/$}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pre =~ m[/$]) 0 0 0
343 0 foreach my $func (qw(boolean ceiling comment concat contains count
344 document false
345 floor id lang last local-name name
346 namespace-uri node normalize-space not number
347 position processing-instruction round
348 starts-with string string-length substring
349 substring-after substring-before sum
350 text translate true),
351 0 (map { 'xsh:'.$_ } XML::XSH2::Functions::get_XPATH_extensions()),
352 0 ▶ map { /^(.*)\n(.*)$/s ?
Branch: 1 branch
BranchTrueFalseTotal
/^(.*)\n(.*)$/s ? : 0 0 0
353 XML::XSH2::Functions::get_registered_prefix($2).":$1" : $_
354 } keys %XML::XSH2::Functions::_func,
355 ) {
356 0 ▶ if ($func =~ /^\Q$axpart\E/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($func =~ /^\Q$axpart\E/) 0 0 0
357 0 push @completions, "${pre}${func}(";
358 }
359 }
360 }
361 }
362 0 return @completions;
363 }
364  
365 8 1;
366  
367  
« XSH2/Parser.pm ↑ Summary XSH2/Functions.pm »