GraphV...::Yacc(3pm)

πŸ“¦
version 2.67 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ 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


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