Skip to content

Instantly share code, notes, and snippets.

@ruz
Created April 12, 2012 08:47
Show Gist options
  • Save ruz/2365674 to your computer and use it in GitHub Desktop.
Save ruz/2365674 to your computer and use it in GitHub Desktop.
use 5.010;
use strict;
use warnings;
my $rec = rec();
$rec->alternative( 'XX', undef, 2 );
while (1) {
say $rec->earleme_complete;
say $rec->exhausted? "exhausted" : "please continue";
}
sub rec {
use Marpa::XS;
my $grammar = Marpa::XS::Grammar->new( {
actions => 'main',
default_action => 'do_what_I_mean',
start => 'query',
rules => [
[ query => [qw(XX)] ],
],
lhs_terminals => 0,
});
$grammar->precompute;
return Marpa::XS::Recognizer->new( { grammar => $grammar } );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment