Skip to content

Instantly share code, notes, and snippets.

View jeffreykegler's full-sized avatar

Jeffrey Kegler jeffreykegler

View GitHub Profile
#!/usr/bin/perl
# Copyright 2014 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 / Scraper
Created March 3, 2014 00:13
Scrape HTML tables
use 5.010;
use strict;
use warnings;
use Marpa::R2 2.082000;
use Marpa::R2::HTML qw(html);
my %handlers_to_keep_only_tables = (
table => sub { return Marpa::R2::HTML::original() },
':TOP' => sub { return \( join q{}, @{ Marpa::R2::HTML::values() } ) }
);
@jeffreykegler
jeffreykegler / scraper2.pl
Created March 3, 2014 03:39
Scrape links from inside HTML tables
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Marpa::R2 2.082000;
use Marpa::R2::HTML qw(html);
# ---------------------------
@jeffreykegler
jeffreykegler / kv_extend.pl
Created March 11, 2014 02:29
Hypothetical extension to Perl 5's hash initialization
use 5.010;
use strict;
use warnings;
use Data::Dumper;
use Marpa::R2 2.082000;
my $input = <<'END_OF_STRING';
{
name => 'test hash 1',
#!/usr/bin/perl
# Copyright 2012 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 / ambig.pl
Created August 18, 2014 20:57
Exploiting ambiguity in language design: an example
#!/usr/bin/perl
# Copyright 2014 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 / bracket.pl
Last active August 29, 2015 14:08
Utility for reporting mismatched brackets
#!/usr/bin/env perl
# Copyright 2014 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 / rodland.md
Last active August 29, 2015 14:08
Notes on Andrew Rodland's Talk

Andrew Rodland at the 2014 YAPC:NA gave a talk on Marpa. A video is available. Here are my notes on it.

The talk is very well-organized, and well-written. Andrew was a last minute fill-in, so there are glitches in the actual delivery of the material, but the material itself is near perfect.

At 4:20, it says that Marpa can modify its grammar at run time. Pedantically, this is not actually true.

These are my notes on Andrew's interview for FLOSS Weekly, #321, which aired 14 January, 2015. Readers may also want to look at Andrew's prepared talk on Marpa.

3:19 Randal talks about ambiguous grammars, which in fact Marpa can handle. But most new users are going to care about grammars that are unambiguous or nearly so. Because of its power Marpa can handle, not just any grammar you're likely to want to parse, but a lot of grammars that you probably did not feel a need to get into. Consider it like the ability of a good sports car to run smoothly at 120mph. Not something that's advisable to do on the US highways, but a sign of the kind of power and handling that can be very nice to have.

@jeffreykegler
jeffreykegler / small233.pl
Created January 30, 2015 05:23
Small example for Marpa::R2 issue #233
use strict;
use warnings;
use Test::More;
use Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Terse = 1;
$Data::Dumper::Deepcopy = 1;