Skip to content

Instantly share code, notes, and snippets.

@rns
rns / lpegerr1.lua
Created May 22, 2015 05:21
locations in LPeg messages on errors in grammars
local lpeg = require 'lpeg'
equalcount = lpeg.P{
"S"; -- initial rule name
S = "a" * lpeg.V"B" + "b" * lpeg.V"A" + "",
A = "a" * lpeg.V"S" + "b" * lpeg.V"A" * lpeg.V"A",
-- , '1' added to produce error
B = "b", '1' * lpeg.V"S" + "a" * lpeg.V"B" * lpeg.V"B",
} * -1
@rns
rns / 12 34-56 78.t
Created May 12, 2015 11:06
unspaced minus warning
use 5.010;
use strict;
use warnings;
use Data::Dumper;
$Data::Dumper::Indent = 0;
$Data::Dumper::Terse = 1;
$Data::Dumper::Deepcopy = 1;
use Marpa::R2;
@rns
rns / output
Created May 8, 2015 10:00
SO q27109840 -- reject AND identifier using events
# foo.AND(5) at C:\cygwin\home\Ruslan\Marpa-R2-work\q27109840.pl line 52.
Invalid Identifier: AND at C:\cygwin\home\Ruslan\Marpa-R2-work\q27109840.pl line 73.
# foo.has(bar == 42 AND baz == 23) at C:\cygwin\home\Ruslan\Marpa-R2-work\q27109840.pl line 52.
['Expression',['Expression',['Identifier','foo']],['Identifier','has'],['Args',['ArgsList',['Expression',['Expression',['Expression',['Identifier','bar']],['Expression',['NumLiteral','42']]],['Expression',['Expression',['Identifier','baz']],['Expression',['NumLiteral','23']]]]]]]
Tool completed successfully
#!perl
# Copyright 2015 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
@rns
rns / marpa-r2-issue-254.t
Created May 4, 2015 09:45
test case for Marpa::R2 #254
package MyActions;
use Marpa::R2;
sub new {
my ($class, %args) = @_;
return bless \%args, $class;
}
sub do_A {
my ($self, $letter) = @_;
@rns
rns / sl_ambiguity_ranking.t
Created February 1, 2015 08:49
sl_ambiguity_ranking.t
#!perl
# Copyright 2015 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
Ambiguous parse: 5 alternatives.
# Alternative 1:
['hex',['hex',['hex',['hex',['digit','0']],['hex',['digit','1']]],['hex',['letter','F']]],['hex',['letter','E']]]
# Alternative 2:
['hex',['hex',['hex',['digit','0']],['hex',['hex',['digit','1']],['hex',['letter','F']]]],['hex',['letter','E']]]
# Alternative 3:
['hex',['hex',['hex',['digit','0']],['hex',['digit','1']]],['hex',['hex',['letter','F']],['hex',['letter','E']]]]
# Alternative 4:
['hex',['hex',['digit','0']],['hex',['hex',['hex',['digit','1']],['hex',['letter','F']]],['hex',['letter','E']]]]
# Alternative 5:
@rns
rns / output
Created January 26, 2015 21:26
#233 rule_describe() with Unicode escape actions
Can't locate object method "rule_describe" via package "Marpa::R2::Grammar" at /usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int/Marpa/R2/Value.pm line 489, <DATA> line 5048.
Marpa::R2::Internal::Value::rule_describe('Marpa::R2::Grammar=ARRAY(0x206fe128)', 23) called at /usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int/Marpa/R2/Value.pm line 472
Marpa::R2::Internal::Value::resolve_rule_by_id('Marpa::R2::Recognizer=ARRAY(0x278bb128)', 23) called at /usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int/Marpa/R2/Value.pm line 589
Marpa::R2::Internal::Value::resolve_recce('Marpa::R2::Recognizer=ARRAY(0x278bb128)', 'Marpa::R2::Scanless::R=ARRAY(0x2008d700)') called at /usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int/Marpa/R2/ASF.pm line 377
Marpa::R2::ASF::new('Marpa::R2::ASF', 'HASH(0x2008d6d0)') called at /usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int/Marpa/R2/SLR.pm line 1413
Marpa::R2::Scanless::R::ambiguous('Marpa::R2::Scanless::R=ARRAY(0x2008d700)') called at C:\cygwin\home
@rns
rns / #233-stand-alone.pl
Last active August 29, 2015 14:14
`ambiguity_metric()` vs `ambiguous()` case from #233 as a single script -- ranking to blame
use strict;
use warnings;
use Test::More;
use Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Terse = 1;
$Data::Dumper::Deepcopy = 1;