- SEE ALSO
- COPYRIGHT AND LICENSE
Graph::Regexp - Create graphical flowchart from a regular expression
# print out ASCII graph perl -Mre=debug -e '/just|another|perl|hacker/' 2>&1 | examples/regraph # the same, as PNG rendered via dot perl -Mre=debug -e '/me|you/' 2>&1 | examples/regraph as_graphviz | dot -Tpng -o me.png
This module takes the debug dump of a regular expression (regexp) as generated by Perl itself, and creates a flowchart from it as a Graph::Easy object.
This in turn can be converted it into all output formats currently supported by
Graph::Easy, namely HTML, SVG, ASCII art, Unicode art, graphviz code (which then can be rendered as PNG etc) etc.
Per default, the graph will have certain properties, like bold start/end blocks, diamond-shaped branch-blocks and so on. You can change these by setting class attributes on the returned graph object. The class for each node is the same as it appears in the dump, in lowercase:
start exact plus star trie curly end
graph() provides a simple function-style interface, while all other methods are for an object-oriented model.
my $graph = Graph::Regexp->graph( $dump );
Takes a regexp dump in $dump (as SCALAR) and returns a Graph::Easy object.
This is a shortcut to avoid the OO interface described below and will be equivalent to:
my $parser = Graph::Regexp->new(); $parser->parse( $dump ); my $graph = $parser->as_graph();
Graph::Easy for further details on what to do with the returned object.
my $parser = Graph::Regexp->new( $options );
Creates a new
$options is a hash reference with parameters.
At the moment no options are defined.
my $option = $parser->option($name);
Return the option with the given name from the
$parser->decompose( \$txt ); # \'...' $parser->decompose( $filename ); # 'regexp_dump.txt'
Takes Regexp dump (scalar ref in
$txt) or file (filename in
$filename) and creates a graph from it.
This is an alias for
Reset the internal state of the parser object. Called automatically by decompose().
my $graph = $parser->as_graph();
Return the internal data structure as
Return the graph as ASCII art. Shortcut for
my $label = $parser->graph_label(); $parser->graph_label('/^foo|bar/');
Set or get the label of the graph.
Does not yet handle the new things like TRIE.
This library is free software; you can redistribute it and/or modify it under the same terms of the GPL version 2 or later. See the LICENSE file for information.
Copyright (C) 2006-2008 by Tels http://bloodgate.com