Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
DotParser.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
38
39#include <iosfwd>
40#include <set>
41#include <string>
42#include <vector>
43
44namespace ogdf {
45class ClusterGraphAttributes;
46class GraphAttributes;
47
48namespace dot {
49
50class Parser;
51struct SubgraphData;
52
54
111class Ast {
112public:
113 struct AList;
114 struct AsgnStmt;
115 struct AttrList;
116 struct AttrStmt;
117 struct CompassPt;
118 struct EdgeLhs;
119 struct EdgeRhs;
120 struct EdgeStmt;
121 struct Graph;
122 struct NodeId;
123 struct NodeStmt;
124 struct Port;
125 struct Stmt;
126 struct StmtList;
127 struct Subgraph;
128
129private:
130 using Tokens = std::vector<Token>;
131 using Iterator = Tokens::const_iterator;
132
135
137
146 Stmt* parseStmt(Iterator current, Iterator& rest);
150 Port* parsePort(Iterator current, Iterator& rest);
152
153public:
155
158 explicit Ast(const Tokens& tokens);
160
162
165 bool build();
166
168 Graph* root() const;
169
170 struct Graph {
171 const bool strict;
172 const bool directed;
173 std::string* id;
174
176
177 Graph(const bool& paramStrict, const bool& dir, std::string* idString,
178 StmtList* statementList);
180
183 };
184
185 struct StmtList {
188
189 StmtList(Stmt* headSTMT, StmtList* tailStatementList);
191 };
192
193 struct Stmt {
194 virtual ~Stmt() = 0;
195
196 virtual bool read(Parser& P, ogdf::Graph& G, GraphAttributes* GA, ClusterGraph* C,
197 ClusterGraphAttributes* CA, const SubgraphData& data) = 0;
198 };
199
200 struct NodeStmt : public Stmt {
203
204 NodeStmt(NodeId* nodeID, AttrList* attrList);
206
207 virtual bool read(Parser& P, ogdf::Graph& G, GraphAttributes* GA, ClusterGraph* C,
208 ClusterGraphAttributes* CA, const SubgraphData& data) override;
209 };
210
211 struct EdgeStmt : public Stmt {
215
216 EdgeStmt(EdgeLhs* edgeLHS, EdgeRhs* edgeRHS, AttrList* attrList);
218
219 virtual bool read(Parser& P, ogdf::Graph& G, GraphAttributes* GA, ClusterGraph* C,
220 ClusterGraphAttributes* CA, const SubgraphData& data) override;
221 };
222
223 struct AsgnStmt : public Stmt {
224 const std::string lhs;
225 const std::string rhs;
226
227 AsgnStmt(const std::string& lhsString, const std::string& rhsString);
229
230 virtual bool read(Parser& P, ogdf::Graph& G, GraphAttributes* GA, ClusterGraph* C,
231 ClusterGraphAttributes* CA, const SubgraphData& data) override;
232 };
233
234 struct AttrStmt : public Stmt {
235 enum class Type { graph, edge, node };
236
239
240 AttrStmt(const Type& paramType, AttrList* attrList);
242
243 virtual bool read(Parser& P, ogdf::Graph& G, GraphAttributes* GA, ClusterGraph* C,
244 ClusterGraphAttributes* CA, const SubgraphData& data) override;
245 };
246
247 struct EdgeLhs {
248 virtual ~EdgeLhs() = 0;
249
250 virtual bool read(Parser& P, ogdf::Graph& G, GraphAttributes* GA, ClusterGraph* C,
251 ClusterGraphAttributes* CA, const SubgraphData& data) = 0;
252 };
253
254 struct Subgraph : public Stmt, EdgeLhs {
255 std::string* id;
257
258 Subgraph(std::string* idString, StmtList* statementList);
260
261 virtual bool read(Parser& P, ogdf::Graph& G, GraphAttributes* GA, ClusterGraph* C,
262 ClusterGraphAttributes* CA, const SubgraphData& data) override;
263 };
264
265 struct NodeId : public EdgeLhs {
266 const std::string id;
268
269 NodeId(const std::string& idString, Port* paramPort);
271
272 virtual bool read(Parser& P, ogdf::Graph& G, GraphAttributes* GA, ClusterGraph* C,
273 ClusterGraphAttributes* CA, const SubgraphData& data) override;
274 };
275
276 struct CompassPt {
277 enum class Type { n, ne, e, se, s, sw, w, nw, c, wildcard };
279
280 CompassPt(const Type& paramType);
282 };
283
284 struct Port {
285 std::string* id;
287
288 Port(std::string* idString, CompassPt* compassPT);
290 };
291
292 struct EdgeRhs {
295
296 EdgeRhs(EdgeLhs* headEdgeLHS, EdgeRhs* tailEdgeRHS);
298 };
299
300 struct AttrList {
303
304 AttrList(AList* headAList, AttrList* tailAttrList);
306 };
307
308 struct AList {
311
312 AList(AsgnStmt* headAsgnStmt, AList* tailAList);
314 };
315};
316
318
325class Parser {
326private:
327 std::istream& m_in;
328
329 // Maps node id to Graph node.
331
333
334public:
336 explicit Parser(std::istream& in);
337
338 bool read(Graph& G);
340 bool read(Graph& G, ClusterGraph& C);
342
344
356 const std::string& id);
357};
358
362 std::vector<Ast::AttrList*>& nodeDefaults;
363 std::vector<Ast::AttrList*>& edgeDefaults;
364 std::set<node>& nodes;
365
367
373 SubgraphData(cluster root, std::vector<Ast::AttrList*>& nodeDefaultsVector,
374 std::vector<Ast::AttrList*>& edgeDefaultsVector, std::set<node>& nodeSet);
375
376
378 SubgraphData withCluster(cluster newRootCluster) const;
379
381 SubgraphData withDefaults(std::vector<Ast::AttrList*>& newNodeDefaults,
382 std::vector<Ast::AttrList*>& newEdgeDefaults) const;
384 SubgraphData withNodes(std::set<node>& newNodes) const;
385};
386
387}
388}
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
Declares stuff related to DOT format lexical analysis.
Includes declaration of graph class.
Declaration and implementation of HashArray class.
Representation of clusters in a clustered graph.
Stores additional attributes of a clustered graph (like layout information).
Representation of clustered graphs.
Stores additional attributes of a graph (like layout information).
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Indexed arrays using hashing for element access.
Definition HashArray.h:93
Class for the representation of nodes.
Definition Graph_d.h:241
DOT format abstract syntax tree class, based on official documentation.
Definition DotParser.h:111
NodeStmt * parseNodeStmt(Iterator current, Iterator &rest)
EdgeRhs * parseEdgeRhs(Iterator current, Iterator &rest)
std::vector< Token > Tokens
Definition DotParser.h:130
AttrStmt * parseAttrStmt(Iterator current, Iterator &rest)
Ast(const Tokens &tokens)
Initializes AST building but does not trigger the process itself.
EdgeStmt * parseEdgeStmt(Iterator current, Iterator &rest)
AsgnStmt * parseAsgnStmt(Iterator current, Iterator &rest)
const Tokens m_tokens
Definition DotParser.h:133
CompassPt * parseCompassPt(Iterator current, Iterator &rest)
Graph * root() const
Returns the root of the AST (nullptr if none).
Graph * m_graph
Definition DotParser.h:136
AttrList * parseAttrList(Iterator current, Iterator &rest)
Subgraph * parseSubgraph(Iterator current, Iterator &rest)
Stmt * parseStmt(Iterator current, Iterator &rest)
const Iterator m_tend
Definition DotParser.h:134
AList * parseAList(Iterator current, Iterator &rest)
Graph * parseGraph(Iterator current, Iterator &rest)
bool build()
Builds the DOT format AST.
Tokens::const_iterator Iterator
Definition DotParser.h:131
Port * parsePort(Iterator current, Iterator &rest)
StmtList * parseStmtList(Iterator current, Iterator &rest)
NodeId * parseNodeId(Iterator current, Iterator &rest)
DOT format parser class.
Definition DotParser.h:325
bool read(Graph &G, ClusterGraph &C, ClusterGraphAttributes &CA)
bool read(Graph &G)
bool readGraph(Graph &G, GraphAttributes *GA, ClusterGraph *C, ClusterGraphAttributes *CA)
bool read(Graph &G, ClusterGraph &C)
Parser(std::istream &in)
Initializes parser class with given input (but does nothing to it).
bool read(Graph &G, GraphAttributes &GA)
std::istream & m_in
Definition DotParser.h:327
node requestNode(Graph &G, GraphAttributes *GA, ClusterGraph *C, const SubgraphData &data, const std::string &id)
Perfoms a node query, returning node for given attribute.
HashArray< std::string, node > m_nodeId
Definition DotParser.h:330
The namespace for all OGDF objects.
AList(AsgnStmt *headAsgnStmt, AList *tailAList)
virtual bool read(Parser &P, ogdf::Graph &G, GraphAttributes *GA, ClusterGraph *C, ClusterGraphAttributes *CA, const SubgraphData &data) override
AsgnStmt(const std::string &lhsString, const std::string &rhsString)
const std::string lhs
Definition DotParser.h:224
const std::string rhs
Definition DotParser.h:225
AttrList(AList *headAList, AttrList *tailAttrList)
virtual bool read(Parser &P, ogdf::Graph &G, GraphAttributes *GA, ClusterGraph *C, ClusterGraphAttributes *CA, const SubgraphData &data) override
AttrStmt(const Type &paramType, AttrList *attrList)
CompassPt(const Type &paramType)
virtual bool read(Parser &P, ogdf::Graph &G, GraphAttributes *GA, ClusterGraph *C, ClusterGraphAttributes *CA, const SubgraphData &data)=0
EdgeRhs(EdgeLhs *headEdgeLHS, EdgeRhs *tailEdgeRHS)
virtual bool read(Parser &P, ogdf::Graph &G, GraphAttributes *GA, ClusterGraph *C, ClusterGraphAttributes *CA, const SubgraphData &data) override
EdgeStmt(EdgeLhs *edgeLHS, EdgeRhs *edgeRHS, AttrList *attrList)
StmtList * statements
Definition DotParser.h:175
std::string * id
Definition DotParser.h:173
Graph(const bool &paramStrict, const bool &dir, std::string *idString, StmtList *statementList)
bool read(Parser &P, ogdf::Graph &G, GraphAttributes *GA, ClusterGraph *C, ClusterGraphAttributes *CA)
virtual bool read(Parser &P, ogdf::Graph &G, GraphAttributes *GA, ClusterGraph *C, ClusterGraphAttributes *CA, const SubgraphData &data) override
NodeId(const std::string &idString, Port *paramPort)
const std::string id
Definition DotParser.h:266
virtual bool read(Parser &P, ogdf::Graph &G, GraphAttributes *GA, ClusterGraph *C, ClusterGraphAttributes *CA, const SubgraphData &data) override
NodeStmt(NodeId *nodeID, AttrList *attrList)
Port(std::string *idString, CompassPt *compassPT)
std::string * id
Definition DotParser.h:285
CompassPt * compassPt
Definition DotParser.h:286
virtual bool read(Parser &P, ogdf::Graph &G, GraphAttributes *GA, ClusterGraph *C, ClusterGraphAttributes *CA, const SubgraphData &data)=0
StmtList(Stmt *headSTMT, StmtList *tailStatementList)
Subgraph(std::string *idString, StmtList *statementList)
virtual bool read(Parser &P, ogdf::Graph &G, GraphAttributes *GA, ClusterGraph *C, ClusterGraphAttributes *CA, const SubgraphData &data) override
A helper structure containing information for recursive graph reading.
Definition DotParser.h:360
std::set< node > & nodes
Definition DotParser.h:364
std::vector< Ast::AttrList * > & edgeDefaults
Definition DotParser.h:363
SubgraphData withCluster(cluster newRootCluster) const
Returns almost the same structure, but with root cluster.
SubgraphData withNodes(std::set< node > &newNodes) const
Returns almost the same structure, but with new node list.
SubgraphData withDefaults(std::vector< Ast::AttrList * > &newNodeDefaults, std::vector< Ast::AttrList * > &newEdgeDefaults) const
Returns almost the same structure, but with new defaults.
std::vector< Ast::AttrList * > & nodeDefaults
Definition DotParser.h:362
SubgraphData(cluster root, std::vector< Ast::AttrList * > &nodeDefaultsVector, std::vector< Ast::AttrList * > &edgeDefaultsVector, std::set< node > &nodeSet)
Initializes structure with given data.