AST/Grammar/ECMAScript_262_5/Pattern/Semantics.pm

filter: Statementstmt 7.5% 37 / 491 Branchbran 0.7% 1 / 126 Conditioncond 0.0% 0 / 58 MC/DCmcdc 0.0% 0 / 33 Subroutinesub 8.9% 9 / 101 Podpod 100% 2 / 2 totaltotal 6.0% 49 / 811 CC 86 SCAR 31.3
CC
86
Cov
6%
_isWordChar
110.0
_repeatMatcher
72.0
_CharacterClassEscape
56.0
CRAP 23.0
« AST/Grammar/ECMAScript_262_5/Template.pm ↑ Summary AST/Util.pm »
1 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern::Semantics;
5 6 ▶use MarpaX::Languages::ECMAScript::AST::Exceptions qw/:all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use List::Compare::Functional 0.21 qw/get_union_ref/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Unicode::Normalize qw/NFD NFC/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 #
12 # Credit goes to utf8::all
13 #
14 6 ▶if ($^V >= v5.11.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^V >= v5.11.0) 6 0 6
15 6 'feature'->import::into(__PACKAGE__, qw/unicode_strings/);
16 }
17  
18 6 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ASSERTION_IS_NOT_MATCHER => 0,
20 ASSERTION_IS_MATCHER => 1
21 6 };
22 6 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ORD_a => ord('a'),
24 ORD_z => ord('z'),
25 ORD_A => ord('A'),
26 ORD_Z => ord('Z'),
27 ORD_0 => ord('0'),
28 ORD_9 => ord('9'),
29 ORD__ => ord('_'),
30 6 };
31  
32 # ABSTRACT: ECMAScript 262, Edition 5, pattern grammar default semantics package
33  
34 6 our $VERSION = '0.020'; # VERSION
35  
36  
37 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
38 0 my ($class) = @_;
39 0 my $self = {_lparen => $MarpaX::Languages::ECMAScript::AST::Grammar::Pattern::lparen};
40 0 bless $self, $class;
41 }
42  
43  
44 0 ▶sub lparen {
Subroutine lparen: not called CC=1 SCAR=6.9
Pod documented
45 0 my ($self) = @_;
46  
47 0 return $self->{_lparen};
48 }
49  
50 #
51 # IMPORTANT NOTE: These actions DELIBIRATELY do not use any perl regular expression. This is the prove that one can
52 # write a fresh regular expression engine from scratch. The only important notion is case-folding. There we rely
53 # on perl.
54 #
55 6 our @LINETERMINATOR = @{MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses::LineTerminator()};
56 6 our %HASHLINETERMINATOR = map {$_ => 1} @LINETERMINATOR;
57 6 our @WHITESPACE = @{MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses::WhiteSpace()};
58  
59 0 ▶sub _Pattern_Disjunction {
Subroutine _Pattern_Disjunction: not called CC=1 SCAR=6.9
60 0 my ($self, $disjunction) = @_;
61  
62 0 my $m = $disjunction;
63  
64 0 ▶ return sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
65 #
66 # Note: $str is a true perl string, $index is a true perl scalar
67 #
68 0 my ($str, $index, $multiline, $ignoreCase, $upperCase) = @_;
69 0 ▶ $multiline //= 0;
Condition0%0/2
$multiline //= 0
l!l
00
MC/DC0%0/1
$multiline //= 0
$multiline
Truth table0%0/2
A
A= $multiline
Aresult
11
00
70 0 ▶ $ignoreCase //= 0;
Condition0%0/2
$ignoreCase //= 0
l!l
00
MC/DC0%0/1
$ignoreCase //= 0
$ignoreCase
Truth table0%0/2
A
A= $ignoreCase
Aresult
11
00
71 0 ▶ $upperCase //= sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
72 0 ▶ if ($^V >= v5.11.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^V >= v5.11.0) { } 0 0 0
73 #
74 # C.f. http://www.effectiveperlprogramming.com/2012/02/fold-cases-properly/
75 # Please note that we really want only the upper case version as per
76 # ECMAScript specification
77 #
78 0 return uc($_[0]);
79 } else {
80 #
81 # C.f. uc from Unicode::Tussle
82 #
83 0 return NFC(uc(NFD($_[0])));
84 }
85 0 ▶ };
Condition0%0/3
$upperCase //= sub { if ($^V >= v5.11.0) { return uc $_[0]; } else { return &NFC(uc &NFD($_[0])); } ; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$upperCase //= sub { if ($^V >= v5.11.0) { return uc $_[0]; } else { return &NFC(uc &NFD($_[0])); } ; }
$upperCase sub { if ($^V >= v5.11.0) { return uc $_[0]; } else { return &NFC(uc &NFD($_[0])); } ; }
Truth table0%0/3
A //= B
A= $upperCaseB= sub { if ($^V >= v5.11.0) { return uc $_[0]; } else { return &NFC(uc &NFD($_[0])); } ; }
ABresult
1X1
011
000
86 #
87 # We localize input, input length, mutiline and ignoreCase
88 #
89 0 local $MarpaX::Languages::ECMAScript::AST::Pattern::input = $str;
90 0 local $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength = length($str);
91 0 local $MarpaX::Languages::ECMAScript::AST::Pattern::multiline = $multiline;
92 0 local $MarpaX::Languages::ECMAScript::AST::Pattern::ignoreCase = $ignoreCase;
93 0 local $MarpaX::Languages::ECMAScript::AST::Pattern::upperCase = $upperCase;
94  
95 0 ▶ my $c = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 0 my ($state) = @_;
97 0 return $state;
98 0 };
99 0 my $cap = [ (undef) x scalar(@{$self->lparen}) ];
100 0 my $x = [ $index, $cap ];
101  
102 0 return &$m($x, $c);
103 0 };
104 }
105  
106 0 ▶sub _Disjunction_Alternative {
Subroutine _Disjunction_Alternative: not called CC=1 SCAR=6.9
107 0 my ($self, $alternative) = @_;
108 0 return $alternative;
109 }
110  
111 0 ▶sub _Disjunction_Alternative_OR_Disjunction {
Subroutine _Disjunction_Alternative_OR_Disjunction: not called CC=1 SCAR=6.9
112 0 my ($self, $alternative, undef, $disjunction) = @_;
113  
114 0 my $m1 = $alternative;
115 0 my $m2 = $disjunction;
116  
117 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
118 0 my ($x, $c) = @_;
119 0 my $r = &$m1($x, $c);
120 0 ▶ if ($r) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) 0 0 0
121 0 return $r;
122 }
123 0 return &$m2($x, $c);
124 0 };
125 }
126  
127 0 ▶sub _Alternative {
Subroutine _Alternative: not called CC=1 SCAR=6.9
128 0 my ($self) = @_;
129  
130 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
131 0 my ($x, $c) = @_;
132 0 return &$c($x);
133 0 };
134 }
135  
136 0 ▶sub _Alternative_Alternative_Term {
Subroutine _Alternative_Alternative_Term: not called CC=1 SCAR=6.9
137 0 my ($self, $alternative, $term) = @_;
138  
139 0 my $m1 = $alternative;
140 0 my $m2 = $term;
141  
142 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
143 0 my ($x, $c) = @_;
144 0 ▶ my $d = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
145 0 my ($y) = @_;
146 0 return &$m2($y, $c);
147 0 };
148 0 return &$m1($x, $d);
149 0 };
150 }
151  
152 0 ▶sub _Term_Assertion {
Subroutine _Term_Assertion: not called CC=1 SCAR=6.9
153 0 my ($self, $assertion) = @_;
154  
155 0 my ($isMatcher, $assertionCode) = @{$assertion};
156  
157 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
158 0 my ($x, $c) = @_;
159  
160 0 ▶ if (! $isMatcher) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $isMatcher) { } 0 0 0
161 0 my $t = $assertionCode;
162 0 my $r = &$t($x, $c); # Take care! Typo in ECMAScript spec, $c is missing
163 0 ▶ if (! $r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
164 0 return 0;
165 }
166 0 return &$c($x);
167 } else {
168 0 my $m = $assertionCode;
169 0 return &$m($x, $c);
170 }
171 0 };
172 }
173  
174 0 ▶sub _Term_Atom {
Subroutine _Term_Atom: not called CC=1 SCAR=6.9
175 0 my ($self, $atom) = @_;
176  
177 0 return $atom;
178 }
179  
180 0 ▶sub _repeatMatcher {
Subroutine _repeatMatcher: not called CC=8 SCAR=42.8
181 0 my ($m, $min, $max, $greedy, $x, $c, $parenIndex, $parenCount) = @_;
182  
183 0 ▶ if (defined($max) && $max == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $max == 0) 0 0 0
Condition0%0/3
defined $max and $max == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $max and $max == 0
defined $max $max == 0
Truth table0%0/3
A and B
A= defined $maxB= $max == 0
ABresult
0X0
100
111
184 0 return &$c($x);
185 }
186 0 ▶ my $d = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
187 0 my ($y) = @_;
188 0 ▶ if ($min == 0 && $y->[0] == $x->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min == 0 and $y->[0] == $x->[0]) 0 0 0
Condition0%0/3
$min == 0 and $y->[0] == $x->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$min == 0 and $y->[0] == $x->[0]
$min == 0 $y->[0] == $x->[0]
Truth table0%0/3
A and B
A= $min == 0B= $y->[0] == $x->[0]
ABresult
0X0
100
111
189 0 return 0;
190 }
191 0 ▶ my $min2 = ($min == 0) ? 0 : ($min - 1);
Branch: 1 branch
BranchTrueFalseTotal
$min == 0 ? : 0 0 0
192 0 ▶ my $max2 = (! defined($max)) ? undef : ($max - 1);
Branch: 1 branch
BranchTrueFalseTotal
!defined($max) ? : 0 0 0
193 0 return _repeatMatcher($m, $min2, $max2, $greedy, $y, $c, $parenIndex, $parenCount);
194 0 };
195 0 my @cap = @{$x->[1]};
196 0 foreach my $k (($parenIndex+1)..($parenIndex+$parenCount)) {
197 0 $cap[$k-1] = undef; # Take care, cap index in ECMA spec start at 1
198 }
199 0 my $e = $x->[0];
200 0 my $xr = [$e, \@cap ];
201 0 ▶ if ($min != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min != 0) 0 0 0
202 0 return &$m($xr, $d);
203 }
204 0 ▶ if (! $greedy) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($greedy) 0 0 0
205 0 my $z = &$c($x);
206 0 ▶ if ($z) {
Branch: 1 branch
BranchTrueFalseTotal
if ($z) 0 0 0
207 0 return $z;
208 }
209 0 return &$m($xr, $d);
210 }
211 0 my $z = &$m($xr, $d);
212 0 ▶ if ($z) {
Branch: 1 branch
BranchTrueFalseTotal
if ($z) 0 0 0
213 0 return $z;
214 }
215 0 return &$c($x);
216 }
217  
218 0 ▶sub _parenIndexAndCount {
Subroutine _parenIndexAndCount: not called CC=4 SCAR=30.0
219 0 my ($self) = @_;
220  
221 0 my ($start, $end) = Marpa::R2::Context::location();
222 0 my $parenIndex = 0;
223 0 my $parenCount = 0;
224 0 foreach (@{$self->lparen}) {
225 0 ▶ if ($_ < $start) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_ < $start) { } 0 0 0
elsif ($_ <= $end) { } 0 0 0
226 0 ++$parenIndex;
227 }
228 elsif ($_ <= $end) {
229 0 ++$parenCount;
230 }
231 }
232 0 return {parenIndex => $parenIndex, parenCount => $parenCount};
233 }
234  
235 #
236 # Note: we will use undef for $max when its value is infinite
237 #
238 0 ▶sub _Term_Atom_Quantifier {
Subroutine _Term_Atom_Quantifier: not called CC=3 SCAR=24.8
239 0 my ($self, $atom, $quantifier) = @_;
240  
241 0 my $m = $atom;
242 0 my ($min, $max, $greedy) = @{$quantifier};
243 0 ▶ if (defined($max) && $max < $min) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $max < $min) 0 0 0
Condition0%0/3
defined $max and $max < $min
!ll&&!rl&&r
000
MC/DC0%0/2
defined $max and $max < $min
defined $max $max < $min
Truth table0%0/3
A and B
A= defined $maxB= $max < $min
ABresult
0X0
100
111
244 0 SyntaxError("Bad quantifier {$min,$max} in regular expression");
245 }
246 0 my $hashp = $self->_parenIndexAndCount();
247  
248 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
249 0 my ($x, $c) = @_;
250  
251 0 return _repeatMatcher($m, $min, $max, $greedy, $x, $c, $hashp->{parenIndex}, $hashp->{parenCount});
252 0 };
253 }
254  
255 0 ▶sub _Assertion_Caret {
Subroutine _Assertion_Caret: not called CC=1 SCAR=6.9
256 0 my ($self, $caret) = @_;
257  
258 return [ASSERTION_IS_NOT_MATCHER,
259 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
260 0 my ($x) = @_;
261  
262  
263 0 my $e = $x->[0];
264 0 ▶ if ($e == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e == 0) 0 0 0
265 0 return 1;
266 }
267 0 ▶ if (! $MarpaX::Languages::ECMAScript::AST::Pattern::multiline) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($MarpaX::Languages::ECMAScript::AST::Pattern::multiline) 0 0 0
268 0 return 0;
269 }
270 0 my $c = substr($MarpaX::Languages::ECMAScript::AST::Pattern::input, $e-1, 1);
271 0 ▶ if (exists($HASHLINETERMINATOR{$c})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern::Semantics::HASHLINETERMINATOR{$c}) 0 0 0
272 0 return 1;
273 }
274  
275 0 return 0;
276 0 }],
277 }
278  
279 0 ▶sub _Assertion_Dollar {
Subroutine _Assertion_Dollar: not called CC=1 SCAR=6.9
280 0 my ($self, $caret) = @_;
281  
282 return [ASSERTION_IS_NOT_MATCHER,
283 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
284 0 my ($x) = @_;
285  
286 0 my $e = $x->[0];
287 0 ▶ if ($e == $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e == $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength) 0 0 0
288 0 return 1;
289 }
290 0 ▶ if (! $MarpaX::Languages::ECMAScript::AST::Pattern::multiline) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($MarpaX::Languages::ECMAScript::AST::Pattern::multiline) 0 0 0
291 0 return 0;
292 }
293 0 my $c = substr($MarpaX::Languages::ECMAScript::AST::Pattern::input, $e, 1);
294 0 ▶ if (exists($HASHLINETERMINATOR{$c})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern::Semantics::HASHLINETERMINATOR{$c}) 0 0 0
295 0 return 1;
296 }
297  
298 0 return 0;
299 0 }];
300 }
301  
302 0 ▶sub _isWordChar {
Subroutine _isWordChar: not called CC=10 SCAR=47.0
303 0 my ($e) = @_;
304  
305 0 ▶ if ($e == -1 || $e == $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e == -1 or $e == $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength) 0 0 0
Condition0%0/3
$e == -1 or $e == $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength
l!l&&r!l&&!r
000
MC/DC0%0/2
$e == -1 or $e == $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength
$e == -1 $e == $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength
Truth table0%0/3
A or B
A= $e == -1B= $e == $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength
ABresult
1X1
011
000
306 0 return 0;
307 }
308 #
309 # This really refers to ASCII characters, so it is ok to test the ord directly
310 #
311 0 my $c = ord(substr($MarpaX::Languages::ECMAScript::AST::Pattern::input, $e, 1));
312 #
313 # I put the most probables (corresponding also to the biggest ranges) first
314 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($c >= 97 and $c <= 122 or $c >= 65 and $c <= 90 or $c >= 48 and $c <= 57 or $c == 95) 0 0 0
Condition0%0/18
$c >= 97 and $c <= 122 or $c >= 65 and $c <= 90 or $c >= 48 and $c <= 57 or $c == 95
l!l&&r!l&&!r
000
$c >= 97 and $c <= 122 or $c >= 65 and $c <= 90 or $c >= 48 and $c <= 57
l!l&&r!l&&!r
000
$c >= 97 and $c <= 122 or $c >= 65 and $c <= 90
l!l&&r!l&&!r
000
$c >= 97 and $c <= 122
!ll&&!rl&&r
000
$c >= 65 and $c <= 90
!ll&&!rl&&r
000
$c >= 48 and $c <= 57
!ll&&!rl&&r
000
MC/DC0%0/7
$c >= 97 and $c <= 122 or $c >= 65 and $c <= 90 or $c >= 48 and $c <= 57 or $c == 95
$c >= 97 $c <= 122 $c >= 65 $c <= 90 $c >= 48 $c <= 57 $c == 95
Truth table0%0/23
A and B or C and D or E and F or G
A= $c >= 97B= $c <= 122C= $c >= 65D= $c <= 90E= $c >= 48F= $c <= 57G= $c == 95
ABCDEFGresult
11XXXXX1
0X11XXX1
1011XXX1
0X0X11X1
0X1011X1
100X11X1
101011X1
0X0X0X11
0X0X1011
0X100X11
0X101011
100X0X11
100X1011
10100X11
10101011
0X0X0X00
0X0X1000
0X100X00
0X101000
100X0X00
100X1000
10100X00
10101000
315 ($c >= ORD_a && $c <= ORD_z)
316 ||
317 ($c >= ORD_A && $c <= ORD_Z)
318 ||
319 ($c >= ORD_0 && $c <= ORD_9)
320 ||
321 ($c == ORD__)
322 ) {
323 0 return 1;
324 }
325  
326 0 return 0;
327 }
328  
329 0 ▶sub _Assertion_b {
Subroutine _Assertion_b: not called CC=1 SCAR=6.9
330 0 my ($self, $caret) = @_;
331  
332 return [ASSERTION_IS_NOT_MATCHER,
333 0 ▶ sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
334 0 my ($x) = @_;
335  
336 0 my $e = $x->[0];
337 0 my $a = _isWordChar($e-1);
338 0 my $b = _isWordChar($e);
339 0 ▶ if ($a && ! $b) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a and not $b) 0 0 0
Condition0%0/3
$a and not $b
!ll&&!rl&&r
000
MC/DC0%0/2
$a and not $b
$a not $b
Truth table0%0/3
A and not(B)
A= $aB= not $b
ABresult
0X0
100
111
340 0 return 1;
341 }
342 0 ▶ if (! $a && $b) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $a and $b) 0 0 0
Condition0%0/3
not $a and $b
!ll&&!rl&&r
000
MC/DC0%0/2
not $a and $b
not $a $b
Truth table0%0/3
not(A) and B
A= not $aB= $b
ABresult
0X0
100
111
343 0 return 1;
344 }
345 0 return 0;
346 0 }];
347 }
348  
349 0 ▶sub _Assertion_B {
Subroutine _Assertion_B: not called CC=1 SCAR=6.9
350 0 my ($self, $caret) = @_;
351  
352 return [ASSERTION_IS_NOT_MATCHER,
353 0 ▶ sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
354 0 my ($x) = @_;
355  
356 0 my $e = $x->[0];
357 0 my $a = _isWordChar($e-1);
358 0 my $b = _isWordChar($e);
359 0 ▶ if ($a && ! $b) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a and not $b) 0 0 0
Condition0%0/3
$a and not $b
!ll&&!rl&&r
000
MC/DC0%0/2
$a and not $b
$a not $b
Truth table0%0/3
A and not(B)
A= $aB= not $b
ABresult
0X0
100
111
360 0 return 0;
361 }
362 0 ▶ if (! $a && $b) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $a and $b) 0 0 0
Condition0%0/3
not $a and $b
!ll&&!rl&&r
000
MC/DC0%0/2
not $a and $b
not $a $b
Truth table0%0/3
not(A) and B
A= not $aB= $b
ABresult
0X0
100
111
363 0 return 0;
364 }
365 0 return 1;
366 0 }];
367 }
368  
369 0 ▶sub _Assertion_DisjunctionPositiveLookAhead {
Subroutine _Assertion_DisjunctionPositiveLookAhead: not called CC=1 SCAR=6.9
370 0 my ($self, undef, $disjunction, undef) = @_;
371  
372 0 my $m = $disjunction;
373  
374 return [ASSERTION_IS_MATCHER,
375 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
376 0 my ($x, $c) = @_;
377  
378 0 ▶ my $d = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
379 0 my ($y) = @_;
380 0 return $y;
381 0 };
382  
383 0 my $r = &$m($x, $d);
384 0 ▶ if (! $r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
385 0 return 0;
386 }
387 0 my $y = $r;
388 0 my $cap = $y->[1];
389 0 my $xe = $x->[0];
390 0 my $z = [$xe, $cap];
391 0 return &$c($z);
392 0 }];
393 }
394  
395 0 ▶sub _Assertion_DisjunctionNegativeLookAhead {
Subroutine _Assertion_DisjunctionNegativeLookAhead: not called CC=1 SCAR=6.9
396 0 my ($self, undef, $disjunction, undef) = @_;
397  
398 0 my $m = $disjunction;
399  
400 return [ASSERTION_IS_MATCHER,
401 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
402 0 my ($x, $c) = @_;
403  
404 0 ▶ my $d = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
405 0 my ($y) = @_;
406 0 return $y;
407 0 };
408  
409 0 my $r = &$m($x, $d);
410 0 ▶ if ($r) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) 0 0 0
411 0 return 0;
412 }
413 0 return &$c($x);
414 0 }];
415 }
416  
417 0 ▶sub _Quantifier_QuantifierPrefix {
Subroutine _Quantifier_QuantifierPrefix: not called CC=1 SCAR=6.9
418 0 my ($self, $quantifierPrefix) = @_;
419  
420 0 my ($min, $max) = @{$quantifierPrefix};
421 0 return [$min, $max, 1];
422 }
423  
424 0 ▶sub _Quantifier_QuantifierPrefix_QuestionMark {
Subroutine _Quantifier_QuantifierPrefix_QuestionMark: not called CC=1 SCAR=6.9
425 0 my ($self, $quantifierPrefix, $questionMark) = @_;
426  
427 0 my ($min, $max) = @{$quantifierPrefix};
428 0 return [$min, $max, 0];
429 }
430  
431 0 ▶sub _QuantifierPrefix_Star {
Subroutine _QuantifierPrefix_Star: not called CC=1 SCAR=6.9
432 0 my ($self, $start) = @_;
433  
434 0 return [0, undef];
435 }
436  
437 0 ▶sub _QuantifierPrefix_Plus {
Subroutine _QuantifierPrefix_Plus: not called CC=1 SCAR=6.9
438 0 my ($self, $plus) = @_;
439  
440 0 return [1, undef];
441 }
442  
443 0 ▶sub _QuantifierPrefix_QuestionMark {
Subroutine _QuantifierPrefix_QuestionMark: not called CC=1 SCAR=6.9
444 0 my ($self, $questionMark) = @_;
445  
446 0 return [0, 1];
447 }
448  
449 0 ▶sub _QuantifierPrefix_DecimalDigits {
Subroutine _QuantifierPrefix_DecimalDigits: not called CC=1 SCAR=6.9
450 0 my ($self, undef, $decimalDigits, undef) = @_;
451  
452 0 return [$decimalDigits, $decimalDigits];
453 }
454  
455 0 ▶sub _QuantifierPrefix_DecimalDigits_Comma {
Subroutine _QuantifierPrefix_DecimalDigits_Comma: not called CC=1 SCAR=6.9
456 0 my ($self, undef, $decimalDigits, undef) = @_;
457  
458 0 return [$decimalDigits, undef];
459 }
460  
461 0 ▶sub _QuantifierPrefix_DecimalDigits_DecimalDigits {
Subroutine _QuantifierPrefix_DecimalDigits_DecimalDigits: not called CC=1 SCAR=6.9
462 0 my ($self, undef, $decimalDigits1, undef, $decimalDigits2, undef) = @_;
463  
464 0 return [$decimalDigits1, $decimalDigits2];
465 }
466  
467 0 ▶sub _canonicalize {
Subroutine _canonicalize: not called CC=5 SCAR=34.0
468 0 my ($ch) = @_;
469  
470 0 ▶ if (! $MarpaX::Languages::ECMAScript::AST::Pattern::ignoreCase) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($MarpaX::Languages::ECMAScript::AST::Pattern::ignoreCase) 0 0 0
471 0 return $ch;
472 }
473  
474 0 my $u = &$MarpaX::Languages::ECMAScript::AST::Pattern::upperCase($ch);
475 0 ▶ if (length($u) != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $u != 1) 0 0 0
476 #
477 # I don't know why it has been designed like that -;
478 #
479 0 return $ch;
480 }
481 0 my $cu = $u;
482 0 ▶ if (ord($ch) >= 128 && ord($cu) < 128) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord $ch >= 128 and ord $cu < 128) 0 0 0
Condition0%0/3
ord $ch >= 128 and ord $cu < 128
!ll&&!rl&&r
000
MC/DC0%0/2
ord $ch >= 128 and ord $cu < 128
ord $ch >= 128 ord $cu < 128
Truth table0%0/3
A and B
A= ord $ch >= 128B= ord $cu < 128
ABresult
0X0
100
111
483 0 return $ch;
484 }
485 0 return $cu;
486 }
487  
488 #
489 # Note: we extend a little the notion of range to:
490 # * range including characters from ... to ...
491 # and
492 # * range NOT including characters from ... to ...
493 #
494 # i.e. a character set is [ negation flag, [range] ]
495 #
496 # This is different from the invert flag. For example:
497 # [^\d] means: $A=[0,[0..9]], $invert=1
498 # [^\D] means: $A=[1,[0..9]], $invert=1, which is equivalent to [\d], i.e.: $A=[0,[0..9], $invert=0
499  
500 0 ▶sub _characterSetMatcher {
Subroutine _characterSetMatcher: not called CC=2 SCAR=17.9
501 0 my ($self, $A, $invert) = @_;
502  
503 0 my ($x, $c) = @_;
504  
505 0 my ($Anegation, $Arange) = @{$A};
506  
507 0 ▶ if ($Anegation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Anegation) 0 0 0
508 0 $invert = ! $invert;
509 }
510  
511 0 ▶ return sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
512 0 my ($x, $c) = @_;
513  
514 0 my $e = $x->[0];
515 0 ▶ if ($e == $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e == $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength) 0 0 0
516 0 return 0;
517 }
518 0 my $ch = substr($MarpaX::Languages::ECMAScript::AST::Pattern::input, $e, 1);
519 0 my $cc = _canonicalize($ch);
520 0 ▶ if (! $invert) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $invert) { } 0 0 0
521 0 ▶ if (! grep {$cc eq _canonicalize($_)} @{$Arange}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$cc eq _canonicalize($_);} @{$Arange;}) 0 0 0
522 0 return 0;
523 }
524 } else {
525 0 ▶ if (grep {$cc eq _canonicalize($_)} @{$Arange}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$cc eq _canonicalize($_);} @{$Arange;}) 0 0 0
526 0 return 0;
527 }
528 }
529 0 my $cap = $x->[1];
530 0 my $y = [$e+1, $cap];
531 0 return &$c($y);
532 0 };
533 }
534  
535 0 ▶sub _Atom_PatternCharacter {
Subroutine _Atom_PatternCharacter: not called CC=1 SCAR=6.9
536 0 my ($self, $patternCharacter) = @_;
537  
538 #
539 # Note: PatternCharacter is a lexeme, default lexeme value is [start,length,value]
540 #
541 0 my $ch = $patternCharacter->[2];
542 0 my $A = [0 , [ $ch ]];
543 0 return $self->_characterSetMatcher($A, 0);
544 }
545  
546 0 ▶sub _Atom_Dot {
Subroutine _Atom_Dot: not called CC=1 SCAR=6.9
547 0 my ($self, $dot) = @_;
548  
549 0 my $A = [1 , \@LINETERMINATOR];
550 0 return $self->_characterSetMatcher($A, 0);
551  
552  
553 }
554  
555 0 ▶sub _Atom_Backslash_AtomEscape {
Subroutine _Atom_Backslash_AtomEscape: not called CC=1 SCAR=6.9
556 0 my ($self, $backslash, $atomEscape) = @_;
557  
558 0 return $atomEscape;
559 }
560  
561 0 ▶sub _Atom_Backslash_CharacterClass {
Subroutine _Atom_Backslash_CharacterClass: not called CC=1 SCAR=6.9
562 0 my ($self, $characterClass) = @_;
563  
564 0 my ($A, $invert) = @{$characterClass};
565 0 return $self->_characterSetMatcher($A, $invert);
566 }
567  
568 0 ▶sub _Atom_Lparen_Disjunction_Rparen {
Subroutine _Atom_Lparen_Disjunction_Rparen: not called CC=1 SCAR=6.9
569 0 my ($self, $lparen, $disjunction, $rparen) = @_;
570  
571 0 my $m = $disjunction;
572 0 my $parenIndex = $self->_parenIndexAndCount()->{parenIndex};
573 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
574 0 my ($x, $c) = @_;
575  
576 0 ▶ my $d = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
577 0 my ($y) = @_;
578  
579 0 my @cap = @{$y->[1]};
580 0 my $xe = $x->[0];
581 0 my $ye = $y->[0];
582 0 my $s = substr($MarpaX::Languages::ECMAScript::AST::Pattern::input, $xe, $ye-$xe);
583 0 $cap[$parenIndex] = $s; # Take care, in ECMA spec, cap index start at 1
584 0 my $z = [$ye, \@cap ];
585 0 return &$c($z);
586 0 };
587  
588 0 return &$m($x, $d);
589 0 };
590 }
591  
592 0 ▶sub _Atom_nonCapturingDisjunction {
Subroutine _Atom_nonCapturingDisjunction: not called CC=1 SCAR=6.9
593 0 my ($self, undef, $disjunction, undef) = @_;
594  
595 0 return $disjunction;
596 }
597  
598 0 ▶sub _AtomEscape_DecimalEscape {
Subroutine _AtomEscape_DecimalEscape: not called CC=5 SCAR=34.0
599 0 my ($self, $decimalEscape) = @_;
600  
601 0 my $E = $decimalEscape;
602  
603 #
604 # We are in an atom escape context: the only allowed character is NUL
605 #
606 0 ▶ my $ch = ($decimalEscape == 0) ? MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses::NULL()->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$decimalEscape == 0 ? : 0 0 0
607  
608 0 ▶ if (defined($ch)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch) 0 0 0
609 0 my $A = [0 , [ $ch ]];
610 0 return $self->_characterSetMatcher($A, 0);
611 }
612 0 my $n = $E;
613 0 ▶ if ($n == 0 || $n > scalar(@{$self->lparen})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 0 or $n > scalar @{$self->lparen;}) 0 0 0
Condition0%0/3
$n == 0 or $n > scalar @{$self->lparen;}
l!l&&r!l&&!r
000
MC/DC0%0/2
$n == 0 or $n > scalar @{$self->lparen;}
$n == 0 $n > scalar @{$self->lparen;}
Truth table0%0/3
A or B
A= $n == 0B= $n > scalar @{$self->lparen;}
ABresult
1X1
011
000
614 0 SyntaxError("backtrack number must be <= " . scalar(@{$self->lparen}));
615 }
616 0 ▶ return sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
617 0 my ($x, $c) = @_;
618  
619 0 my $cap = $x->[1];
620 0 my $s = $cap->[$n-1]; # Take care, in ECMA spec cap index start at 1
621 0 ▶ if (! defined($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s) 0 0 0
622 0 return &$c($x);
623 }
624 0 my $e = $x->[0];
625 0 my $len = length($s);
626 0 my $f = $e+$len;
627 0 ▶ if ($f > $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f > $MarpaX::Languages::ECMAScript::AST::Pattern::inputLength) 0 0 0
628 0 return 0;
629 }
630 0 foreach (0..($len-1)) {
631 0 ▶ if (_canonicalize(substr($s, $_, 1)) ne _canonicalize(substr($MarpaX::Languages::ECMAScript::AST::Pattern::input, $e+$_, 1))) {
Branch: 1 branch
BranchTrueFalseTotal
if (_canonicalize(substr($s, $_, 1)) ne _canonicalize(substr($MarpaX::Languages::ECMAScript::AST::Pattern::input, $e + $_, 1))) 0 0 0
632 0 return 0;
633 }
634 }
635 0 my $y = [$f, $cap];
636 0 return &$c($y);
637 0 };
638 }
639  
640 0 ▶sub _AtomEscape_CharacterEscape {
Subroutine _AtomEscape_CharacterEscape: not called CC=1 SCAR=6.9
641 0 my ($self, $characterEscape) = @_;
642  
643 0 my $ch = $characterEscape;
644 0 my $A = [0 , [ $ch ]];
645 0 return $self->_characterSetMatcher($A, 0);
646 }
647  
648 0 ▶sub _AtomEscape_CharacterClassEscape {
Subroutine _AtomEscape_CharacterClassEscape: not called CC=1 SCAR=6.9
649 0 my ($self, $characterClassEscape) = @_;
650  
651 0 return $self->_characterSetMatcher($characterClassEscape, 0);
652 }
653  
654 0 ▶sub _CharacterEscape_ControlEscape {
Subroutine _CharacterEscape_ControlEscape: not called CC=6 SCAR=37.4
655 0 my ($self, $controlEscape) = @_;
656  
657 #
658 # Note: ControlEscape is a lexeme, default lexeme value is [start,length,value]
659 #
660 0 ▶ if ($controlEscape->[2] eq 't') {
Branch: 5 branches
BranchTrueFalseTotal
if ($controlEscape->[2] eq 't') { } 0 0 0
elsif ($controlEscape->[2] eq 'n') { } 0 0 0
elsif ($controlEscape->[2] eq 'v') { } 0 0 0
elsif ($controlEscape->[2] eq 'f') { } 0 0 0
elsif ($controlEscape->[2] eq 'r') { } 0 0 0
661 0 return MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses::TAB()->[0];
662 }
663 elsif ($controlEscape->[2] eq 'n') {
664 0 return MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses::LF()->[0];
665 }
666 elsif ($controlEscape->[2] eq 'v') {
667 0 return MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses::VT()->[0];
668 }
669 elsif ($controlEscape->[2] eq 'f') {
670 0 return MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses::FF()->[0];
671 }
672 elsif ($controlEscape->[2] eq 'r') {
673 0 return MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses::CR()->[0];
674 }
675 }
676  
677 0 ▶sub _CharacterEscape_ControlLetter {
Subroutine _CharacterEscape_ControlLetter: not called CC=1 SCAR=6.9
678 0 my ($self, undef, $controlLetter) = @_;
679  
680 #
681 # Note: ControlEscape is a lexeme, default lexeme value is [start,length,value]
682 #
683 0 my $ch = $controlLetter->[2];
684 0 my $i = ord($ch);
685 0 my $j = $i % 32;
686 0 return chr($j);
687 }
688  
689 #
690 # Note: _HexDigit is a lexeme, default lexeme value is [start,length,value]
691 #
692 0 ▶sub _HexEscapeSequence { return chr(16 * hex($_[2]->[2]) + hex($_[3]->[2])); }
Subroutine _HexEscapeSequence: not called CC=1 SCAR=6.9
693 0 ▶sub _UnicodeEscapeSequence { return chr(4096 * hex($_[2]->[2]) + 256 * hex($_[3]->[2]) + 16 * hex($_[4]->[2]) + hex($_[5]->[2])); }
Subroutine _UnicodeEscapeSequence: not called CC=1 SCAR=6.9
694  
695 0 ▶sub _CharacterEscape_HexEscapeSequence {
Subroutine _CharacterEscape_HexEscapeSequence: not called CC=1 SCAR=6.9
696 0 my ($self, $hexEscapeSequence) = @_;
697  
698 0 return $hexEscapeSequence;
699 }
700  
701 0 ▶sub _CharacterEscape_UnicodeEscapeSequence {
Subroutine _CharacterEscape_UnicodeEscapeSequence: not called CC=1 SCAR=6.9
702 0 my ($self, $unicodeEscapeSequence) = @_;
703  
704 0 return $unicodeEscapeSequence;
705 }
706  
707 0 ▶sub _CharacterEscape_IdentityEscape {
Subroutine _CharacterEscape_IdentityEscape: not called CC=1 SCAR=6.9
708 0 my ($self, $identityEscape) = @_;
709 #
710 # Note: IdentityEscape is a lexeme, default lexeme value is [start,length,value]
711 #
712 0 return $identityEscape->[2];
713 }
714  
715 0 ▶sub _DecimalEscape_DecimalIntegerLiteral {
Subroutine _DecimalEscape_DecimalIntegerLiteral: not called CC=1 SCAR=6.9
716 0 my ($self, $decimalIntegerLiteral) = @_;
717  
718 #
719 # Note: DecimalIntegerLiteral is already an integer
720 #
721 0 my $i = $decimalIntegerLiteral;
722  
723 0 return $i;
724 }
725  
726 0 ▶sub _DecimalIntegerLiteral {
Subroutine _DecimalIntegerLiteral: not called CC=1 SCAR=6.9
727 0 my ($self, $decimalIntegerLiteral) = @_;
728  
729 #
730 # Note: decimalIntegerLiteral is a lexeme, default lexeme value is [start,length,value]
731 #
732 0 return int($decimalIntegerLiteral->[2]);
733 }
734  
735 0 ▶sub _DecimalDigits {
Subroutine _DecimalDigits: not called CC=1 SCAR=6.9
736 0 my ($self, $decimalDigits) = @_;
737  
738 #
739 # Note: decimalDigits is a lexeme, default lexeme value is [start,length,value]
740 #
741 0 return int($decimalDigits->[2]);
742 }
743  
744 0 ▶sub _CharacterClassEscape {
Subroutine _CharacterClassEscape: not called CC=7 SCAR=40.3
745 0 my ($self, $cCharacterClassEscape) = @_;
746  
747 0 ▶ if ($cCharacterClassEscape eq 'd') {
Branch: 6 branches
BranchTrueFalseTotal
if ($cCharacterClassEscape eq 'd') { } 0 0 0
elsif ($cCharacterClassEscape eq 'D') { } 0 0 0
elsif ($cCharacterClassEscape eq 's') { } 0 0 0
elsif ($cCharacterClassEscape eq 'S') { } 0 0 0
elsif ($cCharacterClassEscape eq 'w') { } 0 0 0
elsif ($cCharacterClassEscape eq 'W') { } 0 0 0
748 0 return [0 , [ '0'..'9' ]];
749 }
750 elsif ($cCharacterClassEscape eq 'D') {
751 0 return [1 , [ '0'..'9' ]];
752 }
753 elsif ($cCharacterClassEscape eq 's') {
754 0 return [0 , [ @WHITESPACE, @LINETERMINATOR ]];
755 }
756 elsif ($cCharacterClassEscape eq 'S') {
757 0 return [1 , [ @WHITESPACE, @LINETERMINATOR ]];
758 }
759 elsif ($cCharacterClassEscape eq 'w') {
760 0 return [0 , [ 'a'..'z', 'A'..'Z', '0'..'9', '_' ]];
761 }
762 elsif ($cCharacterClassEscape eq 'W') {
763 0 return [1 , [ 'a'..'z', 'A'..'Z', '0'..'9', '_' ]];
764 }
765  
766 }
767  
768 0 ▶sub _CharacterClass_ClassRanges {
Subroutine _CharacterClass_ClassRanges: not called CC=1 SCAR=6.9
769 0 my ($self, undef, $classRanges, undef) = @_;
770  
771 0 return [$classRanges, 0];
772 }
773  
774 0 ▶sub _CharacterClass_CaretClassRanges {
Subroutine _CharacterClass_CaretClassRanges: not called CC=1 SCAR=6.9
775 0 my ($self, undef, $classRanges, undef) = @_;
776  
777 0 return [$classRanges, 1];
778 }
779  
780 0 ▶sub _ClassRanges {
Subroutine _ClassRanges: not called CC=1 SCAR=6.9
781 0 my ($self) = @_;
782  
783 0 return [0, []];
784 }
785  
786 0 ▶sub _ClassRanges_NonemptyClassRanges {
Subroutine _ClassRanges_NonemptyClassRanges: not called CC=1 SCAR=6.9
787 0 my ($self, $nonemptyClassRanges) = @_;
788  
789 0 return $nonemptyClassRanges;
790 }
791  
792 0 ▶sub _NonemptyClassRanges_ClassAtom {
Subroutine _NonemptyClassRanges_ClassAtom: not called CC=1 SCAR=6.9
793 0 my ($self, $classAtom) = @_;
794  
795 0 return $classAtom;
796 }
797  
798 0 ▶sub _rangeComplement {
Subroutine _rangeComplement: not called CC=2 SCAR=17.9
799 0 my ($self, $A) = @_;
800  
801 0 my ($Anegation, $Arange) = @{$A};
802  
803 0 my %hash = map {$_ => 1} @{$Arange};
804  
805 0 ▶ return [ $Anegation ? 0 : 1, [ grep {! exists($hash{$_})} (1.65535) ] ];
Branch: 1 branch
BranchTrueFalseTotal
$Anegation ? : 0 0 0
806
807 }
808  
809 0 ▶sub _charsetUnion {
Subroutine _charsetUnion: not called CC=3 SCAR=24.8
810 0 my ($self, $A, $B) = @_;
811  
812 0 my ($Anegation, $Arange) = @{$A};
813 0 my ($Bnegation, $Brange) = @{$B};
814  
815 0 ▶ if ($Anegation == $Bnegation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Anegation == $Bnegation) { } 0 0 0
816 #
817 # If A and B have the same negation, then this really is a normal union
818 #
819 0 return [ $Anegation, get_union_ref('--unsorted', [ $Arange, $Brange ]) ];
820 } else {
821 #
822 # If not A and B have the same negation, then this really is a normal union.
823 # We choose the one with the smallest number of elements
824 #
825 0 my $Aelements = $#{$A->[1]};
826 0 my $Belements = $#{$B->[1]};
827 #
828 # 65534 because this is the maximum index in JavaScript, limited explicitely to UCS-2
829 #
830 0 my $AelementsRevert = 65534 - $#{$A->[1]};
831 0 my $BelementsRevert = 65534 - $#{$B->[1]};
832  
833 0 ▶ if (($Aelements + $BelementsRevert) <= ($AelementsRevert + $Belements)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Aelements + $BelementsRevert <= $AelementsRevert + $Belements) { } 0 0 0
834 #
835 # We take the union of A and reverted B
836 #
837 0 return $self->_charsetUnion($A, $self->_rangeComplement($B));
838 } else {
839 #
840 # We take the union of reverted A and B
841 #
842 0 return $self->_charsetUnion($self->_rangeComplement($A), $B);
843 }
844 }
845 }
846  
847 0 ▶sub _NonemptyClassRanges_ClassAtom_NonemptyClassRangesNoDash {
Subroutine _NonemptyClassRanges_ClassAtom_NonemptyClassRangesNoDash: not called CC=1 SCAR=6.9
848 0 my ($self, $classAtom, $nonemptyClassRangesNoDash) = @_;
849  
850 0 my $A = $classAtom;
851 0 my $B = $nonemptyClassRangesNoDash;
852 0 return $self->_charsetUnion($A, $B);
853 }
854  
855 0 ▶sub _characterRange {
Subroutine _characterRange: not called CC=6 SCAR=37.4
856 0 my ($self, $A, $B) = @_;
857  
858 0 my ($Anegation, $Arange) = @{$A};
859 0 my ($Bnegation, $Brange) = @{$B};
860  
861 0 ▶ if ($Anegation != $Bnegation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Anegation != $Bnegation) 0 0 0
862 # We choose the one with the smallest number of elements
863 #
864 0 my $Aelements = $#{$A->[1]};
865 0 my $Belements = $#{$B->[1]};
866 #
867 # 65534 because this is the maximum index in JavaScript, limited explicitely to UCS-2
868 #
869 0 my $AelementsRevert = 65534 - $#{$A->[1]};
870 0 my $BelementsRevert = 65534 - $#{$B->[1]};
871  
872 0 ▶ if ($AelementsRevert <= $BelementsRevert) {
Branch: 1 branch
BranchTrueFalseTotal
if ($AelementsRevert <= $BelementsRevert) { } 0 0 0
873 #
874 # We take the reverted A
875 #
876 0 ($Anegation, $Arange) = $self->_rangeComplement($A);
877 } else {
878 #
879 # We take the reverted B
880 #
881 0 ($Bnegation, $Brange) = $self->_rangeComplement($B);
882 }
883 }
884  
885 0 ▶ if ($#{$Arange} != 0 || $#{$Brange} != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$Arange;} != 0 or $#{$Brange;} != 0) 0 0 0
Condition0%0/3
$#{$Arange;} != 0 or $#{$Brange;} != 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$#{$Arange;} != 0 or $#{$Brange;} != 0
$#{$Arange;} != 0 $#{$Brange;} != 0
Truth table0%0/3
A or B
A= $#{$Arange;} != 0B= $#{$Brange;} != 0
ABresult
1X1
011
000
886 0 SyntaxError("Doing characterRange requires both charsets to have exactly one element");
887 }
888 0 my $a = $Arange->[0];
889 0 my $b = $Brange->[0];
890 0 my $i = ord($a);
891 0 my $j = ord($b);
892 0 ▶ if ($i > $j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $j) 0 0 0
893 0 SyntaxError("Doing characterRange requires first char '$a' to be <= second char '$b'");
894 }
895  
896 0 return [$Anegation, [ map {chr($_)} ($i..$j) ]];
897  
898 }
899  
900 0 ▶sub _NonemptyClassRanges_ClassAtom_ClassAtom_ClassRanges {
Subroutine _NonemptyClassRanges_ClassAtom_ClassAtom_ClassRanges: not called CC=1 SCAR=6.9
901 0 my ($self, $classAtom1, undef, $classAtom2, $classRanges) = @_;
902  
903 0 my $A = $classAtom1;
904 0 my $B = $classAtom2;
905 0 my $C = $classRanges;
906 0 my $D = $self->_characterRange($A, $B);
907  
908 0 return $self->_charsetUnion($D, $C);
909 }
910  
911 0 ▶sub _NonemptyClassRangesNoDash_ClassAtom {
Subroutine _NonemptyClassRangesNoDash_ClassAtom: not called CC=1 SCAR=6.9
912 0 my ($self, $classAtom) = @_;
913  
914 0 return $classAtom;
915 }
916  
917 0 ▶sub _NonemptyClassRangesNoDash_ClassAtomNoDash_NonemptyClassRangesNoDash {
Subroutine _NonemptyClassRangesNoDash_ClassAtomNoDash_NonemptyClassRangesNoDash: not called CC=1 SCAR=6.9
918 0 my ($self, $classAtomNoDash, $nonemptyClassRangesNoDash) = @_;
919  
920 0 my $A = $classAtomNoDash;
921 0 my $B = $nonemptyClassRangesNoDash;
922 0 return $self->_charsetUnion($A, $B);
923 }
924  
925 0 ▶sub _NonemptyClassRangesNoDash_ClassAtomNoDash_ClassAtom_ClassRanges {
Subroutine _NonemptyClassRangesNoDash_ClassAtomNoDash_ClassAtom_ClassRanges: not called CC=1 SCAR=6.9
926 0 my ($self, $classAtomNoDash, undef, $classAtom, $classRanges) = @_;
927  
928 0 my $A = $classAtomNoDash;
929 0 my $B = $classAtom;
930 0 my $C = $classRanges;
931 0 my $D = $self->_characterRange($A, $B);
932 0 return $self->_charsetUnion($D, $C);
933 }
934  
935 0 ▶sub _ClassAtom_Dash {
Subroutine _ClassAtom_Dash: not called CC=1 SCAR=6.9
936 0 my ($self, undef) = @_;
937  
938 0 return [0, [ '-' ]];
939 }
940  
941 0 ▶sub _ClassAtom_ClassAtomNoDash {
Subroutine _ClassAtom_ClassAtomNoDash: not called CC=1 SCAR=6.9
942 0 my ($self, $classAtomNoDash) = @_;
943  
944 0 return $classAtomNoDash;
945 }
946  
947 0 ▶sub _ClassAtomNoDash_OneChar {
Subroutine _ClassAtomNoDash_OneChar: not called CC=1 SCAR=6.9
948 0 my ($self, $oneChar) = @_;
949  
950 #
951 # Note: OneChar is a lexeme, default lexeme value is [start,length,value]
952 #
953 0 return [0, [ $oneChar->[2] ]];
954 }
955  
956 0 ▶sub _ClassAtomNoDash_ClassEscape {
Subroutine _ClassAtomNoDash_ClassEscape: not called CC=1 SCAR=6.9
957 0 my ($self, undef, $classEscape) = @_;
958  
959 0 return $classEscape;
960 }
961  
962 0 ▶sub _ClassEscape_DecimalEscape {
Subroutine _ClassEscape_DecimalEscape: not called CC=2 SCAR=17.9
963 0 my ($self, $decimalEscape) = @_;
964  
965 0 my $E = $decimalEscape;
966  
967 #
968 # We are in the ClassEscape context. Only a character is possible.
969 # Yet, it is possible that the codepoint $E correspond to no character
970 #
971 0 my $ch = eval {chr($E)};
972 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
973 0 SyntaxError("Decimal Escape is not a valid character");
974 }
975 0 return [0, [ $ch ]];
976 }
977  
978 0 ▶sub _ClassEscape_b {
Subroutine _ClassEscape_b: not called CC=1 SCAR=6.9
979 0 my ($self, undef) = @_;
980  
981 0 return [0, MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses::BS() ];
982 }
983  
984 0 ▶sub _ClassEscape_CharacterEscape {
Subroutine _ClassEscape_CharacterEscape: not called CC=1 SCAR=6.9
985 0 my ($self, $characterEscape) = @_;
986  
987 0 return [0, [ $characterEscape ]];
988 }
989  
990 0 ▶sub _ClassEscape_CharacterClassEscape {
Subroutine _ClassEscape_CharacterClassEscape: not called CC=1 SCAR=6.9
991 0 my ($self, $characterClassEscape) = @_;
992  
993 0 return $characterClassEscape;
994 }
995  
996  
997 6 1;
998  
999 __END__
« AST/Grammar/ECMAScript_262_5/Template.pm ↑ Summary AST/Util.pm »