use
5.010;
use
vars
qw($VERSION $STRING_VERSION)
;
$VERSION
=
'2.096000'
;
$STRING_VERSION
=
$VERSION
;
$VERSION
=
eval
$VERSION
;
my
%node_status
=
map
{ ; (
$_
,
q{}
) }
qw(
action
action_name
adverb_item
adverb_list
adverb_list_items
alternative
alternatives
array_descriptor
bare_name
blessing
blessing_name
boolean
bracketed_name
default_rule
empty_rule
group_association
left_association
lhs
op_declare
op_declare_bnf
parenthesized_rhs_primary_list
Perl_name
priorities
priority_rule
proper_specification
quantified_rule
quantifier
reserved_action_name
reserved_blessing_name
rhs
rhs_primary
rhs_primary_list
right_association
separator_specification
single_symbol
standard_name
start_rule
statement
statements
symbol
symbol_name
)
;
$node_status
{
'Marpa::R2::Internal::MetaAST'
} =
q{}
;
$node_status
{array_descriptor} =
"Actions in the form of array descriptors are not allowed"
;
$node_status
{character_class} =
"Character classes are not allowed"
;
$node_status
{completion_event_declaration} =
"Completion events are not allowed"
;
$node_status
{discard_rule} =
":discard rules are not allowed"
;
$node_status
{event_specification} =
qq{The "event" adverb is not allowed}
;
$node_status
{latm_specification} =
qq{The "latm" adverb is not allowed}
;
$node_status
{lexeme_default_statement} =
"The lexeme default statement is not allowed"
;
$node_status
{lexeme_rule} =
"Lexeme statements are not allowed"
;
$node_status
{nulled_event_declaration} =
"Nulled events are not allowed"
;
$node_status
{op_declare_match} =
"lexical rules are not allowed"
;
$node_status
{pause_specification} =
"The pause adverb is not allowed"
;
$node_status
{prediction_event_declaration} =
"Prediction events are not allowed"
;
$node_status
{priority_specification} =
"The priority adverb is not allowed"
;
$node_status
{single_quoted_string} =
"Quoted strings are not allowed"
;
$node_status
{alternative_name} =
"Alternative naming is not allowed"
;
$node_status
{naming} =
"Alternative naming is not allowed"
;
my
%catch_error_node
=
map
{ ; (
$_
, 1 ) }
qw( alternative statement )
;
sub
Marpa::R2::Internal::Stuifzand::check_ast_node {
my
(
$node
) =
@_
;
my
$ref_type
=
ref
$node
;
return
if
not
$ref_type
;
$ref_type
=~ s/\A Marpa::R2::Internal::MetaAST_Nodes:: //xms;
my
$report_error
= 0;
my
$problem
=
$node_status
{
$ref_type
};
my
$catch_error
=
$catch_error_node
{
$ref_type
};
return
qq{Internal error: Unknown AST node (type "$ref_type") in Stuifzand grammar}
if
not
defined
$problem
;
NORMAL_PROCESSING: {
if
(
$problem
) {
return
$problem
if
not
$catch_error_node
{
$ref_type
};
last
NORMAL_PROCESSING;
}
for
my
$sub_node
( @{
$node
} ) {
$problem
= Marpa::R2::Internal::Stuifzand::check_ast_node(
$sub_node
);
if
(
$problem
) {
return
$problem
if
not
$catch_error
;
last
NORMAL_PROCESSING;
}
}
return
;
}
my
(
$start
,
$end
) = @{
$node
};
my
$problem_was_here
=
substr
${
$Marpa::R2::Internal::P_SOURCE
},
$start
,
(
$end
-
$start
+1);
chomp
$problem_was_here
;
chomp
$problem
;
Marpa::R2::exception(
"Stuifzand (BNF) interface grammar is using a disallowed feature\n"
,
q{ }
.
$problem
.
"\n"
,
" Problem was in the following text:\n"
,
$problem_was_here
,
"\n"
);
}
sub
parse_rules {
my
(
$p_rules_source
) =
@_
;
my
$self
= {};
my
$ast
= Marpa::R2::Internal::MetaAST->new(
$p_rules_source
);
{
local
$Marpa::R2::Internal::P_SOURCE
=
$p_rules_source
;
my
$problem
= Marpa::R2::Internal::Stuifzand::check_ast_node(
$ast
->{top_node} );
if
(
$problem
) {
Marpa::R2::exception(
"Stuifzand (BNF) interface grammar has a problem\n"
,
q{ }
.
$problem
.
"\n"
,
);
}
}
my
$hashed_ast
=
$ast
->ast_to_hash();
my
$start_lhs
=
$hashed_ast
->{
'start_lhs'
} //
$hashed_ast
->{
'first_lhs'
};
Marpa::R2::exception(
'No rules in Stuifzand grammar'
, )
if
not
defined
$start_lhs
;
my
$internal_start_lhs
=
'[:start]'
;
$hashed_ast
->{
'default_g1_start_action'
} =
$hashed_ast
->{
'default_adverbs'
}->{
'G1'
}->{
'action'
};
$hashed_ast
->{
'symbols'
}->{
'G1'
}->{
$internal_start_lhs
} = {
display_form
=>
':start'
,
description
=>
'Internal G1 start symbol'
};
push
@{
$hashed_ast
->{rules}->{G1} },
{
lhs
=>
$internal_start_lhs
,
rhs
=> [
$start_lhs
],
action
=>
'::first'
};
$self
->{rules} =
$hashed_ast
->{rules}->{G1};
return
$self
;
}
1;