| 1 | # ABSTRACT: parses TPath expressions into ASTs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package TPath::Grammar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | $TPath::Grammar::VERSION = '1.007'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 57 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 57 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 57 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 57 | ▶ | no if $] >= 5.018, warnings => "experimental"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 57 | ▶ | use POSIX qw(acos asin atan ceil floor log10 tan); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 57 | ▶ | use Math::Trig qw(pi); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 57 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 57 | ▶ | use parent qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | our @EXPORT_OK = qw(parse %AXES %FUNCTIONS %MATH_CONSTANTS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | our %AXES = map { $_ => 1 } qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | adjacent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ancestor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ancestor-or-self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | child | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | descendant | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | descendant-or-self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | following | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | following-sibling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | leaf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | preceding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | preceding-sibling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | previous | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | sibling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | sibling-or-self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # single-argument mathematical functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | our %FUNCTIONS = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | abs => sub { abs $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | acos => \&acos, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | asin => \&asin, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | atan => \&atan, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ceil => \&ceil, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | cos => sub { cos $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | exp => sub { exp $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | floor => \&floor, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | int => sub { int $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | log => sub { log $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | log10 => \&log10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | sin => sub { sin $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sqrt => sub { sqrt $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | tan => sub { tan $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | our %MATH_CONSTANTS = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | pi => pi, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | e => exp 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # map from operators to their properties; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # [<precedence>, <commutative>, <left-associative>, <dual>] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # not sure if "dual" is the right term; it's the operator one can use to reduce | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # the right operands with a non-commutative operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | our %MATH_OPERATORS = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | '+' => [ 3, 1, 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | '-' => [ 3, 0, 1, '+' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | '*' => [ 2, 1, 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | '/' => [ 2, 0, 1, '*' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | '**' => [ 1, 0, 1, '*' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | '%' => [ 2, 0, 0 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # sort these into a list for use in reducing complex mathematical expressions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | my @math_ops = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | map { my @ar = @{ $MATH_OPERATORS{$_} }; $ar[0] = $_; \@ar } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | $MATH_OPERATORS{$a}[0] <=> $MATH_OPERATORS{$b}[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | || $MATH_OPERATORS{$b}[1] <=> $MATH_OPERATORS{$a}[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | || $MATH_OPERATORS{$b}[2] <=> $MATH_OPERATORS{$a}[2] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | keys %MATH_OPERATORS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | our ( $offset, $quantifiable ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | our $path_grammar = do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | our $buffer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 57 | ▶ | use Regexp::Grammars; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | qr{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | <timeout: 10> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | \A <.ws> <treepath> <.ws> \Z | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | <rule: treepath> <[path]> (?: \| <[path]> )* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | <token: path> (?![\@'"]) <[segment]> (?: (?= / | \( <.ws> / ) <[segment]> )* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | <token: segment> (?: <separator>? <step> | <cs> ) <.ws> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | <token: quantifier> (?: <require: (?{$quantifiable}) > [?+*] | <enum> ) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | <rule: enum> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | [{] <start=(\d*+)> (?: , <end=(\d*+)> )? [}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | <require: (?{length $MATCH{start} or length $MATCH{end}})> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | <rule: grouped_step> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | \( <treepath> \) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | (?: <.ws> <[predicate]> )+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | (?{local $quantifiable = 1}) <quantifier> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | <token: id> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | :id\( ( (?>[^\)\\]|\\.)++ ) \) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | (?{ $MATCH=clean_escapes($^N) }) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | <token: cs> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | <separator>? <step> (?{local $quantifiable = 1}) <quantifier> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | | <grouped_step> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | <token: separator> \/[\/>]?+ <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | <token: step> <full> (?: <.ws> <[predicate]> )* | <abbreviated> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | <token: full> <axis>? <forward> | (?<=(?<!/)/) <previous=(:p)> <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | <token: axis> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | (?<!/[/>]) (<%AXES>) :: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | (?{ $MATCH = $^N }) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | <token: abbreviated> (?<!/[/>]) (?: \.{1,2}+ | <id> | :root ) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | <token: forward> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | <wildcard> | <complement=(\^)>? (?: <specific> | <pattern> | <attribute> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | <token: wildcard> <require: (?{!$quantifiable}) > \* <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | <token: specific> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | <name> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | (?{ $MATCH = $MATCH{name} }) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | <token: pattern> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | (~(?>[^~]|~~)++~) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | (?{ $MATCH = clean_pattern($^N) }) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | <token: aname> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | @ (?: <name> | : <name> (?{ $MATCH{autoloaded} = 1 }) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | <token: name> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | ((?>\\.|[\p{L}\$_])(?>[\p{L}\$\p{N}_]|[-.:](?=[\p{L}_\$\p{N}])|\\.)*+) (?{ $MATCH = clean_escapes($^N ) }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | | <literal> (?{ $MATCH = $MATCH{literal} }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | | (<.qname>) (?{ $MATCH = clean_escapes( substr $^N, 2, length($^N) -3 ) }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | <token: qname> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | : <.qq> <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | <token: qq> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | ([!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]) # [:punct:] excluding backslash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | (?{ local $buffer = end_punct($^N) }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | [^[:punct:]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ([[:punct:]]) (?(?{ $^N eq $buffer or $^N eq '\\' })(?!)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | \\ . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | )++ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ([!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | <require: (?{ $^N eq $buffer })> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | <rule: attribute> <aname> <args>? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | <rule: args> \( <[arg]> (?: , <[arg]> )* \) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | <token: arg> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | <v=literal> | <v=num> | <concat> | <attribute> | <treepath> | <attribute_test> | <condition> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | <rule: concat> # string concatenation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | <[carg]> (?: ~ <[carg]>)+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | <token: carg> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | <v=literal> | <v=num> | <attribute> | <treepath> | <math> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | <token: num> <.signed_int> | <.float> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | <token: signed_int> [+-]?+ <.int> <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | <token: float> [+-]?+ <.int>? \.\d++ (?: [Ee][+-]?+ <.int> )?+ <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | <token: literal> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | ((?> <.squote> | <.dquote> )) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | (?{ $MATCH = clean_literal($^N) }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | <token: squote> ' (?>[^'\\]|\\.)*+ ' <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | <token: dquote> " (?>[^"\\]|\\.)*+ " <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | <rule: predicate> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | \[ (?: <idx=signed_int> | <condition> ) \] <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | <token: int> \b(?:0|[1-9][0-9]*+)\b <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | <rule: condition> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | <[item=not]>? <[item]> (?: <[item=operator]> <[item=not]>? <[item]> )* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | <token: not> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | (?: ! | (?<=[\s\[(]) not (?=\s) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | (?: \s*+ (?: ! | (?<=\s) not (?=\s) ) )*+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | (?{$MATCH = clean_not($^N)}) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | <token: operator> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | (?: <.or> | <.xor> | <.and> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | (?{$MATCH = clean_operator($^N)}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | <token: xor> (?: ; | (?<=\s) one (?=\s) ) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | <token: and> (?: & | (?<=\s) and (?=\s) ) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | <token: or> (?: \|{2} | (?<=\s) or (?=\s) ) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | <token: term> <attribute> | <attribute_test> | <treepath> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | <rule: attribute_test> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | <[value]> (?: <cmp=([!=]~)> <[value=regex]> | <cmp> <[value]> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | <token: regex> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ( / (?:[^/\\]|\\.)++ /(?!=\w|:) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | (?{ $MATCH = clean_regex($^N) }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | :m ( <.qq> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | (?{ local $buffer = $^N }) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | ((?:[msix]+\b)?) <require: (?{ mods_test($^N) })> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | (?{ $MATCH = clean_mregex($buffer, $^N) }) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | <token: cmp> (?: [<>=]=?+ | ![=~] | =~ | =?\|= | =\| ) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | <token: value> <v=literal> | <v=num> | <concat> | <attribute> | <treepath> | <math> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | <rule: math> <function> | <[item=operand]> (?: <.ws> <[item=mop]> <[item=operand]> )* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | <token: function> :? <f=%FUNCTIONS> \( <.ws> <arg=math> <.ws> \) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | <token: mop> :? ( <%MATH_OPERATORS> ) (?{ $MATCH = $^N }) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | <token: operand> <num> | <minus=(-)>? (?: <mconst> | <attribute> | <treepath> | <mgroup> | <function> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | <token: mconst> : ( <%MATH_CONSTANTS> ) (?{ $MATCH = $^N }) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | <rule: mgroup> \( <math> \) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | <rule: group> \( <condition> \) <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | <token: item> <term> | <group> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | <token: ws> (?: \s*+ (?: \#.*? $ )?+ )*+ <.cp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | <token: cp> # "checkpoint" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | (?{ $offset = $INDEX if $INDEX > $offset }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | }xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | local $offset = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my ($expr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if ( $expr =~ $path_grammar ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $ref = \%/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | normalize_math($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | normalize_compounds($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | complement_to_boolean($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if ( contains_condition($ref) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | normalize_parens($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | operator_precedence($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | merge_conditions($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | fix_predicates($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | cull_predicates($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | optimize($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | return $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | die "could not parse '$expr' as a TPath expression; " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | . error_message( $expr, $offset ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # remove necessarily true predicates; throw errors in case of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # necessarily false predicates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub cull_predicates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cull_predicates: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | when ('ARRAY') { cull_predicates($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | cull_predicates($_) for values %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my $predicates = $ref->{predicate}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ($predicates) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | for ( my $i = $#$predicates ; $i >= 0 ; $i-- ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | my $predicate = $predicates->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | my $at = $predicate->{attribute_test}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if ( $at && is_deeply( @{ $at->{value} } ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$at and is_deeply(@{$$at{"value"};})
MC/DC0%0/2
$at and is_deeply(@{$$at{"value"};})
$at
is_deeply(@{$$at{"value"};})
Truth table0%0/3
A and B
A= $atB= is_deeply(@{$$at{"value"};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my $op = $at->{cmp}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | if ( $op =~ /(?<!!)=$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | splice @$predicates, $i; # always true | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | die 'bad predicate: [' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | . $predicate->{''} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | . ']'; # always false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | ▶ | elsif (exists $ref->{step} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
exists $ref->{"step"} and exists $ref->{"step"}{"predicate"} and @{$ref->{"step"}{"predicate"};} == 0
exists $ref->{"step"} and exists $ref->{"step"}{"predicate"}
MC/DC0%0/3
exists $ref->{"step"} and exists $ref->{"step"}{"predicate"} and @{$ref->{"step"}{"predicate"};} == 0
exists $ref->{"step"}
exists $ref->{"step"}{"predicate"}
@{$ref->{"step"}{"predicate"};} == 0
Truth table0%0/4
A and B and C
A= exists $ref->{"step"}B= exists $ref->{"step"}{"predicate"}C= @{$ref->{"step"}{"predicate"};} == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | && exists $ref->{step}{predicate} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | && @{ $ref->{step}{predicate} } == 0 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | delete $ref->{step}{predicate}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # deep equality test used in culling predicates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | sub is_deeply { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_deeply: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my ( $r1, $r2 ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $t1 = ref $r1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $t2 = ref $r2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | return if $t1 xor $t2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$t1 xor $t2
MC/DC0%0/2
$t1 xor $t2
$t1
$t2
Truth table0%0/4
A xor B
A= $t1B= $t2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ($t1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | return unless $t1 eq $t2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | for ($t1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | when ('ARRAY') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my @ar = @$r1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | return unless @ar == @$r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | for my $i ( 0 .. $#ar ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | return unless is_deeply( $ar[$i], $r2->[$i] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my @ar = keys %$r1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | return unless @ar == keys %$r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | for my $k (@ar) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | unless exists $r2->{$k} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | and is_deeply( $r1->{$k}, $r2->{$k} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $r2->{$k} and is_deeply($r1->{$k}, $r2->{$k})
MC/DC0%0/2
exists $r2->{$k} and is_deeply($r1->{$k}, $r2->{$k})
exists $r2->{$k}
is_deeply($r1->{$k}, $r2->{$k})
Truth table0%0/3
A and B
A= exists $r2->{$k}B= is_deeply($r1->{$k}, $r2->{$k})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | default { die "logic failure" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | return $r1 == $r2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
&looks_like_number($r1) and &looks_like_number($r2)
MC/DC0%0/2
&looks_like_number($r1) and &looks_like_number($r2)
&looks_like_number($r1)
&looks_like_number($r2)
Truth table0%0/3
A and B
A= &looks_like_number($r1)B= &looks_like_number($r2)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | if looks_like_number($r1) && looks_like_number($r2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | return $r1 eq $r2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # normalize mathematical expressions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | sub normalize_math { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_math: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ( contains_math($ref) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | normalize_mconst($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | fix_functions($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | reduce_arithmetic($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | promote_operators($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | collapse_math($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # fix { math => { operator=> undef, item=>[ { math => ... } ] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | sub collapse_math { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collapse_math: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | when ('ARRAY') { collapse_math($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | collapse_math($_) for values %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ( my $m = $ref->{math} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | unless ( $m->{operator} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | delete $ref->{$_} for keys %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $m = $m->{item}[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | for ( my ( $k, $v ) = each %$m ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $ref->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub fix_functions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fix_functions: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | when ('ARRAY') { fix_functions($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | fix_functions($_) for values %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | if ( $ref->{function} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my @items = @{ $ref->{function}{arg}{item} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | if ( @items == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | $ref->{function}{arg} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $items[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $ref->{function}{arg} = { math => { item => \@items } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # converts operators from infix to prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub promote_operators { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
promote_operators: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | when ('ARRAY') { promote_operators($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | promote_operators($_) for values %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if ( exists $ref->{math} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | if ( exists $ref->{math}{item} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $ref->{math}{operator} = $ref->{math}{item}[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | $ref->{math}{item} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | [ grep { ref $_ } @{ $ref->{math}{item} } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | elsif ( exists $ref->{math}{function} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $ref->{function} = delete $ref->{math}{function}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | delete $ref->{math}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # apply math to constant operands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | sub reduce_arithmetic { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reduce_arithmetic: not called CC=42 SCAR=75.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # depth first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | reduce_arithmetic($_) for values %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ( exists $ref->{function} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $num = $ref->{function}{arg}{num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ( defined $num ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $num = $FUNCTIONS{ $ref->{function}{f} }->($num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | delete $ref->{function}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $ref->{num} = $num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | elsif ( exists $ref->{attribute_test} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my $values = $ref->{attribute_test}{value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | for my $i ( 0 .. $#$values ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my $value = $values->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | if ( exists $value->{math} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
exists $value->{"math"} and exists $value->{"math"}{"num"}
MC/DC0%0/2
exists $value->{"math"} and exists $value->{"math"}{"num"}
exists $value->{"math"}
exists $value->{"math"}{"num"}
Truth table0%0/3
A and B
A= exists $value->{"math"}B= exists $value->{"math"}{"num"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | && exists $value->{math}{num} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | $value->{v} = $value->{math}{num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | delete $value->{math}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | elsif ( exists $value->{num} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | $value->{v} = $value->{num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | delete $value->{num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | ▶ | elsif ( exists $ref->{math} || exists $ref->{mgroup} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
exists $ref->{"math"} or exists $ref->{"mgroup"}
MC/DC0%0/2
exists $ref->{"math"} or exists $ref->{"mgroup"}
exists $ref->{"math"}
exists $ref->{"mgroup"}
Truth table0%0/3
A or B
A= exists $ref->{"math"}B= exists $ref->{"mgroup"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | my $key = exists $ref->{math} ? 'math' : 'mgroup'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | my $items = $ref->{$key}{item}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | if ( defined $items ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | for ( scalar @$items ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | when (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | if ( exists $items->[0]{num} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | $ref->{num} = $items->[0]{num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | delete $ref->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | when (3) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | if ( exists $items->[0]{num} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $items->[0]{"num"} and exists $items->[2]{"num"}
MC/DC0%0/2
exists $items->[0]{"num"} and exists $items->[2]{"num"}
exists $items->[0]{"num"}
exists $items->[2]{"num"}
Truth table0%0/3
A and B
A= exists $items->[0]{"num"}B= exists $items->[2]{"num"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | && exists $items->[2]{num} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | my ( $l, $op, $r ) = @$items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my $num = eval $l->{num} . $op . $r->{num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $ref->{num} = $num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | delete $ref->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | my $operator = $items->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ( $MATH_OPERATORS{$operator}[1] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | { # commutative? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my ( $variables, $constants ) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | sort_vals( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | grep_nums( $items, [ 0, 2 ] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | splice @$items, 0, 3, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | math => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | item => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | interleave( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | $operator, @$constants, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | @$variables, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | default { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | for my $op_spec (@math_ops) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | if ( @$items == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | delete $ref->{$_} for keys %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | $ref->{$_} = $items->[0]{$_} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | for keys %{ $items->[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | my ( $operator, $commutative, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | $left_associative, $dual ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | = @$op_spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | if ($left_associative) { # left-associative | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my @ranges = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | collect_ranges( $items, $operator ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | if (@ranges) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | ▶ | if ($commutative) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | for my $range ( reverse @ranges ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | my ( $variables, $constants ) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | sort_vals( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | grep_nums( $items, $range ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | my ( $start, $length ) = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | $range->[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | $range->[1] - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | $range->[0] + 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | if ( @$constants > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | my @nums = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | map { $_->{num} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | @$constants; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | my $expr = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | join $operator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | @nums; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my $v = eval $expr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | if (@$variables) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | splice @$items, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | $start, $length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | math => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | item => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | interleave( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | num => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | $v | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | @$variables, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | $operator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | splice @$items, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | $start, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | $length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | { num => $v }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | splice @$items, $start, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | $length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | math => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | item => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | interleave( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | $operator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | @$constants, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | @$variables, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | else { # non-commutative | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | for my $range ( reverse @ranges ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | my ( $start, $length ) = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | $range->[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | $range->[1] - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | $range->[0] + 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | my ( $left, @nums ) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | grep_nums( $items, $range ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my ( $variables, $constants ) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | sort_vals(@nums); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | if ( @$constants > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | my @nums = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | map { $_->{num} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | @$constants; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | my $expr = join $dual, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | @nums; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | my $v = eval $expr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | if (@$variables) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | splice @$items, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | $start, $length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | math => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | item => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | interleave( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | $operator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | $left, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | num => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | $v | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | @$variables, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | elsif ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | exists $left->{num} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | splice @$items, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | $start, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | $length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | { num => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | eval $left->{num} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | . $operator | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | . $v }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | splice @$items, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | $start, $length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | math => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | item => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | interleave( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | $operator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | $left, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | num => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | $v | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | ▶ | elsif (@$constants == 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
@$constants == 1 and not @$variables and exists $left->{"num"}
@$constants == 1 and not @$variables
MC/DC0%0/3
@$constants == 1 and not @$variables and exists $left->{"num"}
@$constants == 1
not @$variables
exists $left->{"num"}
Truth table0%0/4
A and not(B) and C
A= @$constants == 1B= not @$variablesC= exists $left->{"num"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | && !@$variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | && exists $left->{num} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | my $v = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | eval $left->{num} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | . $operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | . $constants->[0]{num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | splice @$items, $start, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | $length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | { num => $v }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | splice @$items, $start, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | $length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | math => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | item => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | interleave( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | $operator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | $left, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | @$constants, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | @$variables, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | else { # right-associative | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | for ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | my $i = $#$items - 1 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | $i > 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | $i -= 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | my $op = $items->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | ▶ | if ( $op eq $operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$op eq $operator and exists $$items[$i - 1]{"num"} and exists $$items[$i + 1]{"num"}
$op eq $operator and exists $$items[$i - 1]{"num"}
MC/DC0%0/3
$op eq $operator and exists $$items[$i - 1]{"num"} and exists $$items[$i + 1]{"num"}
$op eq $operator
exists $$items[$i - 1]{"num"}
exists $$items[$i + 1]{"num"}
Truth table0%0/4
A and B and C
A= $op eq $operatorB= exists $$items[$i - 1]{"num"}C= exists $$items[$i + 1]{"num"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | && exists $items->[ $i - 1 ]{num} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | && exists $items->[ $i + 1 ]{num} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | splice @$items, $i - 1, 3, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | { num => eval $items->[ $i - 1 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | . $op | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | . $items->[ $i + 1 ] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | elsif ( exists $ref->{$key}{num} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | $ref->{num} = $ref->{$key}{num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | delete $ref->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | when ('ARRAY') { reduce_arithmetic($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # like join but it doesn't stringify the results | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | sub interleave { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interleave: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | my ( $op, @items ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | my @ar = ( $items[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | push @ar, $op, $_ for @items[ 1 .. $#items ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | return @ar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | # sorts items conjoined by some arithmetic operator such that variables sort before constants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | sub sort_vals { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort_vals: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | my ( $variables, $constants ) = ( [], [] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | push @{ exists $_->{num} ? $constants : $variables }, $_ for @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | return $variables, $constants; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | # pulls out the non-operators | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | ▶ | sub grep_nums { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
grep_nums: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | my ( $items, $range ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | grep { ref $_ } @$items[ $range->[0] .. $range->[1] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # looks for ranges of mathematical expressions all with the same operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | ▶ | sub collect_ranges { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collect_ranges: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | my ( $items, $op ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | my ( @ranges, $start ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | my ( $i, $lim ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | ▶ | for ( ( $i, $lim ) = ( 1, $#$items - 1 ) ; $i <= $lim ; $i += 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | my $op2 = $items->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | ▶ | if ( $op2 eq $op ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | ▶ | $start = $i - 1 if !defined $start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | elsif ( defined $start ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | push @ranges, [ $start, $i - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | undef $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | push @ranges, [ $start, $i - 1 ] if defined $start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | return @ranges; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | # checks to see whether there is any math in the expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | ▶ | sub contains_math { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains_math: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | ▶ | return 1 if exists $ref->{math}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | for my $v ( values %$ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | ▶ | return 1 if contains_math($v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | when ('ARRAY') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | for my $v (@$ref) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | ▶ | return 1 if contains_math($v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | # convert mathematical constants to values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | ▶ | sub normalize_mconst { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_mconst: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | ▶ | if ( exists $ref->{mconst} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | my $num = $MATH_CONSTANTS{ $ref->{mconst} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | ▶ | $ref->{num} = exists $ref->{minus} ? -$num : $num; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | delete $ref->{mconst}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | delete $ref->{minus}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | normalize_mconst($_) for values %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | when ('ARRAY') { normalize_mconst($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | # constructs an error message indicating the parsable portion of the expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | ▶ | sub error_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_message: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | my ( $expr, $offset ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | my $start = $offset - 20; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | ▶ | $start = 0 if $start < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | my $prefix = substr $expr, 0, $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | my $end = $offset + 20; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | ▶ | $end = length $expr if length $expr < $end; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | my $suffix = substr $expr, $offset, $end - $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | my $error = 'matching failed at position marked by <HERE>: '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | ▶ | $error .= '...' if $start > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | ▶ | $error .= $prefix if $prefix; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | $error .= '<HERE>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | ▶ | $error .= $suffix if $suffix; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | ▶ | $error .= '...' if $end < length $expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | return $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | # convert (/foo) to /foo and (/foo)? to /foo? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | ▶ | sub normalize_compounds { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_compounds: not called CC=25 SCAR=64.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | # depth first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | normalize_compounds($_) for values %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | my $cs = $ref->{cs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | ▶ | if ($cs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | normalize_enums($cs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | my $gs = $cs->{grouped_step}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | if ( $gs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$gs and @{$gs->{"treepath"}{"path"};} == 1 and @{$gs->{"treepath"}{"path"}[0]{"segment"};} == 1 and not $gs->{"predicate"}
$gs and @{$gs->{"treepath"}{"path"};} == 1 and @{$gs->{"treepath"}{"path"}[0]{"segment"};} == 1
$gs and @{$gs->{"treepath"}{"path"};} == 1
MC/DC0%0/4
$gs and @{$gs->{"treepath"}{"path"};} == 1 and @{$gs->{"treepath"}{"path"}[0]{"segment"};} == 1 and not $gs->{"predicate"}
$gs
@{$gs->{"treepath"}{"path"};} == 1
@{$gs->{"treepath"}{"path"}[0]{"segment"};} == 1
not $gs->{"predicate"}
Truth table0%0/5
A and B and C and not(D)
A= $gsB= @{$gs->{"treepath"}{"path"};} == 1C= @{$gs->{"treepath"}{"path"}[0]{"segment"};} == 1D= not $gs->{"predicate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | && @{ $gs->{treepath}{path} } == 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | && @{ $gs->{treepath}{path}[0]{segment} } == 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | && !$gs->{predicate} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 0 | my $quantifier = $gs->{quantifier}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | my $step = $gs->{treepath}{path}[0]{segment}[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | ▶ | $step->{quantifier} = $quantifier if $quantifier; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | $ref->{cs} = $step; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | when ('ARRAY') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | # depth first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | normalize_compounds($_) for @$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | my $among_steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 0 | for my $i ( 0 .. $#$ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | my $v = $ref->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | ▶ | last unless $among_steps // ref $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$among_steps // ref $v
MC/DC0%0/1
$among_steps // ref $v
$among_steps
Truth table0%0/2
A
A= $among_steps
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | my $cs = $v->{cs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | ▶ | $among_steps //= $cs // 0 || $v->{step} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$among_steps //= (($cs // 0) || $v->{"step"}) // 0
(($cs // 0) || $v->{"step"}) // 0
$cs // 0 or $v->{"step"}
$cs // 0
MC/DC0%0/1
$among_steps //= (($cs // 0) || $v->{"step"}) // 0
$among_steps
Truth table0%0/2
A
A= $among_steps
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | ▶ | last unless $among_steps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | ▶ | if ($cs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | ▶ | if ( $cs->{step} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | ▶ | if ( !$cs->{quantifier} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | splice @$ref, $i, 1, $cs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | elsif ( $cs->{quantifier} eq 'vacuous' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | delete $cs->{quantifier}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 0 | splice @$ref, $i, 1, $cs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | ▶ | elsif ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$cs->{"grouped_step"}{"quantifier"} // ""
MC/DC0%0/1
$cs->{"grouped_step"}{"quantifier"} // ""
$cs->{"grouped_step"}{"quantifier"}
Truth table0%0/2
A
A= $cs->{"grouped_step"}{"quantifier"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | ( $cs->{grouped_step}{quantifier} // '' ) eq 'vacuous' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 0 | my $path = $cs->{grouped_step}{treepath}{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | ▶ | if ( @$path == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | splice @$ref, $i, 1, @{ $path->[0]{segment} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | # normalizes enumerated quantifiers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | ▶ | sub normalize_enums { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_enums: not called CC=25 SCAR=64.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 0 | my $cs = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | my $is_grouped = exists $cs->{grouped_step}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | my $q = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | $is_grouped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | ? $cs->{grouped_step}{quantifier} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 0 | ▶ | : $cs->{quantifier}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 0 | ▶ | return unless $q && ref $q; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$q and ref $q
MC/DC0%0/2
$q and ref $q
$q
ref $q
Truth table0%0/3
A and B
A= $qB= ref $q
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 0 | my $enum = $q->{enum}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | my $start_defined = $enum->{start} ne ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | ▶ | my $start = $enum->{start} ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$enum->{"start"} ||= 0
MC/DC0%0/1
$enum->{"start"} ||= 0
$enum->{"start"}
Truth table0%0/2
A
A= $enum->{"start"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 0 | my $end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | ▶ | if ( exists $enum->{end} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | ▶ | $end = $enum->{end} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$enum->{'end'} || 0
MC/DC0%0/1
$enum->{'end'} || 0
$enum->{'end'}
Truth table0%0/2
A
A= $enum->{'end'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 0 | $end = $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 0 | ▶ | if ( $end == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | ▶ | if ( $start == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 0 | ▶ | if ($is_grouped) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 0 | $cs->{grouped_step}{quantifier} = 'vacuous'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 0 | $cs->{quantifier} = 'vacuous'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 0 | ▶ | if ( $start == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 0 | ▶ | if ($is_grouped) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 0 | $cs->{grouped_step}{quantifier} = '?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 0 | $cs->{quantifier} = '?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | ▶ | elsif ( $start == 1 && $end == 0 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$start == 1 and $end == 0
MC/DC0%0/2
$start == 1 and $end == 0
$start == 1
$end == 0
Truth table0%0/3
A and B
A= $start == 1B= $end == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 0 | ▶ | if ($is_grouped) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 0 | $cs->{grouped_step}{quantifier} = '+'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | $cs->{quantifier} = '+'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | ▶ | elsif ($start_defined | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/8
$start_defined and $start == 0 and ($enum->{"end"} // "bad") eq ""
$start_defined and $start == 0
$enum->{"end"} // "bad"
MC/DC0%0/3
$start_defined and $start == 0 and ($enum->{"end"} // "bad") eq ""
$start_defined
$start == 0
$enum->{"end"}
Truth table0%0/4
A and B and C
A= $start_definedB= $start == 0C= $enum->{"end"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | && $start == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | && ( $enum->{end} // 'bad' ) eq '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | ▶ | if ($is_grouped) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | $cs->{grouped_step}{quantifier} = '*'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | $cs->{quantifier} = '*'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | ▶ | die 'empty {x,y} quantifier in ' . $cs->{''} unless $start || $end; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$start or $end
MC/DC0%0/2
$start or $end
$start
$end
Truth table0%0/3
A or B
A= $startB= $end
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | die 'in {x,y} quantifier end is less than start in ' . $cs->{''} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 0 | ▶ | if $start > $end && ( $enum->{end} // '' ) ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$start > $end and ($enum->{"end"} // "") ne ""
$enum->{"end"} // ""
MC/DC0%0/2
$start > $end and ($enum->{"end"} // "") ne ""
$start > $end
$enum->{"end"}
Truth table0%0/3
A and B
A= $start > $endB= $enum->{"end"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | $enum->{end} = $end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | # converts complement => '^' to complement => 1 simply to make AST function clearer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | ▶ | sub complement_to_boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
complement_to_boolean: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | for my $k ( keys %$ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | ▶ | if ( $k eq 'complement' ) { $ref->{$k} &&= 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ref->{$k} &&= 1
MC/DC0%0/1
$ref->{$k} &&= 1
$ref->{$k}
Truth table0%0/2
A
A= $ref->{$k}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | else { complement_to_boolean( $ref->{$k} ) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | when ('ARRAY') { complement_to_boolean($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | # remove no-op steps etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 0 | ▶ | sub optimize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optimize: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 0 | clean_no_op($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 0 | clean_context($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 0 | ▶ | sub clean_context { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_context: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 0 | when ('ARRAY') { clean_context($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 0 | clean_context($_) for values %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 0 | delete $ref->{''}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | # remove . and /. steps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 0 | ▶ | sub clean_no_op { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_no_op: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 0 | for ( ref $ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 0 | my $paths = $ref->{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | ▶ | for my $path ( @{ $paths // [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$paths // []
MC/DC0%0/1
$paths // []
$paths
Truth table0%0/2
A
A= $paths
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 0 | my @segments = @{ $path->{segment} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 0 | my @cleaned; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 0 | for my $i ( 1 .. $#segments ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 0 | my $step = $segments[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | ▶ | push @cleaned, $step unless find_dot($step); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | ▶ | if (@cleaned) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 0 | my $step = $segments[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 0 | ▶ | if ( find_dot($step) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 0 | my $sep = $step->{separator}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | my $next = $cleaned[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | my $nsep = $next->{separator}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 0 | ▶ | if ($sep) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 0 | ▶ | unshift @cleaned, $step | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$nsep eq "/" and find_axis($next)
MC/DC0%0/2
$nsep eq "/" and find_axis($next)
$nsep eq "/"
find_axis($next)
Truth table0%0/3
A and B
A= $nsep eq "/"B= find_axis($next)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | unless $nsep eq '/' && find_axis($next); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 0 | ▶ | if ( $nsep eq '/' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 0 | delete $next->{separator}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 0 | unshift @cleaned, $step; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 0 | unshift @cleaned, $step; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | @cleaned = @segments; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 0 | $path->{segment} = \@cleaned; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 0 | clean_no_op($_) for values %$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 0 | when ('ARRAY') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 0 | clean_no_op($_) for @$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | # returns the axis if any; prevents reification of hash keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 0 | ▶ | sub find_axis { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_axis: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | my $next = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 0 | my $step = $next->{step}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 0 | ▶ | return unless $step; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 0 | my $full = $step->{step}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 0 | ▶ | return unless $full; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | return $full->{axis}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | # finds dot, if any; prevents reification of hash keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 0 | ▶ | sub find_dot { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_dot: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 0 | my $step = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | exists $step->{step} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 0 | ▶ | && ( $step->{step}{abbreviated} // '' ) eq '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$step->{"step"}{"abbreviated"} // ""
MC/DC0%0/1
$step->{"step"}{"abbreviated"} // ""
$step->{"step"}{"abbreviated"}
Truth table0%0/2
A
A= $step->{"step"}{"abbreviated"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | # remove unnecessary levels in predicate trees | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | ▶ | sub fix_predicates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fix_predicates: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | my $type = ref $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | for ($type) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | ▶ | while ( my ( $k, $v ) = each %$ref ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | ▶ | if ( $k eq 'predicate' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | for my $i ( 0 .. $#$v ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | my $item = $v->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | ▶ | next if exists $item->{idx}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 0 | ▶ | if ( ref $item->{condition} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 0 | $item = $item->{condition}[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 0 | splice @$v, $i, 1, $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 0 | fix_predicates($item); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | fix_predicates($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | when ('ARRAY') { fix_predicates($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | # merge nested conditions with the same operator into containing conditions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 0 | ▶ | sub merge_conditions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_conditions: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 0 | my $type = ref $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 0 | ▶ | return $ref unless $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 0 | for ($type) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | ▶ | while ( my ( $k, $v ) = each %$ref ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 0 | ▶ | if ( $k eq 'condition' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | ▶ | if ( !exists $v->{args} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | merge_conditions($_) for values %$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | # depth first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 0 | merge_conditions($_) for @{ $v->{args} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 0 | my $op = $v->{operator}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 0 | my @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 0 | for my $a ( @{ $v->{args} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 0 | my $condition = $a->{condition}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 0 | ▶ | if ( defined $condition ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 0 | my $o = $condition->{operator}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 0 | ▶ | if ( defined $o ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 0 | ▶ | if ( $o eq $op ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 0 | push @args, @{ $condition->{args} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 0 | push @args, $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 0 | push @args, $condition; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 0 | push @args, $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 0 | $v->{args} = \@args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 0 | merge_conditions($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 0 | when ('ARRAY') { merge_conditions($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 0 | default { die "unexpected type $type" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | # group operators and arguments according to operator precedence ! > & > ; > || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 0 | ▶ | sub operator_precedence { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
operator_precedence: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 0 | my $type = ref $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | ▶ | return $ref unless $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 0 | for ($type) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 0 | ▶ | while ( my ( $k, $v ) = each %$ref ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 0 | ▶ | if ( $k eq 'condition' && ref $v eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$k eq "condition" and ref $v eq "ARRAY"
MC/DC0%0/2
$k eq "condition" and ref $v eq "ARRAY"
$k eq "condition"
ref $v eq "ARRAY"
Truth table0%0/3
A and B
A= $k eq "condition"B= ref $v eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 0 | my @ar = @$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | # normalize ! strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | @ar = grep { $_ } map { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 0 | ▶ | if ( !ref $_ && /^!++$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not ref $_ and /^!++$/
MC/DC0%0/2
not ref $_ and /^!++$/
not ref $_
/^!++$/
Truth table0%0/3
not(A) and B
A= not ref $_B= /^!++$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | ( my $s = $_ ) =~ s/..//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 0 | $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 0 | else { $_ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | } @ar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 0 | ▶ | $ref->{$k} = \@ar if @$v != @ar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | # depth first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 0 | operator_precedence($_) for @ar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 0 | ▶ | return $ref if @ar == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | # build binary logical operation tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 0 | ▶ | OUTER: while ( @ar > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 0 | for my $op (qw(! & ; ||)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 0 | for my $i ( 0 .. $#ar ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 0 | my $item = $ar[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 0 | ▶ | next if ref $item; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 0 | ▶ | if ( $item eq $op ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 0 | ▶ | if ( $op eq '!' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 0 | splice @ar, $i, 2, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | condition => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | operator => '!', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | args => [ $ar[ $i + 1 ] ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 0 | splice @ar, $i - 1, 3, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | condition => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | operator => $op, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | args => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | $ar[ $i - 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | $ar[ $i + 1 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 0 | next OUTER; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | # replace condition with logical operation tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 0 | $ref->{condition} = $ar[0]{condition}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | 0 | operator_precedence($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 0 | when ('ARRAY') { operator_precedence($_) for @$ref } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 0 | default { die "unexpected type $type" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | 0 | return $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | # looks for structures requiring normalization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 0 | ▶ | sub contains_condition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains_condition: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 0 | my $type = ref $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | 0 | ▶ | return 0 unless $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | 0 | ▶ | if ( $type eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 0 | ▶ | while ( my ( $k, $v ) = each %$ref ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 0 | ▶ | return 1 if $k eq 'condition' || contains_condition($v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$k eq "condition" or contains_condition($v)
MC/DC0%0/2
$k eq "condition" or contains_condition($v)
$k eq "condition"
contains_condition($v)
Truth table0%0/3
A or B
A= $k eq "condition"B= contains_condition($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 0 | for my $v (@$ref) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | ▶ | return 1 if contains_condition($v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | # removes redundant parentheses and simplifies condition elements somewhat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 0 | ▶ | sub normalize_parens { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_parens: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 0 | my $type = ref $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | ▶ | return $ref unless $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 0 | for ($type) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | 0 | when ('ARRAY') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 0 | normalize_parens($_) for @$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 0 | when ('HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | 0 | for my $name ( keys %$ref ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 0 | my $value = $ref->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 0 | ▶ | if ( $name eq 'condition' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | 0 | my @ar = @{ $value->{item} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 0 | for my $i ( 0 .. $#ar ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 0 | $ar[$i] = normalize_item( $ar[$i] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 0 | $ref->{condition} = \@ar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 0 | normalize_parens($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | 0 | default { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | 0 | die "unexpected type: $type"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | 0 | return $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | # normalizes parentheses in a condition item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 0 | ▶ | sub normalize_item { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_item: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | 0 | my $item = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | 0 | ▶ | return $item unless ref $item; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 0 | ▶ | if ( exists $item->{term} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 0 | return normalize_parens( $item->{term} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | elsif ( exists $item->{group} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | # remove redundant parentheses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | 0 | ▶ | while ( exists $item->{group} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $item->{"group"} and @{$item->{"group"}{"condition"}{"item"};} == 1
MC/DC0%0/2
exists $item->{"group"} and @{$item->{"group"}{"condition"}{"item"};} == 1
exists $item->{"group"}
@{$item->{"group"}{"condition"}{"item"};} == 1
Truth table0%0/3
A and B
A= exists $item->{"group"}B= @{$item->{"group"}{"condition"}{"item"};} == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | 0 | && @{ $item->{group}{condition}{item} } == 1 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | 0 | $item = $item->{group}{condition}{item}[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 0 | ▶ | return normalize_parens( $item->{group} // $item->{term} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$item->{"group"} // $item->{"term"}
MC/DC0%0/2
$item->{"group"} // $item->{"term"}
$item->{"group"}
$item->{"term"}
Truth table0%0/3
A // B
A= $item->{"group"}B= $item->{"term"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | 0 | die 'items in a condition are expected to be either <term> or <group>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | # some functions to undo escaping and normalize strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 0 | ▶ | sub clean_literal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_literal: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 0 | my $m = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 0 | $m = substr $m, 1, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | 0 | return clean_escapes($m); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | 0 | ▶ | sub clean_pattern { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_pattern: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 0 | my $m = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 0 | return clean_special($m, '~~'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 0 | ▶ | sub clean_special { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_special: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 0 | my ($m, $p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 0 | $m = substr $m, 1, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 0 | my $r = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | 0 | my $j = index $m, $p, $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 0 | ▶ | if ( $j > -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 0 | $r .= substr $m, $i, $j - $i + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 0 | $i = $j + 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 0 | redo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | 0 | $r .= substr $m, $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 0 | return $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 0 | ▶ | sub clean_regex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_regex: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 0 | my $m = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 0 | return clean_special($m, '\\/'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 0 | ▶ | sub clean_mregex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_mregex: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 0 | my ($m, $mods) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | 0 | my $p = '\\' . substr $m, -1, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 0 | $m = clean_special($m, $p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 0 | ▶ | return $m unless $mods; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | 0 | return qr/(?$mods:$m)/ . ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | 0 | ▶ | sub clean_not { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_not: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | 0 | my $m = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | 0 | ▶ | return '!' if $m eq 'not'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 0 | return $m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | 0 | ▶ | sub clean_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_operator: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 0 | my $m = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | 0 | for ($m) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 0 | when ('and') { return '&' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 0 | when ('or') { return '||' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | 0 | when ('one') { return ';' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 0 | return $m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 0 | ▶ | sub clean_escapes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_escapes: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | 0 | my $m = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | 0 | ▶ | return '' unless $m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | 0 | my $r = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 0 | my $i = index $m, '\\'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 0 | ▶ | if ( $i > -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 0 | my $prefix = substr $m, 0, $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | 0 | my $c = substr $m, $i + 1, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 0 | for ($c) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | 0 | when ('b') { $c = "\b" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | 0 | when ('f') { $c = "\f" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 0 | when ('n') { $c = "\012" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | 0 | when ('r') { $c = "\015" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 0 | when ('t') { $c = "\t" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 0 | when ('v') { $c = "\013" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 0 | $prefix .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 0 | $m = substr $m, $i + 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 0 | $r .= $prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | 0 | redo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | 0 | $r .= $m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | 0 | return $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | 0 | ▶ | sub end_punct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end_punct: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | 0 | for ($c) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 0 | when ('(') { return ')' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | 0 | when ('{') { return '}' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | 0 | when ('[') { return ']' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | 0 | when ('<') { return '>' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | 0 | return $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | 0 | ▶ | sub mods_test { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mods_test: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | 0 | my $mods = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 0 | my %types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | 0 | ▶ | for ( my ($i,$lim) = (0, length $mods); $i < $lim; ++$i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 0 | $types{substr $mods, $i, 1} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | 0 | return length $mods == scalar keys %types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||