Marpa-R2

 view release on metacpan or  search on metacpan

t/leo_cycle.t  view on Meta::CPAN

AHM 3: postdot = "a"
    S ::= . a A[]
AHM 4: completion
    S ::= a A[] .
AHM 5: postdot = "S"
    H ::= . S
AHM 6: completion
    H ::= S .
AHM 7: postdot = "C"
    B ::= . C
AHM 8: completion
    B ::= C .
AHM 9: postdot = "E"
    D ::= . E
AHM 10: completion
    D ::= E .
AHM 11: postdot = "F"
    E ::= . F
AHM 12: completion
    E ::= F .
AHM 13: postdot = "G"
    F ::= . G
AHM 14: completion
    F ::= G .
AHM 15: postdot = "D"
    C ::= . D
AHM 16: completion
    C ::= D .
AHM 17: postdot = "H"
    G ::= . H
AHM 18: completion
    G ::= H .
AHM 19: postdot = "B"
    A ::= . B
AHM 20: completion
    A ::= B .
AHM 21: postdot = "S"
    S['] ::= . S
AHM 22: completion
    S['] ::= S .
END_OF_STRING

Marpa::R2::Test::is( $grammar->show_ahms(), $expected_ahms_output,
    'Leo166 AHFA' );

my $length = 20;

my $recce = Marpa::R2::Recognizer->new( { grammar => $grammar } );

my $i                 = 0;
my $latest_earley_set = $recce->latest_earley_set();
my $max_size          = $recce->earley_set_size($latest_earley_set);
TOKEN: while ( $i++ < $length ) {
    $recce->read( 'a', 'a' );
    $latest_earley_set = $recce->latest_earley_set();
    my $size = $recce->earley_set_size($latest_earley_set);

    $max_size = $size > $max_size ? $size : $max_size;
} ## end while ( $i++ < $length )

# Note that the length formula only works
# beginning with Earley set c, for some small
# constant c
my $expected_size = 14;
Marpa::R2::Test::is( $max_size, $expected_size, "size $max_size" );

my $show_earley_sets_output = do {
    local $RS = undef;
## no critic(Subroutines::ProhibitCallsToUndeclaredSubs)
    <DATA>;
};

Marpa::R2::Test::is( $recce->show_earley_sets(1),
    $show_earley_sets_output, 'Leo cycle Earley sets' );

my $value_ref = $recce->value();
my $value = $value_ref ? ${$value_ref} : 'No parse';
Marpa::R2::Test::is( $value, 'a' x $length, 'Leo cycle parse' );

1;    # In case used as "do" file

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4:

__DATA__
Last Completed: 20; Furthest: 20
Earley Set 0
ahm21: R10:0@0-0
  R10:0: S['] ::= . S
ahm0: R0:0@0-0
  R0:0: S ::= . a A
ahm3: R1:0@0-0
  R1:0: S ::= . a A[]
Earley Set 1
ahm4: R1$@0-1
  R1$: S ::= a A[] .
  [c=R1:0@0-0; s=a; t=\'a']
ahm1: R0:1@0-1
  R0:1: S ::= a . A
  [c=R0:0@0-0; s=a; t=\'a']
ahm22: R10$@0-1
  R10$: S['] ::= S .
  [p=R10:0@0-0; c=R1$@0-1]
ahm0: R0:0@1-1
  R0:0: S ::= . a A
ahm3: R1:0@1-1
  R1:0: S ::= . a A[]
ahm5: R2:0@1-1
  R2:0: H ::= . S
ahm7: R3:0@1-1
  R3:0: B ::= . C
ahm9: R4:0@1-1
  R4:0: D ::= . E
ahm11: R5:0@1-1
  R5:0: E ::= . F
ahm13: R6:0@1-1
  R6:0: F ::= . G



( run in 0.748 second using v1.01-cache-2.11-cpan-483215c6ad5 )