Commits

camlspotter committed 10b5ea5

bug fix of Ocaml.save_with, and OCaml data decoder

  • Participants
  • Parent commits 6b75822

Comments (0)

Files changed (2)

     | List [] -> fprintf ppf "[]"
     | List ts -> fprintf ppf "[ @[%a@] ]" (format_list ";@ " format) ts
     | Array ts -> fprintf ppf "[ @[%a@] ]" (format_list ";@ " format) ts
+    | Variant ("::", [hd;tl]) -> fprintf ppf "@[<2>(%a@ :: %a)@]" format hd format tl
     | Variant (tag, []) -> fprintf ppf "%s" tag
     | Variant (tag, [t]) -> fprintf ppf "@[<2>%s@ @[%a@]@]" tag format t
     | Variant (tag, ts) -> fprintf ppf "@[<2>%s@ (@[%a@])@]" tag (format_list ",@ " format) ts
     let desc = match desc with
       | `Invalid_construct -> "invalid construct for simple ocaml value"
       | `Exn (Failure s) -> "failure: " ^ s
-      | `Exn exn -> Printexc.to_string exn
+      | `Exn exn ->"exn: " ^  Printexc.to_string exn
     in
     if loc = Location.none then desc
     else format_sprintf "%a: %s" Location.print loc desc
       let str = Parser.implementation Lexer.token lexbuf in
       structure str
     with
+    | (Error _ as exn) -> raise exn
     | e -> exn Location.none e
 
   let from f d = from_lexbuf (f d)
   let from_channel  = from Lexing.from_channel
-  let from_string   =  from Lexing.from_string
+  let from_string   = from Lexing.from_string
   let from_function = from Lexing.from_function
 end
 
   let oc = open_out_gen [Open_wronly; Open_creat; Open_trunc; Open_binary] perm path in
   try
     let ppf = Format.formatter_of_out_channel oc in
-    List.iter (fun t -> format_with ?no_poly encoder ppf t) ts;
-    Format.fprintf ppf "@.";
+    List.iter (fun t -> 
+      Format.fprintf ppf "%a;;@." (format_with ?no_poly encoder) t;
+    ) ts;
     close_out oc
   with
   | e -> 

ocaml/ocaml_conv.ml

   | Float n -> n
   | _ -> failwith "float_of trace: float expected")
 
-let list_of_ocaml f = Helper.list_of (function List xs -> Some xs | _ -> None) f
+let list_of_ocaml f = 
+  (* It must accept both [ a; b; c ] and a :: b :: c :: [] *)
+  let rec get_list revs = function
+    | List xs -> Some (List.rev_append revs xs)
+    | Variant ("[]", []) -> Some (List.rev revs)
+    | Variant ("::", [x; xs]) -> get_list (x::revs) xs
+    | _ -> None
+  in
+  Helper.list_of (get_list []) f
 
 let array_of_ocaml f = Helper.array_of (function Array xs -> Some xs | _ -> None) f