1+ module DOT
2+
3+ using GraphIO. ParserCombinator. Parsers
4+ using LightGraphs
5+ using LightGraphs: AbstractGraphFormat
6+
7+ import LightGraphs: loadgraph, loadgraphs
8+
9+ export DOTFormat
110
211struct DOTFormat <: AbstractGraphFormat end
312# TODO : implement save
413
5- function _dot_read_one_graph (pg:: DOT.Graph )
14+ function _dot_read_one_graph (pg:: Parsers. DOT.Graph )
615 isdir = pg. directed
7- nvg = length (DOT. nodes (pg))
8- nodedict = Dict (zip (collect (DOT. nodes (pg)), 1 : nvg))
16+ nvg = length (Parsers . DOT. nodes (pg))
17+ nodedict = Dict (zip (collect (Parsers . DOT. nodes (pg)), 1 : nvg))
918 if isdir
1019 g = LightGraphs. DiGraph (nvg)
1120 else
1221 g = LightGraphs. Graph (nvg)
1322 end
14- for es in DOT. edges (pg)
23+ for es in Parsers . DOT. edges (pg)
1524 s = nodedict[es[1 ]]
1625 d = nodedict[es[2 ]]
1726 add_edge! (g, s, d)
@@ -20,24 +29,24 @@ function _dot_read_one_graph(pg::DOT.Graph)
2029end
2130
2231function loaddot (io:: IO , gname:: String )
23- p = DOT. parse_dot (read (io, String))
32+ p = Parsers . DOT. parse_dot (read (io, String))
2433 for pg in p
2534 isdir = pg. directed
26- possname = isdir ? DOT. StringID (" digraph" ) : DOT. StringID (" graph" )
35+ possname = isdir ? Parsers . DOT. StringID (" digraph" ) : Parsers . DOT. StringID (" graph" )
2736 name = get (pg. id, possname). id
2837 name == gname && return _dot_read_one_graph (pg)
2938 end
3039 error (" Graph $gname not found" )
3140end
3241
3342function loaddot_mult (io:: IO )
34- p = DOT. parse_dot (read (io, String))
43+ p = Parsers . DOT. parse_dot (read (io, String))
3544
36- graphs = Dict {String,LightGraphs. AbstractGraph} ()
45+ graphs = Dict {String,AbstractGraph} ()
3746
3847 for pg in p
3948 isdir = pg. directed
40- possname = isdir ? DOT. StringID (" digraph" ) : DOT. StringID (" graph" )
49+ possname = isdir ? Parsers . DOT. StringID (" digraph" ) : Parsers . DOT. StringID (" graph" )
4150 name = get (pg. id, possname). id
4251 graphs[name] = _dot_read_one_graph (pg)
4352 end
4655
4756loadgraph (io:: IO , gname:: String , :: DOTFormat ) = loaddot (io, gname)
4857loadgraphs (io:: IO , :: DOTFormat ) = loaddot_mult (io)
58+
59+ end # module
0 commit comments