Skip to content

Instantly share code, notes, and snippets.

View jeffreykegler's full-sized avatar

Jeffrey Kegler jeffreykegler

View GitHub Profile
@jeffreykegler
jeffreykegler / gist:8312534
Created January 8, 2014 06:06
Ruslan Zakirov's example, redone using a forgiving token
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Marpa::R2 2.079_007;
use Data::Dumper;
my $source = <<'END';
:default ::= action => ::array
@jeffreykegler
jeffreykegler / gist:8312524
Created January 8, 2014 06:04
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
@jeffreykegler
jeffreykegler / dyck_hollerith.pl
Created June 9, 2013 21:21
Parse Dyck-Hollerith language using Marpa::R2's SLIF
#!perl
# Copyright 2013 Jeffrey Kegler
# This file is part of Marpa::R2. Marpa::R2 is free software: you can
# redistribute it and/or modify it under the terms of the GNU Lesser
# General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# Marpa::R2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@jeffreykegler
jeffreykegler / test.pl
Last active December 17, 2015 02:09 — forked from pstuifzand/test.pl
use 5.10.0;
use Marpa::R2 2.053_006;
use Data::Dumper;
my $grammar = Marpa::R2::Scanless::G->new({
source => \<<'SOURCE',
:start ::= numbers
event number_found = completed number
@jeffreykegler
jeffreykegler / heredoc.t
Last active December 16, 2015 11:59
Example of Perl-style heredoc parsing, for blog post.
#!perl
# Copyright 2013 Jeffrey Kegler
# This file is part of Marpa::R2. Marpa::R2 is free software: you can
# redistribute it and/or modify it under the terms of the GNU Lesser
# General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# Marpa::R2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
package MonthTotals;
use 5.010;
use strict;
use Marpa::R2;
use Data::Dumper;
sub new {
my ($class) = @_;
my $self = bless {
grammar => Marpa::R2::Scanless::G->new({
@jeffreykegler
jeffreykegler / SLIF_external.pod
Last active December 15, 2015 02:09
A plan for allowing external scanners with the SLIF interface
# Copyright 2013 Jeffrey Kegler # This file is part of Marpa::R2. Marpa::R2 is free software: you can # redistribute it and/or modify it under the terms of the GNU Lesser # General Public License as published by the Free Software Foundation, # either version 3 of the License, or (at your option) any later version. # # Marpa::R2 is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details.
@jeffreykegler
jeffreykegler / interpreter2.pl
Last active March 20, 2016 08:11
The Gang of 4's second Interpreter Pattern example, rewritten to use Marpa::R2.
#!perl
# Copyright 2013 Jeffrey Kegler
# This file is part of Marpa::R2. Marpa::R2 is free software: you can
# redistribute it and/or modify it under the terms of the GNU Lesser
# General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# Marpa::R2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@jeffreykegler
jeffreykegler / comments.t
Last active December 14, 2015 02:39
A script which tests Marpa's parsing of C-style comments against regexes. When run as perl comments.pl --random It will generate a random string for the test. Otherwise it reads STDIN.
#!perl
# Copyright 2013 Jeffrey Kegler
# This file is part of Marpa::R2. Marpa::R2 is free software: you can
# redistribute it and/or modify it under the terms of the GNU Lesser
# General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# Marpa::R2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@jeffreykegler
jeffreykegler / show_comments.pl
Last active September 20, 2016 04:24
A script to illustrate the parsing of C-style comments with Marpa's Scanless interface. It reads a file on standard input and prints the comments to STDOUT.
#!perl
# Copyright 2013 Jeffrey Kegler
# This file is part of Marpa::R2. Marpa::R2 is free software: you can
# redistribute it and/or modify it under the terms of the GNU Lesser
# General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# Marpa::R2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU