Skip to content

Instantly share code, notes, and snippets.

@pstuifzand
Created January 29, 2013 11:07
Show Gist options
  • Save pstuifzand/4663490 to your computer and use it in GitHub Desktop.
Save pstuifzand/4663490 to your computer and use it in GitHub Desktop.
Unproductive symbol: digits at test.pl line 7
package Parse::ProductName;
use Marpa::R2;
sub new {
my($class) = @_;
my $grammar = Marpa::R2::Scanless::G->new({
action_object => 'Parse::ProductName::Actions',
default_action => 'do_first_arg',
source => \<<'SOURCE'
:start ::= product_name
product_name ::= sku
| name name digits action => do_list
sku ~ digits '/' digits
digits ~ [\d]+
name ~ [a-zA-Z]+
:discard ~ ws
ws ~ [\s]+
SOURCE
});
my $self = {
grammar => $grammar,
};
bless $self, $class;
return $self;
}
sub parse {
my $self = shift;
my $input = shift;
my $re = Marpa::R2::Scanless::R->new({grammar => $self->{grammar}});
$re->read(\$input);
return ${$re->value};
}
package Parse::ProductName::Actions;
use strict;
sub new {
my $klass = shift;
return bless {}, $klass;
}
sub do_first_arg {
shift;return $_[0];
}
sub do_list {
shift; return \@_;
}
package main;
my $p = Parse::ProductName->new;
$p->parse("name 100");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment