Refactor
[llpp.git] / keystoml.ml
blob5fe80708a800839c8e9ad958d7905063a72f2a03
1 open Printf
3 let r_dash = Str.regexp " - ";;
4 let tabify s =
5 let dashpos = try Str.search_forward r_dash s 0 with Not_found -> -1 in
6 if dashpos < 1
7 then
9 else
10 let rec findnonwsback i =
11 if i = -1 then 0 else
12 if s.[i] = ' '
13 then findnonwsback (i-1)
14 else i
16 let nonwspos = findnonwsback dashpos in
17 if nonwspos = -1
18 then s
19 else
20 let b = Buffer.create 80 in
21 Buffer.add_substring b s 0 (nonwspos+1);
22 Buffer.add_char b '\t';
23 Buffer.add_substring b s (dashpos+1) (String.length s - dashpos - 1);
24 Buffer.contents b
27 let lines =
28 let lines =
29 let rec fold accu =
30 match (try Some (input_line stdin) with _ -> None) with
31 | Some line -> fold (tabify line :: accu)
32 | None -> List.rev accu
34 fold []
36 lines
39 let _ =
40 printf "let keys = [\n";
41 List.iter (fun l -> printf " %S;\n" l) lines;
42 printf "];;\n"