lib/Lingy/Reader.pm

filter: Statementstmt 81.6% 178 / 218 Branchbran 78.1% 111 / 142 Conditioncond 78.7% 26 / 33 MC/DCmcdc 59.0% 13 / 22 Subroutinesub 90.9% 20 / 22 Podpod 0.0% 0 / 19 totaltotal 76.3% 348 / 456 CC 84 SCAR 24.4
CC
84
Cov
80%
read_hash_set
42.0
read_scalar
19.3
read_form
17.0
CRAP 11.5
« blib/lib/Lingy/RT.pm ↑ Summary blib/lib/Lingy/Number.pm »
1 57 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Lingy::Reader;
3  
4 57 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 57 our $feature_keyword = ':lingy.pl';
7  
8 57 my $tokenize_re = qr/
9 (?: # Ignore:
10 \#\!.* | # hashbang line
11 [\s,] | # whitespace, commas,
12 ;.* # comments
13 )*
14 ( # Capture all these tokens:
15 \#\_ | # Ignore next form
16 \#\' | # Var
17 \#\( | # Lambda
18 \#\{ | # HashSet
19 \#\? | # Reader conditional
20 ~@ | # Unquote-splice token
21 [\[\]{}()'`~^@] | # Single character tokens
22 \#? # Possibly a regex
23 "(?: # Quoted string
24 \\. | # Escaped char
25 [^\\"] # Any other char
26 )*"? | # Match if missing ending quote
27 # Other tokens
28 [^\s\[\]\{\}\(\)\'\"\`\,\;]*
29 )
30 /xo;
31  
32 sub new {
33 105 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
34 105 bless {
35 tokens => [],
36 lambda => [],
37 ignore => 0,
38 @_,
39 }, $class;
40 }
41  
42 sub tokenize {
43 [
44 1381 ▶ grep length,
Subroutine tokenize: called CC=1 SCAR=0.0
Pod undocumented
45 $_[0] =~ /$tokenize_re/g
46 ];
47 }
48  
49 sub read_str {
50 1381 ▶ my ($self, $str, $repl) = @_;
Subroutine read_str: called CC=3 SCAR=11.0
Pod undocumented
51 1381 local $self->{repl} = $repl;
52 1381 my $tokens = $self->{tokens} = tokenize($str);
53 1381 my @forms;
54 1381 ▶ while (@$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens) 9925 1367 11292
55 9925 my $form = $self->read_form;
56 9911 ▶ if (defined $form) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $form) 9847 64 9911
57 9847 push @forms, $form;
58 }
59 }
60 1367 return @forms;
61 }
62  
63 sub read_form {
64 203663 ▶ my ($self) = @_;
Subroutine read_form: called CC=17 SCAR=28.4
Pod undocumented
65 203663 my $tokens = $self->{tokens};
66 203663 ▶ while (not @$tokens) { $self->read_more }
Branch: 1 branch
BranchTrueFalseTotal
unless (@$tokens) 0 203663 203663
67 203663 local $_ = $tokens->[0];
68 203663 ▶ /^\($/ ? $self->read_list(LIST, ')') :
Branch: 15 branches
BranchTrueFalseTotal
/^\($/ ? : 45457 158206 203663
/^\[$/ ? : 14025 144181 158206
/^\{$/ ? : 3707 140474 144181
/^\#\{$/ ? : 415 140059 140474
/^'$/ ? : 2319 137740 140059
/^`$/ ? : 1713 136027 137740
/^~$/ ? : 2796 133231 136027
/^~\@$/ ? : 587 132644 133231
/^\@$/ ? : 5 132639 132644
/^\^$/ ? : 1175 131464 132639
/^#\'$/ ? : 1 131463 131464
/^#\($/ ? : 64 131399 131463
/^#_$/ ? : 73 131326 131399
/^#\?$/ ? : 7 131319 131326
/^%\d*$/ ? : 69 131250 131319
69 /^\[$/ ? $self->read_list(VECTOR, ']') :
70 /^\{$/ ? $self->read_hash('map') :
71 /^\#\{$/ ? $self->read_hash('set') :
72 /^'$/ ? $self->read_quote('quote') :
73 /^`$/ ? $self->read_quote('quasiquote') :
74 /^~$/ ? $self->read_quote('unquote') :
75 /^~\@$/ ? $self->read_quote('splice-unquote') :
76 /^\@$/ ? $self->read_quote('deref') :
77 /^\^$/ ? $self->with_meta :
78 /^#\'$/ ? $self->read_var :
79 /^#\($/ ? $self->read_lambda :
80 /^#_$/ ? $self->read_ignore :
81 /^#\?$/ ? $self->read_cond :
82 /^%\d*$/ ? $self->read_lambda_symbol :
83 $self->read_scalar;
84 }
85  
86 sub read_more {
87 0 ▶ my ($self) = @_;
Subroutine read_more: not called CC=3 SCAR=24.8
Pod undocumented
88 0 ▶ if ($self->{repl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"repl"}) 0 0 0
89 0 my $line = Lingy::ReadLine->readline(1);
90 0 ▶ if (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 0 0 0
91 0 push @{$self->{tokens}}, @{tokenize($line)};
92 0 return 1;
93 }
94 }
95 0 return;
96 }
97  
98 sub read_list {
99 59482 ▶ my ($self, $type, $end) = @_;
Subroutine read_list: called CC=4 SCAR=14.7
Pod undocumented
100 59482 my $tokens = $self->{tokens};
101 59482 shift @$tokens;
102 59482 my $list = $type->new([]);
103 59482 while (1) {
104 59482 ▶ while (@$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens) 224639 0 224639
105 224639 ▶ if ($tokens->[0] eq $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[0] eq $end) 59482 165157 224639
106 59482 shift @$tokens;
107 59482 return $list;
108 }
109 165157 push @$list, $self->read_form;
110 }
111 0 ▶ $self->read_more and next;
Branch: 1 branch
BranchTrueFalseTotal
$self->read_more and next 0 0 0
112 0 err "Reached end of input in 'read_list'";
113 }
114 }
115  
116 sub read_var {
117 1 ▶ my ($self) = @_;
Subroutine read_var: called CC=2 SCAR=7.0
Pod undocumented
118 1 shift @{$self->{tokens}};
119 1 my $var = shift @{$self->{tokens}};
120 1 ▶ if ($var !~ m</>) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($var =~ m[/]) 1 0 1
121 1 $var = RT->current_ns_name . "/$var";
122 }
123 1 VAR->new($var);
124 }
125  
126 sub read_lambda {
127 64 ▶ my ($self) = @_;
Subroutine read_lambda: called CC=6 SCAR=18.2
Pod undocumented
128 64 my $tokens = $self->{tokens};
129 64 shift @$tokens;
130 64 push @{$self->{lambda}}, {
131 sym => {},
132 max => 0,
133 };
134 64 my $list = [];
135 64 outer: while (1) {
136 64 ▶ while (@$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens) 250 0 250
137 250 ▶ if ($tokens->[0] eq ')') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[0] eq ")") 64 186 250
138 64 shift @$tokens;
139 64 last outer;
140 }
141 186 push @$list, $self->read_form;
142 }
143 0 ▶ $self->read_more and next;
Branch: 1 branch
BranchTrueFalseTotal
$self->read_more and next 0 0 0
144 0 err "Reached end of input in 'read_list'";
145 }
146 64 my $lambda = pop @{$self->{lambda}};
147 64 my ($sym, $max) = @{$lambda}{'sym', 'max'};
148 64 my $syms = [];
149 64 ▶ for (my $i = 1; $i <= $lambda->{max}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $lambda->{"max"}) 71 64 135
150 71 ▶ push @$syms, $sym->{"%$i"} // symbol("p${i}_${\RT->nextID}");
Condition66%2/3
$$sym{"%$i"} // symbol("p${i}_${\RT()->nextID;}")
l!l&&r!l&&!r
6830
MC/DC0%0/2
$$sym{"%$i"} // symbol("p${i}_${\RT()->nextID;}")
$$sym{"%$i"} symbol("p${i}_${\RT()->nextID;}")
Truth table66%2/3
A // B
A= $$sym{"%$i"}B= symbol("p${i}_${\RT()->nextID;}")
ABresult
1X1
011
000
151 }
152  
153 64 LIST->new([
154 SYMBOL->new('fn*'),
155 VECTOR->new($syms),
156 LIST->new($list),
157 ]);
158 }
159  
160 sub read_lambda_symbol {
161 69 ▶ my ($self) = @_;
Subroutine read_lambda_symbol: called CC=5 SCAR=16.1
Pod undocumented
162 69 my $token = shift @{$self->{tokens}};
163 69 ▶ return symbol($token) unless @{$self->{lambda}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"lambda"};} 0 69 69
164 69 ▶ $token = '%1' if $token eq '%';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "%" 58 11 69
165 69 my $num = substr($token, 1);
166 69 my $lambda = $self->{lambda}->[-1];
167 69 ▶ $lambda->{max} = $num if $num > $lambda->{max};
Branch: 1 branch
BranchTrueFalseTotal
if $num > $lambda->{"max"} 64 5 69
168 69 ▶ $lambda->{sym}{$token} //= symbol("p${num}_${\RT->nextID}");
Condition66%2/3
$lambda->{"sym"}{$token} //= symbol("p${num}_${\RT()->nextID;}")
l!l&&r!l&&!r
1680
MC/DC0%0/2
$lambda->{"sym"}{$token} //= symbol("p${num}_${\RT()->nextID;}")
$lambda->{"sym"}{$token} symbol("p${num}_${\RT()->nextID;}")
Truth table66%2/3
A //= B
A= $lambda->{"sym"}{$token}B= symbol("p${num}_${\RT()->nextID;}")
ABresult
1X1
011
000
169 }
170  
171 sub read_hash {
172 4122 ▶ my ($self, $type) = @_;
Subroutine read_hash: called CC=4 SCAR=14.6
Pod undocumented
173 4122 my $tokens = $self->{tokens};
174 4122 shift @$tokens;
175 4122 my $hash = [];
176 4122 while (1) {
177 4122 ▶ while (@$tokens > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens > 0) 22659 0 22659
178 22659 ▶ if ($tokens->[0] eq '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[0] eq "}") 4122 18537 22659
179 4122 shift @$tokens;
180 4122 my $method = "make_hash_$type";
181 4122 return $self->$method($hash);
182 }
183 18537 push @$hash, $self->read_form;
184 }
185 0 ▶ $self->read_more and next;
Branch: 1 branch
BranchTrueFalseTotal
$self->read_more and next 0 0 0
186 0 err "Reached end of input in 'read_hash'";
187 }
188 }
189  
190 sub make_hash_map {
191 4882 ▶ my ($self, $data) = @_;
Subroutine make_hash_map: called CC=6 SCAR=17.9
Pod undocumented
192 err "Map literal must contain an even number of forms"
193 4882 ▶ if @$data % 2 and not $self->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if @$data % 2 and not $self->{"ignore"} 1 4881 4882
Condition100%3/3
@$data % 2 and not $self->{"ignore"}
!ll&&!rl&&r
488011
MC/DC100%2/2
@$data % 2 and not $self->{"ignore"}
@$data % 2 not $self->{"ignore"}
Truth table100%3/3
A and not(B)
A= @$data % 2B= not $self->{"ignore"}
ABresult
0X0
100
111
194 4881 my %hash;
195 4881 ▶ for (my $i = 0; $i < @$data; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 11807 4880 16687
196 err "Duplicate key: '$data->[$i]'"
197 if $hash{$data->[$i]}++ and
198 11807 ▶ not $self->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $hash{$data->[$i]}++ and not $self->{"ignore"} 1 11806 11807
Condition100%3/3
$hash{$data->[$i]}++ and not $self->{"ignore"}
!ll&&!rl&&r
1180421
MC/DC100%2/2
$hash{$data->[$i]}++ and not $self->{"ignore"}
$hash{$data->[$i]}++ not $self->{"ignore"}
Truth table100%3/3
A and not(B)
A= $hash{$data->[$i]}++B= not $self->{"ignore"}
ABresult
0X0
100
111
199 }
200 4880 HASHMAP->new($data);
201 }
202  
203 sub make_hash_set {
204 415 ▶ my ($self, $data) = @_;
Subroutine make_hash_set: called CC=4 SCAR=13.9
Pod undocumented
205 415 my %hash;
206 415 my $set = [];
207 415 for my $elem (@$data) {
208 err "Duplicate key: '$elem'"
209 if $hash{$elem}++ and
210 423 ▶ not $self->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if $hash{$elem}++ and not $self->{"ignore"} 2 421 423
Condition100%3/3
$hash{$elem}++ and not $self->{"ignore"}
!ll&&!rl&&r
42012
MC/DC100%2/2
$hash{$elem}++ and not $self->{"ignore"}
$hash{$elem}++ not $self->{"ignore"}
Truth table100%3/3
A and not(B)
A= $hash{$elem}++B= not $self->{"ignore"}
ABresult
0X0
100
111
211 421 push @$set, $elem, $elem;
212 }
213 413 HASHSET->new($data);
214 }
215  
216 sub read_hash_set {
217 0 ▶ my ($self) = @_;
Subroutine read_hash_set: not called CC=6 SCAR=37.4
Pod undocumented
218 0 my $tokens = $self->{tokens};
219 0 shift @$tokens;
220 0 my $hash = HASHSET->new([]);
221 0 my $i = 0;
222 0 while (1) {
223 0 ▶ while (@$tokens > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens > 0) 0 0 0
224 0 ▶ if ($tokens->[0] eq '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[0] eq "}") 0 0 0
225 0 shift @$tokens;
226 0 return $hash;
227 }
228 0 $i++;
229 0 my $val = $self->read_form;
230 0 my $key = HASHSET->_get_key($val);
231 err "Duplicate key: '$val'"
232 if exists $hash->{$key} and
233 0 ▶ not $self->{ignore};
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash->{$key} and not $self->{"ignore"} 0 0 0
Condition0%0/3
exists $hash->{$key} and not $self->{"ignore"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $hash->{$key} and not $self->{"ignore"}
exists $hash->{$key} not $self->{"ignore"}
Truth table0%0/3
A and not(B)
A= exists $hash->{$key}B= not $self->{"ignore"}
ABresult
0X0
100
111
234 0 $hash->{$key} = $val;
235 }
236 0 ▶ $self->read_more and next;
Branch: 1 branch
BranchTrueFalseTotal
$self->read_more and next 0 0 0
237 0 err "Reached end of input in 'read_hash_map'";
238 }
239 }
240  
241 57 my $string_re = qr/#?"((?:\\.|[^\\"])*)"/;
242 57 my $string_unescape = {
243 'n' => "\n",
244 't' => "\t",
245 '"' => '"',
246 '\\' => "\\",
247 };
248 57 my $regexp_unescape = {
249 'A' => "\\A",
250 'b' => "\\b",
251 'd' => "\\d",
252 'n' => "\\n",
253 'r' => "\\r",
254 's' => "\\s",
255 't' => "\\t",
256 'w' => "\\w",
257 'z' => "\\z",
258 '"' => '\\"',
259 '.' => '\\.',
260 '\\' => "\\\\",
261 '[' => "\\[",
262 ']' => "\\]",
263 '{' => "\\{",
264 '}' => "\\}",
265 '(' => "\\(",
266 ')' => "\\)",
267 '+' => "\\+",
268 '*' => "\\*",
269 '?' => "\\?",
270 '^' => "\\^",
271 '$' => "\\\$",
272 '|' => "\\|",
273 };
274 sub read_scalar {
275 131250 ▶ my ($self) = @_;
Subroutine read_scalar: called CC=17 SCAR=29.6
Pod undocumented
276 131250 my $scalar = local $_ = shift @{$self->{tokens}};
277  
278 131250 ▶ while (/^(#?)"/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(#?)"/) 8194 123056 131250
279 8194 my $is_regex = $1;
280 8194 ▶ if (/^$string_re$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^$string_re$/) 8194 0 8194
281 8194 s/^$string_re$/$1/;
282 8194 ▶ if (not $self->{ignore}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"ignore"}) 8075 119 8194
283 8075 ▶ if ($is_regex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_regex) { } 10 8065 8075
284 10 s/\\(.)/
285 18 ▶ $regexp_unescape->{$1}
Branch: 1 branch
BranchTrueFalseTotal
$regexp_unescape->{$1} or err("Unsupported escape character '\\$1'") 0 18 18
286 or err("Unsupported escape character '\\$1'")
287 /ge;
288 } else {
289 8065 s/\\(.)/
290 115 ▶ $string_unescape->{$1}
Branch: 1 branch
BranchTrueFalseTotal
$string_unescape->{$1} or err("Unsupported escape character '\\$1'") 3 112 115
291 or err("Unsupported escape character '\\$1'")
292 /ge;
293 }
294 }
295 8191 ▶ return $is_regex ? REGEX->new($_) : STRING->new($_);
Branch: 1 branch
BranchTrueFalseTotal
$is_regex ? : 10 8181 8191
296 }
297 0 ▶ if ($self->{repl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"repl"}) 0 0 0
298 0 my $line = Lingy::ReadLine::readline(1);
299 0 ▶ if (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 0 0 0
300 0 $_ .= "\n$line";
301 0 next;
302 }
303 }
304 0 err "Reached end of input looking for '\"'";
305 }
306 123056 ▶ return nil if $_ eq 'nil';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "nil" 777 122279 123056
307 122279 ▶ return true if $_ eq 'true';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "true" 2522 119757 122279
308 119757 ▶ return false if $_ eq 'false';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "false" 727 119030 119757
309 119030 ▶ return KEYWORD->new($_) if /^:/;
Branch: 1 branch
BranchTrueFalseTotal
if /^:/ 10274 108756 119030
310 108756 ▶ return NUMBER->new($_) if /^-?\d+(?:\.\d+)?$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^-?\d+(?:\.\d+)?$/ 2860 105896 108756
311 105896 ▶ return CHARACTER->read($_) if /^\\/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\\/ 2 105894 105896
312 105894 ▶ err "Unmatched delimiter: '$_'" if /^[\)\]\}]$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[\)\]\}]$/ 4 105890 105894
313 105890 return $self->read_symbol($_);
314 }
315  
316 # Defined separately to allow subclassing:
317 sub read_symbol {
318 105890 ▶ my ($self, $symbol) = @_;
Subroutine read_symbol: called CC=4 SCAR=13.9
Pod undocumented
319 105890 ▶ if (my $ids = $self->{autogensym}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ids = $self->{"autogensym"}) 9662 96228 105890
320 9662 ▶ if ($symbol =~ m{^([^/]+)#$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ m[^([^/]+)#$]) 755 8907 9662
321 755 ▶ my $id = $ids->{$1} //= RT->nextID();
Condition66%2/3
$ids->{$1} //= RT()->nextID
l!l&&r!l&&!r
4642910
MC/DC0%0/2
$ids->{$1} //= RT()->nextID
$ids->{$1} RT()->nextID
Truth table66%2/3
A //= B
A= $ids->{$1}B= RT()->nextID
ABresult
1X1
011
000
322 755 $symbol =~ s/#$/__${id}__auto__/;
323 }
324 }
325 105890 symbol($symbol);
326 }
327  
328 sub read_quote {
329 7420 ▶ my ($self, $quote) = @_;
Subroutine read_quote: called CC=2 SCAR=6.9
Pod undocumented
330 7420 shift @{$self->{tokens}};
331 7420 my $form;
332 7420 ▶ if ($quote eq 'quasiquote') {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote eq 'quasiquote') { } 1713 5707 7420
333 1713 $self->{autogensym} = {};
334 1713 $form = $self->read_form;
335 1713 delete $self->{autogensym};
336 } else {
337 5707 $form = $self->read_form;
338 }
339 7420 return list([symbol($quote), $form]);
340 }
341  
342 sub with_meta {
343 1175 ▶ my ($self) = @_;
Subroutine with_meta: called CC=7 SCAR=19.5
Pod undocumented
344  
345 1175 my $tokens = $self->{tokens};
346 1175 my @meta;
347  
348 1175 ▶ while (@$tokens > 2 and $tokens->[0] eq '^') {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens > 2 and $tokens->[0] eq "^") 1180 1175 2355
Condition100%3/3
@$tokens > 2 and $tokens->[0] eq "^"
!ll&&!rl&&r
111741180
MC/DC100%2/2
@$tokens > 2 and $tokens->[0] eq "^"
@$tokens > 2 $tokens->[0] eq "^"
Truth table100%3/3
A and B
A= @$tokens > 2B= $tokens->[0] eq "^"
ABresult
0X0
100
111
349 1180 shift @$tokens;
350 1180 my $meta = $self->read_form;
351 1180 my $type = ref($meta);
352 1180 ▶ if ($type eq SYMBOL or $type eq STRING) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'Lingy::Symbol' or $type eq 'Lingy::String') { } 181 999 1180
elsif ($type eq 'Lingy::Keyword') { } 468 531 999
elsif ($type eq 'Lingy::HashMap') { } 531 0 531
Condition100%3/3
$type eq "Lingy::Symbol" or $type eq "Lingy::String"
l!l&&r!l&&!r
1792999
MC/DC100%2/2
$type eq "Lingy::Symbol" or $type eq "Lingy::String"
$type eq "Lingy::Symbol" $type eq "Lingy::String"
Truth table100%3/3
A or B
A= $type eq "Lingy::Symbol"B= $type eq "Lingy::String"
ABresult
1X1
011
000
353 181 unshift @meta, KEYWORD->new(':tag'), $meta;
354 } elsif ($type eq KEYWORD) {
355 468 unshift @meta, $meta, true;
356 } elsif ($type eq HASHMAP) {
357 531 unshift @meta, %$meta;
358 } else {
359 0 err "Metadata must be Symbol,Keyword,String or Map"
360 }
361 }
362  
363 1175 my $meta = $self->make_hash_map(\@meta);
364  
365 1175 my $form = $self->read_form;
366  
367 1175 RT->meta->{"$form"} = $meta;
368  
369 1175 return $form;
370 }
371  
372 sub read_ignore {
373 73 ▶ my ($self) = @_;
Subroutine read_ignore: called CC=2 SCAR=6.9
Pod undocumented
374 73 $self->{ignore}++;
375 73 my $tokens = $self->{tokens};
376 73 shift @$tokens;
377 73 ▶ while (not defined $self->read_form) {}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->read_form) 4 73 77
378 73 $self->{ignore}--;
379 73 return;
380 }
381  
382 sub read_cond {
383 7 ▶ my ($self) = @_;
Subroutine read_cond: called CC=8 SCAR=20.8
Pod undocumented
384 7 my $tokens = $self->{tokens};
385 7 shift @$tokens;
386 7 ▶ err "read-cond body must be a list"
Branch: 1 branch
BranchTrueFalseTotal
unless @$tokens and $tokens->[0] eq "(" 1 6 7
Condition66%2/3
@$tokens and $tokens->[0] eq "("
!ll&&!rl&&r
016
MC/DC50%1/2
@$tokens and $tokens->[0] eq "("
@$tokens $tokens->[0] eq "("
Truth table66%2/3
A and B
A= @$tokensB= $tokens->[0] eq "("
ABresult
0X0
100
111
387 unless @$tokens and $tokens->[0] eq '(';
388 6 my $list = $self->read_form;
389 6 ▶ err "read-cond requires an even number of forms"
Branch: 1 branch
BranchTrueFalseTotal
if @$list % 2 1 5 6
390 if @$list % 2;
391 5 ▶ while (@$list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$list) 7 1 8
392 7 my ($keyword, $form) = splice(@$list, 0, 2);
393 7 ▶ err "Feature should be a keyword: $keyword"
Branch: 1 branch
BranchTrueFalseTotal
unless $keyword->isa("Lingy::Keyword") 1 6 7
394 unless $keyword->isa(KEYWORD);
395 6 ▶ if ("$keyword" eq $feature_keyword or
Branch: 1 branch
BranchTrueFalseTotal
if ("$keyword" eq $Lingy::Reader::feature_keyword or "$keyword" eq ":default") 3 3 6
Condition100%3/3
"$keyword" eq $Lingy::Reader::feature_keyword or "$keyword" eq ":default"
l!l&&r!l&&!r
123
MC/DC100%2/2
"$keyword" eq $Lingy::Reader::feature_keyword or "$keyword" eq ":default"
"$keyword" eq $Lingy::Reader::feature_keyword "$keyword" eq ":default"
Truth table100%3/3
A or B
A= "$keyword" eq $Lingy::Reader::feature_keywordB= "$keyword" eq ":default"
ABresult
1X1
011
000
396 "$keyword" eq ':default'
397 ) {
398 3 return $form;
399 }
400 }
401 1 return;
402 }
403  
404 57 1;
« blib/lib/Lingy/RT.pm ↑ Summary blib/lib/Lingy/Number.pm »