Skip to content

Instantly share code, notes, and snippets.

@jeffreykegler
Created January 8, 2014 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreykegler/8312524 to your computer and use it in GitHub Desktop.
Save jeffreykegler/8312524 to your computer and use it in GitHub Desktop.
Peter Stuifzand's example, redone using a forgiving token
#!/usr/bin/env perl
use 5.010;
use Marpa::R2 2.079_007;
use Data::Dumper;
my $source = <<'SOURCE';
product ::= sku (nl) name (nl) price price price (nl)
sku ~ sku_0 '.' sku_0
sku_0 ~ [\d]+
price ~ price_0 ',' price_0
price_0 ~ [\d]+
nl ~ [\n]
sp ~ [ ]+
:discard ~ sp
:lexeme ~ <name> forgiving => 1
name ~ [^\n]+
SOURCE
my $g = Marpa::R2::Scanless::G->new({
source => \$source,
default_action => '::array',
});
my $input = <<'INPUT';
130.12312
Descriptive line
1,10 1,10 1,30
INPUT
my $slr =
Marpa::R2::Scanless::R->new( { grammar => $g,
# trace_terminals => 1
} );
$slr->read( \$input );
print Dumper([ ${$slr->value} ]);
# vim: set expandtab shiftwidth=4:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment