#!/usr/bin/perl
use
5.010001;
use
Fatal
qw( open close )
;
my
$side_effect
= 0;
no
warnings
'once'
;
$My_Actions::hash_ref
= {
'a hash ref'
=> 1};
$My_Actions::array_ref
= [
'an array ref'
];
$My_Actions::array_ref2
= [
'array ref 2'
];
$My_Actions::scalar_ref
= \8675309;
$My_Actions::scalar
= 42;
$My_Actions::scalar2
=
'scalar2'
;
$My_Actions::code_ref
=
sub
{
return
'code ref'
};
$My_Actions::code_ref2
=
sub
{
return
'code ref 2'
};
$My_Actions::code_ref_ref
= \(
sub
{
return
'code ref ref'
});
sub
My_Actions::scalar2 {
return
(
'should not see me'
,
'shadow of scalar 2'
) };
sub
My_Actions::array_ref2 {
return
'shadow of array_ref2'
};
sub
My_Actions::code_ref2 {
return
'shadow of code_ref2'
};
sub
My_Actions::code {
return
'code'
};
sub
My_Actions::new {
$side_effect
= 42; }
my
$grammar
= Marpa::R3::Scanless::G->new(
{
source
=> \
<<'END_OF_SOURCE',
:default ::= action => ::array
:start ::= S
S ::= <array ref> <hash ref> <ref ref> <code ref>
<code ref ref> <code> <scalar>
<scalar2> <array ref 2> <code ref 2>
<array ref> ::= 'a' action => array_ref
<hash ref> ::= 'a' action => hash_ref
<ref ref> ::= 'a' action => scalar_ref
<code ref> ::= 'a' action => code_ref
<code ref ref> ::= 'a' action => code_ref_ref
<code> ::= 'a' action => code
<scalar> ::= 'a' action => scalar
<scalar2> ::= 'a' action => scalar2
<array ref 2> ::= 'a' action => array_ref2
<code ref 2> ::= 'a' action => code_ref2
END_OF_SOURCE
});
sub
do_parse {
my
$slr
= Marpa::R3::Scanless::R->new(
{
grammar
=>
$grammar
,
semantics_package
=>
'My_Actions'
, } );
$slr
->
read
( \
'aaaaaaaaaa'
);
return
$slr
->value();
}
my
$value_ref
;
$value_ref
= do_parse();
my
$expected
= \[
[
'an array ref'
],
{
'a hash ref'
=> 1 },
\8675309,
$My_Actions::code_ref
,
$My_Actions::code_ref_ref
,
'code'
,
42,
'shadow of scalar 2'
,
'shadow of array_ref2'
,
'shadow of code_ref2'
];
Test::More::is_deeply(
$value_ref
,
$expected
,
'Constant actions'
);
Test::More::is(
$side_effect
, 42,
'semantics_package constructor'
);