Last active
August 29, 2015 14:06
-
-
Save rns/4322555d750a9e83cd54 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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 => [name, value] | |
| lexeme default = action => [name, value] | |
| All ::= Span | |
| Span ::= Closed_Span | Open_Span | |
| Closed_Span ::= Abbreviation | |
| Closed_Span ::= Closed_Syllable | |
| Closed_Span ::= Span Closed_Syllable | |
| Closed_Span ::= Closed_Span Abbreviation | |
| Open_Span ::= Span Open_Syllable | |
| Open_Span ::= Open_Syllable | |
| Abbreviation ::= C | |
| Closed_Syllable ::= C V C | |
| Open_Syllable ::= C V | |
| C ~ [bcdfghjklmnpqrstvwxyz] | |
| V ~ [aeiou] | |
| :discard ~ whitespace | |
| whitespace ~ [\s]+ | |
| END_OF_SOURCE | |
| } ); | |
| my $input = <<EOI; | |
| mat | |
| m | |
| EOI | |
| my $r = Marpa::R2::Scanless::R->new( { grammar => $g } ); | |
| eval {$r->read(\$input)} || die "Parse failure, progress report is:\n" . $r->show_progress; | |
| if ( $r->ambiguity_metric() > 1 ){ | |
| say "Ambiguous parse, use Marpa::R2::ASF, now dumping alternatives:" ; | |
| while (my $v = $r->value){ | |
| say Dumper $v; | |
| } | |
| } | |
| else{ | |
| say Dumper ${ $r->value }; | |
| } |
rns
commented
Sep 4, 2014
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment