@@ -64,6 +64,10 @@ let fprint_string_user ppf s =
64
64
(* let s = String.escaped s in*)
65
65
fprintf ppf " \" %s\" " s
66
66
67
+ let fprint_square_not_empty printer ppf = function
68
+ | [] -> ()
69
+ | l -> fprintf ppf " [%a]" printer l
70
+
67
71
type arrow_style =
68
72
[ `None | `Normal | `Inv | `Dot | `Odot | `Invdot | `Invodot ]
69
73
@@ -80,6 +84,13 @@ let fprint_dir ppf = function
80
84
`TopToBottom -> fprintf ppf " TB"
81
85
| `LeftToRight -> fprintf ppf " LR"
82
86
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 " ;"
83
94
84
95
(* * The [ATTRIBUTES] module type defines the interface for the engines. *)
85
96
module type ATTRIBUTES = sig
@@ -257,8 +268,10 @@ module CommonAttributes = struct
257
268
| `Bold -> " bold"
258
269
| `Invis -> " invis"
259
270
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
262
275
263
276
let fprint_vertex ppf = function
264
277
| `Color a -> fprintf ppf " color=%a" fprint_color a
@@ -312,22 +325,22 @@ module CommonAttributes = struct
312
325
attributes on the formatter [ppf], using the printer [printer] for
313
326
each attribute. The list appears between brackets and attributes
314
327
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 =
316
329
if list <> [] then begin
317
330
let list , styles = filter_style [] [] list in
318
331
let rec fprint_attributes_rec ppf = function
319
332
| [] -> ()
320
333
| 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;
323
337
fprint_attributes_rec ppf tl
324
338
in
325
- fprintf ppf " [ @[<hov>%a" fprint_attributes_rec list ;
339
+ fprintf ppf " @[<hov>%a" fprint_attributes_rec list ;
326
340
if styles <> [] then begin
327
- if list <> [] then fprintf ppf " ,@ " ;
328
- fprint_style_list ppf styles
341
+ fprint_style_list sep ppf styles
329
342
end ;
330
- fprintf ppf " @]] "
343
+ fprintf ppf " @]"
331
344
end
332
345
333
346
let fprint_vertex_list =
@@ -348,8 +361,8 @@ module type ENGINE = sig
348
361
module Attributes : sig
349
362
include ATTRIBUTES
350
363
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
353
366
end
354
367
355
368
(* * The litteral name of the engine. *)
@@ -425,7 +438,7 @@ struct
425
438
let default_node_attributes = X. default_vertex_attributes graph in
426
439
if default_node_attributes <> [] then
427
440
fprintf ppf " node%a;@ "
428
- EN.Attributes. fprint_vertex_list
441
+ (fprint_square_not_empty ( EN.Attributes. fprint_vertex_list COMMA ))
429
442
default_node_attributes;
430
443
431
444
X. iter_vertex
@@ -443,7 +456,7 @@ struct
443
456
end ;
444
457
fprintf ppf " %s%a;@ "
445
458
(X. vertex_name node)
446
- EN.Attributes. fprint_vertex_list
459
+ (fprint_square_not_empty ( EN.Attributes. fprint_vertex_list COMMA ))
447
460
(X. vertex_attributes node)
448
461
)
449
462
graph
@@ -457,14 +470,12 @@ struct
457
470
| name :: worklist ->
458
471
let sg, nodes = SG. find name ! subgraphs in
459
472
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 "
461
474
462
475
name
463
476
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
468
479
469
480
(fun ppf ->
470
481
(List. iter (fun n -> fprintf ppf " %s;" (X. vertex_name n)) nodes)
@@ -489,14 +500,15 @@ struct
489
500
let default_edge_attributes = X. default_edge_attributes graph in
490
501
if default_edge_attributes <> [] then
491
502
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;
493
505
494
506
X. iter_edges_e (function edge ->
495
507
fprintf ppf " %s %s %s%a;@ "
496
508
(X. vertex_name (X.E. src edge))
497
509
EN. edge_arrow
498
510
(X. vertex_name (X.E. dst edge))
499
- EN.Attributes. fprint_edge_list
511
+ (fprint_square_not_empty ( EN.Attributes. fprint_edge_list COMMA ))
500
512
(X. edge_attributes edge)
501
513
) graph
502
514
0 commit comments