| 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::Recognizer; | ||||||||||||||||||||||||||||
| 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_053'; | |||||||||||||||||||||||||||
| 20 | 104 | $STRING_VERSION = $VERSION; | |||||||||||||||||||||||||||
| 21 | ## no critic(BuiltinFunctions::ProhibitStringyEval) | ||||||||||||||||||||||||||||
| 22 | 104 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 23 | ## use critic | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | package Marpa::R3::Internal_R; | ||||||||||||||||||||||||||||
| 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::Recognizer'; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Given a scanless | ||||||||||||||||||||||||||||
| 33 | # recognizer and a symbol, | ||||||||||||||||||||||||||||
| 34 | # return the start earley set | ||||||||||||||||||||||||||||
| 35 | # and length | ||||||||||||||||||||||||||||
| 36 | # of the last such symbol completed, | ||||||||||||||||||||||||||||
| 37 | # undef if there was none. | ||||||||||||||||||||||||||||
| 38 | sub Marpa::R3::Recognizer::last_completed { | ||||||||||||||||||||||||||||
| 39 | 86 | ▶ | my ( $slr, $symbol_name ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
last_completed: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 40 | 86 | my ($start, $length) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 41 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 42 | <<'END_OF_LUA', 'i', $symbol_name); | ||||||||||||||||||||||||||||
| 43 | local slr, xsy_name = ... | ||||||||||||||||||||||||||||
| 44 | local xsyid = slr.slg:symbol_by_name(xsy_name) | ||||||||||||||||||||||||||||
| 45 | if not xsyid then | ||||||||||||||||||||||||||||
| 46 | _M.userX( | ||||||||||||||||||||||||||||
| 47 | "last_completed(%q): no symbol with that name", | ||||||||||||||||||||||||||||
| 48 | xsy_name) | ||||||||||||||||||||||||||||
| 49 | end | ||||||||||||||||||||||||||||
| 50 | return slr:last_completed(xsyid) | ||||||||||||||||||||||||||||
| 51 | END_OF_LUA | ||||||||||||||||||||||||||||
| 52 | 86 | ▶ | return if not defined $start; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 74 | return $start, $length; | |||||||||||||||||||||||||||
| 54 | } ## end sub Marpa::R3::Recognizer::last_completed | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Given a scanless recognizer and | ||||||||||||||||||||||||||||
| 57 | # and two earley sets, return the input string | ||||||||||||||||||||||||||||
| 58 | sub Marpa::R3::Recognizer::g1_literal { | ||||||||||||||||||||||||||||
| 59 | 1635 | ▶ | my ( $slr, $g1_start, $g1_count ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
g1_literal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1635 | my ($literal) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 62 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 63 | <<'END_OF_LUA', 'ii', $g1_start, $g1_count); | ||||||||||||||||||||||||||||
| 64 | local slr, g1_start, g1_count = ... | ||||||||||||||||||||||||||||
| 65 | return slr:g1_literal(g1_start, g1_count) | ||||||||||||||||||||||||||||
| 66 | END_OF_LUA | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1635 | return $literal; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | } ## end sub Marpa::R3::Recognizer::g1_literal | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Substring in terms of locations in the input stream | ||||||||||||||||||||||||||||
| 73 | # This is the one users will be most interested in. | ||||||||||||||||||||||||||||
| 74 | sub Marpa::R3::Recognizer::literal { | ||||||||||||||||||||||||||||
| 75 | 98 | ▶ | my ( $slr, $block_id, $offset, $length ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
literal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | 98 | my ($literal) = $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 77 | <<'END_OF_LUA', 'iii', $block_id, $offset, $length ); | ||||||||||||||||||||||||||||
| 78 | local slr, block_id_arg, offset_arg, length_arg = ... | ||||||||||||||||||||||||||||
| 79 | local block_id, offset, eoread | ||||||||||||||||||||||||||||
| 80 | = slr:block_check_range(block_id_arg, offset_arg, length_arg) | ||||||||||||||||||||||||||||
| 81 | if not block_id then | ||||||||||||||||||||||||||||
| 82 | -- if block == nil, offset is error message | ||||||||||||||||||||||||||||
| 83 | error(offset) | ||||||||||||||||||||||||||||
| 84 | end | ||||||||||||||||||||||||||||
| 85 | return slr:literal(block_id, offset, eoread-offset) | ||||||||||||||||||||||||||||
| 86 | END_OF_LUA | ||||||||||||||||||||||||||||
| 87 | 98 | return $literal; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub Marpa::R3::Internal::meta_recce { | ||||||||||||||||||||||||||||
| 91 | 291 | ▶ | my ($hash_args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
meta_recce: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | 291 | state $meta_grammar = Marpa::R3::Internal::meta_grammar(); | |||||||||||||||||||||||||||
| 93 | 291 | $hash_args->{grammar} = $meta_grammar; | |||||||||||||||||||||||||||
| 94 | 291 | my $self = Marpa::R3::Recognizer->new($hash_args); | |||||||||||||||||||||||||||
| 95 | 291 | return $self; | |||||||||||||||||||||||||||
| 96 | } ## end sub Marpa::R3::Internal::meta_recce | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # Set those common args which are at the Perl level. | ||||||||||||||||||||||||||||
| 99 | sub perl_common_set { | ||||||||||||||||||||||||||||
| 100 | 1215 | ▶ | my ( $slr, $flat_args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
perl_common_set: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 101 | 1215 | ▶ | if ( my $value = $flat_args->{'trace_file_handle'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 10 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE] = $value; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 1215 | my $trace_file_handle = | |||||||||||||||||||||||||||
| 105 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||
| 106 | 1215 | delete $flat_args->{'trace_file_handle'}; | |||||||||||||||||||||||||||
| 107 | 1215 | return $flat_args; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub gen_app_event_handler { | ||||||||||||||||||||||||||||
| 111 | 6111 | ▶ | my ($slr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
gen_app_event_handler: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 112 | 6111 | my $event_handlers = | |||||||||||||||||||||||||||
| 113 | $slr->[Marpa::R3::Internal_R::EVENT_HANDLERS]; | ||||||||||||||||||||||||||||
| 114 | return sub { | ||||||||||||||||||||||||||||
| 115 | 1333 | ▶ | my ( $event_type, $event_name, @data ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=24.3
| |||||||||||||||||||||||||||||
| 116 | 1333 | my $current_event = | |||||||||||||||||||||||||||
| 117 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT]; | ||||||||||||||||||||||||||||
| 118 | 1333 | ▶ | if ($current_event) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 120 | qq{Attempt to call one event handler inside another\n}, | ||||||||||||||||||||||||||||
| 121 | qq{ This is not allowed\n}, | ||||||||||||||||||||||||||||
| 122 | qq{ The currently active handler is for a "$current_event" event\n}, | ||||||||||||||||||||||||||||
| 123 | qq{ The attempted handler call is for a "$event_name" event\n} | ||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 1333 | my $handler = $event_handlers->{$event_name}; | |||||||||||||||||||||||||||
| 127 | 1333 | ▶ | if ( not $handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 725 | $handler = $event_handlers->{"'default"}; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 1333 | ▶ | if ( not $handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 132 | qq{'No event handler for event "$event_name"\n}); | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 1333 | ▶ | if ( ref $handler ne 'CODE' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | my $ref_type = ref $handler; | |||||||||||||||||||||||||||
| 136 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 137 | qq{Bad event handler for event "$event_name"\n}, | ||||||||||||||||||||||||||||
| 138 | qq{ Handler is a ref to $ref_type\n}, | ||||||||||||||||||||||||||||
| 139 | qq{ A handler should be a ref to code\n} | ||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 1333 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT] = $event_name; | |||||||||||||||||||||||||||
| 143 | 1333 | ▶ | my $retour = $handler->( $slr, $event_name, @data ) // 'ok'; | ||||||||||||||||||||||||||
|
Condition50%1/2
&$handler($slr, $event_name, @data) // "ok"
MC/DC0%0/1
&$handler($slr, $event_name, @data) // "ok"
&$handler($slr, $event_name, @data)
Truth table50%1/2
A
A= &$handler($slr, $event_name, @data)
| |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | RETOUR_CHECK: { | ||||||||||||||||||||||||||||
| 146 | 1333 | ▶ | if ($retour eq 'ok') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 644 | ▶ | if ($event_type eq 'before lexeme') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 149 | qq{Bad return from event handler for event "$event_name"\n}, | ||||||||||||||||||||||||||||
| 150 | qq{ Event type was "$event_type"\n}, | ||||||||||||||||||||||||||||
| 151 | qq{ Return from handler was "$retour"\n}, | ||||||||||||||||||||||||||||
| 152 | qq{ A handler of type "$event_type" must return "pause"\n}, | ||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 644 | last RETOUR_CHECK; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 689 | ▶ | last RETOUR_CHECK if $retour eq 'pause'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 159 | qq{Bad return from event handler for event "$event_name"\n}, | ||||||||||||||||||||||||||||
| 160 | qq{ Event type was "$event_type"\n}, | ||||||||||||||||||||||||||||
| 161 | qq{ Return from handler was "$retour"\n}, | ||||||||||||||||||||||||||||
| 162 | qq{ Handler must return "ok" or "pause"\n}, | ||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | 1333 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT] = undef; | |||||||||||||||||||||||||||
| 166 | 1333 | return 'ok', $retour; | |||||||||||||||||||||||||||
| 167 | 6111 | }; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | sub gen_codepoint_event_handler { | ||||||||||||||||||||||||||||
| 171 | 3095 | ▶ | my ($slr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
gen_codepoint_event_handler: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 172 | 3095 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||
| 173 | 3095 | my $character_class_table = | |||||||||||||||||||||||||||
| 174 | $slg->[Marpa::R3::Internal_G::CHARACTER_CLASS_TABLE]; | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | return sub { | ||||||||||||||||||||||||||||
| 177 | 5541 | ▶ | my ( $codepoint, $trace_terminals ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 178 | 5541 | my $character = pack( 'U', $codepoint ); | |||||||||||||||||||||||||||
| 179 | 5541 | my $is_graphic = ( $character =~ m/[[:graph:]]+/ ); | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 5541 | my @symbols; | |||||||||||||||||||||||||||
| 182 | 5541 | for my $entry ( @{$character_class_table} ) { | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 231283 | my ( $symbol_id, $re ) = @{$entry}; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | # say STDERR "Codepoint %x vs $re\n"; | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 231283 | ▶ | if ( $character =~ $re ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 26156 | ▶ | if ( $trace_terminals >= 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 18 | my $trace_file_handle = | |||||||||||||||||||||||||||
| 192 | $slr | ||||||||||||||||||||||||||||
| 193 | ->[ Marpa::R3::Internal_R::TRACE_FILE_HANDLE ]; | ||||||||||||||||||||||||||||
| 194 | 18 | my $char_desc = character_describe( $slr, $codepoint ); | |||||||||||||||||||||||||||
| 195 | 18 | ▶ | say {$trace_file_handle} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | qq{Registering character $char_desc as symbol $symbol_id: }, | ||||||||||||||||||||||||||||
| 197 | $slg->l0_symbol_display_form($symbol_id) | ||||||||||||||||||||||||||||
| 198 | or Marpa::R3::exception("Could not say(): $ERRNO"); | ||||||||||||||||||||||||||||
| 199 | } ## end if ( $trace_terminals >= 2 ) | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 26156 | push @symbols, $symbol_id; | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | } ## end if ( $character =~ $re ) | ||||||||||||||||||||||||||||
| 204 | } ## end for my $entry ( @{$character_class_table} ) | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 5541 | my $coro_arg = { symbols => \@symbols }; | |||||||||||||||||||||||||||
| 207 | 5541 | ▶ | $coro_arg->{is_graphic} = 'true' if $is_graphic; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 5541 | return 'ok', $coro_arg; | |||||||||||||||||||||||||||
| 209 | 3095 | }; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | sub Marpa::R3::Recognizer::new { | ||||||||||||||||||||||||||||
| 213 | 1204 | ▶ | my ( $class, @args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=25.0
| |||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 1204 | my $slr = []; | |||||||||||||||||||||||||||
| 216 | 1204 | bless $slr, $class; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | # Set recognizer args to default | ||||||||||||||||||||||||||||
| 219 | # Lua equivalent is set below | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 1204 | my ( $flat_args, $error_message ) = Marpa::R3::flatten_hash_args( \@args ); | |||||||||||||||||||||||||||
| 222 | 1204 | ▶ | Marpa::R3::exception( sprintf $error_message, '$slr->new' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | if not $flat_args; | ||||||||||||||||||||||||||||
| 224 | 1204 | $flat_args = perl_common_set( $slr, $flat_args ); | |||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 1204 | my $slg = $flat_args->{grammar}; | |||||||||||||||||||||||||||
| 227 | 1204 | ▶ | Marpa::R3::exception( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | qq{Marpa::R3::Recognizer::new() called without a "grammar" argument} ) | ||||||||||||||||||||||||||||
| 229 | if not defined $slg; | ||||||||||||||||||||||||||||
| 230 | 1204 | $slr->[Marpa::R3::Internal_R::SLG] = $slg; | |||||||||||||||||||||||||||
| 231 | 1204 | delete $flat_args->{grammar}; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 1204 | ▶ | my $event_handlers = $flat_args->{event_handlers} // {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$flat_args->{"event_handlers"} // {}
MC/DC100%1/1
$flat_args->{"event_handlers"} // {}
$flat_args->{"event_handlers"}
Truth table100%2/2
A
A= $flat_args->{"event_handlers"}
| |||||||||||||||||||||||||||||
| 234 | 1204 | $slr->[Marpa::R3::Internal_R::EVENT_HANDLERS] = $event_handlers; | |||||||||||||||||||||||||||
| 235 | 1204 | ▶ | if ( ref $event_handlers ne 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 0 | my $ref_type = ref $event_handlers; | |||||||||||||||||||||||||||
| 237 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 238 | qq{'event_handlers' named argument to new() is $ref_type\n}, | ||||||||||||||||||||||||||||
| 239 | " It should be a ref to a hash\n", | ||||||||||||||||||||||||||||
| 240 | " whose keys are event names and\n", | ||||||||||||||||||||||||||||
| 241 | " whose values are code refs\n" | ||||||||||||||||||||||||||||
| 242 | ); | ||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | 1204 | delete $flat_args->{event_handlers}; | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 1204 | my $slg_class = 'Marpa::R3::Grammar'; | |||||||||||||||||||||||||||
| 247 | 1204 | ▶ | if ( not blessed $slg or not $slg->isa($slg_class) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($slg) and $slg->isa($slg_class)
MC/DC0%0/2
builtin::blessed($slg) and $slg->isa($slg_class)
builtin::blessed($slg)
$slg->isa($slg_class)
Truth table33%1/3
A and B
A= builtin::blessed($slg)B= $slg->isa($slg_class)
| |||||||||||||||||||||||||||||
| 248 | 0 | my $ref_type = ref $slg; | |||||||||||||||||||||||||||
| 249 | 0 | ▶ | my $desc = $ref_type ? "a ref to $ref_type" : 'not a ref'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 251 | qq{'grammar' named argument to new() is $desc\n}, | ||||||||||||||||||||||||||||
| 252 | " It should be a ref to $slg_class\n" | ||||||||||||||||||||||||||||
| 253 | ); | ||||||||||||||||||||||||||||
| 254 | } ## end if ( not blessed $slg or not $slg->isa($slg_class) ) | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 1204 | ▶ | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE] //= | ||||||||||||||||||||||||||
|
Condition66%2/3
$slr->[3] //= $slg->[2]
MC/DC0%0/2
$slr->[3] //= $slg->[2]
$slr->[3]
$slg->[2]
Truth table66%2/3
A //= B
A= $slr->[3]B= $slg->[2]
| |||||||||||||||||||||||||||||
| 257 | $slg->[Marpa::R3::Internal_G::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 1204 | my $trace_file_handle = | |||||||||||||||||||||||||||
| 260 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 1204 | my $lua = $slg->[Marpa::R3::Internal_G::L]; | |||||||||||||||||||||||||||
| 263 | 1204 | $slr->[Marpa::R3::Internal_R::L] = $lua; | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | my ( $regix ) = $slg->coro_by_tag( | ||||||||||||||||||||||||||||
| 266 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 267 | { | ||||||||||||||||||||||||||||
| 268 | signature => 's', | ||||||||||||||||||||||||||||
| 269 | args => [$flat_args], | ||||||||||||||||||||||||||||
| 270 | handlers => { | ||||||||||||||||||||||||||||
| 271 | perl_undef => sub { | ||||||||||||||||||||||||||||
| 272 | 0 | ▶ | return 'sig', [ 'S', undef ]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 273 | }, | ||||||||||||||||||||||||||||
| 274 | trace => sub { | ||||||||||||||||||||||||||||
| 275 | 8 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 276 | 8 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||
| 277 | 8 | return 'ok'; | |||||||||||||||||||||||||||
| 278 | }, | ||||||||||||||||||||||||||||
| 279 | 1204 | codepoint => gen_codepoint_event_handler($slr), | |||||||||||||||||||||||||||
| 280 | event => gen_app_event_handler($slr), | ||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | }, | ||||||||||||||||||||||||||||
| 283 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||
| 284 | local slg, flat_args = ... | ||||||||||||||||||||||||||||
| 285 | _M.wrap(function () | ||||||||||||||||||||||||||||
| 286 | local slr = slg:slr_new(flat_args) | ||||||||||||||||||||||||||||
| 287 | return 'ok', slr.regix | ||||||||||||||||||||||||||||
| 288 | end) | ||||||||||||||||||||||||||||
| 289 | END_OF_LUA | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 1204 | $slr->[Marpa::R3::Internal_R::REGIX] = $regix; | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | $slr->coro_by_tag( | ||||||||||||||||||||||||||||
| 294 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 295 | { | ||||||||||||||||||||||||||||
| 296 | signature => 's', | ||||||||||||||||||||||||||||
| 297 | args => [$flat_args], | ||||||||||||||||||||||||||||
| 298 | handlers => { | ||||||||||||||||||||||||||||
| 299 | trace => sub { | ||||||||||||||||||||||||||||
| 300 | 0 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 301 | 0 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||
| 302 | 0 | return 'ok'; | |||||||||||||||||||||||||||
| 303 | }, | ||||||||||||||||||||||||||||
| 304 | 1204 | event => gen_app_event_handler($slr), | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | }, | ||||||||||||||||||||||||||||
| 307 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||
| 308 | local slr, flat_args = ... | ||||||||||||||||||||||||||||
| 309 | _M.wrap(function () | ||||||||||||||||||||||||||||
| 310 | slr:convert_libmarpa_events() | ||||||||||||||||||||||||||||
| 311 | return 'ok' | ||||||||||||||||||||||||||||
| 312 | end) | ||||||||||||||||||||||||||||
| 313 | END_OF_LUA | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 1204 | return $slr; | |||||||||||||||||||||||||||
| 316 | } ## end sub Marpa::R3::Recognizer::new | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | sub Marpa::R3::Recognizer::DESTROY { | ||||||||||||||||||||||||||||
| 319 | # say STDERR "In Marpa::R3::Recognizer::DESTROY before test"; | ||||||||||||||||||||||||||||
| 320 | 1197 | ▶ | my $slr = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 321 | 1197 | my $lua = $slr->[Marpa::R3::Internal_R::L]; | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | # If we are destroying the Perl interpreter, then all the Marpa | ||||||||||||||||||||||||||||
| 324 | # objects will be destroyed, including Marpa's Lua interpreter. | ||||||||||||||||||||||||||||
| 325 | # We do not need to worry about cleaning up the | ||||||||||||||||||||||||||||
| 326 | # recognizer is an orderly manner, because the Lua interpreter | ||||||||||||||||||||||||||||
| 327 | # containing the recognizer will be destroyed. | ||||||||||||||||||||||||||||
| 328 | # In fact, the Lua interpreter may already have been destroyed, | ||||||||||||||||||||||||||||
| 329 | # so this test is necessary to avoid a warning message. | ||||||||||||||||||||||||||||
| 330 | 1197 | ▶ | return if not $lua; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | # say STDERR "In Marpa::R3::Recognizer::DESTROY after test"; | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 1197 | my $regix = $slr->[Marpa::R3::Internal_R::REGIX]; | |||||||||||||||||||||||||||
| 334 | 1197 | $slr->call_by_tag( | |||||||||||||||||||||||||||
| 335 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 336 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||
| 337 | local slr = ... | ||||||||||||||||||||||||||||
| 338 | local regix = slr.regix | ||||||||||||||||||||||||||||
| 339 | _M.unregister(_M.registry, regix) | ||||||||||||||||||||||||||||
| 340 | END_OF_LUA | ||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | sub Marpa::R3::Recognizer::set { | ||||||||||||||||||||||||||||
| 344 | 11 | ▶ | my ( $slr, @args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 11 | my ($flat_args, $error_message) = Marpa::R3::flatten_hash_args(\@args); | |||||||||||||||||||||||||||
| 347 | 11 | ▶ | Marpa::R3::exception( sprintf $error_message, '$slr->set()' ) if not $flat_args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 11 | $flat_args = perl_common_set($slr, $flat_args); | |||||||||||||||||||||||||||
| 349 | 11 | my $trace_file_handle = | |||||||||||||||||||||||||||
| 350 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | $slr->coro_by_tag( | ||||||||||||||||||||||||||||
| 353 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 354 | { | ||||||||||||||||||||||||||||
| 355 | signature => 's', | ||||||||||||||||||||||||||||
| 356 | args => [ $flat_args ], | ||||||||||||||||||||||||||||
| 357 | handlers => { | ||||||||||||||||||||||||||||
| 358 | trace => sub { | ||||||||||||||||||||||||||||
| 359 | 2 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 360 | 2 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||
| 361 | 2 | return 'ok'; | |||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | }, | ||||||||||||||||||||||||||||
| 365 | 11 | <<'END_OF_LUA'); | |||||||||||||||||||||||||||
| 366 | local slr, flat_args = ... | ||||||||||||||||||||||||||||
| 367 | return _M.wrap(function () | ||||||||||||||||||||||||||||
| 368 | slr:common_set(flat_args) | ||||||||||||||||||||||||||||
| 369 | end | ||||||||||||||||||||||||||||
| 370 | ) | ||||||||||||||||||||||||||||
| 371 | END_OF_LUA | ||||||||||||||||||||||||||||
| 372 | 11 | return; | |||||||||||||||||||||||||||
| 373 | } ## end sub Marpa::R3::Recognizer::set | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | sub Marpa::R3::Recognizer::read { | ||||||||||||||||||||||||||||
| 376 | 1209 | ▶ | my ( $slr, $p_string, $start_pos, $length ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 377 | 1209 | ▶ | if ( $slr->[Marpa::R3::Internal_R::CURRENT_EVENT] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 379 | "$slr->read() called from inside a handler\n", | ||||||||||||||||||||||||||||
| 380 | " This is not allowed\n", | ||||||||||||||||||||||||||||
| 381 | " The event was ", | ||||||||||||||||||||||||||||
| 382 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT], | ||||||||||||||||||||||||||||
| 383 | "\n", | ||||||||||||||||||||||||||||
| 384 | ); | ||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | 1209 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 1209 | my $block_id = $slr->block_new($p_string); | |||||||||||||||||||||||||||
| 389 | 1208 | $slr->block_set($block_id); | |||||||||||||||||||||||||||
| 390 | 1208 | $slr->block_move($start_pos, $length); | |||||||||||||||||||||||||||
| 391 | 1208 | return $slr->block_read(); | |||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | sub Marpa::R3::Recognizer::resume { | ||||||||||||||||||||||||||||
| 395 | 549 | ▶ | my ( $slr, $start_pos, $length ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
resume: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 396 | 549 | ▶ | if ( $slr->[Marpa::R3::Internal_R::CURRENT_EVENT] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 397 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 398 | "$slr->resume() called from inside a handler\n", | ||||||||||||||||||||||||||||
| 399 | " This is not allowed\n", | ||||||||||||||||||||||||||||
| 400 | " The event was ", | ||||||||||||||||||||||||||||
| 401 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT], | ||||||||||||||||||||||||||||
| 402 | "\n", | ||||||||||||||||||||||||||||
| 403 | ); | ||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | 549 | my $trace_file_handle = | |||||||||||||||||||||||||||
| 406 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||
| 407 | 549 | ▶ | $length //= -1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$length //= -1
MC/DC100%1/1
$length //= -1
$length
Truth table100%2/2
A
A= $length
| |||||||||||||||||||||||||||||
| 408 | 549 | $slr->block_move( $start_pos, $length ); | |||||||||||||||||||||||||||
| 409 | 549 | return $slr->block_read(); | |||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | sub character_describe { | ||||||||||||||||||||||||||||
| 413 | 18 | ▶ | my ($slr, $codepoint) = @_; | ||||||||||||||||||||||||||
|
Subroutine
character_describe: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 18 | my ($desc) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 416 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 417 | <<'END__OF_LUA', 'i', $codepoint ); | ||||||||||||||||||||||||||||
| 418 | local slr, codepoint = ... | ||||||||||||||||||||||||||||
| 419 | return slr:character_describe(codepoint) | ||||||||||||||||||||||||||||
| 420 | END__OF_LUA | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 18 | return $desc; | |||||||||||||||||||||||||||
| 423 | } ## end sub character_describe | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | # This is a Marpa Grammar method, but is included in this | ||||||||||||||||||||||||||||
| 426 | # file because internally it is all about the recognizer. | ||||||||||||||||||||||||||||
| 427 | sub Marpa::R3::Grammar::parse { | ||||||||||||||||||||||||||||
| 428 | 2 | ▶ | my ( $slg, $input_ref, @more_args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=7 SCAR=22.8
| |||||||||||||||||||||||||||||
| 429 | 2 | ▶ | if ( not defined $input_ref or ref $input_ref ne 'SCALAR' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $input_ref or ref $input_ref ne "SCALAR"
MC/DC0%0/2
not defined $input_ref or ref $input_ref ne "SCALAR"
not defined $input_ref
ref $input_ref ne "SCALAR"
Truth table33%1/3
not(A) or B
A= not defined $input_refB= ref $input_ref ne "SCALAR"
| |||||||||||||||||||||||||||||
| 430 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 431 | q{$slr->parse(): first argument must be a ref to string}); | ||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | 2 | my @recce_args = ( { grammar => $slg } ); | |||||||||||||||||||||||||||
| 434 | 2 | ▶ | if ( grep { ref $_ ne 'HASH' } @more_args ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 435 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 436 | q{$slr->parse(): second and later arguments must be ref to HASH}); | ||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | 2 | my $slr = Marpa::R3::Recognizer->new( @recce_args, @more_args, | |||||||||||||||||||||||||||
| 439 | ); | ||||||||||||||||||||||||||||
| 440 | 2 | my $input_length = ${$input_ref}; | |||||||||||||||||||||||||||
| 441 | 2 | my $length_read = $slr->read($input_ref); | |||||||||||||||||||||||||||
| 442 | 2 | ▶ | if ( $length_read != length $input_length ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 443 | 0 | die 'read in $slr->parse() ended prematurely', "\n", | |||||||||||||||||||||||||||
| 444 | " The input length is $input_length\n", | ||||||||||||||||||||||||||||
| 445 | " The length read is $length_read\n", | ||||||||||||||||||||||||||||
| 446 | " The cause may be an event\n", | ||||||||||||||||||||||||||||
| 447 | " The $slr->parse() method does not allow parses to trigger events"; | ||||||||||||||||||||||||||||
| 448 | } ## end if ( $length_read != length $input_length ) | ||||||||||||||||||||||||||||
| 449 | 2 | my $slv = Marpa::R3::Valuer->new( { recognizer => $slr }); | |||||||||||||||||||||||||||
| 450 | 2 | my $ambiguity_level = $slv->ambiguity_level(); | |||||||||||||||||||||||||||
| 451 | 2 | ▶ | if ( $ambiguity_level != 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | 0 | my $ambiguous_status = $slv->ambiguous(); | |||||||||||||||||||||||||||
| 453 | 0 | Marpa::R3::exception( "Parse of the input is ambiguous\n", | |||||||||||||||||||||||||||
| 454 | $ambiguous_status ); | ||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 2 | my $value_ref = $slv->value(); | |||||||||||||||||||||||||||
| 458 | 2 | ▶ | Marpa::R3::exception( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | '$slr->parse() read the input, but there was no parse', "\n" ) | ||||||||||||||||||||||||||||
| 460 | if not $value_ref; | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 2 | return $value_ref; | |||||||||||||||||||||||||||
| 463 | } ## end sub Marpa::R3::Grammar::parse | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | # Brief description of block/line/column for | ||||||||||||||||||||||||||||
| 466 | # an L0 range | ||||||||||||||||||||||||||||
| 467 | sub lc_brief { | ||||||||||||||||||||||||||||
| 468 | 0 | ▶ | my ( $slr, $pos, $block ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lc_brief: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 469 | 0 | ▶ | my ($result) = $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||
|
Condition0%0/2
$block // -1
MC/DC0%0/1
$block // -1
$block
Truth table0%0/2
A
A= $block
| |||||||||||||||||||||||||||||
| 470 | <<'END_OF_LUA', 'ii', $pos, ($block // -1)); | ||||||||||||||||||||||||||||
| 471 | local slr, pos, block = ... | ||||||||||||||||||||||||||||
| 472 | if block < 0 then block = nil end | ||||||||||||||||||||||||||||
| 473 | return slr:lc_brief(block, pos) | ||||||||||||||||||||||||||||
| 474 | END_OF_LUA | ||||||||||||||||||||||||||||
| 475 | 0 | return $result; | |||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | # Brief description of block/line/column for | ||||||||||||||||||||||||||||
| 479 | # an L0 range | ||||||||||||||||||||||||||||
| 480 | sub lc_range_brief { | ||||||||||||||||||||||||||||
| 481 | 0 | ▶ | my ( $slr, $first_block, $first_pos, $last_block, $last_pos ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lc_range_brief: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 482 | 0 | my ($result) = $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 483 | <<'END_OF_LUA', 'iiii', $first_block, $first_pos, $last_block, $last_pos ); | ||||||||||||||||||||||||||||
| 484 | local slr, block1, pos1, block2, pos2 = ... | ||||||||||||||||||||||||||||
| 485 | return slr:lc_range_brief(block1, pos1, block2, pos2) | ||||||||||||||||||||||||||||
| 486 | END_OF_LUA | ||||||||||||||||||||||||||||
| 487 | 0 | return $result; | |||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | sub Marpa::R3::Recognizer::progress_show { | ||||||||||||||||||||||||||||
| 492 | 19 | ▶ | my ( $slr, $start_ordinal, $end_ordinal ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
progress_show: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 493 | 19 | my ($text) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 494 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 495 | <<'END_OF_LUA', 'ii', $start_ordinal, $end_ordinal ); | ||||||||||||||||||||||||||||
| 496 | local slr, start_ordinal_arg, end_ordinal_arg = ... | ||||||||||||||||||||||||||||
| 497 | return slr:progress_show(start_ordinal_arg, end_ordinal_arg ) | ||||||||||||||||||||||||||||
| 498 | END_OF_LUA | ||||||||||||||||||||||||||||
| 499 | 19 | return $text; | |||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | sub Marpa::R3::Recognizer::progress { | ||||||||||||||||||||||||||||
| 503 | 19 | ▶ | my ( $slr, $ordinal_arg ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
progress: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 504 | 19 | ▶ | my ($result) = $slr->call_by_tag( | ||||||||||||||||||||||||||
|
Condition100%2/2
$ordinal_arg // -1
MC/DC100%1/1
$ordinal_arg // -1
$ordinal_arg
Truth table100%2/2
A
A= $ordinal_arg
| |||||||||||||||||||||||||||||
| 505 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 506 | <<'END_OF_LUA', 'i>0', ($ordinal_arg // -1)); | ||||||||||||||||||||||||||||
| 507 | local slr, ordinal_arg = ... | ||||||||||||||||||||||||||||
| 508 | return slr:progress(ordinal_arg) | ||||||||||||||||||||||||||||
| 509 | END_OF_LUA | ||||||||||||||||||||||||||||
| 510 | 19 | return $result; | |||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | sub Marpa::R3::Recognizer::g1_progress_show { | ||||||||||||||||||||||||||||
| 514 | 0 | ▶ | my ( $slr, $start_ordinal, $end_ordinal ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
g1_progress_show: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 515 | 0 | my ($text) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 516 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 517 | <<'END_OF_LUA', 'ii', $start_ordinal, $end_ordinal ); | ||||||||||||||||||||||||||||
| 518 | local slr, start_ordinal_arg, end_ordinal_arg = ... | ||||||||||||||||||||||||||||
| 519 | return slr:g1_progress_show(start_ordinal_arg, end_ordinal_arg ) | ||||||||||||||||||||||||||||
| 520 | END_OF_LUA | ||||||||||||||||||||||||||||
| 521 | 0 | return $text; | |||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | sub Marpa::R3::Recognizer::g1_progress { | ||||||||||||||||||||||||||||
| 525 | 21 | ▶ | my ( $slr, $ordinal_arg ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
g1_progress: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 526 | 21 | ▶ | my ($result) = $slr->call_by_tag( | ||||||||||||||||||||||||||
|
Condition50%1/2
$ordinal_arg // -1
MC/DC0%0/1
$ordinal_arg // -1
$ordinal_arg
Truth table50%1/2
A
A= $ordinal_arg
| |||||||||||||||||||||||||||||
| 527 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 528 | <<'END_OF_LUA', 'i>0', ($ordinal_arg // -1)); | ||||||||||||||||||||||||||||
| 529 | local slr, ordinal_arg = ... | ||||||||||||||||||||||||||||
| 530 | return slr:g1_progress(ordinal_arg) | ||||||||||||||||||||||||||||
| 531 | END_OF_LUA | ||||||||||||||||||||||||||||
| 532 | 21 | return $result; | |||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | sub Marpa::R3::Recognizer::terminals_expected { | ||||||||||||||||||||||||||||
| 536 | 35 | ▶ | my ($slr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
terminals_expected: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 537 | 35 | my ($results) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 538 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 539 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||
| 540 | local slr = ... | ||||||||||||||||||||||||||||
| 541 | local slg = slr.slg | ||||||||||||||||||||||||||||
| 542 | local g1g = slg.g1 | ||||||||||||||||||||||||||||
| 543 | local terminals_expected = slr.g1:terminals_expected() | ||||||||||||||||||||||||||||
| 544 | local results = {} | ||||||||||||||||||||||||||||
| 545 | for ix = 1, #terminals_expected do | ||||||||||||||||||||||||||||
| 546 | local g1_symbol_id = terminals_expected[ix] | ||||||||||||||||||||||||||||
| 547 | local xsy = g1g:_xsy(g1_symbol_id) | ||||||||||||||||||||||||||||
| 548 | if xsy then | ||||||||||||||||||||||||||||
| 549 | results[#results+1] = xsy.name | ||||||||||||||||||||||||||||
| 550 | end | ||||||||||||||||||||||||||||
| 551 | end | ||||||||||||||||||||||||||||
| 552 | return results | ||||||||||||||||||||||||||||
| 553 | END_OF_LUA | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | 35 | return $results; | |||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | sub Marpa::R3::Recognizer::exhausted { | ||||||||||||||||||||||||||||
| 559 | 18 | ▶ | my ($slr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
exhausted: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 560 | 18 | my ($is_exhausted) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 561 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 562 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||
| 563 | local recce = ... | ||||||||||||||||||||||||||||
| 564 | local is_exhausted = recce.g1:is_exhausted() | ||||||||||||||||||||||||||||
| 565 | return is_exhausted | ||||||||||||||||||||||||||||
| 566 | END_OF_LUA | ||||||||||||||||||||||||||||
| 567 | 18 | return $is_exhausted; | |||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | # Latest and current G1 location are the same | ||||||||||||||||||||||||||||
| 571 | sub Marpa::R3::Recognizer::g1_pos { | ||||||||||||||||||||||||||||
| 572 | 185 | ▶ | my ($slr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
g1_pos: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 573 | 185 | my ($latest_earley_set) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 574 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 575 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||
| 576 | local recce = ... | ||||||||||||||||||||||||||||
| 577 | local latest_earley_set = recce:latest_earley_set() | ||||||||||||||||||||||||||||
| 578 | return latest_earley_set | ||||||||||||||||||||||||||||
| 579 | END_OF_LUA | ||||||||||||||||||||||||||||
| 580 | 185 | return $latest_earley_set; | |||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | sub Marpa::R3::Recognizer::current_earleme { | ||||||||||||||||||||||||||||
| 584 | 12 | ▶ | my ($slr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
current_earleme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 585 | 12 | my ($current_earleme) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 586 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 587 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||
| 588 | local recce = ... | ||||||||||||||||||||||||||||
| 589 | local current_earleme = recce:current_earleme() | ||||||||||||||||||||||||||||
| 590 | return current_earleme | ||||||||||||||||||||||||||||
| 591 | END_OF_LUA | ||||||||||||||||||||||||||||
| 592 | 12 | return $current_earleme; | |||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | sub Marpa::R3::Recognizer::closest_earleme { | ||||||||||||||||||||||||||||
| 596 | 12 | ▶ | my ($slr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
closest_earleme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 597 | 12 | my ($closest_earleme) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 598 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 599 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||
| 600 | local recce = ... | ||||||||||||||||||||||||||||
| 601 | local closest_earleme = recce:closest_earleme() | ||||||||||||||||||||||||||||
| 602 | return closest_earleme | ||||||||||||||||||||||||||||
| 603 | END_OF_LUA | ||||||||||||||||||||||||||||
| 604 | 12 | return $closest_earleme; | |||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | sub Marpa::R3::Recognizer::furthest_earleme { | ||||||||||||||||||||||||||||
| 608 | 12 | ▶ | my ($slr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
furthest_earleme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 609 | 12 | my ($furthest_earleme) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 610 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 611 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||
| 612 | local recce = ... | ||||||||||||||||||||||||||||
| 613 | local furthest_earleme = recce:furthest_earleme() | ||||||||||||||||||||||||||||
| 614 | return furthest_earleme | ||||||||||||||||||||||||||||
| 615 | END_OF_LUA | ||||||||||||||||||||||||||||
| 616 | 12 | return $furthest_earleme; | |||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | sub Marpa::R3::Recognizer::latest_earleme { | ||||||||||||||||||||||||||||
| 620 | 11 | ▶ | my ($slr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
latest_earleme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 621 | 11 | my ($latest_earleme) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 622 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 623 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||
| 624 | local recce = ... | ||||||||||||||||||||||||||||
| 625 | local latest_earleme = recce:latest_earleme() | ||||||||||||||||||||||||||||
| 626 | return latest_earleme | ||||||||||||||||||||||||||||
| 627 | END_OF_LUA | ||||||||||||||||||||||||||||
| 628 | 11 | return $latest_earleme; | |||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||
| 631 | sub Marpa::R3::Recognizer::earleme { | ||||||||||||||||||||||||||||
| 632 | 1 | ▶ | my ( $slr, $earley_set_id ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
earleme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 633 | 1 | my ($earleme) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 634 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 635 | <<'END_OF_LUA', 'i', $earley_set_id); | ||||||||||||||||||||||||||||
| 636 | local recce, earley_set_id = ... | ||||||||||||||||||||||||||||
| 637 | local earleme = recce:earleme(earley_set_id) | ||||||||||||||||||||||||||||
| 638 | return earleme | ||||||||||||||||||||||||||||
| 639 | END_OF_LUA | ||||||||||||||||||||||||||||
| 640 | 1 | return $earleme; | |||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||
| 643 | sub Marpa::R3::Recognizer::lexeme_alternative_literal { | ||||||||||||||||||||||||||||
| 644 | 84 | ▶ | my ( $slr, $symbol_name, $length ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lexeme_alternative_literal: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 645 | 84 | ▶ | $length //= 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$length //= 1
MC/DC100%1/1
$length //= 1
$length
Truth table100%2/2
A
A= $length
| |||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||
| 647 | 84 | ▶ | Marpa::R3::exception( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 648 | "slr->alternative_literal(): symbol name is undefined\n", | ||||||||||||||||||||||||||||
| 649 | " The symbol name cannot be undefined\n" | ||||||||||||||||||||||||||||
| 650 | ) if not defined $symbol_name; | ||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | 84 | my ($ok) = $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 653 | <<'END_OF_LUA', 'si', $symbol_name, $length); | ||||||||||||||||||||||||||||
| 654 | local slr, symbol_name, length = ... | ||||||||||||||||||||||||||||
| 655 | return slr:lexeme_alternative_literal(symbol_name, length) | ||||||||||||||||||||||||||||
| 656 | END_OF_LUA | ||||||||||||||||||||||||||||
| 657 | 84 | ▶ | return 1 if $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 658 | 0 | return; | |||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | sub Marpa::R3::Recognizer::lexeme_alternative { | ||||||||||||||||||||||||||||
| 662 | 137 | ▶ | my ( $slr, $symbol_name, $value, $length ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lexeme_alternative: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||
| 663 | 137 | ▶ | $length //= 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$length //= 1
MC/DC100%1/1
$length //= 1
$length
Truth table100%2/2
A
A= $length
| |||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | 137 | ▶ | if ( Scalar::Util::tainted( $value ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 666 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 667 | "Problem in Marpa::R3: Attempt to use a tainted token value\n", | ||||||||||||||||||||||||||||
| 668 | "Marpa::R3 is insecure for use with tainted data\n" | ||||||||||||||||||||||||||||
| 669 | ); | ||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | Marpa::R3::exception( | ||||||||||||||||||||||||||||
| 673 | 137 | ▶ | "slr->alternative(): symbol name is undefined\n", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 674 | " The symbol name cannot be undefined\n" | ||||||||||||||||||||||||||||
| 675 | ) if not defined $symbol_name; | ||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||
| 677 | 137 | my $ok; | |||||||||||||||||||||||||||
| 678 | 137 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 679 | 127 | ($ok) = $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 680 | <<'END_OF_LUA', 'sSi', $symbol_name, $value, $length ); | ||||||||||||||||||||||||||||
| 681 | local slr, symbol_name, token_sv, length = ... | ||||||||||||||||||||||||||||
| 682 | return slr:lexeme_alternative(symbol_name, token_sv, length) | ||||||||||||||||||||||||||||
| 683 | END_OF_LUA | ||||||||||||||||||||||||||||
| 684 | } else { | ||||||||||||||||||||||||||||
| 685 | 10 | ($ok) = $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 686 | <<'END_OF_LUA', 'si', $symbol_name, $length ); | ||||||||||||||||||||||||||||
| 687 | local slr, symbol_name, length = ... | ||||||||||||||||||||||||||||
| 688 | return slr:lexeme_alternative_undef(symbol_name, length ) | ||||||||||||||||||||||||||||
| 689 | END_OF_LUA | ||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||
| 692 | 135 | ▶ | return 1 if $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 693 | 0 | return; | |||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | # Returns 0 on unthrown failure, current location on success | ||||||||||||||||||||||||||||
| 697 | sub Marpa::R3::Recognizer::lexeme_complete { | ||||||||||||||||||||||||||||
| 698 | 189 | ▶ | my ( $slr, $block, $offset, $length ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lexeme_complete: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||
| 699 | 189 | ▶ | if ( $slr->[Marpa::R3::Internal_R::CURRENT_EVENT] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 700 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 701 | "$slr->lexeme_complete() called from inside a handler\n", | ||||||||||||||||||||||||||||
| 702 | " This is not allowed\n", | ||||||||||||||||||||||||||||
| 703 | " The event was ", | ||||||||||||||||||||||||||||
| 704 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT], | ||||||||||||||||||||||||||||
| 705 | "\n", | ||||||||||||||||||||||||||||
| 706 | ); | ||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||
| 709 | 189 | my $trace_file_handle = | |||||||||||||||||||||||||||
| 710 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||
| 712 | my ($return_value) = $slr->coro_by_tag( | ||||||||||||||||||||||||||||
| 713 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 714 | { | ||||||||||||||||||||||||||||
| 715 | signature => 'iii', | ||||||||||||||||||||||||||||
| 716 | args => [ $block, $offset, $length ], | ||||||||||||||||||||||||||||
| 717 | handlers => { | ||||||||||||||||||||||||||||
| 718 | trace => sub { | ||||||||||||||||||||||||||||
| 719 | 0 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 720 | 0 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||
| 721 | 0 | return 'ok'; | |||||||||||||||||||||||||||
| 722 | }, | ||||||||||||||||||||||||||||
| 723 | 189 | codepoint => gen_codepoint_event_handler($slr), | |||||||||||||||||||||||||||
| 724 | event => gen_app_event_handler($slr), | ||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||
| 726 | }, | ||||||||||||||||||||||||||||
| 727 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||
| 728 | local slr, block_id_arg, offset_arg, length_arg = ... | ||||||||||||||||||||||||||||
| 729 | local block_id, offset, eoread | ||||||||||||||||||||||||||||
| 730 | = slr:block_check_range(block_id_arg, offset_arg, length_arg) | ||||||||||||||||||||||||||||
| 731 | _M.wrap(function () | ||||||||||||||||||||||||||||
| 732 | local new_offset = slr:lexeme_complete(block_id, offset, eoread-offset) | ||||||||||||||||||||||||||||
| 733 | slr:convert_libmarpa_events() | ||||||||||||||||||||||||||||
| 734 | return 'ok', new_offset | ||||||||||||||||||||||||||||
| 735 | end | ||||||||||||||||||||||||||||
| 736 | ) | ||||||||||||||||||||||||||||
| 737 | END_OF_LUA | ||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | 189 | return $return_value; | |||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||
| 741 | } ## end sub Marpa::R3::Recognizer::lexeme_complete | ||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||
| 743 | # Returns 0 on unthrown failure, current location on success, | ||||||||||||||||||||||||||||
| 744 | # undef if lexeme not accepted. | ||||||||||||||||||||||||||||
| 745 | sub Marpa::R3::Recognizer::lexeme_read_literal { | ||||||||||||||||||||||||||||
| 746 | 116 | ▶ | my ( $slr, $symbol_name, $block_id, $offset, $length ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lexeme_read_literal: called CC=3 SCAR=14.7
| |||||||||||||||||||||||||||||
| 747 | 116 | ▶ | if ( $slr->[Marpa::R3::Internal_R::CURRENT_EVENT] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 748 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 749 | "$slr->lexeme_read_literal() called from inside a handler\n", | ||||||||||||||||||||||||||||
| 750 | " This is not allowed\n", | ||||||||||||||||||||||||||||
| 751 | " The event was ", | ||||||||||||||||||||||||||||
| 752 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT], | ||||||||||||||||||||||||||||
| 753 | "\n", | ||||||||||||||||||||||||||||
| 754 | ); | ||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||
| 756 | my ($ok, $return_value) = $slr->coro_by_tag( | ||||||||||||||||||||||||||||
| 757 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 758 | { | ||||||||||||||||||||||||||||
| 759 | signature => 'siii', | ||||||||||||||||||||||||||||
| 760 | args => [ $symbol_name, $block_id, $offset, $length ], | ||||||||||||||||||||||||||||
| 761 | handlers => { | ||||||||||||||||||||||||||||
| 762 | trace => sub { | ||||||||||||||||||||||||||||
| 763 | 0 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 764 | 0 | my $trace_file_handle = | |||||||||||||||||||||||||||
| 765 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||
| 766 | 0 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||
| 767 | 0 | return 'ok'; | |||||||||||||||||||||||||||
| 768 | }, | ||||||||||||||||||||||||||||
| 769 | 116 | codepoint => gen_codepoint_event_handler($slr), | |||||||||||||||||||||||||||
| 770 | event => gen_app_event_handler($slr), | ||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||
| 772 | }, | ||||||||||||||||||||||||||||
| 773 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||
| 774 | local slr, symbol_name, block_id, offset, length = ... | ||||||||||||||||||||||||||||
| 775 | _M.wrap(function () | ||||||||||||||||||||||||||||
| 776 | local offset = slr:lexeme_read_literal(symbol_name, block_id, offset, length ) | ||||||||||||||||||||||||||||
| 777 | if not offset then return 'ok', 0 end | ||||||||||||||||||||||||||||
| 778 | return 'ok', 1, offset | ||||||||||||||||||||||||||||
| 779 | end | ||||||||||||||||||||||||||||
| 780 | ) | ||||||||||||||||||||||||||||
| 781 | END_OF_LUA | ||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||
| 783 | 116 | ▶ | return if not $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 784 | 116 | return $return_value; | |||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||
| 787 | # Returns 0 on unthrown failure, current location on success, | ||||||||||||||||||||||||||||
| 788 | # undef if lexeme not accepted. | ||||||||||||||||||||||||||||
| 789 | sub Marpa::R3::Recognizer::lexeme_read_block { | ||||||||||||||||||||||||||||
| 790 | 243 | ▶ | my ( $slr, $symbol_name, $value, $block_id, $offset, $length ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lexeme_read_block: called CC=4 SCAR=18.5
| |||||||||||||||||||||||||||||
| 791 | 243 | ▶ | if ( $slr->[Marpa::R3::Internal_R::CURRENT_EVENT] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 792 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 793 | "$slr->lexeme_read_block() called from inside a handler\n", | ||||||||||||||||||||||||||||
| 794 | " This is not allowed\n", | ||||||||||||||||||||||||||||
| 795 | " The event was ", | ||||||||||||||||||||||||||||
| 796 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT], | ||||||||||||||||||||||||||||
| 797 | "\n", | ||||||||||||||||||||||||||||
| 798 | ); | ||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||
| 800 | 243 | ▶ | if ( Scalar::Util::tainted( $value ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 801 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 802 | "Problem in Marpa::R3: Attempt to use a tainted token value\n", | ||||||||||||||||||||||||||||
| 803 | "Marpa::R3 is insecure for use with tainted data\n" | ||||||||||||||||||||||||||||
| 804 | ); | ||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||
| 806 | my ($ok, $return_value) = $slr->coro_by_tag( | ||||||||||||||||||||||||||||
| 807 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 808 | { | ||||||||||||||||||||||||||||
| 809 | signature => 'sSiii', | ||||||||||||||||||||||||||||
| 810 | args => [ $symbol_name, $value, $block_id, $offset, $length ], | ||||||||||||||||||||||||||||
| 811 | handlers => { | ||||||||||||||||||||||||||||
| 812 | trace => sub { | ||||||||||||||||||||||||||||
| 813 | 0 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 814 | 0 | my $trace_file_handle = | |||||||||||||||||||||||||||
| 815 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||
| 816 | 0 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||
| 817 | 0 | return 'ok'; | |||||||||||||||||||||||||||
| 818 | }, | ||||||||||||||||||||||||||||
| 819 | 243 | codepoint => gen_codepoint_event_handler($slr), | |||||||||||||||||||||||||||
| 820 | event => gen_app_event_handler($slr), | ||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||
| 822 | }, | ||||||||||||||||||||||||||||
| 823 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||
| 824 | local slr, symbol_name, token_sv, block_id, offset, length = ... | ||||||||||||||||||||||||||||
| 825 | _M.wrap(function () | ||||||||||||||||||||||||||||
| 826 | local offset = slr:lexeme_read_block(symbol_name, token_sv, block_id, offset, length ) | ||||||||||||||||||||||||||||
| 827 | if not offset then return 'ok', 0 end | ||||||||||||||||||||||||||||
| 828 | return 'ok', 1, offset | ||||||||||||||||||||||||||||
| 829 | end | ||||||||||||||||||||||||||||
| 830 | ) | ||||||||||||||||||||||||||||
| 831 | END_OF_LUA | ||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||
| 833 | 243 | ▶ | return if not $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 834 | 243 | return $return_value; | |||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||
| 837 | # Returns 0 on unthrown failure, current location on success, | ||||||||||||||||||||||||||||
| 838 | # undef if lexeme not accepted. | ||||||||||||||||||||||||||||
| 839 | sub Marpa::R3::Recognizer::lexeme_read_string { | ||||||||||||||||||||||||||||
| 840 | 36 | ▶ | my ( $slr, $symbol_name, $string ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lexeme_read_string: called CC=3 SCAR=13.6
| |||||||||||||||||||||||||||||
| 841 | 36 | ▶ | if ( $slr->[Marpa::R3::Internal_R::CURRENT_EVENT] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 842 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 843 | '$recce->lexeme_read_string() called from inside a handler', "\n", | ||||||||||||||||||||||||||||
| 844 | " This is not allowed\n", | ||||||||||||||||||||||||||||
| 845 | " The event was ", | ||||||||||||||||||||||||||||
| 846 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT], | ||||||||||||||||||||||||||||
| 847 | "\n", | ||||||||||||||||||||||||||||
| 848 | ); | ||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||
| 851 | my ($ok, $return_value) = $slr->coro_by_tag( | ||||||||||||||||||||||||||||
| 852 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 853 | { | ||||||||||||||||||||||||||||
| 854 | signature => 'ss', | ||||||||||||||||||||||||||||
| 855 | args => [ $symbol_name, $string ], | ||||||||||||||||||||||||||||
| 856 | handlers => { | ||||||||||||||||||||||||||||
| 857 | trace => sub { | ||||||||||||||||||||||||||||
| 858 | 0 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 859 | 0 | my $trace_file_handle = | |||||||||||||||||||||||||||
| 860 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||
| 861 | 0 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||
| 862 | 0 | return 'ok'; | |||||||||||||||||||||||||||
| 863 | }, | ||||||||||||||||||||||||||||
| 864 | 36 | codepoint => gen_codepoint_event_handler($slr), | |||||||||||||||||||||||||||
| 865 | event => gen_app_event_handler($slr), | ||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||
| 867 | }, | ||||||||||||||||||||||||||||
| 868 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||
| 869 | local slr, symbol_name, input_string = ... | ||||||||||||||||||||||||||||
| 870 | _M.wrap(function () | ||||||||||||||||||||||||||||
| 871 | local offset = slr:lexeme_read_string(symbol_name, input_string ) | ||||||||||||||||||||||||||||
| 872 | if not offset then return 'ok', 0 end | ||||||||||||||||||||||||||||
| 873 | return 'ok', 1, offset | ||||||||||||||||||||||||||||
| 874 | end | ||||||||||||||||||||||||||||
| 875 | ) | ||||||||||||||||||||||||||||
| 876 | END_OF_LUA | ||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||
| 878 | 36 | ▶ | return if not $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 879 | 35 | return $return_value; | |||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||
| 881 | } | ||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||
| 883 | sub Marpa::R3::Recognizer::g1_to_block_first { | ||||||||||||||||||||||||||||
| 884 | 56 | ▶ | my ( $slr, $g1_pos ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
g1_to_block_first: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 885 | 56 | return $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 886 | <<'END_OF_LUA', 'i', $g1_pos ); | ||||||||||||||||||||||||||||
| 887 | local slr, g1_pos = ... | ||||||||||||||||||||||||||||
| 888 | g1_pos = math.tointeger(g1_pos) | ||||||||||||||||||||||||||||
| 889 | if not g1_pos then | ||||||||||||||||||||||||||||
| 890 | _M.userX( | ||||||||||||||||||||||||||||
| 891 | "g1_to_block_first(%s): argument must be an integer", | ||||||||||||||||||||||||||||
| 892 | g1_pos) | ||||||||||||||||||||||||||||
| 893 | end | ||||||||||||||||||||||||||||
| 894 | return slr:g1_to_block_first(g1_pos) | ||||||||||||||||||||||||||||
| 895 | END_OF_LUA | ||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||
| 898 | sub Marpa::R3::Recognizer::g1_to_block_last { | ||||||||||||||||||||||||||||
| 899 | 51 | ▶ | my ( $slr, $g1_pos ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
g1_to_block_last: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 900 | 51 | return $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 901 | <<'END_OF_LUA', 'i', $g1_pos ); | ||||||||||||||||||||||||||||
| 902 | local slr, g1_pos = ... | ||||||||||||||||||||||||||||
| 903 | g1_pos = math.tointeger(g1_pos) | ||||||||||||||||||||||||||||
| 904 | if not g1_pos then | ||||||||||||||||||||||||||||
| 905 | _M.userX( | ||||||||||||||||||||||||||||
| 906 | "g1_to_block_last(%s): argument must be an integer", | ||||||||||||||||||||||||||||
| 907 | g1_pos) | ||||||||||||||||||||||||||||
| 908 | end | ||||||||||||||||||||||||||||
| 909 | return slr:g1_to_block_last(g1_pos) | ||||||||||||||||||||||||||||
| 910 | END_OF_LUA | ||||||||||||||||||||||||||||
| 911 | } | ||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||
| 913 | # TODO -- Document this method ?? | ||||||||||||||||||||||||||||
| 914 | sub Marpa::R3::Recognizer::lc_brief { | ||||||||||||||||||||||||||||
| 915 | 36 | ▶ | my ( $slr, $first_block, $first_pos, $last_block, $last_pos ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lc_brief: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 916 | 36 | my ($desc) = $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 917 | <<'END_OF_LUA', 'iiii', $first_block, $first_pos, $last_block, $last_pos ); | ||||||||||||||||||||||||||||
| 918 | local slr, first_block, first_pos, last_block, last_pos = ... | ||||||||||||||||||||||||||||
| 919 | local function usage() | ||||||||||||||||||||||||||||
| 920 | error( | ||||||||||||||||||||||||||||
| 921 | "usage: $recce->lc_brief(first_block, first_pos, [last_block, last_pos])" | ||||||||||||||||||||||||||||
| 922 | ) | ||||||||||||||||||||||||||||
| 923 | end | ||||||||||||||||||||||||||||
| 924 | if not first_block or not first_pos then | ||||||||||||||||||||||||||||
| 925 | return usage() | ||||||||||||||||||||||||||||
| 926 | end | ||||||||||||||||||||||||||||
| 927 | if last_block == nil or last_pos == nil then | ||||||||||||||||||||||||||||
| 928 | if last_block ~= nil or last_pos ~= nil then | ||||||||||||||||||||||||||||
| 929 | return usage() | ||||||||||||||||||||||||||||
| 930 | end | ||||||||||||||||||||||||||||
| 931 | last_block = first_block | ||||||||||||||||||||||||||||
| 932 | last_pos = first_pos | ||||||||||||||||||||||||||||
| 933 | end | ||||||||||||||||||||||||||||
| 934 | return slr:lc_range_brief( | ||||||||||||||||||||||||||||
| 935 | first_block, first_pos, last_block, last_pos) | ||||||||||||||||||||||||||||
| 936 | END_OF_LUA | ||||||||||||||||||||||||||||
| 937 | 36 | return $desc; | |||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||
| 940 | sub Marpa::R3::Recognizer::line_column { | ||||||||||||||||||||||||||||
| 941 | 131 | ▶ | my ( $slr, $block, $pos, ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
line_column: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 942 | 131 | ▶ | $pos //= $slr->pos(); | ||||||||||||||||||||||||||
|
Condition33%1/3
$pos //= $slr->pos
MC/DC0%0/2
$pos //= $slr->pos
$pos
$slr->pos
Truth table33%1/3
A //= B
A= $posB= $slr->pos
| |||||||||||||||||||||||||||||
| 943 | 131 | ▶ | $block //= -1; | ||||||||||||||||||||||||||
|
Condition50%1/2
$block //= -1
MC/DC0%0/1
$block //= -1
$block
Truth table50%1/2
A
A= $block
| |||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||
| 945 | 131 | my ($line_no, $column_no) = $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 946 | <<'END_OF_LUA', 'ii', $block, $pos ); | ||||||||||||||||||||||||||||
| 947 | local slr, block, pos = ... | ||||||||||||||||||||||||||||
| 948 | if block <= 0 then block = slr.current_block.index end | ||||||||||||||||||||||||||||
| 949 | local _, line_no, column_no = slr:per_pos(block, pos) | ||||||||||||||||||||||||||||
| 950 | return line_no, column_no | ||||||||||||||||||||||||||||
| 951 | END_OF_LUA | ||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||
| 953 | 131 | return $line_no, $column_no; | |||||||||||||||||||||||||||
| 954 | } ## end sub Marpa::R3::Recognizer::line_column | ||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||
| 956 | sub Marpa::R3::Recognizer::block_new { | ||||||||||||||||||||||||||||
| 957 | 1308 | ▶ | my ( $slr, $p_string ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
block_new: called CC=5 SCAR=17.6
| |||||||||||||||||||||||||||||
| 958 | 1308 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||
| 960 | Marpa::R3::exception( | ||||||||||||||||||||||||||||
| 961 | q{Attempt to use a tainted input string in $slr->read()}, | ||||||||||||||||||||||||||||
| 962 | qq{\n Marpa::R3 is insecure for use with tainted data\n} | ||||||||||||||||||||||||||||
| 963 | 1308 | ▶ | ) if Scalar::Util::tainted( ${$p_string} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||
| 965 | 1307 | ▶ | if ( ( my $ref_type = ref $p_string ) ne 'SCALAR' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 966 | 0 | ▶ | my $desc = $ref_type ? "a ref to $ref_type" : 'not a ref'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 967 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 968 | qq{Arg to Marpa::R3::Recognizer::read() is $desc\n}, | ||||||||||||||||||||||||||||
| 969 | ' It should be a ref to scalar' ); | ||||||||||||||||||||||||||||
| 970 | } ## end if ( ( my $ref_type = ref $p_string ) ne 'SCALAR' ) | ||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||
| 972 | 1307 | ▶ | if ( not defined ${$p_string} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 973 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 974 | qq{Arg to Marpa::R3::Recognizer::read() is a ref to an undef\n}, | ||||||||||||||||||||||||||||
| 975 | ' It should be a ref to a defined scalar' ); | ||||||||||||||||||||||||||||
| 976 | } ## end if ( ( my $ref_type = ref $p_string ) ne 'SCALAR' ) | ||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||
| 978 | 1307 | my $character_class_table = | |||||||||||||||||||||||||||
| 979 | $slg->[Marpa::R3::Internal_G::CHARACTER_CLASS_TABLE]; | ||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||
| 981 | my ($block_id) = $slr->coro_by_tag( | ||||||||||||||||||||||||||||
| 982 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 983 | { | ||||||||||||||||||||||||||||
| 984 | signature => 's', | ||||||||||||||||||||||||||||
| 985 | 1307 | args => [ ${$p_string} ], | |||||||||||||||||||||||||||
| 986 | handlers => { | ||||||||||||||||||||||||||||
| 987 | codepoint => gen_codepoint_event_handler($slr), | ||||||||||||||||||||||||||||
| 988 | event => gen_app_event_handler($slr), | ||||||||||||||||||||||||||||
| 989 | }, | ||||||||||||||||||||||||||||
| 990 | }, | ||||||||||||||||||||||||||||
| 991 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||
| 992 | local slr, input_string = ... | ||||||||||||||||||||||||||||
| 993 | local new_block_id | ||||||||||||||||||||||||||||
| 994 | _M.wrap(function() | ||||||||||||||||||||||||||||
| 995 | new_block_id = slr:block_new(input_string) | ||||||||||||||||||||||||||||
| 996 | return 'ok', new_block_id | ||||||||||||||||||||||||||||
| 997 | end | ||||||||||||||||||||||||||||
| 998 | ) | ||||||||||||||||||||||||||||
| 999 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||
| 1001 | 1307 | return $block_id; | |||||||||||||||||||||||||||
| 1002 | } | ||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||
| 1004 | sub Marpa::R3::Recognizer::block_progress { | ||||||||||||||||||||||||||||
| 1005 | 648 | ▶ | my ($slr, $block_id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
block_progress: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1006 | 648 | my ($l0_pos, $l0_end); | |||||||||||||||||||||||||||
| 1007 | 648 | ($block_id, $l0_pos, $l0_end) | |||||||||||||||||||||||||||
| 1008 | = $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 1009 | <<'END_OF_LUA', 'i', $block_id ); | ||||||||||||||||||||||||||||
| 1010 | local slr, block_id_arg = ... | ||||||||||||||||||||||||||||
| 1011 | local block_id, erreur = slr:block_check_id(block_id_arg) | ||||||||||||||||||||||||||||
| 1012 | if not block_id then | ||||||||||||||||||||||||||||
| 1013 | error(erreur) | ||||||||||||||||||||||||||||
| 1014 | end | ||||||||||||||||||||||||||||
| 1015 | local l0_pos, l0_end | ||||||||||||||||||||||||||||
| 1016 | block_id, l0_pos, l0_end = slr:block_progress(block_id) | ||||||||||||||||||||||||||||
| 1017 | return block_id, l0_pos, l0_end | ||||||||||||||||||||||||||||
| 1018 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1019 | 648 | return $block_id, $l0_pos, $l0_end; | |||||||||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||
| 1022 | sub Marpa::R3::Recognizer::block_set { | ||||||||||||||||||||||||||||
| 1023 | 1352 | ▶ | my ($slr, $block_id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
block_set: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||
| 1024 | 1352 | ▶ | if ( $slr->[Marpa::R3::Internal_R::CURRENT_EVENT] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1025 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||
| 1026 | "$slr->block_set() called from inside a handler\n", | ||||||||||||||||||||||||||||
| 1027 | " This is not allowed\n", | ||||||||||||||||||||||||||||
| 1028 | " The event was ", | ||||||||||||||||||||||||||||
| 1029 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT], | ||||||||||||||||||||||||||||
| 1030 | "\n", | ||||||||||||||||||||||||||||
| 1031 | ); | ||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||
| 1033 | 1352 | $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 1034 | <<'END_OF_LUA', 'i', $block_id ); | ||||||||||||||||||||||||||||
| 1035 | local slr, block_id_arg = ... | ||||||||||||||||||||||||||||
| 1036 | local block_id, erreur = slr:block_check_id(block_id_arg) | ||||||||||||||||||||||||||||
| 1037 | if not block_id then | ||||||||||||||||||||||||||||
| 1038 | error(erreur) | ||||||||||||||||||||||||||||
| 1039 | end | ||||||||||||||||||||||||||||
| 1040 | return slr:block_set(block_id) | ||||||||||||||||||||||||||||
| 1041 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1042 | 1352 | return; | |||||||||||||||||||||||||||
| 1043 | } | ||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||
| 1045 | # block_id defaults to current block | ||||||||||||||||||||||||||||
| 1046 | # block_offset defaults to don't set offset | ||||||||||||||||||||||||||||
| 1047 | # length defaults to don't set eoread | ||||||||||||||||||||||||||||
| 1048 | sub Marpa::R3::Recognizer::block_move { | ||||||||||||||||||||||||||||
| 1049 | 2153 | ▶ | my ($slr, $offset, $length) = @_; | ||||||||||||||||||||||||||
|
Subroutine
block_move: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1050 | 2153 | $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 1051 | <<'END_OF_LUA', 'ii', $offset, $length ); | ||||||||||||||||||||||||||||
| 1052 | local slr, offset_arg, length_arg = ... | ||||||||||||||||||||||||||||
| 1053 | local ok, offset, eoread | ||||||||||||||||||||||||||||
| 1054 | = slr:block_check_range(nil, offset_arg, length_arg) | ||||||||||||||||||||||||||||
| 1055 | if not ok then | ||||||||||||||||||||||||||||
| 1056 | -- new_block_offset is error message | ||||||||||||||||||||||||||||
| 1057 | error(offset) | ||||||||||||||||||||||||||||
| 1058 | end | ||||||||||||||||||||||||||||
| 1059 | -- we don't set offset if the arg was nil | ||||||||||||||||||||||||||||
| 1060 | local new_offset = offset_arg and offset or nil | ||||||||||||||||||||||||||||
| 1061 | -- we don't set eoread if the length arg was nil | ||||||||||||||||||||||||||||
| 1062 | local new_eoread = length_arg and eoread or nil | ||||||||||||||||||||||||||||
| 1063 | return slr:block_move(new_offset, new_eoread) | ||||||||||||||||||||||||||||
| 1064 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1065 | 2153 | return; | |||||||||||||||||||||||||||
| 1066 | } | ||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||
| 1068 | sub Marpa::R3::Recognizer::block_read { | ||||||||||||||||||||||||||||
| 1069 | 1812 | ▶ | my ($slr ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
block_read: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1070 | my ($offset) = $slr->coro_by_tag( | ||||||||||||||||||||||||||||
| 1071 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||
| 1072 | { | ||||||||||||||||||||||||||||
| 1073 | signature => '', | ||||||||||||||||||||||||||||
| 1074 | args => [], | ||||||||||||||||||||||||||||
| 1075 | handlers => { | ||||||||||||||||||||||||||||
| 1076 | trace => sub { | ||||||||||||||||||||||||||||
| 1077 | 314 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1078 | 314 | my $trace_file_handle = | |||||||||||||||||||||||||||
| 1079 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||
| 1080 | 314 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||
| 1081 | 314 | return 'ok'; | |||||||||||||||||||||||||||
| 1082 | }, | ||||||||||||||||||||||||||||
| 1083 | 1812 | event => gen_app_event_handler($slr), | |||||||||||||||||||||||||||
| 1084 | } | ||||||||||||||||||||||||||||
| 1085 | }, | ||||||||||||||||||||||||||||
| 1086 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||
| 1087 | local slr = ... | ||||||||||||||||||||||||||||
| 1088 | _M.wrap(function () | ||||||||||||||||||||||||||||
| 1089 | local offset = slr:block_read() | ||||||||||||||||||||||||||||
| 1090 | return 'ok', offset | ||||||||||||||||||||||||||||
| 1091 | end | ||||||||||||||||||||||||||||
| 1092 | ) | ||||||||||||||||||||||||||||
| 1093 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1094 | 1803 | return $offset; | |||||||||||||||||||||||||||
| 1095 | } | ||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||
| 1097 | sub Marpa::R3::Recognizer::input_length { | ||||||||||||||||||||||||||||
| 1098 | 2 | ▶ | my ( $slr, $block_id ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
input_length: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 1099 | 2 | ▶ | my ($length) = $slr->call_by_tag( | ||||||||||||||||||||||||||
|
Condition100%2/2
$block_id // -1
MC/DC100%1/1
$block_id // -1
$block_id
Truth table100%2/2
A
A= $block_id
| |||||||||||||||||||||||||||||
| 1100 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 1101 | <<'END_OF_LUA', 'i', ($block_id // -1)); | ||||||||||||||||||||||||||||
| 1102 | local slr, block_id = ... | ||||||||||||||||||||||||||||
| 1103 | local block = block_id > 0 and slr.inputs[block_id] or slr.current_block | ||||||||||||||||||||||||||||
| 1104 | return #block | ||||||||||||||||||||||||||||
| 1105 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||
| 1107 | 2 | return $length; | |||||||||||||||||||||||||||
| 1108 | } | ||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||
| 1110 | # no return value documented | ||||||||||||||||||||||||||||
| 1111 | sub Marpa::R3::Recognizer::activate { | ||||||||||||||||||||||||||||
| 1112 | 536 | ▶ | my ( $slr, $event_name, $activate ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
activate: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1113 | 536 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||
| 1115 | 536 | $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 1116 | <<'END_OF_LUA', 'si', $event_name, $activate); | ||||||||||||||||||||||||||||
| 1117 | local slr, event_name, activate = ... | ||||||||||||||||||||||||||||
| 1118 | if not activate then | ||||||||||||||||||||||||||||
| 1119 | activate = 1 | ||||||||||||||||||||||||||||
| 1120 | else | ||||||||||||||||||||||||||||
| 1121 | activate = activate ~= 0 | ||||||||||||||||||||||||||||
| 1122 | end | ||||||||||||||||||||||||||||
| 1123 | -- print('$slr->activate():', event_name, activate) | ||||||||||||||||||||||||||||
| 1124 | return slr:activate_by_event_name(event_name, activate) | ||||||||||||||||||||||||||||
| 1125 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1126 | 536 | return; | |||||||||||||||||||||||||||
| 1127 | } | ||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||
| 1129 | # On success, returns the old priority value. | ||||||||||||||||||||||||||||
| 1130 | # Failures are thrown. | ||||||||||||||||||||||||||||
| 1131 | sub Marpa::R3::Recognizer::lexeme_priority_set { | ||||||||||||||||||||||||||||
| 1132 | 12 | ▶ | my ( $slr, $lexeme_name, $new_priority ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lexeme_priority_set: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1133 | 12 | my ($old_priority) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 1134 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 1135 | <<'END_OF_LUA', 'si>*', $lexeme_name, $new_priority ); | ||||||||||||||||||||||||||||
| 1136 | local recce, lexeme_name, new_priority = ... | ||||||||||||||||||||||||||||
| 1137 | local slg = recce.slg | ||||||||||||||||||||||||||||
| 1138 | local g1g = slg.g1 | ||||||||||||||||||||||||||||
| 1139 | local lexeme_id = g1g.isyid_by_name[lexeme_name] | ||||||||||||||||||||||||||||
| 1140 | if not lexeme_id then | ||||||||||||||||||||||||||||
| 1141 | _M.userX( | ||||||||||||||||||||||||||||
| 1142 | "lexeme_priority_set(): no such symbol as %q", | ||||||||||||||||||||||||||||
| 1143 | lexeme_name | ||||||||||||||||||||||||||||
| 1144 | ) | ||||||||||||||||||||||||||||
| 1145 | end | ||||||||||||||||||||||||||||
| 1146 | if type(new_priority) ~= 'number' then | ||||||||||||||||||||||||||||
| 1147 | _M.userX( | ||||||||||||||||||||||||||||
| 1148 | "lexeme_priority_set(): priority is not a number, it is %s", | ||||||||||||||||||||||||||||
| 1149 | new_priority | ||||||||||||||||||||||||||||
| 1150 | ) | ||||||||||||||||||||||||||||
| 1151 | end | ||||||||||||||||||||||||||||
| 1152 | local g_lexeme_data = slg.g1.isys[lexeme_id] | ||||||||||||||||||||||||||||
| 1153 | local r_lexeme_data = recce.g1_isys[lexeme_id] | ||||||||||||||||||||||||||||
| 1154 | if not g_lexeme_data.lexeme then | ||||||||||||||||||||||||||||
| 1155 | print(inspect(lexeme_data)) | ||||||||||||||||||||||||||||
| 1156 | _M.userX( | ||||||||||||||||||||||||||||
| 1157 | "lexeme_priority_set(): %q is not a lexeme", | ||||||||||||||||||||||||||||
| 1158 | lexeme_name | ||||||||||||||||||||||||||||
| 1159 | ) | ||||||||||||||||||||||||||||
| 1160 | end | ||||||||||||||||||||||||||||
| 1161 | local old_priority = r_lexeme_data.lexeme_priority | ||||||||||||||||||||||||||||
| 1162 | r_lexeme_data.lexeme_priority = new_priority | ||||||||||||||||||||||||||||
| 1163 | return old_priority | ||||||||||||||||||||||||||||
| 1164 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||
| 1166 | 12 | return $old_priority; | |||||||||||||||||||||||||||
| 1167 | } | ||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||
| 1169 | # Internal methods, not to be documented | ||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||
| 1171 | # not to be documented | ||||||||||||||||||||||||||||
| 1172 | sub Marpa::R3::Recognizer::call_by_tag { | ||||||||||||||||||||||||||||
| 1173 | 8825 | ▶ | my ( $slr, $tag, $codestr, $signature, @args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
call_by_tag: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 1174 | 8825 | my $lua = $slr->[Marpa::R3::Internal_R::L]; | |||||||||||||||||||||||||||
| 1175 | 8825 | my $regix = $slr->[Marpa::R3::Internal_R::REGIX]; | |||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||
| 1177 | 8825 | ▶ | $DB::single = 1 if not $slr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1178 | 8825 | ▶ | $DB::single = 1 if not $regix; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1179 | # $DB::single = 1 if grep { not defined $_ } @args; | ||||||||||||||||||||||||||||
| 1180 | 8825 | my @results; | |||||||||||||||||||||||||||
| 1181 | my $eval_error; | ||||||||||||||||||||||||||||
| 1182 | 8825 | my $eval_ok; | |||||||||||||||||||||||||||
| 1183 | { | ||||||||||||||||||||||||||||
| 1184 | 8825 | local $@; | |||||||||||||||||||||||||||
| 1185 | 8825 | $eval_ok = eval { | |||||||||||||||||||||||||||
| 1186 | 8825 | @results = | |||||||||||||||||||||||||||
| 1187 | $lua->call_by_tag( $regix, $tag, $codestr, $signature, @args ); | ||||||||||||||||||||||||||||
| 1188 | 8823 | return 1; | |||||||||||||||||||||||||||
| 1189 | }; | ||||||||||||||||||||||||||||
| 1190 | 8825 | $eval_error = $@; | |||||||||||||||||||||||||||
| 1191 | } | ||||||||||||||||||||||||||||
| 1192 | 8825 | ▶ | if ( not $eval_ok ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1193 | 2 | Marpa::R3::exception($eval_error); | |||||||||||||||||||||||||||
| 1194 | } | ||||||||||||||||||||||||||||
| 1195 | 8823 | return @results; | |||||||||||||||||||||||||||
| 1196 | } | ||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||
| 1198 | # not to be documented | ||||||||||||||||||||||||||||
| 1199 | sub Marpa::R3::Recognizer::coro_by_tag { | ||||||||||||||||||||||||||||
| 1200 | 6116 | ▶ | my ( $slr, $tag, $args, $codestr ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
coro_by_tag: called CC=13 SCAR=28.0
| |||||||||||||||||||||||||||||
| 1201 | 6116 | my $lua = $slr->[Marpa::R3::Internal_R::L]; | |||||||||||||||||||||||||||
| 1202 | 6116 | my $regix = $slr->[Marpa::R3::Internal_R::REGIX]; | |||||||||||||||||||||||||||
| 1203 | 6116 | ▶ | 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"}
| |||||||||||||||||||||||||||||
| 1204 | 6116 | my $resume_tag = $tag . '[R]'; | |||||||||||||||||||||||||||
| 1205 | 6116 | ▶ | 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"}
| |||||||||||||||||||||||||||||
| 1206 | 6116 | ▶ | 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"}
| |||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||
| 1208 | 6116 | my @results; | |||||||||||||||||||||||||||
| 1209 | my $eval_error; | ||||||||||||||||||||||||||||
| 1210 | 6116 | my $eval_ok; | |||||||||||||||||||||||||||
| 1211 | { | ||||||||||||||||||||||||||||
| 1212 | 6116 | local $@; | |||||||||||||||||||||||||||
| 1213 | 6116 | $eval_ok = eval { | |||||||||||||||||||||||||||
| 1214 | 6116 | $lua->call_by_tag( $regix, $tag, $codestr, $signature, @{$p_args} ); | |||||||||||||||||||||||||||
| 1215 | 6116 | my @resume_args = (''); | |||||||||||||||||||||||||||
| 1216 | 6116 | my $signature = 's'; | |||||||||||||||||||||||||||
| 1217 | 6116 | CORO_CALL: while (1) { | |||||||||||||||||||||||||||
| 1218 | 13306 | my ( $cmd, $yield_data ) = | |||||||||||||||||||||||||||
| 1219 | $lua->call_by_tag( $regix, $resume_tag, | ||||||||||||||||||||||||||||
| 1220 | 'local slr, resume_arg = ...; return _M.resume(resume_arg)', | ||||||||||||||||||||||||||||
| 1221 | $signature, @resume_args ) ; | ||||||||||||||||||||||||||||
| 1222 | 13297 | ▶ | if (not $cmd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1223 | 6107 | @results = @{$yield_data}; | |||||||||||||||||||||||||||
| 1224 | 6107 | return 1; | |||||||||||||||||||||||||||
| 1225 | } | ||||||||||||||||||||||||||||
| 1226 | 7190 | my $handler = $handler->{$cmd}; | |||||||||||||||||||||||||||
| 1227 | 7190 | ▶ | Marpa::R3::exception(qq{No coro handler for "$cmd"}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1228 | if not $handler; | ||||||||||||||||||||||||||||
| 1229 | 7190 | ▶ | $yield_data //= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$yield_data //= []
MC/DC0%0/1
$yield_data //= []
$yield_data
Truth table50%1/2
A
A= $yield_data
| |||||||||||||||||||||||||||||
| 1230 | 7190 | my ($handler_cmd, $new_resume_args) = $handler->(@{$yield_data}); | |||||||||||||||||||||||||||
| 1231 | 7190 | ▶ | Marpa::R3::exception(qq{Undefined return command from handler for "$cmd"}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1232 | if not defined $handler_cmd; | ||||||||||||||||||||||||||||
| 1233 | 7190 | ▶ | if ($handler_cmd eq 'ok') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1234 | 7190 | $signature = 's'; | |||||||||||||||||||||||||||
| 1235 | 7190 | @resume_args = ($new_resume_args); | |||||||||||||||||||||||||||
| 1236 | 7190 | ▶ | if (scalar @resume_args < 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1237 | 0 | @resume_args = (''); | |||||||||||||||||||||||||||
| 1238 | } | ||||||||||||||||||||||||||||
| 1239 | 7190 | next CORO_CALL; | |||||||||||||||||||||||||||
| 1240 | } | ||||||||||||||||||||||||||||
| 1241 | 0 | ▶ | if ($handler_cmd eq 'sig') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1242 | 0 | @resume_args = @{$new_resume_args}; | |||||||||||||||||||||||||||
| 1243 | 0 | $signature = shift @resume_args; | |||||||||||||||||||||||||||
| 1244 | 0 | next CORO_CALL; | |||||||||||||||||||||||||||
| 1245 | } | ||||||||||||||||||||||||||||
| 1246 | 0 | Marpa::R3::exception(qq{Bad return command ("$handler_cmd") from handler for "$cmd"}) | |||||||||||||||||||||||||||
| 1247 | } | ||||||||||||||||||||||||||||
| 1248 | 0 | return 1; | |||||||||||||||||||||||||||
| 1249 | }; | ||||||||||||||||||||||||||||
| 1250 | 6116 | $eval_error = $@; | |||||||||||||||||||||||||||
| 1251 | } | ||||||||||||||||||||||||||||
| 1252 | 6116 | ▶ | if ( not $eval_ok ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1253 | # if it's an object, just die | ||||||||||||||||||||||||||||
| 1254 | 9 | ▶ | die $eval_error if ref $eval_error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1255 | 9 | Marpa::R3::exception($eval_error); | |||||||||||||||||||||||||||
| 1256 | } | ||||||||||||||||||||||||||||
| 1257 | 6107 | return @results; | |||||||||||||||||||||||||||
| 1258 | } | ||||||||||||||||||||||||||||
| 1259 | |||||||||||||||||||||||||||||
| 1260 | # not to be documented | ||||||||||||||||||||||||||||
| 1261 | sub Marpa::R3::Recognizer::earley_set_size { | ||||||||||||||||||||||||||||
| 1262 | 78 | ▶ | my ($slr, $set_id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
earley_set_size: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 1263 | 78 | ▶ | my ($size) = $slr->call_by_tag( | ||||||||||||||||||||||||||
|
Condition50%1/2
$set_id // -1
MC/DC0%0/1
$set_id // -1
$set_id
Truth table50%1/2
A
A= $set_id
| |||||||||||||||||||||||||||||
| 1264 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 1265 | <<'END_OF_LUA', 'i', ($set_id // -1)); | ||||||||||||||||||||||||||||
| 1266 | local recce, set_id = ... | ||||||||||||||||||||||||||||
| 1267 | local g1r = recce.g1 | ||||||||||||||||||||||||||||
| 1268 | if set_id < 0 then set_id = g1r:latest_earley_set() end | ||||||||||||||||||||||||||||
| 1269 | return g1r:_earley_set_size(set_id) | ||||||||||||||||||||||||||||
| 1270 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1271 | 78 | return $size; | |||||||||||||||||||||||||||
| 1272 | } | ||||||||||||||||||||||||||||
| 1273 | |||||||||||||||||||||||||||||
| 1274 | # not to be documented | ||||||||||||||||||||||||||||
| 1275 | sub Marpa::R3::Recognizer::earley_sets_show { | ||||||||||||||||||||||||||||
| 1276 | 8 | ▶ | my ($slr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
earley_sets_show: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 1277 | |||||||||||||||||||||||||||||
| 1278 | 8 | my ($last_completed_earleme, $furthest_earleme) = $slr->call_by_tag( | |||||||||||||||||||||||||||
| 1279 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 1280 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||
| 1281 | local recce = ... | ||||||||||||||||||||||||||||
| 1282 | local g1r = recce.g1 | ||||||||||||||||||||||||||||
| 1283 | return g1r:current_earleme(), g1r:furthest_earleme() | ||||||||||||||||||||||||||||
| 1284 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1285 | |||||||||||||||||||||||||||||
| 1286 | 8 | my $text = "Last Completed: $last_completed_earleme; " | |||||||||||||||||||||||||||
| 1287 | . "Furthest: $furthest_earleme\n"; | ||||||||||||||||||||||||||||
| 1288 | 8 | LIST: for ( my $ix = 0;; $ix++ ) { | |||||||||||||||||||||||||||
| 1289 | 67 | my $set_desc = | |||||||||||||||||||||||||||
| 1290 | $slr->Marpa::R3::Recognizer::earley_set_show( $ix ); | ||||||||||||||||||||||||||||
| 1291 | 67 | ▶ | last LIST if not $set_desc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1292 | 59 | $text .= "Earley Set $ix\n$set_desc"; | |||||||||||||||||||||||||||
| 1293 | } | ||||||||||||||||||||||||||||
| 1294 | 8 | return $text; | |||||||||||||||||||||||||||
| 1295 | } | ||||||||||||||||||||||||||||
| 1296 | |||||||||||||||||||||||||||||
| 1297 | # not to be documented | ||||||||||||||||||||||||||||
| 1298 | sub Marpa::R3::Recognizer::earley_set_show { | ||||||||||||||||||||||||||||
| 1299 | 67 | ▶ | my ( $slr, $traced_set_id ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
earley_set_show: called CC=19 SCAR=29.7
| |||||||||||||||||||||||||||||
| 1300 | 67 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||
| 1301 | |||||||||||||||||||||||||||||
| 1302 | 67 | my ($set_data) = | |||||||||||||||||||||||||||
| 1303 | $slr->call_by_tag( | ||||||||||||||||||||||||||||
| 1304 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||
| 1305 | <<'END_OF_LUA', 'i>2', $traced_set_id ); | ||||||||||||||||||||||||||||
| 1306 | local recce, traced_set_id = ... | ||||||||||||||||||||||||||||
| 1307 | return recce:g1_earley_set_data(traced_set_id) | ||||||||||||||||||||||||||||
| 1308 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1309 | |||||||||||||||||||||||||||||
| 1310 | 67 | ▶ | return if not $set_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1311 | 59 | my %set_data = @{$set_data}; | |||||||||||||||||||||||||||
| 1312 | |||||||||||||||||||||||||||||
| 1313 | 59 | my $current_earleme = $set_data{earleme}; | |||||||||||||||||||||||||||
| 1314 | |||||||||||||||||||||||||||||
| 1315 | 59 | my @sorted_data = (); | |||||||||||||||||||||||||||
| 1316 | |||||||||||||||||||||||||||||
| 1317 | 59 | EARLEY_ITEM: for ( my $item_id = 0 ; ; $item_id++ ) { | |||||||||||||||||||||||||||
| 1318 | |||||||||||||||||||||||||||||
| 1319 | 511 | my $item_data = $set_data{ $item_id + 1 }; | |||||||||||||||||||||||||||
| 1320 | 511 | ▶ | last EARLEY_ITEM if not defined $item_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||
| 1322 | 452 | my %item_data = @{$item_data}; | |||||||||||||||||||||||||||
| 1323 | |||||||||||||||||||||||||||||
| 1324 | 452 | my $nrl_id = $item_data{nrl_id}; | |||||||||||||||||||||||||||
| 1325 | 452 | my $dot_position = $item_data{dot_position}; | |||||||||||||||||||||||||||
| 1326 | 452 | my $ahm_desc; | |||||||||||||||||||||||||||
| 1327 | 452 | ▶ | if ( $dot_position < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1328 | 177 | $ahm_desc = sprintf( 'R%d$', $nrl_id ); | |||||||||||||||||||||||||||
| 1329 | } | ||||||||||||||||||||||||||||
| 1330 | else { | ||||||||||||||||||||||||||||
| 1331 | 275 | $ahm_desc = sprintf( 'R%d:%d', $nrl_id, $dot_position ); | |||||||||||||||||||||||||||
| 1332 | } | ||||||||||||||||||||||||||||
| 1333 | 452 | my $ahm_id_of_yim = $item_data{ahm_id_of_yim}; | |||||||||||||||||||||||||||
| 1334 | 452 | my $origin_earleme = $item_data{origin_earleme}; | |||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||
| 1336 | 452 | my $text .= sprintf "ahm%d: %s@%d-%d", $ahm_id_of_yim, | |||||||||||||||||||||||||||
| 1337 | $ahm_desc, | ||||||||||||||||||||||||||||
| 1338 | $origin_earleme, $current_earleme; | ||||||||||||||||||||||||||||
| 1339 | |||||||||||||||||||||||||||||
| 1340 | 452 | my @lines = $text; | |||||||||||||||||||||||||||
| 1341 | 452 | push @lines, | |||||||||||||||||||||||||||
| 1342 | qq{ } | ||||||||||||||||||||||||||||
| 1343 | . $ahm_desc . q{: } | ||||||||||||||||||||||||||||
| 1344 | . $slg->dotted_nrl_show( $nrl_id, $dot_position ); | ||||||||||||||||||||||||||||
| 1345 | |||||||||||||||||||||||||||||
| 1346 | 452 | push @sorted_data, @lines; | |||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||
| 1348 | # Token links | ||||||||||||||||||||||||||||
| 1349 | { | ||||||||||||||||||||||||||||
| 1350 | 452 | my @sort_data = (); | |||||||||||||||||||||||||||
| 1351 | 452 | my @lines = (); | |||||||||||||||||||||||||||
| 1352 | 452 | my $token_links = $item_data{token_links}; | |||||||||||||||||||||||||||
| 1353 | 452 | my %token_links = @{$token_links}; | |||||||||||||||||||||||||||
| 1354 | 452 | TOKEN_LINK: for ( my $token_link_ix = 0 ; ; $token_link_ix++ ) { | |||||||||||||||||||||||||||
| 1355 | 519 | my $token_link_data = $token_links{ $token_link_ix + 1 }; | |||||||||||||||||||||||||||
| 1356 | 519 | ▶ | last TOKEN_LINK if not $token_link_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1357 | 67 | my %token_link_data = @{$token_link_data}; | |||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||
| 1359 | 67 | my $predecessor_ahm = $token_link_data{predecessor_ahm}; | |||||||||||||||||||||||||||
| 1360 | 67 | my $origin_earleme = $token_link_data{origin_earleme}; | |||||||||||||||||||||||||||
| 1361 | 67 | my $middle_earleme = $token_link_data{middle_earleme}; | |||||||||||||||||||||||||||
| 1362 | 67 | my $middle_set_id = $token_link_data{middle_set_id}; | |||||||||||||||||||||||||||
| 1363 | 67 | my $token_name = $token_link_data{token_name}; | |||||||||||||||||||||||||||
| 1364 | 67 | my $token_id = $token_link_data{token_id}; | |||||||||||||||||||||||||||
| 1365 | 67 | my $value_ix = $token_link_data{value_ix}; | |||||||||||||||||||||||||||
| 1366 | 67 | my $value = $token_link_data{value}; | |||||||||||||||||||||||||||
| 1367 | my $source_predecessor_state = | ||||||||||||||||||||||||||||
| 1368 | 67 | $token_link_data{source_predecessor_state}; | |||||||||||||||||||||||||||
| 1369 | |||||||||||||||||||||||||||||
| 1370 | 67 | my @pieces = (); | |||||||||||||||||||||||||||
| 1371 | 67 | ▶ | if ( defined $predecessor_ahm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1372 | 67 | my $ahm_desc = $slg->briefer_ahm($predecessor_ahm); | |||||||||||||||||||||||||||
| 1373 | 67 | push @pieces, | |||||||||||||||||||||||||||
| 1374 | 'c=' | ||||||||||||||||||||||||||||
| 1375 | . $ahm_desc . q{@} | ||||||||||||||||||||||||||||
| 1376 | . $origin_earleme . q{-} | ||||||||||||||||||||||||||||
| 1377 | . $middle_earleme; | ||||||||||||||||||||||||||||
| 1378 | } ## end if ( defined $predecessor_ahm ) | ||||||||||||||||||||||||||||
| 1379 | |||||||||||||||||||||||||||||
| 1380 | 67 | push @pieces, 's=' . $token_name; | |||||||||||||||||||||||||||
| 1381 | |||||||||||||||||||||||||||||
| 1382 | 67 | ▶ | if ( not defined $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1383 | |||||||||||||||||||||||||||||
| 1384 | # Value is literal | ||||||||||||||||||||||||||||
| 1385 | 67 | my $token_length = $current_earleme - $middle_earleme; | |||||||||||||||||||||||||||
| 1386 | 67 | $value = $slr->g1_literal( $middle_earleme, $token_length ); | |||||||||||||||||||||||||||
| 1387 | } | ||||||||||||||||||||||||||||
| 1388 | 67 | my $token_dump = | |||||||||||||||||||||||||||
| 1389 | Data::Dumper->new( [ \$value ] )->Terse(1)->Dump; | ||||||||||||||||||||||||||||
| 1390 | 67 | chomp $token_dump; | |||||||||||||||||||||||||||
| 1391 | 67 | push @pieces, "t=$token_dump"; | |||||||||||||||||||||||||||
| 1392 | 67 | my $token_link_desc = '[' . ( join '; ', @pieces ) . ']'; | |||||||||||||||||||||||||||
| 1393 | 67 | push @sort_data, | |||||||||||||||||||||||||||
| 1394 | [ | ||||||||||||||||||||||||||||
| 1395 | $middle_set_id, $token_id, | ||||||||||||||||||||||||||||
| 1396 | $predecessor_ahm, $token_link_desc | ||||||||||||||||||||||||||||
| 1397 | ]; | ||||||||||||||||||||||||||||
| 1398 | } | ||||||||||||||||||||||||||||
| 1399 | 67 | push @sorted_data, map { qq{ } . $_->[-1] } sort { | |||||||||||||||||||||||||||
| 1400 | 452 | ▶ | $a->[0] <=> $b->[0] | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] or $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
MC/DC0%0/2
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] or $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0]
$Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
Truth table0%0/3
A or B
A= $Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0]B= $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
| |||||||||||||||||||||||||||||
| 1401 | || $a->[1] <=> $b->[1] | ||||||||||||||||||||||||||||
| 1402 | || $a->[2] <=> $b->[2] | ||||||||||||||||||||||||||||
| 1403 | } @sort_data; | ||||||||||||||||||||||||||||
| 1404 | } | ||||||||||||||||||||||||||||
| 1405 | |||||||||||||||||||||||||||||
| 1406 | # Completion links | ||||||||||||||||||||||||||||
| 1407 | { | ||||||||||||||||||||||||||||
| 1408 | 452 | my @sort_data = (); | |||||||||||||||||||||||||||
| 1409 | 452 | my @lines = (); | |||||||||||||||||||||||||||
| 1410 | 452 | my $completion_links = $item_data{completion_links}; | |||||||||||||||||||||||||||
| 1411 | 452 | my %completion_links = @{$completion_links}; | |||||||||||||||||||||||||||
| 1412 | TOKEN_LINK: | ||||||||||||||||||||||||||||
| 1413 | 452 | for ( my $completion_link_ix = 0 ; ; $completion_link_ix++ ) { | |||||||||||||||||||||||||||
| 1414 | my $completion_link_data = | ||||||||||||||||||||||||||||
| 1415 | 689 | $completion_links{ $completion_link_ix + 1 }; | |||||||||||||||||||||||||||
| 1416 | 689 | ▶ | last TOKEN_LINK if not $completion_link_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1417 | 237 | my %completion_link_data = @{$completion_link_data}; | |||||||||||||||||||||||||||
| 1418 | |||||||||||||||||||||||||||||
| 1419 | my $predecessor_ahm_id = | ||||||||||||||||||||||||||||
| 1420 | 237 | $completion_link_data{predecessor_state}; | |||||||||||||||||||||||||||
| 1421 | 237 | my $ahm_id = $completion_link_data{ahm_id}; | |||||||||||||||||||||||||||
| 1422 | 237 | my $origin_earleme = $completion_link_data{origin_earleme}; | |||||||||||||||||||||||||||
| 1423 | 237 | my $middle_earleme = $completion_link_data{middle_earleme}; | |||||||||||||||||||||||||||
| 1424 | 237 | my $ahm_desc = $slg->briefer_ahm($ahm_id); | |||||||||||||||||||||||||||
| 1425 | |||||||||||||||||||||||||||||
| 1426 | 237 | my @pieces = (); | |||||||||||||||||||||||||||
| 1427 | 237 | ▶ | if ( defined $predecessor_ahm_id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1428 | 237 | my $predecessor_ahm_desc = | |||||||||||||||||||||||||||
| 1429 | $slg->briefer_ahm($predecessor_ahm_id); | ||||||||||||||||||||||||||||
| 1430 | 237 | push @pieces, | |||||||||||||||||||||||||||
| 1431 | 'p=' | ||||||||||||||||||||||||||||
| 1432 | . $predecessor_ahm_desc . '@' | ||||||||||||||||||||||||||||
| 1433 | . $origin_earleme . q{-} | ||||||||||||||||||||||||||||
| 1434 | . $middle_earleme; | ||||||||||||||||||||||||||||
| 1435 | } | ||||||||||||||||||||||||||||
| 1436 | |||||||||||||||||||||||||||||
| 1437 | 237 | push @pieces, | |||||||||||||||||||||||||||
| 1438 | 'c=' | ||||||||||||||||||||||||||||
| 1439 | . $ahm_desc . q{@} | ||||||||||||||||||||||||||||
| 1440 | . $middle_earleme . q{-} | ||||||||||||||||||||||||||||
| 1441 | . $current_earleme; | ||||||||||||||||||||||||||||
| 1442 | 237 | my $link_desc = '[' . ( join '; ', @pieces ) . ']'; | |||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||
| 1444 | 237 | ▶ | push @sort_data, | ||||||||||||||||||||||||||
|
Condition50%1/2
$predecessor_ahm_id // -1
MC/DC0%0/1
$predecessor_ahm_id // -1
$predecessor_ahm_id
Truth table50%1/2
A
A= $predecessor_ahm_id
| |||||||||||||||||||||||||||||
| 1445 | [ | ||||||||||||||||||||||||||||
| 1446 | $middle_earleme, $ahm_id, | ||||||||||||||||||||||||||||
| 1447 | ( $predecessor_ahm_id // -1 ), $link_desc | ||||||||||||||||||||||||||||
| 1448 | ]; | ||||||||||||||||||||||||||||
| 1449 | } | ||||||||||||||||||||||||||||
| 1450 | 237 | push @sorted_data, map { q{ } . $_->[-1] } sort { | |||||||||||||||||||||||||||
| 1451 | 452 | ▶ | $a->[0] <=> $b->[0] | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] or $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
MC/DC0%0/2
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] or $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0]
$Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
Truth table66%2/3
A or B
A= $Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0]B= $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
| |||||||||||||||||||||||||||||
| 1452 | || $a->[1] <=> $b->[1] | ||||||||||||||||||||||||||||
| 1453 | || $a->[2] <=> $b->[2] | ||||||||||||||||||||||||||||
| 1454 | } @sort_data; | ||||||||||||||||||||||||||||
| 1455 | } | ||||||||||||||||||||||||||||
| 1456 | |||||||||||||||||||||||||||||
| 1457 | # Leo links | ||||||||||||||||||||||||||||
| 1458 | { | ||||||||||||||||||||||||||||
| 1459 | 452 | my @sort_data = (); | |||||||||||||||||||||||||||
| 1460 | 452 | my @lines = (); | |||||||||||||||||||||||||||
| 1461 | 452 | my $leo_links = $item_data{leo_links}; | |||||||||||||||||||||||||||
| 1462 | 452 | my %leo_links = @{$leo_links}; | |||||||||||||||||||||||||||
| 1463 | LEO_LINK: | ||||||||||||||||||||||||||||
| 1464 | 452 | for ( my $leo_link_ix = 0 ; ; $leo_link_ix++ ) { | |||||||||||||||||||||||||||
| 1465 | 460 | my $leo_link_data = $leo_links{ $leo_link_ix + 1 }; | |||||||||||||||||||||||||||
| 1466 | 460 | ▶ | last LEO_LINK if not $leo_link_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1467 | 8 | my %leo_link_data = @{$leo_link_data}; | |||||||||||||||||||||||||||
| 1468 | |||||||||||||||||||||||||||||
| 1469 | 8 | my $middle_earleme = $leo_link_data{middle_earleme}; | |||||||||||||||||||||||||||
| 1470 | 8 | my $middle_set_id = $leo_link_data{middle_set_id}; | |||||||||||||||||||||||||||
| 1471 | my $leo_transition_symbol = | ||||||||||||||||||||||||||||
| 1472 | 8 | $leo_link_data{leo_transition_symbol}; | |||||||||||||||||||||||||||
| 1473 | 8 | my $ahm_id = $leo_link_data{ahm_id}; | |||||||||||||||||||||||||||
| 1474 | 8 | my $ahm_desc = $slg->briefer_ahm($ahm_id); | |||||||||||||||||||||||||||
| 1475 | |||||||||||||||||||||||||||||
| 1476 | 8 | my @pieces = (); | |||||||||||||||||||||||||||
| 1477 | 8 | push @pieces, | |||||||||||||||||||||||||||
| 1478 | 'l=L' . $leo_transition_symbol . q{@} . $middle_earleme; | ||||||||||||||||||||||||||||
| 1479 | 8 | push @pieces, | |||||||||||||||||||||||||||
| 1480 | 'c=' | ||||||||||||||||||||||||||||
| 1481 | . $ahm_desc . q{@} | ||||||||||||||||||||||||||||
| 1482 | . $middle_earleme . q{-} | ||||||||||||||||||||||||||||
| 1483 | . $current_earleme; | ||||||||||||||||||||||||||||
| 1484 | 8 | my $link_desc = '[' . ( join '; ', @pieces ) . ']'; | |||||||||||||||||||||||||||
| 1485 | |||||||||||||||||||||||||||||
| 1486 | 8 | push @sort_data, | |||||||||||||||||||||||||||
| 1487 | [ | ||||||||||||||||||||||||||||
| 1488 | $middle_set_id, $ahm_id, | ||||||||||||||||||||||||||||
| 1489 | $leo_transition_symbol, $link_desc, | ||||||||||||||||||||||||||||
| 1490 | ]; | ||||||||||||||||||||||||||||
| 1491 | } | ||||||||||||||||||||||||||||
| 1492 | 8 | push @sorted_data, map { q{ } . $_->[-1] } sort { | |||||||||||||||||||||||||||
| 1493 | 452 | ▶ | $a->[0] <=> $b->[0] | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] or $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
MC/DC0%0/2
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] or $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0]
$Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
Truth table0%0/3
A or B
A= $Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0]B= $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
| |||||||||||||||||||||||||||||
| 1494 | || $a->[1] <=> $b->[1] | ||||||||||||||||||||||||||||
| 1495 | || $a->[2] <=> $b->[2] | ||||||||||||||||||||||||||||
| 1496 | } @sort_data; | ||||||||||||||||||||||||||||
| 1497 | } | ||||||||||||||||||||||||||||
| 1498 | } | ||||||||||||||||||||||||||||
| 1499 | |||||||||||||||||||||||||||||
| 1500 | # Leo items | ||||||||||||||||||||||||||||
| 1501 | { | ||||||||||||||||||||||||||||
| 1502 | 59 | my $leo_data = $set_data{leo}; | |||||||||||||||||||||||||||
| 1503 | 59 | my %leo_data = @{$leo_data}; | |||||||||||||||||||||||||||
| 1504 | 59 | my @sort_data = (); | |||||||||||||||||||||||||||
| 1505 | 59 | LEO_ITEM: for ( my $leo_item_id = 0 ; ; $leo_item_id++ ) { | |||||||||||||||||||||||||||
| 1506 | |||||||||||||||||||||||||||||
| 1507 | 67 | my $leo_item_data = $leo_data{ $leo_item_id + 1 }; | |||||||||||||||||||||||||||
| 1508 | 67 | ▶ | last LEO_ITEM if not defined $leo_item_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1509 | |||||||||||||||||||||||||||||
| 1510 | 8 | my %leo_item_data = @{$leo_item_data}; | |||||||||||||||||||||||||||
| 1511 | 8 | my $postdot_symbol_id = $leo_item_data{postdot_symbol_id}; | |||||||||||||||||||||||||||
| 1512 | 8 | my $postdot_symbol_name = $leo_item_data{postdot_symbol_name}; | |||||||||||||||||||||||||||
| 1513 | 8 | my $predecessor_symbol_id = $leo_item_data{predecessor_symbol_id}; | |||||||||||||||||||||||||||
| 1514 | 8 | my $base_origin_earleme = $leo_item_data{base_origin_earleme}; | |||||||||||||||||||||||||||
| 1515 | 8 | my $leo_base_state = $leo_item_data{leo_base_state}; | |||||||||||||||||||||||||||
| 1516 | 8 | my $trace_earleme = $leo_item_data{trace_earleme}; | |||||||||||||||||||||||||||
| 1517 | |||||||||||||||||||||||||||||
| 1518 | # L2@8 ["Expression"; L2@6; S16@6-8] | ||||||||||||||||||||||||||||
| 1519 | 8 | my @link_texts = ( q{"} . $postdot_symbol_name . q{"} ); | |||||||||||||||||||||||||||
| 1520 | 8 | ▶ | if ( defined $predecessor_symbol_id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1521 | 6 | push @link_texts, | |||||||||||||||||||||||||||
| 1522 | sprintf( 'L%d@%d', | ||||||||||||||||||||||||||||
| 1523 | $predecessor_symbol_id, $base_origin_earleme ); | ||||||||||||||||||||||||||||
| 1524 | } | ||||||||||||||||||||||||||||
| 1525 | 8 | push @link_texts, | |||||||||||||||||||||||||||
| 1526 | sprintf( 'S%d@%d-%d', | ||||||||||||||||||||||||||||
| 1527 | $leo_base_state, $base_origin_earleme, $trace_earleme ); | ||||||||||||||||||||||||||||
| 1528 | 8 | my $leo_line = sprintf( 'L%d@%d [%s]', | |||||||||||||||||||||||||||
| 1529 | $postdot_symbol_id, $trace_earleme, | ||||||||||||||||||||||||||||
| 1530 | ( join q{; }, @link_texts ) ); | ||||||||||||||||||||||||||||
| 1531 | 8 | push @sort_data, [ $postdot_symbol_id, $leo_line ]; | |||||||||||||||||||||||||||
| 1532 | push @sorted_data, | ||||||||||||||||||||||||||||
| 1533 | ( | ||||||||||||||||||||||||||||
| 1534 | join q{}, | ||||||||||||||||||||||||||||
| 1535 | 8 | map { $_->[-1] } sort { $a->[0] <=> $b->[0] } @sort_data | |||||||||||||||||||||||||||
| 1536 | ); | ||||||||||||||||||||||||||||
| 1537 | } | ||||||||||||||||||||||||||||
| 1538 | } | ||||||||||||||||||||||||||||
| 1539 | |||||||||||||||||||||||||||||
| 1540 | 59 | return join "\n", @sorted_data, q{}; | |||||||||||||||||||||||||||
| 1541 | } | ||||||||||||||||||||||||||||
| 1542 | |||||||||||||||||||||||||||||
| 1543 | # not to be documented | ||||||||||||||||||||||||||||
| 1544 | sub Marpa::R3::Recognizer::regix { | ||||||||||||||||||||||||||||
| 1545 | 1 | ▶ | my ( $slr ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
regix: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1546 | 1 | my $regix = $slr->[Marpa::R3::Internal_R::REGIX]; | |||||||||||||||||||||||||||
| 1547 | 1 | return $regix; | |||||||||||||||||||||||||||
| 1548 | } | ||||||||||||||||||||||||||||
| 1549 | |||||||||||||||||||||||||||||
| 1550 | # Dump semantics for diagnostics | ||||||||||||||||||||||||||||
| 1551 | sub Marpa::R3::Recognizer::show_semantics { | ||||||||||||||||||||||||||||
| 1552 | 0 | ▶ | my ( $slg, @ops ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
show_semantics: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 1553 | 0 | my @op_descs = (); | |||||||||||||||||||||||||||
| 1554 | 0 | my $op_ix = 0; | |||||||||||||||||||||||||||
| 1555 | 0 | ▶ | OP: while ( $op_ix < scalar @ops ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1556 | 0 | my $op = $ops[ $op_ix++ ]; | |||||||||||||||||||||||||||
| 1557 | |||||||||||||||||||||||||||||
| 1558 | 0 | my $op_name = $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||
| 1559 | <<'END_OF_LUA', 'i', $op ); | ||||||||||||||||||||||||||||
| 1560 | local grammar, op = ... | ||||||||||||||||||||||||||||
| 1561 | return _M.op_names[op] | ||||||||||||||||||||||||||||
| 1562 | END_OF_LUA | ||||||||||||||||||||||||||||
| 1563 | |||||||||||||||||||||||||||||
| 1564 | 0 | push @op_descs, $op_name; | |||||||||||||||||||||||||||
| 1565 | 0 | ▶ | if ( $op_name eq 'lua' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1566 | |||||||||||||||||||||||||||||
| 1567 | 0 | my ($lua_op_name) = op_fn_name_by_key( $slg, $ops[$op_ix] ); | |||||||||||||||||||||||||||
| 1568 | 0 | push @op_descs, $lua_op_name; | |||||||||||||||||||||||||||
| 1569 | 0 | $op_ix++; | |||||||||||||||||||||||||||
| 1570 | 0 | ▶ | if ( $lua_op_name eq 'callback' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1571 | 0 | push @op_descs, op_fn_name_by_key( $slg, $ops[$op_ix] ); | |||||||||||||||||||||||||||
| 1572 | } | ||||||||||||||||||||||||||||
| 1573 | else { | ||||||||||||||||||||||||||||
| 1574 | 0 | push @op_descs, $ops[$op_ix]; | |||||||||||||||||||||||||||
| 1575 | } | ||||||||||||||||||||||||||||
| 1576 | 0 | $op_ix++; | |||||||||||||||||||||||||||
| 1577 | 0 | next OP; | |||||||||||||||||||||||||||
| 1578 | } | ||||||||||||||||||||||||||||
| 1579 | 0 | ▶ | if ( $op_name eq 'alternative' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1580 | 0 | push @op_descs, $ops[$op_ix]; | |||||||||||||||||||||||||||
| 1581 | 0 | $op_ix++; | |||||||||||||||||||||||||||
| 1582 | 0 | push @op_descs, $ops[$op_ix]; | |||||||||||||||||||||||||||
| 1583 | 0 | $op_ix++; | |||||||||||||||||||||||||||
| 1584 | 0 | next OP; | |||||||||||||||||||||||||||
| 1585 | } ## end if ( $op_name eq 'alternative' ) | ||||||||||||||||||||||||||||
| 1586 | } ## end OP: while ( $op_ix < scalar @ops ) | ||||||||||||||||||||||||||||
| 1587 | 0 | return join q{ }, @op_descs; | |||||||||||||||||||||||||||
| 1588 | } ## end sub show_semantics | ||||||||||||||||||||||||||||
| 1589 | |||||||||||||||||||||||||||||
| 1590 | # For diagnostics | ||||||||||||||||||||||||||||
| 1591 | sub g1_show_rule_list { | ||||||||||||||||||||||||||||
| 1592 | 0 | ▶ | my ( $slg, $rule_ids ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
g1_show_rule_list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 1593 | 0 | my @rules = map { $slg->g1_rule_show($_) } @{$rule_ids}; | |||||||||||||||||||||||||||
| 1594 | 0 | return join q{}, map { q{ } . $_ . "\n" } @rules; | |||||||||||||||||||||||||||
| 1595 | } | ||||||||||||||||||||||||||||
| 1596 | |||||||||||||||||||||||||||||
| 1597 | sub Marpa::R3::Recognizer::value { | ||||||||||||||||||||||||||||
| 1598 | 738 | ▶ | my ( $slr, $per_parse_arg ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
value: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 1599 | 738 | my $slv = Marpa::R3::Valuer->new( { recognizer => $slr } ); | |||||||||||||||||||||||||||
| 1600 | 738 | my $ambiguity_level = $slv->ambiguity_level(); | |||||||||||||||||||||||||||
| 1601 | 738 | ▶ | return if $ambiguity_level == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1602 | 718 | ▶ | if ( $ambiguity_level != 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1603 | 0 | my $ambiguous_status = $slv->ambiguous(); | |||||||||||||||||||||||||||
| 1604 | 0 | Marpa::R3::exception( "Parse of the input is ambiguous\n", | |||||||||||||||||||||||||||
| 1605 | $ambiguous_status ); | ||||||||||||||||||||||||||||
| 1606 | } | ||||||||||||||||||||||||||||
| 1607 | 718 | my $value_ref = $slv->value($per_parse_arg); | |||||||||||||||||||||||||||
| 1608 | 708 | ▶ | Marpa::R3::exception("$slr->value(): No parse\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1609 | if not $value_ref; | ||||||||||||||||||||||||||||
| 1610 | 708 | return $value_ref; | |||||||||||||||||||||||||||
| 1611 | } | ||||||||||||||||||||||||||||
| 1612 | |||||||||||||||||||||||||||||
| 1613 | # INTERNAL OK AFTER HERE _marpa_ | ||||||||||||||||||||||||||||
| 1614 | |||||||||||||||||||||||||||||
| 1615 | 104 | 1; | |||||||||||||||||||||||||||
| 1616 | |||||||||||||||||||||||||||||
| 1617 | # vim: expandtab shiftwidth=4: | ||||||||||||||||||||||||||||