blib/lib/Marpa/R2/Stuifzand.pm

filter: Statementstmt 85.5% 71 / 83 Branchbran 43.7% 7 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 78.3% 87 / 111 SCAR 25.0
CC
11
Cov
78%
check_ast_node
14.8
parse_rules
4.1
BEGIN
1.0
CRAP 12.2
« blib/lib/Marpa/R2.pm ↑ Summary html/tool/lib/Marpa/R2/HTML/Test/Util.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::Stuifzand;
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::Stuifzand;
30  
31 150 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 # Internal names end in ']' and are distinguished by prefix.
34 #
35 # Suffixed with '[prec%d]' --
36 # a symbol created to implement precedence.
37 # Suffix is removed to restore 'original'.
38 #
39 # Prefixed with '[[' -- a character class
40 # These are their own 'original'.
41 #
42 # Prefixed with '[:' -- a reserved symbol, one which in the
43 # grammars start with a colon.
44 # These are their own 'original'.
45 #
46 # Of the form '[Lex-42]' - where for '42' any other
47 # decimal number can be subsituted. Anonymous lexicals.
48 # These symbols are their own originals.
49 #
50 # Prefixed with '[SYMBOL#' - a unnamed internal symbol.
51 # Seeing these
52 # indicates some sort of internal error. If seen,
53 # they will be treated as their own original.
54 #
55 # Suffixed with '[Sep]' indicates an internal version
56 # of a sequence separator. These are their own
57 # original, because otherwise the "original" name
58 # would conflict with the LHS of the sequence.
59 #
60  
61 my %node_status =
62 150 map { ; ($_ , q{} ) }
63 qw(
64 action
65 action_name
66 adverb_item
67 adverb_list
68 adverb_list_items
69 alternative
70 alternatives
71 array_descriptor
72 bare_name
73 blessing
74 blessing_name
75 boolean
76 bracketed_name
77 default_rule
78 empty_rule
79 group_association
80 left_association
81 lhs
82 op_declare
83 op_declare_bnf
84 parenthesized_rhs_primary_list
85 Perl_name
86 priorities
87 priority_rule
88 proper_specification
89 quantified_rule
90 quantifier
91 reserved_action_name
92 reserved_blessing_name
93 rhs
94 rhs_primary
95 rhs_primary_list
96 right_association
97 separator_specification
98 single_symbol
99 standard_name
100 start_rule
101 statement
102 statements
103 symbol
104 symbol_name
105 );
106  
107  
108 150 $node_status{'Marpa::R2::Internal::MetaAST'} = q{};
109 150 $node_status{array_descriptor} = "Actions in the form of array descriptors are not allowed";
110 150 $node_status{character_class} = "Character classes are not allowed";
111 150 $node_status{completion_event_declaration} = "Completion events are not allowed";
112 150 $node_status{discard_rule} = ":discard rules are not allowed";
113 150 $node_status{event_specification} = qq{The "event" adverb is not allowed};
114 150 $node_status{latm_specification} = qq{The "latm" adverb is not allowed};
115 150 $node_status{lexeme_default_statement} = "The lexeme default statement is not allowed";
116 150 $node_status{lexeme_rule} = "Lexeme statements are not allowed";
117 150 $node_status{nulled_event_declaration} = "Nulled events are not allowed";
118 150 $node_status{op_declare_match} = "lexical rules are not allowed";
119 150 $node_status{pause_specification} = "The pause adverb is not allowed";
120 150 $node_status{prediction_event_declaration} = "Prediction events are not allowed";
121 150 $node_status{priority_specification} = "The priority adverb is not allowed";
122 150 $node_status{single_quoted_string} = "Quoted strings are not allowed";
123 150 $node_status{alternative_name} = "Alternative naming is not allowed";
124 150 $node_status{naming} = "Alternative naming is not allowed";
125  
126 my %catch_error_node =
127 150 map { ; ($_ , 1 ) }
128 qw( alternative statement );
129  
130 # This code goes to some trouble to report errors with a large enough contet
131 # to be meaningful -- rules or alternatives
132  
133 sub Marpa::R2::Internal::Stuifzand::check_ast_node {
134 20419 ▶ my ($node) = @_;
Subroutine check_ast_node: called CC=8 SCAR=26.9
135 20419 my $ref_type = ref $node;
136 20419 ▶ return if not $ref_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref_type 14080 6339 20419
137 6339 $ref_type =~ s/\A Marpa::R2::Internal::MetaAST_Nodes:: //xms;
138 6339 my $report_error = 0;
139 6339 my $problem = $node_status{$ref_type};
140 6339 my $catch_error = $catch_error_node{$ref_type};
141 6339 ▶ return qq{Internal error: Unknown AST node (type "$ref_type") in Stuifzand grammar}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $problem 0 6339 6339
142 if not defined $problem;
143 # "Normal" meaning other than catching errors
144 NORMAL_PROCESSING: {
145 6339 ▶ if ($problem) {
Branch: 1 branch
BranchTrueFalseTotal
if ($problem) 0 6339 6339
146 0 ▶ return $problem if not $catch_error_node{$ref_type};
Branch: 1 branch
BranchTrueFalseTotal
unless $catch_error_node{$ref_type} 0 0 0
147 0 last NORMAL_PROCESSING;
148 }
149 6339 for my $sub_node ( @{$node} ) {
150 20405 $problem = Marpa::R2::Internal::Stuifzand::check_ast_node($sub_node);
151 20405 ▶ if ($problem) {
Branch: 1 branch
BranchTrueFalseTotal
if ($problem) 0 20405 20405
152 0 ▶ return $problem if not $catch_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $catch_error 0 0 0
153 0 last NORMAL_PROCESSING;
154 }
155 } ## end for my $sub_node ( @{$node} )
156 6339 return;
157 } ## end NORMAL_PROCESSING:
158  
159 # If we are here, we are catching an error
160 0 my ( $start, $end ) = @{$node};
161 0 my $problem_was_here = substr ${$Marpa::R2::Internal::P_SOURCE}, $start,
162 ($end-$start+1);
163 0 chomp $problem_was_here;
164 0 chomp $problem;
165 0 Marpa::R2::exception(
166 "Stuifzand (BNF) interface grammar is using a disallowed feature\n",
167 q{ } . $problem . "\n",
168 " Problem was in the following text:\n",
169 $problem_was_here,
170 "\n"
171 );
172 } ## end sub Marpa::R2::Internal::Stuifzand::check_ast_node
173  
174 sub parse_rules {
175 14 ▶ my ($p_rules_source) = @_;
Subroutine parse_rules: called CC=4 SCAR=14.0
176 14 my $self = {};
177 14 my $ast = Marpa::R2::Internal::MetaAST->new($p_rules_source);
178 {
179 14 local $Marpa::R2::Internal::P_SOURCE = $p_rules_source;
180 my $problem = Marpa::R2::Internal::Stuifzand::check_ast_node(
181 14 $ast->{top_node} );
182 ## Uncaught problem -- should not happen
183 14 ▶ if ($problem) {
Branch: 1 branch
BranchTrueFalseTotal
if ($problem) 0 14 14
184 0 Marpa::R2::exception(
185 "Stuifzand (BNF) interface grammar has a problem\n",
186 q{ } . $problem . "\n",
187 );
188 } ## end if ($problem)
189 }
190 14 my $hashed_ast = $ast->ast_to_hash();
191 14 ▶ my $start_lhs = $hashed_ast->{'start_lhs'} // $hashed_ast->{'first_lhs'};
Condition66%2/3
$hashed_ast->{"start_lhs"} // $hashed_ast->{"first_lhs"}
l!l&&r!l&&!r
2120
MC/DC0%0/2
$hashed_ast->{"start_lhs"} // $hashed_ast->{"first_lhs"}
$hashed_ast->{"start_lhs"} $hashed_ast->{"first_lhs"}
Truth table66%2/3
A // B
A= $hashed_ast->{"start_lhs"}B= $hashed_ast->{"first_lhs"}
ABresult
1X1
011
000
192 14 ▶ Marpa::R2::exception( 'No rules in Stuifzand grammar', )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start_lhs 0 14 14
193 if not defined $start_lhs;
194  
195 14 my $internal_start_lhs = '[:start]';
196 $hashed_ast->{'default_g1_start_action'} =
197 14 $hashed_ast->{'default_adverbs'}->{'G1'}->{'action'};
198 14 $hashed_ast->{'symbols'}->{'G1'}->{$internal_start_lhs} = {
199 display_form => ':start',
200 description => 'Internal G1 start symbol'
201 };
202 14 push @{ $hashed_ast->{rules}->{G1} },
203 {
204 lhs => $internal_start_lhs,
205 rhs => [$start_lhs],
206 action => '::first'
207 };
208  
209 14 $self->{rules} = $hashed_ast->{rules}->{G1};
210 14 return $self;
211 } ## end sub parse_rules
212  
213 150 1;
214  
215 # vim: expandtab shiftwidth=4:
« blib/lib/Marpa/R2.pm ↑ Summary html/tool/lib/Marpa/R2/HTML/Test/Util.pm »