| 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_054'; | |||||||||||||||||||||||||||||||||
| 20 | 104 | $STRING_VERSION = $VERSION; | |||||||||||||||||||||||||||||||||
| 21 | ## no critic(BuiltinFunctions::ProhibitStringyEval) | ||||||||||||||||||||||||||||||||||
| 22 | 104 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||
| 23 | ## use critic | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | package Marpa::R3::Internal_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 | 86 | ▶ | sub Marpa::R3::Recognizer::last_completed { | ||||||||||||||||||||||||||||||||
|
Subroutine
last_completed: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 39 | 86 | my ( $slr, $symbol_name ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 1635 | ▶ | sub Marpa::R3::Recognizer::g1_literal { | ||||||||||||||||||||||||||||||||
|
Subroutine
g1_literal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 59 | 1635 | my ( $slr, $g1_start, $g1_count ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 98 | ▶ | sub Marpa::R3::Recognizer::literal { | ||||||||||||||||||||||||||||||||
|
Subroutine
literal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 75 | 98 | my ( $slr, $block_id, $offset, $length ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 292 | ▶ | sub Marpa::R3::Internal::meta_recce { | ||||||||||||||||||||||||||||||||
|
Subroutine
meta_recce: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 91 | 292 | my ($hash_args) = @_; | |||||||||||||||||||||||||||||||||
| 92 | 292 | state $meta_grammar = Marpa::R3::Internal::meta_grammar(); | |||||||||||||||||||||||||||||||||
| 93 | 292 | $hash_args->{grammar} = $meta_grammar; | |||||||||||||||||||||||||||||||||
| 94 | 292 | my $self = Marpa::R3::Recognizer->new($hash_args); | |||||||||||||||||||||||||||||||||
| 95 | 292 | return $self; | |||||||||||||||||||||||||||||||||
| 96 | } ## end sub Marpa::R3::Internal::meta_recce | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | # Set those common args which are at the Perl level. | ||||||||||||||||||||||||||||||||||
| 99 | 1217 | ▶ | sub perl_common_set { | ||||||||||||||||||||||||||||||||
|
Subroutine
perl_common_set: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 100 | 1217 | my ( $slr, $flat_args ) = @_; | |||||||||||||||||||||||||||||||||
| 101 | 1217 | ▶ | if ( my $value = $flat_args->{'trace_file_handle'} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | 10 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE] = $value; | |||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||
| 104 | 1217 | my $trace_file_handle = | |||||||||||||||||||||||||||||||||
| 105 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||
| 106 | 1217 | delete $flat_args->{'trace_file_handle'}; | |||||||||||||||||||||||||||||||||
| 107 | 1217 | return $flat_args; | |||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | 6119 | ▶ | sub gen_app_event_handler { | ||||||||||||||||||||||||||||||||
|
Subroutine
gen_app_event_handler: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||
| 111 | 6119 | my ($slr) = @_; | |||||||||||||||||||||||||||||||||
| 112 | 6119 | my $event_handlers = | |||||||||||||||||||||||||||||||||
| 113 | $slr->[Marpa::R3::Internal_R::EVENT_HANDLERS]; | ||||||||||||||||||||||||||||||||||
| 114 | 1333 | ▶ | return sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=24.3
| |||||||||||||||||||||||||||||||||||
| 115 | 1333 | my ( $event_type, $event_name, @data ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 6119 | }; | |||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | 3099 | ▶ | sub gen_codepoint_event_handler { | ||||||||||||||||||||||||||||||||
|
Subroutine
gen_codepoint_event_handler: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 171 | 3099 | my ($slr) = @_; | |||||||||||||||||||||||||||||||||
| 172 | 3099 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||||||||
| 173 | 3099 | my $character_class_table = | |||||||||||||||||||||||||||||||||
| 174 | $slg->[Marpa::R3::Internal_G::CHARACTER_CLASS_TABLE]; | ||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||
| 176 | 5563 | ▶ | return sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 177 | 5563 | my ( $codepoint, $trace_terminals ) = @_; | |||||||||||||||||||||||||||||||||
| 178 | 5563 | my $character = pack( 'U', $codepoint ); | |||||||||||||||||||||||||||||||||
| 179 | 5563 | my $is_graphic = ( $character =~ m/[[:graph:]]+/ ); | |||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||
| 181 | 5563 | my @symbols; | |||||||||||||||||||||||||||||||||
| 182 | 5563 | for my $entry ( @{$character_class_table} ) { | |||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | 232100 | my ( $symbol_id, $re ) = @{$entry}; | |||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||
| 186 | # say STDERR "Codepoint %x vs $re\n"; | ||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | 232100 | ▶ | if ( $character =~ $re ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 26256 | ▶ | 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 | 26256 | push @symbols, $symbol_id; | |||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||
| 203 | } ## end if ( $character =~ $re ) | ||||||||||||||||||||||||||||||||||
| 204 | } ## end for my $entry ( @{$character_class_table} ) | ||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||
| 206 | 5563 | my $coro_arg = { symbols => \@symbols }; | |||||||||||||||||||||||||||||||||
| 207 | 5563 | ▶ | $coro_arg->{is_graphic} = 'true' if $is_graphic; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 208 | 5563 | return 'ok', $coro_arg; | |||||||||||||||||||||||||||||||||
| 209 | 3099 | }; | |||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||
| 212 | 1206 | ▶ | sub Marpa::R3::Recognizer::new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=25.0
| |||||||||||||||||||||||||||||||||||
| 213 | 1206 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | 1206 | my $slr = []; | |||||||||||||||||||||||||||||||||
| 216 | 1206 | bless $slr, $class; | |||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | # Set recognizer args to default | ||||||||||||||||||||||||||||||||||
| 219 | # Lua equivalent is set below | ||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||
| 221 | 1206 | my ( $flat_args, $error_message ) = Marpa::R3::flatten_hash_args( \@args ); | |||||||||||||||||||||||||||||||||
| 222 | 1206 | ▶ | Marpa::R3::exception( sprintf $error_message, '$slr->new' ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 223 | if not $flat_args; | ||||||||||||||||||||||||||||||||||
| 224 | 1206 | $flat_args = perl_common_set( $slr, $flat_args ); | |||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||
| 226 | 1206 | my $slg = $flat_args->{grammar}; | |||||||||||||||||||||||||||||||||
| 227 | 1206 | ▶ | Marpa::R3::exception( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 228 | qq{Marpa::R3::Recognizer::new() called without a "grammar" argument} ) | ||||||||||||||||||||||||||||||||||
| 229 | if not defined $slg; | ||||||||||||||||||||||||||||||||||
| 230 | 1206 | $slr->[Marpa::R3::Internal_R::SLG] = $slg; | |||||||||||||||||||||||||||||||||
| 231 | 1206 | delete $flat_args->{grammar}; | |||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||
| 233 | 1206 | ▶ | 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 | 1206 | $slr->[Marpa::R3::Internal_R::EVENT_HANDLERS] = $event_handlers; | |||||||||||||||||||||||||||||||||
| 235 | 1206 | ▶ | 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 | 1206 | delete $flat_args->{event_handlers}; | |||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||
| 246 | 1206 | my $slg_class = 'Marpa::R3::Grammar'; | |||||||||||||||||||||||||||||||||
| 247 | 1206 | ▶ | 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 | 1206 | ▶ | $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 | 1206 | my $trace_file_handle = | |||||||||||||||||||||||||||||||||
| 260 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | 1206 | my $lua = $slg->[Marpa::R3::Internal_G::L]; | |||||||||||||||||||||||||||||||||
| 263 | 1206 | $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 | 0 | ▶ | perl_undef => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 272 | 0 | return 'sig', [ 'S', undef ]; | |||||||||||||||||||||||||||||||||
| 273 | }, | ||||||||||||||||||||||||||||||||||
| 274 | 8 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 275 | 8 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 276 | 8 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||||||||
| 277 | 8 | return 'ok'; | |||||||||||||||||||||||||||||||||
| 278 | }, | ||||||||||||||||||||||||||||||||||
| 279 | 1206 | 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 | 1206 | $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 | 0 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 300 | 0 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 301 | 0 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||||||||
| 302 | 0 | return 'ok'; | |||||||||||||||||||||||||||||||||
| 303 | }, | ||||||||||||||||||||||||||||||||||
| 304 | 1206 | 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 | 1206 | return $slr; | |||||||||||||||||||||||||||||||||
| 316 | } ## end sub Marpa::R3::Recognizer::new | ||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||
| 318 | 1199 | ▶ | sub Marpa::R3::Recognizer::DESTROY { | ||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 319 | # say STDERR "In Marpa::R3::Recognizer::DESTROY before test"; | ||||||||||||||||||||||||||||||||||
| 320 | 1199 | my $slr = shift; | |||||||||||||||||||||||||||||||||
| 321 | 1199 | 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 | 1199 | ▶ | return if not $lua; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 331 | # say STDERR "In Marpa::R3::Recognizer::DESTROY after test"; | ||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||
| 333 | 1199 | my $regix = $slr->[Marpa::R3::Internal_R::REGIX]; | |||||||||||||||||||||||||||||||||
| 334 | 1199 | $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 | 11 | ▶ | sub Marpa::R3::Recognizer::set { | ||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 344 | 11 | my ( $slr, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 2 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 359 | 2 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 1211 | ▶ | sub Marpa::R3::Recognizer::read { | ||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||
| 376 | 1211 | my ( $slr, $p_string, $start_pos, $length ) = @_; | |||||||||||||||||||||||||||||||||
| 377 | 1211 | ▶ | 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 | 1211 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||
| 388 | 1211 | my $block_id = $slr->block_new($p_string); | |||||||||||||||||||||||||||||||||
| 389 | 1210 | $slr->block_set($block_id); | |||||||||||||||||||||||||||||||||
| 390 | 1210 | $slr->block_move($start_pos, $length); | |||||||||||||||||||||||||||||||||
| 391 | 1210 | return $slr->block_read(); | |||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||
| 394 | 549 | ▶ | sub Marpa::R3::Recognizer::resume { | ||||||||||||||||||||||||||||||||
|
Subroutine
resume: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||
| 395 | 549 | my ( $slr, $start_pos, $length ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 18 | ▶ | sub character_describe { | ||||||||||||||||||||||||||||||||
|
Subroutine
character_describe: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 413 | 18 | my ($slr, $codepoint) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 2 | ▶ | sub Marpa::R3::Grammar::parse { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=7 SCAR=22.8
| |||||||||||||||||||||||||||||||||||
| 428 | 2 | my ( $slg, $input_ref, @more_args ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | 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 | 0 | ▶ | sub lc_brief { | ||||||||||||||||||||||||||||||||
|
Subroutine
lc_brief: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 468 | 0 | my ( $slr, $pos, $block ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub lc_range_brief { | ||||||||||||||||||||||||||||||||
|
Subroutine
lc_range_brief: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 481 | 0 | my ( $slr, $first_block, $first_pos, $last_block, $last_pos ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 19 | ▶ | sub Marpa::R3::Recognizer::progress_show { | ||||||||||||||||||||||||||||||||
|
Subroutine
progress_show: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 492 | 19 | my ( $slr, $start_ordinal, $end_ordinal ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 19 | ▶ | sub Marpa::R3::Recognizer::progress { | ||||||||||||||||||||||||||||||||
|
Subroutine
progress: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 503 | 19 | my ( $slr, $ordinal_arg ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub Marpa::R3::Recognizer::g1_progress_show { | ||||||||||||||||||||||||||||||||
|
Subroutine
g1_progress_show: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 514 | 0 | my ( $slr, $start_ordinal, $end_ordinal ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 21 | ▶ | sub Marpa::R3::Recognizer::g1_progress { | ||||||||||||||||||||||||||||||||
|
Subroutine
g1_progress: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||
| 525 | 21 | my ( $slr, $ordinal_arg ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 35 | ▶ | sub Marpa::R3::Recognizer::terminals_expected { | ||||||||||||||||||||||||||||||||
|
Subroutine
terminals_expected: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 536 | 35 | my ($slr) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 18 | ▶ | sub Marpa::R3::Recognizer::exhausted { | ||||||||||||||||||||||||||||||||
|
Subroutine
exhausted: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 559 | 18 | my ($slr) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 185 | ▶ | sub Marpa::R3::Recognizer::g1_pos { | ||||||||||||||||||||||||||||||||
|
Subroutine
g1_pos: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 572 | 185 | my ($slr) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 12 | ▶ | sub Marpa::R3::Recognizer::current_earleme { | ||||||||||||||||||||||||||||||||
|
Subroutine
current_earleme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 584 | 12 | my ($slr) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 12 | ▶ | sub Marpa::R3::Recognizer::closest_earleme { | ||||||||||||||||||||||||||||||||
|
Subroutine
closest_earleme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 596 | 12 | my ($slr) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 12 | ▶ | sub Marpa::R3::Recognizer::furthest_earleme { | ||||||||||||||||||||||||||||||||
|
Subroutine
furthest_earleme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 608 | 12 | my ($slr) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 11 | ▶ | sub Marpa::R3::Recognizer::latest_earleme { | ||||||||||||||||||||||||||||||||
|
Subroutine
latest_earleme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 620 | 11 | my ($slr) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub Marpa::R3::Recognizer::earleme { | ||||||||||||||||||||||||||||||||
|
Subroutine
earleme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 632 | 1 | my ( $slr, $earley_set_id ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 84 | ▶ | sub Marpa::R3::Recognizer::lexeme_alternative_literal { | ||||||||||||||||||||||||||||||||
|
Subroutine
lexeme_alternative_literal: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||
| 644 | 84 | my ( $slr, $symbol_name, $length ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 137 | ▶ | sub Marpa::R3::Recognizer::lexeme_alternative { | ||||||||||||||||||||||||||||||||
|
Subroutine
lexeme_alternative: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||||||||
| 662 | 137 | my ( $slr, $symbol_name, $value, $length ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 189 | ▶ | sub Marpa::R3::Recognizer::lexeme_complete { | ||||||||||||||||||||||||||||||||
|
Subroutine
lexeme_complete: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||
| 698 | 189 | my ( $slr, $block, $offset, $length ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 719 | 0 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 116 | ▶ | sub Marpa::R3::Recognizer::lexeme_read_literal { | ||||||||||||||||||||||||||||||||
|
Subroutine
lexeme_read_literal: called CC=3 SCAR=14.7
| |||||||||||||||||||||||||||||||||||
| 746 | 116 | my ( $slr, $symbol_name, $block_id, $offset, $length ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 763 | 0 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 243 | ▶ | sub Marpa::R3::Recognizer::lexeme_read_block { | ||||||||||||||||||||||||||||||||
|
Subroutine
lexeme_read_block: called CC=4 SCAR=18.5
| |||||||||||||||||||||||||||||||||||
| 790 | 243 | my ( $slr, $symbol_name, $value, $block_id, $offset, $length ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 813 | 0 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 36 | ▶ | sub Marpa::R3::Recognizer::lexeme_read_string { | ||||||||||||||||||||||||||||||||
|
Subroutine
lexeme_read_string: called CC=3 SCAR=13.6
| |||||||||||||||||||||||||||||||||||
| 840 | 36 | my ( $slr, $symbol_name, $string ) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 858 | 0 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 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 | 57 | ▶ | sub Marpa::R3::Recognizer::g1_to_block_first { | ||||||||||||||||||||||||||||||||
|
Subroutine
g1_to_block_first: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 884 | 57 | my ( $slr, $g1_pos ) = @_; | |||||||||||||||||||||||||||||||||
| 885 | 57 | 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 | 54 | ▶ | sub Marpa::R3::Recognizer::g1_to_block_last { | ||||||||||||||||||||||||||||||||
|
Subroutine
g1_to_block_last: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 899 | 54 | my ( $slr, $g1_pos ) = @_; | |||||||||||||||||||||||||||||||||
| 900 | 54 | 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 | 39 | ▶ | sub Marpa::R3::Recognizer::lc_brief { | ||||||||||||||||||||||||||||||||
|
Subroutine
lc_brief: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 915 | 39 | my ( $slr, $first_block, $first_pos, $last_block, $last_pos ) = @_; | |||||||||||||||||||||||||||||||||
| 916 | 39 | 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 | 39 | return $desc; | |||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||
| 940 | 131 | ▶ | sub Marpa::R3::Recognizer::line_column { | ||||||||||||||||||||||||||||||||
|
Subroutine
line_column: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||
| 941 | 131 | my ( $slr, $block, $offset, ) = @_; | |||||||||||||||||||||||||||||||||
| 942 | 131 | ▶ | $offset //= -1; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$offset //= -1
MC/DC0%0/1
$offset //= -1
$offset
Truth table50%1/2
A
A= $offset
| |||||||||||||||||||||||||||||||||||
| 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, $offset ); | ||||||||||||||||||||||||||||||||||
| 947 | local slr, block_arg, offset_arg = ... | ||||||||||||||||||||||||||||||||||
| 948 | local block_id = block_arg ~= -1 and block_arg or nil | ||||||||||||||||||||||||||||||||||
| 949 | local offset = offset_arg ~= -1 and offset_arg or nil | ||||||||||||||||||||||||||||||||||
| 950 | local erreur | ||||||||||||||||||||||||||||||||||
| 951 | block_id, offset = slr:block_check_offset(block_id, offset) | ||||||||||||||||||||||||||||||||||
| 952 | if not block_id then | ||||||||||||||||||||||||||||||||||
| 953 | -- if block_id is nil, then offset is an error message | ||||||||||||||||||||||||||||||||||
| 954 | return nil, offset | ||||||||||||||||||||||||||||||||||
| 955 | end | ||||||||||||||||||||||||||||||||||
| 956 | local _, line_no, column_no = slr:per_pos(block_id, offset) | ||||||||||||||||||||||||||||||||||
| 957 | return line_no, column_no | ||||||||||||||||||||||||||||||||||
| 958 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||||||||
| 960 | # if $line_no is nil, 2nd return value is error message | ||||||||||||||||||||||||||||||||||
| 961 | # Marpa::R3::exception("line_column(): ", $column_no) if not defined $line_no; | ||||||||||||||||||||||||||||||||||
| 962 | 131 | ▶ | $DB::single = 1 if not defined $line_no; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 963 | 131 | return $line_no, $column_no; | |||||||||||||||||||||||||||||||||
| 964 | } ## end sub Marpa::R3::Recognizer::line_column | ||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||
| 966 | 1310 | ▶ | sub Marpa::R3::Recognizer::block_new { | ||||||||||||||||||||||||||||||||
|
Subroutine
block_new: called CC=5 SCAR=17.6
| |||||||||||||||||||||||||||||||||||
| 967 | 1310 | my ( $slr, $p_string ) = @_; | |||||||||||||||||||||||||||||||||
| 968 | 1310 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||
| 970 | Marpa::R3::exception( | ||||||||||||||||||||||||||||||||||
| 971 | q{Attempt to use a tainted input string in $slr->read()}, | ||||||||||||||||||||||||||||||||||
| 972 | qq{\n Marpa::R3 is insecure for use with tainted data\n} | ||||||||||||||||||||||||||||||||||
| 973 | 1310 | ▶ | ) if Scalar::Util::tainted( ${$p_string} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||
| 975 | 1309 | ▶ | if ( ( my $ref_type = ref $p_string ) ne 'SCALAR' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 976 | 0 | ▶ | my $desc = $ref_type ? "a ref to $ref_type" : 'not a ref'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 977 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||||||||
| 978 | qq{Arg to Marpa::R3::Recognizer::read() is $desc\n}, | ||||||||||||||||||||||||||||||||||
| 979 | ' It should be a ref to scalar' ); | ||||||||||||||||||||||||||||||||||
| 980 | } ## end if ( ( my $ref_type = ref $p_string ) ne 'SCALAR' ) | ||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||
| 982 | 1309 | ▶ | if ( not defined ${$p_string} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 983 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||||||||
| 984 | qq{Arg to Marpa::R3::Recognizer::read() is a ref to an undef\n}, | ||||||||||||||||||||||||||||||||||
| 985 | ' It should be a ref to a defined scalar' ); | ||||||||||||||||||||||||||||||||||
| 986 | } ## end if ( ( my $ref_type = ref $p_string ) ne 'SCALAR' ) | ||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||
| 988 | 1309 | my $character_class_table = | |||||||||||||||||||||||||||||||||
| 989 | $slg->[Marpa::R3::Internal_G::CHARACTER_CLASS_TABLE]; | ||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||
| 991 | my ($block_id) = $slr->coro_by_tag( | ||||||||||||||||||||||||||||||||||
| 992 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||||||||
| 993 | { | ||||||||||||||||||||||||||||||||||
| 994 | signature => 's', | ||||||||||||||||||||||||||||||||||
| 995 | 1309 | args => [ ${$p_string} ], | |||||||||||||||||||||||||||||||||
| 996 | handlers => { | ||||||||||||||||||||||||||||||||||
| 997 | codepoint => gen_codepoint_event_handler($slr), | ||||||||||||||||||||||||||||||||||
| 998 | event => gen_app_event_handler($slr), | ||||||||||||||||||||||||||||||||||
| 999 | }, | ||||||||||||||||||||||||||||||||||
| 1000 | }, | ||||||||||||||||||||||||||||||||||
| 1001 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||||||||
| 1002 | local slr, input_string = ... | ||||||||||||||||||||||||||||||||||
| 1003 | local new_block_id | ||||||||||||||||||||||||||||||||||
| 1004 | _M.wrap(function() | ||||||||||||||||||||||||||||||||||
| 1005 | new_block_id = slr:block_new(input_string) | ||||||||||||||||||||||||||||||||||
| 1006 | return 'ok', new_block_id | ||||||||||||||||||||||||||||||||||
| 1007 | end | ||||||||||||||||||||||||||||||||||
| 1008 | ) | ||||||||||||||||||||||||||||||||||
| 1009 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||
| 1011 | 1309 | return $block_id; | |||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||
| 1014 | 648 | ▶ | sub Marpa::R3::Recognizer::block_progress { | ||||||||||||||||||||||||||||||||
|
Subroutine
block_progress: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 1015 | 648 | my ($slr, $block_id) = @_; | |||||||||||||||||||||||||||||||||
| 1016 | 648 | my ($l0_pos, $l0_end); | |||||||||||||||||||||||||||||||||
| 1017 | 648 | ($block_id, $l0_pos, $l0_end) | |||||||||||||||||||||||||||||||||
| 1018 | = $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||||||||
| 1019 | <<'END_OF_LUA', 'i', $block_id ); | ||||||||||||||||||||||||||||||||||
| 1020 | local slr, block_id_arg = ... | ||||||||||||||||||||||||||||||||||
| 1021 | local block_id, erreur = slr:block_check_id(block_id_arg) | ||||||||||||||||||||||||||||||||||
| 1022 | if not block_id then | ||||||||||||||||||||||||||||||||||
| 1023 | error(erreur) | ||||||||||||||||||||||||||||||||||
| 1024 | end | ||||||||||||||||||||||||||||||||||
| 1025 | local l0_pos, l0_end | ||||||||||||||||||||||||||||||||||
| 1026 | block_id, l0_pos, l0_end = slr:block_progress(block_id) | ||||||||||||||||||||||||||||||||||
| 1027 | return block_id, l0_pos, l0_end | ||||||||||||||||||||||||||||||||||
| 1028 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1029 | 648 | return $block_id, $l0_pos, $l0_end; | |||||||||||||||||||||||||||||||||
| 1030 | } | ||||||||||||||||||||||||||||||||||
| 1031 | |||||||||||||||||||||||||||||||||||
| 1032 | 1354 | ▶ | sub Marpa::R3::Recognizer::block_set { | ||||||||||||||||||||||||||||||||
|
Subroutine
block_set: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||
| 1033 | 1354 | my ($slr, $block_id) = @_; | |||||||||||||||||||||||||||||||||
| 1034 | 1354 | ▶ | if ( $slr->[Marpa::R3::Internal_R::CURRENT_EVENT] ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1035 | 0 | Marpa::R3::exception( | |||||||||||||||||||||||||||||||||
| 1036 | "$slr->block_set() called from inside a handler\n", | ||||||||||||||||||||||||||||||||||
| 1037 | " This is not allowed\n", | ||||||||||||||||||||||||||||||||||
| 1038 | " The event was ", | ||||||||||||||||||||||||||||||||||
| 1039 | $slr->[Marpa::R3::Internal_R::CURRENT_EVENT], | ||||||||||||||||||||||||||||||||||
| 1040 | "\n", | ||||||||||||||||||||||||||||||||||
| 1041 | ); | ||||||||||||||||||||||||||||||||||
| 1042 | } | ||||||||||||||||||||||||||||||||||
| 1043 | 1354 | $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||||||||
| 1044 | <<'END_OF_LUA', 'i', $block_id ); | ||||||||||||||||||||||||||||||||||
| 1045 | local slr, block_id_arg = ... | ||||||||||||||||||||||||||||||||||
| 1046 | local block_id, erreur = slr:block_check_id(block_id_arg) | ||||||||||||||||||||||||||||||||||
| 1047 | if not block_id then | ||||||||||||||||||||||||||||||||||
| 1048 | error(erreur) | ||||||||||||||||||||||||||||||||||
| 1049 | end | ||||||||||||||||||||||||||||||||||
| 1050 | return slr:block_set(block_id) | ||||||||||||||||||||||||||||||||||
| 1051 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1052 | 1354 | return; | |||||||||||||||||||||||||||||||||
| 1053 | } | ||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||
| 1055 | # block_id defaults to current block | ||||||||||||||||||||||||||||||||||
| 1056 | # block_offset defaults to don't set offset | ||||||||||||||||||||||||||||||||||
| 1057 | # length defaults to don't set eoread | ||||||||||||||||||||||||||||||||||
| 1058 | 2155 | ▶ | sub Marpa::R3::Recognizer::block_move { | ||||||||||||||||||||||||||||||||
|
Subroutine
block_move: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 1059 | 2155 | my ($slr, $offset, $length) = @_; | |||||||||||||||||||||||||||||||||
| 1060 | 2155 | $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||||||||
| 1061 | <<'END_OF_LUA', 'ii', $offset, $length ); | ||||||||||||||||||||||||||||||||||
| 1062 | local slr, offset_arg, length_arg = ... | ||||||||||||||||||||||||||||||||||
| 1063 | local ok, offset, eoread | ||||||||||||||||||||||||||||||||||
| 1064 | = slr:block_check_range(nil, offset_arg, length_arg) | ||||||||||||||||||||||||||||||||||
| 1065 | if not ok then | ||||||||||||||||||||||||||||||||||
| 1066 | -- new_block_offset is error message | ||||||||||||||||||||||||||||||||||
| 1067 | error(offset) | ||||||||||||||||||||||||||||||||||
| 1068 | end | ||||||||||||||||||||||||||||||||||
| 1069 | -- we don't set offset if the arg was nil | ||||||||||||||||||||||||||||||||||
| 1070 | local new_offset = offset_arg and offset or nil | ||||||||||||||||||||||||||||||||||
| 1071 | -- we don't set eoread if the length arg was nil | ||||||||||||||||||||||||||||||||||
| 1072 | local new_eoread = length_arg and eoread or nil | ||||||||||||||||||||||||||||||||||
| 1073 | return slr:block_move(new_offset, new_eoread) | ||||||||||||||||||||||||||||||||||
| 1074 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1075 | 2155 | return; | |||||||||||||||||||||||||||||||||
| 1076 | } | ||||||||||||||||||||||||||||||||||
| 1077 | |||||||||||||||||||||||||||||||||||
| 1078 | 1814 | ▶ | sub Marpa::R3::Recognizer::block_read { | ||||||||||||||||||||||||||||||||
|
Subroutine
block_read: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 1079 | 1814 | my ($slr ) = @_; | |||||||||||||||||||||||||||||||||
| 1080 | my ($offset) = $slr->coro_by_tag( | ||||||||||||||||||||||||||||||||||
| 1081 | ( '@' . __FILE__ . ':' . __LINE__ ), | ||||||||||||||||||||||||||||||||||
| 1082 | { | ||||||||||||||||||||||||||||||||||
| 1083 | signature => '', | ||||||||||||||||||||||||||||||||||
| 1084 | args => [], | ||||||||||||||||||||||||||||||||||
| 1085 | handlers => { | ||||||||||||||||||||||||||||||||||
| 1086 | 314 | ▶ | trace => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 1087 | 314 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||
| 1088 | 314 | my $trace_file_handle = | |||||||||||||||||||||||||||||||||
| 1089 | $slr->[Marpa::R3::Internal_R::TRACE_FILE_HANDLE]; | ||||||||||||||||||||||||||||||||||
| 1090 | 314 | say {$trace_file_handle} $msg; | |||||||||||||||||||||||||||||||||
| 1091 | 314 | return 'ok'; | |||||||||||||||||||||||||||||||||
| 1092 | }, | ||||||||||||||||||||||||||||||||||
| 1093 | 1814 | event => gen_app_event_handler($slr), | |||||||||||||||||||||||||||||||||
| 1094 | } | ||||||||||||||||||||||||||||||||||
| 1095 | }, | ||||||||||||||||||||||||||||||||||
| 1096 | <<'END_OF_LUA'); | ||||||||||||||||||||||||||||||||||
| 1097 | local slr = ... | ||||||||||||||||||||||||||||||||||
| 1098 | _M.wrap(function () | ||||||||||||||||||||||||||||||||||
| 1099 | local offset = slr:block_read() | ||||||||||||||||||||||||||||||||||
| 1100 | return 'ok', offset | ||||||||||||||||||||||||||||||||||
| 1101 | end | ||||||||||||||||||||||||||||||||||
| 1102 | ) | ||||||||||||||||||||||||||||||||||
| 1103 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1104 | 1805 | return $offset; | |||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||
| 1107 | 2 | ▶ | sub Marpa::R3::Recognizer::input_length { | ||||||||||||||||||||||||||||||||
|
Subroutine
input_length: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 1108 | 2 | my ( $slr, $block_id ) = @_; | |||||||||||||||||||||||||||||||||
| 1109 | 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
| |||||||||||||||||||||||||||||||||||
| 1110 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 1111 | <<'END_OF_LUA', 'i', ($block_id // -1)); | ||||||||||||||||||||||||||||||||||
| 1112 | local slr, block_id = ... | ||||||||||||||||||||||||||||||||||
| 1113 | local block = block_id > 0 and slr.inputs[block_id] or slr.current_block | ||||||||||||||||||||||||||||||||||
| 1114 | return #block | ||||||||||||||||||||||||||||||||||
| 1115 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||
| 1117 | 2 | return $length; | |||||||||||||||||||||||||||||||||
| 1118 | } | ||||||||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||||||||
| 1120 | # no return value documented | ||||||||||||||||||||||||||||||||||
| 1121 | 536 | ▶ | sub Marpa::R3::Recognizer::activate { | ||||||||||||||||||||||||||||||||
|
Subroutine
activate: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 1122 | 536 | my ( $slr, $event_name, $activate ) = @_; | |||||||||||||||||||||||||||||||||
| 1123 | 536 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||
| 1125 | 536 | $slr->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||||||||
| 1126 | <<'END_OF_LUA', 'si', $event_name, $activate); | ||||||||||||||||||||||||||||||||||
| 1127 | local slr, event_name, activate = ... | ||||||||||||||||||||||||||||||||||
| 1128 | if not activate then | ||||||||||||||||||||||||||||||||||
| 1129 | activate = 1 | ||||||||||||||||||||||||||||||||||
| 1130 | else | ||||||||||||||||||||||||||||||||||
| 1131 | activate = activate ~= 0 | ||||||||||||||||||||||||||||||||||
| 1132 | end | ||||||||||||||||||||||||||||||||||
| 1133 | -- print('$slr->activate():', event_name, activate) | ||||||||||||||||||||||||||||||||||
| 1134 | return slr:activate_by_event_name(event_name, activate) | ||||||||||||||||||||||||||||||||||
| 1135 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1136 | 536 | return; | |||||||||||||||||||||||||||||||||
| 1137 | } | ||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||
| 1139 | # On success, returns the old priority value. | ||||||||||||||||||||||||||||||||||
| 1140 | # Failures are thrown. | ||||||||||||||||||||||||||||||||||
| 1141 | 12 | ▶ | sub Marpa::R3::Recognizer::lexeme_priority_set { | ||||||||||||||||||||||||||||||||
|
Subroutine
lexeme_priority_set: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 1142 | 12 | my ( $slr, $lexeme_name, $new_priority ) = @_; | |||||||||||||||||||||||||||||||||
| 1143 | 12 | my ($old_priority) = $slr->call_by_tag( | |||||||||||||||||||||||||||||||||
| 1144 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 1145 | <<'END_OF_LUA', 'si>*', $lexeme_name, $new_priority ); | ||||||||||||||||||||||||||||||||||
| 1146 | local recce, lexeme_name, new_priority = ... | ||||||||||||||||||||||||||||||||||
| 1147 | local slg = recce.slg | ||||||||||||||||||||||||||||||||||
| 1148 | local g1g = slg.g1 | ||||||||||||||||||||||||||||||||||
| 1149 | local lexeme_id = g1g.isyid_by_name[lexeme_name] | ||||||||||||||||||||||||||||||||||
| 1150 | if not lexeme_id then | ||||||||||||||||||||||||||||||||||
| 1151 | _M.userX( | ||||||||||||||||||||||||||||||||||
| 1152 | "lexeme_priority_set(): no such symbol as %q", | ||||||||||||||||||||||||||||||||||
| 1153 | lexeme_name | ||||||||||||||||||||||||||||||||||
| 1154 | ) | ||||||||||||||||||||||||||||||||||
| 1155 | end | ||||||||||||||||||||||||||||||||||
| 1156 | if type(new_priority) ~= 'number' then | ||||||||||||||||||||||||||||||||||
| 1157 | _M.userX( | ||||||||||||||||||||||||||||||||||
| 1158 | "lexeme_priority_set(): priority is not a number, it is %s", | ||||||||||||||||||||||||||||||||||
| 1159 | new_priority | ||||||||||||||||||||||||||||||||||
| 1160 | ) | ||||||||||||||||||||||||||||||||||
| 1161 | end | ||||||||||||||||||||||||||||||||||
| 1162 | local g_lexeme_data = slg.g1.isys[lexeme_id] | ||||||||||||||||||||||||||||||||||
| 1163 | local r_lexeme_data = recce.g1_isys[lexeme_id] | ||||||||||||||||||||||||||||||||||
| 1164 | if not g_lexeme_data.lexeme then | ||||||||||||||||||||||||||||||||||
| 1165 | print(inspect(lexeme_data)) | ||||||||||||||||||||||||||||||||||
| 1166 | _M.userX( | ||||||||||||||||||||||||||||||||||
| 1167 | "lexeme_priority_set(): %q is not a lexeme", | ||||||||||||||||||||||||||||||||||
| 1168 | lexeme_name | ||||||||||||||||||||||||||||||||||
| 1169 | ) | ||||||||||||||||||||||||||||||||||
| 1170 | end | ||||||||||||||||||||||||||||||||||
| 1171 | local old_priority = r_lexeme_data.lexeme_priority | ||||||||||||||||||||||||||||||||||
| 1172 | r_lexeme_data.lexeme_priority = new_priority | ||||||||||||||||||||||||||||||||||
| 1173 | return old_priority | ||||||||||||||||||||||||||||||||||
| 1174 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1175 | |||||||||||||||||||||||||||||||||||
| 1176 | 12 | return $old_priority; | |||||||||||||||||||||||||||||||||
| 1177 | } | ||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||
| 1179 | # Internal methods, not to be documented | ||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||
| 1181 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 1182 | 8845 | ▶ | sub Marpa::R3::Recognizer::call_by_tag { | ||||||||||||||||||||||||||||||||
|
Subroutine
call_by_tag: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 1183 | 8845 | my ( $slr, $tag, $codestr, $signature, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 1184 | 8845 | my $lua = $slr->[Marpa::R3::Internal_R::L]; | |||||||||||||||||||||||||||||||||
| 1185 | 8845 | my $regix = $slr->[Marpa::R3::Internal_R::REGIX]; | |||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||
| 1187 | 8845 | ▶ | $DB::single = 1 if not $slr; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1188 | 8845 | ▶ | $DB::single = 1 if not $regix; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1189 | # $DB::single = 1 if grep { not defined $_ } @args; | ||||||||||||||||||||||||||||||||||
| 1190 | 8845 | my @results; | |||||||||||||||||||||||||||||||||
| 1191 | my $eval_error; | ||||||||||||||||||||||||||||||||||
| 1192 | 8845 | my $eval_ok; | |||||||||||||||||||||||||||||||||
| 1193 | { | ||||||||||||||||||||||||||||||||||
| 1194 | 8845 | local $@; | |||||||||||||||||||||||||||||||||
| 1195 | 8845 | $eval_ok = eval { | |||||||||||||||||||||||||||||||||
| 1196 | 8845 | @results = | |||||||||||||||||||||||||||||||||
| 1197 | $lua->call_by_tag( $regix, $tag, $codestr, $signature, @args ); | ||||||||||||||||||||||||||||||||||
| 1198 | 8843 | return 1; | |||||||||||||||||||||||||||||||||
| 1199 | }; | ||||||||||||||||||||||||||||||||||
| 1200 | 8845 | $eval_error = $@; | |||||||||||||||||||||||||||||||||
| 1201 | } | ||||||||||||||||||||||||||||||||||
| 1202 | 8845 | ▶ | if ( not $eval_ok ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1203 | 2 | Marpa::R3::exception($eval_error); | |||||||||||||||||||||||||||||||||
| 1204 | } | ||||||||||||||||||||||||||||||||||
| 1205 | 8843 | return @results; | |||||||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||||||||
| 1208 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 1209 | 6125 | ▶ | sub Marpa::R3::Recognizer::coro_by_tag { | ||||||||||||||||||||||||||||||||
|
Subroutine
coro_by_tag: called CC=13 SCAR=28.0
| |||||||||||||||||||||||||||||||||||
| 1210 | 6125 | my ( $slr, $tag, $args, $codestr ) = @_; | |||||||||||||||||||||||||||||||||
| 1211 | 6125 | my $lua = $slr->[Marpa::R3::Internal_R::L]; | |||||||||||||||||||||||||||||||||
| 1212 | 6125 | my $regix = $slr->[Marpa::R3::Internal_R::REGIX]; | |||||||||||||||||||||||||||||||||
| 1213 | 6125 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||
| 1214 | 6125 | my $resume_tag = $tag . '[R]'; | |||||||||||||||||||||||||||||||||
| 1215 | 6125 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||
| 1216 | 6125 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||
| 1218 | 6125 | my @results; | |||||||||||||||||||||||||||||||||
| 1219 | my $eval_error; | ||||||||||||||||||||||||||||||||||
| 1220 | 6125 | my $eval_ok; | |||||||||||||||||||||||||||||||||
| 1221 | { | ||||||||||||||||||||||||||||||||||
| 1222 | 6125 | local $@; | |||||||||||||||||||||||||||||||||
| 1223 | 6125 | $eval_ok = eval { | |||||||||||||||||||||||||||||||||
| 1224 | 6125 | $lua->call_by_tag( $regix, $tag, $codestr, $signature, @{$p_args} ); | |||||||||||||||||||||||||||||||||
| 1225 | 6125 | my @resume_args = (''); | |||||||||||||||||||||||||||||||||
| 1226 | 6125 | my $signature = 's'; | |||||||||||||||||||||||||||||||||
| 1227 | 6125 | CORO_CALL: while (1) { | |||||||||||||||||||||||||||||||||
| 1228 | 13337 | my ( $cmd, $yield_data ) = | |||||||||||||||||||||||||||||||||
| 1229 | $lua->call_by_tag( $regix, $resume_tag, | ||||||||||||||||||||||||||||||||||
| 1230 | 'local slr, resume_arg = ...; return _M.resume(resume_arg)', | ||||||||||||||||||||||||||||||||||
| 1231 | $signature, @resume_args ) ; | ||||||||||||||||||||||||||||||||||
| 1232 | 13328 | ▶ | if (not $cmd) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1233 | 6116 | @results = @{$yield_data}; | |||||||||||||||||||||||||||||||||
| 1234 | 6116 | return 1; | |||||||||||||||||||||||||||||||||
| 1235 | } | ||||||||||||||||||||||||||||||||||
| 1236 | 7212 | my $handler = $handler->{$cmd}; | |||||||||||||||||||||||||||||||||
| 1237 | 7212 | ▶ | Marpa::R3::exception(qq{No coro handler for "$cmd"}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1238 | if not $handler; | ||||||||||||||||||||||||||||||||||
| 1239 | 7212 | ▶ | $yield_data //= []; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$yield_data //= []
MC/DC0%0/1
$yield_data //= []
$yield_data
Truth table50%1/2
A
A= $yield_data
| |||||||||||||||||||||||||||||||||||
| 1240 | 7212 | my ($handler_cmd, $new_resume_args) = $handler->(@{$yield_data}); | |||||||||||||||||||||||||||||||||
| 1241 | 7212 | ▶ | Marpa::R3::exception(qq{Undefined return command from handler for "$cmd"}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1242 | if not defined $handler_cmd; | ||||||||||||||||||||||||||||||||||
| 1243 | 7212 | ▶ | if ($handler_cmd eq 'ok') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1244 | 7212 | $signature = 's'; | |||||||||||||||||||||||||||||||||
| 1245 | 7212 | @resume_args = ($new_resume_args); | |||||||||||||||||||||||||||||||||
| 1246 | 7212 | ▶ | if (scalar @resume_args < 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1247 | 0 | @resume_args = (''); | |||||||||||||||||||||||||||||||||
| 1248 | } | ||||||||||||||||||||||||||||||||||
| 1249 | 7212 | next CORO_CALL; | |||||||||||||||||||||||||||||||||
| 1250 | } | ||||||||||||||||||||||||||||||||||
| 1251 | 0 | ▶ | if ($handler_cmd eq 'sig') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1252 | 0 | @resume_args = @{$new_resume_args}; | |||||||||||||||||||||||||||||||||
| 1253 | 0 | $signature = shift @resume_args; | |||||||||||||||||||||||||||||||||
| 1254 | 0 | next CORO_CALL; | |||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||
| 1256 | 0 | Marpa::R3::exception(qq{Bad return command ("$handler_cmd") from handler for "$cmd"}) | |||||||||||||||||||||||||||||||||
| 1257 | } | ||||||||||||||||||||||||||||||||||
| 1258 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 1259 | }; | ||||||||||||||||||||||||||||||||||
| 1260 | 6125 | $eval_error = $@; | |||||||||||||||||||||||||||||||||
| 1261 | } | ||||||||||||||||||||||||||||||||||
| 1262 | 6125 | ▶ | if ( not $eval_ok ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1263 | # if it's an object, just die | ||||||||||||||||||||||||||||||||||
| 1264 | 9 | ▶ | die $eval_error if ref $eval_error; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1265 | 9 | Marpa::R3::exception($eval_error); | |||||||||||||||||||||||||||||||||
| 1266 | } | ||||||||||||||||||||||||||||||||||
| 1267 | 6116 | return @results; | |||||||||||||||||||||||||||||||||
| 1268 | } | ||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||
| 1270 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 1271 | 78 | ▶ | sub Marpa::R3::Recognizer::earley_set_size { | ||||||||||||||||||||||||||||||||
|
Subroutine
earley_set_size: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||
| 1272 | 78 | my ($slr, $set_id) = @_; | |||||||||||||||||||||||||||||||||
| 1273 | 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
| |||||||||||||||||||||||||||||||||||
| 1274 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 1275 | <<'END_OF_LUA', 'i', ($set_id // -1)); | ||||||||||||||||||||||||||||||||||
| 1276 | local recce, set_id = ... | ||||||||||||||||||||||||||||||||||
| 1277 | local g1r = recce.g1 | ||||||||||||||||||||||||||||||||||
| 1278 | if set_id < 0 then set_id = g1r:latest_earley_set() end | ||||||||||||||||||||||||||||||||||
| 1279 | return g1r:_earley_set_size(set_id) | ||||||||||||||||||||||||||||||||||
| 1280 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1281 | 78 | return $size; | |||||||||||||||||||||||||||||||||
| 1282 | } | ||||||||||||||||||||||||||||||||||
| 1283 | |||||||||||||||||||||||||||||||||||
| 1284 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 1285 | 8 | ▶ | sub Marpa::R3::Recognizer::earley_sets_show { | ||||||||||||||||||||||||||||||||
|
Subroutine
earley_sets_show: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 1286 | 8 | my ($slr) = @_; | |||||||||||||||||||||||||||||||||
| 1287 | |||||||||||||||||||||||||||||||||||
| 1288 | 8 | my ($last_completed_earleme, $furthest_earleme) = $slr->call_by_tag( | |||||||||||||||||||||||||||||||||
| 1289 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 1290 | <<'END_OF_LUA', ''); | ||||||||||||||||||||||||||||||||||
| 1291 | local recce = ... | ||||||||||||||||||||||||||||||||||
| 1292 | local g1r = recce.g1 | ||||||||||||||||||||||||||||||||||
| 1293 | return g1r:current_earleme(), g1r:furthest_earleme() | ||||||||||||||||||||||||||||||||||
| 1294 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||||||||
| 1296 | 8 | my $text = "Last Completed: $last_completed_earleme; " | |||||||||||||||||||||||||||||||||
| 1297 | . "Furthest: $furthest_earleme\n"; | ||||||||||||||||||||||||||||||||||
| 1298 | 8 | LIST: for ( my $ix = 0;; $ix++ ) { | |||||||||||||||||||||||||||||||||
| 1299 | 67 | my $set_desc = | |||||||||||||||||||||||||||||||||
| 1300 | $slr->Marpa::R3::Recognizer::earley_set_show( $ix ); | ||||||||||||||||||||||||||||||||||
| 1301 | 67 | ▶ | last LIST if not $set_desc; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1302 | 59 | $text .= "Earley Set $ix\n$set_desc"; | |||||||||||||||||||||||||||||||||
| 1303 | } | ||||||||||||||||||||||||||||||||||
| 1304 | 8 | return $text; | |||||||||||||||||||||||||||||||||
| 1305 | } | ||||||||||||||||||||||||||||||||||
| 1306 | |||||||||||||||||||||||||||||||||||
| 1307 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 1308 | 67 | ▶ | sub Marpa::R3::Recognizer::earley_set_show { | ||||||||||||||||||||||||||||||||
|
Subroutine
earley_set_show: called CC=19 SCAR=29.8
| |||||||||||||||||||||||||||||||||||
| 1309 | 67 | my ( $slr, $traced_set_id ) = @_; | |||||||||||||||||||||||||||||||||
| 1310 | 67 | my $slg = $slr->[Marpa::R3::Internal_R::SLG]; | |||||||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||||||||
| 1312 | 67 | my ($set_data) = | |||||||||||||||||||||||||||||||||
| 1313 | $slr->call_by_tag( | ||||||||||||||||||||||||||||||||||
| 1314 | ('@' . __FILE__ . ':' . __LINE__), | ||||||||||||||||||||||||||||||||||
| 1315 | <<'END_OF_LUA', 'i>2', $traced_set_id ); | ||||||||||||||||||||||||||||||||||
| 1316 | local recce, traced_set_id = ... | ||||||||||||||||||||||||||||||||||
| 1317 | return recce:g1_earley_set_data(traced_set_id) | ||||||||||||||||||||||||||||||||||
| 1318 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1319 | |||||||||||||||||||||||||||||||||||
| 1320 | 67 | ▶ | return if not $set_data; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1321 | 59 | my %set_data = @{$set_data}; | |||||||||||||||||||||||||||||||||
| 1322 | |||||||||||||||||||||||||||||||||||
| 1323 | 59 | my $current_earleme = $set_data{earleme}; | |||||||||||||||||||||||||||||||||
| 1324 | |||||||||||||||||||||||||||||||||||
| 1325 | 59 | my @sorted_data = (); | |||||||||||||||||||||||||||||||||
| 1326 | |||||||||||||||||||||||||||||||||||
| 1327 | 59 | EARLEY_ITEM: for ( my $item_id = 0 ; ; $item_id++ ) { | |||||||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||||||||
| 1329 | 511 | my $item_data = $set_data{ $item_id + 1 }; | |||||||||||||||||||||||||||||||||
| 1330 | 511 | ▶ | last EARLEY_ITEM if not defined $item_data; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1331 | |||||||||||||||||||||||||||||||||||
| 1332 | 452 | my %item_data = @{$item_data}; | |||||||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||||||||
| 1334 | 452 | my $nrl_id = $item_data{nrl_id}; | |||||||||||||||||||||||||||||||||
| 1335 | 452 | my $dot_position = $item_data{dot_position}; | |||||||||||||||||||||||||||||||||
| 1336 | 452 | my $ahm_desc; | |||||||||||||||||||||||||||||||||
| 1337 | 452 | ▶ | if ( $dot_position < 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1338 | 177 | $ahm_desc = sprintf( 'R%d$', $nrl_id ); | |||||||||||||||||||||||||||||||||
| 1339 | } | ||||||||||||||||||||||||||||||||||
| 1340 | else { | ||||||||||||||||||||||||||||||||||
| 1341 | 275 | $ahm_desc = sprintf( 'R%d:%d', $nrl_id, $dot_position ); | |||||||||||||||||||||||||||||||||
| 1342 | } | ||||||||||||||||||||||||||||||||||
| 1343 | 452 | my $ahm_id_of_yim = $item_data{ahm_id_of_yim}; | |||||||||||||||||||||||||||||||||
| 1344 | 452 | my $origin_earleme = $item_data{origin_earleme}; | |||||||||||||||||||||||||||||||||
| 1345 | |||||||||||||||||||||||||||||||||||
| 1346 | 452 | my $text .= sprintf "ahm%d: %s@%d-%d", $ahm_id_of_yim, | |||||||||||||||||||||||||||||||||
| 1347 | $ahm_desc, | ||||||||||||||||||||||||||||||||||
| 1348 | $origin_earleme, $current_earleme; | ||||||||||||||||||||||||||||||||||
| 1349 | |||||||||||||||||||||||||||||||||||
| 1350 | 452 | my @lines = $text; | |||||||||||||||||||||||||||||||||
| 1351 | 452 | push @lines, | |||||||||||||||||||||||||||||||||
| 1352 | qq{ } | ||||||||||||||||||||||||||||||||||
| 1353 | . $ahm_desc . q{: } | ||||||||||||||||||||||||||||||||||
| 1354 | . $slg->dotted_nrl_show( $nrl_id, $dot_position ); | ||||||||||||||||||||||||||||||||||
| 1355 | |||||||||||||||||||||||||||||||||||
| 1356 | 452 | push @sorted_data, @lines; | |||||||||||||||||||||||||||||||||
| 1357 | |||||||||||||||||||||||||||||||||||
| 1358 | # Token links | ||||||||||||||||||||||||||||||||||
| 1359 | { | ||||||||||||||||||||||||||||||||||
| 1360 | 452 | my @sort_data = (); | |||||||||||||||||||||||||||||||||
| 1361 | 452 | my @lines = (); | |||||||||||||||||||||||||||||||||
| 1362 | 452 | my $token_links = $item_data{token_links}; | |||||||||||||||||||||||||||||||||
| 1363 | 452 | my %token_links = @{$token_links}; | |||||||||||||||||||||||||||||||||
| 1364 | 452 | TOKEN_LINK: for ( my $token_link_ix = 0 ; ; $token_link_ix++ ) { | |||||||||||||||||||||||||||||||||
| 1365 | 519 | my $token_link_data = $token_links{ $token_link_ix + 1 }; | |||||||||||||||||||||||||||||||||
| 1366 | 519 | ▶ | last TOKEN_LINK if not $token_link_data; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1367 | 67 | my %token_link_data = @{$token_link_data}; | |||||||||||||||||||||||||||||||||
| 1368 | |||||||||||||||||||||||||||||||||||
| 1369 | 67 | my $predecessor_ahm = $token_link_data{predecessor_ahm}; | |||||||||||||||||||||||||||||||||
| 1370 | 67 | my $origin_earleme = $token_link_data{origin_earleme}; | |||||||||||||||||||||||||||||||||
| 1371 | 67 | my $middle_earleme = $token_link_data{middle_earleme}; | |||||||||||||||||||||||||||||||||
| 1372 | 67 | my $middle_set_id = $token_link_data{middle_set_id}; | |||||||||||||||||||||||||||||||||
| 1373 | 67 | my $token_name = $token_link_data{token_name}; | |||||||||||||||||||||||||||||||||
| 1374 | 67 | my $token_id = $token_link_data{token_id}; | |||||||||||||||||||||||||||||||||
| 1375 | 67 | my $value_ix = $token_link_data{value_ix}; | |||||||||||||||||||||||||||||||||
| 1376 | 67 | my $value = $token_link_data{value}; | |||||||||||||||||||||||||||||||||
| 1377 | my $source_predecessor_state = | ||||||||||||||||||||||||||||||||||
| 1378 | 67 | $token_link_data{source_predecessor_state}; | |||||||||||||||||||||||||||||||||
| 1379 | |||||||||||||||||||||||||||||||||||
| 1380 | 67 | my @pieces = (); | |||||||||||||||||||||||||||||||||
| 1381 | 67 | ▶ | if ( defined $predecessor_ahm ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1382 | 67 | my $ahm_desc = $slg->briefer_ahm($predecessor_ahm); | |||||||||||||||||||||||||||||||||
| 1383 | 67 | push @pieces, | |||||||||||||||||||||||||||||||||
| 1384 | 'c=' | ||||||||||||||||||||||||||||||||||
| 1385 | . $ahm_desc . q{@} | ||||||||||||||||||||||||||||||||||
| 1386 | . $origin_earleme . q{-} | ||||||||||||||||||||||||||||||||||
| 1387 | . $middle_earleme; | ||||||||||||||||||||||||||||||||||
| 1388 | } ## end if ( defined $predecessor_ahm ) | ||||||||||||||||||||||||||||||||||
| 1389 | |||||||||||||||||||||||||||||||||||
| 1390 | 67 | push @pieces, 's=' . $token_name; | |||||||||||||||||||||||||||||||||
| 1391 | |||||||||||||||||||||||||||||||||||
| 1392 | 67 | ▶ | if ( not defined $value ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1393 | |||||||||||||||||||||||||||||||||||
| 1394 | # Value is literal | ||||||||||||||||||||||||||||||||||
| 1395 | 67 | my $token_length = $current_earleme - $middle_earleme; | |||||||||||||||||||||||||||||||||
| 1396 | 67 | $value = $slr->g1_literal( $middle_earleme, $token_length ); | |||||||||||||||||||||||||||||||||
| 1397 | } | ||||||||||||||||||||||||||||||||||
| 1398 | 67 | my $token_dump = | |||||||||||||||||||||||||||||||||
| 1399 | Data::Dumper->new( [ \$value ] )->Terse(1)->Dump; | ||||||||||||||||||||||||||||||||||
| 1400 | 67 | chomp $token_dump; | |||||||||||||||||||||||||||||||||
| 1401 | 67 | push @pieces, "t=$token_dump"; | |||||||||||||||||||||||||||||||||
| 1402 | 67 | my $token_link_desc = '[' . ( join '; ', @pieces ) . ']'; | |||||||||||||||||||||||||||||||||
| 1403 | 67 | push @sort_data, | |||||||||||||||||||||||||||||||||
| 1404 | [ | ||||||||||||||||||||||||||||||||||
| 1405 | $middle_set_id, $token_id, | ||||||||||||||||||||||||||||||||||
| 1406 | $predecessor_ahm, $token_link_desc | ||||||||||||||||||||||||||||||||||
| 1407 | ]; | ||||||||||||||||||||||||||||||||||
| 1408 | } | ||||||||||||||||||||||||||||||||||
| 1409 | 67 | push @sorted_data, map { qq{ } . $_->[-1] } sort { | |||||||||||||||||||||||||||||||||
| 1410 | 0 | ▶ | $a->[0] <=> $b->[0] | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] || $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1] || $Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[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]
MC/DC0%0/3
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] || $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1] || $Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[2]
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0]
$Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
$Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[2]
Truth table0%0/4
A or B || C
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]C= $Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[2]
| |||||||||||||||||||||||||||||||||||
| 1411 | || $a->[1] <=> $b->[1] | ||||||||||||||||||||||||||||||||||
| 1412 | || $a->[2] <=> $b->[2] | ||||||||||||||||||||||||||||||||||
| 1413 | } @sort_data; | ||||||||||||||||||||||||||||||||||
| 1414 | } | ||||||||||||||||||||||||||||||||||
| 1415 | |||||||||||||||||||||||||||||||||||
| 1416 | # Completion links | ||||||||||||||||||||||||||||||||||
| 1417 | { | ||||||||||||||||||||||||||||||||||
| 1418 | 452 | my @sort_data = (); | |||||||||||||||||||||||||||||||||
| 1419 | 452 | my @lines = (); | |||||||||||||||||||||||||||||||||
| 1420 | 452 | my $completion_links = $item_data{completion_links}; | |||||||||||||||||||||||||||||||||
| 1421 | 452 | my %completion_links = @{$completion_links}; | |||||||||||||||||||||||||||||||||
| 1422 | TOKEN_LINK: | ||||||||||||||||||||||||||||||||||
| 1423 | 452 | for ( my $completion_link_ix = 0 ; ; $completion_link_ix++ ) { | |||||||||||||||||||||||||||||||||
| 1424 | my $completion_link_data = | ||||||||||||||||||||||||||||||||||
| 1425 | 689 | $completion_links{ $completion_link_ix + 1 }; | |||||||||||||||||||||||||||||||||
| 1426 | 689 | ▶ | last TOKEN_LINK if not $completion_link_data; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1427 | 237 | my %completion_link_data = @{$completion_link_data}; | |||||||||||||||||||||||||||||||||
| 1428 | |||||||||||||||||||||||||||||||||||
| 1429 | my $predecessor_ahm_id = | ||||||||||||||||||||||||||||||||||
| 1430 | 237 | $completion_link_data{predecessor_state}; | |||||||||||||||||||||||||||||||||
| 1431 | 237 | my $ahm_id = $completion_link_data{ahm_id}; | |||||||||||||||||||||||||||||||||
| 1432 | 237 | my $origin_earleme = $completion_link_data{origin_earleme}; | |||||||||||||||||||||||||||||||||
| 1433 | 237 | my $middle_earleme = $completion_link_data{middle_earleme}; | |||||||||||||||||||||||||||||||||
| 1434 | 237 | my $ahm_desc = $slg->briefer_ahm($ahm_id); | |||||||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||||||||
| 1436 | 237 | my @pieces = (); | |||||||||||||||||||||||||||||||||
| 1437 | 237 | ▶ | if ( defined $predecessor_ahm_id ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1438 | 237 | my $predecessor_ahm_desc = | |||||||||||||||||||||||||||||||||
| 1439 | $slg->briefer_ahm($predecessor_ahm_id); | ||||||||||||||||||||||||||||||||||
| 1440 | 237 | push @pieces, | |||||||||||||||||||||||||||||||||
| 1441 | 'p=' | ||||||||||||||||||||||||||||||||||
| 1442 | . $predecessor_ahm_desc . '@' | ||||||||||||||||||||||||||||||||||
| 1443 | . $origin_earleme . q{-} | ||||||||||||||||||||||||||||||||||
| 1444 | . $middle_earleme; | ||||||||||||||||||||||||||||||||||
| 1445 | } | ||||||||||||||||||||||||||||||||||
| 1446 | |||||||||||||||||||||||||||||||||||
| 1447 | 237 | push @pieces, | |||||||||||||||||||||||||||||||||
| 1448 | 'c=' | ||||||||||||||||||||||||||||||||||
| 1449 | . $ahm_desc . q{@} | ||||||||||||||||||||||||||||||||||
| 1450 | . $middle_earleme . q{-} | ||||||||||||||||||||||||||||||||||
| 1451 | . $current_earleme; | ||||||||||||||||||||||||||||||||||
| 1452 | 237 | my $link_desc = '[' . ( join '; ', @pieces ) . ']'; | |||||||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||||||||
| 1454 | 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
| |||||||||||||||||||||||||||||||||||
| 1455 | [ | ||||||||||||||||||||||||||||||||||
| 1456 | $middle_earleme, $ahm_id, | ||||||||||||||||||||||||||||||||||
| 1457 | ( $predecessor_ahm_id // -1 ), $link_desc | ||||||||||||||||||||||||||||||||||
| 1458 | ]; | ||||||||||||||||||||||||||||||||||
| 1459 | } | ||||||||||||||||||||||||||||||||||
| 1460 | 237 | push @sorted_data, map { q{ } . $_->[-1] } sort { | |||||||||||||||||||||||||||||||||
| 1461 | 452 | ▶ | $a->[0] <=> $b->[0] | ||||||||||||||||||||||||||||||||
|
Condition50%3/6
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] || $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1] || $Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[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]
MC/DC0%0/3
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] || $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1] || $Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[2]
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0]
$Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
$Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[2]
Truth table50%2/4
A or B || C
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]C= $Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[2]
| |||||||||||||||||||||||||||||||||||
| 1462 | || $a->[1] <=> $b->[1] | ||||||||||||||||||||||||||||||||||
| 1463 | || $a->[2] <=> $b->[2] | ||||||||||||||||||||||||||||||||||
| 1464 | } @sort_data; | ||||||||||||||||||||||||||||||||||
| 1465 | } | ||||||||||||||||||||||||||||||||||
| 1466 | |||||||||||||||||||||||||||||||||||
| 1467 | # Leo links | ||||||||||||||||||||||||||||||||||
| 1468 | { | ||||||||||||||||||||||||||||||||||
| 1469 | 452 | my @sort_data = (); | |||||||||||||||||||||||||||||||||
| 1470 | 452 | my @lines = (); | |||||||||||||||||||||||||||||||||
| 1471 | 452 | my $leo_links = $item_data{leo_links}; | |||||||||||||||||||||||||||||||||
| 1472 | 452 | my %leo_links = @{$leo_links}; | |||||||||||||||||||||||||||||||||
| 1473 | LEO_LINK: | ||||||||||||||||||||||||||||||||||
| 1474 | 452 | for ( my $leo_link_ix = 0 ; ; $leo_link_ix++ ) { | |||||||||||||||||||||||||||||||||
| 1475 | 460 | my $leo_link_data = $leo_links{ $leo_link_ix + 1 }; | |||||||||||||||||||||||||||||||||
| 1476 | 460 | ▶ | last LEO_LINK if not $leo_link_data; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1477 | 8 | my %leo_link_data = @{$leo_link_data}; | |||||||||||||||||||||||||||||||||
| 1478 | |||||||||||||||||||||||||||||||||||
| 1479 | 8 | my $middle_earleme = $leo_link_data{middle_earleme}; | |||||||||||||||||||||||||||||||||
| 1480 | 8 | my $middle_set_id = $leo_link_data{middle_set_id}; | |||||||||||||||||||||||||||||||||
| 1481 | my $leo_transition_symbol = | ||||||||||||||||||||||||||||||||||
| 1482 | 8 | $leo_link_data{leo_transition_symbol}; | |||||||||||||||||||||||||||||||||
| 1483 | 8 | my $ahm_id = $leo_link_data{ahm_id}; | |||||||||||||||||||||||||||||||||
| 1484 | 8 | my $ahm_desc = $slg->briefer_ahm($ahm_id); | |||||||||||||||||||||||||||||||||
| 1485 | |||||||||||||||||||||||||||||||||||
| 1486 | 8 | my @pieces = (); | |||||||||||||||||||||||||||||||||
| 1487 | 8 | push @pieces, | |||||||||||||||||||||||||||||||||
| 1488 | 'l=L' . $leo_transition_symbol . q{@} . $middle_earleme; | ||||||||||||||||||||||||||||||||||
| 1489 | 8 | push @pieces, | |||||||||||||||||||||||||||||||||
| 1490 | 'c=' | ||||||||||||||||||||||||||||||||||
| 1491 | . $ahm_desc . q{@} | ||||||||||||||||||||||||||||||||||
| 1492 | . $middle_earleme . q{-} | ||||||||||||||||||||||||||||||||||
| 1493 | . $current_earleme; | ||||||||||||||||||||||||||||||||||
| 1494 | 8 | my $link_desc = '[' . ( join '; ', @pieces ) . ']'; | |||||||||||||||||||||||||||||||||
| 1495 | |||||||||||||||||||||||||||||||||||
| 1496 | 8 | push @sort_data, | |||||||||||||||||||||||||||||||||
| 1497 | [ | ||||||||||||||||||||||||||||||||||
| 1498 | $middle_set_id, $ahm_id, | ||||||||||||||||||||||||||||||||||
| 1499 | $leo_transition_symbol, $link_desc, | ||||||||||||||||||||||||||||||||||
| 1500 | ]; | ||||||||||||||||||||||||||||||||||
| 1501 | } | ||||||||||||||||||||||||||||||||||
| 1502 | 8 | push @sorted_data, map { q{ } . $_->[-1] } sort { | |||||||||||||||||||||||||||||||||
| 1503 | 0 | ▶ | $a->[0] <=> $b->[0] | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] || $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1] || $Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[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]
MC/DC0%0/3
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0] || $Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1] || $Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[2]
$Marpa::R3::Internal_R::a->[0] <=> $Marpa::R3::Internal_R::b->[0]
$Marpa::R3::Internal_R::a->[1] <=> $Marpa::R3::Internal_R::b->[1]
$Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[2]
Truth table0%0/4
A or B || C
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]C= $Marpa::R3::Internal_R::a->[2] <=> $Marpa::R3::Internal_R::b->[2]
| |||||||||||||||||||||||||||||||||||
| 1504 | || $a->[1] <=> $b->[1] | ||||||||||||||||||||||||||||||||||
| 1505 | || $a->[2] <=> $b->[2] | ||||||||||||||||||||||||||||||||||
| 1506 | } @sort_data; | ||||||||||||||||||||||||||||||||||
| 1507 | } | ||||||||||||||||||||||||||||||||||
| 1508 | } | ||||||||||||||||||||||||||||||||||
| 1509 | |||||||||||||||||||||||||||||||||||
| 1510 | # Leo items | ||||||||||||||||||||||||||||||||||
| 1511 | { | ||||||||||||||||||||||||||||||||||
| 1512 | 59 | my $leo_data = $set_data{leo}; | |||||||||||||||||||||||||||||||||
| 1513 | 59 | my %leo_data = @{$leo_data}; | |||||||||||||||||||||||||||||||||
| 1514 | 59 | my @sort_data = (); | |||||||||||||||||||||||||||||||||
| 1515 | 59 | LEO_ITEM: for ( my $leo_item_id = 0 ; ; $leo_item_id++ ) { | |||||||||||||||||||||||||||||||||
| 1516 | |||||||||||||||||||||||||||||||||||
| 1517 | 67 | my $leo_item_data = $leo_data{ $leo_item_id + 1 }; | |||||||||||||||||||||||||||||||||
| 1518 | 67 | ▶ | last LEO_ITEM if not defined $leo_item_data; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||||||||
| 1520 | 8 | my %leo_item_data = @{$leo_item_data}; | |||||||||||||||||||||||||||||||||
| 1521 | 8 | my $postdot_symbol_id = $leo_item_data{postdot_symbol_id}; | |||||||||||||||||||||||||||||||||
| 1522 | 8 | my $postdot_symbol_name = $leo_item_data{postdot_symbol_name}; | |||||||||||||||||||||||||||||||||
| 1523 | 8 | my $predecessor_symbol_id = $leo_item_data{predecessor_symbol_id}; | |||||||||||||||||||||||||||||||||
| 1524 | 8 | my $base_origin_earleme = $leo_item_data{base_origin_earleme}; | |||||||||||||||||||||||||||||||||
| 1525 | 8 | my $leo_base_state = $leo_item_data{leo_base_state}; | |||||||||||||||||||||||||||||||||
| 1526 | 8 | my $trace_earleme = $leo_item_data{trace_earleme}; | |||||||||||||||||||||||||||||||||
| 1527 | |||||||||||||||||||||||||||||||||||
| 1528 | # L2@8 ["Expression"; L2@6; S16@6-8] | ||||||||||||||||||||||||||||||||||
| 1529 | 8 | my @link_texts = ( q{"} . $postdot_symbol_name . q{"} ); | |||||||||||||||||||||||||||||||||
| 1530 | 8 | ▶ | if ( defined $predecessor_symbol_id ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1531 | 6 | push @link_texts, | |||||||||||||||||||||||||||||||||
| 1532 | sprintf( 'L%d@%d', | ||||||||||||||||||||||||||||||||||
| 1533 | $predecessor_symbol_id, $base_origin_earleme ); | ||||||||||||||||||||||||||||||||||
| 1534 | } | ||||||||||||||||||||||||||||||||||
| 1535 | 8 | push @link_texts, | |||||||||||||||||||||||||||||||||
| 1536 | sprintf( 'S%d@%d-%d', | ||||||||||||||||||||||||||||||||||
| 1537 | $leo_base_state, $base_origin_earleme, $trace_earleme ); | ||||||||||||||||||||||||||||||||||
| 1538 | 8 | my $leo_line = sprintf( 'L%d@%d [%s]', | |||||||||||||||||||||||||||||||||
| 1539 | $postdot_symbol_id, $trace_earleme, | ||||||||||||||||||||||||||||||||||
| 1540 | ( join q{; }, @link_texts ) ); | ||||||||||||||||||||||||||||||||||
| 1541 | 8 | push @sort_data, [ $postdot_symbol_id, $leo_line ]; | |||||||||||||||||||||||||||||||||
| 1542 | push @sorted_data, | ||||||||||||||||||||||||||||||||||
| 1543 | ( | ||||||||||||||||||||||||||||||||||
| 1544 | join q{}, | ||||||||||||||||||||||||||||||||||
| 1545 | 0 | map { $_->[-1] } sort { $a->[0] <=> $b->[0] } @sort_data | |||||||||||||||||||||||||||||||||
| 1546 | ); | ||||||||||||||||||||||||||||||||||
| 1547 | } | ||||||||||||||||||||||||||||||||||
| 1548 | } | ||||||||||||||||||||||||||||||||||
| 1549 | |||||||||||||||||||||||||||||||||||
| 1550 | 59 | return join "\n", @sorted_data, q{}; | |||||||||||||||||||||||||||||||||
| 1551 | } | ||||||||||||||||||||||||||||||||||
| 1552 | |||||||||||||||||||||||||||||||||||
| 1553 | # not to be documented | ||||||||||||||||||||||||||||||||||
| 1554 | 1 | ▶ | sub Marpa::R3::Recognizer::regix { | ||||||||||||||||||||||||||||||||
|
Subroutine
regix: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 1555 | 1 | my ( $slr ) = @_; | |||||||||||||||||||||||||||||||||
| 1556 | 1 | my $regix = $slr->[Marpa::R3::Internal_R::REGIX]; | |||||||||||||||||||||||||||||||||
| 1557 | 1 | return $regix; | |||||||||||||||||||||||||||||||||
| 1558 | } | ||||||||||||||||||||||||||||||||||
| 1559 | |||||||||||||||||||||||||||||||||||
| 1560 | # Dump semantics for diagnostics | ||||||||||||||||||||||||||||||||||
| 1561 | 0 | ▶ | sub Marpa::R3::Recognizer::show_semantics { | ||||||||||||||||||||||||||||||||
|
Subroutine
show_semantics: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 1562 | 0 | my ( $slg, @ops ) = @_; | |||||||||||||||||||||||||||||||||
| 1563 | 0 | my @op_descs = (); | |||||||||||||||||||||||||||||||||
| 1564 | 0 | my $op_ix = 0; | |||||||||||||||||||||||||||||||||
| 1565 | 0 | ▶ | OP: while ( $op_ix < scalar @ops ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1566 | 0 | my $op = $ops[ $op_ix++ ]; | |||||||||||||||||||||||||||||||||
| 1567 | |||||||||||||||||||||||||||||||||||
| 1568 | 0 | my $op_name = $slg->call_by_tag( ( '@' . __FILE__ . ':' . __LINE__ ), | |||||||||||||||||||||||||||||||||
| 1569 | <<'END_OF_LUA', 'i', $op ); | ||||||||||||||||||||||||||||||||||
| 1570 | local grammar, op = ... | ||||||||||||||||||||||||||||||||||
| 1571 | return _M.op_names[op] | ||||||||||||||||||||||||||||||||||
| 1572 | END_OF_LUA | ||||||||||||||||||||||||||||||||||
| 1573 | |||||||||||||||||||||||||||||||||||
| 1574 | 0 | push @op_descs, $op_name; | |||||||||||||||||||||||||||||||||
| 1575 | 0 | ▶ | if ( $op_name eq 'lua' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1576 | |||||||||||||||||||||||||||||||||||
| 1577 | 0 | my ($lua_op_name) = op_fn_name_by_key( $slg, $ops[$op_ix] ); | |||||||||||||||||||||||||||||||||
| 1578 | 0 | push @op_descs, $lua_op_name; | |||||||||||||||||||||||||||||||||
| 1579 | 0 | $op_ix++; | |||||||||||||||||||||||||||||||||
| 1580 | 0 | ▶ | if ( $lua_op_name eq 'callback' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1581 | 0 | push @op_descs, op_fn_name_by_key( $slg, $ops[$op_ix] ); | |||||||||||||||||||||||||||||||||
| 1582 | } | ||||||||||||||||||||||||||||||||||
| 1583 | else { | ||||||||||||||||||||||||||||||||||
| 1584 | 0 | push @op_descs, $ops[$op_ix]; | |||||||||||||||||||||||||||||||||
| 1585 | } | ||||||||||||||||||||||||||||||||||
| 1586 | 0 | $op_ix++; | |||||||||||||||||||||||||||||||||
| 1587 | 0 | next OP; | |||||||||||||||||||||||||||||||||
| 1588 | } | ||||||||||||||||||||||||||||||||||
| 1589 | 0 | ▶ | if ( $op_name eq 'alternative' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1590 | 0 | push @op_descs, $ops[$op_ix]; | |||||||||||||||||||||||||||||||||
| 1591 | 0 | $op_ix++; | |||||||||||||||||||||||||||||||||
| 1592 | 0 | push @op_descs, $ops[$op_ix]; | |||||||||||||||||||||||||||||||||
| 1593 | 0 | $op_ix++; | |||||||||||||||||||||||||||||||||
| 1594 | 0 | next OP; | |||||||||||||||||||||||||||||||||
| 1595 | } ## end if ( $op_name eq 'alternative' ) | ||||||||||||||||||||||||||||||||||
| 1596 | } ## end OP: while ( $op_ix < scalar @ops ) | ||||||||||||||||||||||||||||||||||
| 1597 | 0 | return join q{ }, @op_descs; | |||||||||||||||||||||||||||||||||
| 1598 | } ## end sub show_semantics | ||||||||||||||||||||||||||||||||||
| 1599 | |||||||||||||||||||||||||||||||||||
| 1600 | # For diagnostics | ||||||||||||||||||||||||||||||||||
| 1601 | 0 | ▶ | sub g1_show_rule_list { | ||||||||||||||||||||||||||||||||
|
Subroutine
g1_show_rule_list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 1602 | 0 | my ( $slg, $rule_ids ) = @_; | |||||||||||||||||||||||||||||||||
| 1603 | 0 | my @rules = map { $slg->g1_rule_show($_) } @{$rule_ids}; | |||||||||||||||||||||||||||||||||
| 1604 | 0 | return join q{}, map { q{ } . $_ . "\n" } @rules; | |||||||||||||||||||||||||||||||||
| 1605 | } | ||||||||||||||||||||||||||||||||||
| 1606 | |||||||||||||||||||||||||||||||||||
| 1607 | 739 | ▶ | sub Marpa::R3::Recognizer::value { | ||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 1608 | 739 | my ( $slr, $per_parse_arg ) = @_; | |||||||||||||||||||||||||||||||||
| 1609 | 739 | my $slv = Marpa::R3::Valuer->new( { recognizer => $slr } ); | |||||||||||||||||||||||||||||||||
| 1610 | 739 | my $ambiguity_level = $slv->ambiguity_level(); | |||||||||||||||||||||||||||||||||
| 1611 | 739 | ▶ | return if $ambiguity_level == 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1612 | 719 | ▶ | if ( $ambiguity_level != 1 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1613 | 1 | my $ambiguous_status = $slv->ambiguous(); | |||||||||||||||||||||||||||||||||
| 1614 | 1 | Marpa::R3::exception( "Parse of the input is ambiguous\n", | |||||||||||||||||||||||||||||||||
| 1615 | $ambiguous_status ); | ||||||||||||||||||||||||||||||||||
| 1616 | } | ||||||||||||||||||||||||||||||||||
| 1617 | 718 | my $value_ref = $slv->value($per_parse_arg); | |||||||||||||||||||||||||||||||||
| 1618 | 708 | ▶ | Marpa::R3::exception("$slr->value(): No parse\n") | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 1619 | if not $value_ref; | ||||||||||||||||||||||||||||||||||
| 1620 | 708 | return $value_ref; | |||||||||||||||||||||||||||||||||
| 1621 | } | ||||||||||||||||||||||||||||||||||
| 1622 | |||||||||||||||||||||||||||||||||||
| 1623 | # INTERNAL OK AFTER HERE _marpa_ | ||||||||||||||||||||||||||||||||||
| 1624 | |||||||||||||||||||||||||||||||||||
| 1625 | 104 | 1; | |||||||||||||||||||||||||||||||||
| 1626 | |||||||||||||||||||||||||||||||||||
| 1627 | # vim: expandtab shiftwidth=4: | ||||||||||||||||||||||||||||||||||