forked from esumii/min-caml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanchor.ml
22 lines (20 loc) · 802 Bytes
/
anchor.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let re = Str.regexp "\\([(\\/]\\)\\* \\(.*\\) (caml2html: \\([a-zA-Z0-9_]+\\)) \\*\\([)\\/]\\)"
let rec loop previous_lines =
try
let current_line = read_line () in
let new_line =
try
ignore (Str.search_forward re current_line 0);
let comment = Str.matched_group 2 current_line in
let anchor = Str.matched_group 3 current_line in
Printf.printf "<a name=\"%s\"></a>" anchor;
Str.global_replace re "\\1* \\2 *\\4" current_line
with Not_found -> current_line in
if List.length previous_lines < 3 then
loop (previous_lines @ [new_line])
else begin
print_endline (List.hd previous_lines);
loop (List.tl previous_lines @ [new_line])
end
with End_of_file -> List.iter print_endline previous_lines
let _ = loop []