Created
May 4, 2015 09:45
-
-
Save rns/d32bfd22893b7c80c50c to your computer and use it in GitHub Desktop.
test case for Marpa::R2 #254
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MyActions; | |
use Marpa::R2; | |
sub new { | |
my ($class, %args) = @_; | |
return bless \%args, $class; | |
} | |
sub do_A { | |
my ($self, $letter) = @_; | |
return "read '$letter'"; | |
} | |
package main; | |
use 5.010; | |
use Test::More tests => 4; | |
sub parse{ | |
my ($class, $recce, $input) = @_; | |
$recce->read(\$input); | |
my $per_parse_argument = $class->new; | |
my $value = $recce->value($per_parse_argument); | |
return $$value; | |
} | |
my $grammar = Marpa::R2::Scanless::G->new({ source => \q(A ::= 'a' action => do_A) }); | |
my $recce_with_semantics_package = | |
Marpa::R2::Scanless::R->new( | |
{ grammar => $grammar, semantics_package => 'MyActions' }); | |
my $recce_without_semantics_package = | |
Marpa::R2::Scanless::R->new( | |
{ grammar => $grammar }); | |
my @tests = ( | |
[ "with semantics_package", $recce_with_semantics_package ], | |
[ "without semantics_package", $recce_without_semantics_package ], | |
); | |
for my $test (@tests){ | |
my ($desc, $recce) = @$test; | |
$desc = qq{per_parse_argument $desc}; | |
my $value = eval { parse | |
( 'MyActions', $recce, 'a') }; | |
is $@, '', "$desc: parse"; | |
is $value, "read 'a'", "$desc: parse value"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment