JE/Parser.pm

filter: Statementstmt 76.1% 571 / 750 Branchbran 64.0% 461 / 720 Conditioncond 68.8% 42 / 61 MC/DCmcdc 43.3% 13 / 30 Subroutinesub 95.0% 76 / 80 Podpod 10.6% 7 / 66 totaltotal 68.5% 1170 / 1707 CC 385 SCAR 40.1
CC
385
Cov
70%
for
342.0
switch
204.5
try
150.4
CRAP 55.2
« JE/Object/Math.pm ↑ Summary JE.pm »
1 package JE::Parser;
2  
3 101 our $VERSION = '0.066';
4  
5 101 ▶use strict; # :-(
Subroutine BEGIN: called CC=1 SCAR=0.0
6 101 ▶use warnings;# :-(
Subroutine BEGIN: called CC=1 SCAR=0.0
7 101 ▶no warnings 'utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 101 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 101 require JE::Code ;
12 101 require JE::Number; # ~~~ Don't want to do this
13  
14 101 import JE::Code 'add_line_number';
15 sub add_line_number;
16  
17 101 our ($_parser, $global, @_decls, @_stms, $_vars);
18  
19 #----------METHODS---------#
20  
21 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
22 2 my %self = (
23 stm_names => [qw[
24 -function block empty if while with for switch try
25 labelled var do continue break return throw expr
26 ]],
27 stm => {
28 -function => \&function, block => \&block,
29 empty => \&empty, if => \&if,
30 while => \&while, with => \&with,
31 for => \&for, switch => \&switch,
32 try => \&try, labelled => \&labelled,
33 var => \&var, do => \&do,
34 continue => \&continue, break => \&break,
35 return => \&return, throw => \&throw,
36 expr => \&expr_statement,
37 },
38 global => pop,
39 );
40 2 return bless \%self, shift;
41 }
42  
43 0 ▶sub add_statement {
Subroutine add_statement: not called CC=4 SCAR=30.0
Pod documented
44 0 my($self,$name,$parser) = shift;
45 0 my $in_list;
46 # no warnings 'exiting';
47 grep $_ eq $name && ++$in_list && goto END_GREP,
48 0 ▶ @{$$self{stm_names}};
Condition0%0/5
$_ eq $name && ++$in_list && (goto END_GREP)
!ll
00
$_ eq $name and ++$in_list
!ll&&!rl&&r
000
MC/DC0%0/2
$_ eq $name && ++$in_list && (goto END_GREP)
$_ eq $name ++$in_list
Truth table0%0/3
A and B
A= $_ eq $nameB= ++$in_list
ABresult
0X0
100
111
49 END_GREP:
50 0 ▶ $in_list or unshift @{$$self{stm_names}} ,$name;
Branch: 1 branch
BranchTrueFalseTotal
$in_list or unshift @{$$self{"stm_names"};}, $name 0 0 0
51 0 $$self{stm}{$name} = $parser;
52 0 return; # Don't return anything for now, because if we return some-
53 # thing, even if it's not documented, someone might start
54 # relying on it.
55 }
56  
57 1 ▶sub delete_statement {
Subroutine delete_statement: called CC=2 SCAR=6.9
Pod documented
58 1 my $self = shift;
59 1 for my $name (@_) {
60 4 delete $$self{stm}{$name};
61 4 @{$$self{stm_names}} =
62 4 grep $_ ne $name, @{$$self{stm_names}};
63 }
64 1 return $self;
65 }
66  
67 2 ▶sub statement_list {
Subroutine statement_list: called CC=1 SCAR=0.0
Pod documented
68 2 $_[0]{stm_names};
69 }
70  
71 11 ▶sub parse {
Subroutine parse: called CC=3 SCAR=11.0
Pod documented
72 11 local $_parser = shift;
73 11 local(@_decls, @_stms); # Doing this here and localising it saves
74 11 for(@{$_parser->{stm_names}}) { # us from having to do it multiple
75 143 ▶ push @{/^-/ ? \@_decls : \@_stms}, # times.
Branch: 1 branch
BranchTrueFalseTotal
/^-/ ? : 0 143 143
76 143 $_parser->{stm}{$_};
77 }
78  
79 11 JE::Code::parse($_parser->{global}, @_);
80 }
81  
82 4 ▶sub eval {
Subroutine eval: called CC=1 SCAR=0.0
Pod documented
83 4 shift->parse(@_)->execute
84 }
85  
86 #----------PARSER---------#
87  
88 101 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
89  
90 101 our @EXPORT_OK = qw/ $h $n $optional_sc $ss $s $S $id_cont
91 str num skip ident expr expr_noin statement
92 statements expected optional_sc/;
93 101 our @EXPORT_TAGS = (
94 vars => [qw/ $h $n $optional_sc $ss $s $S $id_cont/],
95 functions => [qw/ str num skip ident expr expr_noin statement
96 statements expected optional_sc /],
97 );
98  
99 101 ▶use re 'taint';
Subroutine BEGIN: called CC=1 SCAR=0.0
100 #use subs qw'statement statements assign assign_noin expr new';
101 101 ▶use constant JECE => 'JE::Code::Expression';
Subroutine BEGIN: called CC=1 SCAR=0.0
102 101 ▶use constant JECS => 'JE::Code::Statement';
Subroutine BEGIN: called CC=1 SCAR=0.0
103  
104 101 require JE::String;
105 101 import JE::String 'desurrogify';
106 101 import JE::String 'surrogify';
107 sub desurrogify($);
108 sub surrogify($);
109  
110  
111 # die is called with a scalar ref when the string contains what is
112 # expected. This will be converted to a longer message afterwards, which
113 # will read something like "Expected %s but found %s" (probably the most
114 # common error message, which is why there is a shorthand). Using an array
115 # ref is the easiest way to stop the 'at ..., line ...' from being appended
116 # when there is no line break at the end already. die is called with a
117 # double reference to a string if the string is the complete error
118 # message.
119 # ~~~ We may need a function for this second usage, in case we change the
120 # \\ yet again.
121  
122 # @ret != push @ret, ... is a funny way of pushing and then checking to
123 # see whether anything was pushed.
124  
125  
126 21 ▶sub expected($) { # public
Subroutine expected: called CC=1 SCAR=0.0
Pod undocumented
127 21 die \shift
128 }
129  
130  
131 # public vars:
132  
133 # optional horizontal comments and whitespace
134 101 our $h = qr(
135 (?> [ \t\x0b\f\xa0\p{Zs}]* )
136 (?> (?>/\*[^\cm\cj\x{2028}\x{2029}]*?\*/) [ \t\x0b\f\xa0\p{Zs}]* )?
137 )x;
138  
139 # line terminators
140 101 our $n = qr((?>[\cm\cj\x{2028}\x{2029}]));
141  
142 # single space char
143 101 our $ss = qr((?>[\p{Zs}\s\ck\x{2028}\x{2029}]));
144  
145 # optional comments and whitespace
146 101 our $s = qr((?>
147 (?> $ss* )
148 (?> (?> //[^\cm\cj\x{2028}\x{2029}]* (?>$n|\z) | /\*.*?\*/ )
149 (?> $ss* )
150 ) *
151 ))sx;
152  
153 # mandatory comments/whitespace
154 101 our $S = qr(
155 (?>
156 $ss
157 |
158 //[^\cm\cj\x{2028}\x{2029}]*
159 |
160 /\*.*?\*/
161 )
162 $s
163 )xs;
164  
165 101 our $id_cont = qr(
166 (?>
167 \\u([0-9A-Fa-f]{4})
168 |
169 [\p{ID_Continue}\$_]
170 )
171 )x;
172  
173 # end public vars
174  
175  
176 42015 ▶sub str() { # public
Subroutine str: called CC=8 SCAR=20.8
Pod undocumented
177 # For very long strings (>~45000), this pattern hits a perl bug (Complex regular subexpression recursion limit (32766) exceeded)
178 #/\G (?: '((?>(?:[^'\\] | \\.)*))'
179 # |
180 # "((?>(?:[^"\\] | \\.)*))" )/xcgs or return;
181 # There are two solutions:
182 # 1) Use the unrolling technique from the Owl Book.
183 # 2) Use shorter patterns but more code (contributed by Kevin
184 # Cameron)
185 # Number 1 should be faster, but it crashes under perl 5.8.8 on
186 # Windows, and perhaps on other platforms, too. So we use #2 for
187 # 5.8.x regardless of platform to be on the safe side.
188  
189 101 ▶ use constant old_perl => $] < 5.01; # Use a constant so the
Subroutine BEGIN: called CC=1 SCAR=0.0
190 42015 my $yarn; # if-block disappears
191 42015 if(old_perl) { # at compile-time.
192 # Use a simpler pattern (but more code) to break strings up
193 # into extents bounded by the quote or escape
194 my $qt = substr($_,pos($_),1);
195 $qt =~ /['"]/ or return; # not a string literal if first
196 pos($_)++; # char not a quote
197 my $done = 0;
198 while (defined(substr($_,pos($_),1))) {
199 my ($part) = /\G([^\\$qt]*)/xcgs;
200 defined($part) or $part = "";
201 $yarn .= $part;
202 my $next = substr($_,pos($_)++,1);
203  
204 if ($next eq "\\") {
205 #pass on any escaped char
206 $next = substr($_,pos($_)++,1);
207 $yarn .= "\\$next";
208 } else {
209 # handle end quote
210 $done = 1;
211 last;
212 }
213 }
214  
215 # error if EOF before end of string
216 return if !$done;
217 }
218 else {
219 42015 ▶ /\G (?: '([^'\\]*(?:\\.[^'\\]*)*)'
Branch: 1 branch
BranchTrueFalseTotal
/\G (?: '([^'\\]*(?:\\.[^'\\]*)*)' | "([^"\\]*(?:\\.[^"\\]*)*)" )/cgsx or return 9838 32177 42015
220 |
221 "([^"\\]*(?:\\.[^"\\]*)*)" )/xcgs or return;
222 9838 $yarn = $+;
223 }
224 # Get rid of that constant, as it’s no longer needed.
225 101 ▶BEGIN { no strict; delete ${__PACKAGE__.'::'}{old_perl}; }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
226  
227 # transform special chars
228 101 ▶ no re 'taint'; # I need eval "qq-..." to work
Subroutine BEGIN: called CC=1 SCAR=0.0
229 9838 $yarn =~ s/\\(?:
230 u([0-9a-fA-F]{4})
231 |
232 x([0-9a-fA-F]{2})
233 |
234 (\r\n?|[\n\x{2028}\x{2029}])
235 |
236 ([bfnrt])
237 |
238 (v)
239 |
240 ([0-3][0-7]{0,2}|[4-7][0-7]?) # actually slightly looser
241 | # than what ECMAScript v3 has in its
242 (.) # addendum (it forbids \0 when followed by 8)
243 )/
244 22012 ▶ $1 ? chr(hex $1) :
Branch: 6 branches
BranchTrueFalseTotal
$1 ? : 178 21834 22012
$2 ? : 356 21478 21834
$3 ? : 2442 19036 21478
$4 ? : 126 18910 19036
$5 ? : 28 18882 18910
defined $6 ? : 16 18866 18882
245 $2 ? chr(hex $2) :
246 $3 ? "" : # escaped line feed disappears
247 $4 ? eval "qq-\\$4-" :
248 $5 ? "\cK" :
249 defined $6 ? chr oct $6 :
250 $7
251 /sgex;
252 9838 "s$yarn";
253 }
254  
255 32177 ▶sub num() { # public
Subroutine num: called CC=4 SCAR=13.9
Pod undocumented
256 32177 ▶ /\G (?:
Branch: 1 branch
BranchTrueFalseTotal
/\G (?: 0[Xx] ([A-Fa-f0-9]+) | 0 ([01234567]+) | (?=[0-9]|\.[0-9]) ( (?:0|[1-9][0-9]*)? (?:\.[0-9]*)? (?:[Ee][+-]?[0-9]+)? ) ) /cgx or return 21551 10626 32177
257 0[Xx] ([A-Fa-f0-9]+)
258 |
259 0 ([01234567]+)
260 |
261 (?=[0-9]|\.[0-9])
262 (
263 (?:0|[1-9][0-9]*)?
264 (?:\.[0-9]*)?
265 (?:[Ee][+-]?[0-9]+)?
266 )
267 ) /xcg
268 or return;
269 21551 ▶ return defined $1 ? hex $1 : defined $2 ? oct $2 : $3;
Branch: 2 branches
BranchTrueFalseTotal
defined $1 ? : 71 21480 21551
defined $2 ? : 15 21465 21480
270 }
271  
272 101 our $ident = qr(
273 (?! (?: case | default ) (?!$id_cont) )
274 (?:
275 \\u[0-9A-Fa-f]{4}
276 |
277 [\p{ID_Start}\$_]
278 )
279 (?> $id_cont* )
280 )x;
281  
282 23659 ▶sub unescape_ident($) {
Subroutine unescape_ident: called CC=2 SCAR=6.9
Pod undocumented
283 23659 my $ident = shift;
284 23659 $ident =~ s/\\u([0-9a-fA-F]{4})/chr hex $1/ge;
285 23659 $ident = desurrogify $ident;
286 23659 ▶ $ident =~ /^[\p{ID_Start}\$_]
Branch: 1 branch
BranchTrueFalseTotal
$ident =~ /^[\p{ID_Start}\$_] [\p{ID_Continue}\$_]* \z/x or die \(\("'${ident}' is not a valid identifier")) 23658 1 23659
287 [\p{ID_Continue}\$_]*
288 \z/x
289 or die \\"'$ident' is not a valid identifier";
290 23658 $ident;
291 }
292  
293 # public
294 34764 ▶sub skip() { /\G$s/g } # skip whitespace
Subroutine skip: called CC=1 SCAR=0.0
Pod undocumented
295  
296 6468 ▶sub ident() { # public
Subroutine ident: called CC=2 SCAR=6.9
Pod undocumented
297 6468 ▶ return unless my($ident) = /\G($ident)/cgox;
Branch: 1 branch
BranchTrueFalseTotal
unless my($ident) = /\G($JE::Parser::ident)/cgox 930 5538 6468
298 5538 unescape_ident $ident;
299 }
300  
301 364 ▶sub params() { # Only called when we know we need it, which is why it dies
Subroutine params: called CC=6 SCAR=17.9
Pod undocumented
302 # on the second line
303 364 my @ret;
304 364 ▶ /\G\(/gc or expected "'('";
Branch: 1 branch
BranchTrueFalseTotal
/\G\(/cg or &expected("'('") 364 0 364
305 364 &skip;
306 364 ▶ if (@ret != push @ret, &ident) { # first identifier (not prec.
Branch: 1 branch
BranchTrueFalseTotal
if (@ret != push(@ret, &ident)) 111 253 364
307 # by comma)
308 111 ▶ while (/\G$s,$s/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$JE::Parser::s,$JE::Parser::s/cg) 100 109 209
309 # if there's a comma we need another ident
310 100 ▶ @ret != push @ret, &ident or expected 'identifier';
Branch: 1 branch
BranchTrueFalseTotal
@ret != push(@ret, &ident) or &expected("identifier") 98 2 100
311 }
312 109 &skip;
313 }
314 362 ▶ /\G\)/gc or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)/cg or &expected("')'") 360 2 362
315 360 \@ret;
316 }
317  
318 61676 ▶sub term() {
Subroutine term: called CC=35 SCAR=35.8
Pod undocumented
319 61676 my $pos = pos;
320 61676 my $tmp;
321 61676 ▶ if(/\Gfunction(?!$id_cont)$s/cg) {
Branch: 7 branches
BranchTrueFalseTotal
if (/\Gfunction(?!$JE::Parser::id_cont)$JE::Parser::s/cg) { } 163 61513 61676
elsif (($tmp) = /\G($JE::Parser::ident)/cgox) { } 20017 41496 61513
elsif (defined($tmp = &str) or defined($tmp = &num)) { } 31298 10198 41496
elsif (m(\G / ( (?:[^/*\\[] | \\. | \[ (?>(?:[^]\\] | \\.)*) \] ) (?>(?:[^/\\[] | \\. | \[ (?>(?:[^]\\] | \\.)*) \] )*) ) / ($JE::Parser::id_cont*) )cgox) { } 317 9881 10198
elsif (/\G\[$JE::Parser::s/cg) { } 5291 4590 9881
elsif (/\G\{$JE::Parser::s/cg) { } 552 4038 4590
elsif (/\G\($JE::Parser::s/cg) { } 812 3226 4038
322 163 my @ret = (func => ident);
323 163 ▶ @ret == 2 and &skip;
Branch: 1 branch
BranchTrueFalseTotal
@ret == 2 and &skip 7 156 163
324 163 push @ret, &params;
325 163 &skip;
326 163 ▶ /\G \{ /gcx or expected "'{'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \{ /cgx or &expected("'{'") 163 0 163
327 {
328 163 local $_vars = [];
329 163 push @ret, &statements, $_vars;
330 }
331 163 ▶ /\G \} /gocx or expected "'}'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \} /cgox or &expected("'}'") 163 0 163
332  
333 163 return bless [[$pos, pos], @ret], JECE;
334 }
335 # We don’t call the ident subroutine here,
336 # because we need to sift out null/true/false/this.
337 elsif(($tmp)=/\G($ident)/cgox) {
338 20017 ▶ $tmp=~/^(?:(?:tru|fals)e|null)\z/ &&return $global->$tmp;
Branch: 1 branch
BranchTrueFalseTotal
$tmp =~ /^(?:(?:tru|fals)e|null)\z/ and return $JE::Parser::global->$tmp 1769 18248 20017
339 18248 ▶ $tmp eq 'this' and return $tmp;
Branch: 1 branch
BranchTrueFalseTotal
$tmp eq "this" and return $tmp 216 18032 18248
340 18032 return "i" . unescape_ident $tmp;
341 }
342 ▶ elsif(defined($tmp = &str) or
Condition100%3/3
defined($tmp = &str) or defined($tmp = &num)
l!l&&r!l&&!r
98202147810198
MC/DC100%2/2
defined($tmp = &str) or defined($tmp = &num)
defined($tmp = &str) defined($tmp = &num)
Truth table100%3/3
A or B
A= defined($tmp = &str)B= defined($tmp = &num)
ABresult
1X1
011
000
343 defined($tmp = &num)) {
344 31298 return $tmp;
345 }
346 elsif(m-\G
347 /
348 ( (?:[^/*\\[] | \\. | \[ (?>(?:[^]\\] | \\.)*) \] )
349 (?>(?:[^/\\[] | \\. | \[ (?>(?:[^]\\] | \\.)*) \] )*) )
350 /
351 ($id_cont*)
352 -cogx ) {
353  
354 # I have to use local *_ because
355 # 'require JE::Object::RegExp' causes
356 # Scalar::Util->import() to be called (import is inherited
357 # from Exporter), and &Exporter::import does 'local $_',
358 # which, in p5.8.8 (though not 5.9.5) causes pos()
359 # to be reset.
360 317 { local *_; require JE::Object::RegExp; }
361 # ~~~ This needs to unescape the flags.
362 317 return JE::Object::RegExp->new( $global, $1, $2);
363 }
364 elsif(/\G\[$s/cg) {
365 5291 my $anon;
366 my @ret;
367 5291 my $length;
368  
369 5291 while () {
370 20890 ▶ @ret != ($length = push @ret, &assign) and &skip;
Branch: 1 branch
BranchTrueFalseTotal
@ret != ($length = push(@ret, &assign)) and &skip 20721 169 20890
371 20890 ▶ push @ret, bless \$anon, 'comma' while /\G,$s/cg;
Branch: 1 branch
BranchTrueFalseTotal
/\G,$JE::Parser::s/cg and do { push @ret, bless(\$anon, "comma") } 15702 20890 36592
372 20890 ▶ $length == @ret and last;
Branch: 1 branch
BranchTrueFalseTotal
$length == @ret and last 5291 15599 20890
373 }
374  
375 5291 ▶ /\G]/cg or expected "']'";
Branch: 1 branch
BranchTrueFalseTotal
/\G]/cg or &expected("']'") 5287 4 5291
376 5287 return bless [[$pos, pos], array => @ret], JECE;
377 }
378 elsif(/\G\{$s/cg) {
379 552 my @ret;
380  
381 552 ▶ if($tmp = &ident or defined($tmp = &str)&&$tmp=~s/^s// or
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp = &ident or defined($tmp = &str) and $tmp =~ s/^s// or defined($tmp = &num)) 125 427 552
Condition88%8/9
$tmp = &ident or defined($tmp = &str) and $tmp =~ s/^s// or defined($tmp = &num)
l!l&&r!l&&!r
10916427
$tmp = &ident or defined($tmp = &str) and $tmp =~ s/^s//
l!l&&r!l&&!r
9712443
defined($tmp = &str) and $tmp =~ s/^s//
!ll&&!rl&&r
443012
MC/DC75%3/4
$tmp = &ident or defined($tmp = &str) and $tmp =~ s/^s// or defined($tmp = &num)
$tmp = &ident defined($tmp = &str) $tmp =~ s/^s// defined($tmp = &num)
Truth table66%4/6
A or B and C or D
A= $tmp = &identB= defined($tmp = &str)C= $tmp =~ s/^s//D= defined($tmp = &num)
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
382 defined($tmp = &num)) {
383 # first elem, not preceded by comma
384 125 push @ret, $tmp;
385 125 &skip;
386 125 ▶ /\G:$s/cggg or expected 'colon';
Branch: 1 branch
BranchTrueFalseTotal
/\G:$JE::Parser::s/cg or &expected("colon") 125 0 125
387 125 ▶ @ret != push @ret, &assign
Branch: 1 branch
BranchTrueFalseTotal
@ret != push(@ret, &assign) or &expected(\"expression") 125 0 125
388 or expected \'expression';
389 125 &skip;
390  
391 125 ▶ while (/\G,$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G,$JE::Parser::s/cg) 101 124 225
392 $tmp = ident
393 or defined($tmp = &str)&&$tmp=~s/^s// or
394 defined($tmp = &num)
395 101 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$tmp = &ident() or defined($tmp = &str) and $tmp =~ s/^s// or defined($tmp = &num) or do { /\G}/cg or &expected("'}', identifier, or string or number literal"); return bless([[$pos, pos $_], "hash", @ret], "JE::Code::Expression") } 100 1 101
Condition88%8/9
$tmp = &ident() or defined($tmp = &str) and $tmp =~ s/^s// or defined($tmp = &num)
l!l&&r!l&&!r
43571
$tmp = &ident() or defined($tmp = &str) and $tmp =~ s/^s//
l!l&&r!l&&!r
37658
defined($tmp = &str) and $tmp =~ s/^s//
!ll&&!rl&&r
5806
MC/DC75%3/4
$tmp = &ident() or defined($tmp = &str) and $tmp =~ s/^s// or defined($tmp = &num)
$tmp = &ident() defined($tmp = &str) $tmp =~ s/^s// defined($tmp = &num)
Truth table66%4/6
A or B and C or D
A= $tmp = &ident()B= defined($tmp = &str)C= $tmp =~ s/^s//D= defined($tmp = &num)
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
396 # ECMAScript 5 allows a
397 # trailing comma
398 1 ▶ /\G}/cg or expected
Branch: 1 branch
BranchTrueFalseTotal
/\G}/cg or &expected("'}', identifier, or string or number literal") 1 0 1
399 "'}', identifier, or string or ".
400 " number literal";
401 1 return bless [[$pos, pos],
402 hash => @ret], JECE;
403 };
404  
405 100 push @ret, $tmp;
406 100 &skip;
407 100 ▶ /\G:$s/cggg or expected 'colon';
Branch: 1 branch
BranchTrueFalseTotal
/\G:$JE::Parser::s/cg or &expected("colon") 100 0 100
408 100 ▶ @ret != push @ret, &assign
Branch: 1 branch
BranchTrueFalseTotal
@ret != push(@ret, &assign) or &expected("expression") 100 0 100
409 or expected 'expression';
410 100 &skip;
411 }
412 }
413 551 ▶ /\G}/cg or expected "'}'";
Branch: 1 branch
BranchTrueFalseTotal
/\G}/cg or &expected("'}'") 551 0 551
414 551 return bless [[$pos, pos], hash => @ret], JECE;
415 }
416 elsif (/\G\($s/cg) {
417 812 ▶ my $ret = &expr or expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
my $ret = &expr or &expected("expression") 812 0 812
418 812 &skip;
419 812 ▶ /\G\)/cg or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)/cg or &expected("')'") 812 0 812
420 812 return $ret;
421 }
422 return
423 3226 }
424  
425 71534 ▶sub subscript() { # skips leading whitespace
Subroutine subscript: called CC=6 SCAR=18.2
Pod undocumented
426 71534 my $pos = pos;
427 71534 my $subscript;
428 71534 ▶ if (/\G$s\[$s/cg) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\G$JE::Parser::s\[$JE::Parser::s/cg) { } 1012 70522 71534
elsif (/\G$JE::Parser::s\.$JE::Parser::s/cg) { } 4220 66302 70522
429 1012 ▶ $subscript = &expr or expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
$subscript = &expr or &expected("expression") 1012 0 1012
430 1012 &skip;
431 1012 ▶ /\G]/cog or expected "']'";
Branch: 1 branch
BranchTrueFalseTotal
/\G]/cog or &expected("']'") 1012 0 1012
432 }
433 elsif (/\G$s\.$s/cg) {
434 4220 ▶ $subscript = &ident or expected 'identifier';
Branch: 1 branch
BranchTrueFalseTotal
$subscript = &ident or &expected("identifier") 4220 0 4220
435 }
436 66302 else { return }
437  
438 5232 return bless [[$pos, pos], $subscript], 'JE::Code::Subscript';
439 }
440  
441 71502 ▶sub args() { # skips leading whitespace
Subroutine args: called CC=6 SCAR=17.9
Pod undocumented
442 71502 my $pos = pos;
443 71502 my @ret;
444 71502 ▶ /\G$s\($s/gc or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G$JE::Parser::s\($JE::Parser::s/cg or return 10414 61088 71502
445 10414 ▶ if (@ret != push @ret, &assign) { # first expression (not prec.
Branch: 1 branch
BranchTrueFalseTotal
if (@ret != push(@ret, &assign)) 9030 1384 10414
446 # by comma)
447 9030 ▶ while (/\G$s,$s/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$JE::Parser::s,$JE::Parser::s/cg) 9255 9030 18285
448 # if there's a comma we need another expression
449 9255 ▶ @ret != push @ret, &assign
Branch: 1 branch
BranchTrueFalseTotal
@ret != push(@ret, &assign) or &expected("expression") 9255 0 9255
450 or expected 'expression';
451 }
452 9030 &skip;
453 }
454 10414 ▶ /\G\)/gc or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)/cg or &expected("')'") 10412 2 10414
455 10412 return bless [[$pos, pos], @ret], 'JE::Code::Arguments';
456 }
457  
458 62685 ▶sub new_expr() {
Subroutine new_expr: called CC=6 SCAR=18.1
Pod undocumented
459 62685 ▶ /\G new(?!$id_cont) $s /cgx or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G new(?!$JE::Parser::id_cont) $JE::Parser::s /cgx or return 1009 61676 62685
460 1009 my $ret = bless [[pos], 'new'], JECE;
461
462 1009 my $pos = pos;
463 1009 ▶ my @member_expr = &new_expr || &term
Condition50%3/6
&new_expr || &term || &expected(q[identifier, literal, 'new' or '('])
l!l&&r!l&&!r
100900
&new_expr or &term
l!l&&r!l&&!r
810010
MC/DC0%0/3
&new_expr || &term || &expected(q[identifier, literal, 'new' or '('])
&new_expr &term &expected(q[identifier, literal, 'new' or '('])
Truth table50%2/4
A or B || C
A= &new_exprB= &termC= &expected(q[identifier, literal, 'new' or '('])
ABCresult
1XX1
01X1
0011
0000
464 || expected "identifier, literal, 'new' or '('";
465  
466 1009 ▶ 0 while @member_expr != push @member_expr, &subscript;
Branch: 1 branch
BranchTrueFalseTotal
@member_expr != push(@member_expr, &subscript) and do { '???' } 32 1009 1041
467  
468 1009 ▶ push @$ret, @member_expr == 1 ? @member_expr :
Branch: 1 branch
BranchTrueFalseTotal
@member_expr == 1 ? : 977 32 1009
469 bless [[$pos, pos], 'member/call', @member_expr],
470 JECE;
471 1009 push @$ret, args;
472 1009 $ret;
473 }
474  
475 61676 ▶sub left_expr() {
Subroutine left_expr: called CC=6 SCAR=17.9
Pod undocumented
476 61676 my($pos,@ret) = pos;
477 61676 ▶ @ret != push @ret, &new_expr || &term or return;
Branch: 1 branch
BranchTrueFalseTotal
@ret != push(@ret, &new_expr || &term) or return 58440 3226 61666
Condition100%3/3
&new_expr || &term
l!l&&r!l&&!r
1001532527423
MC/DC100%2/2
&new_expr || &term
&new_expr &term
Truth table100%3/3
A || B
A= &new_exprB= &term
ABresult
1X1
011
000
478  
479 58440 ▶ 0 while @ret != push @ret, &subscript, &args;
Branch: 1 branch
BranchTrueFalseTotal
@ret != push(@ret, &subscript, &args) and do { '???' } 12053 58438 70491
480 58438 ▶ @ret ? @ret == 1 ? @ret :
Branch: 2 branches
BranchTrueFalseTotal
@ret ? : 58438 0 58438
@ret == 1 ? : 47319 11119 58438
481 bless([[$pos, pos], 'member/call', @ret],
482 JECE)
483 : return;
484 }
485  
486 61676 ▶sub postfix() {
Subroutine postfix: called CC=4 SCAR=13.9
Pod undocumented
487 61676 my($pos,@ret) = pos;
488 61676 ▶ @ret != push @ret, &left_expr or return;
Branch: 1 branch
BranchTrueFalseTotal
@ret != push(@ret, &left_expr) or return 58438 3226 61664
489 58438 ▶ push @ret, $1 while /\G $h ( \+\+ | -- ) /cogx;
Branch: 1 branch
BranchTrueFalseTotal
/\G $JE::Parser::h ( \+\+ | -- ) /cgox and do { push @ret, $1 } 92 58438 58530
490 58438 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'postfix', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 58346 92 58438
491 JECE;
492 }
493  
494 61676 ▶sub unary() {
Subroutine unary: called CC=5 SCAR=16.1
Pod undocumented
495 61676 my($pos,@ret) = pos;
496 61676 ▶ push @ret, $1 while /\G $s (
Branch: 1 branch
BranchTrueFalseTotal
/\G $JE::Parser::s ( (?: delete | void | typeof )(?!$JE::Parser::id_cont) | \+\+? | --? | ~ | ! ) $JE::Parser::s /cgx and do { push @ret, $1 } 8712 61676 70388
497 (?: delete | void | typeof )(?!$id_cont)
498 |
499 \+\+? | --? | ~ | !
500 ) $s /cgx;
501 61676 ▶ @ret != push @ret, &postfix or (
Branch: 2 branches
BranchTrueFalseTotal
@ret != push(@ret, &postfix) or @ret ? &expected("expression") : (return) 58438 3226 61664
@ret ? : 1 3225 3226
502 @ret
503 ? expected "expression"
504 : return
505 );
506 58438 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'prefix', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 49833 8605 58438
507 JECE;
508 }
509  
510 61456 ▶sub multi() {
Subroutine multi: called CC=5 SCAR=16.1
Pod undocumented
511 61456 my($pos,@ret) = pos;
512 61456 ▶ @ret != push @ret, &unary or return;
Branch: 1 branch
BranchTrueFalseTotal
@ret != push(@ret, &unary) or return 58218 3225 61443
513 58218 ▶ while(m-\G $s ( [*%](?!=) | / (?![*/=]) ) $s -cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[\G $JE::Parser::s ( [*%](?!=) | / (?![*/=]) ) $JE::Parser::s ]cgx) 220 58218 58438
514 220 push @ret, $1;
515 220 ▶ @ret == push @ret, &unary and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &unary) and &expected("expression") 0 220 220
516 }
517 58218 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 58008 210 58218
518 JECE;
519 }
520  
521 60178 ▶sub add() {
Subroutine add: called CC=5 SCAR=16.1
Pod undocumented
522 60178 my($pos,@ret) = pos;
523 60178 ▶ @ret != push @ret, &multi or return;
Branch: 1 branch
BranchTrueFalseTotal
@ret != push(@ret, &multi) or return 56940 3225 60165
524 56940 ▶ while(/\G $s ( \+(?![+=]) | -(?![-=]) ) $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s ( \+(?![+=]) | -(?![-=]) ) $JE::Parser::s /cgx) 1278 56940 58218
525 1278 push @ret, $1;
526 1278 ▶ @ret == push @ret, &multi and expected 'expression'
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &multi) and &expected("expression") 0 1278 1278
527 }
528 56940 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 56038 902 56940
529 JECE;
530 }
531  
532 60022 ▶sub bitshift() {
Subroutine bitshift: called CC=5 SCAR=16.1
Pod undocumented
533 60022 my($pos,@ret) = pos;
534 60022 ▶ @ret == push @ret, &add and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &add) and return 3225 56784 60009
535 56784 ▶ while(/\G $s (>>> | >>(?!>) | <<)(?!=) $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s (>>> | >>(?!>) | <<)(?!=) $JE::Parser::s /cgx) 156 56784 56940
536 156 push @ret, $1;
537 156 ▶ @ret == push @ret, &add and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &add) and &expected("expression") 0 156 156
538 }
539 56784 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 56628 156 56784
540 JECE;
541 }
542  
543 58511 ▶sub rel() {
Subroutine rel: called CC=5 SCAR=16.1
Pod undocumented
544 58511 my($pos,@ret) = pos;
545 58511 ▶ @ret == push @ret, &bitshift and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &bitshift) and return 3217 55281 58498
546 55281 ▶ while(/\G $s ( ([<>])(?!\2|=) | [<>]= |
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s ( ([<>])(?!\2|=) | [<>]= | in(?:stanceof)?(?!$JE::Parser::id_cont) ) $JE::Parser::s /cgx) 944 55281 56225
547 in(?:stanceof)?(?!$id_cont) ) $s /cgx) {
548 944 push @ret, $1;
549 944 ▶ @ret== push @ret, &bitshift and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &bitshift) and &expected("expression") 0 944 944
550 }
551 55281 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 54337 944 55281
552 JECE;
553 }
554  
555 555 ▶sub rel_noin() {
Subroutine rel_noin: called CC=5 SCAR=16.1
Pod undocumented
556 555 my($pos,@ret) = pos;
557 555 ▶ @ret == push @ret, &bitshift and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &bitshift) and return 8 547 555
558 547 ▶ while(/\G $s ( ([<>])(?!\2|=) | [<>]= | instanceof(?!$id_cont) )
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s ( ([<>])(?!\2|=) | [<>]= | instanceof(?!$JE::Parser::id_cont) ) $JE::Parser::s /cgx) 12 547 559
559 $s /cgx) {
560 12 push @ret, $1;
561 12 ▶ @ret == push @ret, &bitshift and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &bitshift) and &expected("expression") 0 12 12
562 }
563 547 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 535 12 547
564 JECE;
565 }
566  
567 55744 ▶sub equal() {
Subroutine equal: called CC=5 SCAR=16.1
Pod undocumented
568 55744 my($pos,@ret) = pos;
569 55744 ▶ @ret == push @ret, &rel and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &rel) and return 3217 52514 55731
570 52514 ▶ while(/\G $s ([!=]==?) $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s ([!=]==?) $JE::Parser::s /cgx) 2767 52514 55281
571 2767 push @ret, $1;
572 2767 ▶ @ret == push @ret, &rel and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &rel) and &expected("expression") 0 2767 2767
573 }
574 52514 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 49849 2665 52514
575 JECE;
576 }
577  
578 545 ▶sub equal_noin() {
Subroutine equal_noin: called CC=5 SCAR=16.1
Pod undocumented
579 545 my($pos,@ret) = pos;
580 545 ▶ @ret == push @ret, &rel_noin and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &rel_noin) and return 8 537 545
581 537 ▶ while(/\G $s ([!=]==?) $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s ([!=]==?) $JE::Parser::s /cgx) 10 537 547
582 10 push @ret, $1;
583 10 ▶ @ret == push @ret, &rel_noin and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &rel_noin) and &expected("expression") 0 10 10
584 }
585 537 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 527 10 537
586 JECE;
587 }
588  
589 55692 ▶sub bit_and() {
Subroutine bit_and: called CC=5 SCAR=16.1
Pod undocumented
590 55692 my($pos,@ret) = pos;
591 55692 ▶ @ret == push @ret, &equal and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &equal) and return 3217 52462 55679
592 52462 ▶ while(/\G $s &(?![&=]) $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s &(?![&=]) $JE::Parser::s /cgx) 52 52462 52514
593 52 ▶ @ret == push @ret, '&', &equal and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, "&", &equal) and &expected("expression") 0 52 52
594 }
595 52462 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 52410 52 52462
596 JECE;
597 }
598  
599 543 ▶sub bit_and_noin() {
Subroutine bit_and_noin: called CC=5 SCAR=16.1
Pod undocumented
600 543 my($pos,@ret) = pos;
601 543 ▶ @ret == push @ret, &equal_noin and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &equal_noin) and return 8 535 543
602 535 ▶ while(/\G $s &(?![&=]) $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s &(?![&=]) $JE::Parser::s /cgx) 2 535 537
603 2 ▶ @ret == push @ret, '&', &equal_noin
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, "&", &equal_noin) and &expected("expression") 0 2 2
604 and expected 'expression';
605 }
606 535 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 533 2 535
607 JECE;
608 }
609  
610 55639 ▶sub bit_or() {
Subroutine bit_or: called CC=5 SCAR=16.1
Pod undocumented
611 55639 my($pos,@ret) = pos;
612 55639 ▶ @ret == push @ret, &bit_and and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &bit_and) and return 3217 52409 55626
613 52409 ▶ while(/\G $s \|(?![|=]) $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s \|(?![|=]) $JE::Parser::s /cgx) 53 52409 52462
614 53 ▶ @ret == push @ret, '|', &bit_and and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, "|", &bit_and) and &expected("expression") 0 53 53
615 }
616 52409 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 52356 53 52409
617 JECE;
618 }
619  
620 541 ▶sub bit_or_noin() {
Subroutine bit_or_noin: called CC=5 SCAR=16.1
Pod undocumented
621 541 my($pos,@ret) = pos;
622 541 ▶ @ret == push @ret, &bit_and_noin and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &bit_and_noin) and return 8 533 541
623 533 ▶ while(/\G $s \|(?![|=]) $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s \|(?![|=]) $JE::Parser::s /cgx) 2 533 535
624 2 ▶ @ret == push @ret, '|', &bit_and_noin
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, "|", &bit_and_noin) and &expected("expression") 0 2 2
625 and expected 'expression';
626 }
627 533 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 531 2 533
628 JECE;
629 }
630  
631 55587 ▶sub bit_xor() {
Subroutine bit_xor: called CC=5 SCAR=16.1
Pod undocumented
632 55587 my($pos,@ret) = pos;
633 55587 ▶ @ret == push @ret, &bit_or and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &bit_or) and return 3217 52357 55574
634 52357 ▶ while(/\G $s \^(?!=) $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s \^(?!=) $JE::Parser::s /cgx) 52 52357 52409
635 52 ▶ @ret == push @ret, '^', &bit_or and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, "^", &bit_or) and &expected("expression") 0 52 52
636 }
637 52357 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 52305 52 52357
638 JECE;
639 }
640  
641 539 ▶sub bit_xor_noin() {
Subroutine bit_xor_noin: called CC=5 SCAR=16.1
Pod undocumented
642 539 my($pos,@ret) = pos;
643 539 ▶ @ret == push @ret, &bit_or_noin and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &bit_or_noin) and return 8 531 539
644 531 ▶ while(/\G $s \^(?!=) $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s \^(?!=) $JE::Parser::s /cgx) 2 531 533
645 2 ▶ @ret == push @ret, '^', &bit_or_noin
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, "^", &bit_or_noin) and &expected("expression") 0 2 2
646 and expected 'expression';
647 }
648 531 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 529 2 531
649 JECE;
650 }
651  
652 55110 ▶sub and_expr() { # If I just call it 'and', then I have to write
Subroutine and_expr: called CC=5 SCAR=16.1
Pod undocumented
653 # CORE::and for the operator! (Far too cumbersome.)
654 55110 my($pos,@ret) = pos;
655 55110 ▶ @ret == push @ret, &bit_xor and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &bit_xor) and return 3217 51880 55097
656 51880 ▶ while(/\G $s && $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s && $JE::Parser::s /cgx) 477 51880 52357
657 477 ▶ @ret == push @ret, '&&', &bit_xor
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, "&&", &bit_xor) and &expected("expression") 0 477 477
658 and expected 'expression';
659 }
660 51880 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 51608 272 51880
661 JECE;
662 }
663  
664 537 ▶sub and_noin() {
Subroutine and_noin: called CC=5 SCAR=16.1
Pod undocumented
665 537 my($pos,@ret) = pos;
666 537 ▶ @ret == push @ret, &bit_xor_noin and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &bit_xor_noin) and return 8 529 537
667 529 ▶ while(/\G $s && $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s && $JE::Parser::s /cgx) 2 529 531
668 2 ▶ @ret == push @ret, '&&', &bit_xor_noin
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, "&&", &bit_xor_noin) and &expected("expression") 0 2 2
669 and expected 'expression';
670 }
671 529 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 527 2 529
672 JECE;
673 }
674  
675 55030 ▶sub or_expr() {
Subroutine or_expr: called CC=5 SCAR=16.1
Pod undocumented
676 55030 my($pos,@ret) = pos;
677 55030 ▶ @ret == push @ret, &and_expr and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &and_expr) and return 3217 51800 55017
678 51800 ▶ while(/\G $s \|\| $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s \|\| $JE::Parser::s /cgx) 80 51800 51880
679 80 ▶ @ret == push @ret, '||', &and_expr
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, "||", &and_expr) and &expected("expression") 0 80 80
680 and expected 'expression';
681 }
682 51800 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 51722 78 51800
683 JECE;
684 }
685  
686 535 ▶sub or_noin() {
Subroutine or_noin: called CC=5 SCAR=16.1
Pod undocumented
687 535 my($pos,@ret) = pos;
688 535 ▶ @ret == push @ret, &and_noin and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &and_noin) and return 8 527 535
689 527 ▶ while(/\G $s \|\| $s /cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G $JE::Parser::s \|\| $JE::Parser::s /cgx) 2 527 529
690 2 ▶ @ret == push @ret, '||', &and_noin
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, "||", &and_noin) and &expected("expression") 0 2 2
691 and expected 'expression';
692 }
693 527 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'lassoc', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 525 2 527
694 JECE;
695 }
696  
697 53412 ▶sub assign() {
Subroutine assign: called CC=9 SCAR=22.3
Pod undocumented
698 53412 my($pos,@ret) = pos;
699 53412 ▶ @ret == push @ret, &or_expr and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &or_expr) and return 3217 50183 53400
700 50183 ▶ while(m@\G $s ((?>(?: [-*/%+&^|] | << | >>>? )?)=) $s @cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[\G $JE::Parser::s ((?>(?: [-*/%+&^|] | << | >>>? )?)=) $JE::Parser::s ]cgx) 1618 50182 51800
701 1618 push @ret, $1;
702 1618 ▶ @ret == push @ret, &or_expr and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &or_expr) and &expected("expression") 0 1617 1617
703 }
704 50182 ▶ if(/\G$s\?$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$JE::Parser::s\?$JE::Parser::s/cg) 48 50134 50182
705 48 ▶ @ret == push @ret, &assign and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &assign) and &expected("expression") 0 48 48
706 48 &skip;
707 48 ▶ /\G:$s/cg or expected "colon";
Branch: 1 branch
BranchTrueFalseTotal
/\G:$JE::Parser::s/cg or &expected("colon") 48 0 48
708 48 ▶ @ret == push @ret, &assign and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &assign) and &expected("expression") 0 48 48
709 }
710 50182 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'assign', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 48539 1643 50182
711 JECE;
712 }
713  
714 311 ▶sub assign_noin() {
Subroutine assign_noin: called CC=9 SCAR=22.3
Pod undocumented
715 311 my($pos,@ret) = pos;
716 311 ▶ @ret == push @ret, &or_noin and return;
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &or_noin) and return 8 303 311
717 303 ▶ while(m~\G $s ((?>(?: [-*/%+&^|] | << | >>>? )?)=) $s ~cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[\G $JE::Parser::s ((?>(?: [-*/%+&^|] | << | >>>? )?)=) $JE::Parser::s ]cgx) 224 303 527
718 224 push @ret, $1;
719 224 ▶ @ret == push @ret, &or_noin and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &or_noin) and &expected("expression") 0 224 224
720 }
721 303 ▶ if(/\G$s\?$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$JE::Parser::s\?$JE::Parser::s/cg) 6 297 303
722 6 ▶ @ret == push @ret, &assign and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &assign) and &expected("expression") 0 6 6
723 6 &skip;
724 6 ▶ /\G:$s/cg or expected "colon";
Branch: 1 branch
BranchTrueFalseTotal
/\G:$JE::Parser::s/cg or &expected("colon") 6 0 6
725 6 ▶ @ret == push @ret, &assign_noin and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &assign_noin) and &expected("expression") 0 6 6
726 }
727 303 ▶ @ret == 1 ? @ret : bless [[$pos, pos], 'assign', @ret],
Branch: 1 branch
BranchTrueFalseTotal
@ret == 1 ? : 77 226 303
728 JECE;
729 }
730  
731 11928 ▶sub expr() { # public
Subroutine expr: called CC=4 SCAR=13.9
Pod undocumented
732 11928 my $ret = bless [[pos], 'expr'], JECE;
733 11928 ▶ @$ret == push @$ret, &assign and return;
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &assign) and return 1664 10251 11915
734 10251 ▶ while(/\G$s,$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$JE::Parser::s,$JE::Parser::s/cg) 304 10251 10555
735 304 ▶ @$ret == push @$ret,& assign and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &assign) and &expected("expression") 0 304 304
736 }
737 10251 push @{$$ret[0]},pos;
738 10251 $ret;
739 }
740  
741 232 ▶sub expr_noin() { # public
Subroutine expr_noin: called CC=4 SCAR=13.9
Pod undocumented
742 232 my $ret = bless [[pos], 'expr'], JECE;
743 232 ▶ @$ret == push @$ret, &assign_noin and return;
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &assign_noin) and return 8 224 232
744 224 ▶ while(/\G$s,$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G$JE::Parser::s,$JE::Parser::s/cg) 22 224 246
745 22 ▶ @$ret == push @$ret, &assign_noin
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &assign_noin) and &expected("expression") 0 22 22
746 and expected 'expression';
747 }
748 224 push @{$$ret[0]},pos;
749 224 $ret;
750 }
751  
752 375 ▶sub vardecl() { # vardecl is only called when we *know* we need it, so it
Subroutine vardecl: called CC=4 SCAR=14.6
Pod undocumented
753 # will die when it can't get the first identifier, instead
754 # of returning undef
755 375 my @ret;
756 375 ▶ @ret == push @ret, &ident and expected 'identifier';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &ident) and &expected("identifier") 0 375 375
757 375 ▶ /\G$s=$s/cg and
Branch: 1 branch
BranchTrueFalseTotal
/\G$JE::Parser::s=$JE::Parser::s/cg and @ret != push(@ret, &assign) || &expected("expression") 294 81 375
Condition50%3/6
/\G$JE::Parser::s=$JE::Parser::s/cg && (@ret != push(@ret, &assign) || &expected('expression'))
!ll&&!rl&&r
812940
@ret != push(@ret, &assign) or &expected("expression")
l!l&&r!l&&!r
29400
MC/DC0%0/3
/\G$JE::Parser::s=$JE::Parser::s/cg && (@ret != push(@ret, &assign) || &expected('expression'))
/\G$JE::Parser::s=$JE::Parser::s/cg @ret != push(@ret, &assign) &expected("expression")
Truth table0%0/4
A && B or C
A= /\G$JE::Parser::s=$JE::Parser::s/cgB= @ret != push(@ret, &assign)C= &expected("expression")
ABCresult
0XX0
1000
11X1
1011
758 (@ret != push @ret, &assign or expected 'expression');
759 375 push @$_vars, $ret[0];
760 375 \@ret;
761 }
762  
763 113 ▶sub vardecl_noin() {
Subroutine vardecl_noin: called CC=4 SCAR=14.6
Pod undocumented
764 113 my @ret;
765 113 ▶ @ret == push @ret, &ident and expected 'identifier';
Branch: 1 branch
BranchTrueFalseTotal
@ret == push(@ret, &ident) and &expected("identifier") 0 113 113
766 113 ▶ /\G$s=$s/cg and
Branch: 1 branch
BranchTrueFalseTotal
/\G$JE::Parser::s=$JE::Parser::s/cg and @ret != push(@ret, &assign_noin) || &expected("expression") 51 62 113
Condition50%3/6
/\G$JE::Parser::s=$JE::Parser::s/cg && (@ret != push(@ret, &assign_noin) || &expected('expression'))
!ll&&!rl&&r
62510
@ret != push(@ret, &assign_noin) or &expected("expression")
l!l&&r!l&&!r
5100
MC/DC0%0/3
/\G$JE::Parser::s=$JE::Parser::s/cg && (@ret != push(@ret, &assign_noin) || &expected('expression'))
/\G$JE::Parser::s=$JE::Parser::s/cg @ret != push(@ret, &assign_noin) &expected("expression")
Truth table0%0/4
A && B or C
A= /\G$JE::Parser::s=$JE::Parser::s/cgB= @ret != push(@ret, &assign_noin)C= &expected("expression")
ABCresult
0XX0
1000
11X1
1011
767 (@ret != push @ret, &assign_noin or expected 'expression');
768 113 push @$_vars, $ret[0];
769 113 \@ret;
770 }
771  
772 291 ▶sub finish_for_sc_sc() { # returns the last two expressions of a for (;;)
Subroutine finish_for_sc_sc: called CC=5 SCAR=16.1
Pod undocumented
773 # loop header
774 291 my @ret;
775 my $msg;
776 291 ▶ if(@ret != push @ret, expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ret != push(@ret, &expr())) { } 250 41 291
777 250 $msg = '';
778 250 &skip
779 } else {
780 41 push @ret, 'empty';
781 41 $msg = 'expression or '
782 }
783 291 ▶ /\G;$s/cg or expected "${msg}semicolon";
Branch: 1 branch
BranchTrueFalseTotal
/\G;$JE::Parser::s/cg or &expected("${msg}semicolon") 291 0 291
784 291 ▶ if(@ret != push @ret, expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ret != push(@ret, &expr())) { } 190 101 291
785 190 $msg = '';
786 190 &skip
787 } else {
788 101 push @ret, 'empty';
789 101 $msg = 'expression or '
790 }
791 291 ▶ /\G\)$s/cg or expected "${msg}')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("${msg}')'") 291 0 291
792  
793 291 @ret;
794 }
795  
796 # ----------- Statement types ------------ #
797 # (used by custom parsers)
798  
799 101 our $optional_sc = # public
800 qr-\G (?:
801 $s (?: \z | ; $s | (?=\}) )
802 |
803  
804 # optional horizontal whitespace
805 # then a line terminator or a comment containing one
806 # then optional trailing whitespace
807 $h
808 (?: $n | //[^\cm\cj\x{2028}\x{2029}]* $n |
809 /\* [^*\cm\cj\x{2028}\x{2029}]*
810 (?: \*(?!/) [^*\cm\cj\x{2028}\x{2029}] )*
811 $n
812 (?s:.)*?
813 \*/
814 )
815 $s
816 )-x;
817  
818 9 ▶sub optional_sc() {
Subroutine optional_sc: called CC=2 SCAR=6.9
Pod undocumented
819 9 ▶ /$optional_sc/gc or expected "semicolon, '}' or end of line";
Branch: 1 branch
BranchTrueFalseTotal
/$JE::Parser::optional_sc/cg or &expected("semicolon, '}' or end of line") 5 4 9
820 }
821  
822 16 ▶sub block() {
Subroutine block: called CC=4 SCAR=26.7
Pod undocumented
823 16 ▶ /\G\{/gc or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G\{/cg or return 0 16 16
824 0 my $ret = [[pos()-1], 'statements'];
825 0 &skip;
826 0 while() { # 'last' does not work when 'while' is a
827 # statement modifier
828 0 ▶ @$ret == push @$ret, &statement and last;
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &statement) and last 0 0 0
829 }
830 0 ▶ expected "'}'" unless /\G\}$s/gc;
Branch: 1 branch
BranchTrueFalseTotal
unless /\G\}$JE::Parser::s/cg 0 0 0
831  
832 0 push @{$$ret[0]},pos;
833  
834 0 bless $ret, JECS;
835 }
836  
837 16 ▶sub empty() {
Subroutine empty: called CC=2 SCAR=8.1
Pod undocumented
838 16 my $pos = pos;
839 16 ▶ /\G;$s/cg or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G;$JE::Parser::s/cg or return 0 16 16
840 0 bless [[$pos,pos], 'empty'], JECS;
841 }
842  
843 7025 ▶sub function() {
Subroutine function: called CC=5 SCAR=16.2
Pod undocumented
844 7025 my $pos = pos;
845 7025 ▶ /\Gfunction$S/cg or return;
Branch: 1 branch
BranchTrueFalseTotal
/\Gfunction$JE::Parser::S/cg or return 132 6893 7025
846 132 my $ret = [[$pos], 'function'];
847 132 ▶ @$ret == push @$ret, &ident
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &ident) and &expected("identifier") 0 132 132
848 and expected "identifier";
849 132 &skip;
850 132 push @$ret, &params;
851 132 &skip;
852 132 ▶ /\G \{ /gcx or expected "'{'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \{ /cgx or &expected("'{'") 132 0 132
853 {
854 132 local $_vars = [];
855 132 push @$ret, &statements, $_vars;
856 }
857 132 ▶ /\G \}$s /gcx or expected "'}'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \}$JE::Parser::s /cgx or &expected("'}'") 132 0 132
858  
859 132 push @{$$ret[0]},pos;
860  
861 132 push @$_vars, $ret;
862  
863 132 bless $ret, JECS;
864 }
865  
866 16 ▶sub if() {
Subroutine if: called CC=7 SCAR=36.8
Pod undocumented
867 16 my $pos = pos;
868 16 ▶ /\Gif$s\($s/cg or return;
Branch: 1 branch
BranchTrueFalseTotal
/\Gif$JE::Parser::s\($JE::Parser::s/cg or return 0 16 16
869 0 my $ret = [[$pos], 'if'];
870  
871 0 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 0 0
872 and expected 'expression';
873 0 &skip;
874 0 ▶ /\G\)$s/gc or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 0 0 0
875 0 ▶ @$ret != push @$ret, &statement
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement) or &expected("statement") 0 0 0
876 or expected 'statement';
877 0 ▶ if (/\Gelse(?!$id_cont)$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\Gelse(?!$JE::Parser::id_cont)$JE::Parser::s/cg) 0 0 0
878 0 ▶ @$ret == push @$ret, &statement
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &statement) and &expected("statement") 0 0 0
879 and expected 'statement';
880 }
881  
882 0 push @{$$ret[0]},pos;
883  
884 0 bless $ret, JECS;
885 }
886  
887 0 ▶sub while() {
Subroutine while: not called CC=5 SCAR=34.0
Pod undocumented
888 0 my $pos = pos;
889 0 ▶ /\Gwhile$s\($s/cg or return;
Branch: 1 branch
BranchTrueFalseTotal
/\Gwhile$JE::Parser::s\($JE::Parser::s/cg or return 0 0 0
890 0 my $ret = [[$pos], 'while'];
891  
892 0 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 0 0
893 and expected 'expression';
894 0 &skip;
895 0 ▶ /\G\)$s/gc or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 0 0 0
896 0 ▶ @$ret != push @$ret, &statement
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement) or &expected("statement") 0 0 0
897 or expected 'statement';
898  
899 0 push @{$$ret[0]},pos;
900  
901 0 bless $ret, JECS;
902 }
903  
904 0 ▶sub for() {
Subroutine for: not called CC=18 SCAR=58.3
Pod documented
905 0 my $pos = pos;
906 0 ▶ /\Gfor$s\($s/cg or return;
Branch: 1 branch
BranchTrueFalseTotal
/\Gfor$JE::Parser::s\($JE::Parser::s/cg or return 0 0 0
907 0 my $ret = [[$pos], 'for'];
908  
909 0 ▶ if (/\G var$S/cgx) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\G var$JE::Parser::S/cgx) { } 0 0 0
elsif (@$ret != push(@$ret, &expr_noin)) { } 0 0 0
910 0 push @$ret, my $var = bless
911 [[pos() - length $1], 'var'],
912 'JE::Code::Statement';
913  
914 0 push @$var, &vardecl_noin;
915 0 &skip;
916 0 ▶ if (/\G([;,])$s/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G([;,])$JE::Parser::s/cg) { } 0 0 0
917 # if there's a comma or sc then
918 # this is a for(;;) loop
919 0 ▶ if ($1 eq ',') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq ",") 0 0 0
920 # finish getting the var
921 # decl list
922 0 ▶ do{
Branch: 1 branch
BranchTrueFalseTotal
/\G$JE::Parser::s,$JE::Parser::s/cg and do { do { @$var == push(@$var, &vardecl) and &expected("identifier") } } 0 0 0
923 0 ▶ @$var ==
Branch: 1 branch
BranchTrueFalseTotal
@$var == push(@$var, &vardecl) and &expected("identifier") 0 0 0
924 push @$var, &vardecl
925 and expected
926 'identifier'
927 } while (/\G$s,$s/gc);
928 0 &skip;
929 0 ▶ /\G;$s/cg
Branch: 1 branch
BranchTrueFalseTotal
/\G;$JE::Parser::s/cg or &expected("semicolon") 0 0 0
930 or expected 'semicolon';
931 }
932 0 push @$ret, &finish_for_sc_sc;
933 }
934 else {
935 0 ▶ /\Gin$s/cg or expected
Branch: 1 branch
BranchTrueFalseTotal
/\Gin$JE::Parser::s/cg or &expected("'in', comma or semicolon") 0 0 0
936 "'in', comma or semicolon";
937 0 push @$ret, 'in';
938 0 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expresssion") 0 0 0
939 and expected 'expresssion';
940 0 &skip;
941 0 ▶ /\G\)$s/cg or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 0 0 0
942 }
943 }
944 elsif(@$ret != push @$ret, &expr_noin) {
945 0 &skip;
946 0 ▶ if (/\G;$s/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G;$JE::Parser::s/cg) { } 0 0 0
947 # if there's a semicolon then
948 # this is a for(;;) loop
949 0 push @$ret, &finish_for_sc_sc;
950 }
951 else {
952 0 ▶ /\Gin$s/cg or expected
Branch: 1 branch
BranchTrueFalseTotal
/\Gin$JE::Parser::s/cg or &expected("'in' or semicolon") 0 0 0
953 "'in' or semicolon";
954 0 push @$ret, 'in';
955 0 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expresssion") 0 0 0
956 and expected 'expresssion';
957 0 &skip;
958 0 ▶ /\G\)$s/cg or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 0 0 0
959 }
960 }
961 else {
962 0 push @$ret, 'empty';
963 0 ▶ /\G;$s/cg
Branch: 1 branch
BranchTrueFalseTotal
/\G;$JE::Parser::s/cg or &expected("expression or semicolon") 0 0 0
964 or expected 'expression or semicolon';
965 0 push @$ret, &finish_for_sc_sc;
966 }
967  
968 # body of the for loop
969 0 ▶ @$ret != push @$ret, &statement
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement) or &expected("statement") 0 0 0
970 or expected 'statement';
971  
972 0 push @{$$ret[0]},pos;
973  
974 0 bless $ret, JECS;
975 }
976  
977 16 ▶sub with() { # almost identical to while
Subroutine with: called CC=5 SCAR=29.7
Pod undocumented
978 16 my $pos = pos;
979 16 ▶ /\Gwith$s\($s/cg or return;
Branch: 1 branch
BranchTrueFalseTotal
/\Gwith$JE::Parser::s\($JE::Parser::s/cg or return 0 16 16
980 0 my $ret = [[$pos], 'with'];
981  
982 0 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 0 0
983 and expected 'expression';
984 0 &skip;
985 0 ▶ /\G\)$s/gc or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 0 0 0
986 0 ▶ @$ret != push @$ret, &statement
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement) or &expected("statement") 0 0 0
987 or expected 'statement';
988  
989 0 push @{$$ret[0]},pos;
990  
991 0 bless $ret, JECS;
992 }
993  
994 16 ▶sub switch() {
Subroutine switch: called CC=15 SCAR=53.2
Pod undocumented
995 16 my $pos = pos;
996 16 ▶ /\Gswitch$s\($s/cg or return;
Branch: 1 branch
BranchTrueFalseTotal
/\Gswitch$JE::Parser::s\($JE::Parser::s/cg or return 0 16 16
997 0 my $ret = [[$pos], 'switch'];
998  
999 0 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 0 0
1000 and expected 'expression';
1001 0 &skip;
1002 0 ▶ /\G\)$s/gc or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 0 0 0
1003 0 ▶ /\G\{$s/gc or expected "'{'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\{$JE::Parser::s/cg or &expected("'{'") 0 0 0
1004  
1005 0 ▶ while (/\G case(?!$id_cont) $s/cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G case(?!$JE::Parser::id_cont) $JE::Parser::s/cgx) 0 0 0
1006 0 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 0 0
1007 and expected 'expression';
1008 0 &skip;
1009 0 ▶ /\G:$s/cg or expected 'colon';
Branch: 1 branch
BranchTrueFalseTotal
/\G:$JE::Parser::s/cg or &expected("colon") 0 0 0
1010 0 push @$ret, &statements;
1011 }
1012 0 my $default=0;
1013 0 ▶ if (/\G default(?!$id_cont) $s/cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G default(?!$JE::Parser::id_cont) $JE::Parser::s/cgx) 0 0 0
1014 0 ▶ /\G : $s /cgx or expected 'colon';
Branch: 1 branch
BranchTrueFalseTotal
/\G : $JE::Parser::s /cgx or &expected("colon") 0 0 0
1015 0 push @$ret, default => &statements;
1016 0 ++$default;
1017 }
1018 0 ▶ while (/\G case(?!$id_cont) $s/cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G case(?!$JE::Parser::id_cont) $JE::Parser::s/cgx) 0 0 0
1019 0 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 0 0
1020 and expected 'expression';
1021 0 &skip;
1022 0 ▶ /\G:$s/cg or expected 'colon';
Branch: 1 branch
BranchTrueFalseTotal
/\G:$JE::Parser::s/cg or &expected("colon") 0 0 0
1023 0 push @$ret, &statements;
1024 }
1025 0 ▶ /\G \} $s /cgx or expected (
Branch: 2 branches
BranchTrueFalseTotal
/\G \} $JE::Parser::s /cgx or &expected(scalar($default ? "'}' or 'case'" : "'}', 'case' or 'default'")) 0 0 0
$default ? : 0 0 0
1026 $default
1027 ? "'}' or 'case'"
1028 : "'}', 'case' or 'default'"
1029 );
1030  
1031 0 push @{$$ret[0]},pos;
1032  
1033 0 bless $ret, JECS;
1034 }
1035  
1036 16 ▶sub try() {
Subroutine try: called CC=13 SCAR=50.1
Pod undocumented
1037 16 my $pos = pos;
1038 16 ▶ /\Gtry$s\{$s/cg or return;
Branch: 1 branch
BranchTrueFalseTotal
/\Gtry$JE::Parser::s\{$JE::Parser::s/cg or return 0 16 16
1039 0 my $ret = [[$pos], 'try', &statements];
1040  
1041 0 ▶ /\G \} $s /cgx or expected "'}'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \} $JE::Parser::s /cgx or &expected("'}'") 0 0 0
1042  
1043 0 $pos = pos;
1044  
1045 0 ▶ if(/\Gcatch$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\Gcatch$JE::Parser::s/cg) 0 0 0
1046 0 ▶ /\G \( $s /cgx or expected "'('";
Branch: 1 branch
BranchTrueFalseTotal
/\G \( $JE::Parser::s /cgx or &expected("'('") 0 0 0
1047 0 ▶ @$ret == push @$ret, &ident
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &ident) and &expected("identifier") 0 0 0
1048 and expected 'identifier';
1049 0 &skip;
1050 0 ▶ /\G \) $s /cgx or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \) $JE::Parser::s /cgx or &expected("')'") 0 0 0
1051  
1052 0 ▶ /\G \{ $s /cgx or expected "'{'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \{ $JE::Parser::s /cgx or &expected("'{'") 0 0 0
1053 0 push @$ret, &statements;
1054 0 ▶ /\G \} $s /cgx or expected "'}'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \} $JE::Parser::s /cgx or &expected("'}'") 0 0 0
1055 }
1056 0 ▶ if(/\Gfinally$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\Gfinally$JE::Parser::s/cg) 0 0 0
1057 0 ▶ /\G \{ $s /cgx or expected "'{'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \{ $JE::Parser::s /cgx or &expected("'{'") 0 0 0
1058 0 push @$ret, &statements;
1059 0 ▶ /\G \} $s /cgx or expected "'}'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \} $JE::Parser::s /cgx or &expected("'}'") 0 0 0
1060 }
1061  
1062 0 ▶ pos eq $pos and expected "'catch' or 'finally'";
Branch: 1 branch
BranchTrueFalseTotal
pos $_ eq $pos and &expected("'catch' or 'finally'") 0 0 0
1063  
1064 0 push @{$$ret[0]},pos;
1065  
1066 0 bless $ret, JECS;
1067 }
1068  
1069 16 ▶sub labelled() {
Subroutine labelled: called CC=4 SCAR=25.0
Pod undocumented
1070 16 my $pos = pos;
1071 16 ▶ /\G ($ident) $s : $s/cgx or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G ($JE::Parser::ident) $JE::Parser::s : $JE::Parser::s/cgx or return 0 16 16
1072 0 my $ret = [[$pos], 'labelled', unescape_ident $1];
1073  
1074 0 ▶ while (/\G($ident)$s:$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G($JE::Parser::ident)$JE::Parser::s:$JE::Parser::s/cg) 0 0 0
1075 0 push @$ret, unescape_ident $1;
1076 }
1077 0 ▶ @$ret != push @$ret, &statement
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement) or &expected("statement") 0 0 0
1078 or expected 'statement';
1079  
1080 0 push @{$$ret[0]},pos;
1081  
1082 0 bless $ret, JECS;
1083 }
1084  
1085 16 ▶sub var() {
Subroutine var: called CC=3 SCAR=19.6
Pod undocumented
1086 16 my $pos = pos;
1087 16 ▶ /\G var $S/cgx or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G var $JE::Parser::S/cgx or return 0 16 16
1088 0 my $ret = [[$pos], 'var'];
1089  
1090 0 ▶ do{
Branch: 1 branch
BranchTrueFalseTotal
/\G$JE::Parser::s,$JE::Parser::s/cg and do { do { push @$ret, &vardecl } } 0 0 0
1091 0 push @$ret, &vardecl;
1092 } while(/\G$s,$s/gc);
1093  
1094 0 optional_sc;
1095  
1096 0 push @{$$ret[0]},pos;
1097  
1098 0 bless $ret, JECS;
1099 }
1100  
1101 0 ▶sub do() {
Subroutine do: not called CC=7 SCAR=40.3
Pod undocumented
1102 0 my $pos = pos;
1103 0 ▶ /\G do(?!$id_cont)$s/cgx or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G do(?!$JE::Parser::id_cont)$JE::Parser::s/cgx or return 0 0 0
1104 0 my $ret = [[$pos], 'do'];
1105  
1106 0 ▶ @$ret != push @$ret, &statement
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement) or &expected("statement") 0 0 0
1107 or expected 'statement';
1108 0 ▶ /\Gwhile$s/cg or expected "'while'";
Branch: 1 branch
BranchTrueFalseTotal
/\Gwhile$JE::Parser::s/cg or &expected("'while'") 0 0 0
1109 0 ▶ /\G\($s/cg or expected "'('";
Branch: 1 branch
BranchTrueFalseTotal
/\G\($JE::Parser::s/cg or &expected("'('") 0 0 0
1110 0 ▶ @$ret != push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &expr) or &expected("expression") 0 0 0
1111 or expected 'expression';
1112 0 &skip;
1113 0 ▶ /\G\)/cog or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)/cog or &expected("')'") 0 0 0
1114  
1115 0 optional_sc;
1116  
1117 0 push @{$$ret[0]},pos;
1118  
1119 0 bless $ret, JECS;
1120 }
1121  
1122 16 ▶sub continue() {
Subroutine continue: called CC=3 SCAR=19.2
Pod undocumented
1123 16 my $pos = pos;
1124 16 ▶ /\G continue(?!$id_cont)/cogx or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G continue(?!$JE::Parser::id_cont)/cgox or return 0 16 16
1125 0 my $ret = [[$pos], 'continue'];
1126  
1127 0 ▶ /\G$h($ident)/cog
Branch: 1 branch
BranchTrueFalseTotal
/\G$JE::Parser::h($JE::Parser::ident)/cog and push @$ret, &unescape_ident($1) 0 0 0
1128 and push @$ret, unescape_ident $1;
1129  
1130 0 optional_sc;
1131  
1132 0 push @{$$ret[0]},pos;
1133  
1134 0 bless $ret, JECS;
1135 }
1136  
1137 16 ▶sub break() { # almost identical to continue
Subroutine break: called CC=3 SCAR=19.2
Pod undocumented
1138 16 my $pos = pos;
1139 16 ▶ /\G break(?!$id_cont)/cogx or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G break(?!$JE::Parser::id_cont)/cgox or return 0 16 16
1140 0 my $ret = [[$pos], 'break'];
1141  
1142 0 ▶ /\G$h($ident)/cog
Branch: 1 branch
BranchTrueFalseTotal
/\G$JE::Parser::h($JE::Parser::ident)/cog and push @$ret, &unescape_ident($1) 0 0 0
1143 and push @$ret, unescape_ident $1;
1144  
1145 0 optional_sc;
1146  
1147 0 push @{$$ret[0]},pos;
1148  
1149 0 bless $ret, JECS;
1150 }
1151  
1152 16 ▶sub return() {
Subroutine return: called CC=3 SCAR=20.0
Pod undocumented
1153 16 my $pos = pos;
1154 16 ▶ /\G return(?!$id_cont)/cogx or return;
Branch: 1 branch
BranchTrueFalseTotal
/\G return(?!$JE::Parser::id_cont)/cgox or return 0 16 16
1155 0 my $ret = [[$pos], 'return'];
1156  
1157 0 $pos = pos;
1158 0 /\G$h/g; # skip horz ws
1159 0 ▶ @$ret == push @$ret, &expr and pos = $pos;
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and pos $_ = $pos 0 0 0
1160 # reverse to before the white space if
1161 # there is no expr
1162  
1163 0 optional_sc;
1164  
1165 0 push @{$$ret[0]},pos;
1166  
1167 0 bless $ret, JECS;
1168 }
1169  
1170 16 ▶sub throw() {
Subroutine throw: called CC=3 SCAR=19.6
Pod undocumented
1171 16 my $pos = pos;
1172 16 ▶ /\G throw(?!$id_cont)/cogx
Branch: 1 branch
BranchTrueFalseTotal
/\G throw(?!$JE::Parser::id_cont)/cgox or return 0 16 16
1173 or return;
1174 0 my $ret = [[$pos], 'throw'];
1175  
1176 0 /\G$h/g; # skip horz ws
1177 0 ▶ @$ret == push @$ret, &expr and expected 'expression';
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 0 0
1178  
1179 0 optional_sc;
1180  
1181 0 push @{$$ret[0]},pos;
1182  
1183 0 bless $ret, JECS;
1184 }
1185  
1186 16 ▶sub expr_statement() {
Subroutine expr_statement: called CC=2 SCAR=6.9
Pod undocumented
1187 16 ▶ my $ret = &expr or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ret = &expr or return 9 5 14
1188 9 optional_sc; # the only difference in behaviour between
1189 # this and &expr
1190 5 $ret;
1191 }
1192  
1193  
1194  
1195 # -------- end of statement types----------#
1196  
1197 # This takes care of trailing white space.
1198 10883 ▶sub statement_default() {
Subroutine statement_default: called CC=87 SCAR=47.9
Pod undocumented
1199 10883 my $ret = [[pos]];
1200  
1201 # Statements that do not have an optional semicolon
1202 10883 ▶ if (/\G (?:
Branch: 1 branch
BranchTrueFalseTotal
if (/\G (?: ( \{ | ; ) | (function)$JE::Parser::S | ( if | w(?:hile|ith) | for | switch ) $JE::Parser::s \( $JE::Parser::s | ( try $JE::Parser::s \{ $JE::Parser::s ) | ($JE::Parser::ident) $JE::Parser::s : $JE::Parser::s ) /cgx) { } 1189 9694 10883
1203 ( \{ | ; )
1204 |
1205 (function)$S
1206 |
1207 ( if | w(?:hile|ith) | for | switch ) $s \( $s
1208 |
1209 ( try $s \{ $s )
1210 |
1211 ($ident) $s : $s
1212 ) /xgc) {
1213 101 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1214 1189 ▶ if($1 eq '{') {
Branch: 9 branches
BranchTrueFalseTotal
if ($1 eq '{') { } 166 1023 1189
elsif ($1 eq ';') { } 144 879 1023
elsif ($2) { } 34 845 879
elsif ($3 eq 'if') { } 78 767 845
elsif ($3 eq 'while') { } 17 750 767
elsif ($3 eq 'for') { } 345 405 750
elsif ($3 eq 'with') { } 18 387 405
elsif ($3 eq 'switch') { } 33 354 387
elsif ($4) { } 316 38 354
1215 166 push @$ret, 'statements';
1216 166 &skip;
1217 166 while() { # 'last' does not work when 'while' is a
1218 # statement modifier
1219 509 ▶ @$ret == push @$ret,
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &statement_default) and last 165 343 508
1220 &statement_default and last;
1221 }
1222
1223 165 ▶ expected "'}'" unless /\G\}$s/gc;
Branch: 1 branch
BranchTrueFalseTotal
unless /\G\}$JE::Parser::s/cg 0 165 165
1224 }
1225 elsif($1 eq ';') {
1226 144 push @$ret, 'empty';
1227 144 &skip;
1228 }
1229 elsif($2) {
1230 34 push @$ret, 'function';
1231 34 ▶ @$ret == push @$ret, &ident
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &ident) and &expected("identifier") 0 34 34
1232 and expected "identifier";
1233 34 &skip;
1234 34 push @$ret, &params;
1235 34 &skip;
1236 34 ▶ /\G \{ /gcx or expected "'{'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \{ /cgx or &expected("'{'") 34 0 34
1237 {
1238 34 local $_vars = [];
1239 34 push @$ret, &statements, $_vars;
1240 }
1241 34 ▶ /\G \}$s /gcx or expected "'}'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \}$JE::Parser::s /cgx or &expected("'}'") 34 0 34
1242 34 push @$_vars, $ret;
1243 }
1244 elsif($3 eq 'if') {
1245 78 push @$ret, 'if';
1246 78 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 78 78
1247 and expected 'expression';
1248 78 &skip;
1249 78 ▶ /\G\)$s/gc or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 78 0 78
1250 78 ▶ @$ret != push @$ret, &statement_default
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement_default) or &expected("statement") 78 0 78
1251 or expected 'statement';
1252 78 ▶ if (/\Gelse(?!$id_cont)$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\Gelse(?!$JE::Parser::id_cont)$JE::Parser::s/cg) 23 55 78
1253 23 ▶ @$ret == push @$ret,
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &statement_default) and &expected("statement") 0 23 23
1254 &statement_default
1255 and expected 'statement';
1256 }
1257 }
1258 elsif($3 eq 'while') {
1259 17 push @$ret, 'while';
1260 17 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 17 17
1261 and expected 'expression';
1262 17 &skip;
1263 17 ▶ /\G\)$s/gc or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 17 0 17
1264 17 ▶ @$ret != push @$ret, &statement_default
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement_default) or &expected("statement") 17 0 17
1265 or expected 'statement';
1266 }
1267 elsif($3 eq 'for') {
1268 345 push @$ret, 'for';
1269 345 ▶ if (/\G var$S/cgx) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\G var$JE::Parser::S/cgx) { } 113 232 345
elsif (@$ret != push(@$ret, &expr_noin)) { } 224 8 232
1270 113 push @$ret, my $var = bless
1271 [[pos() - length $1], 'var'],
1272 'JE::Code::Statement';
1273  
1274 113 push @$var, &vardecl_noin;
1275 113 &skip;
1276 113 ▶ if (/\G([;,])$s/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G([;,])$JE::Parser::s/cg) { } 80 33 113
1277 # if there's a comma or sc then
1278 # this is a for(;;) loop
1279 80 ▶ if ($1 eq ',') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq ",") 34 46 80
1280 # finish getting the var
1281 # decl list
1282 34 ▶ do{
Branch: 1 branch
BranchTrueFalseTotal
/\G$JE::Parser::s,$JE::Parser::s/cg and do { do { @$var == push(@$var, &vardecl) and &expected("identifier") } } 0 34 34
1283 34 ▶ @$var ==
Branch: 1 branch
BranchTrueFalseTotal
@$var == push(@$var, &vardecl) and &expected("identifier") 0 34 34
1284 push @$var, &vardecl
1285 and expected
1286 'identifier'
1287 } while (/\G$s,$s/gc);
1288 34 &skip;
1289 34 ▶ /\G;$s/cg
Branch: 1 branch
BranchTrueFalseTotal
/\G;$JE::Parser::s/cg or &expected("semicolon") 34 0 34
1290 or expected 'semicolon';
1291 }
1292 80 push @$ret, &finish_for_sc_sc;
1293 }
1294 else {
1295 33 ▶ /\Gin$s/cg or expected
Branch: 1 branch
BranchTrueFalseTotal
/\Gin$JE::Parser::s/cg or &expected("'in', comma or semicolon") 33 0 33
1296 "'in', comma or semicolon";
1297 33 push @$ret, 'in';
1298 33 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expresssion") 0 33 33
1299 and expected 'expresssion';
1300 33 &skip;
1301 33 ▶ /\G\)$s/cg or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 33 0 33
1302 }
1303 }
1304 elsif(@$ret != push @$ret, &expr_noin) {
1305 224 &skip;
1306 224 ▶ if (/\G;$s/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G;$JE::Parser::s/cg) { } 203 21 224
1307 # if there's a semicolon then
1308 # this is a for(;;) loop
1309 203 push @$ret, &finish_for_sc_sc;
1310 }
1311 else {
1312 21 ▶ /\Gin$s/cg or expected
Branch: 1 branch
BranchTrueFalseTotal
/\Gin$JE::Parser::s/cg or &expected("'in' or semicolon") 21 0 21
1313 "'in' or semicolon";
1314 21 push @$ret, 'in';
1315 21 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expresssion") 0 21 21
1316 and expected 'expresssion';
1317 21 &skip;
1318 21 ▶ /\G\)$s/cg or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 21 0 21
1319 }
1320 }
1321 else {
1322 8 push @$ret, 'empty';
1323 8 ▶ /\G;$s/cg
Branch: 1 branch
BranchTrueFalseTotal
/\G;$JE::Parser::s/cg or &expected("expression or semicolon") 8 0 8
1324 or expected 'expression or semicolon';
1325 8 push @$ret, &finish_for_sc_sc;
1326 }
1327  
1328 # body of the for loop
1329 345 ▶ @$ret != push @$ret, &statement_default
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement_default) or &expected("statement") 345 0 345
1330 or expected 'statement';
1331 }
1332 elsif($3 eq 'with') {
1333 18 push @$ret, 'with';
1334 18 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 18 18
1335 and expected 'expression';
1336 18 &skip;
1337 18 ▶ /\G\)$s/gc or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 18 0 18
1338 18 ▶ @$ret != push @$ret, &statement_default
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement_default) or &expected("statement") 18 0 18
1339 or expected 'statement';
1340 }
1341 elsif($3 eq 'switch') {
1342 33 push @$ret, 'switch';
1343 33 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 33 33
1344 and expected 'expression';
1345 33 &skip;
1346 33 ▶ /\G\)$s/gc or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)$JE::Parser::s/cg or &expected("')'") 33 0 33
1347 33 ▶ /\G\{$s/gc or expected "'{'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\{$JE::Parser::s/cg or &expected("'{'") 33 0 33
1348  
1349 33 ▶ while (/\G case(?!$id_cont) $s/cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G case(?!$JE::Parser::id_cont) $JE::Parser::s/cgx) 31 33 64
1350 31 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 31 31
1351 and expected 'expression';
1352 31 &skip;
1353 31 ▶ /\G:$s/cg or expected 'colon';
Branch: 1 branch
BranchTrueFalseTotal
/\G:$JE::Parser::s/cg or &expected("colon") 31 0 31
1354 31 push @$ret, &statements;
1355 }
1356 33 my $default=0;
1357 33 ▶ if (/\G default(?!$id_cont) $s/cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G default(?!$JE::Parser::id_cont) $JE::Parser::s/cgx) 20 13 33
1358 20 ▶ /\G : $s /cgx or expected 'colon';
Branch: 1 branch
BranchTrueFalseTotal
/\G : $JE::Parser::s /cgx or &expected("colon") 20 0 20
1359 20 push @$ret, default => &statements;
1360 20 ++$default;
1361 }
1362 33 ▶ while (/\G case(?!$id_cont) $s/cgx) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G case(?!$JE::Parser::id_cont) $JE::Parser::s/cgx) 19 33 52
1363 19 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 0 19 19
1364 and expected 'expression';
1365 19 &skip;
1366 19 ▶ /\G:$s/cg or expected 'colon';
Branch: 1 branch
BranchTrueFalseTotal
/\G:$JE::Parser::s/cg or &expected("colon") 19 0 19
1367 19 push @$ret, &statements;
1368 }
1369 33 ▶ /\G \} $s /cgx or expected (
Branch: 2 branches
BranchTrueFalseTotal
/\G \} $JE::Parser::s /cgx or &expected(scalar($default ? "'}' or 'case'" : "'}', 'case' or 'default'")) 33 0 33
$default ? : 0 0 0
1370 $default
1371 ? "'}' or 'case'"
1372 : "'}', 'case' or 'default'"
1373 );
1374 }
1375 elsif($4) { # try
1376 316 push @$ret, 'try', &statements;
1377 316 ▶ /\G \} $s /cgx or expected "'}'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \} $JE::Parser::s /cgx or &expected("'}'") 316 0 316
1378  
1379 316 my $pos = pos;
1380  
1381 316 ▶ if(/\Gcatch$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\Gcatch$JE::Parser::s/cg) 314 2 316
1382 314 ▶ /\G \( $s /cgx or expected "'('";
Branch: 1 branch
BranchTrueFalseTotal
/\G \( $JE::Parser::s /cgx or &expected("'('") 314 0 314
1383 314 ▶ @$ret == push @$ret, &ident
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &ident) and &expected("identifier") 0 314 314
1384 and expected 'identifier';
1385 314 &skip;
1386 314 ▶ /\G \) $s /cgx or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \) $JE::Parser::s /cgx or &expected("')'") 314 0 314
1387  
1388 314 ▶ /\G \{ $s /cgx or expected "'{'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \{ $JE::Parser::s /cgx or &expected("'{'") 314 0 314
1389 314 push @$ret, &statements;
1390 314 ▶ /\G \} $s /cgx or expected "'}'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \} $JE::Parser::s /cgx or &expected("'}'") 314 0 314
1391 }
1392 316 ▶ if(/\Gfinally$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\Gfinally$JE::Parser::s/cg) 7 309 316
1393 7 ▶ /\G \{ $s /cgx or expected "'{'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \{ $JE::Parser::s /cgx or &expected("'{'") 7 0 7
1394 7 push @$ret, &statements;
1395 7 ▶ /\G \} $s /cgx or expected "'}'";
Branch: 1 branch
BranchTrueFalseTotal
/\G \} $JE::Parser::s /cgx or &expected("'}'") 7 0 7
1396 }
1397  
1398 316 ▶ pos eq $pos and expected "'catch' or 'finally'";
Branch: 1 branch
BranchTrueFalseTotal
pos $_ eq $pos and &expected("'catch' or 'finally'") 0 316 316
1399 }
1400 else { # labelled statement
1401 38 push @$ret, 'labelled', unescape_ident $5;
1402 38 ▶ while (/\G($ident)$s:$s/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\G($JE::Parser::ident)$JE::Parser::s:$JE::Parser::s/cg) 21 38 59
1403 21 push @$ret, unescape_ident $1;
1404 }
1405 38 ▶ @$ret != push @$ret, &statement_default
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement_default) or &expected("statement") 38 0 38
1406 or expected 'statement';
1407 }
1408 }
1409 # Statements that do have an optional semicolon
1410 else {
1411 9694 ▶ if (/\G var$S/xcg) {
Branch: 5 branches
BranchTrueFalseTotal
if (/\G var$JE::Parser::S/cgx) { } 329 9365 9694
elsif (/\Gdo(?!$JE::Parser::id_cont)$JE::Parser::s/cg) { } 25 9340 9365
elsif (/\G(continue|break)(?!$JE::Parser::id_cont)/cog) { } 109 9231 9340
elsif (/\Greturn(?!$JE::Parser::id_cont)/cog) { } 135 9096 9231
elsif (/\Gthrow(?!$JE::Parser::id_cont)/cog) { } 23 9073 9096
1412 329 push @$ret, 'var';
1413  
1414 329 ▶ do{
Branch: 1 branch
BranchTrueFalseTotal
/\G$JE::Parser::s,$JE::Parser::s/cg and do { do { push @$ret, &vardecl } } 12 329 341
1415 341 push @$ret, &vardecl;
1416 } while(/\G$s,$s/gc);
1417 }
1418 elsif(/\Gdo(?!$id_cont)$s/cg) {
1419 25 push @$ret, 'do';
1420 25 ▶ @$ret != push @$ret, &statement_default
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement_default) or &expected("statement") 25 0 25
1421 or expected 'statement';
1422 25 ▶ /\Gwhile$s/cg or expected "'while'";
Branch: 1 branch
BranchTrueFalseTotal
/\Gwhile$JE::Parser::s/cg or &expected("'while'") 25 0 25
1423 25 ▶ /\G\($s/cg or expected "'('";
Branch: 1 branch
BranchTrueFalseTotal
/\G\($JE::Parser::s/cg or &expected("'('") 25 0 25
1424 25 ▶ @$ret != push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &expr) or &expected("expression") 25 0 25
1425 or expected 'expression';
1426 25 &skip;
1427 25 ▶ /\G\)/cog or expected "')'";
Branch: 1 branch
BranchTrueFalseTotal
/\G\)/cog or &expected("')'") 25 0 25
1428 }
1429 elsif(/\G(continue|break)(?!$id_cont)/cog) {
1430 109 push @$ret, $1;
1431 109 ▶ /\G$h($ident)/cog
Branch: 1 branch
BranchTrueFalseTotal
/\G$JE::Parser::h($JE::Parser::ident)/cog and push @$ret, &unescape_ident($1) 30 79 109
1432 and push @$ret, unescape_ident $1;
1433 }
1434 elsif(/\Greturn(?!$id_cont)/cog) {
1435 135 push @$ret, 'return';
1436 135 my $pos = pos;
1437 135 /\G$h/g; # skip horz ws
1438 135 ▶ @$ret == push @$ret, &expr and pos = $pos;
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and pos $_ = $pos 3 132 135
1439 # reverse to before the white space if
1440 # there is no expr
1441 }
1442 elsif(/\Gthrow(?!$id_cont)/cog) {
1443 23 push @$ret, 'throw';
1444 23 /\G$h/g; # skip horz ws
1445 23 ▶ @$ret == push @$ret, &expr
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &expr) and &expected("expression") 1 22 23
1446 and expected 'expression';
1447 }
1448 else { # expression statement
1449 9073 ▶ $ret = &expr or return;
Branch: 1 branch
BranchTrueFalseTotal
$ret = &expr or return 7549 1513 9062
1450 }
1451  
1452 # Check for optional semicolon
1453 8169 ▶ m-$optional_sc-cgx
Branch: 1 branch
BranchTrueFalseTotal
/$JE::Parser::optional_sc/cgx or &expected("semicolon, '}' or end of line") 8166 3 8169
1454 or expected "semicolon, '}' or end of line";
1455 }
1456 9354 ▶ push @{$$ret[0]},pos unless @{$$ret[0]} == 2; # an expr will
Branch: 1 branch
BranchTrueFalseTotal
unless @{$ret->[0];} == 2 1808 7546 9354
1457 # already have this
1458  
1459 9354 ▶ ref $ret eq 'ARRAY' and bless $ret, 'JE::Code::Statement';
Branch: 1 branch
BranchTrueFalseTotal
ref $ret eq "ARRAY" and bless $ret, "JE::Code::Statement" 1808 7546 9354
1460  
1461 9354 return $ret;
1462 }
1463  
1464 16 ▶sub statement() { # public
Subroutine statement: called CC=4 SCAR=13.9
Pod undocumented
1465 16 my $ret;
1466 16 for my $sub(@_stms) {
1467 208 ▶ defined($ret = &$sub)
Branch: 1 branch
BranchTrueFalseTotal
defined($ret = &$sub) and last 5 197 202
1468 and last;
1469 }
1470 10 ▶ defined $ret ? $ret : ()
Branch: 1 branch
BranchTrueFalseTotal
defined $ret ? : 5 5 10
1471 }
1472  
1473 # This takes care of leading white space.
1474 1036 ▶sub statements() {
Subroutine statements: called CC=3 SCAR=11.0
Pod undocumented
1475 1036 my $ret = bless [[pos], 'statements'], 'JE::Code::Statement';
1476 1036 /\G$s/g; # skip initial whitespace
1477 1036 while () { # 'last' does not work when 'while' is a
1478 # statement modifier
1479 2937 ▶ @$ret != push @$ret,
Branch: 2 branches
BranchTrueFalseTotal
@$ret != push(@$ret, $JE::Parser::_parser ? &statement : &statement_default) or last 1901 1036 2937
$JE::Parser::_parser ? : 0 2937 2937
1480 $_parser ? &statement : &statement_default
1481 or last;
1482 }
1483 1036 push @{$$ret[0]},pos;
1484 1036 return $ret;
1485 }
1486  
1487 338 ▶sub program() { # like statements(), but it allows function declarations
Subroutine program: called CC=7 SCAR=19.6
Pod undocumented
1488 # as well
1489 338 my $ret = bless [[pos], 'statements'], 'JE::Code::Statement';
1490 338 /\G$s/g; # skip initial whitespace
1491 338 ▶ if($_parser) {
Branch: 1 branch
BranchTrueFalseTotal
if ($JE::Parser::_parser) { } 11 327 338
1492 11 while () {
1493 DECL: {
1494 16 for my $sub(@_decls) {
1495 0 ▶ @$ret != push @$ret, &$sub
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &$sub) and redo DECL 0 0 0
1496 and redo DECL;
1497 }
1498 }
1499 16 ▶ @$ret != push @$ret, &statement or last;
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement) or last 5 5 10
1500 }
1501 }
1502 else {
1503 327 while () {
1504 6893 while() {
1505 7025 ▶ @$ret == push @$ret, &function and last;
Branch: 1 branch
BranchTrueFalseTotal
@$ret == push(@$ret, &function) and last 6893 132 7025
1506 }
1507 6893 ▶ @$ret != push @$ret, &statement_default or last;
Branch: 1 branch
BranchTrueFalseTotal
@$ret != push(@$ret, &statement_default) or last 6566 312 6878
1508 }
1509 }
1510 317 push @{$$ret[0]},pos;
1511 317 return $ret;
1512 }
1513  
1514  
1515 # ~~~ The second arg to add_line_number is a bit ridiculous. I may change
1516 # add_line_number's parameter list, perhaps so it accepts either a
1517 # code object, or (src,file,line) if $_[1] isn'ta JE::Code. I don't
1518 # know....
1519 373 ▶sub _parse($$$;$$) { # Returns just the parse tree, not a JE::Code object.
Subroutine _parse: called CC=18 SCAR=29.5
1520 # Actually, it returns the source followed by the
1521 # parse tree in list context, or just the parse tree
1522 # in scalar context.
1523 373 my ($rule, $src, $my_global, $file, $line) = @_;
1524 373 local our($_source, $_file, $_line) =($src,$file,$line);
1525  
1526 # Note: We *hafta* stringify the $src, because it could be an
1527 # object with overloading (e.g., JE::String) and we
1528 # need to rely on its pos(), which simply cannot be
1529 # done with an object. Furthermore, perl5.8.5 is
1530 # a bit buggy and sometimes mangles the contents
1531 # of $1 when one does $obj =~ /(...)/.
1532 373 ▶ $src = defined blessed $src && $src->isa("JE::String")
Branch: 1 branch
BranchTrueFalseTotal
defined builtin::blessed($src) && $src->isa('JE::String') ? : 104 269 373
Condition100%3/3
defined builtin::blessed($src) and $src->isa("JE::String")
!ll&&!rl&&r
25712104
MC/DC100%2/2
defined builtin::blessed($src) and $src->isa("JE::String")
defined builtin::blessed($src) $src->isa("JE::String")
Truth table100%3/3
A and B
A= defined builtin::blessed($src)B= $src->isa("JE::String")
ABresult
0X0
100
111
1533 ? $src->value16
1534 : surrogify("$src");
1535  
1536 # remove unicode format chrs
1537 373 $src =~ s/\p{Cf}//g;
1538  
1539 # In HTML mode, modify the whitespace regexps to remove HTML com-
1540 # ment delimiters and following junk up to the end of the line.
1541 373 ▶ $my_global->html_mode and
Branch: 1 branch
BranchTrueFalseTotal
$my_global->html_mode and local $JE::Parser::s = qr"(?> (?> [ \t\x0b\f\xa0\p{Zs}]* ) (?> (?> $JE::Parser::n (?>(?: (?>[ \t\x0b\f\xa0\p{Zs}]*) --> (?>[^\cm\cj\x{2028}\x{2029}]*)(?>$JE::Parser::n|\z) )?) | ^ (?>[ \t\x0b\f\xa0\p{Zs}]*) --> (?>[^\cm\cj\x{2028}\x{2029}]*)(?>$JE::Parser::n|\z) | (?>//|<!--)(?>[^\cm\cj\x{2028}\x{2029}]*)(?>$JE::Parser::n|\z) | /\*.*?\*/ ) (?> [ \t\x0b\f\xa0\p{Zs}]* ) ) * )"sx, local $JE::Parser::S = qr" (?> $JE::Parser::ss | (?>//|<!--)[^\cm\cj\x{2028}\x{2029}]* | /\*.*?\*/ ) $JE::Parser::s "sx, local $JE::Parser::optional_sc = qr"\G (?: $JE::Parser::s (?: \z | ; $JE::Parser::s | (?=\}) ) | # optional horizontal whitespace # then a line terminator or a comment containing one # then optional trailing whitespace $JE::Parser::h (?: $JE::Parser::n | (?>//|<!--)[^\cm\cj\x{2028}\x{2029}]* $JE::Parser::n | /\* [^*\cm\cj\x{2028}\x{2029}]* (?: \*(?!/) [^*\cm\cj\x{2028}\x{2029}] )* $JE::Parser::n (?s:.)*? \*/ ) $JE::Parser::s )"x 12 361 373
1542 local $s = qr((?>
1543 (?> [ \t\x0b\f\xa0\p{Zs}]* )
1544 (?> (?>
1545 $n
1546 (?>(?:
1547 (?>[ \t\x0b\f\xa0\p{Zs}]*) -->
1548 (?>[^\cm\cj\x{2028}\x{2029}]*)(?>$n|\z)
1549 )?)
1550 |
1551 ^
1552 (?>[ \t\x0b\f\xa0\p{Zs}]*) -->
1553 (?>[^\cm\cj\x{2028}\x{2029}]*)(?>$n|\z)
1554 |
1555 (?>//|<!--)(?>[^\cm\cj\x{2028}\x{2029}]*)(?>$n|\z)
1556 |
1557 /\*.*?\*/
1558 )
1559 (?> [ \t\x0b\f\xa0\p{Zs}]* )
1560 ) *
1561 ))sx,
1562 local $S = qr(
1563 (?>
1564 $ss
1565 |
1566 (?>//|<!--)[^\cm\cj\x{2028}\x{2029}]*
1567 |
1568 /\*.*?\*/
1569 )
1570 $s
1571 )xs,
1572 local $optional_sc = qr _\G (?:
1573 $s (?: \z | ; $s | (?=\}) )
1574 |
1575 # optional horizontal whitespace
1576 # then a line terminator or a comment containing one
1577 # then optional trailing whitespace
1578 $h
1579 (?:
1580 $n
1581 |
1582 (?>//|<!--)[^\cm\cj\x{2028}\x{2029}]* $n
1583 |
1584 /\* [^*\cm\cj\x{2028}\x{2029}]*
1585 (?: \*(?!/) [^*\cm\cj\x{2028}\x{2029}] )*
1586 $n
1587 (?s:.)*?
1588 \*/
1589 )
1590 $s
1591 )_x;
1592  
1593 373 my $tree;
1594 373 local $_vars = [];
1595 $rule eq 'program' and !$_parser
1596 and ($ENV{'YES_I_WANT_JE_TO_OPTIMISE'}||'') eq 2
1597 0 ▶ and do { require 'JE/parsetoperl.pl', $rule = \&ptp_program };
Branch: 1 branch
BranchTrueFalseTotal
$rule eq "program" and not $JE::Parser::_parser and ($ENV{"YES_I_WANT_JE_TO_OPTIMISE"} || "") eq 2 and do { require "JE/parsetoperl.pl", $rule = \&JE::Parser::ptp_program } 0 373 373
Condition75%6/8
$rule eq "program" and not $JE::Parser::_parser and ($ENV{"YES_I_WANT_JE_TO_OPTIMISE"} || "") eq 2
!ll&&!rl&&r
463270
$rule eq "program" and not $JE::Parser::_parser
!ll&&!rl&&r
3511327
$ENV{'YES_I_WANT_JE_TO_OPTIMISE'} || ''
l!l
0327
MC/DC0%0/3
$rule eq "program" and not $JE::Parser::_parser and ($ENV{"YES_I_WANT_JE_TO_OPTIMISE"} || "") eq 2
$rule eq "program" not $JE::Parser::_parser $ENV{'YES_I_WANT_JE_TO_OPTIMISE'}
Truth table75%3/4
A and not(B) and C
A= $rule eq "program"B= not $JE::Parser::_parserC= $ENV{'YES_I_WANT_JE_TO_OPTIMISE'}
ABCresult
0XX0
10X0
1100
1111
1598 373 for($src) {
1599 373 pos = 0;
1600 373 eval {
1601 373 local $global = $my_global;
1602 373 $tree = (\&$rule)->();
1603 !defined pos or pos == length
1604 348 ▶ or expected 'statement or function declaration';
Branch: 1 branch
BranchTrueFalseTotal
not defined pos $_ or pos $_ == length $_ or &expected("statement or function declaration") 346 2 348
Condition66%2/3
not defined pos $_ or pos $_ == length $_
l!l&&r!l&&!r
03462
MC/DC50%1/2
not defined pos $_ or pos $_ == length $_
not defined pos $_ pos $_ == length $_
Truth table66%2/3
not(A) or B
A= not defined pos $_B= pos $_ == length $_
ABresult
1X1
011
000
1605 };
1606 373 ▶ if(ref $@ ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $@ ne '') { } 27 346 373
elsif ($@) { } 0 346 346
1607 27 ▶ defined blessed $@ and
Branch: 2 branches
BranchTrueFalseTotal
defined builtin::blessed($@) and $@->isa("JE::Object::Error") ? last : die() 5 22 27
$@->isa('JE::Object::Error') ? : 5 0 5
1608 $@->isa('JE::Object::Error')
1609 ? last : die;
1610 22 ▶ ref($@) =~ /^(?:SCALAR|REF)\z/ or die;
Branch: 1 branch
BranchTrueFalseTotal
ref($@) =~ /^(?:SCALAR|REF)\z/ or die 22 0 22
1611 $@
1612 22 = ref ${$@} eq 'SCALAR'
1613 ? JE::Object::Error::SyntaxError->new(
1614 $my_global,
1615 add_line_number(
1616 22 ▶ $${$@},
Branch: 1 branch
BranchTrueFalseTotal
ref ${$@;} eq 'SCALAR' ? : 1 21 22
1617 {file=>$file,line=>$line,source=>\$src},
1618 pos)
1619 )
1620 : JE::Object::Error::SyntaxError->new(
1621 $my_global,
1622 # ~~~ This should perhaps show more context
1623 add_line_number
1624 21 "Expected ${$@} but found '".
1625 substr($_, pos, 10) . "'",
1626 {file=>$file,line=>$line,source=>\$src},
1627 pos
1628 );
1629 22 return;
1630 }
1631 0 elsif($@) { die }
1632 }
1633 #use Data::Dumper;
1634 #print Dumper $tree;
1635 351 ▶ wantarray ? ($src, $tree, $_vars) : $tree;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 320 31 351
1636 }
1637  
1638  
1639  
1640 #----------DOCS---------#
1641  
1642 101 !!!0;
1643  
1644 =head1 NAME
1645  
1646 JE::Parser - Framework for customising JE's parser
1647  
1648 =cut
1649  
1650 # Actually, this *is* JE's parser. But since JE::Parser's methods are never
1651 # used directly with the default parser, I think it's actually less confus-
1652 # ing to call it this.
1653  
1654 =head1 SYNOPSIS
1655  
1656 use JE;
1657 use JE::Parser;
1658  
1659 $je = new JE;
1660 $p = new JE::Parser $je; # or: $p = $je->new_parser
1661  
1662 $p->delete_statement('for', 'while', 'do'); # disable loops
1663 $p->add_statement(try => \&parser); # replace existing 'try' statement
1664  
1665 =head1 DESCRIPTION
1666  
1667 This allows one to change the list of statement types that the parser
1668 looks for. For instance, one could disable loops for a mini-JavaScript, or
1669 add extensions to the language, such as the 'catch-if' clause of a C<try>
1670 statement.
1671  
1672 As yet, C<delete_statement> works, but I've not finished
1673 designing the API for C<add_statement>.
1674  
1675 I might provide an API for extending expressions, if I can resolve the
1676 complications caused by the 'new' operator. If anyone else wants to have a
1677 go at it, be my guest. :-)
1678  
1679 =head1 METHODS
1680  
1681 =over 4
1682  
1683 =item $p = new JE::Parser
1684  
1685 Creates a new parser object.
1686  
1687 =item $p->add_statement($name, \&parser);
1688  
1689 This adds a new statement (source element, to be precise) type
1690 to the
1691 list of statements types the parser supports. If a statement type called
1692 C<$name> already exists, it will be replaced.
1693 Otherwise, the new statement type will be added to the top of the list.
1694  
1695 (C<$name> ought to be optional; it should only be necessary if one wants to
1696 delete
1697 it
1698 afterwards or rearrange the list.)
1699  
1700 If the name of a statement type begins with a hyphen, it is only allowed at
1701 the 'program' level, not within compound statements. Function declarations
1702 use this. Maybe this
1703 convention is too unintuitive.... (Does anyone think I should change it?
1704 What should I change it too?)
1705  
1706 C<&parser> will need to parse code contained in C<$_> starting at C<pos()>, then either
1707 return an object, list or coderef (see below)
1708 and set C<pos()> to the position of the next token[1], or, if it
1709 could not
1710 parse anything, return undef and reset C<pos()> to its initial value if it
1711 changed.
1712  
1713 [1] I.e., it is expected to move C<pos> past any trailing whitespace.
1714  
1715 The return value of C<&parser> can be one of the following:
1716  
1717 =over 4
1718  
1719 =item 1)
1720  
1721 An object with an C<eval> method, that will execute the statement, and/or
1722 an C<init> method, which will be called
1723 before the code runs.
1724  
1725 =item 2)
1726  
1727 B<(Not yet
1728 supported!)> A coderef, which will be called when the code is executed.
1729  
1730 =item 3)
1731  
1732 B<(Not yet
1733 supported.)> A hash-style list, the two keys being C<eval> and C<init>
1734 (corresponding to
1735 the methods under item 1) and the values being coderefs; i.e.:
1736  
1737 ( init => \&init_sub, eval => \&eval_sub )
1738  
1739 =back
1740  
1741 Maybe we need support for a JavaScript function to be called to handnle the
1742 statement.
1743  
1744 =item $p->delete_statement(@names);
1745  
1746 Deletes the given statement types and returns C<$p>.
1747  
1748 =item $p->statement_list
1749  
1750 B<(Not yet implemented.)>
1751  
1752 Returns an array ref of the names of the various statement types. You can
1753 rearrange this
1754 list, but it is up to you to make sure you do not add to it any statement
1755 types that have not been added via C<add_statement> (or were not there by
1756 default). The statement types in the list will be tried in order, except
1757 that items beginning with a hyphen always come before other items.
1758  
1759 The default list is C<qw/-function block empty if while with for switch try
1760 labelled var do continue break return throw expr/>
1761  
1762 =item $p->parse($code)
1763  
1764 Parses the C<$code> and returns a parse tree (JE::Code object).
1765  
1766 =item $p->eval($code)
1767  
1768 Shorthand for $p->parse($code)->execute;
1769  
1770 =back
1771  
1772 =head1 EXPORTS
1773  
1774 None by default. You may choose to export the following:
1775  
1776 =head2 Exported Variables
1777  
1778 ... blah blah blah ...
1779  
1780 =head2 Exported Functions
1781  
1782 These all have C<()> for their prototype, except for C<expected> which has
1783 C<($)>.
1784  
1785 ... blah blah blah ...
1786  
1787 =head1 SYNTAX ERRORS
1788  
1789 (To be written)
1790  
1791 expected 'aaaa'; # will be changed to 'Expected aaaa but found....'
1792 die \\"You can't put a doodad after a frombiggle!"; # complete message
1793 die 'aoenstuhoeanthu'; # big no-no (the error is propagated)
1794  
1795 =head1 EXAMPLES
1796  
1797 =head2 Mini JavaScript
1798  
1799 This is an example of a mini JavaScript that does not allow loops or the
1800 creation of functions.
1801  
1802 use JE;
1803 $j = new JE;
1804 $p = $j->new_parser;
1805 $p->delete_statement('for','while','do','-function');
1806  
1807 Since function expressions could still create functions, we need to remove
1808 the Function prototype object. Someone might then try to put it back with
1809 C<Function = parseInt.constructor>, so we'll overwrite Function with an
1810 undeletable read-only undefined property.
1811  
1812 $j->prop({ name => 'Function',
1813 value => undef,
1814 readonly => 1,
1815 dontdel => 1 });
1816  
1817 Then, after this, we call C<< $p->eval('...') >> to run JS code.
1818  
1819 =head2 Perl-style for(LIST) loop
1820  
1821 Well, after writing this example, it seems to me this API is not
1822 sufficient....
1823  
1824 This example doesn't actually work yet.
1825  
1826 use JE;
1827 use JE::Parser qw'$s ident expr statement expected';
1828
1829 $j = new JE;
1830 $p = $j->new_parser;
1831 $p->add_statement('for-list',
1832 sub {
1833 /\Gfor$s/cog or return;
1834 my $loopvar = ident or return;
1835 /\G$s\($s/cog or return;
1836 my @expressions;
1837 do {
1838 # This line doesn't actually work properly because
1839 # 'expr' will gobble up all the commas
1840 @expressions == push @expressions, expr
1841 and return; # If nothing gets pushed on to the
1842 # list, we need to give the default
1843 # 'for' handler a chance, instead of
1844 # throwing an error.
1845 } while /\G$s,$s/cog;
1846 my $statement = statement or expected 'statement';
1847 return bless {
1848 var => $loopvar,
1849 expressions => \@expressions,
1850 statement => $statement
1851 }, 'Local::JEx::ForList';
1852 }
1853 );
1854
1855 package Local::JEx::ForList;
1856
1857 sub eval {
1858 my $self = shift;
1859 local $JE::Code::scope =
1860 bless [@$JE::Code::scope], 'JE::Scope';
1861 # I've got to come up with a better interface than this.
1862 my $obj = $JE::Code::global->eval('new Object');
1863 push @$JE::Code::scope, $obj;
1864  
1865 for (@{$self->{expressions}}) {
1866 $obj->{ $self->{loopvar} } = $_->eval;
1867 $self->{statement}->execute;
1868 }
1869 }
1870  
1871 =head1 SEE ALSO
1872  
1873 L<JE> and L<JE::Code>.
1874  
1875 =cut
1876  
1877  
1878  
1879  
« JE/Object/Math.pm ↑ Summary JE.pm »