Skip to content

Instantly share code, notes, and snippets.

@jddurand
jddurand / gist:8630985
Created January 26, 2014 10:33
Marpa version 2.079012: misleading error if action cannot be resolved
#!perl
use Marpa::R2;
print "\$Marpa::R2::VERSION = $Marpa::R2::VERSION\n";
my $g = Marpa::R2::Scanless::G->new({source => \do {local $/; <DATA>}});
my $r = Marpa::R2::Scanless::R->new({grammar => $g});
my $input = 'anything';
$r->read(\$input);
$r->value;
@jddurand
jddurand / MarpaRulesByDepth.pl
Last active June 21, 2017 18:37
Inspect marpa grammar rules by depth
#!env perl
use strict;
use diagnostics;
use Marpa::R2 2.081001;
my $grammar = Marpa::R2::Scanless::G->new({ source => \do {local $/; <DATA>}});
my $fmt = "%5s %-20s %-20s %s\n";
printf $fmt, 'depth', 'ruleName', 'lhsName', 'rhsNames';
foreach (@{rulesByDepth($grammar)}) {
printf $fmt, $_->{depth}, $_->{ruleName}, $_->{lhsName}, join(' ', @{$_->{rhsNames}});
@jddurand
jddurand / EBNF-ISO_IEC_14977_1996_E.pl
Created May 28, 2014 22:24
Marpa grammar of official EBNF ISO/IEC 14977:1996(E)
#!env perl
# -----------------------------------------------------------------------------------------
# Marpa grammar for EBNF published by ISO/IEC 14977:1996(E)
#
# Extensions are minor, and ONLY because our keyboards are more likely to expose Latin-1
# character rather than the Windows-1252 characters as per the spec, i.e.:
#
# Extension 1: Add ' to quoted strings (ISO published the special neighbour character ’)
# Extension 2: Add ^ to <other character> (ISO published the special neighbour character ˆ)
# Extension 3: Add ` to <other character> (ISO published the special neighbour character ‘)
@jddurand
jddurand / xml_1_0.marpa.bnf
Created June 2, 2014 20:22
W3C EBNF to Marpa using Marpa
inaccessible is ok by default
:start ::= document
AttDef ::= S Name S AttType S DefaultDecl
AttDef_any ::= AttDef *
AttType ::= StringType
AttType ::= TokenizedType
AttType ::= EnumeratedType
AttValue ::= _Lex030 _Gen060_any _Lex030
AttValue ::= _Lex032 _Gen063_any _Lex032
@jddurand
jddurand / domLevel3.pm
Last active August 29, 2015 14:04
From dom Level 3 Core specification to Moose using MarpaX::Languages::IDL::AST
#!env perl
package w3c::org::dom {
use Moose::Role;
use MRO::Compat;
use namespace::sweep;
use MooseX::Types::Moose qw/ArrayRef/;
use MooseX::Types -declare => [
qw/
Attr
@jddurand
jddurand / number.pl
Created September 2, 2014 20:05
MintberryCruNCH question on Marpa IRC
use 5.010;
use strict;
use warnings;
use Data::Dumper;
use Marpa::R2;
my $g = Marpa::R2::Scanless::G->new( {
bless_package => 'main',
@jddurand
jddurand / _xml_1_0_parseEventsb.c
Last active March 20, 2016 05:26
_xml_1_0_parseEventsb example
/**************************/
/* _xml_1_0_parseEventsb */
/**************************/
static C_INLINE marpaWrapperBool_t _xml_1_0_parseEventsb(void *datavp, marpaWrapper_t *marpaWrapperp, size_t nEventi, marpaWrapperEvent_t *marpaWrapperEventp) {
marpaWrapperBool_t rcb = MARPAWRAPPER_BOOL_TRUE;
xml_1_0_t *xml_1_0p;
marpaXmlLog_t *marpaXmlLogp = NULL;
xml_1_0_symbol_t symboli;
int i;
#!env perl
use strict;
use diagnostics;
use Marpa::R2;
use Data::Dumper;
use POSIX qw/EXIT_SUCCESS/;
use Data::Section -setup;
use open qw(:std :utf8); # Undeclared streams in UTF-8.
#
@jddurand
jddurand / luaMarpa.sh
Last active June 21, 2017 18:36
Marpa/LUA bindings proof of concept
#!env sh -v
#
# Marpa in Lua proof of concept - Assumption: Debian/Linux
#
# Prologue: apt-get -t unstable install lua5.1 liblua5.1-dev swig
#
# Please go to Marpa-R2-2.096000/engine/read_only and execute this file
# ---------------------------------------------------------------------
#
[ -r ./Makefile ] && make distclean
@jddurand
jddurand / gist:7b7074f8ebbf668c25d7
Created January 18, 2015 22:52
unfinished grammar for java class - totally unusable you are warned
:default ::= action => [values] bless => ::lhs
lexeme default = action => [start,length,value,name]
:start ::= ClassFile
ClassFile ::=
magic
minor_version
major_version
constant_pool_count
constant_pools