#!perl
use
5.010001;
use
POSIX
qw(setlocale LC_ALL)
;
POSIX::setlocale(LC_ALL,
"C"
);
my
$grammar
= Marpa::R3::Scanless::G->new(
{
source
=> \
<<'END_OF_DSL',
pair ::= a a
pair ::= pair a
pair ::= a pair
pair ::= pair pair
a ~ 'a'
END_OF_DSL
}
);
sub
do_pairings {
my
$n
=
shift
;
my
$parse_count
= 0;
my
$recce
= Marpa::R3::Scanless::R->new(
{
grammar
=>
$grammar
,
too_many_earley_items
=> 10 } );
$recce
->set( {
max_parses
=> 999, } );
my
$trace_output
;
open
my
$trace_fh
,
q{>}
, \
$trace_output
;
$recce
->set( {
trace_file_handle
=>
$trace_fh
} );
$recce
->
read
( \(
'a'
x
$n
) );
$recce
->set( {
trace_file_handle
=> \
*STDOUT
} );
close
$trace_fh
;
my
$expected_trace_output
=
<<'END_OF_TRACE';
G1 exceeded earley item threshold at pos 2: 11 Earley items
END_OF_TRACE
Marpa::R3::Test::is(
$trace_output
,
$expected_trace_output
,
'"Too many Earley items" Trace Output'
);
}
my
@catalan_numbers
= ( 0, 1, 1, 2, 5, 14, 42, 132, 429 );
for
my
$a
( 2 ) {
my
$actual_parse_count
= do_pairings(
$a
);
Marpa::R3::Test::is(
$actual_parse_count
,
$catalan_numbers
[
$a
],
"Catalan number $a matches parse count ($actual_parse_count)"
);
}
1;