MarpaX::Demo::SampleScripts - A collection of scripts using Marpa::R2


See scripts/*.pl.


MarpaX::Demo::SampleScripts demonstrates various grammars and various ways to write and test scripts.

The whole point of this module is in scripts/*.pl.


Install MarpaX::Demo::SampleScripts as you would for any Perl module:


        cpanm MarpaX::Demo::SampleScripts

or run:

        sudo cpan MarpaX::Demo::SampleScripts

or unpack the distro, and then either:

        perl Build.PL
        ./Build test
        sudo ./Build install


        perl Makefile.PL
        make (or dmake or nmake)
        make test
        make install

Constructor and Initialization

new() is called as my($parser) = MarpaX::Demo::SampleScripts -> new(k1 => v1, k2 => v2, ...).

It returns a new object of type MarpaX::Demo::SampleScripts.

Key-value pairs accepted in the parameter list:




This method does nothing, and return 0 for success.

Files Shipped with this Module

Many of these scripts are gists, i.e. from You can always go there are search for some unique text within the script, to see if there are other versions, or commentary available.

Runnable Scripts

All these scripts are in the scripts/ directory.


A grammar for the Velocity language.


Display Marpa's view of the structure of a grammar.


Process defective HTML.


Match nested parantheses, i.e. the '(' and ')' pair.


This sophisticated example checks files for matching brackets: (){}[].

Or, it can be run (self-tested) with the '--test' option'.

The new rejection events are used, along with the Ruby Slippers, meaning it requires Marpa::R2 V 2.098000.

This program uses the method of adding known tokens (my $suffix = '(){}[]';) to the end of the input string so Marpa can be told to search just that part of the string when the logic dictates that a Ruby Slippers token (bracket) is to be passed to Marpa to satisfy the grammar. It's put at the end so that it does not interfere with line and column counts in the original input string.


Handle parts of the grammar as strings, and interpolate various things into those strings, before using them to build the final grammar.

o Handle events
o Handle utf8 input
o Handle doublequoted strings
o Handle single-quoted strings

Handle nested, double-quoted, strings.


Handle strings quoted with various characters, and with escaped characters in there too.


Uses a grammar with pauses to handle various types of quoted strings, with manual scanning.

See for getting Marpa to handling the scanning of HTML.


Handles HTML.

o Handle strings containing escaped characters
o Handle events
o Handle unquoted strings
o Handle doublequoted strings
o Handle single-quoted strings
o Handle events
o Handle utf8 input
o Handle unquoted strings
o Handle doublequoted strings
o Handle single-quoted strings

Un-runnable Scripts

All these scripts are in the examples/ directory.


Show how, during an action sub, another parse can be done using the output of the parse which triggered the action. The inner parse uses the same grammar as the outer parse.


Contains both ambiguous and un-ambiguous grammars.

Uses MarpaX::ASF::PFG, which is not on MetaCPAN.


Parse multiple heredocs.


Processes HTML.

Uses HTML::WikiConverter, which won't install without patches, and which the author apparently refuses to fix.



Do any scripts handle HTML?

Yes. See scripts/

Machine-Readable Change Log

The file Changes was converted into Changelog.ini by Module::Metadata::Changes.

Version Numbers

Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.


Email the author, or log a bug on RT:


MarpaX::Demo::SampleScripts was written by Ron Savage <> in 2014.

Marpa's homepage: <>.

My homepage:


Australian copyright (c) 2014, Ron Savage.

        All Programs of mine are 'OSI Certified Open Source Software';
        you can redistribute them and/or modify them under the terms of
        The Artistic License 2.0, a copy of which is available at: