pperl/Marpa/R2/Perl.pm

filter: Statementstmt 83.0% 339 / 408 Branchbran 62.3% 126 / 202 Conditioncond 60.2% 50 / 83 MC/DCmcdc 25.5% 11 / 43 Subroutinesub 89.4% 17 / 19 Podpod 0.0% 0 / 10 totaltotal 70.9% 543 / 765 SCAR 62.3
CC
146
Cov
74%
read_PPI_token
246.3
new
31.9
find_perl
21.5
CRAP 507.2
« blib/lib/Marpa/R2/MetaAST.pm ↑ Summary blib/lib/Marpa/R2/Recognizer.pm »
1 # Copyright 2022 Jeffrey Kegler
2 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
3 # redistribute it and/or modify it under the terms of the GNU Lesser
4 # General Public License as published by the Free Software Foundation,
5 # either version 3 of the License, or (at your option) any later version.
6 #
7 # Marpa::R2 is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 # Lesser General Public License for more details.
11 #
12 # You should have received a copy of the GNU Lesser
13 # General Public License along with Marpa::R2. If not, see
14 # http://www.gnu.org/licenses/.
15  
16 package Marpa::R2::Perl;
17  
18 4 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 package Marpa::R2::Internal::Perl;
23  
24 4 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use charnames ':full';
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 4 ▶use Marpa::R2::Perl::Version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 # This code is about Perl GRAMMAR.
30 # If you're looking here
31 # for a Perl SEMANTICS here,
32 # you won't find one.
33  
34 4 my $reference_grammar = <<'END_OF_GRAMMAR';
35  
36 # This is taken from perly.y for Perl 5.12.1
37 prog: prog ::= lineseq ;
38  
39 # /* An ordinary block */
40 block: block ::= '{' lineseq '}' ;
41  
42 mblock ::= '{' lineseq '}' ;
43  
44 # /* A collection of "lines" in the program */
45 lineseq_t: lineseq ::= ;
46 lineseq__decl: lineseq ::= lineseq decl ;
47 lineseq__line: lineseq ::= lineseq line ;
48  
49 # /* A "line" in the program */
50 line ::= label cond ;
51 line ::= loop ; # /* loops add their own labels */
52 line ::= switch ; # /* ... and so do switches */
53 line ::= label case ;
54 line ::= label ';' ;
55 line__sideff: line ::= label sideff ';' ;
56 line ::= label PLUGSTMT ;
57  
58 /* An expression which may have a side-effect */
59 sideff ::= error ;
60 sideff: sideff ::= expr ;
61 sideff ::= expr IF expr ;
62 sideff ::= expr UNLESS expr ;
63 sideff ::= expr WHILE expr ;
64 sideff ::= expr UNTIL iexpr ;
65 sideff ::= expr FOR expr ;
66 sideff ::= expr WHEN expr ;
67  
68 /* else and elsif blocks */
69 else ::= ; /* NULL */
70 else ::= ELSE mblock ;
71 else ::= ELSIF '(' mexpr ')' mblock else ;
72  
73 /* Real conditional expressions */
74 cond ::= IF '(' mexpr ')' mblock else ;
75 cond ::= UNLESS '(' miexpr ')' mblock else ;
76  
77 /* Cases for a switch statement */
78 case ::= WHEN '(' remember mexpr ')' mblock ;
79 case ::= DEFAULT block ;
80  
81 /* Continue blocks */
82 cont ::= ; /* NULL */
83 cont ::= CONTINUE block ;
84  
85 /* Loops: while, until, for, and a bare block */
86 loop ::= label WHILE '(' remember texpr ')' mintro mblock cont ;
87 loop ::= label UNTIL '(' remember iexpr ')' mintro mblock cont ;
88 loop ::= label FOR MY remember my_scalar '(' mexpr ')' mblock cont ;
89 loop ::= label FOR scalar '(' remember mexpr ')' mblock cont ;
90 loop ::= label FOR '(' remember mexpr ')' mblock cont ;
91 loop ::= label FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')' mblock ;
92 /* basically fake up an initialize-while lineseq */
93 loop ::= label block cont ; /* a block is a loop that happens once */
94  
95 /* Switch blocks */
96 switch ::= label GIVEN '(' remember mydefsv mexpr ')' mblock ;
97  
98 /* determine whether there are any new my declarations */
99 mintro ::= ; /* NULL */
100  
101 /* Normal expression */
102 nexpr ::= ;
103 nexpr ::= sideff ;
104  
105 /* Boolean expression */
106 texpr ::= ; /* NULL means true */
107 texpr ::= expr ;
108  
109 /* Inverted boolean expression */
110 iexpr ::= expr ;
111  
112 /* Expression with its own lexical scope */
113 mexpr ::= expr ;
114  
115 mnexpr ::= nexpr ;
116  
117 miexpr ::= iexpr ;
118  
119 /* Optional "MAIN:"-style loop labels */
120 label ::= ; /* empty */
121 label ::= LABEL ;
122  
123 /* Some kind of declaration - just hang on peg in the parse tree */
124 decl ::= format ;
125 decl ::= subrout ;
126 decl ::= mysubrout ;
127 decl ::= package ;
128 decl ::= use ;
129 decl ::= peg ;
130  
131 peg ::= PEG ;
132  
133 format ::= FORMAT startformsub formname block ;
134  
135 formname ::= WORD ;
136 formname ::= ; /* NULL */
137  
138 /* Unimplemented "my sub foo { }" */
139 mysubrout ::= MYSUB startsub subname proto subattrlist subbody ;
140  
141 /* Subroutine definition */
142 subrout ::= SUB startsub subname proto subattrlist subbody ;
143  
144 startsub ::= ; /* NULL */ /* start a regular subroutine scope */
145  
146 startanonsub ::= ; /* NULL */ /* start an anonymous subroutine scope */
147  
148 startformsub ::= ; /* NULL */ /* start a format subroutine scope */
149  
150 /* Name of a subroutine - must be a bareword, could be special */
151 subname ::= WORD ;
152  
153 /* Subroutine prototype */
154 proto ::= ; /* NULL */
155 proto ::= THING ;
156  
157 /* Optional list of subroutine attributes */
158 subattrlist ::= ; /* NULL */
159 subattrlist ::= COLONATTR THING ;
160 subattrlist ::= COLONATTR ;
161  
162 /* List of attributes for a "my" variable declaration */
163 myattrlist ::= COLONATTR THING ;
164 myattrlist ::= COLONATTR ;
165  
166 /* Subroutine body - either null or a block */
167 subbody ::= block ;
168 subbody ::= ';' ;
169  
170 package ::= PACKAGE WORD WORD ';' ;
171  
172 /* use ::= USE startsub WORD WORD listexpr ';' ; */
173 long_use: use ::= USE startsub WORD VERSION listexpr ';' ;
174 revlong_use: use ::= USE startsub VERSION WORD listexpr ';' ;
175 perl_version_use: use ::= USE startsub VERSION ';' ;
176 short_use: use ::= USE startsub WORD listexpr ';' ;
177  
178 /* Ordinary expressions; logical combinations */
179  
180 expr: expr ::= or_expr;
181  
182 # %left <i_tkval> OROP DOROP
183 or_expr: or_expr ::= or_expr OROP and_expr ;
184 or_expr__dor: or_expr ::= or_expr DOROP and_expr ;
185 or_expr__t : or_expr ::= and_expr ;
186  
187 # %left <i_tkval> ANDOP
188 and_expr: and_expr ::= and_expr ANDOP argexpr ;
189 and_expr__t: and_expr ::= argexpr ;
190  
191 /* Expressions are a list of terms joined by commas */
192 argexpr__comma: argexpr ::= argexpr ',' ;
193 argexpr: argexpr ::= argexpr ',' term ;
194 argexpr__t: argexpr ::= term ;
195  
196 /* Names of methods. May use $object->$methodname */
197 method ::= METHOD ;
198 method ::= scalar ;
199  
200  
201 # %nonassoc <i_tkval> PREC_LOW
202 # %nonassoc LOOPEX
203 # %left <i_tkval> OROP DOROP
204 # %left <i_tkval> ANDOP
205 # %right <i_tkval> NOTOP
206 # %nonassoc LSTOP LSTOPSUB
207 # %left <i_tkval> ','
208 # %right <i_tkval> ASSIGNOP
209 # %right <i_tkval> '?' ':'
210 # %nonassoc DOTDOT YADAYADA
211 # %left <i_tkval> OROR DORDOR
212 # %left <i_tkval> ANDAND
213 # %left <i_tkval> BITOROP
214 # %left <i_tkval> BITANDOP
215 # %nonassoc EQOP
216 # %nonassoc RELOP
217 # %nonassoc UNIOP UNIOPSUB
218 # %nonassoc REQUIRE
219 # %left <i_tkval> SHIFTOP
220 # %left ADDOP
221 # %left MULOP
222 # %left <i_tkval> MATCHOP
223 # %right <i_tkval> '!' '~' UMINUS REFGEN
224 # %right <i_tkval> POWOP
225 # %nonassoc <i_tkval> PREINC PREDEC POSTINC POSTDEC
226 # %left <i_tkval> ARROW
227 # %nonassoc <i_tkval> ')'
228 # %left <i_tkval> '('
229 # %left '[' '{'
230  
231 # %nonassoc <i_tkval> PREC_LOW
232 # no terms
233  
234 # %nonassoc LOOPEX
235 term__t: term ::= term_notop ;
236 term ::= LOOPEX ; /* loop exiting command (goto, last, dump, etc) */
237 term ::= LOOPEX term_notop ;
238  
239 # %left <i_tkval> OROP DOROP
240 # %left <i_tkval> ANDOP
241 # no terms, just expr's
242  
243 # %right <i_tkval> NOTOP
244 term_notop__t: term_notop ::= term_listop ;
245 term_notop ::= NOTOP argexpr ; /* not $foo */
246  
247 # %nonassoc LSTOP LSTOPSUB
248 /* List operators */
249 term_listop__t: term_listop ::= term_assign ;
250 term_listop ::= LSTOP indirob argexpr ; /* map {...} @args or print $fh @args */
251 term_lstop: term_listop ::= LSTOP listexpr ; /* print @args */
252 term_listop ::= LSTOPSUB startanonsub block listexpr ;
253 term_listop ::= METHOD indirob listexpr ; /* new Class @args */
254 term_assign_lstop: term_listop ::= term_cond ASSIGNOP term_listop ; /* $x = bless $x, $y */
255  
256 # /* sub f(&@); f { foo } ... */ /* ... @bar */
257  
258 # %left <i_tkval> ','
259 # no terms
260  
261 # %right <i_tkval> ASSIGNOP
262 /* Binary operators between terms */
263 term_assign__t: term_assign ::= term_cond ;
264 # $x = $y
265 term_assign: term_assign ::= term_cond ASSIGNOP term_assign ;
266  
267 # %right <i_tkval> '?' ':'
268 term_cond__t: term_cond ::= term_dotdot ;
269 term_cond: term_cond ::= term_dotdot '?' term_cond ':' term_cond ;
270  
271 # %nonassoc DOTDOT YADAYADA
272 term_dotdot__t: term_dotdot ::= term_oror ;
273 # $x..$y, $x...$y */
274 term_dotdot: term_dotdot ::= term_oror DOTDOT term_oror ;
275 YADAYADA: term_dotdot ::= YADAYADA ;
276  
277 # %left <i_tkval> OROR DORDOR
278 term_oror__t: term_oror ::= term_andand ;
279 term_oror ::= term_oror OROR term_andand ; /* $x || $y */
280 term_oror ::= term_oror DORDOR term_andand ; /* $x // $y */
281  
282 # %left <i_tkval> ANDAND
283 term_andand__t: term_andand ::= term_bitorop ;
284 term_andand ::= term_andand ANDAND term_bitorop ; /* $x && $y */
285  
286 # %left <i_tkval> BITOROP
287 term_bitorop__t: term_bitorop ::= term_bitandop;
288 term_bitorop ::= term_bitorop BITOROP term_bitandop ; /* $x | $y */
289  
290 # %left <i_tkval> BITANDOP
291 term_bitandop__t: term_bitandop ::= term_eqop ;
292 term_bitandop ::= term_bitandop BITANDOP term_eqop ; /* $x & $y */
293  
294 # %nonassoc EQOP
295 term_eqop__t: term_eqop ::= term_relop ;
296 term_eqop ::= term_relop EQOP term_relop ; /* $x == $y, $x eq $y */
297  
298 # %nonassoc RELOP
299 term_relop__t: term_relop ::= term_uniop ;
300 term_relop ::= term_uniop RELOP term_uniop ; /* $x > $y, etc. */
301  
302 # %nonassoc UNIOP UNIOPSUB
303 term_uniop__t: term_uniop ::= term_require ;
304 uniop: term_uniop ::= UNIOP ; /* Unary op, $_ implied */
305 term_uniop ::= UNIOP block ; /* eval { foo }* */
306 term_uniop ::= UNIOP term_require ; /* Unary op */
307 term_uniop ::= UNIOPSUB ;
308 term_uniop ::= UNIOPSUB term_require ; /* Sub treated as unop */
309 /* Things called with "do" */
310 term_uniop ::= DO term_require ; /* do $filename */
311 /* "my" declarations, with optional attributes */
312 # MY has no precedence
313 # so apparently %prec UNIOP for term ::= myattrterm does the job
314 term_myattr: term_uniop ::= MY myterm myattrlist ;
315 term_my: term_uniop ::= MY myterm ;
316 term_local: term_uniop ::= LOCAL term_require ;
317  
318 # %nonassoc REQUIRE
319 term_require__t: term_require ::= term_shiftop ;
320 term_require ::= REQUIRE ; /* require, $_ implied */
321 term_require ::= REQUIRE term_shiftop ; /* require Foo */
322  
323 # %left <i_tkval> SHIFTOP
324 term_shiftop__t: term_shiftop ::= term_addop ;
325 term_shiftop ::= term_shiftop SHIFTOP term_addop ; /* $x >> $y, $x << $y */
326  
327 # %left ADDOP
328 term_addop__t: term_addop ::= term_mulop ;
329 term_addop ::= term_addop ADDOP term_mulop ; /* $x + $y */
330  
331 # %left MULOP
332 term_mulop__t: term_mulop ::= term_matchop ;
333 term_mulop ::= term_mulop MULOP term_matchop ; /* $x * $y, $x x $y */
334  
335 # %left <i_tkval> MATCHOP
336 term_matchop__t: term_matchop ::= term_uminus ;
337 term_matchop ::= term_matchop MATCHOP term_uminus ; /* $x =~ /$y/ */
338  
339 # %right <i_tkval> '!' '~' UMINUS REFGEN
340 term_uminus__t: term_uminus ::= term_powop ;
341 term_uminus ::= '!' term_uminus ; /* !$x */
342 term_uminus ::= '~' term_uminus ; /* ~$x */
343 /* Unary operators and terms */
344 term_uminus ::= '-' term_uminus ; /* -$x */
345 term_uminus ::= '+' term_uminus ; /* +$x */
346 refgen: term_uminus ::= REFGEN term_uminus ; /* \$x, \@y, \%z */
347  
348 # %right <i_tkval> POWOP
349 term_powop__t: term_powop ::= term_increment ;
350 term_powop ::= term_increment POWOP term_powop ; /* $x ** $y */
351  
352 # %nonassoc <i_tkval> PREINC PREDEC POSTINC POSTDEC
353 term_increment__t: term_increment ::= term_arrow ;
354 term_increment ::= term_arrow POSTINC ; /* $x++ */
355 term_increment ::= term_arrow POSTDEC ; /* $x-- */
356 term_increment ::= PREINC term_arrow ; /* ++$x */
357 term_increment ::= PREDEC term_arrow ; /* --$x */
358  
359 # %left <i_tkval> ARROW
360 term_arrow__t: term_arrow ::= term_hi ;
361 term_arrow ::= term_arrow ARROW method '(' listexprcom ')' ; /* $foo->bar(list) */
362 term_arrow ::= term_arrow ARROW method ; /* $foo->bar */
363  
364 # Able to collapse the last few
365 # because no RHS terms
366 # %nonassoc <i_tkval> ')'
367 # %left <i_tkval> '('
368 # %left '[' '{' -- no terms at this precedence
369  
370 term_hi ::= DO WORD '(' ')' ; /* do somesub() */
371 term_hi ::= DO WORD '(' expr ')' ; /* do somesub(@args) */
372 term_hi ::= DO scalar '(' ')' ; /* do $subref () */
373 term_hi ::= DO scalar '(' expr ')' ; /* do $subref (@args) */
374 term_hi__parens: term_hi ::= '(' expr ')' ;
375 term_hi ::= '(' ')' ;
376 term_hi ::= amper '(' ')' ; /* &foo() */
377 term_hi ::= amper '(' expr ')' ; /* &foo(@args) */
378 term_hi ::= FUNC0 '(' ')' ;
379 term_hi ::= FUNC1 '(' ')' ; /* not () */
380 term_hi ::= FUNC1 '(' expr ')' ; /* not($foo) */
381 term_hi ::= PMFUNC '(' argexpr ')' ; /* m//, s///, tr/// */
382 term_hi ::= FUNC '(' indirob expr ')' ; /* print ($fh @args */
383 term_hi ::= FUNCMETH indirob '(' listexprcom ')' ; /* method $object (@args) */
384 term_hi ::= FUNC '(' listexprcom ')' ; /* print (@args) */
385 anon_hash: term_hi ::= HASHBRACK expr ';' '}' ; /* { foo => "Bar" } */
386 anon_empty_hash: term_hi ::= HASHBRACK ';' '}' ; /* { } (';' by tokener) */
387 term_hi ::= ANONSUB startanonsub proto subattrlist block ;
388 do_block: term_hi ::= DO block ; /* do { code */
389 term_hi__scalar: term_hi ::= scalar ;
390 term_hi__star: term_hi ::= star ;
391 term_hi__hsh: term_hi ::= hsh ;
392 term_hi__ary: term_hi ::= ary ;
393 # $#x, $#{ something }
394 term_hi__arylen: term_hi ::= arylen ;
395 term_hi__subscripted: term_hi ::= subscripted ;
396 term_hi__THING: term_hi ::= THING ;
397 /* Constructors for anonymous data */
398 term_hi__anon_array: term_hi ::= '[' expr ']' ;
399 term_hi__anon_empty_array: term_hi ::= '[' ']' ;
400  
401 # Some kind of subscripted expression
402 subscripted ::= star '{' expr ';' '}' ; /* *main::{something} */
403 array_index: subscripted ::= scalar '[' expr ']' ; /* $array[$element] */
404 term_hi__arrow_array: subscripted ::= term_hi ARROW '[' expr ']' ; /* somearef->[$element] */
405 array_index_r: subscripted ::= subscripted '[' expr ']' ; /* $foo->[$bar]->[$baz] */
406 hash_index: subscripted ::= scalar '{' expr ';' '}' ; /* $foo->{bar();} */
407 term_hi__arrow_hash: subscripted ::= term_hi ARROW '{' expr ';' '}' ; /* somehref->{bar();} */
408 hash_index_r: subscripted ::= subscripted '{' expr ';' '}' ; /* $foo->[bar]->{baz;} */
409 subscripted ::= term_hi ARROW '(' ')' ; /* $subref->() */
410 subscripted ::= term_hi ARROW '(' expr ')' ; /* $subref->(@args) */
411 subscripted ::= subscripted '(' expr ')' ; /* $foo->{bar}->(@args) */
412 subscripted ::= subscripted '(' ')' ; /* $foo->{bar}->() */
413 subscripted ::= '(' expr ')' '[' expr ']' ; /* list slice */
414 subscripted ::= '(' ')' '[' expr ']' ; /* empty list slice! */
415  
416 term_hi ::= ary '[' expr ']' ; /* array slice */
417 term_hi ::= ary '{' expr ';' '}' ; /* @hash{@keys} */
418  
419 term_hi ::= amper ; /* &foo; */
420 term_hi ::= NOAMP WORD listexpr ; /* foo(@args) */
421 term_hi ::= FUNC0 ; /* Nullary operator */
422 term_hi ::= FUNC0SUB ; /* Sub treated as nullop */
423 term_hi ::= WORD ;
424 term_hi ::= PLUGEXPR ;
425  
426 # End of list of terms
427  
428 /* Things that can be "my"'d */
429 myterm_scalar: myterm ::= scalar ;
430 myterm_hash: myterm ::= hsh ;
431 myterm_array: myterm ::= ary ;
432  
433 /* Basic list expressions */
434 # Essentially, a listexpr is a nullable argexpr
435 listexpr_t: listexpr ::= ; /* NULL */
436 listexpr: listexpr ::= argexpr ;
437  
438 # In perly.y listexprcom occurs only inside parentheses
439 listexprcom ::= ; /* NULL */
440 listexprcom ::= expr ;
441 listexprcom ::= expr ',' ;
442  
443 /* A little bit of trickery to make "for my $foo (@bar)" actually be lexical */
444 my_scalar ::= scalar ;
445  
446 amper ::= '&' indirob ;
447  
448 scalar: scalar ::= '$' indirob ;
449  
450 ary ::= '@' indirob ;
451  
452 hsh ::= '%' indirob ;
453  
454 arylen ::= DOLSHARP indirob ;
455  
456 star ::= '*' indirob ;
457  
458 /* Indirect objects */
459 indirob__WORD: indirob ::= WORD ;
460 indirob ::= scalar ;
461 indirob__block: indirob ::= block ;
462 indirob ::= PRIVATEREF ;
463 END_OF_GRAMMAR
464  
465 4 my %symbol_name = (
466 q{~} => 'TILDE',
467 q{-} => 'MINUS',
468 q{,} => 'COMMA',
469 q{;} => 'SEMI',
470 q{:} => 'COLON',
471 q{!} => 'BANG',
472 q{?} => 'QUESTION',
473 q{(} => 'LPAREN',
474 q{)} => 'RPAREN',
475 q{[} => 'LSQUARE',
476 q{]} => 'RSQUARE',
477 q[{] => 'LCURLY',
478 q[}] => 'RCURLY',
479 q{@} => 'ATSIGN',
480 q{$} => 'DOLLAR',
481 q{*} => 'ASTERISK',
482 q{&} => 'AMPERSAND',
483 q{%} => 'PERCENT',
484 q{+} => 'PLUS',
485 );
486  
487 4 my %perl_type_by_cast = (
488 q{\\} => 'REFGEN',
489 q{*} => 'ASTERISK',
490 q{&} => 'AMPERSAND',
491 q{$} => 'DOLLAR',
492 q{@} => 'ATSIGN',
493 q{%} => 'PERCENT',
494 );
495  
496 4 my %perl_type_by_structure = (
497 q{(} => 'LPAREN',
498 q{)} => 'RPAREN',
499 q{[} => 'LSQUARE',
500 q{]} => 'RSQUARE',
501 q[{] => 'LCURLY',
502 q[}] => 'RCURLY',
503 q{;} => 'SEMI',
504 );
505  
506 4 my %perl_type_by_op = (
507 q{->} => 'ARROW', # 1
508 q{--} => 'PREDEC', # 2
509 q{++} => 'PREINC', # 2
510 q{**} => 'POWOP', # 3
511 q{~} => 'TILDE', # 4
512 q{!} => 'BANG', # 4
513 q{\\} => 'REFGEN', # 4
514 q{=~} => 'MATCHOP', # 5
515 q{!~} => 'MATCHOP', # 5
516 q{/} => 'MULOP', # 6
517 q{*} => 'MULOP', # 6
518 q{%} => 'MULOP', # 6
519 q{x} => 'MULOP', # 6
520 q{-} => 'MINUS', # 7
521 q{.} => 'ADDOP', # 7
522 q{+} => 'PLUS', # 7
523 q{<<} => 'SHIFTOP', # 8
524 q{>>} => 'SHIFTOP', # 8
525 q{-A} => 'UNIOP', # 9
526 q{-b} => 'UNIOP', # 9
527 q{-B} => 'UNIOP', # 9
528 q{-c} => 'UNIOP', # 9
529 q{-C} => 'UNIOP', # 9
530 q{-d} => 'UNIOP', # 9
531 q{-e} => 'UNIOP', # 9
532 q{-f} => 'UNIOP', # 9
533 q{-g} => 'UNIOP', # 9
534 q{-k} => 'UNIOP', # 9
535 q{-l} => 'UNIOP', # 9
536 q{-M} => 'UNIOP', # 9
537 q{-o} => 'UNIOP', # 9
538 q{-O} => 'UNIOP', # 9
539 q{-p} => 'UNIOP', # 9
540 q{-r} => 'UNIOP', # 9
541 q{-R} => 'UNIOP', # 9
542 q{-s} => 'UNIOP', # 9
543 q{-S} => 'UNIOP', # 9
544 q{-t} => 'UNIOP', # 9
545 q{-T} => 'UNIOP', # 9
546 q{-u} => 'UNIOP', # 9
547 q{-w} => 'UNIOP', # 9
548 q{-W} => 'UNIOP', # 9
549 q{-x} => 'UNIOP', # 9
550 q{-X} => 'UNIOP', # 9
551 q{-z} => 'UNIOP', # 9
552 q{ge} => 'RELOP', # 10
553 q{gt} => 'RELOP', # 10
554 q{le} => 'RELOP', # 10
555 q{lt} => 'RELOP', # 10
556 q{<=} => 'RELOP', # 10
557 q{<} => 'RELOP', # 10
558 q{>=} => 'RELOP', # 10
559 q{>} => 'RELOP', # 10
560 q{cmp} => 'EQOP', # 11
561 q{eq} => 'EQOP', # 11
562 q{ne} => 'EQOP', # 11
563 q{~~} => 'EQOP', # 11
564 q{<=>} => 'EQOP', # 11
565 q{==} => 'EQOP', # 11
566 q{!=} => 'EQOP', # 11
567 q{&} => 'BITANDOP', # 12
568 q{^} => 'BITOROP', # 13
569 q{|} => 'BITOROP', # 13
570 q{&&} => 'ANDAND', # 14
571 q{||} => 'OROR', # 15
572 q{//} => 'DORDOR', # 15
573 q{..} => 'DOTDOT', # 16
574 q{...} => 'YADAYADA', # 17
575 q{:} => 'COLON', # 18
576 q{?} => 'QUESTION', # 18
577 q{^=} => 'ASSIGNOP', # 19
578 q{<<=} => 'ASSIGNOP', # 19
579 q{=} => 'ASSIGNOP', # 19
580 q{>>=} => 'ASSIGNOP', # 19
581 q{|=} => 'ASSIGNOP', # 19
582 q{||=} => 'ASSIGNOP', # 19
583 q{-=} => 'ASSIGNOP', # 19
584 q{/=} => 'ASSIGNOP', # 19
585 q{.=} => 'ASSIGNOP', # 19
586 q{*=} => 'ASSIGNOP', # 19
587 q{**=} => 'ASSIGNOP', # 19
588 q{&=} => 'ASSIGNOP', # 19
589 q{&&=} => 'ASSIGNOP', # 19
590 q{%=} => 'ASSIGNOP', # 19
591 q{+=} => 'ASSIGNOP', # 19
592 q{x=} => 'ASSIGNOP', # 19
593 q{,} => 'COMMA', # 20
594 q{=>} => 'COMMA', # 20
595 q{not} => 'NOTOP', # 22
596 q{and} => 'ANDOP', # 23
597 q{or} => 'OROP', # 24
598 q{xor} => 'DOROP', # 24
599 );
600  
601 4 my %perl_type_by_word = (
602 'AUTOLOAD' => 'PHASER',
603 'BEGIN' => 'PHASER',
604 'CHECK' => 'PHASER',
605 'CORE' => 'TO_BE_DETERMINED',
606 'DESTROY' => 'PHASER',
607 'END' => 'PHASER',
608 'INIT' => 'PHASER',
609 'NULL' => 'TO_BE_DETERMINED',
610 'UNITCHECK' => 'PHASER',
611 '__DATA__' => 'TO_BE_DETERMINED',
612 '__END__' => 'TO_BE_DETERMINED',
613 '__FILE__' => 'THING',
614 '__LINE__' => 'THING',
615 '__PACKAGE__' => 'THING',
616 'abs' => 'UNIOP',
617 'accept' => 'LSTOP',
618 'alarm' => 'UNIOP',
619 'atan2' => 'LSTOP',
620 'bind' => 'LSTOP',
621 'binmode' => 'LSTOP',
622 'bless' => 'LSTOP',
623 'bless' => 'LSTOP',
624 'break' => 'LOOPEX',
625 'caller' => 'UNIOP',
626 'chdir' => 'UNIOP',
627 'chmod' => 'LSTOP',
628 'chomp' => 'UNIOP',
629 'chop' => 'UNIOP',
630 'chown' => 'LSTOP',
631 'chr' => 'UNIOP',
632 'chroot' => 'UNIOP',
633 'close' => 'UNIOP',
634 'closedir' => 'UNIOP',
635 'connect' => 'LSTOP',
636 'continue' => 'CONTINUE',
637 'cos' => 'UNIOP',
638 'crypt' => 'LSTOP',
639 'dbmclose' => 'UNIOP',
640 'dbmopen' => 'LSTOP',
641 'default' => 'DEFAULT',
642 'defined' => 'UNIOP',
643 'delete' => 'UNIOP',
644 'die' => 'LSTOP',
645 'do' => 'DO',
646 'dump' => 'UNIOP',
647 'each' => 'UNIOP',
648 'else' => 'ELSE',
649 'elsif' => 'ELSIF',
650 'endgrent' => 'FUNC0',
651 'endhostent' => 'FUNC0',
652 'endnetent' => 'FUNC0',
653 'endprotoent' => 'FUNC0',
654 'endpwent' => 'FUNC0',
655 'endservent' => 'FUNC0',
656 'eof' => 'UNIOP',
657 'eval' => 'UNIOP',
658 'exec' => 'LSTOP',
659 'exists' => 'UNIOP',
660 'exit' => 'UNIOP',
661 'exp' => 'UNIOP',
662 'fcntl' => 'LSTOP',
663 'fileno' => 'UNIOP',
664 'flock' => 'LSTOP',
665 'for' => 'FOR',
666 'foreach' => 'FOR',
667 'fork' => 'FUNC0',
668 'format' => 'FUNC0',
669 'formline' => 'LSTOP',
670 'getc' => 'UNIOP',
671 'getgrent' => 'FUNC0',
672 'getgrgid' => 'UNIOP',
673 'getgrnam' => 'UNIOP',
674 'gethostbyaddr' => 'LSTOP',
675 'gethostbyname' => 'UNIOP',
676 'gethostent' => 'FUNC0',
677 'getlogin' => 'FUNC0',
678 'getnetbyaddr' => 'LSTOP',
679 'getnetbyname' => 'UNIOP',
680 'getnetent' => 'FUNC0',
681 'getpeername' => 'UNIOP',
682 'getpgrp' => 'UNIOP',
683 'getppid' => 'FUNC0',
684 'getpriority' => 'LSTOP',
685 'getprotobyname' => 'UNIOP',
686 'getprotobynumber' => 'UNIOP',
687 'getprotoent' => 'FUNC0',
688 'getpwent' => 'FUNC0',
689 'getpwnam' => 'UNIOP',
690 'getpwuid' => 'UNIOP',
691 'getservbyname' => 'LSTOP',
692 'getservbyport' => 'LSTOP',
693 'getservent' => 'FUNC0',
694 'getsockname' => 'UNIOP',
695 'getsockopt' => 'LSTOP',
696 'given' => 'GIVEN',
697 'glob' => 'UNIOP',
698 'gmtime' => 'UNIOP',
699 'goto' => 'LOOPEX',
700 'grep' => 'LSTOP',
701 'hex' => 'UNIOP',
702 'if' => 'IF',
703 'import' => 'LSTOP', # not really a keyword, but make it a LSTOP
704 'index' => 'LSTOP',
705 'int' => 'UNIOP',
706 'ioctl' => 'LSTOP',
707 'join' => 'LSTOP',
708 'keys' => 'UNIOP',
709 'kill' => 'LSTOP',
710 'last' => 'LOOPEX',
711 'lc' => 'UNIOP',
712 'lcfirst' => 'UNIOP',
713 'length' => 'UNIOP',
714 'link' => 'LSTOP',
715 'listen' => 'LSTOP',
716 'local' => 'LOCAL',
717 'localtime' => 'UNIOP',
718 'lock' => 'UNIOP',
719 'log' => 'UNIOP',
720 'lstat' => 'UNIOP',
721 'm' => 'QUOTEABLE -- TO BE DETERMINED',
722 'map' => 'LSTOP',
723 'mkdir' => 'LSTOP',
724 'msgctl' => 'LSTOP',
725 'msgget' => 'LSTOP',
726 'msgrcv' => 'LSTOP',
727 'msgsnd' => 'LSTOP',
728 'my' => 'MY',
729 'my' => 'MY',
730 'next' => 'LOOPEX',
731 'no' => 'USE',
732 'oct' => 'UNIOP',
733 'open' => 'LSTOP',
734 'opendir' => 'LSTOP',
735 'ord' => 'UNIOP',
736 'our' => 'MY',
737 'pack' => 'LSTOP',
738 'package' => 'PACKAGE',
739 'pipe' => 'LSTOP',
740 'pop' => 'UNIOP',
741 'pos' => 'UNIOP',
742 'print' => 'LSTOP',
743 'printf' => 'LSTOP',
744 'prototype' => 'UNIOP',
745 'push' => 'LSTOP',
746 'q' => 'QUOTEABLE -- TO BE DETERMINED',
747 'qq' => 'QUOTEABLE -- TO BE DETERMINED',
748 'qr' => 'QUOTEABLE -- TO BE DETERMINED',
749 'quotemeta' => 'UNIOP',
750 'qw' => 'QUOTEABLE -- TO BE DETERMINED',
751 'qx' => 'QUOTEABLE -- TO BE DETERMINED',
752 'rand' => 'UNIOP',
753 'read' => 'LSTOP',
754 'readdir' => 'UNIOP',
755 'readline' => 'UNIOP',
756 'readlink' => 'UNIOP',
757 'readpipe' => 'UNIOP',
758 'recv' => 'LSTOP',
759 'redo' => 'LOOPEX',
760 'ref' => 'UNIOP',
761 'rename' => 'LSTOP',
762 'require' => 'REQUIRE',
763 'reset' => 'UNIOP',
764 'return' => 'LSTOP',
765 'reverse' => 'LSTOP',
766 'rewinddir' => 'UNIOP',
767 'rindex' => 'LSTOP',
768 'rmdir' => 'UNIOP',
769 's' => 'QUOTEABLE -- TO BE DETERMINED',
770 'say' => 'LSTOP',
771 'scalar' => 'UNIOP',
772 'seek' => 'LSTOP',
773 'seekdir' => 'LSTOP',
774 'select' => 'LSTOP',
775 'semctl' => 'LSTOP',
776 'semget' => 'LSTOP',
777 'semop' => 'LSTOP',
778 'send' => 'LSTOP',
779 'setgrent' => 'FUNC0',
780 'sethostent' => 'UNIOP',
781 'setnetent' => 'UNIOP',
782 'setpgrp' => 'LSTOP',
783 'setpriority' => 'LSTOP',
784 'setprotoent' => 'UNIOP',
785 'setpwent' => 'FUNC0',
786 'setservent' => 'UNIOP',
787 'setsockopt' => 'LSTOP',
788 'shift' => 'UNIOP',
789 'shmctl' => 'LSTOP',
790 'shmget' => 'LSTOP',
791 'shmread' => 'LSTOP',
792 'shmwrite' => 'LSTOP',
793 'shutdown' => 'LSTOP',
794 'sin' => 'UNIOP',
795 'sleep' => 'UNIOP',
796 'socket' => 'LSTOP',
797 'socketpair' => 'LSTOP',
798 'sort' => 'LSTOP',
799 'splice' => 'LSTOP',
800 'split' => 'LSTOP',
801 'sprintf' => 'LSTOP',
802 'sqrt' => 'UNIOP',
803 'srand' => 'UNIOP',
804 'stat' => 'UNIOP',
805 'state' => 'MY',
806 'study' => 'UNIOP',
807 'sub' => 'SUB',
808 'substr' => 'LSTOP',
809 'symlink' => 'LSTOP',
810 'syscall' => 'LSTOP',
811 'sysopen' => 'LSTOP',
812 'sysread' => 'LSTOP',
813 'sysseek' => 'LSTOP',
814 'system' => 'LSTOP',
815 'syswrite' => 'LSTOP',
816 'tell' => 'UNIOP',
817 'telldir' => 'UNIOP',
818 'tie' => 'LSTOP',
819 'tied' => 'UNIOP',
820 'time' => 'FUNC0',
821 'times' => 'FUNC0',
822 'tr' => 'QUOTEABLE -- TO BE DETERMINED',
823 'truncate' => 'LSTOP',
824 'uc' => 'UNIOP',
825 'ucfirst' => 'UNIOP',
826 'umask' => 'UNIOP',
827 'undef' => 'UNIOP',
828 'undef' => 'UNIOP',
829 'unless' => 'UNLESS',
830 'unlink' => 'LSTOP',
831 'unpack' => 'LSTOP',
832 'unshift' => 'LSTOP',
833 'untie' => 'UNIOP',
834 'until' => 'UNTIL',
835 'use' => 'USE',
836 'utime' => 'LSTOP',
837 'values' => 'UNIOP',
838 'vec' => 'LSTOP',
839 'wait' => 'FUNC0',
840 'waitpid' => 'LSTOP',
841 'wantarray' => 'FUNC0',
842 'warn' => 'LSTOP',
843 'when' => 'WHEN',
844 'while' => 'WHILE',
845 'write' => 'UNIOP',
846 'y' => 'QUOTEABLE -- TO BE DETERMINED',
847 );
848  
849 4 my %rule_rank = (
850 long_use => 2,
851 perl_version_use => 1,
852 short_use => 0,
853 );
854  
855 sub Marpa::R2::Perl::new {
856 5 ▶ my ( $class, $args ) = @_;
Subroutine new: called CC=29 SCAR=34.6
Pod undocumented
857 5 ▶ $args //= {};
Condition50%1/2
$args //= {}
l!l
50
MC/DC0%0/1
$args //= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
858 5 my $gen_closure;
859 5 my $embedded = 0;
860  
861 5 ▶ die 'Closure argument to new must be HASH of named arguments'
Branch: 1 branch
BranchTrueFalseTotal
if ref $args ne "HASH" 0 5 5
862 if ref $args ne 'HASH';
863  
864 5 NAMED_ARG: for my $named_arg ( keys %{$args} ) {
865 6 ▶ if ( $named_arg eq 'closures' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($named_arg eq "closures") 5 1 6
866 5 $gen_closure = $args->{$named_arg};
867 5 my $closure_type = ref $gen_closure;
868 5 ▶ if ( $closure_type ne 'HASH' and $closure_type ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closure_type ne "HASH" and $closure_type ne "CODE") 0 5 5
Condition66%2/3
$closure_type ne "HASH" and $closure_type ne "CODE"
!ll&&!rl&&r
320
MC/DC0%0/2
$closure_type ne "HASH" and $closure_type ne "CODE"
$closure_type ne "HASH" $closure_type ne "CODE"
Truth table66%2/3
A and B
A= $closure_type ne "HASH"B= $closure_type ne "CODE"
ABresult
0X0
100
111
869 0 die 'Closure argument to new must be HASH or CODE ref';
870 }
871 5 next NAMED_ARG;
872 } ## end if ( $named_arg eq 'closures' )
873 1 ▶ if ( $named_arg eq 'embedded' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($named_arg eq "embedded") 1 0 1
874 1 ▶ $embedded = $args->{$named_arg} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args->{$named_arg} ? : 1 0 1
875 1 next NAMED_ARG;
876 }
877 0 die qq{"Unknown named argument to new(): "$named_arg"};
878 } ## end NAMED_ARG: for my $named_arg ( keys %{$args} )
879  
880 5 ▶ die q{"closure" named argument is required}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gen_closure 0 5 5
881 if not defined $gen_closure;
882  
883 5 my %symbol = ();
884 5 my @rules;
885 my %closure;
886  
887 LINE:
888 5 for my $line ( split /\n/xms, $reference_grammar ) {
889 2140 chomp $line;
890 2140 $line =~ s/ [#] .* \z //xms;
891 2140 $line =~ s/ [\/][*] .* \z //xms;
892 2140 $line =~ s/ \A \s+ //xms;
893 2140 ▶ next LINE if $line eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "" 1010 1130 2140
894 1130 ▶ Carp::croak("Misformed line: $line")
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ / [:][:][=] .* [;] \s* \z /msx 0 1130 1130
895 if $line !~ / [:][:][=] .* [;] \s* \z /xms;
896 1130 my ($rule_name) = ( $line =~ /\A (\w+) \s* [:] [^:] /gxms );
897 1130 my ( $lhs, $rhs_string ) =
898 ( $line =~ / \s* (\w+) \s* [:][:][=] \s* (.*) [;] \s* \z/xms );
899 1130 my @rhs = ();
900 1130 RHS: for my $rhs_desc ( split q{ }, $rhs_string ) {
901  
902 2755 ▶ if ( $rhs_desc =~ m/\A ['] ([^']*) ['] \z/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhs_desc =~ /\A ['] ([^']*) ['] \z/msx) 645 2110 2755
903 645 my $rhs_name = $symbol_name{$1};
904 645 ▶ die "No symbol name for $rhs_desc" if not defined $rhs_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rhs_name 0 645 645
905 645 push @rhs, $rhs_name;
906 645 next RHS;
907 } ## end if ( $rhs_desc =~ m/\A ['] ([^']*) ['] \z/xms )
908 2110 push @rhs, $rhs_desc;
909 } ## end RHS: for my $rhs_desc ( split q{ }, $rhs_string )
910  
911 1130 for my $symbol ( $lhs, @rhs ) {
912 3885 ▶ $symbol{$symbol} //= 0;
Condition100%2/2
$symbol{$symbol} //= 0
l!l
3045840
MC/DC100%1/1
$symbol{$symbol} //= 0
$symbol{$symbol}
Truth table100%2/2
A
A= $symbol{$symbol}
Aresult
11
00
913 3885 ▶ if ( $symbol =~ /\W/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ /\W/msx) 0 3885 3885
914 0 Carp::croak("Misformed symbol: $symbol");
915 }
916 } ## end for my $symbol ( $lhs, @rhs )
917 1130 $symbol{$lhs}++;
918  
919 1130 my @additional_args = ();
920 1130 my $closure_type = ref $gen_closure;
921 1130 ▶ if ( $closure_type eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closure_type eq "CODE") 452 678 1130
922 452 ▶ $rule_name ||= q{!} . scalar @rules;
Condition100%2/2
$rule_name ||= '!' . scalar(@rules)
l!l
160292
MC/DC100%1/1
$rule_name ||= '!' . scalar(@rules)
$rule_name
Truth table100%2/2
A
A= $rule_name
Aresult
11
00
923 452 my ($action) = $gen_closure->( $lhs, \@rhs, $rule_name );
924 452 ▶ if ( defined $action ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $action) 452 0 452
925 452 $closure{"!$rule_name"} = $action;
926 452 push @additional_args, action => "!$rule_name";
927 }
928 } ## end if ( $closure_type eq 'CODE' )
929 1130 ▶ if ( $closure_type eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closure_type eq "HASH") 678 452 1130
930 678 ▶ my $action_name = $rule_name // $lhs;
Condition66%2/3
$rule_name // $lhs
l!l&&r!l&&!r
2404380
MC/DC0%0/2
$rule_name // $lhs
$rule_name $lhs
Truth table66%2/3
A // B
A= $rule_nameB= $lhs
ABresult
1X1
011
000
931 678 my $action = $gen_closure->{$action_name};
932 678 ▶ if ( defined $action ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $action) 0 678 678
933 0 $closure{"!$action_name"} = $action;
934 0 push @additional_args, action => "!$action_name";
935 }
936 } ## end if ( $closure_type eq 'HASH' )
937 1130 ▶ my $rank = defined $rule_name ? $rule_rank{$rule_name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $rule_name ? : 692 438 1130
938 1130 ▶ if ( defined $rank ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rank) 15 1115 1130
939 15 push @additional_args, rank => $rank;
940 }
941 1130 push @rules,
942 {
943 lhs => $lhs,
944 rhs => \@rhs,
945 @additional_args, name => $rule_name
946 };
947  
948 } ## end LINE: for my $line ( split /\n/xms, $reference_grammar )
949  
950 5 my $start = 'prog';
951 5 ▶ if ($embedded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($embedded) 1 4 5
952 1 push @rules,
953 [ 'embedded_perl', [qw(target)] ],
954 [ 'embedded_perl', [qw(non_perl_prefix target)] ],
955 [ 'target', [qw(target_start_marker line non_trivial_target_end)] ],
956 [ 'target', [qw(target_start_marker decl non_trivial_target_end)] ],
957 [ 'target', [qw(target_start_marker prog target_end_marker)] ],
958 {
959 lhs => 'non_perl_prefix',
960 rhs => ['non_perl_token'],
961 min => 1,
962 };
963 1 $start = 'embedded_perl';
964 } ## end if ($embedded)
965  
966 5 my $grammar = Marpa::R2::Grammar->new(
967 { start => $start,
968 rules => \@rules,
969 }
970 );
971  
972 5 $grammar->precompute();
973  
974 5 my $self = bless { grammar => $grammar, closure => \%closure }, $class;
975 5 ▶ $self->{embedded} = $embedded ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$embedded ? : 1 4 5
976 5 return $self;
977  
978 } ## end sub Marpa::R2::Perl::new
979  
980 4 my @RECCE_NAMED_ARGUMENTS =
981 qw(trace_terminals trace_values trace_actions);
982  
983 sub token_not_accepted {
984 27 ▶ my ( $ppi_token, $token_name, $token_value, $length ) = @_;
Subroutine token_not_accepted: called CC=7 SCAR=20.5
985  
986 27 local $Data::Dumper::Maxdepth = 2;
987 27 local $Data::Dumper::Terse = 1;
988 27 my $perl_token_desc;
989 27 ▶ if ( not defined $token_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $token_name) { } 0 27 27
990 0 $perl_token_desc = 'Undefined Perl token was not accepted: ';
991 }
992 else {
993 27 $perl_token_desc = qq{Perl token "$token_name" was not accepted: };
994 }
995 27 ▶ if ( defined $length and $length != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length and $length != 1) 0 27 27
Condition66%2/3
defined $length and $length != 1
!ll&&!rl&&r
2340
MC/DC0%0/2
defined $length and $length != 1
defined $length $length != 1
Truth table66%2/3
A and B
A= defined $lengthB= $length != 1
ABresult
0X0
100
111
996 0 $perl_token_desc .= ' length=' . $length;
997 }
998 27 $perl_token_desc .= Data::Dumper::Dumper($token_value);
999 27 my $logical_filename = $ppi_token->logical_filename();
1000 27 ▶ $logical_filename = '[no file]' if not $logical_filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $logical_filename 27 0 27
1001 27 my $error_string = join q{},
1002 "$perl_token_desc", 'PPI token is ',
1003 ( ref $ppi_token ), qq{: $logical_filename:},
1004 $ppi_token->logical_line_number(), q{:},
1005 $ppi_token->column_number(), q{, },
1006 q{content="}, $ppi_token->content(),
1007 q{"}
1008 ;
1009 27 ▶ if ($Marpa::R2::Perl::PARSER->{embedded}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Marpa::R2::Perl::PARSER->{"embedded"}) 27 0 27
1010 27 push @{$Marpa::R2::Perl::PARSER->{token_issues}}, $error_string;
1011 27 ▶ return if $Marpa::R2::Perl::PARSER->{in_prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $Marpa::R2::Perl::PARSER->{"in_prefix"} 23 4 27
1012 4 die "TOKEN_NOT_ACCEPTED\n";
1013 }
1014 0 Carp::croak($error_string);
1015 } ## end sub token_not_accepted
1016  
1017 sub unknown_ppi_token {
1018 0 ▶ my ($ppi_token) = @_;
Subroutine unknown_ppi_token: not called CC=3 SCAR=24.8
1019 0 my $issue = join q{}, 'Failed at Token: ', Data::Dumper::Dumper($ppi_token),
1020 'Marpa::R2::Perl did not know how to process token',
1021 Marpa::R2::Perl::default_show_location($ppi_token), "\n";
1022 0 ▶ if ($Marpa::R2::Perl::PARSER->{embedded}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Marpa::R2::Perl::PARSER->{"embedded"}) 0 0 0
1023 0 push @{$Marpa::R2::Perl::PARSER->{token_issues}}, $issue;
1024 0 ▶ return if $Marpa::R2::Perl::PARSER->{in_prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $Marpa::R2::Perl::PARSER->{"in_prefix"} 0 0 0
1025 0 die "TOKEN_NOT_ACCEPTED\n";
1026 }
1027 0 die $issue;
1028 } ## end sub unknown_ppi_token
1029  
1030 sub Marpa::R2::Perl::tokens {
1031 18 ▶ my ( $parser, $input ) = @_;
Subroutine tokens: called CC=1 SCAR=0.0
Pod undocumented
1032 # We need to keep a reference to the document,
1033 # not just the tokens,
1034 # or bad things happen.
1035 18 my $document = $parser->{document} = PPI::Document->new($input);
1036 18 $document->index_locations();
1037 18 return $parser->{PPI_tokens} = [$document->tokens()];
1038 } ## end sub Marpa::R2::Perl::tokens
1039  
1040 sub Marpa::R2::Perl::clone_tokens {
1041 1 ▶ my ( $to_parser, $from_parser ) = @_;
Subroutine clone_tokens: called CC=1 SCAR=0.0
Pod undocumented
1042 1 $to_parser->{document} = $from_parser->{document} ;
1043 1 $to_parser->{PPI_tokens} = $from_parser->{PPI_tokens} ;
1044 }
1045  
1046 sub Marpa::R2::Perl::read {
1047 17 ▶ my ( $parser, $input ) = @_;
Subroutine read: called CC=1 SCAR=0.0
Pod undocumented
1048 17 $parser->tokens($input);
1049 17 $parser->read_tokens();
1050 }
1051  
1052 sub Marpa::R2::Perl::read_tokens {
1053  
1054 21 ▶ my ( $parser, $first_token_ix, $last_token_ix, $hash_arg ) = @_;
Subroutine read_tokens: called CC=8 SCAR=22.3
Pod undocumented
1055  
1056 21 ▶ $hash_arg //= {};
Condition50%1/2
$hash_arg //= {}
l!l
021
MC/DC0%0/1
$hash_arg //= {}
$hash_arg
Truth table50%1/2
A
A= $hash_arg
Aresult
11
00
1057  
1058 21 my @recce_args = ();
1059 21 HASH_ARG: for my $arg ( keys %{$hash_arg} ) {
1060 0 my $value = $hash_arg->{$arg};
1061 0 ▶ if ( grep { $_ eq $arg } @RECCE_NAMED_ARGUMENTS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $arg;} @RECCE_NAMED_ARGUMENTS) 0 0 0
1062 0 push @recce_args, $arg, $value;
1063 0 next HASH_ARG;
1064 }
1065 0 Carp::croak("Unknown hash arg: $arg");
1066 } ## end HASH_ARG: for my $arg ( keys %{$hash_arg} )
1067  
1068 21 my $grammar = $parser->{grammar};
1069  
1070 my $recce = Marpa::R2::Recognizer->new(
1071 { grammar => $grammar,
1072 closures => $parser->{closure},
1073 21 ranking_method => 'high_rule_only',
1074 @recce_args
1075 }
1076 );
1077 21 $parser->{recce} = $recce;
1078 21 $parser->{terminals_expected} = $recce->terminals_expected();
1079  
1080 # This is convenient for making the recognizer available to
1081 # error messages
1082 21 local $Marpa::R2::Perl::RECOGNIZER = $recce;
1083  
1084 21 my $PPI_tokens = $parser->{PPI_tokens};
1085 21 my $earleme_to_PPI_token = $parser->{earleme_to_PPI_token} = [];
1086  
1087 # For use by read_PPI_token
1088 21 local $Marpa::R2::Perl::LAST_PERL_TYPE = undef;
1089  
1090 21 ▶ $first_token_ix //= 0;
Condition100%2/2
$first_token_ix //= 0
l!l
417
MC/DC100%1/1
$first_token_ix //= 0
$first_token_ix
Truth table100%2/2
A
A= $first_token_ix
Aresult
11
00
1091 21 ▶ $last_token_ix //= $#{$PPI_tokens};
Condition66%2/3
$last_token_ix //= $#{$PPI_tokens;}
l!l&&r!l&&!r
4170
MC/DC0%0/2
$last_token_ix //= $#{$PPI_tokens;}
$last_token_ix $#{$PPI_tokens;}
Truth table66%2/3
A //= B
A= $last_token_ixB= $#{$PPI_tokens;}
ABresult
1X1
011
000
1092 21 for my $PPI_token_ix ( $first_token_ix .. $last_token_ix ) {
1093 1202 my $current_earleme = $recce->current_earleme();
1094 1202 ▶ $earleme_to_PPI_token->[$current_earleme] //= $PPI_token_ix;
Condition66%2/3
$earleme_to_PPI_token->[$current_earleme] //= $PPI_token_ix
l!l&&r!l&&!r
3818210
MC/DC0%0/2
$earleme_to_PPI_token->[$current_earleme] //= $PPI_token_ix
$earleme_to_PPI_token->[$current_earleme] $PPI_token_ix
Truth table66%2/3
A //= B
A= $earleme_to_PPI_token->[$current_earleme]B= $PPI_token_ix
ABresult
1X1
011
000
1095 1202 read_PPI_token( $parser, $PPI_token_ix );
1096 }
1097  
1098 21 $recce->end_input();
1099 21 return $parser;
1100  
1101 } ## end sub Marpa::R2::Perl::read
1102  
1103 sub Marpa::R2::Perl::earleme_complete {
1104 1146 ▶ my ($parser) = @_;
Subroutine earleme_complete: called CC=7 SCAR=24.1
Pod undocumented
1105  
1106 1146 my $recce = $parser->{recce};
1107 1146 my $recce_c = $recce->thin();
1108 1146 my $grammar = $parser->{grammar};
1109 1146 my $grammar_c = $grammar->thin();
1110  
1111 1146 ▶ if ( $parser->{in_prefix} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->{"in_prefix"}) 135 1011 1146
1112 135 ▶ if ( grep { $_ eq 'target_start_marker' }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "target_start_marker";} @{$$parser{"terminals_expected"};}) 135 0 135
1113 135 @{ $parser->{terminals_expected} } )
1114 {
1115 135 $recce->alternative('target_start_marker');
1116 }
1117 135 $recce->alternative('non_perl_token');
1118 } ## end if ( $parser->{in_prefix} )
1119 1146 my $event_count = $recce_c->earleme_complete();
1120 1146 $parser->{terminals_expected} = $recce->terminals_expected();
1121 1146 EVENT: for my $event_ix ( 0 .. $event_count - 1 ) {
1122 0 my ( $event_type, $value ) = $grammar_c->event($event_ix);
1123 0 ▶ next EVENT if $event_type eq 'MARPA_EVENT_EXHAUSTED';
Branch: 1 branch
BranchTrueFalseTotal
if $event_type eq "MARPA_EVENT_EXHAUSTED" 0 0 0
1124 0 ▶ if ( $event_type eq 'MARPA_EVENT_EARLEY_ITEM_THRESHOLD' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event_type eq "MARPA_EVENT_EARLEY_ITEM_THRESHOLD") 0 0 0
1125 say {
1126 0 ▶ $recce->[Marpa::R2::Internal::Recognizer::TRACE_FILE_HANDLE] }
Branch: 1 branch
BranchTrueFalseTotal
say {$recce->[9];} "Earley item count ($value) exceeds warning threshold" or die "say: $Marpa::R2::Internal::Perl::ERRNO" 0 0 0
1127 "Earley item count ($value) exceeds warning threshold"
1128 or die "say: $ERRNO";
1129 0 next EVENT;
1130 } ## end if ( $event_type eq 'MARPA_EVENT_EARLEY_ITEM_THRESHOLD')
1131 Marpa::R2::exception(
1132 0 qq{Unknown earleme completion event; type="$event_type"});
1133 } ## end EVENT: for my $event_ix ( 0 .. $event_count - 1 )
1134  
1135 1146 return $event_count;
1136  
1137 } ## end sub Marpa::R2::Perl::earleme_complete
1138  
1139 sub read_PPI_token {
1140 1495 ▶ my ( $parser, $token_ix ) = @_;
Subroutine read_PPI_token: called CC=75 SCAR=55.1
1141 1495 my $recce = $parser->{recce};
1142 1495 my $token = $parser->{PPI_tokens}->[$token_ix];
1143 1495 my $PPI_type = ref $token;
1144 1495 ▶ return 1 if $PPI_type eq 'PPI::Token::Whitespace';
Branch: 1 branch
BranchTrueFalseTotal
if $PPI_type eq "PPI::Token::Whitespace" 498 997 1495
1145 997 ▶ return 1 if $PPI_type eq 'PPI::Token::Comment';
Branch: 1 branch
BranchTrueFalseTotal
if $PPI_type eq "PPI::Token::Comment" 0 997 997
1146 997 ▶ return 1 if $PPI_type eq 'PPI::Token::Pod';
Branch: 1 branch
BranchTrueFalseTotal
if $PPI_type eq "PPI::Token::Pod" 0 997 997
1147  
1148 997 my $perl_type = undef;
1149  
1150 997 ▶ if ( $PPI_type eq 'PPI::Token::Symbol' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI_type eq "PPI::Token::Symbol") 72 925 997
1151 my ( $sigil, $word ) =
1152 72 ( $token->{content} =~ / \A ([&*\$@%]) ([':\w]*) \z /xms );
1153 72 ▶ if ( not defined $sigil ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sigil) 0 72 72
1154 0 Carp::croak( 'Unknown symbol type: ',
1155 Data::Dumper::Dumper($token) );
1156 0 goto SUCCESS;
1157 }
1158 72 my $symbol_name = $symbol_name{$sigil};
1159 72 ▶ if ( not defined $symbol_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $symbol_name) 0 72 72
1160 0 Carp::croak( 'Unknown symbol type: ',
1161 Data::Dumper::Dumper($token) );
1162 0 goto SUCCESS;
1163 }
1164 72 ▶ defined $recce->alternative( $symbol_name, \$sigil )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($symbol_name, \$sigil) or token_not_accepted($token, $symbol_name, $sigil) 0 72 72
1165 or token_not_accepted( $token, $symbol_name, $sigil );
1166 72 $parser->earleme_complete();
1167 72 ▶ defined $recce->alternative( 'WORD', \$word )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative("WORD", \$word) or token_not_accepted($token, "WORD", $word) 0 72 72
1168 or token_not_accepted( $token, 'WORD', $word );
1169 72 $parser->earleme_complete();
1170 72 goto SUCCESS;
1171 } ## end if ( $PPI_type eq 'PPI::Token::Symbol' )
1172  
1173 925 ▶ if ( $PPI_type eq 'PPI::Token::Cast' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI_type eq "PPI::Token::Cast") 30 895 925
1174 30 my $content = $token->{content};
1175 30 my $token_found;
1176 30 for my $cast ( split //xms, $content ) {
1177 30 $perl_type = $perl_type_by_cast{$content};
1178 30 ▶ defined $perl_type or unknown_ppi_token($token);
Branch: 1 branch
BranchTrueFalseTotal
defined $perl_type or unknown_ppi_token($token) 0 30 30
1179 30 ▶ if ( defined $perl_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $perl_type) 30 0 30
1180 30 $token_found = 1;
1181 30 ▶ defined $recce->alternative( $perl_type, \$cast )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($perl_type, \$cast) or token_not_accepted($token, $perl_type, $cast) 0 30 30
1182 or token_not_accepted( $token, $perl_type, $cast );
1183 30 $parser->earleme_complete();
1184 } ## end if ( defined $perl_type )
1185 } ## end for my $cast ( split //xms, $content )
1186 30 ▶ defined $token_found or unknown_ppi_token($token);
Branch: 1 branch
BranchTrueFalseTotal
defined $token_found or unknown_ppi_token($token) 0 30 30
1187 30 goto SUCCESS;
1188 } ## end if ( $PPI_type eq 'PPI::Token::Cast' )
1189  
1190 895 ▶ if ( $PPI_type eq 'PPI::Token::Word' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI_type eq "PPI::Token::Word") 138 757 895
1191 138 my $content = $token->{content};
1192 138 ▶ $perl_type = $perl_type_by_word{$content} // 'WORD';
Condition100%2/2
$perl_type_by_word{$content} // "WORD"
l!l
4593
MC/DC100%1/1
$perl_type_by_word{$content} // "WORD"
$perl_type_by_word{$content}
Truth table100%2/2
A
A= $perl_type_by_word{$content}
Aresult
11
00
1193 138 ▶ if ( $perl_type eq 'WORD' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_type eq "WORD") 93 45 138
1194 93 my $token_found = 0;
1195 93 TYPE: for my $type (qw(WORD FUNC METHOD FUNCMETH)) {
1196 372 ▶ defined $recce->alternative( $type, \$content, 1 )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($type, \$content, 1) and ++$token_found 284 88 372
1197 and $token_found++;
1198 }
1199 $token_found
1200 93 ▶ or token_not_accepted( $token, 'WORD', $content, 1 );
Branch: 1 branch
BranchTrueFalseTotal
$token_found or token_not_accepted($token, "WORD", $content, 1) 4 89 93
1201 93 $parser->earleme_complete();
1202 93 goto SUCCESS;
1203 } ## end if ( $perl_type eq 'WORD' )
1204 45 ▶ if ( $perl_type eq 'PHASER' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_type eq "PHASER") 0 45 45
1205 0 ▶ defined $recce->alternative('SUB')
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative("SUB") or token_not_accepted($token, "PHASER", "no value") 0 0 0
1206 or token_not_accepted( $token, 'PHASER', 'no value' );
1207 0 $parser->earleme_complete();
1208 0 ▶ defined $recce->alternative( 'WORD', \$content )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative("WORD", \$content) or token_not_accepted($token, "WORD", $content) 0 0 0
1209 or token_not_accepted( $token, 'WORD', $content );
1210 0 $parser->earleme_complete();
1211 0 goto SUCCESS;
1212 } ## end if ( $perl_type eq 'PHASER' )
1213 45 ▶ defined $recce->alternative( $perl_type, \$content )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($perl_type, \$content) or token_not_accepted($token, $perl_type, $content) 0 45 45
1214 or token_not_accepted( $token, $perl_type, $content );
1215 45 $parser->earleme_complete();
1216 45 goto SUCCESS;
1217 } ## end if ( $PPI_type eq 'PPI::Token::Word' )
1218  
1219 757 ▶ if ( $PPI_type eq 'PPI::Token::Label' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI_type eq "PPI::Token::Label") 2 755 757
1220 2 my $content = $token->{content};
1221 2 ▶ defined $recce->alternative( 'LABEL', \$content )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative("LABEL", \$content) or token_not_accepted($token, "LABEL", $content) 1 1 2
1222 or token_not_accepted( $token, 'LABEL', $content );
1223 2 $parser->earleme_complete();
1224 2 goto SUCCESS;
1225 } ## end if ( $PPI_type eq 'PPI::Token::Label' )
1226  
1227 755 ▶ if ( $PPI_type eq 'PPI::Token::Operator' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI_type eq "PPI::Token::Operator") 171 584 755
1228 171 my $content = $token->{content};
1229 171 $perl_type = $perl_type_by_op{$content};
1230 171 ▶ if (not defined $perl_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $perl_type) 0 171 171
1231 0 unknown_ppi_token($token);
1232 0 $parser->earleme_complete();
1233 0 goto SUCCESS;
1234 }
1235 171 ▶ if ( $perl_type eq 'PLUS' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_type eq "PLUS") 3 168 171
1236  
1237 # Apply the "ruby slippers"
1238 # Make the plus sign be whatever the parser
1239 # wishes it was
1240 3 my @potential_types = qw(ADDOP PLUS);
1241 3 my $expected_tokens = $parser->{terminals_expected};
1242 3 my $token_found;
1243 3 TYPE: for my $type (@potential_types) {
1244 6 ▶ next TYPE if not grep { $_ eq $type } @{$expected_tokens};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $type;} @{$expected_tokens;} 3 3 6
1245 3 $token_found = 1;
1246 3 ▶ defined $recce->alternative( $type, \$content, 1 )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($type, \$content, 1) or token_not_accepted($token, $type, $content, 1) 0 3 3
1247 or token_not_accepted( $token, $type, $content, 1 );
1248 } ## end TYPE: for my $type (@potential_types)
1249 3 ▶ defined $token_found or unknown_ppi_token($token);
Branch: 1 branch
BranchTrueFalseTotal
defined $token_found or unknown_ppi_token($token) 0 3 3
1250 3 $parser->earleme_complete();
1251 3 goto SUCCESS;
1252 } ## end if ( $perl_type eq 'PLUS' )
1253  
1254 168 ▶ if ( $perl_type eq 'MINUS' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_type eq "MINUS") 0 168 168
1255  
1256 # Apply the "ruby slippers"
1257 # Make the plus sign be whatever the parser
1258 # wishes it was
1259 0 my $expected_tokens = $parser->{terminals_expected};
1260 0 my @potential_types = qw(ADDOP UMINUS);
1261 0 my $token_found;
1262 0 TYPE: for my $type (@potential_types) {
1263 0 ▶ next TYPE if not grep { $_ eq $type } @{$expected_tokens};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $type;} @{$expected_tokens;} 0 0 0
1264 0 $token_found = 1;
1265 0 ▶ defined $recce->alternative( $type, \$content, 1 )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($type, \$content, 1) or token_not_accepted($token, $type, $content, 1) 0 0 0
1266 or token_not_accepted( $token, $type, $content, 1 );
1267 } ## end TYPE: for my $type (@potential_types)
1268 0 ▶ defined $token_found or unknown_ppi_token($token);
Branch: 1 branch
BranchTrueFalseTotal
defined $token_found or unknown_ppi_token($token) 0 0 0
1269 0 $parser->earleme_complete();
1270 0 goto SUCCESS;
1271 } ## end if ( $perl_type eq 'MINUS' )
1272 168 ▶ defined $recce->alternative( $perl_type, \$content )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($perl_type, \$content) or token_not_accepted($token, $perl_type, $content) 20 148 168
1273 or token_not_accepted( $token, $perl_type, $content );
1274 166 $parser->earleme_complete();
1275 166 goto SUCCESS;
1276 } ## end if ( $PPI_type eq 'PPI::Token::Operator' )
1277  
1278 584 ▶ if ( $PPI_type eq 'PPI::Token::Structure' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI_type eq "PPI::Token::Structure") 351 233 584
1279 351 my $content = $token->{content};
1280 351 $perl_type = $perl_type_by_structure{$content};
1281 351 my $expected_tokens = $parser->{terminals_expected};
1282 351 ▶ if ( not defined $perl_type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $perl_type) 0 351 351
1283 0 unknown_ppi_token($token);
1284 0 $parser->earleme_complete();
1285 0 goto SUCCESS;
1286 }
1287 351 ▶ if ( $perl_type eq 'RCURLY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_type eq "RCURLY") 81 270 351
1288 81 ▶ if (( not defined $Marpa::R2::Perl::LAST_PERL_TYPE
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($Marpa::R2::Perl::LAST_PERL_TYPE) || $Marpa::R2::Perl::LAST_PERL_TYPE ne "SEMI" and grep {"SEMI" eq $_;} @{$expected_tokens;}) 81 0 81
Condition50%3/6
!defined($Marpa::R2::Perl::LAST_PERL_TYPE) || $Marpa::R2::Perl::LAST_PERL_TYPE ne "SEMI" and grep {"SEMI" eq $_;} @{$expected_tokens;}
!ll&&!rl&&r
0081
not defined $Marpa::R2::Perl::LAST_PERL_TYPE or $Marpa::R2::Perl::LAST_PERL_TYPE ne "SEMI"
l!l&&r!l&&!r
46350
MC/DC0%0/3
!defined($Marpa::R2::Perl::LAST_PERL_TYPE) || $Marpa::R2::Perl::LAST_PERL_TYPE ne "SEMI" and grep {"SEMI" eq $_;} @{$expected_tokens;}
not defined $Marpa::R2::Perl::LAST_PERL_TYPE $Marpa::R2::Perl::LAST_PERL_TYPE ne "SEMI" grep {"SEMI" eq $_;} @{$expected_tokens;}
Truth table40%2/5
not(A) or B and C
A= not defined $Marpa::R2::Perl::LAST_PERL_TYPEB= $Marpa::R2::Perl::LAST_PERL_TYPE ne "SEMI"C= grep {"SEMI" eq $_;} @{$expected_tokens;}
ABCresult
00X0
1X00
0100
1X11
0111
1289 or $Marpa::R2::Perl::LAST_PERL_TYPE ne 'SEMI'
1290 )
1291 2517 and ( grep { 'SEMI' eq $_ } @{$expected_tokens} )
1292 )
1293 {
1294 81 ▶ defined $recce->alternative( 'SEMI', \q{;} )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative("SEMI", \";") or token_not_accepted($token, "SEMI", ";") 0 81 81
1295 or token_not_accepted( $token, 'SEMI', q{;} );
1296 81 $parser->earleme_complete();
1297 } ## end if ( ( not defined $Marpa::R2::Perl::LAST_PERL_TYPE ...))
1298 81 ▶ defined $recce->alternative( $perl_type, \$content )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($perl_type, \$content) or token_not_accepted($token, $perl_type, $content) 0 81 81
1299 or token_not_accepted( $token, $perl_type, $content );
1300 81 $parser->earleme_complete();
1301 81 goto SUCCESS;
1302 } ## end if ( $perl_type eq 'RCURLY' )
1303 270 ▶ if ( $perl_type eq 'LCURLY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_type eq "LCURLY") 81 189 270
1304 81 my @potential_types = ();
1305 81 push @potential_types, 'LCURLY';
1306 81 ▶ if ( not defined $Marpa::R2::Perl::LAST_PERL_TYPE
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $Marpa::R2::Perl::LAST_PERL_TYPE or $Marpa::R2::Perl::LAST_PERL_TYPE ne "DO") 74 7 81
Condition100%3/3
not defined $Marpa::R2::Perl::LAST_PERL_TYPE or $Marpa::R2::Perl::LAST_PERL_TYPE ne "DO"
l!l&&r!l&&!r
8667
MC/DC100%2/2
not defined $Marpa::R2::Perl::LAST_PERL_TYPE or $Marpa::R2::Perl::LAST_PERL_TYPE ne "DO"
not defined $Marpa::R2::Perl::LAST_PERL_TYPE $Marpa::R2::Perl::LAST_PERL_TYPE ne "DO"
Truth table100%3/3
not(A) or B
A= not defined $Marpa::R2::Perl::LAST_PERL_TYPEB= $Marpa::R2::Perl::LAST_PERL_TYPE ne "DO"
ABresult
1X1
011
000
1307 or $Marpa::R2::Perl::LAST_PERL_TYPE ne 'DO' )
1308 {
1309 74 push @potential_types, 'HASHBRACK';
1310 }
1311 81 my $token_found;
1312 81 TYPE: for my $type (@potential_types) {
1313 155 ▶ next TYPE if not grep { $type eq $_ } @{$expected_tokens};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$type eq $_;} @{$expected_tokens;} 53 102 155
1314 102 $token_found = 1;
1315 102 ▶ defined $recce->alternative( $type, \$content, 1 )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($type, \$content, 1) or token_not_accepted($token, $type, $content, 1) 0 102 102
1316 or token_not_accepted( $token, $type, $content, 1 );
1317 } ## end TYPE: for my $type (@potential_types)
1318 81 ▶ defined $token_found or unknown_ppi_token($token);
Branch: 1 branch
BranchTrueFalseTotal
defined $token_found or unknown_ppi_token($token) 0 81 81
1319 81 $parser->earleme_complete();
1320 81 goto SUCCESS;
1321 } ## end if ( $perl_type eq 'LCURLY' )
1322 189 ▶ defined $recce->alternative( $perl_type, \$content )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($perl_type, \$content) or token_not_accepted($token, $perl_type, $content) 0 189 189
1323 or token_not_accepted( $token, $perl_type, $content );
1324 189 $parser->earleme_complete();
1325 189 goto SUCCESS;
1326 } ## end if ( $PPI_type eq 'PPI::Token::Structure' )
1327  
1328 233 ▶ if ( $PPI_type eq 'PPI::Token::Number'
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI_type eq "PPI::Token::Number" or $PPI_type eq "PPI::Token::Number::Float" or $PPI_type eq "PPI::Token::Magic" or $PPI_type eq "PPI::Token::Number::Version") 7 54 61
Condition88%8/9
$PPI_type eq "PPI::Token::Number" or $PPI_type eq "PPI::Token::Number::Float" or $PPI_type eq "PPI::Token::Magic" or $PPI_type eq "PPI::Token::Number::Version"
l!l&&r!l&&!r
172754
$PPI_type eq "PPI::Token::Number" or $PPI_type eq "PPI::Token::Number::Float" or $PPI_type eq "PPI::Token::Magic"
l!l&&r!l&&!r
172061
$PPI_type eq "PPI::Token::Number" or $PPI_type eq "PPI::Token::Number::Float"
l!l&&r!l&&!r
164861
MC/DC75%3/4
$PPI_type eq "PPI::Token::Number" or $PPI_type eq "PPI::Token::Number::Float" or $PPI_type eq "PPI::Token::Magic" or $PPI_type eq "PPI::Token::Number::Version"
$PPI_type eq "PPI::Token::Number" $PPI_type eq "PPI::Token::Number::Float" $PPI_type eq "PPI::Token::Magic" $PPI_type eq "PPI::Token::Number::Version"
Truth table80%4/5
A or B or C or D
A= $PPI_type eq "PPI::Token::Number"B= $PPI_type eq "PPI::Token::Number::Float"C= $PPI_type eq "PPI::Token::Magic"D= $PPI_type eq "PPI::Token::Number::Version"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1329 or $PPI_type eq 'PPI::Token::Number::Float'
1330 or $PPI_type eq 'PPI::Token::Magic'
1331 or $PPI_type eq 'PPI::Token::Number::Version' )
1332 {
1333 179 my $content = $token->{content};
1334 179 my $token_found = 0;
1335 179 TYPE: for my $type (qw(THING VERSION)) {
1336 358 ▶ defined $recce->alternative( $type, \$content, 1 )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative($type, \$content, 1) and ++$token_found 187 171 358
1337 and $token_found++;
1338 }
1339 179 ▶ $token_found or token_not_accepted( $token, 'THING', $content );
Branch: 1 branch
BranchTrueFalseTotal
$token_found or token_not_accepted($token, "THING", $content) 2 177 179
1340 177 $parser->earleme_complete();
1341 177 goto SUCCESS;
1342 } ## end if ( $PPI_type eq 'PPI::Token::Number' or $PPI_type ...)
1343  
1344 54 ▶ if ( $PPI_type eq 'PPI::Token::Quote::Single'
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI_type eq "PPI::Token::Quote::Single" or $PPI_type eq "PPI::Token::Quote::Double" or $PPI_type eq "PPI::Token::Quote::Literal" or $PPI_type eq "PPI::Token::Quote::Interpolate" or $PPI_type eq "PPI::Token::HereDoc" or $PPI_type eq "PPI::Token::Regexp::Match" or $PPI_type eq "PPI::Token::Regexp::Substitute" or $PPI_type eq "PPI::Token::Regexp::Transliterate" or $PPI_type eq "PPI::Token::Magic") 0 0 0
Condition33%8/24
$PPI_type eq "PPI::Token::Quote::Single" or $PPI_type eq "PPI::Token::Quote::Double" or $PPI_type eq "PPI::Token::Quote::Literal" or $PPI_type eq "PPI::Token::Quote::Interpolate" or $PPI_type eq "PPI::Token::HereDoc" or $PPI_type eq "PPI::Token::Regexp::Match" or $PPI_type eq "PPI::Token::Regexp::Substitute" or $PPI_type eq "PPI::Token::Regexp::Transliterate" or $PPI_type eq "PPI::Token::Magic"
l!l&&r!l&&!r
5400
$PPI_type eq "PPI::Token::Quote::Single" or $PPI_type eq "PPI::Token::Quote::Double" or $PPI_type eq "PPI::Token::Quote::Literal" or $PPI_type eq "PPI::Token::Quote::Interpolate" or $PPI_type eq "PPI::Token::HereDoc" or $PPI_type eq "PPI::Token::Regexp::Match" or $PPI_type eq "PPI::Token::Regexp::Substitute" or $PPI_type eq "PPI::Token::Regexp::Transliterate"
l!l&&r!l&&!r
5400
$PPI_type eq "PPI::Token::Quote::Single" or $PPI_type eq "PPI::Token::Quote::Double" or $PPI_type eq "PPI::Token::Quote::Literal" or $PPI_type eq "PPI::Token::Quote::Interpolate" or $PPI_type eq "PPI::Token::HereDoc" or $PPI_type eq "PPI::Token::Regexp::Match" or $PPI_type eq "PPI::Token::Regexp::Substitute"
l!l&&r!l&&!r
5400
$PPI_type eq "PPI::Token::Quote::Single" or $PPI_type eq "PPI::Token::Quote::Double" or $PPI_type eq "PPI::Token::Quote::Literal" or $PPI_type eq "PPI::Token::Quote::Interpolate" or $PPI_type eq "PPI::Token::HereDoc" or $PPI_type eq "PPI::Token::Regexp::Match"
l!l&&r!l&&!r
5400
$PPI_type eq "PPI::Token::Quote::Single" or $PPI_type eq "PPI::Token::Quote::Double" or $PPI_type eq "PPI::Token::Quote::Literal" or $PPI_type eq "PPI::Token::Quote::Interpolate" or $PPI_type eq "PPI::Token::HereDoc"
l!l&&r!l&&!r
5400
$PPI_type eq "PPI::Token::Quote::Single" or $PPI_type eq "PPI::Token::Quote::Double" or $PPI_type eq "PPI::Token::Quote::Literal" or $PPI_type eq "PPI::Token::Quote::Interpolate"
l!l&&r!l&&!r
5400
$PPI_type eq "PPI::Token::Quote::Single" or $PPI_type eq "PPI::Token::Quote::Double" or $PPI_type eq "PPI::Token::Quote::Literal"
l!l&&r!l&&!r
5400
$PPI_type eq "PPI::Token::Quote::Single" or $PPI_type eq "PPI::Token::Quote::Double"
l!l&&r!l&&!r
5400
MC/DC0%0/9
$PPI_type eq "PPI::Token::Quote::Single" or $PPI_type eq "PPI::Token::Quote::Double" or $PPI_type eq "PPI::Token::Quote::Literal" or $PPI_type eq "PPI::Token::Quote::Interpolate" or $PPI_type eq "PPI::Token::HereDoc" or $PPI_type eq "PPI::Token::Regexp::Match" or $PPI_type eq "PPI::Token::Regexp::Substitute" or $PPI_type eq "PPI::Token::Regexp::Transliterate" or $PPI_type eq "PPI::Token::Magic"
$PPI_type eq "PPI::Token::Quote::Single" $PPI_type eq "PPI::Token::Quote::Double" $PPI_type eq "PPI::Token::Quote::Literal" $PPI_type eq "PPI::Token::Quote::Interpolate" $PPI_type eq "PPI::Token::HereDoc" $PPI_type eq "PPI::Token::Regexp::Match" $PPI_type eq "PPI::Token::Regexp::Substitute" $PPI_type eq "PPI::Token::Regexp::Transliterate" $PPI_type eq "PPI::Token::Magic"
Truth table10%1/10
A or B or C or D or E or F or G or H or I
A= $PPI_type eq "PPI::Token::Quote::Single"B= $PPI_type eq "PPI::Token::Quote::Double"C= $PPI_type eq "PPI::Token::Quote::Literal"D= $PPI_type eq "PPI::Token::Quote::Interpolate"E= $PPI_type eq "PPI::Token::HereDoc"F= $PPI_type eq "PPI::Token::Regexp::Match"G= $PPI_type eq "PPI::Token::Regexp::Substitute"H= $PPI_type eq "PPI::Token::Regexp::Transliterate"I= $PPI_type eq "PPI::Token::Magic"
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
1345 or $PPI_type eq 'PPI::Token::Quote::Double'
1346 or $PPI_type eq 'PPI::Token::Quote::Literal'
1347 or $PPI_type eq 'PPI::Token::Quote::Interpolate'
1348 or $PPI_type eq 'PPI::Token::HereDoc'
1349 or $PPI_type eq 'PPI::Token::Regexp::Match'
1350 or $PPI_type eq 'PPI::Token::Regexp::Substitute'
1351 or $PPI_type eq 'PPI::Token::Regexp::Transliterate'
1352 or $PPI_type eq 'PPI::Token::Magic')
1353 {
1354 54 my $content = $token->{content};
1355 54 ▶ defined $recce->alternative( 'THING', \$content )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative("THING", \$content) or token_not_accepted($token, "THING", $content) 0 54 54
1356 or token_not_accepted( $token, 'THING', $content );
1357 54 $parser->earleme_complete();
1358 54 goto SUCCESS;
1359 } ## end if ( $PPI_type eq 'PPI::Token::Quote::Single' or $PPI_type...)
1360  
1361 0 ▶ if ( $PPI_type eq 'PPI::Token::QuoteLike::Words' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI_type eq "PPI::Token::QuoteLike::Words") 0 0 0
1362 0 my $content = $token->{content};
1363 0 my $words = $token->literal();
1364 0 ▶ defined $recce->alternative( 'THING', \$words )
Branch: 1 branch
BranchTrueFalseTotal
defined $recce->alternative("THING", \$words) or token_not_accepted($token, "THING", $words) 0 0 0
1365 or token_not_accepted( $token, 'THING', $words );
1366 0 $parser->earleme_complete();
1367 0 goto SUCCESS;
1368 } ## end if ( $PPI_type eq 'PPI::Token::QuoteLike::Words' )
1369  
1370 0 unknown_ppi_token($token);
1371  
1372 993 SUCCESS:
1373 $Marpa::R2::Perl::LAST_PERL_TYPE = $perl_type;
1374 993 return 1;
1375  
1376 } ## end sub read_PPI_token
1377  
1378 sub Marpa::R2::Perl::find_perl {
1379  
1380 5 ▶ my ( $parser, $first_token_ix, $last_token_ix ) = @_;
Subroutine find_perl: called CC=20 SCAR=30.7
Pod undocumented
1381  
1382 5 my $grammar = $parser->{grammar};
1383  
1384 5 my $recce = Marpa::R2::Recognizer->new(
1385 { grammar => $grammar,
1386 ranking_method => 'high_rule_only',
1387 }
1388 );
1389 5 $parser->{recce} = $recce;
1390 5 $parser->{terminals_expected} = $recce->terminals_expected();
1391 5 my $earleme_to_PPI_token = $parser->{earleme_to_PPI_token} = ();
1392  
1393 # This is convenient for making the recognizer available to
1394 # error messages
1395 5 local $Marpa::R2::Perl::PARSER = $parser;
1396  
1397 5 my $PPI_tokens = $parser->{PPI_tokens};
1398 5 my @PPI_token_to_earleme = ();
1399  
1400 # For use by read_PPI_token
1401 5 local $Marpa::R2::Perl::LAST_PERL_TYPE = undef;
1402 5 ▶ die 'find_perl requires embedded parser' if not $parser->{embedded};
Branch: 1 branch
BranchTrueFalseTotal
unless $parser->{"embedded"} 0 5 5
1403 5 my $in_prefix = $parser->{in_prefix} = 1;
1404 5 my $last_end_marker_ix;
1405 my $last_end_marker_earleme;
1406  
1407 5 ▶ $last_token_ix //= $#{$PPI_tokens};
Condition33%1/3
$last_token_ix //= $#{$PPI_tokens;}
l!l&&r!l&&!r
050
MC/DC0%0/2
$last_token_ix //= $#{$PPI_tokens;}
$last_token_ix $#{$PPI_tokens;}
Truth table33%1/3
A //= B
A= $last_token_ixB= $#{$PPI_tokens;}
ABresult
1X1
011
000
1408 5 my $PPI_token_ix;
1409 TOKEN:
1410 5 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI_token_ix <= $last_token_ix) 293 1 294
Condition50%1/2
$first_token_ix // 0
l!l
50
MC/DC0%0/1
$first_token_ix // 0
$first_token_ix
Truth table50%1/2
A
A= $first_token_ix
Aresult
11
00
1411 $PPI_token_ix = $first_token_ix // 0;
1412 $PPI_token_ix <= $last_token_ix;
1413 $PPI_token_ix++
1414 )
1415 {
1416 293 ▶ if ($recce->exhausted())
Branch: 1 branch
BranchTrueFalseTotal
if ($recce->exhausted) 0 293 293
1417 {
1418 0 ▶ die 'Exhausted but no program found\?' if not defined $last_end_marker_ix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $last_end_marker_ix 0 0 0
1419 0 last TOKEN;
1420 }
1421 293 my $current_earleme = $recce->current_earleme();
1422 293 ▶ $earleme_to_PPI_token->[$current_earleme] //= $PPI_token_ix;
Condition66%2/3
$earleme_to_PPI_token->[$current_earleme] //= $PPI_token_ix
l!l&&r!l&&!r
991940
MC/DC0%0/2
$earleme_to_PPI_token->[$current_earleme] //= $PPI_token_ix
$earleme_to_PPI_token->[$current_earleme] $PPI_token_ix
Truth table66%2/3
A //= B
A= $earleme_to_PPI_token->[$current_earleme]B= $PPI_token_ix
ABresult
1X1
011
000
1423 293 $PPI_token_to_earleme[$PPI_token_ix] = $current_earleme;
1424 293 $parser->{token_issues} = [];
1425 293 eval { read_PPI_token( $parser, $PPI_token_ix ); };
1426 293 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Marpa::R2::Internal::Perl::EVAL_ERROR) 4 289 293
1427 4 ▶ die $EVAL_ERROR if $EVAL_ERROR ne "TOKEN_NOT_ACCEPTED\n";
Branch: 1 branch
BranchTrueFalseTotal
if $Marpa::R2::Internal::Perl::EVAL_ERROR ne "TOKEN_NOT_ACCEPTED\n" 0 4 4
1428 4 last TOKEN;
1429 }
1430 289 my $terminals_expected = $parser->{terminals_expected};
1431 289 ▶ if ( grep { $_ eq 'non_trivial_target_end' } @{$terminals_expected} )
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "non_trivial_target_end";} @{$terminals_expected;}) 15 274 289
1432 {
1433 15 $in_prefix = $parser->{in_prefix} = 0;
1434 15 $last_end_marker_ix = $PPI_token_ix;
1435 15 $last_end_marker_earleme = $recce->current_earleme();
1436 } ## end if ( grep { $_ eq 'non_trivial_target_end' } @{...})
1437 289 ▶ if ( defined $last_end_marker_earleme
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_end_marker_earleme and grep {$_ eq "target_end_marker";} @{$terminals_expected;}) 15 274 289
Condition100%3/3
defined $last_end_marker_earleme and grep {$_ eq "target_end_marker";} @{$terminals_expected;}
!ll&&!rl&&r
2175715
MC/DC100%2/2
defined $last_end_marker_earleme and grep {$_ eq "target_end_marker";} @{$terminals_expected;}
defined $last_end_marker_earleme grep {$_ eq "target_end_marker";} @{$terminals_expected;}
Truth table100%3/3
A and B
A= defined $last_end_marker_earlemeB= grep {$_ eq "target_end_marker";} @{$terminals_expected;}
ABresult
0X0
100
111
1438 3219 && grep { $_ eq 'target_end_marker' } @{$terminals_expected} )
1439 {
1440 15 $last_end_marker_ix = $PPI_token_ix;
1441 15 $last_end_marker_earleme = $recce->current_earleme();
1442 } ## end if ( defined $last_end_marker_earleme && grep { $_ eq...})
1443 } ## end for ( $PPI_token_ix = $first_token_ix // 0; $PPI_token_ix...)
1444  
1445 # We are one past the last token successfully parsed
1446 5 $PPI_token_ix--;
1447  
1448 5 $recce->end_input();
1449  
1450 5 ▶ return (undef, $PPI_token_ix) if not defined $last_end_marker_earleme;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $last_end_marker_earleme 1 4 5
1451 4 my $report = $recce->progress($last_end_marker_earleme);
1452 4 my $start;
1453 4 ITEM: for my $item (@{$report}) {
1454 1200 my ($rule_id, $dot_position, $origin) = @{$item};
1455 1200 ▶ next ITEM if $dot_position >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $dot_position >= 0 1021 179 1200
1456 179 ▶ next ITEM if ($grammar->rule($rule_id))[0] ne 'prog';
Branch: 1 branch
BranchTrueFalseTotal
if ($grammar->rule($rule_id))[0] ne "prog" 175 4 179
1457 4 ▶ $start //= $origin;
Condition33%1/3
$start //= $origin
l!l&&r!l&&!r
040
MC/DC0%0/2
$start //= $origin
$start $origin
Truth table33%1/3
A //= B
A= $startB= $origin
ABresult
1X1
011
000
1458 4 ▶ $start = $origin if $start > $origin;
Branch: 1 branch
BranchTrueFalseTotal
if $start > $origin 0 4 4
1459 }
1460 4 ▶ die 'End marker, but no Perl prog?' if not defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 4 4
1461 4 my $start_PPI_ix = $earleme_to_PPI_token->[$start];
1462 4 return ($start_PPI_ix, $last_end_marker_ix);
1463  
1464 } ## end sub Marpa::R2::Perl::find_perl
1465  
1466 sub Marpa::R2::Perl::eval {
1467 17 ▶ my ($parser) = @_;
Subroutine eval: called CC=3 SCAR=11.0
Pod undocumented
1468 17 my $recce = $parser->{recce};
1469 local $Marpa::R2::Perl::Internal::CONTEXT =
1470 17 [ $parser->{PPI_tokens}, $parser->{earleme_to_PPI_token} ];
1471 17 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 4 13 17
1472 4 my @values = ();
1473 4 ▶ while ( defined( my $value_ref = $recce->value() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value_ref = $recce->value)) 5 4 9
1474 5 push @values, ${$value_ref};
1475 }
1476 4 return @values;
1477 } ## end if (wantarray)
1478 13 my $value_ref = $recce->value();
1479 13 return $value_ref;
1480 } ## end sub Marpa::R2::Perl::eval
1481  
1482 sub Marpa::R2::Perl::parse {
1483 12 ▶ my ( $parser, $input, $hash_arg ) = @_;
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
1484 12 $parser->Marpa::R2::Perl::read( $input, $hash_arg );
1485 12 return $parser->Marpa::R2::Perl::eval();
1486 }
1487  
1488 sub Marpa::R2::Perl::default_show_location {
1489 0 ▶ my ($token) = @_;
Subroutine default_show_location: not called CC=2 SCAR=17.9
Pod undocumented
1490 0 my $file_name = $token->logical_filename();
1491 0 ▶ my $file_description = $file_name ? qq{ file "$file_name"} : q{};
Branch: 1 branch
BranchTrueFalseTotal
$file_name ? : 0 0 0
1492 return
1493 0 "$file_description at line "
1494 . $token->logical_line_number()
1495 . q{, column }
1496 . $token->column_number();
1497 } ## end sub Marpa::R2::Perl::default_show_location
1498  
1499 4 1;
1500  
1501 # vim: set expandtab shiftwidth=4:
« blib/lib/Marpa/R2/MetaAST.pm ↑ Summary blib/lib/Marpa/R2/Recognizer.pm »