| 1 | # Marpa::R3 is Copyright (C) 2018, Jeffrey Kegler. | ||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||
| 3 | # This module is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||
| 4 | # under the same terms as Perl 5.10.1. For more details, see the full text | ||||||||||||||||||||||||||||||||||
| 5 | # of the licenses in the directory LICENSES. | ||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||
| 7 | # This program is distributed in the hope that it will be | ||||||||||||||||||||||||||||||||||
| 8 | # useful, but it is provided "as is" and without any express | ||||||||||||||||||||||||||||||||||
| 9 | # or implied warranties. For details, see the full text of | ||||||||||||||||||||||||||||||||||
| 10 | # of the licenses in the directory LICENSES. | ||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | package Marpa::R3::Valuer; | ||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 104 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 104 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 104 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 104 | ▶ | use vars qw($VERSION $STRING_VERSION); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | 104 | $VERSION = '4.001_054'; | |||||||||||||||||||||||||||||||||
| 20 | 104 | $STRING_VERSION = $VERSION; | |||||||||||||||||||||||||||||||||
| 21 | ## no critic(BuiltinFunctions::ProhibitStringyEval) | ||||||||||||||||||||||||||||||||||
| 22 | 104 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||
| 23 | ## use critic | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | package Marpa::R3::Internal_V; | ||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 104 | ▶ | use Scalar::Util qw(blessed tainted); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 28 | 104 | ▶ | use English qw( -no_match_vars ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | 104 | our $PACKAGE = 'Marpa::R3::Valuer'; | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | # Set those common args which are at the Perl level. | ||||||||||||||||||||||||||||||||||
| 33 | 1144 | ▶ | sub slv_common_set { | ||||||||||||||||||||||||||||||||
|
Subroutine
slv_common_set: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 34 | 1144 | my ( $slv, $flat_args ) = @_; | |||||||||||||||||||||||||||||||||
| 35 | 1144 | ▶ | if ( my $value = $flat_args->{'trace_file_handle'} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 36 | 2 | $slv->[Marpa::R3::Internal_V::TRACE_FILE_HANDLE] = $value; | |||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||
| 38 | 1144 | my $trace_file_handle = | |||||||||||||||||||||||||||||||||
| 39 | $slv->[Marpa::R3::Internal_V::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||
| 40 | 1144 | delete $flat_args->{'trace_file_handle'}; | |||||||||||||||||||||||||||||||||
| 41 | 1144 | return $flat_args; | |||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | 104 | our $CONTEXT_EXCEPTION_CLASS = __PACKAGE__ . '::Context_Exception'; | |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 4 | ▶ | sub Marpa::R3::Context::bail { ## no critic (Subroutines::RequireArgUnpacking) | ||||||||||||||||||||||||||||||||
|
Subroutine
bail: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 47 | 4 | ▶ | if ( scalar @_ == 1 and ref $_[0] ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @_ == 1 and ref $_[0]
MC/DC50%1/2
scalar @_ == 1 and ref $_[0]
scalar @_ == 1
ref $_[0]
Truth table66%2/3
A and B
A= scalar @_ == 1B= ref $_[0]
| |||||||||||||||||||||||||||||||||||
| 48 | 2 | die bless { exception_object => $_[0] }, $CONTEXT_EXCEPTION_CLASS; | |||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||
| 50 | 2 | my $error_string = join q{}, @_; | |||||||||||||||||||||||||||||||||
| 51 | 2 | my ( $package, $filename, $line ) = caller; | |||||||||||||||||||||||||||||||||
| 52 | 2 | chomp $error_string; | |||||||||||||||||||||||||||||||||
| 53 | 2 | die bless { message => qq{User bailed at line $line in file "$filename"\n} | |||||||||||||||||||||||||||||||||
| 54 | . $error_string | ||||||||||||||||||||||||||||||||||
| 55 | . "\n" }, $CONTEXT_EXCEPTION_CLASS; | ||||||||||||||||||||||||||||||||||
| 56 | } ## end sub Marpa::R3::Context::bail | ||||||||||||||||||||||||||||||||||
| 57 | ## use critic | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | sub Marpa::R3::Context::g1_range { | ||||||||||||||||||||||||||||||||
|
Subroutine
g1_range: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 60 | 2 | my $slv = $Marpa::R3::Context::valuer; | |||||||||||||||||||||||||||||||||
| 61 | 2 | my ( $start, $end ) = | |||||||||||||||||||||||||||||||||
| 62 | $slv->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), <<'END_OF_LUA', '>*' ); | ||||||||||||||||||||||||||||||||||
| 63 | local slv = ... | ||||||||||||||||||||||||||||||||||
| 64 | return slv:g1_range() | ||||||||||||||||||||||||||||||||||
| 65 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 66 | 2 | return $start, $end; | |||||||||||||||||||||||||||||||||
| 67 | } ## end sub Marpa::R3::Context::g1_range | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 8 | ▶ | sub Marpa::R3::Context::lc_range { | ||||||||||||||||||||||||||||||||
|
Subroutine
lc_range: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 70 | 8 | my $slv = $Marpa::R3::Context::valuer; | |||||||||||||||||||||||||||||||||
| 71 | 8 | my ( $lc_range ) = | |||||||||||||||||||||||||||||||||
| 72 | $slv->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), <<'END_OF_LUA', '>*' ); | ||||||||||||||||||||||||||||||||||
| 73 | local slv = ... | ||||||||||||||||||||||||||||||||||
| 74 | local slr = slv.slr | ||||||||||||||||||||||||||||||||||
| 75 | local g1_first, g1_last = slv:g1_range() | ||||||||||||||||||||||||||||||||||
| 76 | local l0_first_b, l0_first_p = slr:g1_to_block_first(g1_first) | ||||||||||||||||||||||||||||||||||
| 77 | local l0_last_b, l0_last_p = slr:g1_to_block_last(g1_last) | ||||||||||||||||||||||||||||||||||
| 78 | return slr:lc_range_brief(l0_first_b, l0_first_p, l0_last_b, l0_last_p) | ||||||||||||||||||||||||||||||||||
| 79 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 80 | 8 | return $lc_range; | |||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub Marpa::R3::Context::g1_span { | ||||||||||||||||||||||||||||||||
|
Subroutine
g1_span: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 84 | 0 | my $slv = $Marpa::R3::Context::valuer; | |||||||||||||||||||||||||||||||||
| 85 | 0 | my ( $start, $length ) = | |||||||||||||||||||||||||||||||||
| 86 | $slv->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), <<'END_OF_LUA', '>*' ); | ||||||||||||||||||||||||||||||||||
| 87 | local slv = ... | ||||||||||||||||||||||||||||||||||
| 88 | local g1_first, g1_last = slv:g1_range() | ||||||||||||||||||||||||||||||||||
| 89 | local length = g1_last - g1_first + 1 | ||||||||||||||||||||||||||||||||||
| 90 | return start, length | ||||||||||||||||||||||||||||||||||
| 91 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 92 | 0 | return $start, $length; | |||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | 10 | ▶ | sub code_problems { | ||||||||||||||||||||||||||||||||
|
Subroutine
code_problems: called CC=22 SCAR=31.7
| |||||||||||||||||||||||||||||||||||
| 96 | 10 | my $args = shift; | |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | 10 | my $grammar; | |||||||||||||||||||||||||||||||||
| 99 | my $fatal_error; | ||||||||||||||||||||||||||||||||||
| 100 | 10 | my $warnings = []; | |||||||||||||||||||||||||||||||||
| 101 | 10 | my $where = '?where?'; | |||||||||||||||||||||||||||||||||
| 102 | 10 | my $long_where; | |||||||||||||||||||||||||||||||||
| 103 | 10 | my @msg = (); | |||||||||||||||||||||||||||||||||
| 104 | 10 | my $eval_value; | |||||||||||||||||||||||||||||||||
| 105 | 10 | my $eval_given = 0; | |||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | 10 | push @msg, q{=} x 60, "\n"; | |||||||||||||||||||||||||||||||||
| 108 | 10 | ARG: for my $arg ( keys %{$args} ) { | |||||||||||||||||||||||||||||||||
| 109 | 50 | my $value = $args->{$arg}; | |||||||||||||||||||||||||||||||||
| 110 | 50 | ▶ | if ( $arg eq 'fatal_error' ) { $fatal_error = $value; next ARG } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ( $arg eq 'grammar' ) { $grammar = $value; next ARG } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 112 | 40 | ▶ | if ( $arg eq 'where' ) { $where = $value; next ARG } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 113 | 30 | ▶ | if ( $arg eq 'long_where' ) { $long_where = $value; next ARG } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 114 | 20 | ▶ | if ( $arg eq 'warnings' ) { $warnings = $value; next ARG } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 115 | 10 | ▶ | if ( $arg eq 'eval_ok' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 116 | 10 | $eval_value = $value; | |||||||||||||||||||||||||||||||||
| 117 | 10 | $eval_given = 1; | |||||||||||||||||||||||||||||||||
| 118 | 10 | next ARG; | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | 0 | push @msg, "Unknown argument to code_problems: $arg"; | |||||||||||||||||||||||||||||||||
| 121 | } ## end ARG: for my $arg ( keys %{$args} ) | ||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | GIVEN_FATAL_ERROR_REF_TYPE: { | ||||||||||||||||||||||||||||||||||
| 124 | 10 | my $fatal_error_ref_type = ref $fatal_error; | |||||||||||||||||||||||||||||||||
| 125 | 10 | ▶ | last GIVEN_FATAL_ERROR_REF_TYPE if not $fatal_error_ref_type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 126 | 4 | ▶ | if ( $fatal_error_ref_type eq $CONTEXT_EXCEPTION_CLASS ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 127 | 4 | my $exception_object = $fatal_error->{exception_object}; | |||||||||||||||||||||||||||||||||
| 128 | 4 | ▶ | die $exception_object if defined $exception_object; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 129 | 2 | my $exception_message = $fatal_error->{message}; | |||||||||||||||||||||||||||||||||
| 130 | 2 | ▶ | die $exception_message if defined $exception_message; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 131 | 0 | die "Internal error: bad $CONTEXT_EXCEPTION_CLASS object"; | |||||||||||||||||||||||||||||||||
| 132 | } ## end if ( $fatal_error_ref_type eq $CONTEXT_EXCEPTION_CLASS) | ||||||||||||||||||||||||||||||||||
| 133 | $fatal_error = | ||||||||||||||||||||||||||||||||||
| 134 | 0 | "Exception thrown as object inside Marpa closure\n" | |||||||||||||||||||||||||||||||||
| 135 | . ( q{ } x 4 ) | ||||||||||||||||||||||||||||||||||
| 136 | . "This is not allowed\n" | ||||||||||||||||||||||||||||||||||
| 137 | . ( q{ } x 4 ) | ||||||||||||||||||||||||||||||||||
| 138 | . qq{Exception as string is "$fatal_error"}; | ||||||||||||||||||||||||||||||||||
| 139 | } ## end GIVEN_FATAL_ERROR_REF_TYPE: | ||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | 6 | my @problem_line = (); | |||||||||||||||||||||||||||||||||
| 142 | 6 | my $max_problem_line = -1; | |||||||||||||||||||||||||||||||||
| 143 | 6 | for my $warning_data ( @{$warnings} ) { | |||||||||||||||||||||||||||||||||
| 144 | 4 | my ( $warning, $package, $filename, $problem_line ) = @{$warning_data}; | |||||||||||||||||||||||||||||||||
| 145 | 4 | $problem_line[$problem_line] = 1; | |||||||||||||||||||||||||||||||||
| 146 | 4 | $max_problem_line = List::Util::max $problem_line, $max_problem_line; | |||||||||||||||||||||||||||||||||
| 147 | } ## end for my $warning_data ( @{$warnings} ) | ||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | 6 | ▶ | $long_where //= $where; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$long_where //= $where
MC/DC0%0/2
$long_where //= $where
$long_where
$where
Truth table33%1/3
A //= B
A= $long_whereB= $where
| |||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | 6 | my $warnings_count = scalar @{$warnings}; | |||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||
| 153 | 6 | my @problems; | |||||||||||||||||||||||||||||||||
| 154 | 6 | ▶ | my $false_eval = $eval_given && !$eval_value && !$fatal_error; | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
$eval_given && !$eval_value && !$fatal_error
$eval_given and not $eval_value
MC/DC0%0/3
$eval_given && !$eval_value && !$fatal_error
$eval_given
not $eval_value
!$fatal_error
Truth table50%2/4
A and not(B) && not(C)
A= $eval_givenB= not $eval_valueC= !$fatal_error
| |||||||||||||||||||||||||||||||||||
| 155 | 6 | ▶ | if ($false_eval) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 156 | 0 | push @problems, '* THE MARPA SEMANTICS RETURNED A PERL FALSE', | |||||||||||||||||||||||||||||||||
| 157 | 'Marpa::R3 requires its semantics to return a true value'; | ||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||
| 159 | 6 | ▶ | if ($fatal_error) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 160 | 4 | push @problems, '* THE MARPA SEMANTICS PRODUCED A FATAL ERROR'; | |||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||
| 162 | 6 | ▶ | if ($warnings_count) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 163 | 2 | push @problems, | |||||||||||||||||||||||||||||||||
| 164 | "* THERE WERE $warnings_count WARNING(S) IN THE MARPA SEMANTICS:", | ||||||||||||||||||||||||||||||||||
| 165 | 'Marpa treats warnings as fatal errors'; | ||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||
| 167 | 6 | ▶ | if ( not scalar @problems ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | 0 | push @msg, '* THERE WAS A FATAL PROBLEM IN THE MARPA SEMANTICS'; | |||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||
| 170 | 6 | push @msg, ( join "\n", @problems ) . "\n"; | |||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | 6 | push @msg, "* THIS IS WHAT MARPA WAS DOING WHEN THE PROBLEM OCCURRED:\n" | |||||||||||||||||||||||||||||||||
| 174 | . $long_where . "\n"; | ||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||
| 176 | 6 | for my $warning_ix ( 0 .. ( $warnings_count - 1 ) ) { | |||||||||||||||||||||||||||||||||
| 177 | 4 | push @msg, "* WARNING MESSAGE NUMBER $warning_ix:\n"; | |||||||||||||||||||||||||||||||||
| 178 | 4 | my $warning_message = $warnings->[$warning_ix]->[0]; | |||||||||||||||||||||||||||||||||
| 179 | 4 | $warning_message =~ s/\n*\z/\n/xms; | |||||||||||||||||||||||||||||||||
| 180 | 4 | push @msg, $warning_message; | |||||||||||||||||||||||||||||||||
| 181 | } ## end for my $warning_ix ( 0 .. ( $warnings_count - 1 ) ) | ||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||
| 183 | 6 | ▶ | if ($fatal_error) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 184 | 4 | push @msg, "* THIS WAS THE FATAL ERROR MESSAGE:\n"; | |||||||||||||||||||||||||||||||||
| 185 | 4 | my $fatal_error_message = $fatal_error; | |||||||||||||||||||||||||||||||||
| 186 | 4 | $fatal_error_message =~ s/\n*\z/\n/xms; | |||||||||||||||||||||||||||||||||
| 187 | 4 | push @msg, $fatal_error_message; | |||||||||||||||||||||||||||||||||
| 188 | } ## end if ($fatal_error) | ||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 6 | Marpa::R3::exception(@msg); | |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | # this is to keep perlcritic happy | ||||||||||||||||||||||||||||||||||
| 193 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||
| 197 | 1141 | ▶ | sub Marpa::R3::Valuer::new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=25.1
| |||||||||||||||||||||||||||||||||||
| 198 | 1141 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | 1141 | my $slv = []; | |||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||
| 202 | # Set recognizer args to default | ||||||||||||||||||||||||||||||||||
| 203 | # Lua equivalent is set below | ||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||
| 205 | 1141 | my ( $flat_args, $error_message ) = Marpa::R3::flatten_hash_args( \@args ); | |||||||||||||||||||||||||||||||||
| 206 | 1141 | ▶ | Marpa::R3::exception( sprintf $error_message, '$slv->new' ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 207 | if not $flat_args; | ||||||||||||||||||||||||||||||||||
| 208 | 1141 | $flat_args = slv_common_set( $slv, $flat_args ); | |||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | 1141 | my $slr = $flat_args->{recognizer}; | |||||||||||||||||||||||||||||||||
| 211 | 1141 | ▶ | Marpa::R3::exception( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 212 | qq{Marpa::R3::Valuer::new() called without a "recognizer" argument} ) | ||||||||||||||||||||||||||||||||||
| 213 | if not defined $slr; | ||||||||||||||||||||||||||||||||||
| 214 | 1141 | $slv->[Marpa::R3::Internal_V::SLR] = $slr; | |||||||||||||||||||||||||||||||||
| 215 | 1141 | delete $flat_args->{recognizer}; | |||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||
| 217 | 1141 | my $slr_class = 'Marpa::R3::Recognizer'; | |||||||||||||||||||||||||||||||||
| 218 | 1141 | ▶ | if ( not blessed $slr or not $slr->isa($slr_class) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($slr) and $slr->isa($slr_class)
MC/DC0%0/2
builtin::blessed($slr) and $slr->isa($slr_class)
builtin::blessed($slr)
$slr->isa($slr_class)
Truth table33%1/3
A and B
A= builtin::blessed($slr)B= $slr->isa($slr_class)
| |||||||||||||||||||||||||||||||||||
| 219 | 0 | my $ref_type = ref $slr; | |||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | my $desc = $ref_type ? "a ref to $ref_type" : 'not a ref'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 221 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||||||||
| 222 | qq{'recognizer' named argument to new() is $desc\n}, | ||||||||||||||||||||||||||||||||||
| 223 | " It should be a ref to $slr_class\n" | ||||||||||||||||||||||||||||||||||
| 224 | ); | ||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||
| 227 | 1141 | ▶ | $slv->[Marpa::R3::Internal_V::TRACE_FILE_HANDLE] //= | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$slv->[3] //= $slr->[3]
MC/DC0%0/2
$slv->[3] //= $slr->[3]
$slv->[3]
$slr->[3]
Truth table33%1/3
A //= B
A= $slv->[3]B= $slr->[3]
| |||||||||||||||||||||||||||||||||||
| 228 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||
| 230 | 1141 | my $trace_file_handle = | |||||||||||||||||||||||||||||||||
| 231 | $slv->[Marpa::R3::Internal_V::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||
| 233 | 1141 | my $lua = $slr->[Marpa::R3::Internal_R::L]; | |||||||||||||||||||||||||||||||||
| 234 | 1141 | $slv->[Marpa::R3::Internal_V::L] = $lua; | |||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||
| 236 | my ( $regix ) = $slr->coro_by_tag( | ||||||||||||||||||||||||||||||||||
| 237 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||||||||
| 238 | { | ||||||||||||||||||||||||||||||||||
| 239 | signature => 's', | ||||||||||||||||||||||||||||||||||
| 240 | args => [$flat_args], | ||||||||||||||||||||||||||||||||||
| 241 | handlers => { | ||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 243 | 0 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 244 | 0 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||||||||
| 245 | 0 | return 'ok'; | |||||||||||||||||||||||||||||||||
| 246 | }, | ||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||
| 248 | }, | ||||||||||||||||||||||||||||||||||
| 249 | 1141 | <<'END_OF_LUA'); | |||||||||||||||||||||||||||||||||
| 250 | local slr, flat_args = ... | ||||||||||||||||||||||||||||||||||
| 251 | _M.wrap(function () | ||||||||||||||||||||||||||||||||||
| 252 | local slv = slr:slv_new(flat_args) | ||||||||||||||||||||||||||||||||||
| 253 | if not slv then return 'ok', -1 end | ||||||||||||||||||||||||||||||||||
| 254 | return 'ok', slv.regix | ||||||||||||||||||||||||||||||||||
| 255 | end) | ||||||||||||||||||||||||||||||||||
| 256 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||
| 258 | 1141 | ▶ | return if $regix < 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 259 | 1141 | $slv->[Marpa::R3::Internal_V::REGIX] = $regix; | |||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||
| 261 | 1141 | return bless $slv, $class; | |||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||
| 264 | 1141 | ▶ | sub Marpa::R3::Valuer::DESTROY { | ||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 265 | # say STDERR "In Marpa::R3::Valuer::DESTROY before test"; | ||||||||||||||||||||||||||||||||||
| 266 | 1141 | my $slv = shift; | |||||||||||||||||||||||||||||||||
| 267 | 1141 | my $lua = $slv->[Marpa::R3::Internal_V::L]; | |||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | # If we are destroying the Perl interpreter, then all the Marpa | ||||||||||||||||||||||||||||||||||
| 270 | # objects will be destroyed, including Marpa's Lua interpreter. | ||||||||||||||||||||||||||||||||||
| 271 | # We do not need to worry about cleaning up the | ||||||||||||||||||||||||||||||||||
| 272 | # recognizer is an orderly manner, because the Lua interpreter | ||||||||||||||||||||||||||||||||||
| 273 | # containing the recognizer will be destroyed. | ||||||||||||||||||||||||||||||||||
| 274 | # In fact, the Lua interpreter may already have been destroyed, | ||||||||||||||||||||||||||||||||||
| 275 | # so this test is necessary to avoid a warning message. | ||||||||||||||||||||||||||||||||||
| 276 | 1141 | ▶ | return if not $lua; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 277 | # say STDERR "In Marpa::R3::Valuer::DESTROY after test"; | ||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||
| 279 | 1141 | my $regix = $slv->[Marpa::R3::Internal_V::REGIX]; | |||||||||||||||||||||||||||||||||
| 280 | 1141 | $slv->call_by_tag( | |||||||||||||||||||||||||||||||||
| 281 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 282 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||||||||
| 283 | local slv = ... | ||||||||||||||||||||||||||||||||||
| 284 | local regix = slv.regix | ||||||||||||||||||||||||||||||||||
| 285 | _M.unregister(_M.registry, regix) | ||||||||||||||||||||||||||||||||||
| 286 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||
| 289 | 3 | ▶ | sub Marpa::R3::Valuer::set { | ||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 290 | 3 | my ( $slv, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||
| 292 | 3 | my ($flat_args, $error_message) = Marpa::R3::flatten_hash_args(\@args); | |||||||||||||||||||||||||||||||||
| 293 | 3 | ▶ | Marpa::R3::exception( sprintf $error_message, '$slv->set()' ) if not $flat_args; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 294 | 3 | $flat_args = slv_common_set($slv, $flat_args); | |||||||||||||||||||||||||||||||||
| 295 | 3 | my $trace_file_handle = | |||||||||||||||||||||||||||||||||
| 296 | $slv->[Marpa::R3::Internal_V::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||
| 298 | $slv->coro_by_tag( | ||||||||||||||||||||||||||||||||||
| 299 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||||||||
| 301 | signature => 's', | ||||||||||||||||||||||||||||||||||
| 302 | args => [ $flat_args ], | ||||||||||||||||||||||||||||||||||
| 303 | handlers => { | ||||||||||||||||||||||||||||||||||
| 304 | 1 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 305 | 1 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 306 | 1 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||||||||
| 307 | 1 | return 'ok'; | |||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||
| 310 | }, | ||||||||||||||||||||||||||||||||||
| 311 | 3 | <<'END_OF_LUA'); | |||||||||||||||||||||||||||||||||
| 312 | local slv, flat_args = ... | ||||||||||||||||||||||||||||||||||
| 313 | return _M.wrap(function () | ||||||||||||||||||||||||||||||||||
| 314 | slv:common_set(flat_args) | ||||||||||||||||||||||||||||||||||
| 315 | end | ||||||||||||||||||||||||||||||||||
| 316 | ) | ||||||||||||||||||||||||||||||||||
| 317 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 318 | 3 | return; | |||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||
| 321 | # Returns false if no parse | ||||||||||||||||||||||||||||||||||
| 322 | 2488 | ▶ | sub Marpa::R3::Valuer::value { | ||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||
| 323 | 2488 | my ( $slv, $per_parse_arg ) = @_; | |||||||||||||||||||||||||||||||||
| 324 | 2488 | my $slr = $slv->[Marpa::R3::Internal_V::SLR]; | |||||||||||||||||||||||||||||||||
| 325 | 2488 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||
| 327 | 2488 | ▶ | my $trace_actions = | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$slg->[7] // 0
MC/DC0%0/1
$slg->[7] // 0
$slg->[7]
Truth table50%1/2
A
A= $slg->[7]
| |||||||||||||||||||||||||||||||||||
| 328 | $slg->[Marpa::R3::Internal_G::TRACE_ACTIONS] // 0; | ||||||||||||||||||||||||||||||||||
| 329 | 2488 | my $trace_file_handle = | |||||||||||||||||||||||||||||||||
| 330 | $slv->[Marpa::R3::Internal_V::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | 2488 | ▶ | my $semantics_arg0 = $per_parse_arg // {}; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$per_parse_arg // {}
MC/DC100%1/1
$per_parse_arg // {}
$per_parse_arg
Truth table100%2/2
A
A= $per_parse_arg
| |||||||||||||||||||||||||||||||||||
| 333 | 2488 | my $constants = $slg->[Marpa::R3::Internal_G::CONSTANTS]; | |||||||||||||||||||||||||||||||||
| 334 | 2488 | my $null_values = $slg->[Marpa::R3::Internal_G::NULL_VALUES]; | |||||||||||||||||||||||||||||||||
| 335 | 2488 | my $nulling_closures = | |||||||||||||||||||||||||||||||||
| 336 | $slg->[Marpa::R3::Internal_G::CLOSURE_BY_SYMBOL_ID]; | ||||||||||||||||||||||||||||||||||
| 337 | 2488 | my $rule_closures = | |||||||||||||||||||||||||||||||||
| 338 | $slg->[Marpa::R3::Internal_G::CLOSURE_BY_RULE_ID]; | ||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||
| 340 | 2488 | local $Marpa::R3::Context::rule = undef; | |||||||||||||||||||||||||||||||||
| 341 | 2488 | local $Marpa::R3::Context::irlid = undef; | |||||||||||||||||||||||||||||||||
| 342 | 2488 | local $Marpa::R3::Context::grammar = $slg; | |||||||||||||||||||||||||||||||||
| 343 | 2488 | local $Marpa::R3::Context::recognizer = $slr; | |||||||||||||||||||||||||||||||||
| 344 | 2488 | local $Marpa::R3::Context::valuer = $slv; | |||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||
| 346 | my %value_handlers = ( | ||||||||||||||||||||||||||||||||||
| 347 | 108 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 348 | 108 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 349 | 108 | ▶ | my $nl = ( $msg =~ /\n\z/xms ) ? '' : "\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 350 | 108 | print {$trace_file_handle} $msg, $nl; | |||||||||||||||||||||||||||||||||
| 351 | 108 | return 'ok'; | |||||||||||||||||||||||||||||||||
| 352 | }, | ||||||||||||||||||||||||||||||||||
| 353 | 10 | ▶ | terse_dump => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 354 | 10 | my ($value) = @_; | |||||||||||||||||||||||||||||||||
| 355 | 10 | my $dumped = Data::Dumper->new( [$value] )->Terse(1)->Dump; | |||||||||||||||||||||||||||||||||
| 356 | 10 | chomp $dumped; | |||||||||||||||||||||||||||||||||
| 357 | 10 | return 'ok', $dumped; | |||||||||||||||||||||||||||||||||
| 358 | }, | ||||||||||||||||||||||||||||||||||
| 359 | 5874 | ▶ | constant => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 360 | 5874 | my ($constant_ix) = @_; | |||||||||||||||||||||||||||||||||
| 361 | 5874 | my $constant = $constants->[$constant_ix]; | |||||||||||||||||||||||||||||||||
| 362 | 5874 | return 'sig', [ 'S', $constant ]; | |||||||||||||||||||||||||||||||||
| 363 | }, | ||||||||||||||||||||||||||||||||||
| 364 | 2096 | ▶ | perl_undef => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 365 | 2096 | return 'sig', [ 'S', undef ]; | |||||||||||||||||||||||||||||||||
| 366 | }, | ||||||||||||||||||||||||||||||||||
| 367 | 46767 | ▶ | bless => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.7
| |||||||||||||||||||||||||||||||||||
| 368 | 46767 | my ( $value, $blessing_ix ) = @_; | |||||||||||||||||||||||||||||||||
| 369 | 46767 | my $blessing_data = $constants->[$blessing_ix]; | |||||||||||||||||||||||||||||||||
| 370 | 46767 | my ( $irlid, $lexeme_id, $blessing ) = @{$blessing_data}; | |||||||||||||||||||||||||||||||||
| 371 | 46767 | my $lexeme_name; | |||||||||||||||||||||||||||||||||
| 372 | 46767 | ▶ | if ( defined $lexeme_id ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 373 | 9744 | $lexeme_name = $slg->g1_symbol_name($lexeme_id); | |||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||
| 375 | else { | ||||||||||||||||||||||||||||||||||
| 376 | 37023 | $lexeme_name = "[IRL# $irlid]"; | |||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||
| 379 | FIND_BASE_BLESSING: { | ||||||||||||||||||||||||||||||||||
| 380 | 46767 | ▶ | if ( $blessing eq '::name' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 381 | 9744 | ▶ | if ( $lexeme_name =~ / [^ [:alnum:]] /xms ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 382 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||||||||
| 383 | qq{Lexeme blessing by '::name' only allowed if lexeme name is whitespace and alphanumerics\n}, | ||||||||||||||||||||||||||||||||||
| 384 | qq{ Problematic lexeme was <$lexeme_name>\n} | ||||||||||||||||||||||||||||||||||
| 385 | ); | ||||||||||||||||||||||||||||||||||
| 386 | } ## end if ( $lexeme_name =~ / [^ [:alnum:]] /xms ) | ||||||||||||||||||||||||||||||||||
| 387 | 9744 | $blessing = $lexeme_name; | |||||||||||||||||||||||||||||||||
| 388 | 9744 | $blessing =~ s/[ ]/_/gxms; | |||||||||||||||||||||||||||||||||
| 389 | 9744 | last FIND_BASE_BLESSING; | |||||||||||||||||||||||||||||||||
| 390 | } ## end if ( $default_blessing eq '::name' ) | ||||||||||||||||||||||||||||||||||
| 391 | 37023 | ▶ | if ( $blessing =~ /^ :: /xms ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 392 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||||||||
| 393 | qq{Blessing lexeme as '$blessing' is not allowed\n}, | ||||||||||||||||||||||||||||||||||
| 394 | qq{ It is in pseudo-blessing form, but there is no such psuedo-blessing\n}, | ||||||||||||||||||||||||||||||||||
| 395 | qq{ Problematic lexeme was <$lexeme_name>\n} | ||||||||||||||||||||||||||||||||||
| 396 | ); | ||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||
| 398 | 37023 | ▶ | if ( $blessing =~ / [\W] /xms ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 399 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||||||||
| 400 | qq{Blessing lexeme as '$blessing' is not allowed\n}, | ||||||||||||||||||||||||||||||||||
| 401 | qq{ It contained non-word characters and that is not allowed\n}, | ||||||||||||||||||||||||||||||||||
| 402 | qq{ Problematic lexeme was <$lexeme_name>\n} | ||||||||||||||||||||||||||||||||||
| 403 | ); | ||||||||||||||||||||||||||||||||||
| 404 | } ## end if ( $default_blessing =~ / [\W] /xms ) | ||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||
| 407 | 46767 | ▶ | if ( $blessing !~ / :: /xms ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 408 | 46767 | my $bless_package = | |||||||||||||||||||||||||||||||||
| 409 | $slg->[Marpa::R3::Internal_G::BLESS_PACKAGE]; | ||||||||||||||||||||||||||||||||||
| 410 | 46767 | ▶ | if ( not defined $bless_package ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 411 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||||||||
| 412 | qq{Blessing package needed, but grammar has none\n}, | ||||||||||||||||||||||||||||||||||
| 413 | qq{ The blessing was "$blessing"\n} ); | ||||||||||||||||||||||||||||||||||
| 414 | } ## end if ( not defined $bless_package ) | ||||||||||||||||||||||||||||||||||
| 415 | 46767 | $blessing = $bless_package . q{::} . $blessing; | |||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||
| 417 | 46767 | return 'sig', [ 'S', ( bless $value, $blessing ) ]; | |||||||||||||||||||||||||||||||||
| 418 | }, | ||||||||||||||||||||||||||||||||||
| 419 | 147 | ▶ | perl_nulling_semantics => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||
| 420 | 147 | my ($token_id) = @_; | |||||||||||||||||||||||||||||||||
| 421 | 147 | my $value_ref = $nulling_closures->[$token_id]; | |||||||||||||||||||||||||||||||||
| 422 | 147 | my $result; | |||||||||||||||||||||||||||||||||
| 423 | my @warnings; | ||||||||||||||||||||||||||||||||||
| 424 | 147 | my $eval_ok; | |||||||||||||||||||||||||||||||||
| 425 | DO_EVAL: { | ||||||||||||||||||||||||||||||||||
| 426 | 147 | ▶ | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 427 | 0 | push @warnings, [ $_[0], ( caller 0 ) ]; | |||||||||||||||||||||||||||||||||
| 428 | 147 | }; | |||||||||||||||||||||||||||||||||
| 429 | 147 | $eval_ok = eval { | |||||||||||||||||||||||||||||||||
| 430 | 147 | my $irlid = $null_values->[$token_id]; | |||||||||||||||||||||||||||||||||
| 431 | 147 | local $Marpa::R3::Context::irlid = $irlid; | |||||||||||||||||||||||||||||||||
| 432 | 147 | local $Marpa::R3::Context::production_id = | |||||||||||||||||||||||||||||||||
| 433 | $slg->g1_rule_to_production_id($irlid); | ||||||||||||||||||||||||||||||||||
| 434 | 147 | $result = $value_ref->( $semantics_arg0, [] ); | |||||||||||||||||||||||||||||||||
| 435 | 147 | 1; | |||||||||||||||||||||||||||||||||
| 436 | }; | ||||||||||||||||||||||||||||||||||
| 437 | } ## end DO_EVAL: | ||||||||||||||||||||||||||||||||||
| 438 | 147 | ▶ | if ( not $eval_ok or @warnings ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $eval_ok or @warnings
MC/DC0%0/2
not $eval_ok or @warnings
not $eval_ok
@warnings
Truth table33%1/3
not(A) or B
A= not $eval_okB= @warnings
| |||||||||||||||||||||||||||||||||||
| 439 | 0 | my $fatal_error = $EVAL_ERROR; | |||||||||||||||||||||||||||||||||
| 440 | 0 | code_problems( | |||||||||||||||||||||||||||||||||
| 441 | { | ||||||||||||||||||||||||||||||||||
| 442 | fatal_error => $fatal_error, | ||||||||||||||||||||||||||||||||||
| 443 | eval_ok => $eval_ok, | ||||||||||||||||||||||||||||||||||
| 444 | warnings => \@warnings, | ||||||||||||||||||||||||||||||||||
| 445 | where => 'computing value', | ||||||||||||||||||||||||||||||||||
| 446 | long_where => 'Computing value for null symbol: ' | ||||||||||||||||||||||||||||||||||
| 447 | . $slg->g1_symbol_display_form($token_id), | ||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||
| 449 | ); | ||||||||||||||||||||||||||||||||||
| 450 | } ## end if ( not $eval_ok or @warnings ) | ||||||||||||||||||||||||||||||||||
| 451 | 147 | return 'sig', [ 'S', $result ]; | |||||||||||||||||||||||||||||||||
| 452 | }, | ||||||||||||||||||||||||||||||||||
| 453 | 7512 | ▶ | perl_rule_semantics => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 454 | 7512 | my ( $irlid, $values ) = @_; | |||||||||||||||||||||||||||||||||
| 455 | # say Data::Dumper::Dumper($values); | ||||||||||||||||||||||||||||||||||
| 456 | 7512 | my $closure = $rule_closures->[$irlid]; | |||||||||||||||||||||||||||||||||
| 457 | 7512 | my $result; | |||||||||||||||||||||||||||||||||
| 458 | 7512 | ▶ | if ( defined $closure ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 459 | 7512 | my @warnings; | |||||||||||||||||||||||||||||||||
| 460 | my $eval_ok; | ||||||||||||||||||||||||||||||||||
| 461 | 4 | ▶ | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 462 | 4 | push @warnings, [ $_[0], ( caller 0 ) ]; | |||||||||||||||||||||||||||||||||
| 463 | 7512 | }; | |||||||||||||||||||||||||||||||||
| 464 | 7512 | local $Marpa::R3::Context::irlid = $irlid; | |||||||||||||||||||||||||||||||||
| 465 | 7512 | local $Marpa::R3::Context::production_id = | |||||||||||||||||||||||||||||||||
| 466 | $slg->g1_rule_to_production_id($irlid); | ||||||||||||||||||||||||||||||||||
| 467 | 7512 | $eval_ok = eval { | |||||||||||||||||||||||||||||||||
| 468 | 7512 | $result = $closure->( $semantics_arg0, $values ); | |||||||||||||||||||||||||||||||||
| 469 | 7504 | 1; | |||||||||||||||||||||||||||||||||
| 470 | }; | ||||||||||||||||||||||||||||||||||
| 471 | 7512 | ▶ | if ( not $eval_ok or @warnings ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $eval_ok or @warnings
MC/DC100%2/2
not $eval_ok or @warnings
not $eval_ok
@warnings
Truth table100%3/3
not(A) or B
A= not $eval_okB= @warnings
| |||||||||||||||||||||||||||||||||||
| 472 | 10 | my $fatal_error = $EVAL_ERROR; | |||||||||||||||||||||||||||||||||
| 473 | 10 | code_problems( | |||||||||||||||||||||||||||||||||
| 474 | { | ||||||||||||||||||||||||||||||||||
| 475 | fatal_error => $fatal_error, | ||||||||||||||||||||||||||||||||||
| 476 | eval_ok => $eval_ok, | ||||||||||||||||||||||||||||||||||
| 477 | warnings => \@warnings, | ||||||||||||||||||||||||||||||||||
| 478 | where => 'computing value', | ||||||||||||||||||||||||||||||||||
| 479 | long_where => 'Computing value for rule: ' | ||||||||||||||||||||||||||||||||||
| 480 | . $slg->g1_rule_show($irlid), | ||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||
| 482 | ); | ||||||||||||||||||||||||||||||||||
| 483 | } ## end if ( not $eval_ok or @warnings ) | ||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||
| 485 | 7502 | return 'sig', [ 'S', $result ]; | |||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||
| 487 | 2488 | ); | |||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||
| 489 | 2488 | my ($cmd, $final_value) = | |||||||||||||||||||||||||||||||||
| 490 | $slv->coro_by_tag( | ||||||||||||||||||||||||||||||||||
| 491 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||||||||
| 492 | { | ||||||||||||||||||||||||||||||||||
| 493 | signature => '', | ||||||||||||||||||||||||||||||||||
| 494 | args => [], | ||||||||||||||||||||||||||||||||||
| 495 | handlers => \%value_handlers | ||||||||||||||||||||||||||||||||||
| 496 | }, | ||||||||||||||||||||||||||||||||||
| 497 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||||||||
| 498 | local slv = ... | ||||||||||||||||||||||||||||||||||
| 499 | return slv:value() | ||||||||||||||||||||||||||||||||||
| 500 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||
| 502 | 2478 | ▶ | return if $cmd ne 'ok'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 503 | 2420 | return \($final_value); | |||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||
| 507 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 508 | 2451 | ▶ | sub Marpa::R3::Valuer::call_by_tag { | ||||||||||||||||||||||||||||||||
|
Subroutine
call_by_tag: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 509 | 2451 | my ( $slv, $tag, $codestr, $signature, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 510 | 2451 | my $lua = $slv->[Marpa::R3::Internal_V::L]; | |||||||||||||||||||||||||||||||||
| 511 | 2451 | my $regix = $slv->[Marpa::R3::Internal_V::REGIX]; | |||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||
| 513 | 2451 | my @results; | |||||||||||||||||||||||||||||||||
| 514 | my $eval_error; | ||||||||||||||||||||||||||||||||||
| 515 | 2451 | my $eval_ok; | |||||||||||||||||||||||||||||||||
| 516 | { | ||||||||||||||||||||||||||||||||||
| 517 | 2451 | local $@; | |||||||||||||||||||||||||||||||||
| 518 | 2451 | $eval_ok = eval { | |||||||||||||||||||||||||||||||||
| 519 | 2451 | @results = | |||||||||||||||||||||||||||||||||
| 520 | $lua->call_by_tag( $regix, $tag, $codestr, $signature, @args ); | ||||||||||||||||||||||||||||||||||
| 521 | 2451 | return 1; | |||||||||||||||||||||||||||||||||
| 522 | }; | ||||||||||||||||||||||||||||||||||
| 523 | 2451 | $eval_error = $@; | |||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||
| 525 | 2451 | ▶ | if ( not $eval_ok ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 526 | 0 | Marpa::R3::exception($eval_error); | |||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||
| 528 | 2451 | return @results; | |||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||
| 531 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 532 | 2491 | ▶ | sub Marpa::R3::Valuer::coro_by_tag { | ||||||||||||||||||||||||||||||||
|
Subroutine
coro_by_tag: called CC=13 SCAR=26.1
| |||||||||||||||||||||||||||||||||||
| 533 | 2491 | my ( $slv, $tag, $args, $codestr ) = @_; | |||||||||||||||||||||||||||||||||
| 534 | 2491 | my $lua = $slv->[Marpa::R3::Internal_V::L]; | |||||||||||||||||||||||||||||||||
| 535 | 2491 | my $regix = $slv->[Marpa::R3::Internal_V::REGIX]; | |||||||||||||||||||||||||||||||||
| 536 | 2491 | ▶ | my $handler = $args->{handlers} // {}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"handlers"} // {}
MC/DC0%0/1
$args->{"handlers"} // {}
$args->{"handlers"}
Truth table50%1/2
A
A= $args->{"handlers"}
| |||||||||||||||||||||||||||||||||||
| 537 | 2491 | my $resume_tag = $tag . '[R]'; | |||||||||||||||||||||||||||||||||
| 538 | 2491 | ▶ | my $signature = $args->{signature} // ''; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"signature"} // ""
MC/DC0%0/1
$args->{"signature"} // ""
$args->{"signature"}
Truth table50%1/2
A
A= $args->{"signature"}
| |||||||||||||||||||||||||||||||||||
| 539 | 2491 | ▶ | my $p_args = $args->{args} // []; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"args"} // []
MC/DC0%0/1
$args->{"args"} // []
$args->{"args"}
Truth table50%1/2
A
A= $args->{"args"}
| |||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||
| 541 | 2491 | my @results; | |||||||||||||||||||||||||||||||||
| 542 | my $eval_error; | ||||||||||||||||||||||||||||||||||
| 543 | 2491 | my $eval_ok; | |||||||||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||||||||||
| 545 | 2491 | local $@; | |||||||||||||||||||||||||||||||||
| 546 | 2491 | $eval_ok = eval { | |||||||||||||||||||||||||||||||||
| 547 | 2491 | $lua->call_by_tag( $regix, $tag, $codestr, $signature, @{$p_args} ); | |||||||||||||||||||||||||||||||||
| 548 | 2491 | my @resume_args = (''); | |||||||||||||||||||||||||||||||||
| 549 | 2491 | my $signature = 's'; | |||||||||||||||||||||||||||||||||
| 550 | 2491 | CORO_CALL: while (1) { | |||||||||||||||||||||||||||||||||
| 551 | 64996 | my ( $cmd, $yield_data ) = | |||||||||||||||||||||||||||||||||
| 552 | $lua->call_by_tag( $regix, $resume_tag, | ||||||||||||||||||||||||||||||||||
| 553 | 'local slv, resume_arg = ...; return _M.resume(resume_arg)', | ||||||||||||||||||||||||||||||||||
| 554 | $signature, @resume_args ) ; | ||||||||||||||||||||||||||||||||||
| 555 | 64996 | ▶ | if (not $cmd) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 556 | 2481 | @results = @{$yield_data}; | |||||||||||||||||||||||||||||||||
| 557 | 2481 | return 1; | |||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||
| 559 | 62515 | my $handler = $handler->{$cmd}; | |||||||||||||||||||||||||||||||||
| 560 | 62515 | ▶ | Marpa::R3::exception(qq{No coro handler for "$cmd"}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 561 | if not $handler; | ||||||||||||||||||||||||||||||||||
| 562 | 62515 | ▶ | $yield_data //= []; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$yield_data //= []
MC/DC0%0/1
$yield_data //= []
$yield_data
Truth table50%1/2
A
A= $yield_data
| |||||||||||||||||||||||||||||||||||
| 563 | 62515 | my ($handler_cmd, $new_resume_args) = $handler->(@{$yield_data}); | |||||||||||||||||||||||||||||||||
| 564 | 62505 | ▶ | Marpa::R3::exception(qq{Undefined return command from handler for "$cmd"}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 565 | if not defined $handler_cmd; | ||||||||||||||||||||||||||||||||||
| 566 | 62505 | ▶ | if ($handler_cmd eq 'ok') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 567 | 119 | $signature = 's'; | |||||||||||||||||||||||||||||||||
| 568 | 119 | @resume_args = ($new_resume_args); | |||||||||||||||||||||||||||||||||
| 569 | 119 | ▶ | if (scalar @resume_args < 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 570 | 0 | @resume_args = (''); | |||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||
| 572 | 119 | next CORO_CALL; | |||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||
| 574 | 62386 | ▶ | if ($handler_cmd eq 'sig') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 575 | 62386 | @resume_args = @{$new_resume_args}; | |||||||||||||||||||||||||||||||||
| 576 | 62386 | $signature = shift @resume_args; | |||||||||||||||||||||||||||||||||
| 577 | 62386 | next CORO_CALL; | |||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||
| 579 | 0 | Marpa::R3::exception(qq{Bad return command ("$handler_cmd") from handler for "$cmd"}) | |||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||
| 581 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 582 | }; | ||||||||||||||||||||||||||||||||||
| 583 | 2491 | $eval_error = $@; | |||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||
| 585 | 2491 | ▶ | if ( not $eval_ok ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 586 | # if it's an object, just die | ||||||||||||||||||||||||||||||||||
| 587 | 10 | ▶ | die $eval_error if ref $eval_error; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 588 | 8 | Marpa::R3::exception($eval_error); | |||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||
| 590 | 2481 | return @results; | |||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||
| 593 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 594 | 4 | ▶ | sub Marpa::R3::Valuer::tree_show { | ||||||||||||||||||||||||||||||||
|
Subroutine
tree_show: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 595 | 4 | my ( $slv, $verbose ) = @_; | |||||||||||||||||||||||||||||||||
| 596 | 4 | my $text = q{}; | |||||||||||||||||||||||||||||||||
| 597 | 4 | NOOK: for ( my $nook_id = 0; 1; $nook_id++ ) { | |||||||||||||||||||||||||||||||||
| 598 | 44 | my $nook_text = $slv->nook_show( $nook_id, $verbose ); | |||||||||||||||||||||||||||||||||
| 599 | 44 | ▶ | last NOOK if not defined $nook_text; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 600 | 40 | $text .= "$nook_id: $nook_text"; | |||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||
| 602 | 4 | return $text; | |||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||
| 605 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 606 | 44 | ▶ | sub Marpa::R3::Valuer::nook_show { | ||||||||||||||||||||||||||||||||
|
Subroutine
nook_show: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||
| 607 | 44 | my ( $slv, $nook_id, $verbose ) = @_; | |||||||||||||||||||||||||||||||||
| 608 | 44 | my $slr = $slv->[Marpa::R3::Internal_V::SLR]; | |||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||
| 610 | 44 | my ($or_node_id, $text) = $slv->call_by_tag( | |||||||||||||||||||||||||||||||||
| 611 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 612 | <<'END_OF_LUA', 'i', $nook_id); | ||||||||||||||||||||||||||||||||||
| 613 | local slv, nook_id = ... | ||||||||||||||||||||||||||||||||||
| 614 | local slr = slv.slr | ||||||||||||||||||||||||||||||||||
| 615 | local tree = slv.lmw_t | ||||||||||||||||||||||||||||||||||
| 616 | -- print('nook_id', nook_id) | ||||||||||||||||||||||||||||||||||
| 617 | local or_node_id = tree:_nook_or_node(nook_id) | ||||||||||||||||||||||||||||||||||
| 618 | if not or_node_id then return end | ||||||||||||||||||||||||||||||||||
| 619 | local text = 'o' .. or_node_id | ||||||||||||||||||||||||||||||||||
| 620 | local parent = tree:_nook_parent(nook_id) or '-' | ||||||||||||||||||||||||||||||||||
| 621 | -- print('nook_is_cause', tree:_nook_is_cause(nook_id)) | ||||||||||||||||||||||||||||||||||
| 622 | if tree:_nook_is_cause(nook_id) ~= 0 then | ||||||||||||||||||||||||||||||||||
| 623 | text = text .. '[c' .. parent .. ']' | ||||||||||||||||||||||||||||||||||
| 624 | goto CHILD_TYPE_FOUND | ||||||||||||||||||||||||||||||||||
| 625 | end | ||||||||||||||||||||||||||||||||||
| 626 | if tree:_nook_is_predecessor(nook_id) ~= 0 then | ||||||||||||||||||||||||||||||||||
| 627 | text = text .. '[p' .. parent .. ']' | ||||||||||||||||||||||||||||||||||
| 628 | goto CHILD_TYPE_FOUND | ||||||||||||||||||||||||||||||||||
| 629 | end | ||||||||||||||||||||||||||||||||||
| 630 | text = text .. '[-]' | ||||||||||||||||||||||||||||||||||
| 631 | ::CHILD_TYPE_FOUND:: | ||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||
| 633 | if not or_node_id then return end | ||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||
| 635 | local tree = slv.lmw_t | ||||||||||||||||||||||||||||||||||
| 636 | text = text .. " " .. slv:or_node_tag(or_node_id) .. ' p' | ||||||||||||||||||||||||||||||||||
| 637 | if tree:_nook_predecessor_is_ready(nook_id) ~= 0 then | ||||||||||||||||||||||||||||||||||
| 638 | text = text .. '=ok' | ||||||||||||||||||||||||||||||||||
| 639 | else | ||||||||||||||||||||||||||||||||||
| 640 | text = text .. '-' | ||||||||||||||||||||||||||||||||||
| 641 | end | ||||||||||||||||||||||||||||||||||
| 642 | text = text .. ' c' | ||||||||||||||||||||||||||||||||||
| 643 | if tree:_nook_cause_is_ready(nook_id) ~= 0 then | ||||||||||||||||||||||||||||||||||
| 644 | text = text .. '=ok' | ||||||||||||||||||||||||||||||||||
| 645 | else | ||||||||||||||||||||||||||||||||||
| 646 | text = text .. '-' | ||||||||||||||||||||||||||||||||||
| 647 | end | ||||||||||||||||||||||||||||||||||
| 648 | text = text .. '\n' | ||||||||||||||||||||||||||||||||||
| 649 | return or_node_id, text | ||||||||||||||||||||||||||||||||||
| 650 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||
| 652 | 44 | ▶ | return if not defined $or_node_id; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||
| 654 | DESCRIBE_CHOICES: { | ||||||||||||||||||||||||||||||||||
| 655 | 40 | my $this_choice; | |||||||||||||||||||||||||||||||||
| 656 | 40 | ($this_choice) = $slv->call_by_tag( | |||||||||||||||||||||||||||||||||
| 657 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 658 | 'local slv, nook_id = ...; return slv.lmw_t:_nook_choice(nook_id)', | ||||||||||||||||||||||||||||||||||
| 659 | 'i', $nook_id | ||||||||||||||||||||||||||||||||||
| 660 | ); | ||||||||||||||||||||||||||||||||||
| 661 | 40 | CHOICE: for ( my $choice_ix = 0;; $choice_ix++ ) { | |||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||
| 663 | 89 | my ($and_node_id) = $slv->call_by_tag( | |||||||||||||||||||||||||||||||||
| 664 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 665 | <<'END_OF_LUA', 'ii>*', $or_node_id, $choice_ix ); | ||||||||||||||||||||||||||||||||||
| 666 | local slv, or_node_id, choice_ix = ... | ||||||||||||||||||||||||||||||||||
| 667 | return slv.lmw_o:_and_order_get(or_node_id+0, choice_ix+0) | ||||||||||||||||||||||||||||||||||
| 668 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||
| 670 | 89 | ▶ | last CHOICE if not defined $and_node_id; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 671 | 49 | $text .= " o$or_node_id" . '[' . $choice_ix . ']'; | |||||||||||||||||||||||||||||||||
| 672 | 49 | ▶ | if ( defined $this_choice and $this_choice == $choice_ix ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $this_choice and $this_choice == $choice_ix
MC/DC50%1/2
defined $this_choice and $this_choice == $choice_ix
defined $this_choice
$this_choice == $choice_ix
Truth table66%2/3
A and B
A= defined $this_choiceB= $this_choice == $choice_ix
| |||||||||||||||||||||||||||||||||||
| 673 | 40 | $text .= q{*}; | |||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||
| 675 | 49 | my $and_node_tag = | |||||||||||||||||||||||||||||||||
| 676 | $slv->and_node_tag( $and_node_id ); | ||||||||||||||||||||||||||||||||||
| 677 | 49 | $text .= " ::= a$and_node_id $and_node_tag"; | |||||||||||||||||||||||||||||||||
| 678 | 49 | $text .= "\n"; | |||||||||||||||||||||||||||||||||
| 679 | } ## end CHOICE: for ( my $choice_ix = 0;; $choice_ix++ ) | ||||||||||||||||||||||||||||||||||
| 680 | } ## end DESCRIBE_CHOICES: | ||||||||||||||||||||||||||||||||||
| 681 | 40 | return $text; | |||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||
| 684 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 685 | 49 | ▶ | sub Marpa::R3::Valuer::and_node_tag { | ||||||||||||||||||||||||||||||||
|
Subroutine
and_node_tag: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 686 | 49 | my ( $slv, $and_node_id ) = @_; | |||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||
| 688 | 49 | my ($tag) = $slv->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||||||||
| 689 | << 'END_OF_LUA', 'i', $and_node_id ); | ||||||||||||||||||||||||||||||||||
| 690 | local slv, and_node_id=... | ||||||||||||||||||||||||||||||||||
| 691 | return slv:and_node_tag(and_node_id) | ||||||||||||||||||||||||||||||||||
| 692 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||
| 694 | 49 | return $tag; | |||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||
| 697 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 698 | 0 | ▶ | sub Marpa::R3::Valuer::verbose_or_node { | ||||||||||||||||||||||||||||||||
|
Subroutine
verbose_or_node: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 699 | 0 | my ( $slv, $or_node_id ) = @_; | |||||||||||||||||||||||||||||||||
| 700 | 0 | my $slr = $slv->[Marpa::R3::Internal_V::SLR]; | |||||||||||||||||||||||||||||||||
| 701 | 0 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||
| 703 | 0 | my ($text, $nrl_id, $position) | |||||||||||||||||||||||||||||||||
| 704 | = $slv->call_by_tag( | ||||||||||||||||||||||||||||||||||
| 705 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 706 | <<'END_OF_LUA', 'i', $or_node_id); | ||||||||||||||||||||||||||||||||||
| 707 | local slv, or_node_id = ... | ||||||||||||||||||||||||||||||||||
| 708 | local slr = slv.slr | ||||||||||||||||||||||||||||||||||
| 709 | local bocage = slv.lmw_b | ||||||||||||||||||||||||||||||||||
| 710 | local origin = bocage:_or_node_origin(or_node_id) | ||||||||||||||||||||||||||||||||||
| 711 | if not origin then return end | ||||||||||||||||||||||||||||||||||
| 712 | local set = bocage:_or_node_set(or_node_id) | ||||||||||||||||||||||||||||||||||
| 713 | local position = bocage:_or_node_position(or_node_id) | ||||||||||||||||||||||||||||||||||
| 714 | local g1r = slr.g1 | ||||||||||||||||||||||||||||||||||
| 715 | local origin_earleme = g1r:earleme(origin) | ||||||||||||||||||||||||||||||||||
| 716 | local current_earleme = g1r:earleme(set) | ||||||||||||||||||||||||||||||||||
| 717 | local text = string.format( | ||||||||||||||||||||||||||||||||||
| 718 | 'OR-node #%d: R%d:@%d-%d\n', | ||||||||||||||||||||||||||||||||||
| 719 | or_node_id, | ||||||||||||||||||||||||||||||||||
| 720 | position, | ||||||||||||||||||||||||||||||||||
| 721 | origin_earleme, | ||||||||||||||||||||||||||||||||||
| 722 | current_earleme, | ||||||||||||||||||||||||||||||||||
| 723 | ) | ||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||
| 725 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 726 | 0 | ▶ | return if not $text; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||
| 728 | 0 | $text .= ( q{ } x 4 ) | |||||||||||||||||||||||||||||||||
| 729 | . $slg->dotted_nrl_show( $nrl_id, $position ) . "\n"; | ||||||||||||||||||||||||||||||||||
| 730 | 0 | return $text; | |||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||
| 733 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 734 | 3 | ▶ | sub Marpa::R3::Valuer::bocage_show { | ||||||||||||||||||||||||||||||||
|
Subroutine
bocage_show: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 735 | 3 | my ($slv) = @_; | |||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||
| 737 | 3 | my ($result) = $slv->call_by_tag( | |||||||||||||||||||||||||||||||||
| 738 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 739 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||||||||
| 740 | local slv = ... | ||||||||||||||||||||||||||||||||||
| 741 | return slv:bocage_show() | ||||||||||||||||||||||||||||||||||
| 742 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||
| 744 | 3 | return $result; | |||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||
| 747 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 748 | 4 | ▶ | sub Marpa::R3::Valuer::or_nodes_show { | ||||||||||||||||||||||||||||||||
|
Subroutine
or_nodes_show: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 749 | 4 | my ( $slv ) = @_; | |||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||
| 751 | 4 | my ($result) = $slv->call_by_tag( | |||||||||||||||||||||||||||||||||
| 752 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 753 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||||||||
| 754 | local slv = ... | ||||||||||||||||||||||||||||||||||
| 755 | return slv:or_nodes_show() | ||||||||||||||||||||||||||||||||||
| 756 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||
| 758 | 4 | return $result; | |||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||
| 761 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 762 | 4 | ▶ | sub Marpa::R3::Valuer::and_nodes_show { | ||||||||||||||||||||||||||||||||
|
Subroutine
and_nodes_show: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 763 | 4 | my ( $slv ) = @_; | |||||||||||||||||||||||||||||||||
| 764 | 4 | my ($result) = $slv->call_by_tag( | |||||||||||||||||||||||||||||||||
| 765 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 766 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||||||||
| 767 | local slv = ... | ||||||||||||||||||||||||||||||||||
| 768 | return slv:and_nodes_show() | ||||||||||||||||||||||||||||||||||
| 769 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||
| 771 | 4 | return $result; | |||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||
| 774 | 7 | ▶ | sub Marpa::R3::Valuer::ambiguous { | ||||||||||||||||||||||||||||||||
|
Subroutine
ambiguous: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 775 | 7 | my ($slv) = @_; | |||||||||||||||||||||||||||||||||
| 776 | 7 | my $slr = $slv->[Marpa::R3::Internal_V::SLR]; | |||||||||||||||||||||||||||||||||
| 777 | 7 | my $ambiguity_level = $slv->ambiguity_level(); | |||||||||||||||||||||||||||||||||
| 778 | 7 | ▶ | return q{No parse} if $ambiguity_level <= 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 779 | 7 | ▶ | return q{} if $ambiguity_level == 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 780 | # ASF must be created for end location of SLV (not SLR!) | ||||||||||||||||||||||||||||||||||
| 781 | 5 | my $asf = Marpa::R3::ASF2->new( { recognizer => $slr, end => $slv->g1_pos() } ); | |||||||||||||||||||||||||||||||||
| 782 | 5 | ▶ | die 'Could not create ASF' if not defined $asf; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 783 | 5 | my $ambiguities = Marpa::R3::Internal_ASF2::ambiguities($asf); | |||||||||||||||||||||||||||||||||
| 784 | 5 | my @ambiguities = grep {defined} @{$ambiguities}[ 0 .. 1 ]; | |||||||||||||||||||||||||||||||||
| 785 | 5 | return Marpa::R3::Internal_ASF2::ambiguities_show( $asf, \@ambiguities ); | |||||||||||||||||||||||||||||||||
| 786 | } ## end sub Marpa::R3::Recognizer::ambiguous | ||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||
| 788 | 1061 | ▶ | sub Marpa::R3::Valuer::ambiguity_level { | ||||||||||||||||||||||||||||||||
|
Subroutine
ambiguity_level: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 789 | 1061 | my ($slv) = @_; | |||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||
| 791 | 1061 | my ($metric) = $slv->call_by_tag( | |||||||||||||||||||||||||||||||||
| 792 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 793 | <<'END__OF_LUA', '>*' ); | ||||||||||||||||||||||||||||||||||
| 794 | local slv = ... | ||||||||||||||||||||||||||||||||||
| 795 | return slv:ambiguity_level() | ||||||||||||||||||||||||||||||||||
| 796 | END__OF_LUA | ||||||||||||||||||||||||||||||||||
| 797 | 1061 | return $metric; | |||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||
| 800 | 6 | ▶ | sub Marpa::R3::Valuer::g1_pos { | ||||||||||||||||||||||||||||||||
|
Subroutine
g1_pos: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 801 | 6 | my ( $slv ) = @_; | |||||||||||||||||||||||||||||||||
| 802 | 6 | my ($g1_pos) = $slv->call_by_tag( | |||||||||||||||||||||||||||||||||
| 803 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 804 | <<'END__OF_LUA', '>*' ); | ||||||||||||||||||||||||||||||||||
| 805 | local slv = ... | ||||||||||||||||||||||||||||||||||
| 806 | return slv:g1_pos() | ||||||||||||||||||||||||||||||||||
| 807 | END__OF_LUA | ||||||||||||||||||||||||||||||||||
| 808 | 6 | return $g1_pos; | |||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||
| 811 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 812 | 0 | ▶ | sub Marpa::R3::Valuer::regix { | ||||||||||||||||||||||||||||||||
|
Subroutine
regix: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 813 | 0 | my ( $slv ) = @_; | |||||||||||||||||||||||||||||||||
| 814 | 0 | my $regix = $slv->[Marpa::R3::Internal_V::REGIX]; | |||||||||||||||||||||||||||||||||
| 815 | 0 | return $regix; | |||||||||||||||||||||||||||||||||
| 816 | } | ||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||
| 818 | 104 | 1; | |||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||
| 820 | # vim: expandtab shiftwidth=4: | ||||||||||||||||||||||||||||||||||