#!/usr/bin/perl
use
5.010001;
use
Fatal
qw( open close )
;
use
POSIX
qw(setlocale LC_ALL)
;
POSIX::setlocale(LC_ALL,
"C"
);
my
$side_effect
= 0;
no
warnings
'once'
;
sub
My_Actions::new {
$side_effect
= 42; }
sub
My_Actions::join_contents {
my
(
$ppo
,
$child
) =
@_
;
my
@elements
=
map
{
$_
->[0] } @{
$child
};
return
join
''
,
@elements
;
}
my
$grammar
= Marpa::R3::Scanless::G->new(
{
semantics_package
=>
'My_Actions'
,
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>
action => join_contents
<array ref> ::= 'a'
<hash ref> ::= 'a'
<ref ref> ::= 'a'
<code ref> ::= 'a'
<code ref ref> ::= 'a'
<code> ::= 'a'
<scalar> ::= 'a'
<scalar2> ::= 'a'
<array ref 2> ::= 'a'
<code ref 2> ::= 'a'
END_OF_SOURCE
}
);
sub
do_parse {
my
$slr
= Marpa::R3::Scanless::R->new( {
grammar
=>
$grammar
} );
$slr
->
read
( \
'aaaaaaaaaa'
);
return
$slr
->value();
}
my
$value_ref
= do_parse();
my
$value
=
$value_ref
? ${
$value_ref
} :
'No parse'
;
Test::More::is(
$value
,
'aaaaaaaaaa'
,
'Result'
);
Test::More::is(
$side_effect
, 0,
'semantics_package constructor elminated'
);