Skip to content

Instantly share code, notes, and snippets.

@rns
Created January 15, 2014 13:03
Show Gist options
  • Save rns/8435795 to your computer and use it in GitHub Desktop.
Save rns/8435795 to your computer and use it in GitHub Desktop.
use 5.010;
use strict;
use warnings;
use Data::Dumper;
use Marpa::R2;
my $g = Marpa::R2::Scanless::G->new( {
source => \(<<'END_OF_SOURCE'),
:default ::= action => [values] bless => ::lhs
lexeme default = action => [value] bless => ::name
lhs ::= rhs1 rhs2
|| rhs1 rhs2
rhs1 ~ 'rhs1'
rhs2 ~ 'rhs2'
:discard ~ whitespace
whitespace ~ [\s]+
END_OF_SOURCE
} );
for my $input ('rhs1 rhs2'){
my $r = Marpa::R2::Scanless::R->new( { grammar => $g } );
eval { $r->read(\$input) };
say $@ ? $@ : Dumper $r->value();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment