The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Graph::Easy::Marpa::Parser - Proof-of-concept Marpa-based parser for Graph::Easy

Synopsis

For sample code, see scripts/demo.pl, t/attr.t and t/edge.t.

For more details, see Graph::Easy::Marpa.

Description

Graph::Easy::Marpa::Parser provides a Marpa-based parser for Graph::Easy-style graph definitions.

Installation

Install Graph::Easy::Marpa as you would for any Perl module:

Run:

        cpanm Graph::Easy::Marpa

or run:

        sudo cpan Graph::Easy::Marpa

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) = Graph::Easy::Marpa::Parser -> new(k1 => v1, k2 => v2, ...).

It returns a new object of type Graph::Easy::Marpa::Parser.

Key-value pairs accepted in the parameter list (see corresponding methods for details [e.g. verbose()]):

o verbose

Takes either 0 (the default) or 1.

If 0, nothing is printed.

If 1, nothing is printed, yet.

See scripts/demo.pl and Graph::Easy::Marpa::Test.

Methods

add_globals()

The special items, global_node and global_edge, are added to the arrayref of items if the user did not supply them. See the "FAQ" in Graph::Easy::Marpa for details, and in particular the discussion under the question "How are graphs stored in RAM (by Graph::Easy::Marpa::Parser)?".

add_globals() is called automatically near the end of run().

attrs([$new_arrayref])

The [] indicate an optional parameter.

Returns an arrayref of hashrefs, 1 hashref for each attribute belonging to the 'current' node or edge. See the "FAQ" in Graph::Easy::Marpa for details.

This arrayref is reset to [] as soon as the current attributes are transferred into the arrayref managed by the items() method.

If called as attrs([...]), set the arrayref of hashrefs to the parameter.

attr_name([$name])

The [] indicate an optional parameter.

Sets or returns the 'current' attribute's name, during the parse of each attribute definition attached to either a node or an edge.

grammar()

Initializes and returns a data structure of type Marpa::Grammar. This defines the acceptable syntax of the precise subset of Graph::Easy definitions which this module is able to parse.

Note that the method grammar() calls (via Marpa) various helper functions (i.e. not methods), including edge_id(). The latter applies a restriction to the definition of edges in the grammar.

Specifically, edges must currently match this regexp: /^<?(-|=|\.|~|- |= |\.-|\.\.-){1,}>?$/, which I've gleaned from the Graph::Easy docs at Edges.

Later, the allowable syntax will be exanded to accept special arrow heads, etc.

Also, since edges can have attributes, such attributes are another method of describing the desired edge's characteristics. That is, besides using a string matching that regexp to specify what the edge looks like when plotted.

items([$new_arrayref])

The [] indicate an optional parameter.

Returns an arrayref of items. See the "FAQ" in Graph::Easy::Marpa for details.

If called as items([...]), set the arrayref of hashrefs to the parameter.

See also run(), below.

log($s)

If new() was called as new() or new(verbose => 0), do nothing.

If new() was called as new(verbose => 1), print the string $s.

node_name([$name])

The [] indicate an optional parameter.

Sets or returns the 'current' node's name, after the parse of each node definition.

run($token, [$grammar])

Returns 'OK' or dies with an error message.

The [] indicate an optional parameter.

$token is an arrayref of tokens, to be consumed by the Marpa parser.

See Graph::Easy::Marpa::Test, scripts/demo.pl, and data/intermediary.*.csv, for samples.

$grammar is the grammar to be used by Marpa. It defaults to the return value of grammar().

Purpose: Run the Marpa parser, using @$token and $grammar.

The end result is an arrayref, accessible with the items() method, of hashrefs representing items in the input stream.

The structure of this arrayref of hashrefs is discussed in the "FAQ" in Graph::Easy::Marpa.

verbose([0 or 1])

The [] indicate an optional parameter.

Get or set the value of the verbose option.

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=Graph::Easy::Marpa.

Author

Graph::Easy::Marpa::Parser was written by Ron Savage <ron@savage.net.au> in 2011.

Home page: http://savage.net.au/index.html.

Copyright

Australian copyright (c) 2011, 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, a copy of which is available at:
        http://www.opensource.org/licenses/index.html