GraphV...::Yacc(3pm)
β¨ GraphViz2::Parse::Yacc β¨
hi bestie!! π welcome to the GraphV...::Yacc(3pm) page, straight outta the User Contributed Perl Documentation. it's giving "make a yacc grammar look pretty as a graph" and honestly? obsessed. π¦
π NAME π
GraphViz2::Parse::Yacc β Visualize a yacc grammar as a graph
like. that's the whole job. turn your yacc grammar into a picture. iconic.
πΈ SYNOPSIS πΈ
okay so here's how you actually use this thing, no gatekeeping:
use GraphViz2::Parse::Yacc;
# no objects - quicker
my $gd = GraphViz2::Parse::Yacc::to_graph('t/calc3.output');
# populate a GraphViz2 object with a Graph::Directed of a parser
my $gv = GraphViz2->from_graph(GraphViz2::Parse::Yacc::graphvizify($gd));
# OO interface, using lazy-built attributes
my $gvp = GraphViz2::Parse::Yacc->new(file_name => $file_name);
my $gd = $gvp->as_graph; # Graph::Directed object
# or supply a suitable Graph::Directed object
my $gvp = GraphViz2::Parse::Yacc->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::Yacc->new;
$gvp->create(file_name => 't/calc3.output');
my $gv = $gvp->graph;
# or give it a pre-set-up GraphViz2 object
my $gv = GraphViz2->new(...);
my $gvp = GraphViz2::Parse::Yacc->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);
and yeah, peep t/gen.parse.yacc.pl. for a real live example. π
π§ DESCRIPTION π§
you hand it a yacc grammar, and it hands you back a Graph::Directed object β or, if you're feeling fancy, it goes straight to a GraphViz2 object. two paths, one glow-up. β¨
π FUNCTIONS π
this is the recommended interface, bestie. do this.
π to_graph
my $gd = GraphViz2::Parse::Yacc::to_graph('t/calc3.output');
give it a yacc grammar, get back a Graph::Directed object that describes the finite state machine for it. that's it. that's the magic. π₯
π graphvizify
my $gv = GraphViz2->from_graph(GraphViz2::Parse::Yacc::graphvizify($gd));
this one mutates the graph object you give it β it adds the "graphviz" attributes, the visualisation "hints" that make the "from_graph" in GraphViz2 method draw this thing in the most meaningful way possible, labels and groupings included. β¨
and good news: it's idempotent, because all it does is set the "graphviz" attribute of the relevant graph entities. run it again, nothing breaks, we love a stable queen. π
it returns the graph object too, just for convenience. π«Ά
π¦ METHODS π¦
this is a Moo class, but with a recommended functional interface. so you can go OO, but the functional route is what's being hyped here.
π Constructor attributes π
file_name
the name of a yacc output file. see t/calc3.output. π
this key is optional. but you do need to provide it by the time you access either the "as_graph" or "graph". no skipping ahead, bestie. β°
as_graph
the Graph::Directed object to use. if you don't give it one, it'll be lazily built on access, from the "file_name".
graph
the GraphViz2 object to use. this one lets you configure it however you want. π
this key is optional. if you provide it, the "create" method will populate it. if you don't, it'll get 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(file_name => $file_name) π
DEPRECATED. bestie, this is the old way. it still works, but know what you're getting into. π
it 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".
and it returns $self for method chaining. chain away. π
π THANKS π
so much love to the people who chose to make Graphviz Open Source β http://www.graphviz.org/ π
and thanks to Leon Brocard β http://search.cpan.org/~lbrocard/ β who wrote GraphViz, and kindly gave me co-maint of the module. π«Ά legend behaviour, fr fr.
π 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/
okay that's the whole page bestie, you're officially caught up. πβ¨
this was perl v5.36.0, dated 2023-07-12, from the GraphV...::Yacc(3pm) page β go forth and graph your grammars, main character. ππ¦
π¦ where this page comes from
- debian trixie: libgraphviz2-perl 2.67-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libgraphviz2-perl 2.67-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libgraphviz2-perl 2.67-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libgraphviz2-perl 2.67-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms