File Coverage

blib/lib/Marpa/PP/Callback.pm
Criterion Covered Total %
statement 38 40 95.0
branch 4 8 50.0
condition n/a
subroutine 10 10 100.0
pod 0 2 0.0
total 52 60 86.6


line stmt bran cond sub pod time code
1             # Copyright 2012 Jeffrey Kegler
2             # This file is part of Marpa::PP. Marpa::PP 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::PP 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::PP. If not, see
14             # http://www.gnu.org/licenses/.
15              
16             package Marpa::PP::Callback;
17              
18 44     44   1373 use 5.010;
  44         172  
  44         2142  
19 44     44   298 use warnings;
  44         106  
  44         2024  
20 44     44   263 use strict;
  44         97  
  44         1808  
21 44     44   254 use integer;
  44         100  
  44         341  
22              
23 44     44   1290 use vars qw($VERSION $STRING_VERSION);
  44         97  
  44         5454  
24             $VERSION = '0.014000';
25             $STRING_VERSION = $VERSION;
26             {
27             ## no critic (BuiltinFunctions::ProhibitStringyEval)
28             ## no critic (ValuesAndExpressions::RequireConstantVersion)
29             $VERSION = eval $VERSION;
30             }
31              
32             package Marpa::PP::Internal::Callback;
33              
34 44     44   360 use English qw( -no_match_vars );
  44         105  
  44         472  
35              
36             sub Marpa::PP::location {
37 66 50   66 0 219 Marpa::PP::exception('No context for location callback')
38             if not my $context = $Marpa::PP::Internal::CONTEXT;
39 66         79 my ( $context_type, $and_node, $recce ) = @{$context};
  66         122  
40 66 50       235 if ( $context_type eq 'and-node' ) {
41 66         115 my $earleme =
42             $and_node->[Marpa::PP::Internal::And_Node::START_EARLEME];
43 66         98 my $earley_sets =
44             $recce->[Marpa::PP::Internal::Recognizer::EARLEY_SETS];
45 66         230 return $earley_sets->[$earleme]
46             ->[Marpa::PP::Internal::Earley_Set::ORDINAL];
47             } ## end if ( $context_type eq 'and-node' )
48 0         0 Marpa::PP::exception('LOCATION called outside and-node context');
49             } ## end sub Marpa::PP::location
50              
51             sub Marpa::PP::cause_location {
52 80 50   80 0 512 Marpa::PP::exception('No context for cause_location callback')
53             if not my $context = $Marpa::PP::Internal::CONTEXT;
54 80         93 my ( $context_type, $and_node, $recce ) = @{$context};
  80         137  
55 80 50       183 if ( $context_type eq 'and-node' ) {
56 80         115 my $earleme =
57             $and_node->[Marpa::PP::Internal::And_Node::CAUSE_EARLEME];
58 80         103 my $earley_sets =
59             $recce->[Marpa::PP::Internal::Recognizer::EARLEY_SETS];
60 80         401 return $earley_sets->[$earleme]
61             ->[Marpa::PP::Internal::Earley_Set::ORDINAL];
62             } ## end if ( $context_type eq 'and-node' )
63 0           Marpa::PP::exception('cause_location() called outside and-node context');
64             } ## end sub Marpa::PP::cause_location
65              
66 44     44   47940 no strict 'refs';
  44         114  
  44         2214  
67             *{'Marpa::PP::token_location'} = \&Marpa::PP::cause_location;
68 44     44   240 use strict;
  44         103  
  44         2516  
69              
70             1;