Created
January 30, 2015 05:23
-
-
Save jeffreykegler/0ce38abec2fe14e458b4 to your computer and use it in GitHub Desktop.
Small example for Marpa::R2 issue #233
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
use strict; | |
use warnings; | |
use Test::More; | |
use Data::Dumper; | |
$Data::Dumper::Indent = 1; | |
$Data::Dumper::Terse = 1; | |
$Data::Dumper::Deepcopy = 1; | |
use Carp::Always; # force stack trace | |
use Marpa::R2; | |
my $input = q{a b}; | |
my $grammar = ''; | |
while (<DATA>) { $grammar .= $_ } | |
my $slg = Marpa::R2::Scanless::G->new({ source => \$grammar }); | |
# no ranking | |
my $slr_ranking_none = Marpa::R2::Scanless::R->new({ | |
grammar => $slg, | |
ranking_method => 'none', | |
} ); | |
$slr_ranking_none->read(\$input); | |
ok $slr_ranking_none->ambiguous() ne '', "No ranking, many parses, ambiguous status isn't empty"; | |
ok $slr_ranking_none->ambiguity_metric() > 1, "No ranking, many parses, ambiguity metric > 1"; | |
# high_rule_only | |
my $slr_ranking_high_rule = Marpa::R2::Scanless::R->new({ | |
grammar => $slg, | |
ranking_method => 'high_rule_only', | |
} ); | |
$slr_ranking_high_rule->read(\$input); | |
# count parses | |
my $parse_count = 0; | |
while (defined $slr_ranking_high_rule->value()) { ++$parse_count } | |
$slr_ranking_high_rule->series_restart(); | |
is $parse_count, 1, "high_rule_only ranking, single parse"; | |
is $slr_ranking_high_rule->ambiguous(), '', "high_rule_only ranking, single parse, ambiguous status is empty"; | |
is $slr_ranking_high_rule->ambiguity_metric(), 1, "high_rule_only ranking, single parse ambiguity metric is 1"; | |
done_testing(); | |
__END__ | |
lexeme default = latm => 1 | |
top ::= unchoice rank => 1 | |
top ::= choice | |
unchoice ::= choice1 | |
choice ::= choice1 | choice2 | |
choice1 ::= A1 B1 | |
choice2 ::= A2 B2 | |
A1 ~ 'a' | |
A2 ~ 'a' | |
B1 ~ 'b' | |
B2 ~ 'b' | |
:discard ~ ws | |
ws ~ [\s]+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment