-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ml
36 lines (33 loc) · 855 Bytes
/
main.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
let lexbuf outchan str =
(*Printf.printf "%s\n" str;*)
Syntax.counter := 0;
let ast = Parser.parse str in
(*Format.printf "%a@." show_e ast;*)
Emit.f outchan (ast)
let read_all inchan =
let lines = ref [] in
try
while true; do
lines := input_line inchan :: !lines
done;
""
with
| e -> String.concat "\n" (List.rev !lines)
let file f =
let inchan = open_in (f ^ ".ml") in
let outchan = open_out (f ^ ".js") in
try
lexbuf outchan (read_all inchan);
close_in inchan;
close_out outchan;
with e -> (close_in inchan; close_out outchan; raise e)
let () =
let files = ref [] in
Arg.parse
[]
(fun s -> files := !files @ [s])
("Min-Caml-JS Compiler\n" ^
Printf.sprintf "usage: %s ...filenames without \".ml\"..." Sys.argv.(0));
List.iter
(fun f -> ignore (file f))
!files