lib/YAMLScript/Reader.pm

filter: Statementstmt 87.9% 504 / 573 Branchbran 73.4% 219 / 298 Conditioncond 75.8% 85 / 112 MC/DCmcdc 43.6% 24 / 55 Subroutinesub 83.5% 122 / 146 Podpod 0.0% 0 / 118 totaltotal 73.2% 954 / 1302 CC 199 SCAR 17.9
CC
199
Cov
82%
construct_let1
42.0
tag_node
20.1
tag_val
12.6
CRAP 6.0
↑ Summary lib/YAMLScript/Test.pm »
1 20 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 # Needed for Perl versions < 5.20
4 20 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
5 20 ▶ warnings->unimport('experimental::signatures')
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if eval "use warnings 'experimental::signatures'; 1" 20 0 20
6 if eval "use warnings 'experimental::signatures'; 1";
7 }
8 20 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 package YAMLScript::Reader;
11  
12 20 ▶use YAMLScript::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 20 ▶use Lingy::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 20 ▶use base 'Lingy::Reader';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 20 ▶use Regexp::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 20 ▶use Scalar::Util 'refaddr';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 20 our %events;
21 20 our %functions;
22 20 our %refs;
23  
24 20 my $main_called = 0;
25  
26 20 our $read_ys = 0;
27  
28 #------------------------------------------------------------------------------
29 # Convert YAMLScript into a Lingy AST
30 #------------------------------------------------------------------------------
31 50 ▶sub new { bless {}, shift }
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
32  
33 142 ▶sub read_str {
Subroutine read_str: called CC=2 SCAR=6.9
Pod undocumented
34 142 my $self = shift;
35 142 my ($str) = @_;
36 142 ▶ if ($read_ys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YAMLScript::Reader::read_ys) { } 7 135 142
37 7 return $self->read_ys($str);
38 } else {
39 135 return $self->SUPER::read_str(@_);
40 }
41 }
42  
43 67 ▶sub read_ys {
Subroutine read_ys: called CC=2 SCAR=6.9
Pod undocumented
44 67 my ($self, $yaml, $file) = (@_, '');
45  
46 67 $self->{yaml} = $yaml;
47 67 $self->{file} = $file;
48  
49 67 %events = ();
50 67 %functions = ();
51 67 %refs = ();
52  
53 67 $self->{events} = $self->parse_yaml_pp($yaml);
54 67 my $dom = $self->compose_dom;
55 66 ▶ my $ast = $file
Branch: 1 branch
BranchTrueFalseTotal
$file ? : 9 57 66
56 ? $self->construct_ast($dom)
57 : $self->construct_expr($dom);
58  
59 66 return $ast;
60 }
61  
62 20 our @event_keys = (qw<
63 type
64 bpos blin bcol
65 epos elin ecol
66 anch ytag
67 styl valu
68 >);
69  
70 0 ▶sub parse_yaml_fy {
Subroutine parse_yaml_fy: not called CC=1 SCAR=6.9
Pod undocumented
71 0 my ($self, $yaml) = @_;
72  
73 0 require IPC::Run;
74  
75 0 my ($out, $err);
76 0 IPC::Run::run(
77 [qw< fy-tool --testsuite --tsv-format >],
78 $yaml,
79 \$out,
80 \$err,
81 IPC::Run::timeout(5),
82 );
83  
84 0 [ map 'event'->new($_), split /\n/, $out ];
85 }
86  
87 20 my $event_dict = {
88 stream_start_event => '+str',
89 stream_end_event => '-str',
90 document_start_event => '+doc',
91 document_end_event => '-doc',
92 mapping_start_event => '+map',
93 mapping_end_event => '-map',
94 sequence_start_event => '+seq',
95 sequence_end_event => '-seq',
96 scalar_event => '=val',
97 alias_event => '=ali',
98 };
99  
100 67 ▶sub parse_yaml_pp {
Subroutine parse_yaml_pp: called CC=1 SCAR=0.0
Pod undocumented
101 67 my ($self, $yaml) = @_;
102 67 require YAML::PP::Parser;
103 67 my $events = [];
104 YAML::PP::Parser->new(
105 1049 ▶ receiver => sub {
Subroutine __ANON__: called CC=7 SCAR=19.6
106 1049 my ($self, undef, $event) = @_;
107 my @event = (
108 ($event_dict->{$event->{name}} || XXX($event)),
109 0, 0, 0, 0, 0, 0,
110 ($event->{anchor} || '-'),
111 1049 ▶ ($event->{tag} || '-'),
Condition57%4/7
$$event_dict{$event->{'name'}} || XXX($event)
l!l&&r!l&&!r
104900
$event->{'anchor'} || '-'
l!l
01049
$event->{'tag'} || '-'
l!l
11048
MC/DC0%0/2
$$event_dict{$event->{'name'}} || XXX($event)
$$event_dict{$event->{'name'}} XXX($event)
MC/DC0%0/1
$event->{'anchor'} || '-'
$event->{'anchor'}
MC/DC100%1/1
$event->{'tag'} || '-'
$event->{'tag'}
Truth table33%1/3
A || B
A= $$event_dict{$event->{'name'}}B= XXX($event)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $event->{'anchor'}
Aresult
11
00
Truth table100%2/2
A
A= $event->{'tag'}
Aresult
11
00
112 );
113 1049 ▶ if ($event->{name} eq 'scalar_event') {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"name"} eq "scalar_event") 399 650 1049
114 399 my $value = $event->{value};
115 399 my $style = $event->{style};
116 399 $value =~ s/\\/\\\\/g;
117 399 $value =~ s/\n/\\n/g;
118 399 ▶ push @event,
Branch: 2 branches
BranchTrueFalseTotal
$style == 1 ? : 352 47 399
$style == 4 ? : 2 45 47
119 (
120 $style == 1 ? ':' :
121 $style == 4 ? '|' :
122 '"'
123 ),
124 $value;
125 }
126 1049 push @$events, join "\t", @event;
127 },
128 67 )->parse_string($yaml);
129 67 [ map 'event'->new($_), @$events ];
130 }
131  
132 #------------------------------------------------------------------------------
133 # AST Implicit Typing Methods
134 #------------------------------------------------------------------------------
135  
136 20 my $bp = $RE{balanced}{-parens=>'()'};
137 20 my $bs = $RE{balanced}{-parens=>'[]'};
138  
139 20 my $E_GROUP = 'event'->new("=xxx\t-1\t-1\t-1\t-1\t-1\t-1\t-\t-\t-\t-");
140 20 my $E_PLAIN = 'event'->new("=xxx\t-1\t-1\t-1\t-1\t-1\t-1\t-\t-\t:\t-");
141 20 my $E_QUOTE = 'event'->new("=xxx\t-1\t-1\t-1\t-1\t-1\t-1\t-\t-\t'\t-");
142 0 ▶sub PAIR { 'pair'->new(@_) }
Subroutine PAIR: not called CC=1 SCAR=6.9
Pod undocumented
143 0 ▶sub MAP { 'map'->new($E_GROUP, @_) }
Subroutine MAP: not called CC=1 SCAR=6.9
Pod undocumented
144 82 ▶sub SEQ { 'seq'->new($E_GROUP, @_) }
Subroutine SEQ: called CC=1 SCAR=0.0
Pod undocumented
145 0 ▶sub VAL { 'val'->new($E_PLAIN, @_) }
Subroutine VAL: not called CC=1 SCAR=6.9
Pod undocumented
146 0 ▶sub STR { 'val'->new($E_QUOTE, @_) }
Subroutine STR: not called CC=1 SCAR=6.9
Pod undocumented
147  
148 0 ▶sub B { BOOLEAN->new($_[0]) }
Subroutine B: not called CC=1 SCAR=6.9
Pod undocumented
149 8 ▶sub K { KEYWORD->new(@_) }
Subroutine K: called CC=1 SCAR=0.0
Pod undocumented
150 349 ▶sub L { LIST->new([@_]) }
Subroutine L: called CC=1 SCAR=0.0
Pod undocumented
151 28 ▶sub N { NUMBER->new($_[0]) }
Subroutine N: called CC=1 SCAR=0.0
Pod undocumented
152 461 ▶sub S { SYMBOL->new($_[0]) }
Subroutine S: called CC=1 SCAR=0.0
Pod undocumented
153 54 ▶sub T { STRING->new($_[0]) }
Subroutine T: called CC=1 SCAR=0.0
Pod undocumented
154 63 ▶sub V { VECTOR->new([@_]) }
Subroutine V: called CC=1 SCAR=0.0
Pod undocumented
155  
156 54 ▶sub DEF { S 'def' }
Subroutine DEF: called CC=1 SCAR=0.0
Pod undocumented
157 20 ▶sub DO { S 'do' }
Subroutine DO: called CC=1 SCAR=0.0
Pod undocumented
158 47 ▶sub FN { S 'fn*' }
Subroutine FN: called CC=1 SCAR=0.0
Pod undocumented
159 0 ▶sub IF { S 'if' }
Subroutine IF: not called CC=1 SCAR=6.9
Pod undocumented
160 0 ▶sub LET { S 'let*' }
Subroutine LET: not called CC=1 SCAR=6.9
Pod undocumented
161  
162 20 my $sym = qr<(?:
163 [-:.]?
164 \w+
165 (?:
166 (?:[-+./]|::)
167 \w+
168 )*
169 [\?\!\*]?
170 )>x;
171  
172 0 ▶sub error($m) { die "YS Error: $m\n" }
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
173 806 ▶sub event($n) { $events{refaddr($n)} }
Subroutine event: called CC=1 SCAR=0.0
Pod undocumented
174 594 ▶sub e_style($n) { event($n)->{styl} }
Subroutine e_style: called CC=1 SCAR=0.0
Pod undocumented
175 212 ▶sub e_tag($n) { event($n)->{ytag} }
Subroutine e_tag: called CC=1 SCAR=0.0
Pod undocumented
176 1430 ▶sub is_map($n) { ref($n) eq 'map' }
Subroutine is_map: called CC=1 SCAR=0.0
Pod undocumented
177 613 ▶sub is_seq($n) { ref($n) eq 'seq' }
Subroutine is_seq: called CC=1 SCAR=0.0
Pod undocumented
178 708 ▶sub is_val($n) { ref($n) eq 'val' }
Subroutine is_val: called CC=1 SCAR=0.0
Pod undocumented
179 808 ▶sub is_pair($n) { ref($n) eq 'pair' }
Subroutine is_pair: called CC=1 SCAR=0.0
Pod undocumented
180 165 ▶sub is_key($n) { $n->{xkey} }
Subroutine is_key: called CC=1 SCAR=0.0
Pod undocumented
181 249 ▶sub is_plain($n) { is_val($n) and e_style($n) eq ':' }
Subroutine is_plain: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
is_val($n) and e_style($n) eq ":" 207 42 249
182 212 ▶sub is_double($n) { is_val($n) and e_style($n) eq '"' }
Subroutine is_double: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
is_val($n) and e_style($n) eq "\"" 212 0 212
183 167 ▶sub is_literal($n) { is_val($n) and e_style($n) eq '|' }
Subroutine is_literal: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
is_val($n) and e_style($n) eq "|" 167 0 167
184 0 ▶sub is_single($n) {
Subroutine is_single: not called CC=3 SCAR=24.8
Pod undocumented
185 0 ▶ return unless is_map($n) and pairs($n) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless is_map($n) and pairs($n) == 1 0 0 0
Condition0%0/3
is_map($n) and pairs($n) == 1
!ll&&!rl&&r
000
MC/DC0%0/2
is_map($n) and pairs($n) == 1
is_map($n) pairs($n) == 1
Truth table0%0/3
A and B
A= is_map($n)B= pairs($n) == 1
ABresult
0X0
100
111
186 0 @{$n->{pair}[0]};
187 }
188 0 ▶sub is_assign($n) {
Subroutine is_assign: not called CC=2 SCAR=17.9
Pod undocumented
189 0 ▶ is_single($n) and
Branch: 1 branch
BranchTrueFalseTotal
is_single($n) and text(key(first_pair($n))) =~ /^$sym\s+=$/ 0 0 0
190 text(key(first_pair($n))) =~ /^$sym\s+=$/;
191 }
192 64 ▶sub is_def($n) { is_map($n) and tag(key(first_pair($n))) eq 'def' }
Subroutine is_def: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
is_map($n) and tag(key(first_pair($n))) eq "def" 49 15 64
193  
194 509 ▶sub assert_map($n) { is_map($n) or ZZZ($n) }
Subroutine assert_map: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
is_map($n) or ZZZ($n) 509 0 509
195 201 ▶sub assert_seq($n) { is_seq($n) or ZZZ($n) }
Subroutine assert_seq: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
is_seq($n) or ZZZ($n) 201 0 201
196 74 ▶sub assert_val($n) { is_val($n) or ZZZ($n) }
Subroutine assert_val: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
is_val($n) or ZZZ($n) 74 0 74
197 209 ▶sub assert_pair($n) { is_pair($n) or ZZZ($n) }
Subroutine assert_pair: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
is_pair($n) or ZZZ($n) 209 0 209
198 38 ▶sub assert_elems($n) { assert_seq($n); @{$n->elem} > 0 or ZZZ($n) }
Subroutine assert_elems: called CC=2 SCAR=7.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@{$n->elem;} > 0 or ZZZ($n) 38 0 38
199 49 ▶sub assert_pairs($n) { assert_map($n); @{$n->pair} > 0 or ZZZ($n) }
Subroutine assert_pairs: called CC=2 SCAR=7.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@{$n->pair;} > 0 or ZZZ($n) 49 0 49
200 460 ▶sub pairs($n) { assert_map($n); @{$n->pair} }
Subroutine pairs: called CC=1 SCAR=0.0
Pod undocumented
201 163 ▶sub elems($n) { assert_seq($n); @{$n->elem} }
Subroutine elems: called CC=1 SCAR=0.0
Pod undocumented
202 648 ▶sub tag($n) { $n->{ytag} }
Subroutine tag: called CC=1 SCAR=0.0
Pod undocumented
203 209 ▶sub key($p) { assert_pair($p); $p->key }
Subroutine key: called CC=1 SCAR=0.0
Pod undocumented
204 0 ▶sub val($p) { assert_pair($p); $p->val }
Subroutine val: not called CC=1 SCAR=6.9
Pod undocumented
205 0 ▶sub key_val($p) { assert_pair($p); @$p }
Subroutine key_val: not called CC=1 SCAR=6.9
Pod undocumented
206 74 ▶sub text($v) { assert_val($v); $v->{text} }
Subroutine text: called CC=1 SCAR=0.0
Pod undocumented
207 38 ▶sub first_elem($n) { assert_elems($n); (elems($n))[0] }
Subroutine first_elem: called CC=1 SCAR=0.0
Pod undocumented
208 49 ▶sub first_pair($n) { assert_pairs($n); (pairs($n))[0] }
Subroutine first_pair: called CC=1 SCAR=0.0
Pod undocumented
209  
210 66 ▶sub construct_expr($s, $n) {
Subroutine construct_expr: called CC=2 SCAR=6.9
Pod undocumented
211 66 my @ast = $s->construct($n);
212  
213 66 ▶ @ast == 1
Branch: 1 branch
BranchTrueFalseTotal
@ast == 1 ? : 65 1 66
214 ? $ast[0]
215 : L(DO, @ast);
216 }
217  
218 9 ▶sub construct_ast($s, $n) {
Subroutine construct_ast: called CC=2 SCAR=6.9
Pod undocumented
219 9 my $ast = $s->construct_expr($n);
220  
221 9 ▶ if (need_main_call($ast)) {
Branch: 1 branch
BranchTrueFalseTotal
if (need_main_call($ast)) 5 4 9
222 5 $ast = L(
223 DO,
224 $ast,
225 L(
226 S('apply'),
227 S('main'),
228 S('*command-line-args*'),
229 ),
230  
231 );
232 }
233  
234 9 return $ast;
235 }
236  
237 599 ▶sub construct($s, $n) {
Subroutine construct: called CC=3 SCAR=11.0
Pod undocumented
238 599 ▶ my $tag = is_pair($n) ? tag(key($n)) : tag($n);
Branch: 1 branch
BranchTrueFalseTotal
is_pair($n) ? : 160 439 599
239 599 ▶ XXX $n, "No tag for node" unless $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag 0 599 599
240 599 my $constructor = "construct_$tag";
241 599 $s->$constructor($n);
242 }
243  
244 0 ▶sub construct_boolean($s, $n) {
Subroutine construct_boolean: not called CC=3 SCAR=24.8
Pod undocumented
245 0 ▶ "$n" eq 'true' ? true :
Branch: 2 branches
BranchTrueFalseTotal
"$n" eq 'true' ? : 0 0 0
"$n" eq 'false' ? : 0 0 0
246 "$n" eq 'false' ? false :
247 die;
248 }
249  
250 82 ▶sub construct_call($s, $p) {
Subroutine construct_call: called CC=6 SCAR=18.1
Pod undocumented
251 82 my ($k, $v) = @$p;
252 82 ▶ "$k" =~ /^($sym)($bp?)$/ or die;
Branch: 1 branch
BranchTrueFalseTotal
"$k" =~ /^($sym)($bp?)$/ or die 82 0 82
253 82 my $fn = $1;
254 82 my $args = $2; # TODO add these args to value args
255 82 ▶ if ($args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args) 21 61 82
256 21 ▶ $args =~ s/^\((.*)\)$/$1/ or die;
Branch: 1 branch
BranchTrueFalseTotal
$args =~ s/^\((.*)\)$/$1/ or die 21 0 21
257 }
258 82 $fn =~ s/^(let|try|catch)$/$1*/;
259 82 ▶ $main_called = 1 if $fn eq 'main';
Branch: 1 branch
BranchTrueFalseTotal
if $fn eq "main" 0 82 82
260 82 $args = 'val'->new(undef, $args);
261 82 $args->{ytag} = 'ysexpr';
262 82 ▶ $v = SEQ($v) unless is_seq($v);
Branch: 1 branch
BranchTrueFalseTotal
unless is_seq($v) 45 37 82
263 82 L(S($fn), map $s->construct($_), $args, elems($v));
264 }
265  
266 16 ▶sub construct_def($s, $p) {
Subroutine construct_def: called CC=2 SCAR=7.0
Pod undocumented
267 16 my ($k, $v) = @$p;
268 16 ▶ "$k" =~ /^($sym)\s*=$/ or die;
Branch: 1 branch
BranchTrueFalseTotal
"$k" =~ /^($sym)\s*=$/ or die 16 0 16
269 16 my $sym = S($1);
270 16 my $rhs = $s->construct($v);
271 16 return L(DEF, $sym, $rhs);
272 }
273  
274 38 ▶sub get_sig {
Subroutine get_sig: called CC=6 SCAR=17.9
Pod undocumented
275 38 my ($sig) = @_;
276 38 my $args = [];
277 38 my $dargs = [];
278 38 ▶ while ($sig =~ s/^($sym)(?=,?\s|$),?\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig =~ s/^($sym)(?=,?\s|$),?\s*//) 37 38 75
279 37 push @$args, symbol($1);
280 }
281 38 ▶ if ($sig =~ s/^\*($sym)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig =~ s/^\*($sym)//) { } 3 35 38
282 3 push @$args, symbol('&'), symbol($1);
283 }
284 else {
285 35 ▶ if ($sig =~ /^($sym)=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig =~ /^($sym)=/) 6 29 35
286 6 push @$args, symbol('&'), symbol('_args_');
287 }
288 35 ▶ while ($sig =~ s/^($sym)=(\S+),?\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig =~ s/^($sym)=(\S+),?\s*//) 9 35 44
289 9 my ($s, $x) = ($1, $2);
290 9 push @$dargs, $1;
291 9 push @$dargs, read_ysexpr($x);
292 }
293 }
294 38 ▶ err "Can't parse function signature '$_[0]'"
Branch: 1 branch
BranchTrueFalseTotal
if length $sig 0 38 38
295 if length($sig);
296 38 return ($args, $dargs);
297 }
298  
299 25 ▶sub construct_defn($s, $p) {
Subroutine construct_defn: called CC=1 SCAR=0.0
Pod undocumented
300 25 my ($k, $v) = @$p;
301 25 my ($def, $name, $args, $body) = $s->_defn_parse($k, $v, 0);
302 25 return L($def, $name, V(@$args), @$body);
303 }
304  
305 1 ▶sub construct_defn_multi($s, $p) {
Subroutine construct_defn_multi: called CC=2 SCAR=6.9
Pod undocumented
306 1 my ($k, $v) = @$p;
307 1 ▶ text($k) =~ /^(defn|defmacro)\s+($sym)$/ or die;
Branch: 1 branch
BranchTrueFalseTotal
text($k) =~ /^(defn|defmacro)\s+($sym)$/ or die 1 0 1
308 1 my $def = $1;
309 1 my $name = S($2);
310 my @defs = map {
311 1 my ($k, $v) = @$_;
312 4 my (undef, undef, $args, $body) = $s->_defn_parse($k, $v, 1);
313 4 L(V(@$args), @$body);
314 } pairs($v);
315 1 return L($def, $name, @defs);
316 }
317  
318 9 ▶sub construct_fn($s, $p) {
Subroutine construct_fn: called CC=1 SCAR=0.0
Pod undocumented
319 9 my ($k, $v) = @$p;
320 9 my ($def, $name, $args, $body) = $s->_defn_parse($k, $v, 0);
321 9 return L(FN, V(@$args), @$body);
322 }
323  
324 38 ▶sub _defn_parse($s, $k, $v, $m) {
Subroutine _defn_parse: called CC=8 SCAR=20.8
325 38 my ($def, $name, $sig);
326 38 ▶ if ($m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m) { } 4 34 38
327 4 ▶ text($k) =~ /^($sym?)?\((.*)\)$/ or XXX $k;
Branch: 1 branch
BranchTrueFalseTotal
text($k) =~ /^($sym?)?\((.*)\)$/ or XXX($k) 4 0 4
328 4 $def = '';
329 4 $name = S($1);
330 4 $sig = $2;
331 } else {
332 34 ▶ text($k) =~ /^(fn|defn|defmacro)\s+($sym?)?\((.*)\)$/ or XXX $k;
Branch: 1 branch
BranchTrueFalseTotal
text($k) =~ /^(fn|defn|defmacro)\s+($sym?)?\((.*)\)$/ or XXX($k) 34 0 34
333 34 $def = S($1);
334 34 $name = S($2);
335 34 $sig = $3;
336 }
337 38 my ($args, $dargs) = get_sig($sig);
338 38 my $defn = L( DEF, $name, L( FN, L, nil ) );
339 38 ▶ my $seq = is_seq($v) ? $v : SEQ($v);
Branch: 1 branch
BranchTrueFalseTotal
is_seq($v) ? : 1 37 38
340 38 my $first = first_elem($seq);
341 my $body = [
342 (@$dargs or is_def($first) or is_map($first))
343 ? ($s->construct_let($seq, $args, $dargs))
344 38 ▶ : map $s->construct($_), @{$seq->elem},
Branch: 1 branch
BranchTrueFalseTotal
@$dargs || is_def($first) || is_map($first) ? : 25 13 38
Condition100%6/6
@$dargs or is_def($first) or is_map($first)
l!l&&r!l&&!r
101513
@$dargs or is_def($first)
l!l&&r!l&&!r
6428
MC/DC100%3/3
@$dargs or is_def($first) or is_map($first)
@$dargs is_def($first) is_map($first)
Truth table100%4/4
A or B or C
A= @$dargsB= is_def($first)C= is_map($first)
ABCresult
1XX1
01X1
0011
0000
345 ];
346 38 return $def, $name, $args, $body;
347 }
348  
349 7 ▶sub construct_do($s, $n) {
Subroutine construct_do: called CC=2 SCAR=6.9
Pod undocumented
350 7 my @elems = elems($n);
351 7 ▶ if (@elems == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@elems == 1) { } 3 4 7
352 3 $s->construct($elems[0]);
353 } else {
354 4 L(
355 DO,
356 map $s->construct($_), @elems,
357 );
358 }
359 }
360  
361 8 ▶sub construct_if($s, $p) {
Subroutine construct_if: called CC=3 SCAR=11.0
Pod undocumented
362 8 my ($k, $v) = @$p;
363 8 ▶ "$k" =~ /^if +($bp)/ or die;
Branch: 1 branch
BranchTrueFalseTotal
"$k" =~ /^if +($bp)/ or die 8 0 8
364 8 my $cond = read_ysexpr($1);
365 8 ▶ my @elems = is_seq($v) ? elems($v) : $v;
Branch: 1 branch
BranchTrueFalseTotal
is_seq($v) ? : 5 3 8
366 8 L(
367 S('if'),
368 $cond,
369 map $s->construct($_), @elems,
370 );
371 }
372  
373 19 ▶sub construct_int($s, $n) { N("$n") }
Subroutine construct_int: called CC=1 SCAR=0.0
Pod undocumented
374  
375 11 ▶sub construct_istr($s, $n) {
Subroutine construct_istr: called CC=5 SCAR=16.1
Pod undocumented
376 11 my @list;
377 11 local $_ = "$n";
378 11 ▶ while (length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_) 36 11 47
379 36 ▶ if (s/\A\$($sym)//) {
Branch: 3 branches
BranchTrueFalseTotal
if (s/\A\$($sym)//) { } 11 25 36
elsif (s/\A\$($bp)//s) { } 7 18 25
elsif (s/\A(.+?)(?=\$)//s) { } 13 5 18
380 11 push @list, S($1);
381 } elsif (s/\A\$($bp)//s) {
382 7 push @list, read_ysexpr($1);
383 } elsif (s/\A(.+?)(?=\$)//s) {
384 13 push @list, T($1);
385 } else {
386 5 push @list, T($_);
387 5 $_ = '';
388 }
389 }
390 11 L(S('str'), @list);
391 }
392  
393 8 ▶sub construct_keyword($s, $n) {
Subroutine construct_keyword: called CC=1 SCAR=0.0
Pod undocumented
394 8 K("$n");
395 }
396  
397 25 ▶sub construct_let($s, $n, $a, $d) {
Subroutine construct_let: called CC=8 SCAR=20.8
Pod undocumented
398 25 my @elems = elems($n);
399 25 ▶ if (is_map($elems[0]) and @{$elems[0]->{pair}} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_map($elems[0]) and @{$elems[0]{"pair"};} > 1) 6 19 25
Condition100%3/3
is_map($elems[0]) and @{$elems[0]{"pair"};} > 1
!ll&&!rl&&r
1186
MC/DC100%2/2
is_map($elems[0]) and @{$elems[0]{"pair"};} > 1
is_map($elems[0]) @{$elems[0]{"pair"};} > 1
Truth table100%3/3
A and B
A= is_map($elems[0])B= @{$elems[0]{"pair"};} > 1
ABresult
0X0
100
111
400 6 my $elem = shift @elems;
401 6 for my $pair (reverse @{$elem->{pair}}) {
402 21 unshift @elems, bless {
403 pair => [$pair],
404 ytag => 'module',
405 }, 'map';
406 }
407 }
408 25 my @defs;
409 25 my $i = 0;
410 25 ▶ while (@$d) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$d) 9 25 34
411 9 my ($sym, $form) = splice(@$d, 0, 2);
412 9 push @defs, S($sym), L(S('nth'), S('_args_'), N($i), $form);
413 9 $i++;
414 }
415 25 ▶ while (@elems and is_def($elems[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@elems and is_def($elems[0])) 7 25 32
Condition66%2/3
@elems and is_def($elems[0])
!ll&&!rl&&r
0257
MC/DC50%1/2
@elems and is_def($elems[0])
@elems is_def($elems[0])
Truth table66%2/3
A and B
A= @elemsB= is_def($elems[0])
ABresult
0X0
100
111
416 7 my $d = shift @elems;
417 7 my ($p) = pairs($d);
418 7 my ($k, $v) = @$p;
419 7 ▶ (my $sym = "$k") =~ s/\s+=$// or die;
Branch: 1 branch
BranchTrueFalseTotal
(my $sym = "$k") =~ s/\s+=$// or die 7 0 7
420 7 push @defs, S($sym), $s->construct($v);
421 }
422 L(
423 25 S('let*'),
424 V(@defs),
425 map $s->construct($_), @elems,
426 );
427 }
428  
429 0 ▶sub construct_let1($s, $n) {
Subroutine construct_let1: not called CC=6 SCAR=37.4
Pod undocumented
430 0 my @elems = elems($n->[1]);
431 0 ▶ my $assigns = shift @elems or die;
Branch: 1 branch
BranchTrueFalseTotal
my $assigns = shift @elems or die 0 0 0
432 0 my $defs = [];
433 0 ▶ if (is_map($assigns)) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_map($assigns)) { } 0 0 0
elsif (is_seq($assigns)) { } 0 0 0
434 0 for my $pair (pairs($assigns)) {
435 0 my ($k, $v) = @$pair;
436 0 $k = "$k";
437 0 ▶ $k =~ s/\ +=$// or die;
Branch: 1 branch
BranchTrueFalseTotal
$k =~ s/\ +=$// or die 0 0 0
438 0 push @$defs, S($k);
439 0 push @$defs, $s->construct($v);
440 }
441 } elsif (is_seq($assigns)) {
442 0 XXX $n;
443 } else {
444 0 XXX $n;
445 }
446  
447 0 L(
448 S('let*'),
449 $defs,
450 map $s->construct($_), @elems,
451 );
452 }
453  
454 5 ▶sub construct_loop($s, $p) {
Subroutine construct_loop: called CC=3 SCAR=11.0
Pod undocumented
455 5 my ($k, $v) = @$p;
456 5 ▶ "$k" =~ /^loop +($bs)/ or die;
Branch: 1 branch
BranchTrueFalseTotal
"$k" =~ /^loop +($bs)/ or die 5 0 5
457 5 my $bindings = read_ysexpr($1);
458 5 ▶ my @elems = is_seq($v) ? elems($v) : $v;
Branch: 1 branch
BranchTrueFalseTotal
is_seq($v) ? : 1 4 5
459 5 L(
460 S('loop'),
461 $bindings,
462 map $s->construct($_), @elems,
463 );
464 }
465  
466 137 ▶sub construct_module($s, $n) {
Subroutine construct_module: called CC=2 SCAR=6.9
Pod undocumented
467 137 my @forms = map $s->construct($_), pairs($n);
468 137 ▶ return $forms[0] if @forms == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @forms == 1 127 10 137
469 10 L(DO, @forms);
470 }
471  
472 36 ▶sub construct_str($s, $n) {
Subroutine construct_str: called CC=1 SCAR=0.0
Pod undocumented
473 36 T("$n");
474 }
475  
476 45 ▶sub construct_sym($s, $n) {
Subroutine construct_sym: called CC=1 SCAR=0.0
Pod undocumented
477 45 S("$n");
478 }
479  
480 0 ▶sub construct_try($s, $p) {
Subroutine construct_try: not called CC=2 SCAR=17.9
Pod undocumented
481 L(
482 S('try*'),
483 map $s->construct($_),
484 map {
485 0 ▶ is_map($_) ? first_pair($_) : $_
Branch: 1 branch
BranchTrueFalseTotal
is_map($_) ? : 0 0 0
486 } elems(val($p)),
487 );
488 }
489  
490 0 ▶sub construct_catch($s, $p) {
Subroutine construct_catch: not called CC=2 SCAR=17.9
Pod undocumented
491 0 ▶ key($p) =~ /^catch\(($sym)\)$/ or die;
Branch: 1 branch
BranchTrueFalseTotal
key($p) =~ /^catch\(($sym)\)$/ or die 0 0 0
492 0 L(
493 S('catch*'),
494 S($1),
495 $s->construct(val($p)),
496 );
497 }
498  
499 1 ▶sub construct_use($s, $p) {
Subroutine construct_use: called CC=2 SCAR=7.0
Pod undocumented
500 1 my ($k, $v) = @$p;
501 1 $v = $s->construct($v);
502 1 ▶ if (ref($v) eq SYMBOL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "Lingy::Symbol") 1 0 1
503 1 $v = L(S('quote'), $v);
504 }
505 1 L(S("$k"), $v);
506 }
507  
508 0 ▶sub construct_val($s, $n) {
Subroutine construct_val: not called CC=1 SCAR=6.9
Pod undocumented
509 0 T("$n");
510 }
511  
512 13 ▶sub construct_when($s, $p) {
Subroutine construct_when: called CC=4 SCAR=13.9
Pod undocumented
513 13 my ($k, $v) = @$p;
514 13 ▶ (my $expr = "$k") =~ s/ ?([?|])$// or die;
Branch: 1 branch
BranchTrueFalseTotal
(my $expr = "$k") =~ s/ ?([?|])$// or die 13 0 13
515 13 ▶ my $fn = $1 eq '?' ? 'when' : 'when-not';
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '?' ? : 9 4 13
516 13 my $cond = read_ysexpr($expr);
517 13 ▶ my @elems = is_seq($v) ? elems($v) : $v;
Branch: 1 branch
BranchTrueFalseTotal
is_seq($v) ? : 3 10 13
518 13 L(
519 S($fn),
520 $cond,
521 map $s->construct($_), @elems,
522 );
523 }
524  
525 0 ▶sub construct_yamlscript($s, $n) {
Subroutine construct_yamlscript: not called CC=2 SCAR=17.9
Pod undocumented
526 0 my @forms = map $s->construct($_), pairs($n);
527 0 ▶ return $forms[0] if @forms == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @forms == 1 0 0 0
528 0 L(DO, @forms);
529 }
530  
531 175 ▶sub construct_ysexpr($s, $n) {
Subroutine construct_ysexpr: called CC=1 SCAR=0.0
Pod undocumented
532 175 read_ysexpr($n);
533 }
534  
535 # Plain YAML data constructors:
536 4 ▶sub construct_map($s, $n) {
Subroutine construct_map: called CC=3 SCAR=11.0
Pod undocumented
537 4 my $map = [];
538 4 for my $p (pairs($n)) {
539 6 my ($k, $v) = @$p;
540 6 ▶ is_val($k) or XXX $k, "!map keys must be strings";
Branch: 1 branch
BranchTrueFalseTotal
is_val($k) or XXX($k, "!map keys must be strings") 6 0 6
541 6 push @$map, STRING->new("$k");
542 6 push @$map, $s->construct_value($v);
543 }
544 4 HASHMAP->new($map);
545 }
546  
547 2 ▶sub construct_seq($s, $n) {
Subroutine construct_seq: called CC=2 SCAR=6.9
Pod undocumented
548 2 my $seq = [];
549 2 for my $v (elems($n)) {
550 7 push @$seq, $s->construct_value($v);
551 }
552 2 VECTOR->new($seq);
553 }
554  
555 13 ▶sub construct_value($s, $v) {
Subroutine construct_value: called CC=9 SCAR=22.9
Pod undocumented
556 13 my $t = ref($v);
557 13 ▶ if ($t eq 'val') {
Branch: 3 branches
BranchTrueFalseTotal
if ($t eq 'val') { } 8 5 13
elsif ($t eq 'map') { } 4 1 5
elsif ($t eq 'seq') { } 1 0 1
558 8 my $s = e_style($v);
559 8 ▶ if ($s eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq ':') { } 8 0 8
560 return
561 8 ▶ ($v =~ /^-?\d+(\.d+)?$/) ? NUMBER->new("$v") :
Branch: 4 branches
BranchTrueFalseTotal
$v =~ /^-?\d+(\.d+)?$/ ? : 4 4 8
"$v" eq 'true' ? : 2 2 4
"$v" eq 'false' ? : 0 2 2
"$v" eq 'null' ? : 0 2 2
562 ("$v" eq 'true') ? true :
563 ("$v" eq 'false') ? false :
564 ("$v" eq 'null') ? nil :
565 STRING->new("$v");
566 } else {
567 0 return STRING->new("$v");
568 }
569 }
570 elsif ($t eq 'map') {
571 4 $v->{ytag} = 'map';
572 4 return $s->construct_map($v);
573 }
574 elsif ($t eq 'seq') {
575 1 $v->{ytag} = 'seq';
576 1 return $s->construct_seq($v);
577 }
578 else {
579 0 XXX $v, "Don't know how to contruct this";;
580 }
581 }
582  
583 44 ▶sub is_main($n) {
Subroutine is_main: called CC=7 SCAR=19.8
Pod undocumented
584 44 ▶ ref($n) eq LIST and
Branch: 1 branch
BranchTrueFalseTotal
ref $n eq "Lingy::List" and @$n >= 2 and ref $n->[0] eq "Lingy::Symbol" and "$n->[0]" eq "defn" and ref $n->[1] eq "Lingy::Symbol" and "$n->[1]" eq "main" and 1 5 39 44
Condition80%12/15
ref $n eq "Lingy::List" and @$n >= 2 and ref $n->[0] eq "Lingy::Symbol" and "$n->[0]" eq "defn" and ref $n->[1] eq "Lingy::Symbol" and "$n->[1]" eq "main"
!ll&&!rl&&r
3815
ref $n eq "Lingy::List" and @$n >= 2 and ref $n->[0] eq "Lingy::Symbol" and "$n->[0]" eq "defn" and ref $n->[1] eq "Lingy::Symbol"
!ll&&!rl&&r
3806
ref $n eq "Lingy::List" and @$n >= 2 and ref $n->[0] eq "Lingy::Symbol" and "$n->[0]" eq "defn"
!ll&&!rl&&r
10286
ref $n eq "Lingy::List" and @$n >= 2 and ref $n->[0] eq "Lingy::Symbol"
!ll&&!rl&&r
10034
ref $n eq "Lingy::List" and @$n >= 2
!ll&&!rl&&r
10034
MC/DC50%3/6
ref $n eq "Lingy::List" and @$n >= 2 and ref $n->[0] eq "Lingy::Symbol" and "$n->[0]" eq "defn" and ref $n->[1] eq "Lingy::Symbol" and "$n->[1]" eq "main"
ref $n eq "Lingy::List" @$n >= 2 ref $n->[0] eq "Lingy::Symbol" "$n->[0]" eq "defn" ref $n->[1] eq "Lingy::Symbol" "$n->[1]" eq "main"
Truth table57%4/7
A and B and C and D and E and F
A= ref $n eq "Lingy::List"B= @$n >= 2C= ref $n->[0] eq "Lingy::Symbol"D= "$n->[0]" eq "defn"E= ref $n->[1] eq "Lingy::Symbol"F= "$n->[1]" eq "main"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
585 @$n >= 2 and
586 ref($n->[0]) eq SYMBOL and
587 "$n->[0]" eq 'defn' and
588 ref($n->[1]) eq SYMBOL and
589 "$n->[1]" eq 'main' and
590 1;
591 }
592  
593 9 ▶sub need_main_call($ast) {
Subroutine need_main_call: called CC=6 SCAR=18.5
Pod undocumented
594 9 ▶ return 0 if $main_called;
Branch: 1 branch
BranchTrueFalseTotal
if $main_called 0 9 9
595 9 ▶ return 1 if is_main($ast);
Branch: 1 branch
BranchTrueFalseTotal
if is_main($ast) 0 9 9
596 9 ▶ return 0 unless ref($ast) eq LIST;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ast eq "Lingy::List" 0 9 9
597 9 for my $node (@$ast) {
598 35 ▶ return 1 if is_main($node);
Branch: 1 branch
BranchTrueFalseTotal
if is_main($node) 5 30 35
599 }
600 4 return 0;
601 }
602  
603 #------------------------------------------------------------------------------
604 # YS expression reader.
605 #
606 # Converts these special forms:
607 # x(...) -> (x ...)
608 # (x + y) -> (+ x y)
609 # (x + y * z) -> (+ x (* y z))
610 # x(y + z) -> (x (+ y z))
611 #------------------------------------------------------------------------------
612  
613 20 my $dyn = qr<(?:\*$sym\*)>;
614 20 my $op = qr{(?:[-+*/]|[<>=]=?|and|or|\.\.)};
615  
616 20 my $pn = qr=(?:->|~@|[\'\`\[\]\{\}\(\)\~\^\@])=;
617 # my $pn = qr<(?:~@|[\'\`\[\]\{\}\(\)\~\^\@])>;
618  
619 20 my $re = qr<(?:/(?:\\.|[^\\\/])*/)>;
620 20 my $str = qr<(?:#?"(?:\\.|[^\\"])*"?)>;
621 20 my $tok = qr<[^\s\[\]{}('",;)]>;
622 20 my $ws = qr<(?:[\s,])>;
623  
624 217 ▶sub tokenize {
Subroutine tokenize: called CC=2 SCAR=6.9
Pod undocumented
625 [
626 map {
627 217 ▶ s/::/./g if /^\w+(?:::\w+)+$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\w+(?:::\w+)+$/ 4 645 649
628 649 $_;
629 }
630 $_[0] =~ /
631 $ws*
632 (
633 $re |
634 $pn |
635 $str |
636 $dyn |
637 $op(?=\s) |
638 $sym\( |
639 '?$sym |
640 '?$tok
641 )
642 /xog
643 ];
644 }
645  
646 217 ▶sub read_ysexpr($expr) {
Subroutine read_ysexpr: called CC=3 SCAR=11.2
Pod undocumented
647 217 $expr = lingy_expr($expr);
648 217 my @ast = Lingy::Reader->new->read_str($expr);
649 217 ▶ return @ast if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 183 34 217
650 34 ▶ ZZZ [@ast, "Should have got exactly one result"]
Branch: 1 branch
BranchTrueFalseTotal
unless @ast == 1 0 34 34
651 unless @ast == 1;
652 34 return $ast[0];
653 0 Lingy::Reader->new->read_str($expr)
654 }
655  
656 217 ▶sub lingy_expr($expr) {
Subroutine lingy_expr: called CC=4 SCAR=13.9
Pod undocumented
657 217 my $tokens = tokenize($expr);
658 217 my $self = bless { tokens => $tokens }, __PACKAGE__;
659 217 my @groups;
660 217 ▶ while (@$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens) 199 217 416
661 199 push @groups, eval { $self->group };
662 199 ▶ die "Failed to parse expr '$expr': '$@'" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 199 199
663 }
664 join ' ', map {
665 217 ▶ ref($_) ? $self->group_print($_) : $_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 111 88 199
666 } @groups;
667 }
668  
669 233 ▶sub group($s) {
Subroutine group: called CC=10 SCAR=23.1
Pod undocumented
670 233 my $tokens = $s->{tokens};
671 233 my $token = shift @$tokens;
672 233 ▶ if (@$tokens >= 2 and
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens >= 2 and $tokens->[0] eq "->" and $tokens->[1] =~ /^$sym\($/) 4 229 233
Condition83%5/6
@$tokens >= 2 and $tokens->[0] eq "->" and $tokens->[1] =~ /^$sym\($/
!ll&&!rl&&r
22904
@$tokens >= 2 and $tokens->[0] eq "->"
!ll&&!rl&&r
591704
MC/DC66%2/3
@$tokens >= 2 and $tokens->[0] eq "->" and $tokens->[1] =~ /^$sym\($/
@$tokens >= 2 $tokens->[0] eq "->" $tokens->[1] =~ /^$sym\($/
Truth table75%3/4
A and B and C
A= @$tokens >= 2B= $tokens->[0] eq "->"C= $tokens->[1] =~ /^$sym\($/
ABCresult
0XX0
10X0
1100
1111
673 $tokens->[0] eq '->' and
674 $tokens->[1] =~ /^$sym\($/
675 ) {
676 4 shift(@$tokens);
677 4 my $method = shift(@$tokens);
678 4 ▶ $method =~ s/\($// or die;
Branch: 1 branch
BranchTrueFalseTotal
$method =~ s/\($// or die 4 0 4
679 4 return [ '.', $token, $s->group_call($method) ];
680 }
681 229 ▶ $token =~ s/^($sym)\($/$1/ ? $s->group_call($token) :
Branch: 5 branches
BranchTrueFalseTotal
$token =~ s/^($sym)\($/$1/ ? : 74 155 229
$token =~ /^\('\s$/ ? : 0 155 155
$token eq '(' ? : 67 88 155
$token eq '`' ? : 2 86 88
$token =~ /^$re$/ ? : 1 85 86
682 $token =~ /^\('\s$/ ? $s->group_list(1) :
683 $token eq '(' ? $s->group_list(0) :
684 $token eq '`' ? $token :
685 $token =~ /^$re$/ ? '#"' . substr($token, 1, length($token) - 2) . '"' :
686 $token;
687 # die "Unknown token '$token'";
688 }
689  
690 67 ▶sub group_list($s, $l) {
Subroutine group_list: called CC=5 SCAR=16.1
Pod undocumented
691 67 my $tokens = $s->{tokens};
692 67 my $group = $s->group_rest;
693 67 ▶ return $group if $l or @$group != 3 or $group->[1] !~ qr<^$op$>;
Branch: 1 branch
BranchTrueFalseTotal
if $l or @$group != 3 or not $group->[1] =~ qr/^$op$/ 28 39 67
Condition83%5/6
$l or @$group != 3 or not $group->[1] =~ qr/^$op$/
l!l&&r!l&&!r
23539
$l or @$group != 3
l!l&&r!l&&!r
02344
MC/DC66%2/3
$l or @$group != 3 or not $group->[1] =~ qr/^$op$/
$l @$group != 3 not $group->[1] =~ qr/^$op$/
Truth table75%3/4
A or B or not(C)
A= $lB= @$group != 3C= not $group->[1] =~ qr/^$op$/
ABCresult
1XX1
01X1
0011
0000
694  
695 39 my $oper = $group->[1];
696 39 ▶ $oper = '-range' if $oper eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $oper eq ".." 10 29 39
697  
698 # TODO Support infix group > 3
699 39 [ $oper, $group->[0], $group->[2] ];
700 }
701  
702 78 ▶sub group_call($s, @t) {
Subroutine group_call: called CC=3 SCAR=12.6
Pod undocumented
703 78 my $tokens = $s->{tokens};
704 78 my $group = [@t];
705 78 my $rest = $s->group_rest;
706 78 ▶ if (@$rest == 3 and $rest->[1] =~ qr<^$op$>) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$rest == 3 and $rest->[1] =~ qr/^$op$/) 0 78 78
Condition33%1/3
@$rest == 3 and $rest->[1] =~ qr/^$op$/
!ll&&!rl&&r
7800
MC/DC0%0/2
@$rest == 3 and $rest->[1] =~ qr/^$op$/
@$rest == 3 $rest->[1] =~ qr/^$op$/
Truth table33%1/3
A and B
A= @$rest == 3B= $rest->[1] =~ qr/^$op$/
ABresult
0X0
100
111
707 0 $rest = [ $rest->[1], $rest->[0], $rest->[2] ];
708 0 $rest = ([$rest]);
709 }
710 78 push @$group, @$rest;
711 78 return $group;
712 }
713  
714 145 ▶sub group_rest($s) {
Subroutine group_rest: called CC=4 SCAR=14.0
Pod undocumented
715 145 my $tokens = $s->{tokens};
716 145 my $rest = [];
717 145 ▶ while (@$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens) 442 0 442
718 442 ▶ if ($tokens->[0] eq ')') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tokens->[0] eq ')') { } 145 297 442
elsif ($tokens->[0] =~ qr/^$sym?\('?$/) { } 34 263 297
719 145 shift @$tokens;
720 145 return $rest;
721 } elsif ($tokens->[0] =~ qr<^$sym?\('?$>) {
722 34 push @$rest, $s->group;
723 } else {
724 263 push @$rest, shift @$tokens;
725 }
726 }
727 0 die "Failed to parse expression";
728 }
729  
730 149 ▶sub group_print($s, $g) {
Subroutine group_print: called CC=2 SCAR=6.9
Pod undocumented
731 '(' .
732 join(' ',
733 map {
734 149 ▶ ref($_) ? $s->group_print($_) : $_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 38 349 387
735 } @$g
736 )
737 . ')';
738 }
739  
740  
741 #------------------------------------------------------------------------------
742 # AST Composer Methods
743 #------------------------------------------------------------------------------
744 67 ▶sub compose_dom {
Subroutine compose_dom: called CC=1 SCAR=0.0
Pod undocumented
745 67 my ($self) = @_;
746 67 my $node = $self->compose_node;
747 67 $node->{xtop} = 1;
748 67 tag_node($node);
749 66 return $node;
750 }
751  
752 590 ▶sub compose_node {
Subroutine compose_node: called CC=6 SCAR=18.3
Pod undocumented
753 590 my ($self) = (@_, '');
754 590 my $events = $self->{events};
755 590 ▶ while (@$events) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$events) 724 0 724
756 724 my $event = shift(@$events);
757 724 ▶ if ($event->{type} =~ /^[+=](map|seq|val|ali)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"type"} =~ /^[+=](map|seq|val|ali)$/) 590 134 724
758 590 my $composer = "compose_$1";
759 590 my $node = $self->$composer($event);
760 590 ▶ if ((my $ytag = $event->{ytag}) ne '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $ytag = $event->{"ytag"}) ne "-") 1 589 590
761 1 ▶ $ytag =~ s/^!(\w*)$/$1/ or XXX $event;
Branch: 1 branch
BranchTrueFalseTotal
$ytag =~ s/^!(\w*)$/$1/ or XXX($event) 1 0 1
762 1 ▶ $node->{ytag} = $ytag || ref($node);
Condition33%1/3
$ytag || ref $node
l!l&&r!l&&!r
010
MC/DC0%0/2
$ytag || ref $node
$ytag ref $node
Truth table33%1/3
A || B
A= $ytagB= ref $node
ABresult
1X1
011
000
763 }
764 590 return $node;
765 }
766 }
767 }
768  
769 144 ▶sub compose_map {
Subroutine compose_map: called CC=3 SCAR=11.1
Pod undocumented
770 144 my ($self, $event) = @_;
771 144 my $map = 'map'->new($event);;
772 144 my $events = $self->{events};
773 144 ▶ while (@$events) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$events) 354 0 354
774 354 ▶ shift(@$events), return $map if $events->[0]{type} eq '-map';
Branch: 1 branch
BranchTrueFalseTotal
if $events->[0]{"type"} eq "-map" 144 210 354
775 210 my $k = $self->compose_node;
776 210 $k->{xkey} = 1;
777 210 my $v = $self->compose_node;
778 210 my $pair = 'pair'->new($k, $v);
779 210 $map->add($pair);
780 }
781 0 XXX $map, "problem composing map";
782 }
783  
784 47 ▶sub compose_seq {
Subroutine compose_seq: called CC=3 SCAR=11.1
Pod undocumented
785 47 my ($self, $event) = @_;
786 47 my $seq = 'seq'->new($event);
787 47 my $events = $self->{events};
788 47 ▶ while (@$events) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$events) 150 0 150
789 150 ▶ shift(@$events), return $seq if $events->[0]{type} eq '-seq';
Branch: 1 branch
BranchTrueFalseTotal
if $events->[0]{"type"} eq "-seq" 47 103 150
790 103 my $elem = $self->compose_node;
791 103 $seq->add($elem);
792 }
793 0 XXX $seq, "problem composing seq";
794 }
795  
796 399 ▶sub compose_val {
Subroutine compose_val: called CC=1 SCAR=0.0
Pod undocumented
797 399 my ($self, $event) = @_;
798 399 'val'->new($event);
799 }
800  
801 0 ▶sub compose_ali {
Subroutine compose_ali: not called CC=1 SCAR=6.9
Pod undocumented
802 0 my ($self, $event) = @_;
803 0 'ali'->new($event);
804 }
805  
806 #------------------------------------------------------------------------------
807 # AST Tag Resolution Methods
808 #------------------------------------------------------------------------------
809 {
810 20 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
811 0 ▶ sub YAMLScript::Common::_dump {
Subroutine _dump: not called CC=1 SCAR=6.9
812 0 (my $type = (caller(1))[3]) =~ s/.*://;
813 0 my $sub = (caller(2))[3];
814 0 my $line = (caller(1))[2];
815 0 require YAML::PP;
816 0 my $dump = YAML::PP->new(
817 schema => ['Core', 'Perl', '-dumpcode'],
818 )->dump_string(@_) . "\e[0;33m... $type $sub $line\e[0m\n\n";
819 0 $dump =~ s/\A(.*)/\n\e[0;33m$1\e[0m/;
820 0 $dump;
821 }
822 }
823  
824 0 ▶sub tag_error($msg) { ZZZ "$msg: '$_'" }
Subroutine tag_error: not called CC=1 SCAR=1.2
Pod undocumented
825  
826 397 ▶sub tag_node($n) {
Subroutine tag_node: called CC=19 SCAR=30.0
Pod undocumented
827 397 ▶ if ($n->{ytag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"ytag"}) 1 396 397
828 1 ▶ if ($n->{ytag} ne 'yamlscript') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"ytag"} ne "yamlscript") 1 0 1
829 1 return 1;
830 }
831 }
832 396 $n = transform($n);
833 396 ▶ if (is_map($n)) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_map($n)) { } 130 266 396
elsif (is_seq($n)) { } 54 212 266
834 130 for my $p (pairs($n)) {
835 168 ▶ tag_catch($p) or
Branch: 1 branch
BranchTrueFalseTotal
tag_catch($p) or tag_defn_multi($p) or tag_defn($p) or tag_def($p) or tag_if($p) or tag_fn($p) or tag_let($p) or tag_loop($p) or tag_try($p) or tag_when($p) or tag_call($p) or XXX($p, "Unable to implicitly tag this map pair.") 167 0 167
Condition83%25/30
tag_catch($p) or tag_defn_multi($p) or tag_defn($p) or tag_def($p) or tag_if($p) or tag_fn($p) or tag_let($p) or tag_loop($p) or tag_try($p) or tag_when($p) or tag_call($p)
l!l&&r!l&&!r
84840
tag_catch($p) or tag_defn_multi($p) or tag_defn($p) or tag_def($p) or tag_if($p) or tag_fn($p) or tag_let($p) or tag_loop($p) or tag_try($p) or tag_when($p)
l!l&&r!l&&!r
71988
tag_catch($p) or tag_defn_multi($p) or tag_defn($p) or tag_def($p) or tag_if($p) or tag_fn($p) or tag_let($p) or tag_loop($p) or tag_try($p)
l!l&&r!l&&!r
71097
tag_catch($p) or tag_defn_multi($p) or tag_defn($p) or tag_def($p) or tag_if($p) or tag_fn($p) or tag_let($p) or tag_loop($p)
l!l&&r!l&&!r
660102
tag_catch($p) or tag_defn_multi($p) or tag_defn($p) or tag_def($p) or tag_if($p) or tag_fn($p) or tag_let($p)
l!l&&r!l&&!r
660102
tag_catch($p) or tag_defn_multi($p) or tag_defn($p) or tag_def($p) or tag_if($p) or tag_fn($p)
l!l&&r!l&&!r
573108
tag_catch($p) or tag_defn_multi($p) or tag_defn($p) or tag_def($p) or tag_if($p)
l!l&&r!l&&!r
494115
tag_catch($p) or tag_defn_multi($p) or tag_defn($p) or tag_def($p)
l!l&&r!l&&!r
2618124
tag_catch($p) or tag_defn_multi($p) or tag_defn($p)
l!l&&r!l&&!r
17160
tag_catch($p) or tag_defn_multi($p)
l!l&&r!l&&!r
01167
MC/DC0%0/11
tag_catch($p) or tag_defn_multi($p) or tag_defn($p) or tag_def($p) or tag_if($p) or tag_fn($p) or tag_let($p) or tag_loop($p) or tag_try($p) or tag_when($p) or tag_call($p)
tag_catch($p) tag_defn_multi($p) tag_defn($p) tag_def($p) tag_if($p) tag_fn($p) tag_let($p) tag_loop($p) tag_try($p) tag_when($p) tag_call($p)
Truth table58%7/12
A or B or C or D or E or F or G or H or I or J or K
A= tag_catch($p)B= tag_defn_multi($p)C= tag_defn($p)D= tag_def($p)E= tag_if($p)F= tag_fn($p)G= tag_let($p)H= tag_loop($p)I= tag_try($p)J= tag_when($p)K= tag_call($p)
ABCDEFGHIJKresult
1XXXXXXXXXX1
01XXXXXXXXX1
001XXXXXXXX1
0001XXXXXXX1
00001XXXXXX1
000001XXXXX1
0000001XXXX1
00000001XXX1
000000001XX1
0000000001X1
000000000011
000000000000
836 tag_defn_multi($p) or
837 tag_defn($p) or
838 tag_def($p) or
839 tag_if($p) or
840 tag_fn($p) or
841 tag_let($p) or
842 tag_loop($p) or
843 tag_try($p) or
844 tag_when($p) or
845 tag_call($p) or
846 XXX $p, "Unable to implicitly tag this map pair.";
847 }
848 129 ▶ $n->{ytag} //= 'module';
Condition50%1/2
$n->{"ytag"} //= "module"
l!l
0129
MC/DC0%0/1
$n->{"ytag"} //= "module"
$n->{"ytag"}
Truth table50%1/2
A
A= $n->{"ytag"}
Aresult
11
00
849 }
850 elsif (is_seq($n)) {
851 54 for my $e (@{$n->{elem}}) {
852 160 tag_node($e);
853 }
854 54 $n->{ytag} = 'do';
855 }
856 else {
857 212 tag_val($n);
858 }
859  
860 395 1;
861 }
862  
863 396 ▶sub transform($n) {
Subroutine transform: called CC=7 SCAR=19.5
Pod undocumented
864 396 ▶ if (is_map($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_map($n)) 130 266 396
865 130 for my $p (pairs($n)) {
866 168 my ($k, $v) = @$p;
867  
868 $k->{text} =
869 "$k" eq '???' ? 'cond' :
870 "$k" eq '^^^' ? 'recur' :
871 168 ▶ $k->{text};
Branch: 2 branches
BranchTrueFalseTotal
"$k" eq '???' ? : 10 158 168
"$k" eq '^^^' ? : 4 154 158
872  
873 168 ▶ if ("$k" eq 'cond' and is_map($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$k" eq "cond" and is_map($v)) 9 159 168
Condition100%3/3
"$k" eq "cond" and is_map($v)
!ll&&!rl&&r
15729
MC/DC100%2/2
"$k" eq "cond" and is_map($v)
"$k" eq "cond" is_map($v)
Truth table100%3/3
A and B
A= "$k" eq "cond"B= is_map($v)
ABresult
0X0
100
111
874 $p->[1] = bless {
875 elem => [
876 64 map { delete($_->{xkey}); $_ }
877 9 map { @$_ } @{$v->{pair}}
878 ],
879 }, 'seq';
880 }
881 }
882 }
883  
884 396 return $n;
885 }
886  
887 212 ▶sub tag_val($n) {
Subroutine tag_val: called CC=10 SCAR=25.3
Pod undocumented
888 212 ▶ if (e_tag($n) ne '-') {
Branch: 3 branches
BranchTrueFalseTotal
if (e_tag($n) ne '-') { } 0 212 212
elsif (is_double($n) or is_literal($n)) { } 47 165 212
elsif (is_plain($n)) { } 165 0 165
889 0 $n->{ytag} = substr(e_tag($n), 1);
890 ▶ } elsif (is_double($n) or is_literal($n)) {
Condition100%3/3
is_double($n) or is_literal($n)
l!l&&r!l&&!r
452165
MC/DC100%2/2
is_double($n) or is_literal($n)
is_double($n) is_literal($n)
Truth table100%3/3
A or B
A= is_double($n)B= is_literal($n)
ABresult
1X1
011
000
891 47 ▶ ($n->{xtop} and tag_ysexpr($n)) or
Branch: 1 branch
BranchTrueFalseTotal
$n->{"xtop"} and tag_ysexpr($n) or tag_istr($n) or tag_str($n) 11 36 47
Condition50%3/6
$n->{"xtop"} and tag_ysexpr($n) or tag_istr($n)
l!l&&r!l&&!r
01136
$n->{"xtop"} and tag_ysexpr($n)
!ll&&!rl&&r
4700
MC/DC33%1/3
$n->{"xtop"} and tag_ysexpr($n) or tag_istr($n)
$n->{"xtop"} tag_ysexpr($n) tag_istr($n)
Truth table40%2/5
A and B or C
A= $n->{"xtop"}B= tag_ysexpr($n)C= tag_istr($n)
ABCresult
11X1
0X11
1011
0X00
1000
892 tag_istr($n) or
893 tag_str($n);
894 } elsif (is_plain($n)) {
895 165 ▶ is_key($n) or
Branch: 1 branch
BranchTrueFalseTotal
is_key($n) or tag_scalar($n) or tag_ysexpr($n) 72 93 165
Condition66%2/3
is_key($n) or tag_scalar($n)
l!l&&r!l&&!r
07293
MC/DC50%1/2
is_key($n) or tag_scalar($n)
is_key($n) tag_scalar($n)
Truth table66%2/3
A or B
A= is_key($n)B= tag_scalar($n)
ABresult
1X1
011
000
896 tag_scalar($n) or
897 tag_ysexpr($n);
898 } else {
899 0 tag_str($n);
900 }
901 }
902  
903 84 ▶sub tag_call($p) {
Subroutine tag_call: called CC=6 SCAR=17.9
Pod undocumented
904 84 my ($k, $v) = @$p;
905 84 ▶ if ($k =~ /^$sym($bp?)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^$sym($bp?)$/) 84 0 84
906 84 my $args = $1;
907 $k->{ytag} =
908 84 ▶ "$k" eq 'use'
Branch: 1 branch
BranchTrueFalseTotal
"$k" eq 'use' ? : 1 83 84
909 ? "$k" :'call';
910  
911 # Empty (null) value
912 84 ▶ if (is_plain($v) and text($v) eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (is_plain($v) and text($v) eq "") 4 80 84
Condition100%3/3
is_plain($v) and text($v) eq ""
!ll&&!rl&&r
49314
MC/DC100%2/2
is_plain($v) and text($v) eq ""
is_plain($v) text($v) eq ""
Truth table100%3/3
A and B
A= is_plain($v)B= text($v) eq ""
ABresult
0X0
100
111
913 4 ▶ err "Use 'foo():' for a call with no args"
Branch: 1 branch
BranchTrueFalseTotal
if $args eq "" 1 3 4
914 if $args eq '';
915 }
916  
917 83 tag_node($v);
918 }
919 }
920  
921 168 ▶sub tag_catch($n) {
Subroutine tag_catch: called CC=2 SCAR=7.6
Pod undocumented
922 168 ▶ $n->{ytag} = 'catch' if $n =~ /^catch\($sym\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ /^catch\($sym\)$/ 0 168 168
923 }
924  
925 142 ▶sub tag_def($p) {
Subroutine tag_def: called CC=2 SCAR=6.9
Pod undocumented
926 142 my ($k, $v) = @$p;
927 142 ▶ return unless $k =~ /^$sym\s*=$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^$sym\s*=$/ 119 23 142
928 23 $k->{ytag} = 'def';
929 23 tag_node($v);
930 }
931  
932 167 ▶sub tag_defn($p) {
Subroutine tag_defn: called CC=2 SCAR=6.9
Pod undocumented
933 167 my ($k, $v) = @$p;
934 167 ▶ return unless $k =~ /^(?:defn|defmacro)\s+$sym$bp$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^(?:defn|defmacro)\s+$sym$bp$/ 142 25 167
935 25 $k->{ytag} = 'defn';
936 25 tag_node($v);
937 }
938  
939 168 ▶sub tag_defn_multi($p) {
Subroutine tag_defn_multi: called CC=6 SCAR=18.0
Pod undocumented
940 168 my ($k, $v) = @$p;
941 168 ▶ return unless $k =~ /^(?:defn|defmacro)\s+$sym$/ and is_map($v);
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^(?:defn|defmacro)\s+$sym$/ and is_map($v) 167 1 168
Condition66%2/3
$k =~ /^(?:defn|defmacro)\s+$sym$/ and is_map($v)
!ll&&!rl&&r
16701
MC/DC50%1/2
$k =~ /^(?:defn|defmacro)\s+$sym$/ and is_map($v)
$k =~ /^(?:defn|defmacro)\s+$sym$/ is_map($v)
Truth table66%2/3
A and B
A= $k =~ /^(?:defn|defmacro)\s+$sym$/B= is_map($v)
ABresult
0X0
100
111
942 1 for my $p (pairs($v)) {
943 4 ▶ return unless $p->[0] =~ /^$bp$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $p->[0] =~ /^$bp$/ 0 4 4
944 }
945 1 $k->{ytag} = 'defn_multi';
946 1 for my $p (pairs($v)) {
947 4 my ($k, $v) = @$p;
948 4 tag_node($v);
949 }
950 1 return 1;
951 }
952  
953 119 ▶sub tag_if($p) {
Subroutine tag_if: called CC=2 SCAR=6.9
Pod undocumented
954 119 my ($k, $v) = @$p;
955 119 ▶ return unless $k =~ /^if +\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^if +\S/ 111 8 119
956 8 $k->{ytag} = 'if';
957 8 tag_node($v);
958 }
959  
960 47 ▶sub tag_istr($n) {
Subroutine tag_istr: called CC=2 SCAR=6.9
Pod undocumented
961 47 ▶ $n->{ytag} = 'istr' if $n =~ /(\$$sym|\$\()/;
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ /(\$$sym|\$\()/ 11 36 47
962 }
963  
964 111 ▶sub tag_fn($p) {
Subroutine tag_fn: called CC=2 SCAR=6.9
Pod undocumented
965 111 my ($k, $v) = @$p;
966 111 ▶ return unless $k =~ /^fn\s+$bp$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^fn\s+$bp$/ 102 9 111
967 9 $k->{ytag} = 'fn';
968 9 tag_node($v);
969 }
970  
971 102 ▶sub tag_let($n) {
Subroutine tag_let: called CC=2 SCAR=7.6
Pod undocumented
972 102 ▶ $n->{ytag} = 'let1' if $n =~ /^let$/;
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ /^let$/ 0 102 102
973 }
974  
975 102 ▶sub tag_loop($p) {
Subroutine tag_loop: called CC=2 SCAR=6.9
Pod undocumented
976 102 my ($k, $v) = @$p;
977 102 ▶ return unless $k =~ /^loop +\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^loop +\S/ 97 5 102
978 5 $k->{ytag} = 'loop';
979 5 tag_node($v);
980 }
981  
982 165 ▶sub tag_scalar($n) {
Subroutine tag_scalar: called CC=7 SCAR=19.9
Pod undocumented
983 165 local $_ = $n;
984 $n->{ytag} =
985 /^(true|false)$/ ? 'boolean' :
986 /^-?\d+$/ ? 'int' :
987 /^-?\d+\.\d*$/ ? 'float' :
988 /^:$sym$/ ? 'keyword' :
989 /^null$/ ? 'null' :
990 165 ▶ /^$sym$/ ? do {
Branch: 6 branches
BranchTrueFalseTotal
/^(true|false)$/ ? : 0 165 165
/^-?\d+$/ ? : 19 146 165
/^-?\d+\.\d*$/ ? : 0 146 146
/^:$sym$/ ? : 8 138 146
/^null$/ ? : 0 138 138
/^$sym$/ ? : 45 93 138
991 45 $n->{text} =~ s/::/./g;
992 45 'sym';
993 } :
994 return;
995 }
996  
997 36 ▶sub tag_str($n) {
Subroutine tag_str: called CC=1 SCAR=0.0
Pod undocumented
998 36 $n->{ytag} = 'str';
999 }
1000  
1001 97 ▶sub tag_try($n) {
Subroutine tag_try: called CC=2 SCAR=7.6
Pod undocumented
1002 97 ▶ $n->{ytag} = 'try' if $n =~ /^try$/;
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ /^try$/ 0 97 97
1003 }
1004  
1005 97 ▶sub tag_when($p) {
Subroutine tag_when: called CC=2 SCAR=6.9
Pod undocumented
1006 97 my ($k, $v) = @$p;
1007 97 ▶ return unless $k =~ /(?:\)|. )[?|]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /(?:\)|. )[?|]$/ 84 13 97
1008 13 $k->{ytag} = 'when';
1009 13 tag_node($v);
1010 }
1011  
1012 93 ▶sub tag_ysexpr($n) {
Subroutine tag_ysexpr: called CC=1 SCAR=0.0
Pod undocumented
1013 93 $n->{text} =~ s/^\.(?!\d)//;
1014 93 $n->{ytag} = 'ysexpr';
1015 }
1016  
1017 #------------------------------------------------------------------------------
1018 # Event and Node Classes
1019 #------------------------------------------------------------------------------
1020 {
1021 package event;
1022 1109 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1023 1109 my ($class, $line) = @_;
1024 1109 chomp $line;
1025 1109 my $self = bless {}, $class;
1026 1109 @{$self}{@event_keys} = split /\t/, $line;
1027 1109 return $self;
1028 }
1029 }
1030  
1031 {
1032 20 package pair;
1033 210 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1034 210 my ($class, $k, $v) = @_;
1035 210 bless [$k, $v], $class;
1036 }
1037 209 ▶ sub key($p) { $p->[0] }
Subroutine key: called CC=1 SCAR=0.0
1038 0 ▶ sub val($p) { $p->[1] }
Subroutine val: not called CC=1 SCAR=6.9
1039 }
1040  
1041 {
1042 20 package map;
1043 144 ▶ sub new {
Subroutine new: called CC=2 SCAR=7.0
1044 144 my ($class, $event, @pairs) = @_;
1045 144 my $self = bless {
1046 pair => [@pairs],
1047 }, $class;
1048 $refs{$event->{anch}} = $self
1049 144 ▶ if $event->{anch} ne '-';
Branch: 1 branch
BranchTrueFalseTotal
if $event->{"anch"} ne "-" 0 144 144
1050 144 $events{Scalar::Util::refaddr($self)} = $event;
1051 144 return $self;
1052 }
1053 210 ▶ sub add {
Subroutine add: called CC=1 SCAR=0.0
1054 210 my ($self, $pair) = @_;
1055 210 push @{$self->{pair}}, $pair;
1056 }
1057 509 ▶ sub pair { $_[0]->{pair} }
Subroutine pair: called CC=1 SCAR=0.0
1058 }
1059  
1060 {
1061 20 package seq;
1062 129 ▶ sub new {
Subroutine new: called CC=3 SCAR=11.2
1063 129 my ($class, $event, @elems) = @_;
1064 129 my $self = bless {
1065 elem => [@elems],
1066 }, $class;
1067 129 ▶ if ($event) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event) 129 0 129
1068 $refs{$event->{anch}} = $self
1069 129 ▶ if $event->{anch} ne '-';
Branch: 1 branch
BranchTrueFalseTotal
if $event->{"anch"} ne "-" 0 129 129
1070 129 $events{Scalar::Util::refaddr($self)} = $event;
1071 }
1072 129 return $self;
1073 }
1074 103 ▶ sub add {
Subroutine add: called CC=1 SCAR=0.0
1075 103 my ($self, $value) = @_;
1076 103 push @{$self->{elem}}, $value;
1077 103 return $self;
1078 }
1079 214 ▶ sub elem { $_[0]->{elem} }
Subroutine elem: called CC=1 SCAR=0.0
1080 }
1081  
1082 {
1083 20 package val;
1084 20 ▶ use overload '""' => sub { $_[0]->{text} };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
1085 20 my %escapes = (
1086 'n' => "\n",
1087 't' => "\t",
1088 '\\' => '\\',
1089 '"' => '"',
1090 );
1091 481 ▶ sub new {
Subroutine new: called CC=5 SCAR=16.1
1092 481 my ($class, $event, $text) = @_;
1093 481 ▶ $text //= $event->{valu} // '';
Condition100%4/4
$text //= $event->{"valu"} // ""
l!l
82399
$event->{"valu"} // ""
l!l
3954
MC/DC100%1/1
$text //= $event->{"valu"} // ""
$text
Truth table100%2/2
A
A= $text
Aresult
11
00
1094 481 $text =~ s/\\([nt\\\"])/$escapes{$1}/g;
1095 481 my $self = bless {
1096 text => $text,
1097 }, $class;
1098 481 ▶ if ($event) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event) 399 82 481
1099 399 delete $event->{valu};
1100 $refs{$event->{anch}} = $self
1101 399 ▶ if $event->{anch} ne '-';
Branch: 1 branch
BranchTrueFalseTotal
if $event->{"anch"} ne "-" 0 399 399
1102 399 $events{Scalar::Util::refaddr($self)} = $event;
1103 }
1104 481 return $self;
1105 }
1106 }
1107  
1108 {
1109 20 package ali;
1110 0 ▶ sub new {
Subroutine new: not called CC=1 SCAR=6.9
1111 0 my ($class, $event) = @_;
1112 my $self = bless {
1113 name => $event->{valu},
1114 0 }, $class;
1115 0 delete $event->{valu};
1116 0 $events{Scalar::Util::refaddr($self)} = $event;
1117 0 return $self;
1118 }
1119 }
1120  
1121 20 1;
↑ Summary lib/YAMLScript/Test.pm »