-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPPP_CSV.ml
27 lines (21 loc) · 917 Bytes
/
PPP_CSV.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(* This parser just output everything in a sequence of values separated by
* pipes. This is obviously not conserving most of structures so suitable only
* for very simple data. *)
include PPP.Ops
let unit : unit PPP.t = cst ""
let tuple_open = ""
let tuple_close = "\n"
let tuple_sep = "|"
let list (ppp : 'a PPP.t) : 'a list PPP.t =
PPP.seq "list" "" "" tuple_sep List.fold_left List.rev ppp
(*$= list
(Ok ([1;2;3], 6)) (PPP.of_string (list int) "1|2|3\n" 0)
*)
let array (ppp : 'a PPP.t) : 'a array PPP.t =
PPP.seq "array" "" "" tuple_sep Array.fold_left (fun l -> Array.of_list (List.rev l)) ppp
let pair (p1 : 'a PPP.t) (p2 : 'b PPP.t) : ('a * 'b) PPP.t =
p1 +- cst tuple_sep ++ p2
let triple (p1 : 'a PPP.t) (p2 : 'b PPP.t) (p3 : 'c PPP.t) : ('a * 'b * 'c) PPP.t =
p1 +- cst tuple_sep ++ p2 +- cst tuple_sep ++ p3 >>:
((fun (v1,v2,v3) -> (v1,v2),v3),
(fun ((v1,v2),v3) -> v1,v2,v3))