#!perl
use
5.010001;
use
POSIX
qw(setlocale LC_ALL)
;
POSIX::setlocale(LC_ALL,
"C"
);
sub
default_action {
my
(
undef
,
$values
) =
@_
;
my
$v_count
=
scalar
@{
$values
};
return
q{}
if
$v_count
== 0;
return
$values
->[0]
if
$v_count
== 1;
return
'('
.
join
(
q{;}
, @{
$values
} ) .
')'
;
}
my
$high_dsl
=
<<'END_OF_DSL';
:default ::= action => main::default_action
:start ::= S
A ::= 'a'
A ::= empty
empty ::=
S ::= A A A A null-ranking => high
END_OF_DSL
my
$low_dsl
=
$high_dsl
;
$low_dsl
=~ s/\s+ [=][>] \s+ high \Z/ => low/xms;
my
%dsl
= (
high
=> \
$high_dsl
,
low
=> \
$low_dsl
);
my
@maximal
= (
q{}
,
qw[(a;;;) (a;a;;) (a;a;a;) (a;a;a;a)]
);
my
@minimal
= (
q{}
,
qw[(;;;a) (;;a;a) (;a;a;a) (a;a;a;a)]
);
for
my
$maximal
( 0, 1 ) {
my
$dsl
=
$dsl
{
$maximal
?
'low'
:
'high'
};
my
$grammar
= Marpa::R3::Scanless::G->new(
{
ranking_method
=>
'high_rule_only'
,
source
=>
$dsl
} );
my
$recce
= Marpa::R3::Scanless::R->new( {
grammar
=>
$grammar
} );
my
$input_length
= 4;
my
$input
=
'a'
x
$input_length
;
$recce
->
read
( \
$input
);
for
my
$i
( 0 ..
$input_length
) {
my
$expected
=
$maximal
? \
@maximal
: \
@minimal
;
my
$name
=
$maximal
?
'maximal'
:
'minimal'
;
$recce
->series_restart( {
end
=>
$i
} );
$recce
->set( {
max_parses
=> 42 } );
my
$result
=
$recce
->value();
die
"No parse"
if
not
defined
$result
;
Test::More::is( ${
$result
},
$expected
->[
$i
],
"$name parse, length=$i"
);
}
}
1;