comparison tools/prepare_spellcheck.ml @ 571:3fc43e261f67

Spacing and indentation fixes in tools, from Chen Yiwu
author Adam Chlipala <adam@chlipala.net>
date Sun, 21 Apr 2019 16:09:55 -0400
parents 6833a1b778c0
children
comparison
equal deleted inserted replaced
570:c3d4217e1da7 571:3fc43e261f67
1 let read_line () = 1 let read_line () =
2 try 2 try
3 Some (read_line ()) 3 Some (read_line ())
4 with End_of_file -> None 4 with End_of_file -> None
5 5
6 let strstr' p s n = 6 let strstr' p s n =
15 let sanitize s = 15 let sanitize s =
16 let rec san n acc = 16 let rec san n acc =
17 try 17 try
18 let pos = Str.search_forward (Str.regexp "\\[\\|%\\|#") s n in 18 let pos = Str.search_forward (Str.regexp "\\[\\|%\\|#") s n in
19 let ender = match s.[pos] with 19 let ender = match s.[pos] with
20 | '[' -> ']' 20 | '[' -> ']'
21 | _ -> s.[pos] in 21 | _ -> s.[pos] in
22 let pos' = String.index_from s (pos+1) ender in 22 let pos' = String.index_from s (pos+1) ender in
23 san (pos'+1) (acc ^ String.sub s n (pos-n)) 23 san (pos'+1) (acc ^ String.sub s n (pos-n))
24 with Not_found -> acc ^ Str.string_after s n 24 with Not_found -> acc ^ Str.string_after s n
25 in san 0 "" 25 in san 0 ""
26 26
27 let rec initial () = 27 let rec initial () =
28 match read_line () with 28 match read_line () with
29 | None -> () 29 | None -> ()
30 | Some line -> 30 | Some line ->
31 match strstr "(**" line with 31 match strstr "(**" line with
32 | None -> initial () 32 | None -> initial ()
33 | Some pos -> 33 | Some pos ->
34 match strstr "*)" line with 34 match strstr "*)" line with
35 | None -> 35 | None ->
36 begin match strstr "[[" line with 36 begin match strstr "[[" line with
37 | None -> 37 | None ->
38 print_endline (sanitize (Str.string_after line (pos+3))); 38 print_endline (sanitize (Str.string_after line (pos+3)));
39 comment () 39 comment ()
40 | Some _ -> runTo "]]" 40 | Some _ -> runTo "]]"
41 end 41 end
42 | Some pos' -> 42 | Some pos' ->
43 let rest = Str.string_after line (pos+3) in 43 let rest = Str.string_after line (pos+3) in
44 if not (prefix " printing" rest || prefix " begin" rest || prefix " end" rest) then 44 if not (prefix " printing" rest || prefix " begin" rest || prefix " end" rest) then
45 print_endline (sanitize (String.sub line (pos+3) (pos' - (pos+3)))); 45 print_endline (sanitize (String.sub line (pos+3) (pos' - (pos+3))));
46 initial () 46 initial ()
47 47
48 and comment () = 48 and comment () =
49 match read_line () with 49 match read_line () with
50 | None -> () 50 | None -> ()
51 | Some line -> 51 | Some line ->
52 match strstr "*)" line with 52 match strstr "*)" line with
53 | None -> 53 | None ->
54 begin match strstr "[[" line with 54 begin match strstr "[[" line with
55 | None -> 55 | None ->
56 begin match strstr "<<" line with 56 begin match strstr "<<" line with
57 | None -> 57 | None ->
58 print_endline (sanitize line); 58 print_endline (sanitize line);
59 comment () 59 comment ()
60 | Some _ -> runTo ">>" 60 | Some _ -> runTo ">>"
61 end 61 end
62 | Some _ -> runTo "]]" 62 | Some _ -> runTo "]]"
63 end 63 end
64 | Some pos -> 64 | Some pos ->
65 print_endline (sanitize (Str.string_before line pos)); 65 print_endline (sanitize (Str.string_before line pos));
66 initial () 66 initial ()
67 67
68 and runTo ender = 68 and runTo ender =
69 match read_line () with 69 match read_line () with
70 | None -> () 70 | None -> ()
71 | Some line -> 71 | Some line ->
72 match strstr ender line with 72 match strstr ender line with
73 | None -> runTo ender 73 | None -> runTo ender
74 | _ -> 74 | _ ->
75 match strstr "*)" line with 75 match strstr "*)" line with
76 | None -> comment () 76 | None -> comment ()
77 | _ -> initial () 77 | _ -> initial ()
78 78
79 let () = initial () 79 let () = initial ()