Skip to content

Commit 7defcab

Browse files
committed
Merge pull request #11 from bobot/revert-style-list
[Dot] fix previous commit
2 parents 8a9fbd4 + 708a904 commit 7defcab

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

src/graphviz.ml

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ let fprint_string_user ppf s =
6464
(* let s = String.escaped s in*)
6565
fprintf ppf "\"%s\"" s
6666

67+
let fprint_square_not_empty printer ppf = function
68+
| [] -> ()
69+
| l -> fprintf ppf " [%a]" printer l
70+
6771
type arrow_style =
6872
[ `None | `Normal | `Inv | `Dot | `Odot | `Invdot | `Invodot ]
6973

@@ -80,6 +84,13 @@ let fprint_dir ppf = function
8084
`TopToBottom -> fprintf ppf "TB"
8185
| `LeftToRight -> fprintf ppf "LR"
8286

87+
type symbseq =
88+
| COMMA
89+
| SEMI
90+
91+
let fprint_symbseq ppf = function
92+
| COMMA -> pp_print_string ppf ","
93+
| SEMI -> pp_print_string ppf ";"
8394

8495
(** The [ATTRIBUTES] module type defines the interface for the engines. *)
8596
module type ATTRIBUTES = sig
@@ -257,8 +268,10 @@ module CommonAttributes = struct
257268
| `Bold -> "bold"
258269
| `Invis -> "invis"
259270

260-
let fprint_style_list ppf a =
261-
fprintf ppf "style=\"%a\"" fprint_string_list (List.map node_style_str a)
271+
let fprint_style_list sep ppf a =
272+
fprintf ppf "style=\"%a\"%a@ "
273+
fprint_string_list (List.map node_style_str a)
274+
fprint_symbseq sep
262275

263276
let fprint_vertex ppf = function
264277
| `Color a -> fprintf ppf "color=%a" fprint_color a
@@ -312,22 +325,22 @@ module CommonAttributes = struct
312325
attributes on the formatter [ppf], using the printer [printer] for
313326
each attribute. The list appears between brackets and attributes
314327
are speparated by ",". If the list is empty, nothing is printed. *)
315-
let fprint_attributes fprint_style_list fprint_attribute ppf list =
328+
let fprint_attributes fprint_style_list fprint_attribute sep ppf list =
316329
if list <> [] then begin
317330
let list, styles = filter_style [] [] list in
318331
let rec fprint_attributes_rec ppf = function
319332
| [] -> ()
320333
| hd :: tl ->
321-
fprintf ppf "%a" fprint_attribute hd;
322-
if tl <> [] then fprintf ppf ",@ ";
334+
fprintf ppf "%a%a@ "
335+
fprint_attribute hd
336+
fprint_symbseq sep;
323337
fprint_attributes_rec ppf tl
324338
in
325-
fprintf ppf " [@[<hov>%a" fprint_attributes_rec list;
339+
fprintf ppf "@[<hov>%a" fprint_attributes_rec list;
326340
if styles <> [] then begin
327-
if list <> [] then fprintf ppf ",@ ";
328-
fprint_style_list ppf styles
341+
fprint_style_list sep ppf styles
329342
end;
330-
fprintf ppf "@]]"
343+
fprintf ppf "@]"
331344
end
332345

333346
let fprint_vertex_list =
@@ -348,8 +361,8 @@ module type ENGINE = sig
348361
module Attributes : sig
349362
include ATTRIBUTES
350363
val fprint_graph:formatter -> graph -> unit
351-
val fprint_vertex_list: formatter -> vertex list -> unit
352-
val fprint_edge_list: formatter -> edge list -> unit
364+
val fprint_vertex_list: symbseq -> formatter -> vertex list -> unit
365+
val fprint_edge_list: symbseq -> formatter -> edge list -> unit
353366
end
354367

355368
(** The litteral name of the engine. *)
@@ -425,7 +438,7 @@ struct
425438
let default_node_attributes = X.default_vertex_attributes graph in
426439
if default_node_attributes <> [] then
427440
fprintf ppf "node%a;@ "
428-
EN.Attributes.fprint_vertex_list
441+
(fprint_square_not_empty (EN.Attributes.fprint_vertex_list COMMA))
429442
default_node_attributes;
430443

431444
X.iter_vertex
@@ -443,7 +456,7 @@ struct
443456
end;
444457
fprintf ppf "%s%a;@ "
445458
(X.vertex_name node)
446-
EN.Attributes.fprint_vertex_list
459+
(fprint_square_not_empty (EN.Attributes.fprint_vertex_list COMMA))
447460
(X.vertex_attributes node)
448461
)
449462
graph
@@ -457,14 +470,12 @@ struct
457470
| name :: worklist ->
458471
let sg, nodes = SG.find name !subgraphs in
459472
let children = SG.filter (fun n (sg, nodes) -> sg.EN.Attributes.sg_parent = Some name) !subgraphs in
460-
fprintf ppf "@[<v 2>subgraph cluster_%s { %t%t@ %t };@]@\n"
473+
fprintf ppf "@[<v 2>subgraph cluster_%s { %a%t@ %t };@]@\n"
461474

462475
name
463476

464-
(fun ppf ->
465-
EN.Attributes.fprint_vertex_list ppf
466-
sg.EN.Attributes.sg_attributes
467-
)
477+
(EN.Attributes.fprint_vertex_list SEMI)
478+
sg.EN.Attributes.sg_attributes
468479

469480
(fun ppf ->
470481
(List.iter (fun n -> fprintf ppf "%s;" (X.vertex_name n)) nodes)
@@ -489,14 +500,15 @@ struct
489500
let default_edge_attributes = X.default_edge_attributes graph in
490501
if default_edge_attributes <> [] then
491502
fprintf ppf "edge%a;@ "
492-
EN.Attributes.fprint_edge_list default_edge_attributes;
503+
(fprint_square_not_empty (EN.Attributes.fprint_edge_list COMMA))
504+
default_edge_attributes;
493505

494506
X.iter_edges_e (function edge ->
495507
fprintf ppf "%s %s %s%a;@ "
496508
(X.vertex_name (X.E.src edge))
497509
EN.edge_arrow
498510
(X.vertex_name (X.E.dst edge))
499-
EN.Attributes.fprint_edge_list
511+
(fprint_square_not_empty (EN.Attributes.fprint_edge_list COMMA))
500512
(X.edge_attributes edge)
501513
) graph
502514

0 commit comments

Comments
 (0)