Skip to content

Instantly share code, notes, and snippets.

@rns
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save rns/4322555d750a9e83cd54 to your computer and use it in GitHub Desktop.

Select an option

Save rns/4322555d750a9e83cd54 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 ::= 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

rns commented Sep 4, 2014

Copy link
Copy Markdown
Author
$VAR1 = [
          'All',
          [
            'Span',
            [
              'Closed_Span',
              [
                'Closed_Span',
                [
                  'Closed_Syllable',
                  [
                    'C',
                    'm'
                  ],
                  [
                    'V',
                    'a'
                  ],
                  [
                    ${\$VAR1->[1][1][1][1][1][0]},
                    't'
                  ]
                ]
              ],
              [
                'Abbreviation',
                [
                  ${\$VAR1->[1][1][1][1][1][0]},
                  'm'
                ]
              ]
            ]
          ]
        ];

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