Highlife/Rule/Repetition.pm

filter: Statementstmt 27.7% 10 / 36 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 2 totaltotal 22.8% 13 / 57 CC 5 SCAR 27.5
CC
5
Cov
22%
parse_from_token
30.0
new
2.0
_init
2.0
CRAP 15.7
« Highlife/Utils.pm ↑ Summary Highlife/Rule/Choice.pm »
1 package Parse::Highlife::Rule::Repetition;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw(Parse::Highlife::Rule);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Parse::Highlife::Utils qw(params);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub new
8 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
9 0 my( $class, @args ) = @_;
10 0 my $self = bless Parse::Highlife::Rule->new( @args ), $class;
11 0 return $self -> _init( @args );
12 }
13  
14 sub _init
15 0 ▶{
Subroutine _init: not called CC=1 SCAR=6.9
16 0 my( $self, $repetition, $min, $max )
17 = params( \@_,
18 -repetition => '',
19 -min => 0,
20 -max => 0, # 0 = unlimited
21 );
22 0 $self->{'repetition'} = $repetition;
23 0 $self->{'min'} = $min;
24 0 $self->{'max'} = $max;
25 0 return $self;
26 }
27  
28 sub parse_from_token
29 0 ▶{
Subroutine parse_from_token: not called CC=5 SCAR=34.0
Pod undocumented
30 0 my( $self, $parser, $tokens, $t ) = @_;
31 # - turn list of subrules into a single SEQ() rule
32 # - try to parse SEQ() rule until failure
33 # - if no success at all: return failure, else return result
34
35 0 my $subrule = $parser->get_rule( $self->{'repetition'} );
36  
37 0 my $_t = $t;
38 0 my ($_status, $_result);
39 0 my @results;
40 0 my $n = 0;
41 0 while (1) {
42 0 my $prev_t = $_t;
43 0 ($_t) = $self->_parse_ignored_tokens( $tokens, $_t );
44 0 ($_status, $_t, $_result) = $subrule->wrap_parse_from_token( $parser, $tokens, $_t );
45 0 ▶ unless ($_status) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_status) 0 0 0
46 0 $_t = $prev_t;
47 0 last;
48 }
49 0 push @results, $_result;
50 0 $n++;
51 }
52
53 0 ▶ if( scalar @results >= $self->{'min'} &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @results >= $self->{'min'} and scalar @results <= $self->{'max'} || $self->{'max'} == 0) { } 0 0 0
Condition0%0/6
scalar @results >= $self->{"min"} and scalar @results <= $self->{"max"} || $self->{"max"} == 0
!ll&&!rl&&r
000
scalar @results <= $self->{"max"} or $self->{"max"} == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar @results >= $self->{"min"} and scalar @results <= $self->{"max"} || $self->{"max"} == 0
scalar @results >= $self->{"min"} scalar @results <= $self->{"max"} $self->{"max"} == 0
Truth table0%0/4
A and B or C
A= scalar @results >= $self->{"min"}B= scalar @results <= $self->{"max"}C= $self->{"max"} == 0
ABCresult
0XX0
1000
11X1
1011
54 ( scalar @results <= $self->{'max'} || $self->{'max'} == 0 ) ) {
55 return (
56 1,
57 $_t,
58 0 $parser->make_ast_element('group', $self->{'name'}, \@results)
59 );
60 }
61 else {
62 0 return(0,0,0);
63 }
64 }
65  
66 1 1;
« Highlife/Utils.pm ↑ Summary Highlife/Rule/Choice.pm »