blib/lib/YATT/Lite/LanguageServer/SpecParser.pm

filter: Statementstmt 10.8% 23 / 212 Branchbran 0.8% 1 / 118 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 21.8% 7 / 32 Podpod 0.0% 0 / 22 totaltotal 7.2% 31 / 428 CC 70 SCAR 44.6
CC
70
Cov
7%
parse_declbody
272.0
parse_typeconj
210.0
__ANON__
42.0
CRAP 86.8
« blib/lib/YATT/Lite/LanguageServer/Spec2Types.pm ↑ Summary blib/lib/YATT/Lite/Test/TestFCGI.pm »
1 #!/usr/bin/env perl
2 package YATT::Lite::LanguageServer::SpecParser;
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::AddInc;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use MOP4Import::Base::CLI_JSON -as_base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use open qw/:std :locale/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 use MOP4Import::Types
11 1 ▶ (Annotated => [[fields => qw/comment body deprecated/]
Subroutine BEGIN: called CC=1 SCAR=0.0
12 , [subtypes =>
13 Decl => [[fields => qw/kind name exported/]
14 , [subtypes =>
15 Interface => [[fields => qw/extends/]]
16 ]]
17 ]]
18 1 );
19  
20 # SpecParser.pm extract_codeblock typescript specification.md|
21 # SpecParser.pm cli_xargs_json extract_statement_list|
22 # grep -v 'interface ParameterInformation'|
23 # SpecParser.pm cli_xargs_json --single tokenize_statement_list|
24 # SpecParser.pm cli_xargs_json --single parse_statement_list |
25 # jq --slurp .
26  
27 0 ▶sub parse_files :method {
Subroutine parse_files: not called CC=1 SCAR=6.9
Pod undocumented
28 0 (my MY $self, my @files) = @_;
29 0 $self->parse_statement_list(
30 [$self->tokenize_statement_list(
31 [$self->extract_statement_list(
32 [$self->extract_codeblock(typescript => @files)]
33 )]
34 )]
35 );
36 }
37  
38 0 ▶sub parse_statement_list :method {
Subroutine parse_statement_list: not called CC=5 SCAR=34.0
Pod undocumented
39 0 (my MY $self, my $statementTokList) = @_;
40 map {
41 0 my ($declarator, $comment, $bodyTokList) = @$_;
42 #
43 0 my Decl $decl = $self->parse_declarator($declarator);
44 0 $self->parse_comment_into_decl($decl, $comment);
45  
46 0 ▶ if (my $sub = $self->can("parse_$decl->{kind}_declbody")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can("parse_$decl->{'kind'}_declbody")) { } 0 0 0
47 0 $decl->{body} = \ my @body;
48 0 ▶ while (@$bodyTokList) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$bodyTokList) 0 0 0
49 0 push @body, $sub->($self, $decl, $bodyTokList);
50 }
51 0 ▶ if (@$bodyTokList) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$bodyTokList) 0 0 0
52 0 $self->tokerror(["Invalid trailing token(s) for declbody of ", $decl]
53 , $bodyTokList);
54 }
55 } else {
56 print STDERR "# Not yet supported: "
57 . MOP4Import::Util::terse_dump($_), "\n"
58 0 ▶ unless $self->{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quiet"} 0 0 0
59 }
60  
61 0 $decl;
62  
63 } @$statementTokList;
64 }
65  
66 0 ▶sub tokerror {
Subroutine tokerror: not called CC=1 SCAR=6.9
Pod undocumented
67 0 (my MY $self, my $diag, my $bodyTokList) = @_;
68 0 Carp::croak MOP4Import::Util::terse_dump($diag)
69 . ": " . MOP4Import::Util::terse_dump($bodyTokList);
70 }
71  
72 0 ▶sub parse_comment_into_decl :method {
Subroutine parse_comment_into_decl: not called CC=3 SCAR=24.8
Pod undocumented
73 0 (my MY $self, my Decl $decl, my $comment) = @_;
74 0 ▶ return unless defined $comment;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $comment 0 0 0
75 0 ▶ if ($comment =~ s/\@deprecated(?:\s+(?<by>\S[^\n]*))?//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comment =~ s/\@deprecated(?:\s+(?<by>\S[^\n]*))?//) 0 0 0
76 0 $decl->{deprecated} = $+{by};
77 }
78 0 $decl->{comment} = $comment;
79 }
80  
81 0 ▶sub parse_type_declbody :method {
Subroutine parse_type_declbody: not called CC=1 SCAR=6.9
Pod undocumented
82 0 (my MY $self, my Decl $decl, my $bodyTokList) = @_;
83 0 $self->parse_typeunion($decl, $bodyTokList);
84 }
85  
86 0 ▶sub parse_namespace_declbody :method {
Subroutine parse_namespace_declbody: not called CC=1 SCAR=6.9
Pod undocumented
87 0 (my MY $self, my Decl $decl, my $bodyTokList) = @_;
88 $self->parse_declbody(
89 0 ▶ $decl, $bodyTokList, [], sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
90 0 (my $origTok, my Annotated $ast) = @_;
91 0 my $tok = $origTok;
92 # Currently only something like `export const Error = 1;` are supported.
93 0 ▶ $tok =~ s{^export\s+const\s+(\w+)\s*}{}x or do {
Branch: 1 branch
BranchTrueFalseTotal
$tok =~ s/^export\s+const\s+(\w+)\s*//x or do { $self->tokerror(["Unsupported namespace statement: ", $tok, "decl", $decl], $bodyTokList) } 0 0 0
94 0 $self->tokerror(["Unsupported namespace statement: ", $tok
95 , decl => $decl], $bodyTokList);
96 };
97 0 my $name = $1;
98  
99 0 my ($type, $value);
100 0 ▶ if ($tok =~ m{= \s* (\S+)\z}x) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok =~ /= \s* (\S+)\z/x) { } 0 0 0
elsif ($self->eat_token(':', $bodyTokList)) { } 0 0 0
101 0 $value = $1;
102 } elsif ($self->eat_token(':', $bodyTokList)) {
103 0 ($type, $value) = $self->re_match_token(qr{([^\s=]+) (?: \s* = \s* (\S+))?}xs, $bodyTokList);
104 } else {
105 0 $self->tokerror(["Unsupported namespace statement: ", $origTok
106 , decl => $decl], $bodyTokList);
107 }
108  
109 # , $type, $value
110  
111 # (?: : \s* ([^\s=]+) \s*)?
112 # (?: = \s* (\S+))?
113  
114 # and $self->eat_token(':', $bodyTokList))
115 0 $ast->{body} = my Decl $const = {};
116 # enum assignment.
117 0 $const->{kind} = 'const';
118 0 $const->{name} = $name;
119 0 my $expr = $self->unquote_string($value);
120 0 ▶ $const->{body} = (defined $type ? [$type => $expr] : $expr);
Branch: 1 branch
BranchTrueFalseTotal
defined $type ? : 0 0 0
121 0 $self->eat_token(';', $bodyTokList);
122 0 ▶ return defined $ast->{comment} ? $ast : $ast->{body};
Branch: 1 branch
BranchTrueFalseTotal
defined $ast->{'comment'} ? : 0 0 0
123 }
124 0 );
125 }
126  
127 0 ▶sub unquote_string :method {
Subroutine unquote_string: not called CC=2 SCAR=17.9
Pod undocumented
128 0 (my MY $self, my $str) = @_;
129 0 ▶ $str =~ s/^'([^']*)'\z/$1/ or
Branch: 1 branch
BranchTrueFalseTotal
$str =~ s/^'([^']*)'\z/$1/ or $str =~ s/^"([^"]*)"\z/$1/ 0 0 0
130 $str =~ s/^"([^"]*)"\z/$1/;
131 0 $str;
132 }
133  
134 0 ▶sub parse_enum_declbody :method {
Subroutine parse_enum_declbody: not called CC=1 SCAR=6.9
Pod undocumented
135 0 (my MY $self, my Decl $decl, my $bodyTokList) = @_;
136 $self->parse_declbody(
137 0 ▶ $decl, $bodyTokList, [], sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
138 0 (my $tok, my Annotated $ast) = @_;
139 0 ▶ $tok =~ s{^(?<ident>\w+)\s*=\s*}{}x
Branch: 1 branch
BranchTrueFalseTotal
$tok =~ s/^(?<ident>\w+)\s*=\s*//x or return 0 0 0
140 or return;
141 # enum assignment.
142 0 $ast->{body} = [$+{ident}, $tok];
143 # ',' may not exist
144 0 $self->eat_token(',', $bodyTokList);
145 0 ▶ return defined $ast->{comment} ? $ast : $ast->{body};
Branch: 1 branch
BranchTrueFalseTotal
defined $ast->{'comment'} ? : 0 0 0
146 }
147 0 );
148 }
149  
150 0 ▶sub parse_class_declbody :method {
Subroutine parse_class_declbody: not called CC=1 SCAR=6.9
Pod undocumented
151 0 shift->parse_interface_declbody(@_);
152 }
153  
154 0 ▶sub parse_interface_declbody :method {
Subroutine parse_interface_declbody: not called CC=1 SCAR=6.9
Pod undocumented
155 0 (my MY $self, my Decl $decl, my $bodyTokList) = @_;
156  
157 # I'm not sure why this requires ',' too.
158 # Found after TextDocumentClientCapabilities.completion.completionItemKind
159  
160 $self->parse_declbody(
161 0 ▶ $decl, $bodyTokList, [';', ','], sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
162 0 (my $tok, my Annotated $ast) = @_;
163 0 ▶ ($tok =~ s{^(?:(?<ro>readonly)\s+)?
Branch: 1 branch
BranchTrueFalseTotal
$tok =~ s/^(?:(?<ro>readonly)\s+)? (?<slotName>(?:\w+ |\[[^]]+\]) \??)//x and $self->eat_token(":", $bodyTokList) or return 0 0 0
Condition0%0/3
$tok =~ s/^(?:(?<ro>readonly)\s+)? (?<slotName>(?:\w+ |\[[^]]+\]) \??)//x and $self->eat_token(":", $bodyTokList)
!ll&&!rl&&r
000
MC/DC0%0/2
$tok =~ s/^(?:(?<ro>readonly)\s+)? (?<slotName>(?:\w+ |\[[^]]+\]) \??)//x and $self->eat_token(":", $bodyTokList)
$tok =~ s/^(?:(?<ro>readonly)\s+)? (?<slotName>(?:\w+ |\[[^]]+\]) \??)//x $self->eat_token(":", $bodyTokList)
Truth table0%0/3
A and B
A= $tok =~ s/^(?:(?<ro>readonly)\s+)? (?<slotName>(?:\w+ |\[[^]]+\]) \??)//xB= $self->eat_token(":", $bodyTokList)
ABresult
0X0
100
111
164 (?<slotName>(?:\w+ |\[[^]]+\]) \??)}{}x
165 and $self->eat_token(':', $bodyTokList))
166 or return;
167 # Drop 'readonly' for now.
168 # slot
169 0 $ast->{body} = my $slotDef = [$+{slotName}];
170 0 ▶ unshift @$bodyTokList, $tok if $tok =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $tok =~ /\S/ 0 0 0
171 0 push @$slotDef, $self->parse_typeunion($decl, $bodyTokList);
172 0 ▶ return defined $ast->{comment} ? $ast : $ast->{body};
Branch: 1 branch
BranchTrueFalseTotal
defined $ast->{'comment'} ? : 0 0 0
173 }
174 0 );
175 }
176  
177 # https://github.com/microsoft/TypeScript/blob/master/doc/spec.md#A
178  
179 0 ▶sub parse_declbody :method {
Subroutine parse_declbody: not called CC=16 SCAR=56.1
Pod undocumented
180 0 (my MY $self, my Decl $decl, my ($bodyTokList, $terminators, $elemParser)) = @_;
181 0 my @result;
182 0 ▶ unless ($self->eat_token('{', $bodyTokList)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eat_token("{", $bodyTokList)) 0 0 0
183 0 $self->tokerror(["Invalid leading token for declbody of ", $decl], $bodyTokList);
184 }
185 0 my Annotated $ast = +{};
186 0 ▶ while (@$bodyTokList and $bodyTokList->[0] ne '}') {
Branch: 1 branch
BranchTrueFalseTotal
if (@$bodyTokList and $bodyTokList->[0] ne "}") 0 0 0
Condition0%0/3
@$bodyTokList and $bodyTokList->[0] ne "}"
!ll&&!rl&&r
000
MC/DC0%0/2
@$bodyTokList and $bodyTokList->[0] ne "}"
@$bodyTokList $bodyTokList->[0] ne "}"
Truth table0%0/3
A and B
A= @$bodyTokListB= $bodyTokList->[0] ne "}"
ABresult
0X0
100
111
187 0 my $tok = shift @$bodyTokList;
188 0 ▶ if ($tok eq '{') {
Branch: 5 branches
BranchTrueFalseTotal
if ($tok eq '{') { } 0 0 0
elsif ($tok eq '[') { } 0 0 0
elsif ($tok =~ m[^/\*\*]) { } 0 0 0
elsif ($tok =~ m[^//]) { } 0 0 0
elsif (my $elem = &$elemParser($tok, $ast)) { } 0 0 0
189 0 $ast->{body} = [$self->parse_declbody($decl, $bodyTokList, $terminators, $elemParser)];
190 } elsif ($tok eq '[') {
191 # Index Signatures. 3.9.4
192 0 ▶ unless (@$bodyTokList >= 4
Branch: 1 branch
BranchTrueFalseTotal
unless (@$bodyTokList >= 4 and $bodyTokList->[0] =~ /^\w+\z/ and $bodyTokList->[1] eq ":") 0 0 0
Condition0%0/6
@$bodyTokList >= 4 and $bodyTokList->[0] =~ /^\w+\z/ and $bodyTokList->[1] eq ":"
!ll&&!rl&&r
000
@$bodyTokList >= 4 and $bodyTokList->[0] =~ /^\w+\z/
!ll&&!rl&&r
000
MC/DC0%0/3
@$bodyTokList >= 4 and $bodyTokList->[0] =~ /^\w+\z/ and $bodyTokList->[1] eq ":"
@$bodyTokList >= 4 $bodyTokList->[0] =~ /^\w+\z/ $bodyTokList->[1] eq ":"
Truth table0%0/4
A and B and C
A= @$bodyTokList >= 4B= $bodyTokList->[0] =~ /^\w+\z/C= $bodyTokList->[1] eq ":"
ABCresult
0XX0
10X0
1100
1111
193 and $bodyTokList->[0] =~ /^\w+\z/
194 and $bodyTokList->[1] eq ':') {
195 0 Carp::croak "Invalid Index Signature after '[':"
196 . MOP4Import::Util::terse_dump($bodyTokList);
197 }
198 0 (my $name, undef, my $ixType, undef) = splice @$bodyTokList, 0, 4;
199 0 $ast->{body} = my $slotDef = [$name];
200 0 ▶ if ($self->eat_token(':', $bodyTokList)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eat_token(":", $bodyTokList)) 0 0 0
201 0 push @$slotDef, $self->parse_typeunion($decl, $bodyTokList);
202 }
203 0 push @result, $ast;
204 0 $ast = +{};
205 } elsif ($tok =~ m{^/\*\*}) {
206 0 $self->parse_comment_into_decl($ast, $self->tokenize_comment_block($tok));
207 } elsif ($tok =~ m{^//}) {
208 # Just ignored.
209 } elsif (my $elem = $elemParser->($tok, $ast)) {
210 0 push @result, $elem;
211 0 $ast = +{};
212 } else {
213 0 die "HOEHOE? tok='$tok': "
214 .MOP4Import::Util::terse_dump($bodyTokList, [decl => $decl]);
215 }
216 }
217 0 ▶ unless ($self->eat_token('}', $bodyTokList)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eat_token("}", $bodyTokList)) 0 0 0
218 0 $self->tokerror(["Invalid closing token for declbody of ", $decl], $bodyTokList);
219 }
220  
221 # trailing terminators after '}' is eaten here.
222 0 $self->eat_token($_, $bodyTokList) for @$terminators;
223  
224 0 ▶ if (%$ast) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$ast) 0 0 0
225 0 $self->tokerror(["Something went wrong for declbody of ", $decl], $bodyTokList);
226 }
227 0 @result;
228 }
229  
230 # I call here UnionOrIntersectionOrPrimaryType as typeunion
231 # and IntersectionOrPrimaryType as typeconj
232  
233 # typeunion -> typeconj -> typeunion
234  
235 0 ▶sub parse_typeunion :method {
Subroutine parse_typeunion: not called CC=6 SCAR=37.4
Pod undocumented
236 0 (my MY $self, my Decl $decl, my $bodyTokList) = @_;
237 0 my @union;
238 0 ▶ while (@$bodyTokList and $bodyTokList->[0] ne ';') {
Branch: 1 branch
BranchTrueFalseTotal
if (@$bodyTokList and $bodyTokList->[0] ne ";") 0 0 0
Condition0%0/3
@$bodyTokList and $bodyTokList->[0] ne ";"
!ll&&!rl&&r
000
MC/DC0%0/2
@$bodyTokList and $bodyTokList->[0] ne ";"
@$bodyTokList $bodyTokList->[0] ne ";"
Truth table0%0/3
A and B
A= @$bodyTokListB= $bodyTokList->[0] ne ";"
ABresult
0X0
100
111
239 0 ▶ if ($bodyTokList->[0] eq '{') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bodyTokList->[0] eq '{') { } 0 0 0
240 0 push @union, $self->parse_interface_declbody($decl, $bodyTokList);
241 } else {
242 0 push @union, $self->parse_typeconj($decl, $bodyTokList);
243 0 ▶ if ($self->eat_token(';', $bodyTokList)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eat_token(";", $bodyTokList)) 0 0 0
244 0 last;
245 }
246 }
247 0 ▶ if (not $self->eat_token('|', $bodyTokList)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eat_token("|", $bodyTokList)) 0 0 0
248 0 last;
249 }
250 }
251 0 @union;
252 }
253  
254 #
255 # parse conjunctive? type expression. (IntersectionOrPrimaryType)
256 #
257 0 ▶sub parse_typeconj :method {
Subroutine parse_typeconj: not called CC=14 SCAR=53.5
Pod undocumented
258 0 (my MY $self, my Decl $decl, my $bodyTokList) = @_;
259 0 ▶ if (my ($ident, $bracket) = $bodyTokList->[0] =~ /^(\w+(?:<[^>]+>)?)(\[\])?\z/) {
Branch: 4 branches
BranchTrueFalseTotal
if (() = $bodyTokList->[0] =~ /^(\w+(?:<[^>]+>)?)(\[\])?\z/) { } 0 0 0
elsif (my($string) = $bodyTokList->[0] =~ /^('[^']*' | "[^"]*" )\z/x) { } 0 0 0
elsif ($self->eat_token('(', $bodyTokList)) { } 0 0 0
elsif ($self->eat_token('[', $bodyTokList)) { } 0 0 0
260 0 shift @$bodyTokList;
261 0 ▶ return defined $bracket ? [$ident, $bracket] : $ident;
Branch: 1 branch
BranchTrueFalseTotal
defined $bracket ? : 0 0 0
262 } elsif (my ($string) = $bodyTokList->[0] =~ /^('[^']*' | "[^"]*" )\z/x) {
263 0 shift @$bodyTokList;
264 0 return [constant => $string];
265 } elsif ($self->eat_token('(', $bodyTokList)) {
266 0 my $expr = [\ my @union];
267 0 ▶ until ($self->eat_token(')', $bodyTokList)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eat_token(")", $bodyTokList)) 0 0 0
268 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->eat_token("|", $bodyTokList) and do { do { my $e = $self->parse_typeconj($decl, $bodyTokList); if ($self->eat_token("&", $bodyTokList)) { $e = ["&", $e]; do { push @$e, $self->parse_typeconj($decl, $bodyTokList) } while $self->eat_token("&", $bodyTokList); } ; push @union, $e } } 0 0 0
269 0 my $e = $self->parse_typeconj($decl, $bodyTokList);
270 0 ▶ if ($self->eat_token('&', $bodyTokList)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eat_token("&", $bodyTokList)) 0 0 0
271 0 $e = ['&', $e];
272 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->eat_token("&", $bodyTokList) and do { do { push @$e, $self->parse_typeconj($decl, $bodyTokList) } } 0 0 0
273 0 push @$e, $self->parse_typeconj($decl, $bodyTokList);
274 } while ($self->eat_token('&', $bodyTokList));
275 }
276 0 push @union, $e;
277 } while ($self->eat_token('|', $bodyTokList));
278 }
279 # For ()[] <-- this.
280 0 ▶ if (my $bracket = $self->eat_token('[]', $bodyTokList)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $bracket = $self->eat_token("[]", $bodyTokList)) 0 0 0
281 0 push @$expr, $bracket;
282 }
283 0 return $expr;
284 } elsif ($self->eat_token('[', $bodyTokList)) {
285 0 my $expr = [\ my @tuple]; # XXX
286 0 ▶ unless ($self->eat_token(']', $bodyTokList)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eat_token("]", $bodyTokList)) 0 0 0
287 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->eat_token(",", $bodyTokList) and do { do { push @tuple, my $e = $self->parse_typeconj($decl, $bodyTokList) } } 0 0 0
288 0 push @tuple, my $e = $self->parse_typeconj($decl, $bodyTokList);
289 } while ($self->eat_token(',', $bodyTokList));
290 }
291 0 ▶ unless ($self->eat_token(']', $bodyTokList)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eat_token("]", $bodyTokList)) 0 0 0
292 0 $self->tokerror(["Tuple not closed for declbody of ", $decl], $bodyTokList);
293 }
294 0 return $expr;
295 } else {
296 0 die "Really? ".MOP4Import::Util::terse_dump($bodyTokList, [decl => $decl]);
297 }
298 }
299  
300 0 ▶sub parse_declarator :method {
Subroutine parse_declarator: not called CC=4 SCAR=30.0
Pod undocumented
301 0 (my MY $self, my $declTokIn) = @_;
302 0 my $declTok = [@$declTokIn];
303 0 my Decl $decl = {};
304 0 ▶ if ($self->eat_token(export => $declTok)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eat_token("export", $declTok)) 0 0 0
305 0 $decl->{exported} = 1;
306 }
307 0 $decl->{kind} = shift @$declTok;
308 0 $decl->{name} = shift @$declTok;
309 0 ▶ if ($decl->{kind} eq 'interface') {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->{"kind"} eq "interface") 0 0 0
310 0 ▶ if ($self->eat_token(extends => $declTok)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eat_token("extends", $declTok)) 0 0 0
311 0 my Interface $if = $decl;
312 0 $if->{extends} = shift @$declTok;
313 }
314 }
315 0 $decl;
316 }
317  
318 0 ▶sub eat_token :method {
Subroutine eat_token: not called CC=3 SCAR=24.8
Pod undocumented
319 0 (my MY $self, my ($tokString, $tokList)) = @_;
320 0 ▶ if (@$tokList and $tokList->[0] eq $tokString) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokList and $tokList->[0] eq $tokString) 0 0 0
Condition0%0/3
@$tokList and $tokList->[0] eq $tokString
!ll&&!rl&&r
000
MC/DC0%0/2
@$tokList and $tokList->[0] eq $tokString
@$tokList $tokList->[0] eq $tokString
Truth table0%0/3
A and B
A= @$tokListB= $tokList->[0] eq $tokString
ABresult
0X0
100
111
321 0 shift @$tokList;
322 }
323 }
324  
325 0 ▶sub re_match_token :method {
Subroutine re_match_token: not called CC=3 SCAR=24.8
Pod undocumented
326 0 (my MY $self, my ($pattern, $tokList)) = @_;
327 0 ▶ if (@$tokList and my @match = ($tokList->[0] =~ $pattern)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokList and my(@match) = $tokList->[0] =~ /$pattern/) 0 0 0
Condition0%0/3
@$tokList and my(@match) = $tokList->[0] =~ /$pattern/
!ll&&!rl&&r
000
MC/DC0%0/2
@$tokList and my(@match) = $tokList->[0] =~ /$pattern/
@$tokList my(@match) = $tokList->[0] =~ /$pattern/
Truth table0%0/3
A and B
A= @$tokListB= my(@match) = $tokList->[0] =~ /$pattern/
ABresult
0X0
100
111
328 0 shift @$tokList;
329 0 return @match;
330 }
331 0 return ();
332 }
333  
334 #----------------------------------------
335  
336 0 ▶sub tokenize_statement_list :method {
Subroutine tokenize_statement_list: not called CC=1 SCAR=6.9
Pod undocumented
337 0 (my MY $self, my $statementList) = @_;
338 map {
339 0 my ($declarator, $comment, $body) = @$_;
340 0 [$self->tokenize_declarator($declarator)
341 , $self->tokenize_comment_block($comment)
342 , $self->tokenize_declbody($body)];
343 } @$statementList;
344 }
345  
346 0 ▶sub tokenize_declbody :method {
Subroutine tokenize_declbody: not called CC=1 SCAR=6.9
Pod undocumented
347 0 (my MY $self, my $declString) = @_;
348 0 [map {s/\s*\z//; $_}
349 0 grep {/\S/}
350 split m{(; | [{}(),\|&:]
351 | \[ (?=[^]]) | (?<!\[) \]
352 | /\*\*\n(?:.*?)\*/ | //[^\n]*\n) \s*}xs, $declString];
353 }
354  
355 0 ▶sub tokenize_comment_block :method {
Subroutine tokenize_comment_block: not called CC=4 SCAR=30.0
Pod undocumented
356 0 (my MY $self, my $commentString) = @_;
357 0 ▶ return undef unless defined $commentString;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $commentString 0 0 0
358 0 ▶ unless ($commentString =~ s,^\s*/\*\*\n,,s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($commentString =~ s[^\s*/\*\*\n][]s) 0 0 0
359 0 Carp::croak "Comment doesn't start with /**\\n: "
360 . MOP4Import::Util::terse_dump($commentString);
361 }
362 0 ▶ unless ($commentString =~ s,\*/\n?\z,,s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($commentString =~ s[\*/\n?\z][]s) 0 0 0
363 0 Carp::croak "Comment doesn't end with */: "
364 . MOP4Import::Util::terse_dump($commentString);
365 }
366 0 $commentString =~ s/^\s+\*\ //mg;
367 0 $commentString =~ s/\s+\z//;
368 0 $commentString;
369 }
370  
371 0 ▶sub tokenize_declarator :method {
Subroutine tokenize_declarator: not called CC=1 SCAR=6.9
Pod undocumented
372 0 (my MY $self, my $declString) = @_;
373 0 [split " ", $declString];
374 }
375  
376 0 ▶sub extract_statement_list :method {
Subroutine extract_statement_list: not called CC=4 SCAR=30.0
Pod undocumented
377 0 (my MY $self, my ($codeList)) = @_;
378 0 local $_;
379 0 my $wordRe = qr{[^\s{}=\|]+};
380 0 my $commentRe = qr{/\*\*\n(?:.*?)\*/\n?}sx;
381 0 my $groupRe = qr{( \{ (?: (?> [^{}/]+) | $commentRe | /[^\*] | (?-1) )* \} )}x;
382 0 my $typeElemRe = qr{$wordRe | $groupRe}sx;
383 0 my @result;
384 0 foreach (@$codeList) {
385 0 ▶ while (m{
Branch: 1 branch
BranchTrueFalseTotal
if (/ \G \s* (?<comment>$commentRe)? (?<decl>(?:$wordRe\s+)+) (?: (?<body> $groupRe ) | = \s* (?<type> $typeElemRe (?: \s* \| \s*$typeElemRe)* ) \s*; ) /gsx) 0 0 0
386 \G
387 \s*
388 (?<comment>$commentRe)?
389 (?<decl>(?:$wordRe\s+)+)
390 (?: (?<body> $groupRe )
391 | = \s* (?<type>
392 $typeElemRe (?: \s* \| \s*$typeElemRe)*
393 )
394 \s*;
395 )
396 }sgx) {
397 0 ▶ push @result, [$+{decl}, $+{comment}, $+{body} // $+{type}];
Condition0%0/3
$+{"body"} // $+{"type"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$+{"body"} // $+{"type"}
$+{"body"} $+{"type"}
Truth table0%0/3
A // B
A= $+{"body"}B= $+{"type"}
ABresult
1X1
011
000
398 }
399 }
400 0 @result;
401 }
402  
403 # Lite/LanguageServer/SpecParser.pm --flatten --output=raw extract_codeblock typescript specification.md
404 0 ▶sub extract_codeblock :method {
Subroutine extract_codeblock: not called CC=6 SCAR=37.4
Pod undocumented
405 0 (my MY $self, my $langId, local @ARGV) = @_;
406 0 local $_;
407 0 my ($chunk, @result);
408 0 ▶ while (defined($_ = $self->cli_compat_diamond)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->cli_compat_diamond)) 0 0 0
409 0 ▶ my $line = s{^```$langId\b}{} .. s{^```}{}
Branch: 1 branch
BranchTrueFalseTotal
my $line = s/^```$langId\b// .. s/^```// or next 0 0 0
410 or next;
411 0 my $end = $line =~ /E0/;
412 0 s/\r//;
413 0 ▶ $chunk .= $_ if $line >= 2 and not $end;
Branch: 1 branch
BranchTrueFalseTotal
if $line >= 2 and not $end 0 0 0
Condition0%0/3
$line >= 2 and not $end
!ll&&!rl&&r
000
MC/DC0%0/2
$line >= 2 and not $end
$line >= 2 not $end
Truth table0%0/3
A and not(B)
A= $line >= 2B= not $end
ABresult
0X0
100
111
414 0 ▶ if ($end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end) 0 0 0
415 0 push @result, $chunk;
416 0 $chunk = "";
417 }
418 }
419 0 @result;
420 }
421  
422 1 ▶MY->run(\@ARGV) unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 1 1
423 1 1;
« blib/lib/YATT/Lite/LanguageServer/Spec2Types.pm ↑ Summary blib/lib/YATT/Lite/Test/TestFCGI.pm »