Skip to content

Instantly share code, notes, and snippets.

@rns
Last active August 29, 2015 14:06
Show Gist options
  • Save rns/fb6abf62a5fa779957ba to your computer and use it in GitHub Desktop.
Save rns/fb6abf62a5fa779957ba 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 => [name, value]
lexeme default = action => [name, value]
All ::= Syllable+
Syllable ::=
Syllable_CVC |
Syllable_CV |
Syllable_C_or_Abbrev
Syllable_CVC ~ C V C
Syllable_CV ~ C V
Syllable_C_or_Abbrev ~ C
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;
while (my $v = $r->value){
say Dumper $v;
}
@rns
Copy link
Author

rns commented Sep 3, 2014

$VAR1 = \[
            'All',
            [
              'Syllable',
              [
                'Syllable_CVC',
                'mat'
              ]
            ],
            [
              'Syllable',
              [
                'Syllable_C_or_Abbrev',
                'm'
              ]
            ]
          ];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment