blib/lib/Marpa/R2/SLR.pm

filter: Statementstmt 73.0% 790 / 1081 Branchbran 56.0% 196 / 350 Conditioncond 52.9% 54 / 102 MC/DCmcdc 27.8% 17 / 61 Subroutinesub 73.0% 65 / 89 Podpod n/a totaltotal 66.6% 1122 / 1683 SCAR 76.8
CC
240
Cov
68%
read_problem
74.5
reversed_input_escape
56.0
new
36.7
CRAP 2155.7
« blib/lib/Marpa/R2/Value.pm ↑ Summary blib/lib/Marpa/R2/Grammar.pm »
1 # Copyright 2022 Jeffrey Kegler
2 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
3 # redistribute it and/or modify it under the terms of the GNU Lesser
4 # General Public License as published by the Free Software Foundation,
5 # either version 3 of the License, or (at your option) any later version.
6 #
7 # Marpa::R2 is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 # Lesser General Public License for more details.
11 #
12 # You should have received a copy of the GNU Lesser
13 # General Public License along with Marpa::R2. If not, see
14 # http://www.gnu.org/licenses/.
15  
16 package Marpa::R2::Scanless::R;
17  
18 150 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 150 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 150 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 150 ▶use vars qw($VERSION $STRING_VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 150 $VERSION = '13.003_000';
24 150 $STRING_VERSION = $VERSION;
25 ## no critic(BuiltinFunctions::ProhibitStringyEval)
26 150 $VERSION = eval $VERSION;
27 ## use critic
28  
29 package Marpa::R2::Internal::Scanless::R;
30  
31 150 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 150 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 150 our $PACKAGE = 'Marpa::R2::Scanless::R';
35 150 our $TRACE_FILE_HANDLE;
36  
37 sub Marpa::R2::Scanless::R::last_completed_range {
38 43 ▶ my ( $self, $symbol_name ) = @_;
Subroutine last_completed_range: called CC=2 SCAR=6.9
39 43 my ( $start, $length ) = $self->last_completed($symbol_name);
40 43 ▶ return if not defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 12 31 43
41 31 my $end = $start + $length;
42 31 return ( $start, $end );
43 } ## end sub Marpa::R2::Scanless::R::last_completed_range
44  
45 # Given a scanless
46 # recognizer and a symbol,
47 # return the start earley set
48 # and length
49 # of the last such symbol completed,
50 # undef if there was none.
51 sub Marpa::R2::Scanless::R::last_completed {
52 86 ▶ my ( $slr, $symbol_name ) = @_;
Subroutine last_completed: called CC=11 SCAR=24.0
53 86 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
54 86 my $thick_g1_grammar =
55 $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR];
56 86 my $thick_g1_recce =
57 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
58 86 my $thin_g1_recce = $thick_g1_recce->thin();
59 my $sought_rules =
60 $slg->[Marpa::R2::Internal::Scanless::G::CACHE_RULEIDS_BY_LHS_NAME]
61 86 ->{$symbol_name};
62 86 ▶ if ( not defined $sought_rules ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sought_rules) 25 61 86
63 25 my $g1_tracer = $thick_g1_grammar->tracer();
64 25 my $thin_g1_grammar = $thick_g1_grammar->thin();
65 25 my $symbol_id = $g1_tracer->symbol_by_name($symbol_name);
66 25 ▶ Marpa::R2::exception("Bad symbol in last_completed(): $symbol_name")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $symbol_id 0 25 25
67 if not defined $symbol_id;
68 $sought_rules =
69 $slg->[Marpa::R2::Internal::Scanless::G::CACHE_RULEIDS_BY_LHS_NAME]
70 ->{$symbol_name} =
71 25 [ grep { $thin_g1_grammar->rule_lhs($_) == $symbol_id; }
72 0 .. $thin_g1_grammar->highest_rule_id() ];
73 Marpa::R2::exception(
74 "Looking for completion of non-existent rule lhs: $symbol_name")
75 25 ▶ if not scalar @{$sought_rules};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$sought_rules;} 0 25 25
76 } ## end if ( not defined $sought_rules )
77 86 my $latest_earley_set = $thin_g1_recce->latest_earley_set();
78 86 my $earley_set = $latest_earley_set;
79  
80 # Initialize to one past the end, so we can tell if there were no hits
81 86 my $first_origin = $latest_earley_set + 1;
82 86 ▶ EARLEY_SET: while ( $earley_set >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($earley_set >= 0) 151 12 163
83 151 $thin_g1_recce->progress_report_start($earley_set);
84 151 ITEM: while (1) {
85 999 my ( $rule_id, $dot_position, $origin ) =
86 $thin_g1_recce->progress_item();
87 999 ▶ last ITEM if not defined $rule_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule_id 151 848 999
88 848 ▶ next ITEM if $dot_position != -1;
Branch: 1 branch
BranchTrueFalseTotal
if $dot_position != -1 522 326 848
89 326 ▶ next ITEM if not scalar grep { $_ == $rule_id } @{$sought_rules};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar grep({$_ == $rule_id;} @{$sought_rules;}) 250 76 326
90 76 ▶ next ITEM if $origin >= $first_origin;
Branch: 1 branch
BranchTrueFalseTotal
if $origin >= $first_origin 0 76 76
91 76 $first_origin = $origin;
92 } ## end ITEM: while (1)
93 151 $thin_g1_recce->progress_report_finish();
94 151 ▶ last EARLEY_SET if $first_origin <= $latest_earley_set;
Branch: 1 branch
BranchTrueFalseTotal
if $first_origin <= $latest_earley_set 74 77 151
95 77 $earley_set--;
96 } ## end EARLEY_SET: while ( $earley_set >= 0 )
97 86 ▶ return if $earley_set < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $earley_set < 0 12 74 86
98 74 return ( $first_origin, ( $earley_set - $first_origin ) );
99 } ## end sub Marpa::R2::Scanless::R::last_completed
100  
101 # Returns most input stream span for symbol.
102 # If more than one ends at the same location,
103 # returns the longest.
104 # Returns under if there is no such span.
105 # Other failure is thrown.
106 sub Marpa::R2::Scanless::R::last_completed_span {
107 43 ▶ my ( $slr, $symbol_name ) = @_;
Subroutine last_completed_span: called CC=2 SCAR=7.0
108 43 my ($g1_origin, $g1_span) = $slr->last_completed( $symbol_name );
109 43 ▶ return if not defined $g1_origin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $g1_origin 0 43 43
110 43 my ($start_input_location) = $slr->g1_location_to_span($g1_origin + 1);
111 43 my @end_span = $slr->g1_location_to_span($g1_origin + $g1_span);
112 43 return ($start_input_location, ($end_span[0]+$end_span[1])-$start_input_location);
113 }
114  
115 # In terms of earley sets.
116 # Kept for backward compatibiity
117 sub Marpa::R2::Scanless::R::range_to_string {
118 31 ▶ my ( $self, $start_earley_set, $end_earley_set ) = @_;
Subroutine range_to_string: called CC=1 SCAR=0.0
119 31 return $self->substring( $start_earley_set,
120 $end_earley_set - $start_earley_set );
121 }
122  
123 # Not documented. Should I?
124 sub Marpa::R2::Scanless::R::es_to_input_span {
125 1498 ▶ my ( $slr, $start_earley_set, $length_in_parse_locations ) = @_;
Subroutine es_to_input_span: called CC=6 SCAR=18.6
126 return
127 1498 ▶ if not defined $start_earley_set
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start_earley_set and defined $length_in_parse_locations 0 1498 1498
Condition33%1/3
defined $start_earley_set and defined $length_in_parse_locations
!ll&&!rl&&r
001498
MC/DC0%0/2
defined $start_earley_set and defined $length_in_parse_locations
defined $start_earley_set defined $length_in_parse_locations
Truth table33%1/3
A and B
A= defined $start_earley_setB= defined $length_in_parse_locations
ABresult
0X0
100
111
128 or not defined $length_in_parse_locations;
129 1498 my $thick_g1_recce =
130 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
131 1498 my $thin_g1_recce = $thick_g1_recce->thin();
132 1498 my $latest_earley_set = $thin_g1_recce->latest_earley_set();
133  
134 1498 my $earley_set_for_first_position = $start_earley_set + 1;
135 1498 my $earley_set_for_last_position =
136 $start_earley_set + $length_in_parse_locations;
137  
138 1498 ▶ die 'Error in $slr->substring(',
Branch: 1 branch
BranchTrueFalseTotal
if $earley_set_for_first_position > $latest_earley_set 0 1498 1498
139 "$start_earley_set, $length_in_parse_locations", '): ',
140 "start ($start_earley_set) is at or after latest_earley_set ($latest_earley_set)"
141 if $earley_set_for_first_position > $latest_earley_set;
142 1498 ▶ die 'Error in $slr->substring(',
Branch: 1 branch
BranchTrueFalseTotal
if $earley_set_for_last_position > $latest_earley_set 0 1498 1498
143 "$start_earley_set, $length_in_parse_locations", '): ',
144 "end ( $start_earley_set + $length_in_parse_locations ) is after latest_earley_set ($latest_earley_set)"
145 if $earley_set_for_last_position > $latest_earley_set;
146  
147 1498 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
148 1498 my ($first_start_position) =
149 $thin_slr->span($earley_set_for_first_position);
150 1498 my ( $last_start_position, $last_length ) =
151 $thin_slr->span($earley_set_for_last_position);
152 1498 my $length_in_characters =
153 ( $last_start_position + $last_length ) - $first_start_position;
154  
155 # Negative lengths are quite possible if the application has jumped around in
156 # the input.
157 1498 ▶ $length_in_characters = 0 if $length_in_characters <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $length_in_characters <= 0 0 1498 1498
158 1498 return ( $first_start_position, $length_in_characters );
159  
160 } ## end sub Marpa::R2::Scanless::R::es_to_input_span
161  
162 # Substring in terms of earley sets.
163 # Necessary for the use of show_progress()
164 # Given a scanless recognizer and
165 # and two earley sets, return the input string
166 sub Marpa::R2::Scanless::R::substring {
167 1435 ▶ my ( $slr, $start_earley_set, $length_in_parse_locations ) = @_;
Subroutine substring: called CC=1 SCAR=0.0
168 1435 my ( $first_start_position, $length_in_characters ) =
169 $slr->es_to_input_span( $start_earley_set,
170 $length_in_parse_locations );
171 1435 my $p_input = $slr->[Marpa::R2::Internal::Scanless::R::P_INPUT_STRING];
172 1435 return substr ${$p_input}, $first_start_position, $length_in_characters;
173 } ## end sub Marpa::R2::Scanless::R::substring
174  
175 sub Marpa::R2::Scanless::R::g1_location_to_span {
176 210 ▶ my ( $self, $g1_location ) = @_;
Subroutine g1_location_to_span: called CC=1 SCAR=0.0
177 210 my $thin_self = $self->[Marpa::R2::Internal::Scanless::R::C];
178 210 return $thin_self->span($g1_location);
179 }
180  
181 # Substring in terms of locations in the input stream
182 # This is the one users will be most interested in.
183 sub Marpa::R2::Scanless::R::literal {
184 181 ▶ my ( $slr, $start_pos, $length ) = @_;
Subroutine literal: called CC=1 SCAR=0.0
185 181 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
186 181 return $thin_slr->substring( $start_pos, $length );
187 } ## end sub Marpa::R2::Scanless::R::literal
188  
189 sub Marpa::R2::Internal::Scanless::meta_recce {
190 217 ▶ my ($hash_args) = @_;
Subroutine meta_recce: called CC=1 SCAR=0.0
191 217 state $meta_grammar = Marpa::R2::Internal::Scanless::meta_grammar();
192 217 $hash_args->{grammar} = $meta_grammar;
193 217 my $self = Marpa::R2::Scanless::R->new($hash_args);
194 217 return $self;
195 } ## end sub Marpa::R2::Internal::Scanless::meta_recce
196  
197 # For error messages, make it convenient to use an SLR
198 sub Marpa::R2::Scanless::R::rule_show {
199 1 ▶ my ( $slr, $rule_id ) = @_;
Subroutine rule_show: called CC=1 SCAR=0.0
200 1 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
201 1 return $slg->rule_show($rule_id);
202 }
203  
204 sub Marpa::R2::Scanless::R::new {
205 975 ▶ my ( $class, @args ) = @_;
Subroutine new: called CC=28 SCAR=36.0
206  
207 975 my $slr = [];
208 975 bless $slr, $class;
209  
210 # Set SLIF (not NAIF) recognizer args to default
211 975 $slr->[Marpa::R2::Internal::Scanless::R::EXHAUSTION_ACTION] = 'fatal';
212 975 $slr->[Marpa::R2::Internal::Scanless::R::REJECTION_ACTION] = 'fatal';
213 975 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_LEXERS] = 0;
214 975 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_TERMINALS] = 0;
215  
216 975 my ($g1_recce_args, $flat_args) =
217 Marpa::R2::Internal::Scanless::R::set( $slr, "new", @args );
218 975 my $too_many_earley_items = $g1_recce_args->{too_many_earley_items};
219  
220 975 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
221  
222 975 ▶ Marpa::R2::exception(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $slg 0 975 975
223 qq{Marpa::R2::Scanless::R::new() called without a "grammar" argument}
224 ) if not defined $slg;
225  
226 975 my $slg_class = 'Marpa::R2::Scanless::G';
227 975 ▶ if ( not blessed $slg or not $slg->isa($slg_class) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($slg) and $slg->isa($slg_class)) 0 975 975
Condition33%1/3
builtin::blessed($slg) and $slg->isa($slg_class)
!ll&&!rl&&r
00975
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)
ABresult
0X0
100
111
228 0 my $ref_type = ref $slg;
229 0 ▶ my $desc = $ref_type ? "a ref to $ref_type" : 'not a ref';
Branch: 1 branch
BranchTrueFalseTotal
$ref_type ? : 0 0 0
230 0 Marpa::R2::exception(
231 qq{'grammar' named argument to new() is $desc\n},
232 " It should be a ref to $slg_class\n" );
233 } ## end if ( not blessed $slg or not $slg->isa($slg_class) )
234  
235 975 my $thick_g1_grammar =
236 $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR];
237  
238 975 my $trace_file_handle = $g1_recce_args->{trace_file_handle};
239 975 ▶ $trace_file_handle //= $thick_g1_grammar->[Marpa::R2::Internal::Grammar::TRACE_FILE_HANDLE] ;
Condition66%2/3
$trace_file_handle //= $thick_g1_grammar->[8]
l!l&&r!l&&!r
19740
MC/DC0%0/2
$trace_file_handle //= $thick_g1_grammar->[8]
$trace_file_handle $thick_g1_grammar->[8]
Truth table66%2/3
A //= B
A= $trace_file_handleB= $thick_g1_grammar->[8]
ABresult
1X1
011
000
240  
241 975 my $thick_g1_recce =
242 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE] = bless [],
243 'Marpa::R2::Recognizer';
244  
245 975 local $Marpa::R2::Internal::TRACE_FH =
246 $thick_g1_recce->[Marpa::R2::Internal::Recognizer::TRACE_FILE_HANDLE] = $trace_file_handle;
247  
248 975 $thick_g1_recce->[Marpa::R2::Internal::Recognizer::GRAMMAR] = $thick_g1_grammar;
249  
250 975 my $grammar_c = $thick_g1_grammar->[Marpa::R2::Internal::Grammar::C];
251  
252 975 my $recce_c = $thick_g1_recce->[Marpa::R2::Internal::Recognizer::C] =
253 Marpa::R2::Thin::R->new($grammar_c);
254 975 ▶ if ( not defined $recce_c ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $recce_c) 0 975 975
255 0 Marpa::R2::exception( $grammar_c->error() );
256 }
257  
258 975 $recce_c->ruby_slippers_set(1);
259  
260 975 ▶ if ( defined $thick_g1_grammar->[Marpa::R2::Internal::Grammar::ACTION_OBJECT]
Branch: 1 branch
BranchTrueFalseTotal
if (defined $thick_g1_grammar->[15] or defined $thick_g1_grammar->[5] or not defined $thick_g1_grammar->[11]) 0 974 974
Condition66%4/6
defined $thick_g1_grammar->[15] or defined $thick_g1_grammar->[5] or not defined $thick_g1_grammar->[11]
l!l&&r!l&&!r
10974
defined $thick_g1_grammar->[15] or defined $thick_g1_grammar->[5]
l!l&&r!l&&!r
10974
MC/DC33%1/3
defined $thick_g1_grammar->[15] or defined $thick_g1_grammar->[5] or not defined $thick_g1_grammar->[11]
defined $thick_g1_grammar->[15] defined $thick_g1_grammar->[5] not defined $thick_g1_grammar->[11]
Truth table50%2/4
A or B or not(C)
A= defined $thick_g1_grammar->[15]B= defined $thick_g1_grammar->[5]C= not defined $thick_g1_grammar->[11]
ABCresult
1XX1
01X1
0011
0000
261 or defined $thick_g1_grammar->[Marpa::R2::Internal::Grammar::ACTIONS]
262 or not defined $thick_g1_grammar->[Marpa::R2::Internal::Grammar::INTERNAL] )
263 {
264 1 $thick_g1_recce->[Marpa::R2::Internal::Recognizer::RESOLVE_PACKAGE_SOURCE] =
265 'legacy';
266 } ## end if ( defined $grammar->[...])
267  
268 975 ▶ if ( defined( my $value = $g1_recce_args->{'leo'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = $g1_recce_args->{"leo"})) 0 975 975
269 0 ▶ my $boolean = $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
270 0 $thick_g1_recce->use_leo_set($boolean);
271 0 delete $g1_recce_args->{leo};
272 }
273  
274 975 $thick_g1_recce->[Marpa::R2::Internal::Recognizer::WARNINGS] = 1;
275 975 $thick_g1_recce->[Marpa::R2::Internal::Recognizer::RANKING_METHOD] = 'none';
276 975 $thick_g1_recce->[Marpa::R2::Internal::Recognizer::MAX_PARSES] = 0;
277 975 $thick_g1_recce->[Marpa::R2::Internal::Recognizer::TRACE_TERMINALS] = 0;
278  
279 # Position 0 is not used because 0 indicates an unvalued token.
280 # Position 1 is reserved for undef.
281 # Position 2 is reserved for literal tokens (used in SLIF).
282 975 $thick_g1_recce->[Marpa::R2::Internal::Recognizer::TOKEN_VALUES] = [undef, undef, undef];
283  
284 975 $thick_g1_recce->reset_evaluation();
285  
286 975 my $thin_slr =
287 Marpa::R2::Thin::SLR->new( $slg->[Marpa::R2::Internal::Scanless::G::C],
288 $thick_g1_recce->thin() );
289 975 ▶ $thin_slr->earley_item_warning_threshold_set($too_many_earley_items)
Branch: 1 branch
BranchTrueFalseTotal
if defined $too_many_earley_items 1 974 975
290 if defined $too_many_earley_items;
291 975 $slr->[Marpa::R2::Internal::Scanless::R::C] = $thin_slr;
292 975 $slr->[Marpa::R2::Internal::Scanless::R::EVENTS] = [];
293  
294 975 my $symbol_ids_by_event_name_and_type =
295 $slg->[
296 Marpa::R2::Internal::Scanless::G::SYMBOL_IDS_BY_EVENT_NAME_AND_TYPE];
297  
298 975 ▶ my $event_is_active_arg = $flat_args->{event_is_active} // {};
Condition100%2/2
$flat_args->{"event_is_active"} // {}
l!l
308667
MC/DC100%1/1
$flat_args->{"event_is_active"} // {}
$flat_args->{"event_is_active"}
Truth table100%2/2
A
A= $flat_args->{"event_is_active"}
Aresult
11
00
299 975 ▶ if (ref $event_is_active_arg ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $event_is_active_arg ne "HASH") 0 975 975
300 0 Marpa::R2::exception( 'event_is_active named argument must be ref to hash' );
301 }
302  
303 # Completion/nulled/prediction events are always initialized by
304 # Libmarpa to 'on'. So here we need to override that if and only
305 # if we in fact want to initialize them to 'off'.
306  
307 # Events are already initialized as described by
308 # the DSL. Here we override that with the recce arg, if
309 # necessary.
310
311 975 EVENT: for my $event_name ( keys %{$event_is_active_arg} ) {
312  
313 470 my $is_active = $event_is_active_arg->{$event_name};
314  
315 my $symbol_ids =
316 470 $symbol_ids_by_event_name_and_type->{$event_name}->{lexeme};
317 $thin_slr->lexeme_event_activate( $_, $is_active )
318 470 for @{$symbol_ids};
319 my $lexer_rule_ids =
320 470 $symbol_ids_by_event_name_and_type->{$event_name}->{discard};
321 $thin_slr->discard_event_activate( $_, $is_active )
322 470 for @{$lexer_rule_ids};
323  
324 $symbol_ids =
325 $symbol_ids_by_event_name_and_type->{$event_name}->{completion}
326 470 ▶ // [];
Condition100%2/2
$symbol_ids_by_event_name_and_type->{$event_name}{"completion"} // []
l!l
54416
MC/DC100%1/1
$symbol_ids_by_event_name_and_type->{$event_name}{"completion"} // []
$symbol_ids_by_event_name_and_type->{$event_name}{"completion"}
Truth table100%2/2
A
A= $symbol_ids_by_event_name_and_type->{$event_name}{"completion"}
Aresult
11
00
327 $recce_c->completion_symbol_activate( $_, $is_active )
328 470 for @{$symbol_ids};
329 $symbol_ids =
330 470 ▶ $symbol_ids_by_event_name_and_type->{$event_name}->{nulled} // [];
Condition100%2/2
$symbol_ids_by_event_name_and_type->{$event_name}{"nulled"} // []
l!l
42428
MC/DC100%1/1
$symbol_ids_by_event_name_and_type->{$event_name}{"nulled"} // []
$symbol_ids_by_event_name_and_type->{$event_name}{"nulled"}
Truth table100%2/2
A
A= $symbol_ids_by_event_name_and_type->{$event_name}{"nulled"}
Aresult
11
00
331 470 $recce_c->nulled_symbol_activate( $_, $is_active ) for @{$symbol_ids};
332 $symbol_ids =
333 $symbol_ids_by_event_name_and_type->{$event_name}->{prediction}
334 470 ▶ // [];
Condition100%2/2
$symbol_ids_by_event_name_and_type->{$event_name}{"prediction"} // []
l!l
54416
MC/DC100%1/1
$symbol_ids_by_event_name_and_type->{$event_name}{"prediction"} // []
$symbol_ids_by_event_name_and_type->{$event_name}{"prediction"}
Truth table100%2/2
A
A= $symbol_ids_by_event_name_and_type->{$event_name}{"prediction"}
Aresult
11
00
335 $recce_c->prediction_symbol_activate( $_, $is_active )
336 470 for @{$symbol_ids};
337 } ## end EVENT: for my $event_name ( keys %{$event_is_active_arg} )
338  
339 975 ▶ if ( not $recce_c->start_input() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($recce_c->start_input) 0 975 975
340 0 my $error = $grammar_c->error();
341 0 Marpa::R2::exception( 'Recognizer start of input failed: ', $error );
342 }
343  
344 975 $thick_g1_recce->set($g1_recce_args);
345  
346 975 ▶ if ( $thick_g1_recce->[Marpa::R2::Internal::Recognizer::TRACE_TERMINALS] > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thick_g1_recce->[21] > 1) 1 974 975
347 1 my @terminals_expected = @{ $thick_g1_recce->terminals_expected() };
348 1 for my $terminal ( sort @terminals_expected ) {
349 3 ▶ say {$Marpa::R2::Internal::TRACE_FH}
Branch: 1 branch
BranchTrueFalseTotal
say {$Marpa::R2::Internal::TRACE_FH;} qq[Expecting "$terminal" at earleme 0] or Marpa::R2::exception("Cannot print: $Marpa::R2::Internal::Scanless::R::ERRNO") 0 3 3
350 qq{Expecting "$terminal" at earleme 0}
351 or Marpa::R2::exception("Cannot print: $ERRNO");
352 }
353 } ## end if ( $thick_g1_recce->[Marpa::R2::Internal::Recognizer::TRACE_TERMINALS...])
354  
355 975 Marpa::R2::Internal::Scanless::convert_libmarpa_events($slr);
356  
357 975 return $slr;
358 } ## end sub Marpa::R2::Scanless::R::new
359  
360 sub Marpa::R2::Scanless::R::set {
361 11 ▶ my ( $slr, @args ) = @_;
Subroutine set: called CC=1 SCAR=0.0
362 11 my $naif_recce_args =
363 Marpa::R2::Internal::Scanless::R::set( $slr, "set", @args );
364 11 my $naif_recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
365 11 $naif_recce->set($naif_recce_args);
366 11 return $slr;
367 } ## end sub Marpa::R2::Scanless::R::set
368  
369 # The context flag indicates whether this set is called directly by the user
370 # or is for series reset or the constructor. "Context" flags of this kind
371 # are much decried practice, and for good reason, but in this case
372 # I think it is justified.
373 # This logic really needs to be all in one place, and so a flag
374 # to trigger the minor differences needed by the various calling
375 # contexts is a small price to pay.
376 sub Marpa::R2::Internal::Scanless::R::set {
377  
378 1042 ▶ my ( $slr, $method, @hash_ref_args ) = @_;
Subroutine set: called CC=21 SCAR=31.2
379  
380 # These NAIF recce args are allowed in all contexts
381 state $common_naif_recce_args = {
382 1042 map { ( $_, 1 ); }
383 qw(end max_parses semantics_package too_many_earley_items
384 trace_actions trace_file_handle trace_terminals trace_values)
385 };
386 state $common_slif_recce_args =
387 1042 { map { ( $_, 1 ); } qw(trace_lexers rejection exhaustion) };
388 state $set_method_args = {
389 935 map { ( $_, 1 ); } (
390 85 keys %{$common_slif_recce_args},
391 1042 keys %{$common_naif_recce_args}
392 )
393 };
394 state $new_method_args = {
395 1190 map { ( $_, 1 ); } qw(grammar ranking_method event_is_active),
396 1042 keys %{$set_method_args}
397 };
398 state $series_restart_method_args = {
399 935 map { ( $_, 1 ); } (
400 85 keys %{$common_slif_recce_args},
401 1042 keys %{$common_naif_recce_args}
402 )
403 };
404  
405 1042 for my $args (@hash_ref_args) {
406 1414 my $ref_type = ref $args;
407 1414 ▶ if ( not $ref_type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref_type) 0 1414 1414
408 0 Marpa::R2::exception( q{$slr->}
409 . $method
410 . qq{() expects args as ref to HASH; got non-reference instead}
411 );
412 } ## end if ( not $ref_type )
413 1414 ▶ if ( $ref_type ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_type ne "HASH") 0 1414 1414
414 0 Marpa::R2::exception( q{$slr->}
415 . $method
416 . qq{() expects args as ref to HASH, got ref to $ref_type instead}
417 );
418 } ## end if ( $ref_type ne 'HASH' )
419 } ## end for my $args (@hash_ref_args)
420  
421 1042 my %flat_args = ();
422 1042 for my $hash_ref (@hash_ref_args) {
423 1414 ARG: for my $arg_name ( keys %{$hash_ref} ) {
424 1570 $flat_args{$arg_name} = $hash_ref->{$arg_name};
425 }
426 }
427 1042 my $ok_args = $set_method_args;
428 1042 ▶ $ok_args = $new_method_args if $method eq 'new';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "new" 975 67 1042
429 1042 ▶ $ok_args = $series_restart_method_args if $method eq 'series_restart';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "series_restart" 56 986 1042
430 1042 my @bad_args = grep { not $ok_args->{$_} } keys %flat_args;
431 1042 ▶ if ( scalar @bad_args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @bad_args) 0 1042 1042
432 0 Marpa::R2::exception(
433 q{Bad named argument(s) to $slr->}
434 . $method
435 . q{() method: }
436 . join q{ },
437 @bad_args
438 );
439 } ## end if ( scalar @bad_args )
440  
441 # Special SLIF (not NAIF) recce arg processing goes here
442 1042 ▶ if ( exists $flat_args{'exhaustion'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $flat_args{"exhaustion"}) 26 1016 1042
443  
444 26 state $exhaustion_actions = { map { ( $_, 0 ) } qw(fatal event) };
445 26 ▶ my $value = $flat_args{'exhaustion'} // 'undefined';
Condition50%1/2
$flat_args{"exhaustion"} // "undefined"
l!l
260
MC/DC0%0/1
$flat_args{"exhaustion"} // "undefined"
$flat_args{"exhaustion"}
Truth table50%1/2
A
A= $flat_args{"exhaustion"}
Aresult
11
00
446 Marpa::R2::exception(
447 qq{'exhaustion' named arg value is $value (should be one of },
448 ( join q{, },
449 0 map { q{'} . $_ . q{'} } keys %{$exhaustion_actions}
450 ),
451 ')'
452 26 ▶ ) if not exists $exhaustion_actions->{$value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $exhaustion_actions->{$value} 0 26 26
453 26 $slr->[Marpa::R2::Internal::Scanless::R::EXHAUSTION_ACTION] = $value;
454  
455 } ## end if ( exists $flat_args{'exhaustion'} )
456  
457 # Special SLIF (not NAIF) recce arg processing goes here
458 1042 ▶ if ( exists $flat_args{'rejection'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $flat_args{"rejection"}) 20 1022 1042
459  
460 20 state $rejection_actions = { map { ( $_, 0 ) } qw(fatal event) };
461 20 ▶ my $value = $flat_args{'rejection'} // 'undefined';
Condition50%1/2
$flat_args{"rejection"} // "undefined"
l!l
200
MC/DC0%0/1
$flat_args{"rejection"} // "undefined"
$flat_args{"rejection"}
Truth table50%1/2
A
A= $flat_args{"rejection"}
Aresult
11
00
462 Marpa::R2::exception(
463 qq{'rejection' named arg value is $value (should be one of },
464 ( join q{, },
465 0 map { q{'} . $_ . q{'} } keys %{$rejection_actions}
466 ),
467 ')'
468 20 ▶ ) if not exists $rejection_actions->{$value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rejection_actions->{$value} 0 20 20
469 20 $slr->[Marpa::R2::Internal::Scanless::R::REJECTION_ACTION] = $value;
470  
471 } ## end if ( exists $flat_args{'rejection'} )
472  
473 # A bit hack-ish, but some named args are copies straight to an member of
474 # the Scanless::R class, so this maps named args to the index of the array
475 # that holds the members.
476 1042 state $copy_arg_to_index = {
477 trace_file_handle =>
478 Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE,
479 trace_lexers => Marpa::R2::Internal::Scanless::R::TRACE_LEXERS,
480 trace_terminals => Marpa::R2::Internal::Scanless::R::TRACE_TERMINALS,
481 grammar => Marpa::R2::Internal::Scanless::R::GRAMMAR,
482 };
483  
484 1042 ARG: for my $arg_name ( keys %flat_args ) {
485 1570 my $index = $copy_arg_to_index->{$arg_name};
486 1570 ▶ next ARG if not defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 592 978 1570
487 978 my $value = $flat_args{$arg_name};
488 978 $slr->[$index] = $value;
489 } ## end ARG: for my $arg_name ( keys %flat_args )
490  
491 # Normalize trace levels to numbers
492 1042 for my $trace_level_arg (
493 Marpa::R2::Internal::Scanless::R::TRACE_TERMINALS,
494 Marpa::R2::Internal::Scanless::R::TRACE_LEXERS
495 )
496 {
497 2084 ▶ $slr->[$trace_level_arg] = 0
Branch: 1 branch
BranchTrueFalseTotal
unless &Scalar::Util::looks_like_number($slr->[$trace_level_arg]) 0 2084 2084
498 if
499 not Scalar::Util::looks_like_number( $slr->[$trace_level_arg] );
500 } ## end for my $trace_level_arg ( ...)
501  
502 # Trace file handle can never be undefined
503 1042 ▶ if (not defined $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE] )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $slr->[6]) 974 68 1042
504 {
505 974 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
506 974 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE] =
507 $slg->[Marpa::R2::Internal::Scanless::G::TRACE_FILE_HANDLE];
508 } ## end if ( not defined $slr->[...])
509  
510 # These NAIF recce args, when applicable, are simply copies of the the
511 # SLIF args of the same name
512 state $copyable_naif_recce_args = {
513 1042 map { ( $_, 1 ); }
514 qw(end max_parses semantics_package too_many_earley_items ranking_method
515 trace_actions trace_file_handle trace_terminals trace_values)
516 };
517  
518 # Prune flat args of all those named args which are NOT to be copied
519 # into the NAIF recce args
520 1042 my %g1_recce_args = ();
521 1042 for my $arg_name ( grep { $copyable_naif_recce_args->{$_} }
522 keys %flat_args )
523 {
524 241 $g1_recce_args{$arg_name} = $flat_args{$arg_name};
525 }
526  
527 1042 return \%g1_recce_args, \%flat_args;
528  
529 } ## end sub Marpa::R2::Internal::Scanless::R::set
530  
531 sub Marpa::R2::Scanless::R::thin {
532 5691 ▶ return $_[0]->[Marpa::R2::Internal::Scanless::R::C];
Subroutine thin: called CC=1 SCAR=0.0
533 }
534  
535 sub Marpa::R2::Scanless::R::trace {
536 0 ▶ my ( $self, $level ) = @_;
Subroutine trace: not called CC=2 SCAR=17.9
537 0 my $thin_slr = $self->[Marpa::R2::Internal::Scanless::R::C];
538 0 ▶ $level //= 1;
Condition0%0/2
$level //= 1
l!l
00
MC/DC0%0/1
$level //= 1
$level
Truth table0%0/2
A
A= $level
Aresult
11
00
539 0 return $thin_slr->trace($level);
540 } ## end sub Marpa::R2::Scanless::R::trace
541  
542 sub Marpa::R2::Scanless::R::error {
543 0 ▶ my ($self) = @_;
Subroutine error: not called CC=1 SCAR=6.9
544 0 return $self->[Marpa::R2::Internal::Scanless::R::READ_STRING_ERROR];
545 }
546  
547 sub Marpa::R2::Scanless::R::read {
548 975 ▶ my ( $self, $p_string, $start_pos, $length ) = @_;
Subroutine read: called CC=10 SCAR=24.3
549  
550 975 ▶ $start_pos //= 0;
Condition100%2/2
$start_pos //= 0
l!l
55920
MC/DC100%1/1
$start_pos //= 0
$start_pos
Truth table100%2/2
A
A= $start_pos
Aresult
11
00
551 975 ▶ $length //= -1;
Condition100%2/2
$length //= -1
l!l
41934
MC/DC100%1/1
$length //= -1
$length
Truth table100%2/2
A
A= $length
Aresult
11
00
552 975 ▶ Marpa::R2::exception(
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->[3] 0 975 975
553 "Multiple read()'s tried on a scannerless recognizer\n",
554 ' Currently the string cannot be changed once set'
555 ) if defined $self->[Marpa::R2::Internal::Scanless::R::P_INPUT_STRING];
556  
557 975 ▶ if ( ( my $ref_type = ref $p_string ) ne 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $ref_type = ref $p_string) ne "SCALAR") 0 975 975
558 0 ▶ my $desc = $ref_type ? "a ref to $ref_type" : 'not a ref';
Branch: 1 branch
BranchTrueFalseTotal
$ref_type ? : 0 0 0
559 0 Marpa::R2::exception(
560 qq{Arg to Marpa::R2::Scanless::R::read() is $desc\n},
561 ' It should be a ref to scalar' );
562 } ## end if ( ( my $ref_type = ref $p_string ) ne 'SCALAR' )
563  
564 975 ▶ if ( not defined ${$p_string} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined ${$p_string;}) 0 975 975
565 0 Marpa::R2::exception(
566 qq{Arg to Marpa::R2::Scanless::R::read() is a ref to an undef\n},
567 ' It should be a ref to a defined scalar' );
568 } ## end if ( ( my $ref_type = ref $p_string ) ne 'SCALAR' )
569  
570 975 $self->[Marpa::R2::Internal::Scanless::R::P_INPUT_STRING] = $p_string;
571  
572 975 my $thin_slr = $self->[Marpa::R2::Internal::Scanless::R::C];
573 975 my $trace_terminals = $self->[Marpa::R2::Internal::Scanless::R::TRACE_TERMINALS];
574 975 my $trace_lexers = $self->[Marpa::R2::Internal::Scanless::R::TRACE_LEXERS];
575 975 ▶ $thin_slr->trace_terminals($trace_terminals) if $trace_terminals;
Branch: 1 branch
BranchTrueFalseTotal
if $trace_terminals 2 973 975
576 975 ▶ $thin_slr->trace_lexers($trace_lexers) if $trace_lexers;
Branch: 1 branch
BranchTrueFalseTotal
if $trace_lexers 0 975 975
577  
578 975 $thin_slr->string_set($p_string);
579  
580 974 ▶ return 0 if @{ $self->[Marpa::R2::Internal::Scanless::R::EVENTS] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->[10];} 31 943 974
581  
582 943 return $self->resume( $start_pos, $length );
583  
584 } ## end sub Marpa::R2::Scanless::R::read
585  
586 my $libmarpa_trace_event_handlers = {
587  
588 'g1 accepted lexeme' => sub {
589 16 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
590 my ( undef, undef, $lexeme_start_pos, $lexeme_end_pos, $g1_lexeme)
591 16 = @{$event};
592 16 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
593 16 my $raw_token_value =
594 $thin_slr->substring( $lexeme_start_pos,
595 $lexeme_end_pos - $lexeme_start_pos );
596 16 my $trace_file_handle =
597 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
598 16 my $thick_g1_recce =
599 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
600 16 my $thick_g1_grammar = $thick_g1_recce->grammar();
601 16 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
602 16 ▶ say {$trace_file_handle} qq{Accepted lexeme },
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Accepted lexeme ", input_range_describe($slr, $lexeme_start_pos, $lexeme_end_pos - 1), " e", $slr->current_g1_location, ": ", $thick_g1_grammar->symbol_in_display_form($g1_lexeme), qq[; value="$raw_token_value"] or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 16 16
603 input_range_describe( $slr, $lexeme_start_pos,
604 $lexeme_end_pos - 1 ),
605 q{ e}, $slr->current_g1_location(),
606 q{: },
607 $thick_g1_grammar->symbol_in_display_form($g1_lexeme),
608 qq{; value="$raw_token_value"}
609 or Marpa::R2::exception("Could not say(): $ERRNO");
610 },
611 'rejected lexeme' => sub {
612 7 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
613 # Necessary to check, because this one can be returned when not tracing
614 7 ▶ return if not $slr->[Marpa::R2::Internal::Scanless::R::TRACE_TERMINALS];
Branch: 1 branch
BranchTrueFalseTotal
unless $slr->[8] 3 4 7
615 my ( undef, undef, $lexeme_start_pos, $lexeme_end_pos, $g1_lexeme)
616 4 = @{$event};
617 4 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
618 4 my $raw_token_value =
619 $thin_slr->substring( $lexeme_start_pos,
620 $lexeme_end_pos - $lexeme_start_pos );
621 4 my $trace_file_handle =
622 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
623 4 my $thick_g1_recce =
624 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
625 4 my $thick_g1_grammar = $thick_g1_recce->grammar();
626 4 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
627 4 ▶ say {$trace_file_handle} qq{Rejected lexeme },
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Rejected lexeme ", input_range_describe($slr, $lexeme_start_pos, $lexeme_end_pos - 1), ": ", $thick_g1_grammar->symbol_in_display_form($g1_lexeme), qq[; value="$raw_token_value"] or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 4 4
628 input_range_describe( $slr, $lexeme_start_pos,
629 $lexeme_end_pos - 1 ),
630 q{: },
631 $thick_g1_grammar->symbol_in_display_form($g1_lexeme),
632 qq{; value="$raw_token_value"}
633 or Marpa::R2::exception("Could not say(): $ERRNO");
634 },
635 'expected lexeme' => sub {
636 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
637 # Necessary to check, because this one can be returned when not tracing
638 0 ▶ return if not $slr->[Marpa::R2::Internal::Scanless::R::TRACE_TERMINALS];
Branch: 1 branch
BranchTrueFalseTotal
unless $slr->[8] 0 0 0
639 my ( undef, undef, $position, $g1_lexeme, $assertion_id)
640 0 = @{$event};
641 0 my ( $line, $column ) = $slr->line_column($position);
642 0 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
643 0 my $trace_file_handle =
644 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
645 0 my $thick_g1_recce =
646 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
647 0 my $thick_g1_grammar = $thick_g1_recce->grammar();
648 0 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
649 0 ▶ say {$trace_file_handle} qq{Expected lexeme },
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Expected lexeme ", $thick_g1_grammar->symbol_in_display_form($g1_lexeme), " at line $line, column $column; assertion ID = $assertion_id" or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
650 $thick_g1_grammar->symbol_in_display_form($g1_lexeme),
651 " at line $line, column $column; assertion ID = $assertion_id"
652 or Marpa::R2::exception("Could not say(): $ERRNO");
653 },
654 'outprioritized lexeme' => sub {
655 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
656 my ( undef, undef, $lexeme_start_pos, $lexeme_end_pos, $g1_lexeme,
657 $lexeme_priority, $required_priority )
658 0 = @{$event};
659 0 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
660 0 my $raw_token_value =
661 $thin_slr->substring( $lexeme_start_pos,
662 $lexeme_end_pos - $lexeme_start_pos );
663 0 my $trace_file_handle =
664 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
665 0 my $thick_g1_recce =
666 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
667 0 my $thick_g1_grammar = $thick_g1_recce->grammar();
668 0 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
669 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Outprioritized lexeme ", input_range_describe($slr, $lexeme_start_pos, $lexeme_end_pos - 1), ": ", $thick_g1_grammar->symbol_in_display_form($g1_lexeme), qq[; value="$raw_token_value"; ], "priority was $lexeme_priority, but $required_priority was required" or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
670 qq{Outprioritized lexeme },
671 input_range_describe( $slr, $lexeme_start_pos,
672 $lexeme_end_pos - 1 ),
673 q{: },
674 $thick_g1_grammar->symbol_in_display_form($g1_lexeme),
675 qq{; value="$raw_token_value"; },
676 qq{priority was $lexeme_priority, but $required_priority was required}
677 or Marpa::R2::exception("Could not say(): $ERRNO");
678 },
679 'g1 duplicate lexeme' => sub {
680 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
681 my ( undef, undef, $lexeme_start_pos, $lexeme_end_pos, $g1_lexeme ) =
682 0 @{$event};
683 0 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
684 0 my $raw_token_value =
685 $thin_slr->substring( $lexeme_start_pos,
686 $lexeme_end_pos - $lexeme_start_pos );
687 0 my $trace_file_handle =
688 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
689 0 my $thick_g1_recce =
690 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
691 0 my $thick_g1_grammar = $thick_g1_recce->grammar();
692 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Rejected as duplicate lexeme ", input_range_describe($slr, $lexeme_start_pos, $lexeme_end_pos - 1), ": ", $thick_g1_grammar->symbol_in_display_form($g1_lexeme), qq[; value="$raw_token_value"] or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
693 'Rejected as duplicate lexeme ',
694 input_range_describe( $slr, $lexeme_start_pos,
695 $lexeme_end_pos - 1 ),
696 q{: },
697 $thick_g1_grammar->symbol_in_display_form($g1_lexeme),
698 qq{; value="$raw_token_value"}
699 or Marpa::R2::exception("Could not say(): $ERRNO");
700 },
701 'g1 attempting lexeme' => sub {
702 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
703 my ( undef, undef, $lexeme_start_pos, $lexeme_end_pos, $g1_lexeme ) =
704 0 @{$event};
705 0 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
706 0 my $raw_token_value =
707 $thin_slr->substring( $lexeme_start_pos,
708 $lexeme_end_pos - $lexeme_start_pos );
709 0 my $trace_file_handle =
710 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
711 0 my $thick_g1_recce =
712 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
713 0 my $thick_g1_grammar = $thick_g1_recce->grammar();
714 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Attempting to read lexeme ", input_range_describe($slr, $lexeme_start_pos, $lexeme_end_pos - 1), " e", $slr->current_g1_location, ": ", $thick_g1_grammar->symbol_in_display_form($g1_lexeme), qq[; value="$raw_token_value"] or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
715 'Attempting to read lexeme ',
716 input_range_describe( $slr, $lexeme_start_pos,
717 $lexeme_end_pos - 1 ),
718 q{ e}, $slr->current_g1_location(),
719 q{: },
720 $thick_g1_grammar->symbol_in_display_form($g1_lexeme),
721 qq{; value="$raw_token_value"}
722 or Marpa::R2::exception("Could not say(): $ERRNO");
723 },
724 'lexer reading codepoint' => sub {
725 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
726 0 my ( undef, undef, $codepoint, $position, ) = @{$event};
727 0 my $char = chr $codepoint;
728 0 my @char_desc = ();
729 0 ▶ push @char_desc, qq{"$char"}
Branch: 1 branch
BranchTrueFalseTotal
if $char =~ /[\p{IsGraph}]/msx 0 0 0
730 if $char =~ /[\p{IsGraph}]/xms;
731 0 push @char_desc, ( sprintf '0x%04x', $codepoint );
732 0 my $char_desc = join q{ }, @char_desc;
733 0 my ( $line, $column ) = $slr->line_column($position);
734 0 my $trace_file_handle =
735 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
736 0 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
737 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Reading codepoint $char_desc at line $line, column $column" or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
738 qq{Reading codepoint $char_desc at line $line, column $column}
739 or Marpa::R2::exception("Could not say(): $ERRNO");
740 },
741 'lexer accepted codepoint' => sub {
742 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
743 my ( undef, undef, $codepoint, $position, $token_id ) =
744 0 @{$event};
745 0 my $char = chr $codepoint;
746 0 my @char_desc = ();
747 0 ▶ push @char_desc, qq{"$char"}
Branch: 1 branch
BranchTrueFalseTotal
if $char =~ /[\p{IsGraph}]/msx 0 0 0
748 if $char =~ /[\p{IsGraph}]/xms;
749 0 push @char_desc, ( sprintf '0x%04x', $codepoint );
750 0 my $char_desc = join q{ }, @char_desc;
751 0 my $grammar = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
752 0 my $thick_lex_grammar =
753 $grammar->[Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS]
754 ->[0];
755 0 my $symbol_in_display_form =
756 $thick_lex_grammar->symbol_in_display_form($token_id),
757 my ( $line, $column ) = $slr->line_column($position);
758 0 my $trace_file_handle =
759 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
760 0 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
761 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Codepoint $char_desc accepted as $symbol_in_display_form at line $line, column $column" or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
762 qq{Codepoint $char_desc accepted as $symbol_in_display_form at line $line, column $column}
763 or Marpa::R2::exception("Could not say(): $ERRNO");
764 },
765 'lexer rejected codepoint' => sub {
766 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
767 my ( undef, undef, $codepoint, $position, $token_id ) =
768 0 @{$event};
769 0 my $char = chr $codepoint;
770 0 my @char_desc = ();
771 0 ▶ push @char_desc, qq{"$char"}
Branch: 1 branch
BranchTrueFalseTotal
if $char =~ /[\p{IsGraph}]/msx 0 0 0
772 if $char =~ /[\p{IsGraph}]/xms;
773 0 push @char_desc, ( sprintf '0x%04x', $codepoint );
774 0 my $char_desc = join q{ }, @char_desc;
775 0 my $grammar = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
776 0 my $thick_lex_grammar =
777 $grammar->[Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS]
778 ->[0];
779 0 my $symbol_in_display_form =
780 $thick_lex_grammar->symbol_in_display_form($token_id),
781 my ( $line, $column ) = $slr->line_column($position);
782 0 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
783 0 my $trace_file_handle =
784 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
785 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Codepoint $char_desc rejected as $symbol_in_display_form at line $line, column $column" or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
786 qq{Codepoint $char_desc rejected as $symbol_in_display_form at line $line, column $column}
787 or Marpa::R2::exception("Could not say(): $ERRNO");
788 },
789 'lexer restarted recognizer' => sub {
790 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
791 0 my ( undef, undef, $position ) = @{$event};
792 0 my ( $line, $column ) = $slr->line_column($position);
793 0 my $trace_file_handle =
794 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
795 0 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
796 0 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Restarted recognizer at line $line, column $column" or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
797 qq{Restarted recognizer at line $line, column $column}
798 or Marpa::R2::exception("Could not say(): $ERRNO");
799 },
800 'discarded lexeme' => sub {
801 13 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
802 my ( undef, undef, $lex_rule_id, $start, $end ) =
803 13 @{$event};
804 13 my $grammar = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
805 13 my $thick_lex_grammar =
806 $grammar->[Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS]
807 ->[0];
808 13 my $grammar_c = $thick_lex_grammar->[Marpa::R2::Internal::Grammar::C];
809 13 my $rule_length = $grammar_c->rule_length($lex_rule_id);
810 my @rhs_ids =
811 13 map { $grammar_c->rule_rhs( $lex_rule_id, $_ ) }
812 ( 0 .. $rule_length - 1 );
813 my @rhs =
814 13 map { $thick_lex_grammar->symbol_in_display_form($_) } @rhs_ids;
815 13 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
816 13 my $trace_file_handle =
817 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
818 13 ▶ say {$trace_file_handle} qq{Discarded lexeme },
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Discarded lexeme ", input_range_describe($slr, $start, $end - 1), ": ", join(" ", @rhs) or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 13 13
819 input_range_describe( $slr, $start, $end - 1 ), q{: }, join q{ },
820 @rhs
821 or Marpa::R2::exception("Could not say(): $ERRNO");
822 },
823 'g1 pausing before lexeme' => sub {
824 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
825 0 my ( undef, undef, $start, $end, $lexeme_id ) = @{$event};
826 0 my $thick_g1_recce =
827 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
828 0 my $thick_g1_grammar = $thick_g1_recce->grammar();
829 0 my $lexeme_name =
830 $thick_g1_grammar->symbol_in_display_form($lexeme_id);
831 0 my $trace_file_handle =
832 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
833 0 ▶ say {$trace_file_handle} 'Paused before lexeme ',
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Paused before lexeme ", input_range_describe($slr, $start, $end - 1), ": $lexeme_name" or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
834 input_range_describe( $slr, $start, $end - 1 ), ": $lexeme_name"
835 or Marpa::R2::exception("Could not say(): $ERRNO");
836 },
837 'g1 pausing after lexeme' => sub {
838 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
839 0 my ( undef, undef, $start, $end, $lexeme_id ) = @{$event};
840 0 my $thick_g1_recce =
841 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
842 0 my $thick_g1_grammar = $thick_g1_recce->grammar();
843 0 my $lexeme_name =
844 $thick_g1_grammar->symbol_in_display_form($lexeme_id);
845 0 my $trace_file_handle =
846 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
847 0 ▶ say {$trace_file_handle} 'Paused after lexeme ',
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Paused after lexeme ", input_range_describe($slr, $start, $end - 1), ": $lexeme_name" or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
848 input_range_describe( $slr, $start, $end - 1 ), ": $lexeme_name"
849 or Marpa::R2::exception("Could not say(): $ERRNO");
850 },
851 'ignored lexeme' => sub {
852 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
853 0 my ( undef, undef, $g1_symbol_id, $start, $end ) = @{$event};
854 0 my $thick_g1_recce =
855 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
856 0 my $thick_g1_grammar = $thick_g1_recce->grammar();
857 0 my $lexeme_name =
858 $thick_g1_grammar->symbol_in_display_form($g1_symbol_id);
859 0 my $trace_file_handle =
860 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
861 0 ▶ say {$trace_file_handle} 'Ignored lexeme ',
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Ignored lexeme ", input_range_describe($slr, $start, $end - 1), ": $lexeme_name" or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
862 input_range_describe( $slr, $start, $end - 1 ), ": $lexeme_name"
863 or Marpa::R2::exception("Could not say(): $ERRNO");
864 },
865 150 };
866  
867 my $libmarpa_event_handlers = {
868 q{'trace} => sub {
869 36 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: called CC=3 SCAR=15.4
870 36 my $handler = $libmarpa_trace_event_handlers->{ $event->[1] };
871 36 ▶ if ( defined $handler ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $handler) { } 36 0 36
872 36 $handler->( $slr, $event );
873 }
874 else {
875 0 my $trace_file_handle =
876 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
877 0 ▶ say {$trace_file_handle} join q{ }, qw(Trace event:), @{$event}[1 .. $#{$event}]
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} join(" ", ("Trace", "event:"), @{$event;}[1 .. $#{$event;}]) or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
878 or Marpa::R2::exception("Could not say(): $ERRNO");
879 } ## end else [ if ( defined $handler ) ]
880 36 return 0;
881 },
882  
883 'symbol completed' => sub {
884 243 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
885 243 my ( undef, $completed_symbol_id ) = @{$event};
886 243 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
887 243 my $completion_event_by_id =
888 $slg->[Marpa::R2::Internal::Scanless::G::COMPLETION_EVENT_BY_ID];
889 243 push @{ $slr->[Marpa::R2::Internal::Scanless::R::EVENTS] },
890 [ $completion_event_by_id->[$completed_symbol_id] ];
891 243 return 1;
892 },
893  
894 'symbol nulled' => sub {
895 59 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
896 59 my ( undef, $nulled_symbol_id ) = @{$event};
897 59 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
898 59 my $nulled_event_by_id =
899 $slg->[Marpa::R2::Internal::Scanless::G::NULLED_EVENT_BY_ID];
900 59 push @{ $slr->[Marpa::R2::Internal::Scanless::R::EVENTS] },
901 [ $nulled_event_by_id->[$nulled_symbol_id] ];
902 59 return 1;
903 },
904  
905 'symbol predicted' => sub {
906 104 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
907 104 my ( undef, $predicted_symbol_id ) = @{$event};
908 104 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
909 104 my $prediction_event_by_id =
910 $slg->[Marpa::R2::Internal::Scanless::G::PREDICTION_EVENT_BY_ID];
911 104 push @{ $slr->[Marpa::R2::Internal::Scanless::R::EVENTS] },
912 [ $prediction_event_by_id->[$predicted_symbol_id] ];
913 104 return 1;
914 },
915  
916 # 'after lexeme' is same -- copied over below
917 'before lexeme' => sub {
918 388 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
919 388 my ( undef, $lexeme_id ) = @{$event};
920 388 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
921 388 my $lexeme_event =
922 $slg->[Marpa::R2::Internal::Scanless::G::LEXEME_EVENT_BY_ID]
923 ->[$lexeme_id];
924 388 ▶ push @{ $slr->[Marpa::R2::Internal::Scanless::R::EVENTS] },
Branch: 1 branch
BranchTrueFalseTotal
if defined $lexeme_event 224 164 388
925 [$lexeme_event]
926 if defined $lexeme_event;
927 388 return 1;
928 },
929  
930 'discarded lexeme' => sub {
931 485 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
932 485 my ( undef, $rule_id, @other_data) = @{$event};
933 485 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
934 485 my $lexeme_event =
935 $slg->[Marpa::R2::Internal::Scanless::G::DISCARD_EVENT_BY_LEXER_RULE]
936 ->[$rule_id];
937 485 ▶ push @{ $slr->[Marpa::R2::Internal::Scanless::R::EVENTS] },
Branch: 1 branch
BranchTrueFalseTotal
if defined $lexeme_event 485 0 485
938 [$lexeme_event, @other_data]
939 if defined $lexeme_event;
940 485 return 1;
941 },
942  
943 'unknown g1 event' => sub {
944 0 ▶ my ( $slr, $event ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
945 0 Marpa::R2::exception( ( join q{ }, 'Unknown event:', @{$event} ) );
946 0 return 0;
947 },
948  
949 'no acceptable input' => sub {
950 ## Do nothing at this point
951 0 ▶ return 0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
952 },
953 150 };
954  
955 150 $libmarpa_event_handlers->{'after lexeme'} = $libmarpa_event_handlers->{'before lexeme'};
956  
957 # Return 1 if internal scanning should pause
958 sub Marpa::R2::Internal::Scanless::convert_libmarpa_events {
959 6780 ▶ my ($slr) = @_;
Subroutine convert_libmarpa_events: called CC=4 SCAR=14.0
960 6780 my $pause = 0;
961 6780 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
962 6780 EVENT: for my $event ( $thin_slr->events() ) {
963 1315 my ($event_type) = @{$event};
964 1315 my $handler = $libmarpa_event_handlers->{$event_type};
965 1315 ▶ Marpa::R2::exception( ( join q{ }, 'Unknown event:', @{$event} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $handler 0 1315 1315
966 if not defined $handler;
967 1315 ▶ $pause = 1 if $handler->( $slr, $event );
Branch: 1 branch
BranchTrueFalseTotal
if &$handler($slr, $event) 1279 36 1315
968 } ## end EVENT: for my $event ( $thin_slr->events() )
969 6780 return $pause;
970 } ## end sub Marpa::R2::Internal::Scanless::convert_libmarpa_events
971  
972 sub Marpa::R2::Scanless::R::resume {
973 1911 ▶ my ( $slr, $start_pos, $length ) = @_;
Subroutine resume: called CC=22 SCAR=31.6
974 1911 ▶ Marpa::R2::exception(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $slr->[3] 0 1911 1911
975 "Attempt to resume an SLIF recce which has no string set\n",
976 ' The string should be set first using read()'
977 )
978 if not defined $slr->[Marpa::R2::Internal::Scanless::R::P_INPUT_STRING];
979  
980 1911 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
981 1911 my $trace_terminals =
982 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_TERMINALS];
983 1911 my $trace_lexers = $slr->[Marpa::R2::Internal::Scanless::R::TRACE_LEXERS];
984  
985 1911 ▶ $thin_slr->pos_set( ($start_pos // $thin_slr->pos()), ($length // -1));
Condition100%5/5
$start_pos // $thin_slr->pos
l!l&&r!l&&!r
15653424
$length // -1
l!l
1097814
MC/DC100%2/2
$start_pos // $thin_slr->pos
$start_pos $thin_slr->pos
MC/DC100%1/1
$length // -1
$length
Truth table100%3/3
A // B
A= $start_posB= $thin_slr->pos
ABresult
1X1
011
000
Truth table100%2/2
A
A= $length
Aresult
11
00
986 1911 $slr->[Marpa::R2::Internal::Scanless::R::EVENTS] = [];
987 1911 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
988 1911 my $thin_slg = $slg->[Marpa::R2::Internal::Scanless::G::C];
989  
990 1911 OUTER_READ: while (1) {
991  
992 6472 my $problem_code = $thin_slr->read();
993  
994 6472 ▶ last OUTER_READ if not $problem_code;
Branch: 1 branch
BranchTrueFalseTotal
unless $problem_code 861 5611 6472
995 5611 my $pause =
996 Marpa::R2::Internal::Scanless::convert_libmarpa_events($slr);
997  
998 5611 ▶ if ( $trace_lexers > 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace_lexers > 2) 0 5611 5611
999 0 my $stream_pos = $thin_slr->pos();
1000 0 my $trace_file_handle =
1001 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
1002 0 my $thick_lex_grammar =
1003 $slg->[Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS]->[0];
1004 0 my $lex_tracer = $thick_lex_grammar->tracer();
1005 0 my ( $line, $column ) = $slr->line_column($stream_pos);
1006 0 ▶ print {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
print {$trace_file_handle;} "\n=== Progress report at line $line, column $column\n", $lex_tracer->lexer_progress_report($slr), "=== End of progress report at line $line, column $column\n" or Marpa::R2::exception("Cannot print(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 0 0
1007 qq{\n=== Progress report at line $line, column $column\n},
1008 $lex_tracer->lexer_progress_report($slr),
1009 qq{=== End of progress report at line $line, column $column\n},
1010 or Marpa::R2::exception("Cannot print(): $ERRNO");
1011 } ## end if ( $trace_lexers > 2 )
1012  
1013 5611 ▶ last OUTER_READ if $pause;
Branch: 1 branch
BranchTrueFalseTotal
if $pause 1011 4600 5611
1014 4600 ▶ next OUTER_READ if $problem_code eq 'event';
Branch: 1 branch
BranchTrueFalseTotal
if $problem_code eq "event" 31 4569 4600
1015 4569 ▶ next OUTER_READ if $problem_code eq 'trace';
Branch: 1 branch
BranchTrueFalseTotal
if $problem_code eq "trace" 0 4569 4569
1016  
1017 # The event on exhaustion only occurs if needed to provide a reason
1018 # to return -- if an exhausted reader would return anyway, there is
1019 # no exhaustion event. For a reliable way to detect exhaustion,
1020 # use the $slr->exhausted() method.
1021 # The name of the exhausted event begins with a single quote, so
1022 # that it will not conflict with any user-defined event name.
1023  
1024 4569 ▶ if ( $problem_code eq 'R1 exhausted before end'
Branch: 1 branch
BranchTrueFalseTotal
if ($problem_code eq "R1 exhausted before end" and $slr->[4] eq "event") 8 4561 4569
Condition100%3/3
$problem_code eq "R1 exhausted before end" and $slr->[4] eq "event"
!ll&&!rl&&r
455928
MC/DC100%2/2
$problem_code eq "R1 exhausted before end" and $slr->[4] eq "event"
$problem_code eq "R1 exhausted before end" $slr->[4] eq "event"
Truth table100%3/3
A and B
A= $problem_code eq "R1 exhausted before end"B= $slr->[4] eq "event"
ABresult
0X0
100
111
1025 and $slr->[Marpa::R2::Internal::Scanless::R::EXHAUSTION_ACTION]
1026 eq 'event' )
1027 {
1028 8 push @{ $slr->[Marpa::R2::Internal::Scanless::R::EVENTS] },
1029 [q{'exhausted}];
1030 8 last OUTER_READ;
1031 } ## end if ( $problem_code eq 'R1 exhausted before end' and ...)
1032  
1033 4561 ▶ if ( $problem_code eq 'no lexeme'
Branch: 1 branch
BranchTrueFalseTotal
if ($problem_code eq "no lexeme" and $slr->[5] eq "event") 22 4539 4561
Condition100%3/3
$problem_code eq "no lexeme" and $slr->[5] eq "event"
!ll&&!rl&&r
4532722
MC/DC100%2/2
$problem_code eq "no lexeme" and $slr->[5] eq "event"
$problem_code eq "no lexeme" $slr->[5] eq "event"
Truth table100%3/3
A and B
A= $problem_code eq "no lexeme"B= $slr->[5] eq "event"
ABresult
0X0
100
111
1034 and $slr->[Marpa::R2::Internal::Scanless::R::REJECTION_ACTION]
1035 eq 'event' )
1036 {
1037 22 push @{ $slr->[Marpa::R2::Internal::Scanless::R::EVENTS] },
1038 [q{'rejected}];
1039 22 last OUTER_READ;
1040 }
1041  
1042 4539 ▶ if ( $problem_code eq 'invalid char' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($problem_code eq "invalid char") 0 4539 4539
1043 0 my $codepoint = $thin_slr->codepoint();
1044 0 Marpa::R2::exception(
1045 qq{Failed at unacceptable character },
1046 character_describe( chr $codepoint ) );
1047 } ## end if ( $problem_code eq 'invalid char' )
1048  
1049 4539 ▶ if ( $problem_code eq 'unregistered char' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($problem_code eq "unregistered char") 4530 9 4539
1050  
1051 4530 state $op_alternative = Marpa::R2::Thin::op('alternative');
1052 4530 state $op_invalid_char = Marpa::R2::Thin::op('invalid_char');
1053 4530 state $op_earleme_complete =
1054 Marpa::R2::Thin::op('earleme_complete');
1055  
1056 # Recover by registering character, if we can
1057 4530 my $codepoint = $thin_slr->codepoint();
1058 my $character =
1059 4530 substr ${$slr->[Marpa::R2::Internal::Scanless::R::P_INPUT_STRING]},
1060 $thin_slr->pos(), 1;
1061 4530 my $character_class_table =
1062 $slg->[Marpa::R2::Internal::Scanless::G::CHARACTER_CLASS_TABLES]
1063 ->[0];
1064 4530 my @ops;
1065 4530 for my $entry ( @{$character_class_table} ) {
1066  
1067 200367 my ( $symbol_id, $re ) = @{$entry};
1068 200367 ▶ if ( $character =~ $re ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($character =~ /$re/) 22630 177737 200367
1069  
1070 22630 ▶ if ( $trace_terminals >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace_terminals >= 2) 12 22618 22630
1071 12 my $thick_lex_grammar =
1072 $slg->[
1073 Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS]
1074 ->[0];
1075 12 my $trace_file_handle = $slr->[
1076 Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
1077 12 my $char_desc = sprintf 'U+%04x', $codepoint;
1078 12 ▶ if ( $character =~ m/[[:graph:]]+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($character =~ /[[:graph:]]+/) 10 2 12
1079 10 $char_desc .= qq{ '$character'};
1080 }
1081 12 ▶ say {$trace_file_handle}
Branch: 1 branch
BranchTrueFalseTotal
say {$trace_file_handle;} "Registering character $char_desc as symbol ${symbol_id}: ", $thick_lex_grammar->symbol_in_display_form($symbol_id) or Marpa::R2::exception("Could not say(): $Marpa::R2::Internal::Scanless::R::ERRNO") 0 12 12
1082 qq{Registering character $char_desc as symbol $symbol_id: },
1083 $thick_lex_grammar->symbol_in_display_form(
1084 $symbol_id)
1085 or
1086 Marpa::R2::exception("Could not say(): $ERRNO");
1087 } ## end if ( $trace_terminals >= 2 )
1088 22630 push @ops, $op_alternative, $symbol_id, 1, 1;
1089 } ## end if ( $character =~ $re )
1090 } ## end for my $entry ( @{$character_class_table} )
1091  
1092 4530 ▶ if ( not @ops ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ops) 1 4529 4530
1093 1 $thin_slr->char_register( $codepoint, $op_invalid_char );
1094 1 next OUTER_READ;
1095 }
1096 4529 $thin_slr->char_register( $codepoint, @ops,
1097 $op_earleme_complete );
1098 4529 next OUTER_READ;
1099 } ## end if ( $problem_code eq 'unregistered char' )
1100  
1101 9 return $slr->read_problem($problem_code);
1102  
1103 } ## end OUTER_READ: while (1)
1104  
1105 1902 return $thin_slr->pos();
1106 } ## end sub Marpa::R2::Scanless::R::resume
1107  
1108 sub Marpa::R2::Scanless::R::event {
1109 333 ▶ my ( $self, $event_ix ) = @_;
Subroutine event: called CC=1 SCAR=0.0
1110 333 return $self->[Marpa::R2::Internal::Scanless::R::EVENTS]->[$event_ix];
1111 }
1112  
1113 sub Marpa::R2::Scanless::R::events {
1114 962 ▶ my ($self) = @_;
Subroutine events: called CC=1 SCAR=0.0
1115 962 return $self->[Marpa::R2::Internal::Scanless::R::EVENTS];
1116 }
1117  
1118 ## From here, recovery is a matter for the caller,
1119 ## if it is possible at all
1120 sub Marpa::R2::Scanless::R::read_problem {
1121 9 ▶ my ( $slr, $problem_code ) = @_;
Subroutine read_problem: called CC=27 SCAR=43.1
1122  
1123 9 ▶ die 'No problem_code in slr->read_problem()' if not $problem_code;
Branch: 1 branch
BranchTrueFalseTotal
unless $problem_code 0 9 9
1124  
1125 9 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1126 9 my $grammar = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1127  
1128 9 my $thick_lex_grammar =
1129 $grammar->[Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS]->[0];
1130 9 my $lex_tracer = $thick_lex_grammar->tracer();
1131  
1132 9 my $trace_file_handle =
1133 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
1134  
1135 9 my $thick_g1_recce =
1136 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1137 9 my $thin_g1_recce = $thick_g1_recce->thin();
1138 9 my $thick_g1_grammar = $thick_g1_recce->grammar();
1139 9 my $g1_tracer = $thick_g1_grammar->tracer();
1140  
1141 9 my $pos = $thin_slr->pos();
1142 9 my $problem_pos = $pos;
1143 9 my $p_string = $slr->[Marpa::R2::Internal::Scanless::R::P_INPUT_STRING];
1144 9 my $length_of_string = length ${$p_string};
1145  
1146 9 my $problem;
1147 9 my $stream_status = 0;
1148 9 my $g1_status = 0;
1149 CODE_TO_PROBLEM: {
1150 9 ▶ if ( $problem_code eq 'R1 exhausted before end' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($problem_code eq "R1 exhausted before end") 2 7 9
1151 2 my ($lexeme_start) = $thin_slr->lexeme_span();
1152 2 my ( $line, $column ) = $slr->line_column($lexeme_start);
1153 2 $problem =
1154 "Parse exhausted, but lexemes remain, at line $line, column $column\n";
1155 2 last CODE_TO_PROBLEM;
1156 }
1157 7 ▶ if ( $problem_code eq 'SLIF loop' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($problem_code eq "SLIF loop") 0 7 7
1158 0 my ($lexeme_start) = $thin_slr->lexeme_span();
1159 0 my ( $line, $column ) = $slr->line_column($lexeme_start);
1160 0 $problem = "SLIF loops at line $line, column $column";
1161 0 last CODE_TO_PROBLEM;
1162 }
1163 7 ▶ if ( $problem_code eq 'no lexeme' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($problem_code eq "no lexeme") 7 0 7
1164 7 $problem_pos = $thin_slr->problem_pos();
1165 7 my ( $line, $column ) = $slr->line_column($problem_pos);
1166 7 my $lexer_name;
1167 7 my @details = ();
1168 7 my %rejections = ();
1169 7 my @events = $thin_slr->events();
1170 7 ▶ if ( scalar @events > 100 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @events > 100) 0 7 7
1171 0 my $omitted = scalar @events - 100;
1172 0 push @details,
1173 " [there were $omitted events -- only the first 100 were examined]";
1174 0 $#events = 99;
1175 } ## end if ( scalar @events > 100 )
1176 7 EVENT: for my $event (@events) {
1177 my ( $event_type, $trace_event_type, $lexeme_start_pos,
1178 $lexeme_end_pos, $g1_lexeme )
1179 2 = @{$event};
1180 next EVENT
1181 2 ▶ if $event_type ne q{'trace}
Branch: 1 branch
BranchTrueFalseTotal
if $event_type ne "'trace" or $trace_event_type ne "rejected lexeme" 0 2 2
Condition33%1/3
$event_type ne "'trace" or $trace_event_type ne "rejected lexeme"
l!l&&r!l&&!r
002
MC/DC0%0/2
$event_type ne "'trace" or $trace_event_type ne "rejected lexeme"
$event_type ne "'trace" $trace_event_type ne "rejected lexeme"
Truth table33%1/3
A or B
A= $event_type ne "'trace"B= $trace_event_type ne "rejected lexeme"
ABresult
1X1
011
000
1182 or $trace_event_type ne 'rejected lexeme';
1183 2 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1184 2 my $raw_token_value =
1185 $thin_slr->substring( $lexeme_start_pos,
1186 $lexeme_end_pos - $lexeme_start_pos );
1187 2 my $trace_file_handle =
1188 $slr
1189 ->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
1190 2 my $thick_g1_recce =
1191 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1192 2 my $thick_g1_grammar = $thick_g1_recce->grammar();
1193 2 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1194  
1195 # Different internal symbols may have the same external "display form",
1196 # which in naive reporting logic would result in many identical messages,
1197 # confusing the user. This logic makes sure that identical rejection
1198 # reports are not repeated, even when they have different causes
1199 # internally.
1200  
1201 $rejections{
1202 2 $thick_g1_grammar->symbol_in_display_form(
1203 $g1_lexeme)
1204 . qq{; value="$raw_token_value"; length = }
1205 . ( $lexeme_end_pos - $lexeme_start_pos ) } = 1;
1206 } ## end EVENT: for my $event (@events)
1207 7 my @problem = ();
1208 7 my @rejections = keys %rejections;
1209 7 ▶ if ( scalar @rejections ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @rejections) { } 2 5 7
1210 2 my $rejection_count = scalar @rejections;
1211 2 push @problem,
1212 "No lexemes accepted at line $line, column $column";
1213 2 REJECTION: for my $i ( 0 .. 5 ) {
1214 4 my $rejection = $rejections[$i];
1215 4 ▶ last REJECTION if not defined $rejection;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rejection 2 2 4
1216 2 push @problem, qq{ Rejected lexeme #$i: $rejection};
1217 }
1218 2 ▶ if ( $rejection_count > 5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rejection_count > 5) 0 2 2
1219 0 push @problem,
1220 " [there were $rejection_count rejection messages -- only the first 5 are shown]";
1221 }
1222 2 push @problem, @details;
1223 } ## end if ( scalar @rejections )
1224 else {
1225 5 push @problem,
1226 "No lexeme found at line $line, column $column";
1227 }
1228 7 $problem = join "\n", @problem;
1229 7 last CODE_TO_PROBLEM;
1230 } ## end if ( $problem_code eq 'no lexeme' )
1231 0 $problem = 'Unrecognized problem code: ' . $problem_code;
1232 } ## end CODE_TO_PROBLEM:
1233  
1234 9 my $desc;
1235 DESC: {
1236 9 ▶ if ( defined $problem ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $problem) 9 0 9
1237 9 $desc .= "$problem";
1238 }
1239 9 ▶ if ( $stream_status == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream_status == -1) 0 9 9
1240 0 $desc = 'Lexer: Character rejected';
1241 0 last DESC;
1242 }
1243 9 ▶ if ( $stream_status == -2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream_status == -2) 0 9 9
1244 0 $desc = 'Lexer: Unregistered character';
1245 0 last DESC;
1246 }
1247  
1248 # -5 indicates success, in which case we should never have called this subroutine.
1249 9 ▶ if ( $stream_status == -3 || $stream_status == -5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream_status == -3 or $stream_status == -5) 0 9 9
Condition33%1/3
$stream_status == -3 or $stream_status == -5
l!l&&r!l&&!r
009
MC/DC0%0/2
$stream_status == -3 or $stream_status == -5
$stream_status == -3 $stream_status == -5
Truth table33%1/3
A or B
A= $stream_status == -3B= $stream_status == -5
ABresult
1X1
011
000
1250 0 $desc = 'Unexpected return value from lexer: Parse exhausted';
1251 0 last DESC;
1252 }
1253 9 ▶ if ($g1_status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($g1_status) 0 9 9
1254 0 my $true_event_count = $thin_slr->g1()->event_count();
1255 EVENT:
1256 0 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($event_ix < $true_event_count) 0 0 0
1257 my $event_ix = 0;
1258 $event_ix < $true_event_count;
1259 $event_ix++
1260 )
1261 {
1262 0 my ( $event_type, $value ) =
1263 $thin_slr->g1()->event($event_ix);
1264 0 ▶ if ( $event_type eq 'MARPA_EVENT_EARLEY_ITEM_THRESHOLD' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event_type eq "MARPA_EVENT_EARLEY_ITEM_THRESHOLD") 0 0 0
1265 0 $desc = join "\n", $desc,
1266 "G1 grammar: Earley item count ($value) exceeds warning threshold\n";
1267 0 next EVENT;
1268 }
1269 0 ▶ if ( $event_type eq 'MARPA_EVENT_SYMBOL_EXPECTED' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event_type eq "MARPA_EVENT_SYMBOL_EXPECTED") 0 0 0
1270 0 $desc = join "\n", $desc,
1271 "Unexpected G1 grammar event: $event_type "
1272 . $g1_tracer->symbol_name($value);
1273 0 next EVENT;
1274 } ## end if ( $event_type eq 'MARPA_EVENT_SYMBOL_EXPECTED' )
1275 0 ▶ if ( $event_type eq 'MARPA_EVENT_EXHAUSTED' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event_type eq "MARPA_EVENT_EXHAUSTED") 0 0 0
1276 0 $desc = join "\n", $desc, 'Parse exhausted';
1277 0 next EVENT;
1278 }
1279 0 Marpa::R2::exception( $desc, "\n",
1280 qq{Unknown event: "$event_type"; event value = $value\n}
1281 );
1282 } ## end EVENT: for ( my $event_ix = 0; $event_ix < ...)
1283 0 last DESC;
1284 } ## end if ($g1_status)
1285 9 ▶ if ( $g1_status < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($g1_status < 0) 0 9 9
1286 0 $desc = 'G1 error: ' . $thin_slr->g1()->error();
1287 0 chomp $desc;
1288 0 last DESC;
1289 }
1290 } ## end DESC:
1291 9 my $read_string_error;
1292 9 ▶ if ( $problem_pos < $length_of_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($problem_pos < $length_of_string) { } 9 0 9
1293 9 my $char = substr ${$p_string}, $problem_pos, 1;
1294 9 my $char_desc = character_describe($char);
1295 9 my ( $line, $column ) = $thin_slr->line_column($problem_pos);
1296 my $prefix =
1297 $problem_pos >= 50
1298 0 ? ( substr ${$p_string}, $problem_pos - 50, 50 )
1299 9 ▶ : ( substr ${$p_string}, 0, $problem_pos );
Branch: 1 branch
BranchTrueFalseTotal
$problem_pos >= 50 ? : 0 9 9
1300  
1301 $read_string_error =
1302 "Error in SLIF parse: $desc\n"
1303 . '* String before error: '
1304 . Marpa::R2::escape_string( $prefix, -50 ) . "\n"
1305 . "* The error was at line $line, column $column, and at character $char_desc, ...\n"
1306 . '* here: '
1307 9 . Marpa::R2::escape_string( ( substr ${$p_string}, $problem_pos, 50 ),
1308 50 )
1309 . "\n";
1310 } ## end elsif ( $problem_pos < $length_of_string )
1311 else {
1312 $read_string_error =
1313 "Error in SLIF parse: $desc\n"
1314 . "* Error was at end of input\n"
1315 . '* String before error: '
1316 0 . Marpa::R2::escape_string( ${$p_string}, -50 ) . "\n";
1317 } ## end else [ if ($g1_status) ]
1318  
1319 9 ▶ if ( $slr->[Marpa::R2::Internal::Scanless::R::TRACE_LEXERS] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slr->[7]) 0 9 9
1320 0 my $stream_pos = $thin_slr->pos();
1321 0 my $trace_file_handle =
1322 $slr->[Marpa::R2::Internal::Scanless::R::TRACE_FILE_HANDLE];
1323 0 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1324 0 my $thick_lex_grammar =
1325 $grammar->[Marpa::R2::Internal::Scanless::G::THICK_LEX_GRAMMARS]->[0];
1326 0 my $lex_tracer = $thick_lex_grammar->tracer();
1327 0 my ( $line, $column ) = $slr->line_column($stream_pos);
1328 0 $read_string_error .=
1329 qq{\n=== Progress report for lexer at line $line, column $column\n} .
1330 $lex_tracer->lexer_progress_report($slr);
1331 }
1332  
1333 9 $slr->[Marpa::R2::Internal::Scanless::R::READ_STRING_ERROR] =
1334 $read_string_error;
1335 9 Marpa::R2::exception($read_string_error);
1336  
1337 # Never reached
1338 # Fall through to return undef
1339 0 return;
1340  
1341 } ## end sub Marpa::R2::Scanless::R::read_problem
1342  
1343 sub character_describe {
1344 9 ▶ my ($char) = @_;
Subroutine character_describe: called CC=2 SCAR=7.0
1345 9 my $text = sprintf '0x%04x', ord $char;
1346 9 ▶ $text .= q{ }
Branch: 1 branch
BranchTrueFalseTotal
$char =~ /[[:graph:]]/msx ? : 9 0 9
1347 . (
1348 $char =~ m/[[:graph:]]/xms
1349 ? qq{'$char'}
1350 : '(non-graphic character)'
1351 );
1352 9 return $text;
1353 } ## end sub character_describe
1354  
1355 150 my @escape_by_ord = ();
1356 150 $escape_by_ord[ ord q{\\} ] = q{\\\\};
1357 $escape_by_ord[ ord eval qq{"$_"} ] = $_
1358 150 for "\\t", "\\r", "\\f", "\\b", "\\a", "\\e";
1359 150 $escape_by_ord[0xa] = '\\n';
1360 150 ▶$escape_by_ord[$_] //= chr $_ for 32 .. 126;
Condition100%3/3
$escape_by_ord[$_] //= chr $_
l!l&&r!l&&!r
15013950150
MC/DC100%2/2
$escape_by_ord[$_] //= chr $_
$escape_by_ord[$_] chr $_
Truth table100%3/3
A //= B
A= $escape_by_ord[$_]B= chr $_
ABresult
1X1
011
000
1361 150 ▶$escape_by_ord[$_] //= sprintf( "\\x%02x", $_ ) for 0 .. 255;
Condition66%2/3
$escape_by_ord[$_] //= sprintf("\\x%02x", $_)
l!l&&r!l&&!r
15300231000
MC/DC0%0/2
$escape_by_ord[$_] //= sprintf("\\x%02x", $_)
$escape_by_ord[$_] sprintf("\\x%02x", $_)
Truth table66%2/3
A //= B
A= $escape_by_ord[$_]B= sprintf("\\x%02x", $_)
ABresult
1X1
011
000
1362  
1363 # This and the sister routine for "forward strings"
1364 # should replace the other string "escaping" subroutine
1365 # in the NAIF
1366 sub Marpa::R2::Internal::Scanless::reversed_input_escape {
1367 0 ▶ my ( $p_input, $base_pos, $length ) = @_;
Subroutine reversed_input_escape: not called CC=7 SCAR=40.3
1368 0 my @escaped_chars = ();
1369 0 my $pos = $base_pos - 1 ;
1370  
1371 0 my $trailing_spaces = 0;
1372 0 ▶ CHAR: while ( $pos > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos > 0) 0 0 0
1373 0 ▶ last CHAR if substr ${$p_input}, $pos, 1 ne q{ };
Branch: 1 branch
BranchTrueFalseTotal
if 0 0 0
1374 0 $trailing_spaces++;
1375 0 $pos--;
1376 }
1377 0 my $length_so_far = $trailing_spaces * 2;
1378  
1379 0 ▶ CHAR: while ( $pos >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= 0) 0 0 0
1380 0 my $char = substr ${$p_input}, $pos, 1;
1381 0 my $ord = ord $char;
1382 0 ▶ my $escaped_char = $escape_by_ord[$ord]
Condition0%0/3
$escape_by_ord[$ord] // sprintf("\\x{%04x}", $ord)
l!l&&r!l&&!r
000
MC/DC0%0/2
$escape_by_ord[$ord] // sprintf("\\x{%04x}", $ord)
$escape_by_ord[$ord] sprintf("\\x{%04x}", $ord)
Truth table0%0/3
A // B
A= $escape_by_ord[$ord]B= sprintf("\\x{%04x}", $ord)
ABresult
1X1
011
000
1383 // sprintf( "\\x{%04x}", $ord );
1384 0 my $char_length = length $escaped_char;
1385 0 $length_so_far += $char_length;
1386 0 ▶ last CHAR if $length_so_far > $length;
Branch: 1 branch
BranchTrueFalseTotal
if $length_so_far > $length 0 0 0
1387 0 push @escaped_chars, $escaped_char;
1388 0 $pos--;
1389 } ## end CHAR: while ( $pos > 0 and $pos < $end_of_input )
1390 0 @escaped_chars = reverse @escaped_chars;
1391 0 push @escaped_chars, '\\s' for 1 .. $trailing_spaces;
1392 0 return join q{}, @escaped_chars;
1393 } ## end sub Marpa::R2::Internal::Scanless::input_escape
1394  
1395 sub Marpa::R2::Internal::Scanless::input_escape {
1396 11 ▶ my ( $p_input, $base_pos, $length ) = @_;
Subroutine input_escape: called CC=9 SCAR=25.4
1397 11 my @escaped_chars = ();
1398 11 my $pos = $base_pos;
1399  
1400 11 my $length_so_far = 0;
1401  
1402 11 my $end_of_input = length ${$p_input};
1403 11 ▶ CHAR: while ( $pos < $end_of_input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $end_of_input) 121 3 124
1404 121 my $char = substr ${$p_input}, $pos, 1;
1405 121 my $ord = ord $char;
1406 121 ▶ my $escaped_char = $escape_by_ord[$ord]
Condition33%1/3
$escape_by_ord[$ord] // sprintf("\\x{%04x}", $ord)
l!l&&r!l&&!r
12100
MC/DC0%0/2
$escape_by_ord[$ord] // sprintf("\\x{%04x}", $ord)
$escape_by_ord[$ord] sprintf("\\x{%04x}", $ord)
Truth table33%1/3
A // B
A= $escape_by_ord[$ord]B= sprintf("\\x{%04x}", $ord)
ABresult
1X1
011
000
1407 // sprintf( "\\x{%04x}", $ord );
1408 121 my $char_length = length $escaped_char;
1409 121 $length_so_far += $char_length;
1410 121 ▶ last CHAR if $length_so_far > $length;
Branch: 1 branch
BranchTrueFalseTotal
if $length_so_far > $length 8 113 121
1411 113 push @escaped_chars, $escaped_char;
1412 113 $pos++;
1413 } ## end CHAR: while ( $pos < $end_of_input )
1414  
1415 11 my $trailing_spaces = 0;
1416 TRAILING_SPACE:
1417 11 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($first_non_space_ix >= 0) 11 0 11
1418 my $first_non_space_ix = $#escaped_chars;
1419 $first_non_space_ix >= 0;
1420 $first_non_space_ix--
1421 )
1422 {
1423 11 ▶ last TRAILING_SPACE if $escaped_chars[$first_non_space_ix] ne q{ };
Branch: 1 branch
BranchTrueFalseTotal
if $escaped_chars[$first_non_space_ix] ne " " 11 0 11
1424 0 pop @escaped_chars;
1425 0 $trailing_spaces++;
1426 } ## end TRAILING_SPACE: for ( my $first_non_space_ix = $#escaped_chars; ...)
1427 11 ▶ if ($trailing_spaces) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailing_spaces) 0 11 11
1428 0 $length_so_far -= $trailing_spaces;
1429 0 ▶ TRAILING_SPACE: while ( $trailing_spaces-- > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailing_spaces-- > 0) 0 0 0
1430 0 $length_so_far += 2;
1431 0 ▶ last TRAILING_SPACE if $length_so_far > $length;
Branch: 1 branch
BranchTrueFalseTotal
if $length_so_far > $length 0 0 0
1432 0 push @escaped_chars, '\\s';
1433 }
1434 } ## end if ($trailing_spaces)
1435 11 return join q{}, @escaped_chars;
1436 } ## end sub Marpa::R2::Internal::Scanless::input_escape
1437  
1438 sub Marpa::R2::Scanless::R::ambiguity_metric {
1439 233 ▶ my ($slr) = @_;
Subroutine ambiguity_metric: called CC=2 SCAR=7.0
1440 233 my $thick_g1_recce =
1441 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1442 233 my $ordering = $thick_g1_recce->ordering_get();
1443 233 ▶ my $metric = $ordering ? $ordering->ambiguity_metric() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ordering ? : 233 0 233
1444 233 my $bocage = $thick_g1_recce->[Marpa::R2::Internal::Recognizer::B_C];
1445 233 return $metric;
1446 } ## end sub Marpa::R2::Scanless::R::ambiguity_metric
1447  
1448 sub Marpa::R2::Scanless::R::ambiguous {
1449 222 ▶ my ($slr) = @_;
Subroutine ambiguous: called CC=4 SCAR=13.9
1450 222 local $Marpa::R2::Context::slr = $slr;
1451 222 my $ambiguity_metric = $slr->ambiguity_metric();
1452 222 ▶ return q{No parse} if $ambiguity_metric <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ambiguity_metric <= 0 0 222 222
1453 222 ▶ return q{} if $ambiguity_metric == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $ambiguity_metric == 1 218 4 222
1454 4 my $asf = Marpa::R2::ASF->new( { slr => $slr } );
1455 4 ▶ die 'Could not create ASF' if not defined $asf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $asf 0 4 4
1456 4 my $ambiguities = Marpa::R2::Internal::ASF::ambiguities($asf);
1457 4 my @ambiguities = grep {defined} @{$ambiguities}[ 0 .. 1 ];
1458 4 return Marpa::R2::Internal::ASF::ambiguities_show( $asf, \@ambiguities );
1459 } ## end sub Marpa::R2::Scanless::R::ambiguous
1460  
1461 # This is a Marpa Scanless::G method, but is included in this
1462 # file because internally it is all about the recognizer.
1463 sub Marpa::R2::Scanless::G::parse {
1464 2 ▶ my ( $slg, $input_ref, $arg1, @more_args ) = @_;
Subroutine parse: called CC=12 SCAR=30.4
1465 2 ▶ if ( not defined $input_ref or ref $input_ref ne 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $input_ref or ref $input_ref ne "SCALAR") 0 2 2
Condition33%1/3
not defined $input_ref or ref $input_ref ne "SCALAR"
l!l&&r!l&&!r
002
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"
ABresult
1X1
011
000
1466 0 Marpa::R2::exception(
1467 q{$slr->parse(): first argument must be a ref to string});
1468 }
1469 2 my @recce_args = ( { grammar => $slg } );
1470 2 my @semantics_package_arg = ();
1471 DO_ARG1: {
1472 2 ▶ last if not defined $arg1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg1 0 2 2
1473 2 my $reftype = ref $arg1;
1474 2 ▶ if ( $reftype eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reftype eq "HASH") 0 2 2
1475  
1476 # if second arg is ref to hash, it is the first set
1477 # of named args for
1478 # the recognizer
1479 0 push @recce_args, $arg1;
1480 0 last DO_ARG1;
1481 } ## end if ( $reftype eq 'HASH' )
1482 2 ▶ if ( $reftype eq q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reftype eq "") 2 0 2
1483  
1484 # if second arg is a string, it is the semantic package
1485 2 push @semantics_package_arg, { semantics_package => $arg1 };
1486 }
1487 2 ▶ if ( ref $arg1 and ref $input_ref ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg1 and ref $input_ref ne "HASH") 0 2 2
Condition33%1/3
ref $arg1 and ref $input_ref ne "HASH"
!ll&&!rl&&r
200
MC/DC0%0/2
ref $arg1 and ref $input_ref ne "HASH"
ref $arg1 ref $input_ref ne "HASH"
Truth table33%1/3
A and B
A= ref $arg1B= ref $input_ref ne "HASH"
ABresult
0X0
100
111
1488 0 Marpa::R2::exception(
1489 q{$slr->parse(): second argument must be a package name or a ref to HASH}
1490 );
1491 }
1492 } ## end DO_ARG1:
1493 2 ▶ if ( grep { ref $_ ne 'HASH' } @more_args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {ref $_ ne "HASH";} @more_args) 0 2 2
1494 0 Marpa::R2::exception(
1495 q{$slr->parse(): third and later arguments must be ref to HASH});
1496 }
1497 2 my $slr = Marpa::R2::Scanless::R->new( @recce_args, @more_args,
1498 @semantics_package_arg );
1499 2 my $input_length = ${$input_ref};
1500 2 my $length_read = $slr->read($input_ref);
1501 2 ▶ if ( $length_read != length $input_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length_read != length $input_length) 0 2 2
1502 0 die 'read in $slr->parse() ended prematurely', "\n",
1503 " The input length is $input_length\n",
1504 " The length read is $length_read\n",
1505 " The cause may be an event\n",
1506 " The $slr->parse() method does not allow parses to trigger events";
1507 } ## end if ( $length_read != length $input_length )
1508 2 ▶ if ( my $ambiguous_status = $slr->ambiguous() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ambiguous_status = $slr->ambiguous) 0 2 2
1509 0 Marpa::R2::exception( "Parse of the input is ambiguous\n",
1510 $ambiguous_status );
1511 }
1512  
1513 2 my $value_ref = $slr->value();
1514 2 ▶ Marpa::R2::exception(
Branch: 1 branch
BranchTrueFalseTotal
unless $value_ref 0 2 2
1515 '$slr->parse() read the input, but there was no parse', "\n" )
1516 if not $value_ref;
1517  
1518 2 return $value_ref;
1519 } ## end sub Marpa::R2::Scanless::G::parse
1520  
1521 sub Marpa::R2::Scanless::R::rule_closure {
1522  
1523 15 ▶ my ( $slr, $rule_id ) = @_;
Subroutine rule_closure: called CC=6 SCAR=18.7
1524  
1525 15 my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1526  
1527 15 ▶ if ( not $recce->[Marpa::R2::Internal::Recognizer::REGISTRATIONS] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($recce->[32]) 1 14 15
1528  
1529 1 my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR];
1530 1 my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C];
1531 1 my $recce_c = $recce->[Marpa::R2::Internal::Recognizer::C];
1532 1 my $per_parse_arg = {};
1533 1 ▶ my $trace_actions = $recce->[Marpa::R2::Internal::Recognizer::TRACE_ACTIONS] // 0;
Condition50%1/2
$recce->[16] // 0
l!l
01
MC/DC0%0/1
$recce->[16] // 0
$recce->[16]
Truth table50%1/2
A
A= $recce->[16]
Aresult
11
00
1534 1 my $trace_file_handle = $recce->[Marpa::R2::Internal::Recognizer::TRACE_FILE_HANDLE];
1535 1 my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES];
1536 1 my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS];
1537 1 my $tracer = $grammar->[Marpa::R2::Internal::Grammar::TRACER];
1538  
1539 1 Marpa::R2::Internal::Value::registration_init( $recce, $per_parse_arg );
1540  
1541 } ## end if ( not $recce->[Marpa::R2::Internal::Recognizer::REGISTRATIONS...])
1542  
1543 15 my $rule_closure = $recce->[Marpa::R2::Internal::Recognizer::CLOSURE_BY_RULE_ID]->[$rule_id];
1544 15 ▶ if (defined $rule_closure){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rule_closure) { } 15 0 15
1545 15 my $ref_rule_closure = ref $rule_closure;
1546 15 ▶ if ( $ref_rule_closure eq 'CODE' ){
Branch: 2 branches
BranchTrueFalseTotal
if ($ref_rule_closure eq 'CODE') { } 15 0 15
elsif ($ref_rule_closure eq 'SCALAR') { } 0 0 0
1547 15 return $rule_closure;
1548 }
1549 elsif ( $ref_rule_closure eq 'SCALAR' ){
1550 0 return $rule_closure;
1551 }
1552 }
1553 else{
1554 return
1555 0 }
1556  
1557 } ## end sub Marpa::R2::Scanless::R::rule_closure
1558  
1559 sub Marpa::R2::Scanless::R::value {
1560 5742 ▶ my ( $slr, $per_parse_arg ) = @_;
Subroutine value: called CC=1 SCAR=0.0
1561 5742 my $thick_g1_recce =
1562 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1563 5742 my $thick_g1_value = $thick_g1_recce->value( $slr, $per_parse_arg );
1564 5739 return $thick_g1_value;
1565 } ## end sub Marpa::R2::Scanless::R::value
1566  
1567 sub Marpa::R2::Scanless::R::series_restart {
1568 56 ▶ my ( $slr , @args ) = @_;
Subroutine series_restart: called CC=1 SCAR=0.0
1569 56 my $thick_g1_recce =
1570 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1571  
1572 # Reset SLIF (not NAIF) recognizer args to default
1573 56 $slr->[Marpa::R2::Internal::Scanless::R::EXHAUSTION_ACTION] = 'fatal';
1574 56 $slr->[Marpa::R2::Internal::Scanless::R::REJECTION_ACTION] = 'fatal';
1575  
1576 56 $thick_g1_recce->reset_evaluation();
1577 56 my ($g1_recce_args) = Marpa::R2::Internal::Scanless::R::set($slr, "series_restart", @args );
1578 56 $thick_g1_recce->set( $g1_recce_args );
1579 56 return 1;
1580 }
1581  
1582 # Given a list of G1 locations, return the minimum span in the input string
1583 # that includes them all
1584 # Caller must ensure that there is an input, which is not the case
1585 # when the parse is initialized.
1586 sub g1_locations_to_input_range {
1587 108 ▶ my ( $slr, @g1_locations ) = @_;
Subroutine g1_locations_to_input_range: called CC=5 SCAR=16.1
1588 108 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1589 108 my $first_pos = $thin_slr->input_length();
1590 108 my $last_pos = 0;
1591 108 for my $g1_location (@g1_locations) {
1592 269 my ( $input_start, $input_length ) = $thin_slr->span($g1_location);
1593 269 ▶ my $input_end = $input_length ? $input_start + $input_length - 1 : $input_start;
Branch: 1 branch
BranchTrueFalseTotal
$input_length ? : 243 26 269
1594 269 ▶ $first_pos = $input_start if $input_start < $first_pos;
Branch: 1 branch
BranchTrueFalseTotal
if $input_start < $first_pos 179 90 269
1595 269 ▶ $last_pos = $input_end if $input_end > $last_pos;
Branch: 1 branch
BranchTrueFalseTotal
if $input_end > $last_pos 104 165 269
1596 } ## end for my $g1_location (@other_g1_locations)
1597 108 return ($first_pos, $last_pos);
1598 }
1599  
1600 sub input_range_describe {
1601 141 ▶ my ( $slr, $first_pos, $last_pos ) = @_;
Subroutine input_range_describe: called CC=3 SCAR=11.0
1602 141 my ( $first_line, $first_column ) = $slr->line_column($first_pos);
1603 141 my ( $last_line, $last_column ) = $slr->line_column($last_pos);
1604 141 ▶ if ( $first_line == $last_line ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_line == $last_line) 129 12 141
1605 129 ▶ return join q{}, 'L', $first_line, 'c', $first_column
Branch: 1 branch
BranchTrueFalseTotal
if $first_column == $last_column 58 71 129
1606 if $first_column == $last_column;
1607 71 return join q{}, 'L', $first_line, 'c', $first_column, '-',
1608 $last_column;
1609 } ## end if ( $first_line == $last_line )
1610 12 return join q{}, 'L', $first_line, 'c', $first_column, '-L', $last_line,
1611 'c', $last_column;
1612 } ## end sub input_range_describe
1613  
1614 sub Marpa::R2::Scanless::R::show_progress {
1615 13 ▶ my ( $slr, $start_ordinal, $end_ordinal ) = @_;
Subroutine show_progress: called CC=18 SCAR=29.1
1616 13 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1617 13 my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1618 13 my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR];
1619 13 my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C];
1620  
1621 13 my $last_ordinal = $recce->latest_earley_set();
1622  
1623 13 ▶ if ( not defined $start_ordinal ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $start_ordinal) 2 11 13
1624 2 $start_ordinal = $last_ordinal;
1625 }
1626 13 ▶ if ( $start_ordinal < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_ordinal < 0) { } 0 13 13
1627 0 $start_ordinal += $last_ordinal + 1;
1628 }
1629 else {
1630 13 ▶ if ( $start_ordinal < 0 or $start_ordinal > $last_ordinal ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_ordinal < 0 or $start_ordinal > $last_ordinal) 0 13 13
Condition33%1/3
$start_ordinal < 0 or $start_ordinal > $last_ordinal
l!l&&r!l&&!r
0013
MC/DC0%0/2
$start_ordinal < 0 or $start_ordinal > $last_ordinal
$start_ordinal < 0 $start_ordinal > $last_ordinal
Truth table33%1/3
A or B
A= $start_ordinal < 0B= $start_ordinal > $last_ordinal
ABresult
1X1
011
000
1631 return
1632 0 "Marpa::PP::Recognizer::show_progress start index is $start_ordinal, "
1633 . "must be in range 0-$last_ordinal";
1634 }
1635 } ## end else [ if ( $start_ordinal < 0 ) ]
1636  
1637 13 ▶ if ( not defined $end_ordinal ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $end_ordinal) { } 12 1 13
1638 12 $end_ordinal = $start_ordinal;
1639 }
1640 else {
1641 1 my $end_ordinal_argument = $end_ordinal;
1642 1 ▶ if ( $end_ordinal < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_ordinal < 0) 1 0 1
1643 1 $end_ordinal += $last_ordinal + 1;
1644 }
1645 1 ▶ if ( $end_ordinal < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_ordinal < 0) 0 1 1
1646 return
1647 0 "Marpa::PP::Recognizer::show_progress end index is $end_ordinal_argument, "
1648 . sprintf ' must be in range %d-%d', -( $last_ordinal + 1 ),
1649 $last_ordinal;
1650 } ## end if ( $end_ordinal < 0 )
1651 } ## end else [ if ( not defined $end_ordinal ) ]
1652  
1653 13 my $text = q{};
1654 13 for my $current_ordinal ( $start_ordinal .. $end_ordinal ) {
1655 18 my $current_earleme = $recce->earleme($current_ordinal);
1656 18 my %by_rule_by_position = ();
1657 18 for my $progress_item ( @{ $recce->progress($current_ordinal) } ) {
1658 170 my ( $rule_id, $position, $origin ) = @{$progress_item};
1659 170 ▶ if ( $position < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position < 0) 100 70 170
1660 100 $position = $grammar_c->rule_length($rule_id);
1661 }
1662 170 $by_rule_by_position{$rule_id}->{$position}->{$origin}++;
1663 } ## end for my $progress_item ( @{ $recce->progress($current_ordinal...)})
1664  
1665 18 for my $rule_id ( sort { $a <=> $b } keys %by_rule_by_position ) {
1666 98 my $by_position = $by_rule_by_position{$rule_id};
1667 98 for my $position ( sort { $a <=> $b } keys %{$by_position} ) {
1668 117 my $raw_origins = $by_position->{$position};
1669 117 my @origins = sort { $a <=> $b } keys %{$raw_origins};
1670 117 my $origins_count = scalar @origins;
1671 117 my $origin_desc;
1672 117 ▶ if ( $origins_count <= 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($origins_count <= 3) { } 114 3 117
1673 114 $origin_desc = join q{,}, @origins;
1674 }
1675 else {
1676 3 $origin_desc = $origins[0] . q{...} . $origins[-1];
1677 }
1678  
1679 117 my $rhs_length = $grammar_c->rule_length($rule_id);
1680 117 my @item_text;
1681  
1682 117 ▶ if ( $position >= $rhs_length ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($position >= $rhs_length) { } 47 70 117
elsif ($position) { } 28 42 70
1683 47 push @item_text, "F$rule_id";
1684 }
1685 elsif ($position) {
1686 28 push @item_text, "R$rule_id:$position";
1687 }
1688 else {
1689 42 push @item_text, "P$rule_id";
1690 }
1691 117 ▶ push @item_text, "x$origins_count" if $origins_count > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $origins_count > 1 15 102 117
1692 117 push @item_text, q{@} . $origin_desc . q{-} . $current_earleme;
1693  
1694 117 ▶ if ( $current_earleme > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_earleme > 0) { } 108 9 117
1695 108 my $input_range = input_range_describe(
1696 $slr,
1697 g1_locations_to_input_range(
1698 $slr, $current_earleme, @origins
1699 )
1700 );
1701 108 push @item_text, $input_range;
1702 }
1703 else {
1704 9 push @item_text, 'L0c0';
1705 }
1706  
1707 117 push @item_text, $slg->show_dotted_rule( $rule_id, $position );
1708 117 $text .= ( join q{ }, @item_text ) . "\n";
1709 } ## end for my $position ( sort { $a <=> $b } keys %{...})
1710 } ## end for my $rule_id ( sort { $a <=> $b } keys ...)
1711  
1712 } ## end for my $current_ordinal ( $start_ordinal .. $end_ordinal)
1713 13 return $text;
1714 }
1715  
1716 sub Marpa::R2::Scanless::R::progress {
1717 30 ▶ my ( $self, @args ) = @_;
Subroutine progress: called CC=1 SCAR=0.0
1718 30 return $self->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]
1719 ->progress(@args);
1720 }
1721  
1722 sub Marpa::R2::Scanless::R::terminals_expected {
1723 69 ▶ my ($self) = @_;
Subroutine terminals_expected: called CC=1 SCAR=0.0
1724 69 return $self->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]
1725 ->terminals_expected();
1726 }
1727  
1728 sub Marpa::R2::Scanless::R::exhausted {
1729 18 ▶ my ($self) = @_;
Subroutine exhausted: called CC=1 SCAR=0.0
1730 18 return $self->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]
1731 ->exhausted();
1732 }
1733  
1734 # Latest and current G1 location are the same
1735 sub Marpa::R2::Scanless::R::latest_g1_location {
1736 1 ▶ my ($slg) = @_;
Subroutine latest_g1_location: called CC=1 SCAR=0.0
1737 1 return $slg->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]
1738 ->latest_earley_set();
1739 }
1740  
1741 # Latest and current G1 location are the same
1742 sub Marpa::R2::Scanless::R::current_g1_location {
1743 137 ▶ my ($slg) = @_;
Subroutine current_g1_location: called CC=1 SCAR=0.0
1744 137 return $slg->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]
1745 ->latest_earley_set();
1746 }
1747  
1748 sub Marpa::R2::Scanless::R::lexeme_alternative {
1749 194 ▶ my ( $slr, $symbol_name, @value ) = @_;
Subroutine lexeme_alternative: called CC=7 SCAR=26.3
1750 194 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1751  
1752 194 ▶ Marpa::R2::exception(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $symbol_name 0 194 194
1753 "slr->alternative(): symbol name is undefined\n",
1754 " The symbol name cannot be undefined\n"
1755 ) if not defined $symbol_name;
1756  
1757 194 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1758 194 my $g1_grammar = $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR];
1759 194 my $g1_tracer = $g1_grammar->tracer();
1760 194 my $symbol_id = $g1_tracer->symbol_by_name($symbol_name);
1761 194 ▶ if ( not defined $symbol_id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $symbol_id) 0 194 194
1762 0 Marpa::R2::exception(
1763 qq{slr->alternative(): symbol "$symbol_name" does not exist});
1764 }
1765  
1766 194 my $result = $thin_slr->g1_alternative( $symbol_id, @value );
1767 194 ▶ return 1 if $result == $Marpa::R2::Error::NONE;
Branch: 1 branch
BranchTrueFalseTotal
if $result == $Marpa::R2::Error::NONE 194 0 194
1768  
1769 # The last two are perhaps unnecessary or arguable,
1770 # but they preserve compatibility with Marpa::XS
1771 return
1772 0 ▶ if $result == $Marpa::R2::Error::UNEXPECTED_TOKEN_ID
Branch: 1 branch
BranchTrueFalseTotal
if $result == $Marpa::R2::Error::UNEXPECTED_TOKEN_ID or $result == $Marpa::R2::Error::NO_TOKEN_EXPECTED_HERE or $result == $Marpa::R2::Error::INACCESSIBLE_TOKEN 0 0 0
Condition0%0/6
$result == $Marpa::R2::Error::UNEXPECTED_TOKEN_ID or $result == $Marpa::R2::Error::NO_TOKEN_EXPECTED_HERE or $result == $Marpa::R2::Error::INACCESSIBLE_TOKEN
l!l&&r!l&&!r
000
$result == $Marpa::R2::Error::UNEXPECTED_TOKEN_ID or $result == $Marpa::R2::Error::NO_TOKEN_EXPECTED_HERE
l!l&&r!l&&!r
000
MC/DC0%0/3
$result == $Marpa::R2::Error::UNEXPECTED_TOKEN_ID or $result == $Marpa::R2::Error::NO_TOKEN_EXPECTED_HERE or $result == $Marpa::R2::Error::INACCESSIBLE_TOKEN
$result == $Marpa::R2::Error::UNEXPECTED_TOKEN_ID $result == $Marpa::R2::Error::NO_TOKEN_EXPECTED_HERE $result == $Marpa::R2::Error::INACCESSIBLE_TOKEN
Truth table0%0/4
A or B or C
A= $result == $Marpa::R2::Error::UNEXPECTED_TOKEN_IDB= $result == $Marpa::R2::Error::NO_TOKEN_EXPECTED_HEREC= $result == $Marpa::R2::Error::INACCESSIBLE_TOKEN
ABCresult
1XX1
01X1
0011
0000
1773 || $result == $Marpa::R2::Error::NO_TOKEN_EXPECTED_HERE
1774 || $result == $Marpa::R2::Error::INACCESSIBLE_TOKEN;
1775  
1776 0 Marpa::R2::exception( qq{Problem reading symbol "$symbol_name": },
1777 ( scalar $g1_grammar->error() ) );
1778 } ## end sub Marpa::R2::Scanless::R::lexeme_alternative
1779  
1780 # Returns 0 on unthrown failure, current location on success
1781 sub Marpa::R2::Scanless::R::lexeme_complete {
1782 194 ▶ my ( $slr, $start, $length ) = @_;
Subroutine lexeme_complete: called CC=9 SCAR=25.6
1783 194 ▶ Marpa::R2::exception( q{Bad call to $recce->lexeme_complete(): },
Branch: 1 branch
BranchTrueFalseTotal
if defined $start and not &Scalar::Util::looks_like_number($start) 0 194 194
Condition66%2/3
defined $start and not &Scalar::Util::looks_like_number($start)
!ll&&!rl&&r
91850
MC/DC0%0/2
defined $start and not &Scalar::Util::looks_like_number($start)
defined $start not &Scalar::Util::looks_like_number($start)
Truth table66%2/3
A and not(B)
A= defined $startB= not &Scalar::Util::looks_like_number($start)
ABresult
0X0
100
111
1784 qq{start "$start" is not numeric})
1785 if defined $start
1786 and not Scalar::Util::looks_like_number( $start );
1787 194 ▶ Marpa::R2::exception( q{Bad call to $recce->lexeme_complete(): },
Branch: 1 branch
BranchTrueFalseTotal
if defined $length and not &Scalar::Util::looks_like_number($length) 0 194 194
Condition33%1/3
defined $length and not &Scalar::Util::looks_like_number($length)
!ll&&!rl&&r
01940
MC/DC0%0/2
defined $length and not &Scalar::Util::looks_like_number($length)
defined $length not &Scalar::Util::looks_like_number($length)
Truth table33%1/3
A and not(B)
A= defined $lengthB= not &Scalar::Util::looks_like_number($length)
ABresult
0X0
100
111
1788 qq{length "$length" is not numeric})
1789 if defined $length
1790 and not Scalar::Util::looks_like_number( $length );
1791 194 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1792 194 $slr->[Marpa::R2::Internal::Scanless::R::EVENTS] = [];
1793 194 my $thin_pos = $thin_slr->pos();
1794 194 ▶ $start //= $thin_pos;
Condition66%2/3
$start //= $thin_pos
l!l&&r!l&&!r
18590
MC/DC0%0/2
$start //= $thin_pos
$start $thin_pos
Truth table66%2/3
A //= B
A= $startB= $thin_pos
ABresult
1X1
011
000
1795 194 ▶ if (not defined $length) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $length) 0 194 194
1796 0 my ($pause_start, $pause_length) = $thin_slr->pause_span();
1797 0 ▶ $length = ($pause_start == $thin_pos) ? $pause_length : -1;
Branch: 1 branch
BranchTrueFalseTotal
$pause_start == $thin_pos ? : 0 0 0
1798 }
1799 194 my $return_value = $thin_slr->g1_lexeme_complete($start, $length);
1800 194 Marpa::R2::Internal::Scanless::convert_libmarpa_events($slr);
1801 194 ▶ die q{} . $thin_slr->g1()->error() if $return_value == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $return_value == 0 0 194 194
1802 194 return $return_value;
1803 } ## end sub Marpa::R2::Scanless::R::lexeme_complete
1804  
1805 # Returns 0 on unthrown failure, current location on success,
1806 # undef if lexeme not accepted.
1807 sub Marpa::R2::Scanless::R::lexeme_read {
1808 163 ▶ my ( $slr, $symbol_name, $start, $length, @value ) = @_;
Subroutine lexeme_read: called CC=2 SCAR=7.1
1809 163 ▶ return if not $slr->lexeme_alternative( $symbol_name, @value );
Branch: 1 branch
BranchTrueFalseTotal
unless $slr->lexeme_alternative($symbol_name, @value) 0 163 163
1810 163 return $slr->lexeme_complete( $start, $length );
1811 }
1812  
1813 sub Marpa::R2::Scanless::R::pause_span {
1814 242 ▶ my ($slr) = @_;
Subroutine pause_span: called CC=1 SCAR=0.0
1815 242 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1816 242 return $thin_slr->pause_span();
1817 }
1818  
1819 sub Marpa::R2::Scanless::R::pause_lexeme {
1820 67 ▶ my ($slr) = @_;
Subroutine pause_lexeme: called CC=2 SCAR=6.9
1821 67 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1822 67 my $grammar = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1823 67 my $thick_g1_grammar =
1824 $grammar->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR];
1825 67 my $g1_tracer = $thick_g1_grammar->tracer();
1826 67 my $symbol = $thin_slr->pause_lexeme();
1827 67 ▶ return if not defined $symbol;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $symbol 1 66 67
1828 66 return $g1_tracer->symbol_name($symbol);
1829 } ## end sub Marpa::R2::Scanless::R::pause_lexeme
1830  
1831 sub Marpa::R2::Scanless::R::line_column {
1832 429 ▶ my ( $slr, $pos ) = @_;
Subroutine line_column: called CC=2 SCAR=7.4
1833 429 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1834 429 ▶ $pos //= $thin_slr->pos();
Condition33%1/3
$pos //= $thin_slr->pos
l!l&&r!l&&!r
42900
MC/DC0%0/2
$pos //= $thin_slr->pos
$pos $thin_slr->pos
Truth table33%1/3
A //= B
A= $posB= $thin_slr->pos
ABresult
1X1
011
000
1835 429 return $thin_slr->line_column($pos);
1836 } ## end sub Marpa::R2::Scanless::R::line_column
1837  
1838 sub Marpa::R2::Scanless::R::pos {
1839 9 ▶ my ( $slr ) = @_;
Subroutine pos: called CC=1 SCAR=0.0
1840 9 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1841 9 return $thin_slr->pos();
1842 }
1843  
1844 sub Marpa::R2::Scanless::R::input_length {
1845 1 ▶ my ( $slr ) = @_;
Subroutine input_length: called CC=1 SCAR=0.0
1846 1 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1847 1 return $thin_slr->input_length();
1848 }
1849  
1850 # no return value documented
1851 sub Marpa::R2::Scanless::R::activate {
1852 536 ▶ my ( $slr, $event_name, $activate ) = @_;
Subroutine activate: called CC=6 SCAR=17.9
1853 536 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1854 536 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1855 536 ▶ $activate //= 1;
Condition100%2/2
$activate //= 1
l!l
51620
MC/DC100%1/1
$activate //= 1
$activate
Truth table100%2/2
A
A= $activate
Aresult
11
00
1856 536 my $thick_g1_recce =
1857 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1858 536 my $thin_g1_recce = $thick_g1_recce->thin();
1859 my $event_symbol_ids_by_type =
1860 $slg
1861 ->[Marpa::R2::Internal::Scanless::G::SYMBOL_IDS_BY_EVENT_NAME_AND_TYPE]
1862 536 ->{$event_name};
1863 $thin_g1_recce->completion_symbol_activate( $_, $activate )
1864 536 for @{ $event_symbol_ids_by_type->{completion} };
1865 $thin_g1_recce->nulled_symbol_activate( $_, $activate )
1866 536 for @{ $event_symbol_ids_by_type->{nulled} };
1867 $thin_g1_recce->prediction_symbol_activate( $_, $activate )
1868 536 for @{ $event_symbol_ids_by_type->{prediction} };
1869 $thin_slr->lexeme_event_activate( $_, $activate )
1870 536 for @{ $event_symbol_ids_by_type->{lexeme} };
1871 536 return 1;
1872 } ## end sub Marpa::R2::Scanless::R::activate
1873  
1874 # On success, returns the old priority value.
1875 # Failures are thrown.
1876 sub Marpa::R2::Scanless::R::lexeme_priority_set {
1877 12 ▶ my ($slr, $lexeme_name, $new_priority) = @_;
Subroutine lexeme_priority_set: called CC=2 SCAR=7.0
1878 12 my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C];
1879 12 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1880 12 my $thick_g1_grammar =
1881 $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR];
1882 12 my $g1_tracer = $thick_g1_grammar->tracer();
1883 12 my $lexeme_id = $g1_tracer->symbol_by_name($lexeme_name);
1884 12 ▶ Marpa::R2::exception("Bad symbol in lexeme_priority_set(): $lexeme_name")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lexeme_id 0 12 12
1885 if not defined $lexeme_id;
1886 12 return $thin_slr->lexeme_priority_set($lexeme_id, $new_priority);
1887 }
1888  
1889 # Internal methods, not to be documented
1890  
1891 sub Marpa::R2::Scanless::R::thick_g1_grammar {
1892 0 ▶ my ($slr) = @_;
Subroutine thick_g1_grammar: not called CC=1 SCAR=6.9
1893 0 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1894 0 return $slg->[Marpa::R2::Internal::Scanless::G::THICK_G1_GRAMMAR];
1895 }
1896  
1897 sub Marpa::R2::Scanless::R::thick_g1_recce {
1898 0 ▶ my ($slr) = @_;
Subroutine thick_g1_recce: not called CC=1 SCAR=6.9
1899 0 return $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1900 }
1901  
1902 sub Marpa::R2::Scanless::R::default_g1_start_closure {
1903 0 ▶ my ($slr) = @_;
Subroutine default_g1_start_closure: not called CC=2 SCAR=17.9
1904 0 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1905 0 my $default_action_name =
1906 $slg->[Marpa::R2::Internal::Scanless::G::DEFAULT_G1_START_ACTION];
1907 0 my $thick_g1_recce =
1908 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1909 0 my $resolution =
1910 Marpa::R2::Internal::Recognizer::resolve_action( $thick_g1_recce,
1911 $default_action_name );
1912 0 ▶ return if not $resolution;
Branch: 1 branch
BranchTrueFalseTotal
unless $resolution 0 0 0
1913 0 my ( undef, $closure ) = @{$resolution};
1914 0 return $closure;
1915 } ## end sub Marpa::R2::Scanless::R::default_g1_start_closure
1916  
1917 # not to be documented
1918 sub Marpa::R2::Scanless::R::latest_earley_set {
1919 1 ▶ my ($self) = @_;
Subroutine latest_earley_set: called CC=1 SCAR=0.0
1920 1 return $self->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]
1921 ->latest_earley_set();
1922 }
1923  
1924 sub Marpa::R2::Scanless::R::earley_set_size {
1925 0 ▶ my ($self, $set_id) = @_;
Subroutine earley_set_size: not called CC=1 SCAR=6.9
1926 # OK if set ID is undef, just pass it on.
1927 0 return $self->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]
1928 ->earley_set_size($set_id);
1929 }
1930  
1931 sub Marpa::R2::Scanless::R::verbose_or_nodes {
1932 0 ▶ my ( $slr ) = @_;
Subroutine verbose_or_nodes: not called CC=1 SCAR=6.9
1933 0 my $thick_g1_recce =
1934 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1935 0 return $thick_g1_recce->verbose_or_nodes();
1936 }
1937  
1938 sub Marpa::R2::Scanless::R::show_and_nodes {
1939 0 ▶ my ( $slr, $verbose ) = @_;
Subroutine show_and_nodes: not called CC=2 SCAR=17.9
1940 0 ▶ $verbose //= 0;
Condition0%0/2
$verbose //= 0
l!l
00
MC/DC0%0/1
$verbose //= 0
$verbose
Truth table0%0/2
A
A= $verbose
Aresult
11
00
1941 0 my $thick_g1_recce =
1942 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1943 0 return $thick_g1_recce->show_and_nodes($verbose);
1944 }
1945  
1946 sub Marpa::R2::Scanless::R::show_bocage {
1947 0 ▶ my ( $slr, $verbose ) = @_;
Subroutine show_bocage: not called CC=2 SCAR=17.9
1948 0 ▶ $verbose //= 0;
Condition0%0/2
$verbose //= 0
l!l
00
MC/DC0%0/1
$verbose //= 0
$verbose
Truth table0%0/2
A
A= $verbose
Aresult
11
00
1949 0 my $thick_g1_recce =
1950 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1951 0 return $thick_g1_recce->show_bocage($verbose);
1952 }
1953  
1954 sub Marpa::R2::Scanless::R::show_earley_sets {
1955 0 ▶ my ( $slr, $verbose ) = @_;
Subroutine show_earley_sets: not called CC=2 SCAR=17.9
1956 0 ▶ $verbose //= 0;
Condition0%0/2
$verbose //= 0
l!l
00
MC/DC0%0/1
$verbose //= 0
$verbose
Truth table0%0/2
A
A= $verbose
Aresult
11
00
1957 0 my $thick_g1_recce =
1958 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1959 0 return $thick_g1_recce->show_earley_sets($verbose);
1960 }
1961  
1962 sub Marpa::R2::Scanless::R::show_leo_items {
1963 10 ▶ my ( $slr, $ordinal ) = @_;
Subroutine show_leo_items: called CC=6 SCAR=18.3
1964 10 my $thick_g1_recce =
1965 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
1966 10 my $grammar = $thick_g1_recce->[Marpa::R2::Internal::Recognizer::GRAMMAR];
1967 10 my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C];
1968 10 my $recce_c = $thick_g1_recce->[Marpa::R2::Internal::Recognizer::C];
1969  
1970 10 my $last_ordinal = $thick_g1_recce->latest_earley_set();
1971 10 ▶ if ( $ordinal < 0 or $ordinal > $last_ordinal ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ordinal < 0 or $ordinal > $last_ordinal) 0 10 10
Condition33%1/3
$ordinal < 0 or $ordinal > $last_ordinal
l!l&&r!l&&!r
0010
MC/DC0%0/2
$ordinal < 0 or $ordinal > $last_ordinal
$ordinal < 0 $ordinal > $last_ordinal
Truth table33%1/3
A or B
A= $ordinal < 0B= $ordinal > $last_ordinal
ABresult
1X1
011
000
1972 return
1973 0 "Marpa::PP::Recognizer::show_leo_items start index is $ordinal, "
1974 . "must be in range 0-$last_ordinal";
1975 }
1976 10 ▶ die if not defined $recce_c->_marpa_r_earley_set_trace($ordinal);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $recce_c->_marpa_r_earley_set_trace($ordinal) 0 10 10
1977 10 my @lines = ();
1978 POSTDOT_ITEM:
1979 10 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $postdot_symbol_id) 38 10 48
1980 my $postdot_symbol_id = $recce_c->_marpa_r_first_postdot_item_trace() ;
1981 defined $postdot_symbol_id ;
1982 $postdot_symbol_id = $recce_c->_marpa_r_next_postdot_item_trace()
1983 )
1984 {
1985  
1986 # If there is no base Earley item,
1987 # then this is not a Leo item, so we skip it
1988 38 my $leo_item_desc = $slr->show_leo_item();
1989 38 ▶ next POSTDOT_ITEM if not defined $leo_item_desc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $leo_item_desc 32 6 38
1990 6 push @lines, $leo_item_desc;
1991 } ## end POSTDOT_ITEM: for ( my $postdot_symbol_id = $recce_c...)
1992  
1993 10 return join "\n", @lines, '';
1994 }
1995  
1996 sub Marpa::R2::Scanless::R::show_leo_item {
1997 38 ▶ my ($slr) = @_;
Subroutine show_leo_item: called CC=3 SCAR=11.0
1998 38 my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR];
1999 38 my $thick_g1_recce =
2000 $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
2001 38 my $recce_c = $thick_g1_recce->[Marpa::R2::Internal::Recognizer::C];
2002 38 my $grammar = $thick_g1_recce->[Marpa::R2::Internal::Recognizer::GRAMMAR];
2003 38 my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C];
2004 38 my $tracer = $grammar->[Marpa::R2::Internal::Grammar::TRACER];
2005 38 my $base_ahm_id = $recce_c->_marpa_r_leo_top_ahm();
2006 38 ▶ return if not defined $base_ahm_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base_ahm_id 32 6 38
2007 6 my $trace_earley_set = $recce_c->_marpa_r_trace_earley_set();
2008 6 my $trace_earleme = $recce_c->earleme($trace_earley_set);
2009 6 my $postdot_symbol_id = $recce_c->_marpa_r_postdot_item_symbol();
2010 6 my $postdot_symbol_name = $tracer->isy_name($postdot_symbol_id);
2011 # my $predecessor_symbol_id = $recce_c->_marpa_r_leo_predecessor_symbol();
2012 6 my $base_origin_set_id = $recce_c->_marpa_r_leo_base_origin();
2013 6 my $base_origin_earleme = $recce_c->earleme($base_origin_set_id);
2014  
2015 6 my $base_irl_id = $grammar_c->_marpa_g_ahm_irl($base_ahm_id);
2016 6 my $base_rule_id = $grammar_c->_marpa_g_source_xrl($base_irl_id);
2017 6 my $base_desc;
2018 6 ▶ if (defined $base_rule_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base_rule_id) { } 6 0 6
2019 6 $base_desc = '[' . $slg->show_dotted_rule($base_rule_id, -2) . ']';
2020 } else {
2021 0 $base_desc = 'IRL#' . $base_irl_id;
2022 }
2023  
2024 6 my $text = sprintf 'L%d', $trace_earleme;
2025 6 my @link_texts = ($base_desc, qq{"$postdot_symbol_name"}, "$base_origin_earleme");
2026 6 $text .= ' [' . ( join '; ', @link_texts ) . ']';
2027 6 return $text;
2028 }
2029  
2030 sub Marpa::R2::Scanless::R::show_parse_items {
2031 10 ▶ my ( $slr, $ordinal ) = @_;
Subroutine show_parse_items: called CC=1 SCAR=0.0
2032 10 my $text = $slr->show_progress($ordinal);
2033 10 $text .= $slr->show_leo_items($ordinal);
2034 10 return $text;
2035 }
2036  
2037 150 1;
2038  
2039 # vim: expandtab shiftwidth=4:
« blib/lib/Marpa/R2/Value.pm ↑ Summary blib/lib/Marpa/R2/Grammar.pm »