|
1 |
| -(** Bundled by ocamlpack 08/11-09:12 *) |
| 1 | +(** Bundled by ocamlpack 08/11-09:55 *) |
2 | 2 | module String_map : sig
|
3 | 3 | #1 "string_map.mli"
|
4 | 4 | (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
|
@@ -1853,7 +1853,8 @@ module Ext_pervasives : sig
|
1853 | 1853 | *)
|
1854 | 1854 |
|
1855 | 1855 | external reraise: exn -> 'a = "%reraise"
|
1856 |
| -val finally : 'a -> ('a -> 'b) -> ('a -> 'c) -> 'b |
| 1856 | + |
| 1857 | +val finally : 'a -> ('a -> 'c) -> ('a -> 'b) -> 'b |
1857 | 1858 |
|
1858 | 1859 | val with_file_as_chan : string -> (out_channel -> 'a) -> 'a
|
1859 | 1860 |
|
@@ -1905,26 +1906,24 @@ end = struct
|
1905 | 1906 |
|
1906 | 1907 | external reraise: exn -> 'a = "%reraise"
|
1907 | 1908 |
|
1908 |
| -let finally v f action = |
| 1909 | +let finally v action f = |
1909 | 1910 | match f v with
|
1910 | 1911 | | exception e ->
|
1911 | 1912 | action v ;
|
1912 | 1913 | reraise e
|
1913 | 1914 | | e -> action v ; e
|
1914 | 1915 |
|
1915 | 1916 | let with_file_as_chan filename f =
|
1916 |
| - let chan = open_out filename in |
1917 |
| - finally chan f close_out |
| 1917 | + finally (open_out filename) close_out f |
1918 | 1918 |
|
1919 | 1919 | let with_file_as_pp filename f =
|
1920 |
| - let chan = open_out filename in |
1921 |
| - finally chan |
| 1920 | + finally (open_out filename) close_out |
1922 | 1921 | (fun chan ->
|
1923 | 1922 | let fmt = Format.formatter_of_out_channel chan in
|
1924 | 1923 | let v = f fmt in
|
1925 | 1924 | Format.pp_print_flush fmt ();
|
1926 | 1925 | v
|
1927 |
| - ) close_out |
| 1926 | + ) |
1928 | 1927 |
|
1929 | 1928 |
|
1930 | 1929 | let is_pos_pow n =
|
@@ -8969,6 +8968,83 @@ let reset () =
|
8969 | 8968 | let undefined = create_js "undefined"
|
8970 | 8969 | let nil = create_js "null"
|
8971 | 8970 |
|
| 8971 | +end |
| 8972 | +module Ext_io : sig |
| 8973 | +#1 "ext_io.mli" |
| 8974 | +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. |
| 8975 | + * |
| 8976 | + * This program is free software: you can redistribute it and/or modify |
| 8977 | + * it under the terms of the GNU Lesser General Public License as published by |
| 8978 | + * the Free Software Foundation, either version 3 of the License, or |
| 8979 | + * (at your option) any later version. |
| 8980 | + * |
| 8981 | + * In addition to the permissions granted to you by the LGPL, you may combine |
| 8982 | + * or link a "work that uses the Library" with a publicly distributed version |
| 8983 | + * of this file to produce a combined library or application, then distribute |
| 8984 | + * that combined work under the terms of your choosing, with no requirement |
| 8985 | + * to comply with the obligations normally placed on you by section 4 of the |
| 8986 | + * LGPL version 3 (or the corresponding section of a later version of the LGPL |
| 8987 | + * should you choose to use a later version). |
| 8988 | + * |
| 8989 | + * This program is distributed in the hope that it will be useful, |
| 8990 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8991 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 8992 | + * GNU Lesser General Public License for more details. |
| 8993 | + * |
| 8994 | + * You should have received a copy of the GNU Lesser General Public License |
| 8995 | + * along with this program; if not, write to the Free Software |
| 8996 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) |
| 8997 | + |
| 8998 | +val load_file : string -> string |
| 8999 | + |
| 9000 | +val rev_lines_of_file : string -> string list |
| 9001 | + |
| 9002 | +end = struct |
| 9003 | +#1 "ext_io.ml" |
| 9004 | +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. |
| 9005 | + * |
| 9006 | + * This program is free software: you can redistribute it and/or modify |
| 9007 | + * it under the terms of the GNU Lesser General Public License as published by |
| 9008 | + * the Free Software Foundation, either version 3 of the License, or |
| 9009 | + * (at your option) any later version. |
| 9010 | + * |
| 9011 | + * In addition to the permissions granted to you by the LGPL, you may combine |
| 9012 | + * or link a "work that uses the Library" with a publicly distributed version |
| 9013 | + * of this file to produce a combined library or application, then distribute |
| 9014 | + * that combined work under the terms of your choosing, with no requirement |
| 9015 | + * to comply with the obligations normally placed on you by section 4 of the |
| 9016 | + * LGPL version 3 (or the corresponding section of a later version of the LGPL |
| 9017 | + * should you choose to use a later version). |
| 9018 | + * |
| 9019 | + * This program is distributed in the hope that it will be useful, |
| 9020 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9021 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 9022 | + * GNU Lesser General Public License for more details. |
| 9023 | + * |
| 9024 | + * You should have received a copy of the GNU Lesser General Public License |
| 9025 | + * along with this program; if not, write to the Free Software |
| 9026 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) |
| 9027 | + |
| 9028 | + |
| 9029 | +(** on 32 bit , there are 16M limitation *) |
| 9030 | +let load_file f = |
| 9031 | + Ext_pervasives.finally (open_in f) close_in begin fun ic -> |
| 9032 | + let n = in_channel_length ic in |
| 9033 | + let s = Bytes.create n in |
| 9034 | + really_input ic s 0 n; |
| 9035 | + Bytes.unsafe_to_string s |
| 9036 | + end |
| 9037 | + |
| 9038 | + |
| 9039 | +let rev_lines_of_file file = |
| 9040 | + Ext_pervasives.finally (open_in file) close_in begin fun chan -> |
| 9041 | + let rec loop acc = |
| 9042 | + match input_line chan with |
| 9043 | + | line -> loop (line :: acc) |
| 9044 | + | exception End_of_file -> close_in chan ; acc in |
| 9045 | + loop [] |
| 9046 | + end |
| 9047 | + |
8972 | 9048 | end
|
8973 | 9049 | module Ext_map : sig
|
8974 | 9050 | #1 "ext_map.mli"
|
@@ -9400,7 +9476,7 @@ let group t i action =
|
9400 | 9476 | else
|
9401 | 9477 | let old = t.indent_level in
|
9402 | 9478 | t.indent_level <- t.indent_level + i;
|
9403 |
| - Ext_pervasives.finally () action (fun _ -> t.indent_level <- old) |
| 9479 | + Ext_pervasives.finally () (fun _ -> t.indent_level <- old) action |
9404 | 9480 |
|
9405 | 9481 | let vgroup = group
|
9406 | 9482 |
|
@@ -33384,114 +33460,3 @@ let builtin_modules =
|
33384 | 33460 | ]
|
33385 | 33461 |
|
33386 | 33462 | end
|
33387 |
| -module Line_process : sig |
33388 |
| -#1 "line_process.mli" |
33389 |
| - |
33390 |
| - |
33391 |
| -(** Given a filename return a list of modules *) |
33392 |
| -val read_lines : string -> string -> string list |
33393 |
| -val load_file : string -> string |
33394 |
| - |
33395 |
| -end = struct |
33396 |
| -#1 "line_process.ml" |
33397 |
| - |
33398 |
| -(* let lexer = Genlex.make_lexer [] (\* poor man *\) *) |
33399 |
| - |
33400 |
| -(* let rec to_list acc stream = *) |
33401 |
| -(* match Stream.next stream with *) |
33402 |
| -(* | exception _ -> List.rev acc *) |
33403 |
| -(* | v -> to_list (v::acc) stream *) |
33404 |
| - |
33405 |
| - |
33406 |
| -let rev_lines_of_file file = |
33407 |
| - let chan = open_in file in |
33408 |
| - let rec loop acc = |
33409 |
| - match input_line chan with |
33410 |
| - | line -> loop (line :: acc) |
33411 |
| - | exception End_of_file -> close_in chan ; acc in |
33412 |
| - loop [] |
33413 |
| - |
33414 |
| - |
33415 |
| -let rec filter_map (f: 'a -> 'b option) xs = |
33416 |
| - match xs with |
33417 |
| - | [] -> [] |
33418 |
| - | y :: ys -> |
33419 |
| - begin match f y with |
33420 |
| - | None -> filter_map f ys |
33421 |
| - | Some z -> z :: filter_map f ys |
33422 |
| - end |
33423 |
| - |
33424 |
| - |
33425 |
| -(** on 32 bit , there are 16M limitation *) |
33426 |
| -let load_file f = |
33427 |
| - let ic = open_in f in |
33428 |
| - let n = in_channel_length ic in |
33429 |
| - let s = Bytes.create n in |
33430 |
| - really_input ic s 0 n; |
33431 |
| - close_in ic; |
33432 |
| - Bytes.unsafe_to_string s |
33433 |
| - |
33434 |
| -let (@>) (b, v) acc = |
33435 |
| - if b then |
33436 |
| - v :: acc |
33437 |
| - else |
33438 |
| - acc |
33439 |
| - |
33440 |
| - |
33441 |
| -let (//) = Filename.concat |
33442 |
| - |
33443 |
| -let rec process_line cwd filedir line = |
33444 |
| - let line = Ext_string.trim line in |
33445 |
| - let len = String.length line in |
33446 |
| - if len = 0 then [] |
33447 |
| - else |
33448 |
| - match line.[0] with |
33449 |
| - | '#' -> [] |
33450 |
| - | _ -> |
33451 |
| - let segments = |
33452 |
| - Ext_string.split_by ~keep_empty:false (fun x -> x = ' ' || x = '\t' ) line |
33453 |
| - in |
33454 |
| - |
33455 |
| - begin |
33456 |
| - match segments with |
33457 |
| - | ["include" ; path ] |
33458 |
| - -> |
33459 |
| - (* prerr_endline path; *) |
33460 |
| - read_lines cwd (filedir// path) |
33461 |
| - | [ x ] -> |
33462 |
| - let ml = filedir // x ^ ".ml" in |
33463 |
| - let mli = filedir // x ^ ".mli" in |
33464 |
| - let ml_exists, mli_exists = Sys.file_exists ml , Sys.file_exists mli in |
33465 |
| - if not ml_exists && not mli_exists then |
33466 |
| - begin |
33467 |
| - prerr_endline (filedir //x ^ " not exists"); |
33468 |
| - [] |
33469 |
| - end |
33470 |
| - else |
33471 |
| - (ml_exists, ml) @> (mli_exists , mli) @> [] |
33472 |
| - |
33473 |
| - | _ |
33474 |
| - -> Ext_pervasives.failwithf ~loc:__LOC__ "invalid line %s" line |
33475 |
| - end |
33476 |
| - |
33477 |
| -(* example |
33478 |
| - {[ |
33479 |
| - Line_process.read_lines "." "./tools/tools.mllib" |
33480 |
| - ]} |
33481 |
| - |
33482 |
| - FIXME: we can only concat (dir/file) not (dir/dir) |
33483 |
| - {[ |
33484 |
| - Filename.concat "/bb/x/" "/bb/x/";; |
33485 |
| - ]} |
33486 |
| -*) |
33487 |
| -and read_lines cwd file = |
33488 |
| - |
33489 |
| - file |
33490 |
| - |> rev_lines_of_file |
33491 |
| - |> List.fold_left (fun acc f -> |
33492 |
| - let filedir = Filename.dirname file in |
33493 |
| - let extras = process_line cwd filedir f in |
33494 |
| - extras @ acc |
33495 |
| - ) [] |
33496 |
| - |
33497 |
| -end |
0 commit comments