| 1 | package TAP::Spec::Parser; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | $TAP::Spec::Parser::AUTHORITY = 'cpan:ARODLAND'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | { | ||||||||||||||||||||||||||||
| 6 | 2 | $TAP::Spec::Parser::VERSION = '0.10'; | |||||||||||||||||||||||||||
| 7 | } | ||||||||||||||||||||||||||||
| 8 | # ABSTRACT: Reference implementation of the TAP specification | ||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Method::Signatures::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Marpa::R2 2.025_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use TAP::Spec::TestSet (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | has 'exhaustive_strings' => ( | |||||||||||||||||||||||||||
| 16 | isa => 'Int', | ||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||
| 18 | default => 0, | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | has 'reader' => ( | |||||||||||||||||||||||||||
| 22 | isa => 'CodeRef', | ||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # API adapters to MGC | ||||||||||||||||||||||||||||
| 29 | 2 | ▶ | method new_from_string ($class: $string, %args) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
new_from_string: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 30 | 5 | ▶ | open my $fh, '<', \$string or die $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 20 | ▶ | my $reader = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 20 | scalar <$fh>; | |||||||||||||||||||||||||||
| 33 | 5 | }; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 5 | $class->new(%args, reader => $reader); | |||||||||||||||||||||||||||
| 36 | 2 | } | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | method parse_from_string ($class: $string, %args) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
parse_from_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 5 | $class->new_from_string($string, %args)->parse; | |||||||||||||||||||||||||||
| 40 | 2 | } | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | method new_from_handle ($class: $handle, %args) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=5.7
Subroutine
new_from_handle: not called CC=1 SCAR=5.7
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $reader = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 45 | 0 | scalar <$handle>; | |||||||||||||||||||||||||||
| 46 | 0 | }; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | $class->new(%args, reader => $reader); | |||||||||||||||||||||||||||
| 49 | 2 | } | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | method parse_from_handle ($class: $handle, %args) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.5
Subroutine
parse_from_handle: not called CC=1 SCAR=4.1
| |||||||||||||||||||||||||||||
| 52 | 0 | $class->new_from_handle($handle, %args)->parse; | |||||||||||||||||||||||||||
| 53 | 2 | } | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | method new_from_file ($class: $file, %args) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.5
Subroutine
new_from_file: not called CC=2 SCAR=15.9
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | open my $fh, '<', $file or die $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $reader = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 59 | 0 | scalar <$fh>; | |||||||||||||||||||||||||||
| 60 | 0 | }; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | $class->new(%args, reader => $reader); | |||||||||||||||||||||||||||
| 63 | 2 | } | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | method parse_from_file ($class: $file, %args) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.5
Subroutine
parse_from_file: not called CC=1 SCAR=4.1
| |||||||||||||||||||||||||||||
| 66 | 0 | $class->new_from_file($file, %args)->parse; | |||||||||||||||||||||||||||
| 67 | 2 | } | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | my $stream_grammar = Marpa::R2::Grammar->new({ | |||||||||||||||||||||||||||
| 70 | actions => 'TAP::Spec::Parser::Actions', | ||||||||||||||||||||||||||||
| 71 | start => 'Testset', | ||||||||||||||||||||||||||||
| 72 | rules => q{ | ||||||||||||||||||||||||||||
| 73 | # Testset = Header (Plan Body / Body Plan) Footer | ||||||||||||||||||||||||||||
| 74 | Testset ::= Header Plan_And_Body Footer EOF action => Testset | ||||||||||||||||||||||||||||
| 75 | Plan_And_Body ::= | ||||||||||||||||||||||||||||
| 76 | Plan Body action => Plan_Body | ||||||||||||||||||||||||||||
| 77 | | Body Plan action => Body_Plan | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Header = [Comments] [Version] | ||||||||||||||||||||||||||||
| 80 | Header ::= Maybe_Comments Maybe_Version action => Header | ||||||||||||||||||||||||||||
| 81 | Maybe_Comments ::= Comments action => subrule1 | ||||||||||||||||||||||||||||
| 82 | Maybe_Comments ::= action => undef | ||||||||||||||||||||||||||||
| 83 | Maybe_Version ::= Version action => subrule1 | ||||||||||||||||||||||||||||
| 84 | Maybe_Version ::= action => undef | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # Footer = [Comments] | ||||||||||||||||||||||||||||
| 87 | Footer ::= Maybe_Comments action => Footer | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # Body = *(Comment / TAP-Line) | ||||||||||||||||||||||||||||
| 90 | Body ::= Body_Line* action => Body | ||||||||||||||||||||||||||||
| 91 | Body_Line ::= | ||||||||||||||||||||||||||||
| 92 | Comment action => subrule1 | ||||||||||||||||||||||||||||
| 93 | | TAP_Line action => subrule1 | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # Comments = 1*Comment | ||||||||||||||||||||||||||||
| 96 | Comments ::= Comment+ action => Comments | ||||||||||||||||||||||||||||
| 97 | }, | ||||||||||||||||||||||||||||
| 98 | }); | ||||||||||||||||||||||||||||
| 99 | 2 | $stream_grammar->precompute; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 2 | ▶ | method stream_grammar { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | 5 | $stream_grammar | |||||||||||||||||||||||||||
| 103 | 2 | } | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | my $line_grammar = Marpa::R2::Grammar->new({ | |||||||||||||||||||||||||||
| 106 | actions => 'TAP::Spec::Parser::Actions', | ||||||||||||||||||||||||||||
| 107 | start => 'Valid_Line', | ||||||||||||||||||||||||||||
| 108 | rules => q{ | ||||||||||||||||||||||||||||
| 109 | # "Any output line that is not a version, a plan, a test line, a diagnostic | ||||||||||||||||||||||||||||
| 110 | # or a bail out is considered an 'unknown' line." | ||||||||||||||||||||||||||||
| 111 | # Valid_Line is a meta-rule that matches any valid line of TAP (a rule that | ||||||||||||||||||||||||||||
| 112 | # starts at the beginning of a line and matches EOL at the end). Any line of | ||||||||||||||||||||||||||||
| 113 | # input that doesn't match "Valid_Line" is discarded as a "junk line", so | ||||||||||||||||||||||||||||
| 114 | # keep this up to date. | ||||||||||||||||||||||||||||
| 115 | Valid_Line ::= | ||||||||||||||||||||||||||||
| 116 | TAP_Line action => tokenize_TAP_Line | ||||||||||||||||||||||||||||
| 117 | | Version action => tokenize_Version | ||||||||||||||||||||||||||||
| 118 | | Plan action => tokenize_Plan | ||||||||||||||||||||||||||||
| 119 | | Comment action => tokenize_Comment | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # Tap-Line = Test-Result / Bail-Out | ||||||||||||||||||||||||||||
| 122 | TAP_Line ::= | ||||||||||||||||||||||||||||
| 123 | Test_Result action => subrule1 | ||||||||||||||||||||||||||||
| 124 | | Bail_Out action => subrule1 | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # Version = "TAP version" SP Version-Number EOL ; ie. "TAP version 13" | ||||||||||||||||||||||||||||
| 127 | Version ::= TAP_version SP Version_Number EOL action => Version | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # Version-Number = Positive-Integer | ||||||||||||||||||||||||||||
| 130 | Version_Number ::= Positive_Integer action => subrule1 | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # Plan = ( Plan-Simple / Plan-Todo / Plan-Skip-All ) EOL | ||||||||||||||||||||||||||||
| 133 | Plan ::= | ||||||||||||||||||||||||||||
| 134 | Plan_Simple EOL action => subrule1 | ||||||||||||||||||||||||||||
| 135 | | Plan_Todo EOL action => subrule1 | ||||||||||||||||||||||||||||
| 136 | | Plan_Skip_All EOL action => subrule1 | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # Plan-Simple = "1.." Number-Of-Tests | ||||||||||||||||||||||||||||
| 139 | Plan_Simple ::= Plan_Simple_Body action => Plan_Simple | ||||||||||||||||||||||||||||
| 140 | Plan_Simple_Body ::= ONE_DOT_DOT Number_Of_Tests action => subrule2 # Capture no. of tests | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | # Plan-Todo = Plan-Simple "todo" 1*(SP Test-Number) ";" ; obsolete | ||||||||||||||||||||||||||||
| 143 | Plan_Todo ::= Plan_Simple_Body SP todo SP Test_Numbers SEMI action => Plan_Todo | ||||||||||||||||||||||||||||
| 144 | Test_Numbers ::= Test_Number+ separator => SP proper => 1 action => Test_Numbers | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # Plan-Skip-All = "1..0" SP "skip" SP Reason | ||||||||||||||||||||||||||||
| 147 | Plan_Skip_All ::= ONE_DOT_DOT_0 SP skip SP Reason action => Plan_Skip_All | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # Reason = String | ||||||||||||||||||||||||||||
| 150 | Reason ::= String action => subrule1 | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # Test-Number = Positive-Integer | ||||||||||||||||||||||||||||
| 153 | Test_Number ::= Positive_Integer action => subrule1 | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # Test-Result = Status [SP Test-Number] [SP Description] | ||||||||||||||||||||||||||||
| 156 | # [SP "#" SP Directive [SP Reason]] EOL | ||||||||||||||||||||||||||||
| 157 | Test_Result ::= Status Maybe_Test_Number Maybe_Description Maybe_Directive_Reason EOL action => Test_Result | ||||||||||||||||||||||||||||
| 158 | Maybe_Test_Number ::= SP Test_Number action => subrule2 | ||||||||||||||||||||||||||||
| 159 | Maybe_Test_Number ::= action => undef | ||||||||||||||||||||||||||||
| 160 | Maybe_Description ::= SP Description action => subrule2 | ||||||||||||||||||||||||||||
| 161 | Maybe_Description ::= action => undef | ||||||||||||||||||||||||||||
| 162 | Maybe_Directive_Reason ::= SP HASH SP Directive Maybe_Reason action => Maybe_Directive_Reason | ||||||||||||||||||||||||||||
| 163 | Maybe_Directive_Reason ::= action => undef | ||||||||||||||||||||||||||||
| 164 | Maybe_Reason ::= SP Reason action => subrule2 | ||||||||||||||||||||||||||||
| 165 | Maybe_Reason ::= action => undef | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | # Status = "ok" / "not ok" | ||||||||||||||||||||||||||||
| 168 | Status ::= | ||||||||||||||||||||||||||||
| 169 | ok action => subrule1 | ||||||||||||||||||||||||||||
| 170 | | not_ok action => subrule1 | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # Description = Safe-String | ||||||||||||||||||||||||||||
| 173 | Description ::= Safe_String action => subrule1 | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # Directive = "SKIP" / "TODO" | ||||||||||||||||||||||||||||
| 176 | Directive ::= | ||||||||||||||||||||||||||||
| 177 | SKIP action => subrule1 | ||||||||||||||||||||||||||||
| 178 | | TODO action => subrule1 | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # Bail-Out = "Bail out!" [SP Reason] EOL | ||||||||||||||||||||||||||||
| 181 | Bail_Out ::= Bail_out Maybe_Reason EOL action => Bail_Out | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | # Comment = "#" String EOL | ||||||||||||||||||||||||||||
| 184 | Comment ::= HASH String EOL action => Comment | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | # String = 1*(Safe-String / "#") | ||||||||||||||||||||||||||||
| 187 | String ::= String_Part+ action => String | ||||||||||||||||||||||||||||
| 188 | String_Part ::= | ||||||||||||||||||||||||||||
| 189 | Safe_String action => subrule1 | ||||||||||||||||||||||||||||
| 190 | | HASH action => subrule1 | ||||||||||||||||||||||||||||
| 191 | }, | ||||||||||||||||||||||||||||
| 192 | }); | ||||||||||||||||||||||||||||
| 193 | 2 | $line_grammar->precompute; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 2 | ▶ | method line_grammar { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 196 | 16 | $line_grammar | |||||||||||||||||||||||||||
| 197 | 2 | } | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | my %tokens = ( | ||||||||||||||||||||||||||||
| 200 | 'ONE_DOT_DOT' => [ qr/\G1\.\./ ], | ||||||||||||||||||||||||||||
| 201 | 'ONE_DOT_DOT_0' => [ qr/\G1\.\.0/ ], | ||||||||||||||||||||||||||||
| 202 | 'TODO' => [ qr/\GTODO/i, 'TODO' ], | ||||||||||||||||||||||||||||
| 203 | 'SKIP' => [ qr/\GSKIP/i, 'SKIP' ], | ||||||||||||||||||||||||||||
| 204 | 'ok' => [ qr/\Gok/i, 'ok' ], | ||||||||||||||||||||||||||||
| 205 | 'not_ok' => [ qr/\Gnot ok/i, 'not ok' ], | ||||||||||||||||||||||||||||
| 206 | 'TAP_version' => [ qr/\GTAP version/i ], | ||||||||||||||||||||||||||||
| 207 | 'Bail_out' => [ qr/\GBail out!/i ], | ||||||||||||||||||||||||||||
| 208 | 'HASH' => [ qr/\G#/, '#' ], | ||||||||||||||||||||||||||||
| 209 | 'SEMI' => [ qr/\G;/, ';' ], | ||||||||||||||||||||||||||||
| 210 | 'SP' => [ qr/\G /, ' ' ], | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | # EOL = LF / CRLF | ||||||||||||||||||||||||||||
| 213 | 'EOL' => [ qr/\G(?:\n|\r\n)/ ], | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | # Safe-String = 1*(%x01-09 %x0B-0C %x0E-22 %x24-FF) ; UTF8 without EOL or "#" | ||||||||||||||||||||||||||||
| 216 | 'Safe_String' => [ qr/\G([\x01-\x09\x0b-\x0c\x0e-\x22\x24-\xff]+)/ ], | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | # Positive-Integer = ("1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9") *DIGIT | ||||||||||||||||||||||||||||
| 219 | 9 | ▶ | 'Positive_Integer' => [ qr/\G([1-9][0-9]*)/, sub { 0 + $1 } ], | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | # Number-Of-Tests = 1*DIGIT | ||||||||||||||||||||||||||||
| 222 | 6 | ▶ | 'Number_Of_Tests' => [ qr/\G(\d+)/, sub { 0 + $1 } ], | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 223 | ); | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 2 | ▶ | method lex ($input, $pos, $expected) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
lex: called CC=11 SCAR=24.7
| |||||||||||||||||||||||||||||
| 226 | 55 | my @matches; | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 55 | TOKEN: for my $token_name (@$expected) { | |||||||||||||||||||||||||||
| 229 | 189 | my $token = $tokens{$token_name}; | |||||||||||||||||||||||||||
| 230 | 189 | ▶ | die "Unknown token $token_name" unless defined $token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 189 | my $rule = $token->[0]; | |||||||||||||||||||||||||||
| 232 | 189 | pos($$input) = $pos; | |||||||||||||||||||||||||||
| 233 | 189 | ▶ | next TOKEN unless $$input =~ $rule; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 62 | my $matched_len = $+[0] - $-[0]; | |||||||||||||||||||||||||||
| 236 | 62 | my $matched_value = undef; | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 62 | ▶ | if (defined( my $val = $token->[1] )) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 239 | 32 | ▶ | if (ref $val eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 15 | $matched_value = $val->(); | |||||||||||||||||||||||||||
| 241 | } else { | ||||||||||||||||||||||||||||
| 242 | 17 | $matched_value = $val; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | } elsif ($#- > 0) { # Captured a value | ||||||||||||||||||||||||||||
| 245 | 8 | $matched_value = $1; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 62 | push @matches, [ $token_name, \$matched_value, $matched_len ]; | |||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 62 | ▶ | if ($token_name eq 'Safe_String') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 8 | ▶ | if ($self->exhaustive_strings) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 252 | 0 | for my $len (reverse 1 .. $matched_len - 1) { | |||||||||||||||||||||||||||
| 253 | 0 | my $value = substr($matched_value, 0, $len); | |||||||||||||||||||||||||||
| 254 | 0 | push @matches, [ $token_name, \$value, $len ]; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | } elsif ($matched_value =~ /(.*) $/) { | ||||||||||||||||||||||||||||
| 257 | 0 | my $value = $1; | |||||||||||||||||||||||||||
| 258 | 0 | push @matches, [ $token_name, \$value, $matched_len - 1 ]; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 55 | return @matches; | |||||||||||||||||||||||||||
| 264 | 2 | } | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 2 | ▶ | method parse_line ($line) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 267 | 16 | my $rec = Marpa::R2::Recognizer->new({ | |||||||||||||||||||||||||||
| 268 | grammar => $self->line_grammar, | ||||||||||||||||||||||||||||
| 269 | ranking_method => 'rule', | ||||||||||||||||||||||||||||
| 270 | # trace_terminals => 2, | ||||||||||||||||||||||||||||
| 271 | # trace_values => 1, | ||||||||||||||||||||||||||||
| 272 | # trace_actions => 1, | ||||||||||||||||||||||||||||
| 273 | }); | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 16 | for my $pos (0 .. length($line) - 1) { | |||||||||||||||||||||||||||
| 276 | 90 | my $expected_tokens = $rec->terminals_expected; | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 90 | ▶ | if (@$expected_tokens) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 55 | my @matching_tokens = $self->lex(\$line, $pos, $expected_tokens); | |||||||||||||||||||||||||||
| 280 | 55 | $rec->alternative( @$_ ) for @matching_tokens; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 90 | my $ok = eval { | |||||||||||||||||||||||||||
| 284 | 90 | $rec->earleme_complete; | |||||||||||||||||||||||||||
| 285 | 89 | 1; | |||||||||||||||||||||||||||
| 286 | }; | ||||||||||||||||||||||||||||
| 287 | 90 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 1 | return [ 'Junk_Line', $line ]; | |||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 15 | $rec->end_input; | |||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 15 | return ${$rec->value}; | |||||||||||||||||||||||||||
| 295 | 2 | } | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 2 | ▶ | method parse { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 298 | 5 | my $rec = Marpa::R2::Recognizer->new({ | |||||||||||||||||||||||||||
| 299 | grammar => $self->stream_grammar, | ||||||||||||||||||||||||||||
| 300 | ranking_method => 'rule', | ||||||||||||||||||||||||||||
| 301 | # trace_terminals => 2, | ||||||||||||||||||||||||||||
| 302 | # trace_values => 1, | ||||||||||||||||||||||||||||
| 303 | # trace_actions => 1, | ||||||||||||||||||||||||||||
| 304 | }); | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 5 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 5 | ▶ | while (defined( my $line = $reader->() )) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | # print "Expecting: ", join(" ", @{ $rec->terminals_expected }), "\n"; | ||||||||||||||||||||||||||||
| 310 | 16 | my $line_token = $self->parse_line($line); | |||||||||||||||||||||||||||
| 311 | 16 | ▶ | next if $line_token->[0] eq 'Junk_Line'; # XXX do something cooler | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 15 | ▶ | unless (defined $rec->read(@$line_token)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 1 | my $expected = $rec->terminals_expected; | |||||||||||||||||||||||||||
| 314 | 1 | die "Parse error, expecting [@$expected], got $line_token->[0]"; | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 4 | $rec->read('EOF'); | |||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 4 | return ${$rec->value}; | |||||||||||||||||||||||||||
| 321 | 2 | } | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 2 | ▶ | no Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | package TAP::Spec::Parser::Actions; | ||||||||||||||||||||||||||||
| 326 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 327 | 2 | $TAP::Spec::Parser::Actions::AUTHORITY = 'cpan:ARODLAND'; | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | { | ||||||||||||||||||||||||||||
| 330 | 2 | $TAP::Spec::Parser::Actions::VERSION = '0.10'; | |||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 38 | ▶ | sub subrule1 { | ||||||||||||||||||||||||||
|
Subroutine
subrule1: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 334 | 38 | $_[1]; | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 14 | ▶ | sub subrule2 { | ||||||||||||||||||||||||||
|
Subroutine
subrule2: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 338 | 14 | $_[2]; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 8 | ▶ | sub tokenize_TAP_Line { | ||||||||||||||||||||||||||
|
Subroutine
tokenize_TAP_Line: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 342 | 8 | [ 'TAP_Line', $_[1] ]; | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 1 | ▶ | sub tokenize_Version { | ||||||||||||||||||||||||||
|
Subroutine
tokenize_Version: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 346 | 1 | [ 'Version', $_[1] ]; | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 6 | ▶ | sub tokenize_Plan { | ||||||||||||||||||||||||||
|
Subroutine
tokenize_Plan: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 350 | 6 | [ 'Plan', $_[1] ]; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | ▶ | sub tokenize_Comment { | ||||||||||||||||||||||||||
|
Subroutine
tokenize_Comment: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 354 | 0 | [ 'Comment', $_[1] ]; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 4 | ▶ | sub Testset { | ||||||||||||||||||||||||||
|
Subroutine
Testset: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 358 | 4 | my %tmp; | |||||||||||||||||||||||||||
| 359 | 4 | ▶ | $tmp{header} = $_[1] || TAP::Spec::Header->new; | ||||||||||||||||||||||||||
|
Condition33%1/3
$_[1] || 'TAP::Spec::Header'->new
MC/DC0%0/2
$_[1] || 'TAP::Spec::Header'->new
$_[1]
'TAP::Spec::Header'->new
Truth table33%1/3
A || B
A= $_[1]B= 'TAP::Spec::Header'->new
| |||||||||||||||||||||||||||||
| 360 | 4 | $tmp{plan} = $_[2][0]; | |||||||||||||||||||||||||||
| 361 | 4 | $tmp{body} = $_[2][1]; | |||||||||||||||||||||||||||
| 362 | 4 | ▶ | $tmp{footer} = $_[3] || TAP::Spec::Footer->new; | ||||||||||||||||||||||||||
|
Condition33%1/3
$_[3] || 'TAP::Spec::Footer'->new
MC/DC0%0/2
$_[3] || 'TAP::Spec::Footer'->new
$_[3]
'TAP::Spec::Footer'->new
Truth table33%1/3
A || B
A= $_[3]B= 'TAP::Spec::Footer'->new
| |||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 4 | TAP::Spec::TestSet->new(%tmp); | |||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 4 | ▶ | sub Plan_Body { | ||||||||||||||||||||||||||
|
Subroutine
Plan_Body: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 368 | 4 | my $plan = $_[1]; | |||||||||||||||||||||||||||
| 369 | 4 | my $body = $_[2]; | |||||||||||||||||||||||||||
| 370 | 4 | [ $plan, $body ]; | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | sub Body_Plan { | ||||||||||||||||||||||||||
|
Subroutine
Body_Plan: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 374 | 0 | my $body = $_[1]; | |||||||||||||||||||||||||||
| 375 | 0 | my $plan = $_[2]; | |||||||||||||||||||||||||||
| 376 | 0 | [ $plan, $body ]; | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 4 | ▶ | sub Header { | ||||||||||||||||||||||||||
|
Subroutine
Header: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 380 | 4 | my %tmp; | |||||||||||||||||||||||||||
| 381 | 4 | ▶ | $tmp{comments} = $_[1] if defined $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | 4 | ▶ | $tmp{version} = $_[2] if defined $_[2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | 4 | TAP::Spec::Header->new(%tmp); | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | # Footer = [Comments] | ||||||||||||||||||||||||||||
| 387 | 4 | ▶ | sub Footer { | ||||||||||||||||||||||||||
|
Subroutine
Footer: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 388 | 4 | my %tmp; | |||||||||||||||||||||||||||
| 389 | 4 | ▶ | $tmp{comments} = $_[1] if defined $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | 4 | TAP::Spec::Footer->new(%tmp); | |||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | # Body = *(Comment / TAP-Line) | ||||||||||||||||||||||||||||
| 394 | 4 | ▶ | sub Body { | ||||||||||||||||||||||||||
|
Subroutine
Body: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 395 | 4 | shift; | |||||||||||||||||||||||||||
| 396 | 4 | my @lines = @_; | |||||||||||||||||||||||||||
| 397 | 4 | TAP::Spec::Body->new(lines => \@lines); | |||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 0 | ▶ | sub Comments { | ||||||||||||||||||||||||||
|
Subroutine
Comments: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 401 | 0 | shift; | |||||||||||||||||||||||||||
| 402 | 0 | my @comments = @_; | |||||||||||||||||||||||||||
| 403 | 0 | return \@comments; | |||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 1 | ▶ | sub Version { | ||||||||||||||||||||||||||
|
Subroutine
Version: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 407 | 1 | my $version_number = $_[3]; | |||||||||||||||||||||||||||
| 408 | 1 | TAP::Spec::Version->new(version_number => $version_number); | |||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 6 | ▶ | sub Plan_Simple { | ||||||||||||||||||||||||||
|
Subroutine
Plan_Simple: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 412 | 6 | my $number_of_tests = $_[1]; | |||||||||||||||||||||||||||
| 413 | 6 | TAP::Spec::Plan::Simple->new(number_of_tests => $number_of_tests); | |||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 0 | ▶ | sub Plan_Todo { | ||||||||||||||||||||||||||
|
Subroutine
Plan_Todo: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 417 | 0 | my $number_of_tests = $_[1]; | |||||||||||||||||||||||||||
| 418 | 0 | my $skipped_tests = $_[5]; | |||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 0 | TAP::Spec::Plan::Todo->new( | |||||||||||||||||||||||||||
| 421 | number_of_tests => $number_of_tests, | ||||||||||||||||||||||||||||
| 422 | skipped_tests => $skipped_tests, | ||||||||||||||||||||||||||||
| 423 | ); | ||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 0 | ▶ | sub Test_Numbers { | ||||||||||||||||||||||||||
|
Subroutine
Test_Numbers: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 427 | 0 | shift; | |||||||||||||||||||||||||||
| 428 | 0 | my @test_numbers = @_; | |||||||||||||||||||||||||||
| 429 | 0 | \@test_numbers; | |||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 0 | ▶ | sub Plan_Skip_All { | ||||||||||||||||||||||||||
|
Subroutine
Plan_Skip_All: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 433 | 0 | my $reason = $_[5]; | |||||||||||||||||||||||||||
| 434 | 0 | TAP::Spec::Plan::SkipAll->new( | |||||||||||||||||||||||||||
| 435 | reason => $reason, | ||||||||||||||||||||||||||||
| 436 | ); | ||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 8 | ▶ | sub Test_Result { | ||||||||||||||||||||||||||
|
Subroutine
Test_Result: called CC=7 SCAR=22.7
| |||||||||||||||||||||||||||||
| 440 | 8 | my %tmp; | |||||||||||||||||||||||||||
| 441 | 8 | $tmp{status} = $_[1]; | |||||||||||||||||||||||||||
| 442 | 8 | ▶ | $tmp{number} = $_[2] if defined $_[2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 443 | 8 | ▶ | $tmp{description} = $_[3] if defined $_[3]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | 8 | ▶ | $tmp{directive} = $_[4][0] if defined $_[4] && defined $_[4][0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[4] and defined $_[4][0]
MC/DC0%0/2
defined $_[4] and defined $_[4][0]
defined $_[4]
defined $_[4][0]
Truth table33%1/3
A and B
A= defined $_[4]B= defined $_[4][0]
| |||||||||||||||||||||||||||||
| 445 | 8 | ▶ | $tmp{reason} = $_[4][1] if defined $_[4] && defined $_[4][1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[4] and defined $_[4][1]
MC/DC0%0/2
defined $_[4] and defined $_[4][1]
defined $_[4]
defined $_[4][1]
Truth table33%1/3
A and B
A= defined $_[4]B= defined $_[4][1]
| |||||||||||||||||||||||||||||
| 446 | 8 | TAP::Spec::TestResult->new(%tmp); | |||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | 0 | ▶ | sub Maybe_Directive_Reason { | ||||||||||||||||||||||||||
|
Subroutine
Maybe_Directive_Reason: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 450 | 0 | my $directive = $_[4]; | |||||||||||||||||||||||||||
| 451 | 0 | my $reason = $_[5]; | |||||||||||||||||||||||||||
| 452 | 0 | return [ $directive, $reason ]; | |||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | 0 | ▶ | sub Bail_Out { | ||||||||||||||||||||||||||
|
Subroutine
Bail_Out: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 456 | 0 | my %tmp; | |||||||||||||||||||||||||||
| 457 | 0 | ▶ | $tmp{reason} = $_[1] if defined $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 458 | 0 | TAP::Spec::BailOut->new( %tmp ); | |||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 0 | ▶ | sub Comment { | ||||||||||||||||||||||||||
|
Subroutine
Comment: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 462 | 0 | my $text = $_[1]; | |||||||||||||||||||||||||||
| 463 | 0 | TAP::Spec::Comment->new( text => $text ); | |||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 0 | ▶ | sub String { | ||||||||||||||||||||||||||
|
Subroutine
String: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 467 | 0 | shift; | |||||||||||||||||||||||||||
| 468 | 0 | my @parts = @_; | |||||||||||||||||||||||||||
| 469 | 0 | return join "", @parts; | |||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 17 | ▶ | sub undef { | ||||||||||||||||||||||||||
|
Subroutine
undef: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 473 | undef | ||||||||||||||||||||||||||||
| 474 | 17 | } | |||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 2 | 1; | |||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | __END__ | ||||||||||||||||||||||||||||