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>
41
42#include <cstdio>
43#include <set>
44#include <string>
45#include <vector>
46
47namespace ogdf {
48
49namespace dot {
50
51class Parser;
52struct SubgraphData;
53
55
112class Ast {
113public:
114 struct Graph;
115 struct StmtList;
116 struct NodeStmt;
117 struct EdgeStmt;
118 struct AttrStmt;
119 struct AsgnStmt;
120 struct Subgraph;
121 struct NodeId;
122 struct EdgeRhs;
123 struct AttrList;
124 struct AList;
125 struct Port;
126 struct CompassPt;
127
128 struct Stmt;
129 struct EdgeLhs;
130
131private:
132 using Tokens = std::vector<Token>;
133 using Iterator = Tokens::const_iterator;
134
137
139
154
155public:
157
160 explicit Ast(const Tokens& tokens);
162
164
167 bool build();
168
170 Graph* root() const;
171
172 struct Graph {
173 const bool strict;
174 const bool directed;
175 std::string* id;
176
178
179 Graph(const bool& paramStrict, const bool& dir, std::string* idString,
182
185 };
186
194
195 struct Stmt {
196 virtual ~Stmt() = 0;
197
199 ClusterGraphAttributes* CA, const SubgraphData& data) = 0;
200 };
201
202 struct NodeStmt : public Stmt {
205
208
210 ClusterGraphAttributes* CA, const SubgraphData& data) override;
211 };
212
224
225 struct AsgnStmt : public Stmt {
226 const std::string lhs;
227 const std::string rhs;
228
229 AsgnStmt(const std::string& lhsString, const std::string& rhsString);
231
233 ClusterGraphAttributes* CA, const SubgraphData& data) override;
234 };
235
236 struct AttrStmt : public Stmt {
237 enum class Type { graph, edge, node };
238
241
244
246 ClusterGraphAttributes* CA, const SubgraphData& data) override;
247 };
248
249 struct EdgeLhs {
250 virtual ~EdgeLhs() = 0;
251
253 ClusterGraphAttributes* CA, const SubgraphData& data) = 0;
254 };
255
256 struct Subgraph : public Stmt, EdgeLhs {
257 std::string* id;
259
262
264 ClusterGraphAttributes* CA, const SubgraphData& data) override;
265 };
266
267 struct NodeId : public EdgeLhs {
268 const std::string id;
270
271 NodeId(const std::string& idString, Port* paramPort);
273
275 ClusterGraphAttributes* CA, const SubgraphData& data) override;
276 };
277
278 struct CompassPt {
279 enum class Type { n, ne, e, se, s, sw, w, nw, c, wildcard };
281
284 };
285
286 struct Port {
287 std::string* id;
289
292 };
293
301
309
317};
318
320
327class Parser {
328private:
329 std::istream& m_in;
330
331 // Maps node id to Graph node.
333
335
336public:
338 explicit Parser(std::istream& in);
339
340 bool read(Graph& G);
342 bool read(Graph& G, ClusterGraph& C);
344
346
358 const std::string& id);
359};
360
364 std::vector<Ast::AttrList*>& nodeDefaults;
365 std::vector<Ast::AttrList*>& edgeDefaults;
366 std::set<node>& nodes;
367
369
375 SubgraphData(cluster root, std::vector<Ast::AttrList*>& nodeDefaultsVector,
376 std::vector<Ast::AttrList*>& edgeDefaultsVector, std::set<node>& nodeSet);
377
378
381
383 SubgraphData withDefaults(std::vector<Ast::AttrList*>& newNodeDefaults,
384 std::vector<Ast::AttrList*>& newEdgeDefaults) const;
386 SubgraphData withNodes(std::set<node>& newNodes) const;
387};
388
389}
390}
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
Declares ClusterGraphAttributes, an extension of class GraphAttributes, to store clustergraph layout ...
DOT related enums and string conversion functions.
Declares stuff related to DOT format lexical analysis.
Includes declaration of graph class.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
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:521
Indexed arrays using hashing for element access.
Definition HashArray.h:93
Class for the representation of nodes.
Definition Graph_d.h:177
DOT format abstract syntax tree class, based on official documentation.
Definition DotParser.h:112
NodeStmt * parseNodeStmt(Iterator current, Iterator &rest)
EdgeRhs * parseEdgeRhs(Iterator current, Iterator &rest)
std::vector< Token > Tokens
Definition DotParser.h:132
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:135
CompassPt * parseCompassPt(Iterator current, Iterator &rest)
Graph * root() const
Returns the root of the AST (nullptr if none).
Graph * m_graph
Definition DotParser.h:138
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:136
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:133
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:327
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:329
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:332
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
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:226
const std::string rhs
Definition DotParser.h:227
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:177
std::string * id
Definition DotParser.h:175
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:268
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:287
CompassPt * compassPt
Definition DotParser.h:288
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:362
std::set< node > & nodes
Definition DotParser.h:366
std::vector< Ast::AttrList * > & edgeDefaults
Definition DotParser.h:365
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:364
SubgraphData(cluster root, std::vector< Ast::AttrList * > &nodeDefaultsVector, std::vector< Ast::AttrList * > &edgeDefaultsVector, std::set< node > &nodeSet)
Initializes structure with given data.