1GraphViz2::Parse::STT(3U)ser Contributed Perl DocumentatiGornaphViz2::Parse::STT(3)
2
3
4
6 GraphViz2::Parse::STT - Visualize a Set::FA::Element state transition
7 table as a graph
8
10 use GraphViz2::Parse::STT;
11 use File::Slurp; # For read_file().
12 my $stt = read_file('sample.stt.1.dat');
13 # no objects - quicker
14 my $gd = GraphViz2::Parse::STT::to_graph($stt);
15
16 # populate a GraphViz2 object with a Graph::Directed of a parser
17 my $gv = GraphViz2->from_graph(GraphViz2::Parse::STT::graphvizify($gd));
18
19 # visualise with another mode
20 $gd = GraphViz2::Parse::STT::graphvizify($gd, 're_nodes'); # or 're_edges'
21
22 # OO interface, using lazy-built attributes
23 my $gvp = GraphViz2::Parse::STT->new(stt => $stt, mode => 're_structs');
24 my $gd = $gvp->as_graph; # Graph::Directed object
25 # or supply a suitable Graph::Directed object
26 my $gvp = GraphViz2::Parse::STT->new(as_graph => $gd);
27 # then get the GraphViz2 object
28 my $gv = $gvp->graph;
29
30 # DEPRECATED ways to get $gvp with populated $gv
31 my $gvp = GraphViz2::Parse::STT->new;
32 $gvp->create(stt => $stt);
33 my $gv = $gvp->graph;
34 # or give it a pre-set-up GraphViz2 object
35 my $gv = GraphViz2->new(...);
36 my $gvp = GraphViz2::Parse::STT->new(graph => $gv);
37 # call ->create as above
38
39 # produce a visualisation
40 my $format = shift || 'svg';
41 my $output_file = shift || "output.$format";
42 $gv->run(format => $format, output_file => $output_file);
43
44 See t/gen.parse.stt.t.
45
46 Note: t/sample.stt.2.dat is output from Graph::Easy::Marpa::DFA V 0.70,
47 and can be used instead of t/sample.stt.1.dat in the above code.
48
50 Takes a Set::FA::Element-style state transition table and converts it
51 into a Graph::Directed object, or directly into a GraphViz2 object.
52
54 This is the recommended interface.
55
56 to_graph
57 my $gd = GraphViz2::Parse::STT::to_graph($stt);
58
59 Given STT text, returns a Graph::Directed object describing the finite
60 state machine for it.
61
62 The nodes are all states, and the edges are regular expressions that
63 cause a transition to another state.
64
65 graphvizify
66 my $gv = GraphViz2->from_graph(GraphViz2::Parse::STT::graphvizify($gd, $mode));
67
68 Mutates the given graph object to add to it the "graphviz" attributes
69 visualisation "hints" that will make the "from_graph" in GraphViz2
70 method visualise this regular expression in the most meaningful way,
71 including labels and groupings.
72
73 It is idempotent, but in "re_nodes" mode, it deletes the transition
74 edges and replaces them with additional nodes and edges.
75
76 If a second argument is given, it will be the visualisation "mode". The
77 default is "re_structs". Also available is "re_nodes", and "re_edges"
78 where the regular expressions are simply added as labels to the state-
79 transition edges.
80
81 Returns the graph object for convenience.
82
84 This is a Moo class, but with a recommended functional interface.
85
86 Constructor attributes
87 stt
88
89 Text with a state transition table, with a Perl-ish list of arrayrefs,
90 each with 3 elements.
91
92 That is, it is the contents of the arrayref 'transitions', which is one
93 of the keys in the parameter list to Set::FA::Element's new().
94
95 A quick summary of each element of this list, where each element is an
96 arrayref with 3 elements:
97
98 o [0] A state name
99 o [1] A regexp
100 o [2] Another state name (which may be the same as the first)
101
102 The DFA in Set::FA::Element tests the 'current' state against the state
103 name ([0]), and for each state name which matches, tests the regexp
104 ([1]) against the next character in the input stream. The first regexp
105 to match causes the DFA to transition to the state named in the 3rd
106 element of the arrayref ([2]).
107
108 See t/sample.stt.1.dat for an example.
109
110 This key is optional. You need to provide it by the time you access
111 either the "as_graph" or "graph".
112
113 as_graph
114
115 The Graph::Directed object to use. If not given, will be lazily built
116 on access, from the "stt".
117
118 graph
119
120 The GraphViz2 object to use. This allows you to configure it as
121 desired.
122
123 This key is optional. If provided, the "create" method will populate
124 it. If not, it will have these defaults, lazy-built and populated from
125 the "as_graph".
126
127 my $gv = GraphViz2->new(
128 edge => {color => 'grey'},
129 global => {directed => 1},
130 graph => {rankdir => 'TB'},
131 node => {color => 'blue', shape => 'oval'},
132 );
133
134 mode
135
136 The mode to be used by "graphvizify".
137
138 create(regexp => $regexp, mode => $mode)
139 DEPRECATED. Mutates the object to set the "stt" attribute, then
140 accesses the "as_graph" attribute (possibly lazy-building it), then
141 "graphvizify"s its "as_graph" attribute with that information, then
142 "from_graph"s its "graph".
143
144 Returns $self for method chaining.
145
147 Many thanks are due to the people who chose to make Graphviz
148 <http://www.graphviz.org/> Open Source.
149
150 And thanks to Leon Brocard <http://search.cpan.org/~lbrocard/>, who
151 wrote GraphViz, and kindly gave me co-maint of the module.
152
154 GraphViz2 was written by Ron Savage <ron@savage.net.au> in 2011.
155
156 Home page: <http://savage.net.au/index.html>.
157
159 Australian copyright (c) 2011, Ron Savage.
160
161 All Programs of mine are 'OSI Certified Open Source Software'; you can
162 redistribute them and/or modify them under the terms of The Perl
163 License, a copy of which is available at: http://dev.perl.org/licenses/
164
165
166
167perl v5.32.1 2021-01-27 GraphViz2::Parse::STT(3)