| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $decl->{body} = \ my @body; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | while (@$bodyTokList) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | push @body, $sub->($self, $decl, $bodyTokList); | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (@$bodyTokList) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ($comment =~ s/\@deprecated(?:\s+(?<by>\S[^\n]*))?//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->eat_token(';', $bodyTokList); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return defined $ast->{comment} ? $ast : $ast->{body}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$tok =~ s/^(?:(?<ro>readonly)\s+)?
(?<slotName>(?:\w+ |\[[^]]+\]) \??)//x and $self->eat_token(":", $bodyTokList)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | push @$slotDef, $self->parse_typeunion($decl, $bodyTokList); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | return defined $ast->{comment} ? $ast : $ast->{body}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
@$bodyTokList and $bodyTokList->[0] ne "}"
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 "}"
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $tok = shift @$bodyTokList; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ($tok eq '{') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
@$bodyTokList >= 4 and $bodyTokList->[0] =~ /^\w+\z/ and $bodyTokList->[1] eq ":"
@$bodyTokList >= 4 and $bodyTokList->[0] =~ /^\w+\z/
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 ":"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
@$bodyTokList and $bodyTokList->[0] ne ";"
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 ";"
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ($bodyTokList->[0] eq '{') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if (not $self->eat_token('|', $bodyTokList)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | shift @$bodyTokList; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | return defined $bracket ? [$ident, $bracket] : $ident; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $e = $self->parse_typeconj($decl, $bodyTokList); | |||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | if ($self->eat_token('&', $bodyTokList)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $e = ['&', $e]; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | if ($self->eat_token(extends => $declTok)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
@$tokList and $tokList->[0] eq $tokString
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
@$tokList and my(@match) = $tokList->[0] =~ /$pattern/
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/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | unless ($commentString =~ s,^\s*/\*\*\n,,s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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"}
MC/DC0%0/2
$+{"body"} // $+{"type"}
$+{"body"}
$+{"type"}
Truth table0%0/3
A // B
A= $+{"body"}B= $+{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | my $line = s{^```$langId\b}{} .. s{^```}{} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$line >= 2 and not $end
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
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | if ($end) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||