AST/Util.pm

filter: Statementstmt 31.0% 9 / 29 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 26.6% 12 / 45 CC 7 SCAR 37.8
CC
7
Cov
22%
showLineAndCol
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 43.8
« AST/Data/Scan/Impl/Perl5.pm ↑ Summary AST.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package MarpaX::Languages::IDL::AST::Util;
5  
6 # ABSTRACT: Translate an IDL source to an AST - Tools
7  
8 3 our $VERSION = '0.007'; # VERSION
9  
10 # Marpa follows Unicode recommendation, i.e. perl's \R, that cannot be in a character class
11 3 our $NEWLINE_REGEXP = qr/(?>\x0D\x0A|\v)/;
12  
13  
14  
15 0 ▶sub showLineAndCol {
Subroutine showLineAndCol: not called CC=7 SCAR=40.3
Pod documented
16 0 my ($line, $col, $source) = @_;
17  
18 0 ▶ my $pointer = ($col > 0 ? '-' x ($col-1) : '') . '^';
Branch: 1 branch
BranchTrueFalseTotal
$col > 0 ? : 0 0 0
19 0 my $content = '';
20  
21 0 my $prevpos = pos($source);
22 0 pos($source) = undef;
23 0 my $thisline = 0;
24 0 my $nbnewlines = 0;
25 0 my $eos = 0;
26 0 ▶ while ($source =~ m/\G(.*?)($NEWLINE_REGEXP|\Z)/scmg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source =~ /\G(.*?)($MarpaX::Languages::IDL::AST::Util::NEWLINE_REGEXP|\Z)/cgms) 0 0 0
27 0 ▶ if (++$thisline == $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$thisline == $line) 0 0 0
28 0 $content = substr($source, $-[1], $+[1] - $-[1]);
29 0 ▶ $eos = (($+[2] - $-[2]) > 0) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$+[2] - $-[2] > 0 ? : 0 0 0
30 0 last;
31 }
32 }
33 0 $content =~ s/\t/ /g;
34 0 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) 0 0 0
35 0 $nbnewlines = (substr($source, 0, pos($source)) =~ tr/\n//);
36 0 ▶ if ($eos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eos) 0 0 0
37 0 ++$nbnewlines; # End of string instead of $NEWLINE_REGEXP
38 }
39 }
40 0 pos($source) = $prevpos;
41  
42 # return "line:column $line:$col (Unicode newline count) $nbnewlines:$col (\\n count)\n\n$content\n$pointer";
43 0 return "line:column $nbnewlines:$col\n\n$content\n$pointer";
44 }
45  
46 3 1;
47  
48 __END__
« AST/Data/Scan/Impl/Perl5.pm ↑ Summary AST.pm »