forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbspp_main.ml
44 lines (38 loc) · 1007 Bytes
/
bspp_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
37
38
39
40
41
42
43
44
(*let buffer_intervals (intervals : (int * int) list) buf ic oc =
intervals
|> List.iter
(fun (start, stop) ->
let len = stop - start in
if len <> 0 then
begin
seek_in ic start ;
Buffer.add_channel buf ic len ;
Buffer.output_buffer oc buf ;
Buffer.clear buf;
end
)*)
let preprocess fn oc =
let ic = open_in_bin fn in
let lexbuf = Lexing.from_channel ic in
let buf = Buffer.create 4096 in
Location.init lexbuf fn;
Lexer.init ();
lexbuf
|> Lexer.filter_directive_from_lexbuf
(* Get a list of segments
TODO: output line directive
*)
|> List.iter
(fun (start, stop) ->
let len = stop - start in
if len <> 0 then
begin
seek_in ic start ;
Buffer.add_channel buf ic len ;
Buffer.output_buffer oc buf ;
Buffer.clear buf;
end
);
close_in ic
let () =
preprocess Sys.argv.(1) stdout