-
Notifications
You must be signed in to change notification settings - Fork 2
/
keystoml.ml
43 lines (40 loc) · 937 Bytes
/
keystoml.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
open Printf
let r_dash = Str.regexp " - ";;
let tabify s =
let dashpos = try Str.search_forward r_dash s 0 with Not_found -> -1 in
if dashpos < 1
then
s
else
let rec findnonwsback i =
if i = -1 then 0 else
if s.[i] = ' '
then findnonwsback (i-1)
else i
in
let nonwspos = findnonwsback dashpos in
if nonwspos = -1
then s
else
let b = Buffer.create 80 in
Buffer.add_substring b s 0 (nonwspos+1);
Buffer.add_char b '\t';
Buffer.add_substring b s (dashpos+1) (String.length s - dashpos - 1);
Buffer.contents b
;;
let lines =
let lines =
let rec fold accu =
match (try Some (input_line stdin) with _ -> None) with
| Some line -> fold (tabify line :: accu)
| None -> List.rev accu
in
fold []
in
lines
;;
let _ =
printf "let keys = [\n";
List.iter (fun l -> printf " %S;\n" l) lines;
printf "];;\n"
;;