12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697(**********************************************************************)(* *)(* LASCAr *)(* *)(* Copyright (c) 2017-present, Jocelyn SEROT. All rights reserved. *)(* *)(* This source code is licensed under the license found in the *)(* LICENSE file in the root directory of this source tree. *)(* *)(**********************************************************************)(** Input signature of the functor {!Tree.Make}. *)moduletypeArg=sigtypenodetypeedgevalstring_of_node:node->stringvalstring_of_edge:edge->stringend(** Output signature of the functor {!Tree.Make}. *)moduletypeS=sigtypenode(** The type of information attached to the nodes of the tree *)typeedge(** The type of information attached to the edges of the tree *)typet=(** The type of trees *)Empty|Nodeofnode*(t*edge)listvalfold:(node->node->node)->node->t->node(** [fold f z t] is [f (... (f (f z n1) n2) ...) nn], where [n1, ..., nn] are the nodes of [t].
The in which the nodes are presented is unspecified. *)(* TO BE COMPLETED ... *)valdot_output:string->string->?options:Dot.graph_stylelist->t->unitvaldot_view:string->?options:Dot.graph_stylelist->?dir:string->?cmd:string->t->intend(** Functor building an implementation of the tree structure *)moduleMake(A:Arg)=structtypenode=A.nodetypeedge=A.edgetypet=Empty|Nodeofnode*(t*edge)listletrecfoldfz=functionEmpty->z|Node(a,ts)->List.fold_left(funz(t,_)->fz(foldfzt))atsletoutputnameocoptionst=letrankdir=ifList.memDot.RankdirLRoptionsthen"LR"else"UD"inletcnt=ref0inletrecoutpparent(t,l)=matchtwithEmpty->letcurrent=!cntinPrintf.fprintfoc"%d [label = \"%s\" shape = plaintext]\n"current"...";ifparent>=0thenPrintf.fprintfoc"%d -> %d [label = \"%s\"]\n"parentcurrentl;incrcnt|Node(n,ts)->letcurrent=!cntinPrintf.fprintfoc"%d [label = \"%s\" shape = plaintext]\n"current(A.string_of_noden);ifparent>=0thenPrintf.fprintfoc"%d -> %d [label = \"%s\"]\n"parentcurrentl;incrcnt;List.iteri(funi(t,l)->outpcurrent(t,A.string_of_edgel))tsinPrintf.fprintfoc"digraph %s {\nrankdir = %s;\nsize = \"8.5,11\";\nlabel = \"\"\n center = 1;\n nodesep = \"0.350000\"\n ranksep = \"0.400000\"\n fontsize = 12\n orientation = Portrait\n"namerankdir;outp(-1)(t,"");Printf.fprintfoc"}\n"letdot_outputnamefname?(options=[])t=letoc=open_outfnameinoutputnameocoptionst;close_outocletdot_viewname?(options=[])?(dir="/tmp")?(cmd="open -a Graphviz")t=letfname=dir^"/"^name^".dot"indot_outputnamefname~options:optionst;Printf.printf"Wrote file %s\n"fname;Sys.command(cmd^" "^fname)end