AST/Util.pm

filter: Statementstmt 26.3% 20 / 76 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 35.7% 5 / 14 Podpod 100% 8 / 8 totaltotal 24.8% 33 / 133 CC 14 SCAR 30.0
CC
14
Cov
19%
showLineAndCol
56.0
_cutbase
20.0
traceAndUnpack
12.0
CRAP 20.2
« AST/Grammar/ECMAScript_262_5/Pattern/Semantics.pm ↑ Summary AST/Grammar/ECMAScript_262_5/StringNumericLiteral/NativeNumberSemantics.pm »
1 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 17 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package MarpaX::Languages::ECMAScript::AST::Util;
5  
6 # ABSTRACT: ECMAScript Translation to AST - Class method utilities
7  
8 17 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use Log::Any qw/$log/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 17 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 # Marpa follows Unicode recommendation, i.e. perl's \R, that cannot be in a character class
12 17 our $NEWLINE_REGEXP = qr/(?>\x0D\x0A|\v)/;
13  
14 17 our $VERSION = '0.020'; # VERSION
15 # CONTRIBUTORS
16  
17 17 our @EXPORT_OK = qw/whoami whowasi traceAndUnpack showLineAndCol lineAndCol lastCompleted startAndLength lastLexemeSpan/;
18 17 our %EXPORT_TAGS = ('all' => [ @EXPORT_OK ]);
19  
20  
21 0 ▶sub _cutbase {
Subroutine _cutbase: not called CC=4 SCAR=30.0
22 0 my ($rc, $base) = @_;
23 0 ▶ if (defined($base) && "$base" && index($rc, "${base}::") == $[) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base and "$base" and index($rc, "${base}::") == $[) 0 0 0
Condition0%0/6
defined $base and "$base" and index($rc, "${base}::") == $[
!ll&&!rl&&r
000
defined $base and "$base"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $base and "$base" and index($rc, "${base}::") == $[
defined $base "$base" index($rc, "${base}::") == $[
Truth table0%0/4
A and B and C
A= defined $baseB= "$base"C= index($rc, "${base}::") == $[
ABCresult
0XX0
10X0
1100
1111
24 0 substr($rc, $[, length($base) + 2, '');
25 }
26 0 return $rc;
27 }
28  
29 0 ▶sub whoami {
Subroutine whoami: not called CC=1 SCAR=6.9
Pod documented
30 0 return _cutbase((caller(1))[3], @_);
31 }
32  
33  
34 0 ▶sub whowasi {
Subroutine whowasi: not called CC=1 SCAR=6.9
Pod documented
35 0 return _cutbase((caller(2))[3], @_);
36 }
37  
38  
39 0 ▶sub traceAndUnpack {
Subroutine traceAndUnpack: not called CC=3 SCAR=24.8
Pod documented
40 0 my $nameOfArgumentsp = shift;
41  
42 0 my $whowasi = whowasi();
43 0 my @string = ();
44 0 my $min1 = scalar(@{$nameOfArgumentsp});
45 0 my $min2 = scalar(@_);
46 0 ▶ my $min = ($min1 < $min2) ? $min1 : $min2;
Branch: 1 branch
BranchTrueFalseTotal
$min1 < $min2 ? : 0 0 0
47 0 my $rc = {};
48 0 foreach (0..--$min) {
49 0 my ($key, $value) = ($nameOfArgumentsp->[$_], $_[$_]);
50 0 my $string = Data::Dumper->new([$value], [$key])->Indent(0)->Sortkeys(1)->Quotekeys(0)->Terse(0)->Dump();
51 0 $rc->{$key} = $value;
52 #
53 # Remove the ';'
54 #
55 0 substr($string, -1, 1, '');
56 0 push(@string, $string);
57 }
58 #
59 # Skip MarpaX::Languages::ECMAScript::AST::if any
60 #
61 0 $whowasi =~ s/^MarpaX::Languages::ECMAScript::AST:://;
62 0 $log->tracef('%s(%s)', $whowasi, join(', ', @string));
63 0 return($rc);
64 }
65  
66  
67 0 ▶sub showLineAndCol {
Subroutine showLineAndCol: not called CC=7 SCAR=40.3
Pod documented
68 0 my ($line, $col, $source) = @_;
69  
70 0 ▶ my $pointer = ($col > 0 ? '-' x ($col-1) : '') . '^';
Branch: 1 branch
BranchTrueFalseTotal
$col > 0 ? : 0 0 0
71 0 my $content = '';
72  
73 0 my $prevpos = pos($source);
74 0 pos($source) = undef;
75 0 my $thisline = 0;
76 0 my $nbnewlines = 0;
77 0 my $eos = 0;
78 0 ▶ while ($source =~ m/\G(.*?)($NEWLINE_REGEXP|\Z)/scmg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source =~ /\G(.*?)($MarpaX::Languages::ECMAScript::AST::Util::NEWLINE_REGEXP|\Z)/cgms) 0 0 0
79 0 ▶ if (++$thisline == $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$thisline == $line) 0 0 0
80 0 $content = substr($source, $-[1], $+[1] - $-[1]);
81 0 ▶ $eos = (($+[2] - $-[2]) > 0) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$+[2] - $-[2] > 0 ? : 0 0 0
82 0 last;
83 }
84 }
85 0 $content =~ s/\t/ /g;
86 0 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) 0 0 0
87 0 $nbnewlines = (substr($source, 0, pos($source)) =~ tr/\n//);
88 0 ▶ if ($eos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eos) 0 0 0
89 0 ++$nbnewlines; # End of string instead of $NEWLINE_REGEXP
90 }
91 }
92 0 pos($source) = $prevpos;
93  
94 0 return "line:column $line:$col (Unicode newline count) $nbnewlines:$col (\\n count)\n\n$content\n$pointer";
95 }
96  
97  
98 0 ▶sub lineAndCol {
Subroutine lineAndCol: not called CC=2 SCAR=17.9
Pod documented
99 0 my ($impl, $g1) = @_;
100  
101 0 ▶ $g1 //= $impl->current_g1_location();
Condition0%0/3
$g1 //= $impl->current_g1_location
l!l&&r!l&&!r
000
MC/DC0%0/2
$g1 //= $impl->current_g1_location
$g1 $impl->current_g1_location
Truth table0%0/3
A //= B
A= $g1B= $impl->current_g1_location
ABresult
1X1
011
000
102 0 my ($start, $length) = $impl->g1_location_to_span($g1);
103 0 my ($line, $column) = $impl->line_column($start);
104 0 return [ $line, $column ];
105 }
106  
107  
108 0 ▶sub startAndLength {
Subroutine startAndLength: not called CC=2 SCAR=17.9
Pod documented
109 0 my ($impl, $g1) = @_;
110  
111 0 ▶ $g1 //= $impl->current_g1_location();
Condition0%0/3
$g1 //= $impl->current_g1_location
l!l&&r!l&&!r
000
MC/DC0%0/2
$g1 //= $impl->current_g1_location
$g1 $impl->current_g1_location
Truth table0%0/3
A //= B
A= $g1B= $impl->current_g1_location
ABresult
1X1
011
000
112 0 my ($start, $length) = $impl->g1_location_to_span($g1);
113 0 return [ $start, $length ];
114 }
115  
116  
117 0 ▶sub lastCompleted {
Subroutine lastCompleted: not called CC=1 SCAR=6.9
Pod documented
118 0 my ($impl, $symbol) = @_;
119 0 return $impl->substring($impl->last_completed($symbol));
120 }
121  
122  
123 0 ▶sub lastLexemeSpan {
Subroutine lastLexemeSpan: not called CC=1 SCAR=6.9
Pod documented
124 0 my ($impl) = @_;
125 0 return $impl->g1_location_to_span($impl->current_g1_location());
126 }
127  
128 17 1;
129  
130 __END__
« AST/Grammar/ECMAScript_262_5/Pattern/Semantics.pm ↑ Summary AST/Grammar/ECMAScript_262_5/StringNumericLiteral/NativeNumberSemantics.pm »