NAME
GraphViz2::Parse::Yapp - Visualize a yapp grammar as a graph
SYNOPSIS
use GraphViz2::Parse::Yapp;
# no objects - quicker
my $gd = GraphViz2::Parse::Yapp::to_graph('t/calc.output');
# populate a GraphViz2 object with a Graph::Directed of a parser
my $gv = GraphViz2->from_graph(GraphViz2::Parse::Yapp::graphvizify($gd));
# OO interface, using lazy-built attributes
my $gvp = GraphViz2::Parse::Yapp->new(file_name => $file_name);
my $gd = $gvp->as_graph; # Graph::Directed object
# or supply a suitable Graph::Directed object
my $gvp = GraphViz2::Parse::Yapp->new(as_graph => $gd);
# then get the GraphViz2 object
my $gv = $gvp->graph;
# DEPRECATED ways to get $gvp with populated $gv
my $gvp = GraphViz2::Parse::Yapp->new;
$gvp->create(file_name => 't/calc.output');
my $gv = $gvp->graph;
# or give it a pre-set-up GraphViz2 object
my $gv = GraphViz2->new(...);
my $gvp = GraphViz2::Parse::Yapp->new(graph => $gv);
# call ->create as above
# produce a visualisation
my $format = shift || 'svg';
my $output_file = shift || "output.$format";
$gv->run(format => $format, output_file => $output_file);
See t/gen.parse.yapp.pl.
DESCRIPTION
Takes a yapp grammar and converts it into a Graph::Directed object, or directly into a GraphViz2 object.
FUNCTIONS
This is the recommended interface.
to_graph
my $gd = GraphViz2::Parse::Yapp::to_graph('t/calc.output');
Given a yapp grammar, returns a Graph::Directed object describing the finite state machine for it.
graphvizify
my $gv = GraphViz2->from_graph(GraphViz2::Parse::Yapp::graphvizify($gd));
Mutates the given graph object to add to it the graphviz
attributes visualisation "hints" that will make the "from_graph" in GraphViz2 method visualise this regular expression in the most meaningful way, including labels and groupings.
It is idempotent as it simply sets the graphviz
attribute of the relevant graph entities.
Returns the graph object for convenience.
METHODS
This is a Moo class, but with a recommended functional interface.
Constructor attributes
file_name
The name of a yapp output file. See t/calc.output.
This key is optional. You need to provide it by the time you access either the "as_graph" or "graph".
as_graph
The Graph::Directed object to use. If not given, will be lazily built on access, from the "regexp".
graph
The GraphViz2 object to use. This allows you to configure it as desired.
This key is optional. If provided, the create
method will populate it. If not, it will have these defaults, lazy-built and populated from the "as_graph".
my $gv = GraphViz2->new(
edge => {color => 'grey'},
global => {directed => 1},
graph => {rankdir => 'TB'},
node => {color => 'blue', shape => 'oval'},
);
create(regexp => $regexp)
DEPRECATED. Mutates the object to set the file_name
attribute, then accesses the as_graph
attribute (possibly lazy-building it), then graphvizify
s its as_graph
attribute with that information, then from_graph
s its graph
.
Returns $self for method chaining.
THANKS
Many thanks are due to the people who chose to make Graphviz Open Source.
And thanks to Leon Brocard, who wrote GraphViz, and kindly gave me co-maint of the module.
AUTHOR
GraphViz2 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 Perl License, a copy of which is available at: http://dev.perl.org/licenses/