« 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
Condition0%0/6
defined $base and "$base" and index($rc, "${base}::") == $[
defined $base and "$base"
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}::") == $[
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (++$thisline == $line) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $content = substr($source, $-[1], $+[1] - $-[1]); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $eos = (($+[2] - $-[2]) > 0) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $content =~ s/\t/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($content) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $nbnewlines = (substr($source, 0, pos($source)) =~ tr/\n//); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($eos) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||