NAME

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

Synopsis

See scripts/*.pl.

Description

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

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

Installation

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

Run:

cpanm MarpaX::Demo::SampleScripts

or run:

sudo cpan MarpaX::Demo::SampleScripts

or unpack the distro, and then either:

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

or:

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:

    (None).

Methods

run()

This method does nothing, and return 0 for success.

Files Shipped with this Module

Many of these scripts are gists, i.e. from https://gist.github.com/. 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.

o ambiguous.grammar.03.pl

A grammar for the Velocity language.

o grammar.inspector.01.pl

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

o html.02.pl

Process defective HTML.

o match.parentheses.01.pl

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

o match.parentheses.02.pl

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.

o parmaterized.grammar.01.pl

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

o quoted.strings.01.pl
o Handle events
o Handle utf8 input
o Handle doublequoted strings
o Handle single-quoted strings
o quoted.strings.02.pl

Handle nested, double-quoted, strings.

o quoted.strings.03.pl

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

o quoted.strings.04.pl

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

See quoted.strings.05.pl for getting Marpa to handling the scanning of HTML.

o quoted.strings.05.pl

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 use.utf8.01.pl
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.

o action.parse.pl

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.

o ambiguous.grammar.01.pl

Contains both ambiguous and un-ambiguous grammars.

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

o heredoc.pl

Parse multiple heredocs.

o html.01.pl

Processes HTML.

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

o match.keywords.pl

FAQ

Do any scripts handle HTML?

Yes. See scripts/quoted.strings.05.pl.

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.

Support

Email the author, or log a bug on RT:

https://rt.cpan.org/Public/Dist/Display.html?Name=MarpaX::Demo::SampleScripts.

Author

MarpaX::Demo::SampleScripts was written by Ron Savage <ron@savage.net.au> in 2014.

Marpa's homepage: <http://savage.net.au/Marpa.html>.

My homepage: http://savage.net.au/.

Copyright

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:
http://www.opensource.org/licenses/index.html