├── .gitignore ├── test ├── defns │ ├── exportAssignment.d.ts │ ├── module.d.ts │ ├── enum.d.ts │ ├── extmodule.d.ts │ ├── importDecls.d.ts │ ├── interface.d.ts │ ├── ambient.d.ts │ └── decls.d.ts ├── collapsed.png ├── expanded.png ├── jsoo │ ├── index.html │ └── test_lib.ml ├── interface_index.ts ├── makefile ├── index.html ├── index.css ├── test.ts ├── jsserver.ml └── test_ml.ml ├── .merlin ├── src ├── unit_tests.mli ├── print.mli ├── DefinitelyMaybeTyped.mldylib ├── DefinitelyMaybeTyped.mllib ├── DefinitelyMaybeTyped.mlpack ├── summary.mli ├── ts.ml ├── convert.mli ├── META ├── parser.mli ├── summary.ml ├── ast.mli ├── convert.ml ├── print.ml ├── unit_tests.ml └── parser.ml ├── .ocamlinit ├── README.md ├── _oasis ├── Makefile ├── _tags ├── app └── otypescript.ml └── myocamlbuild.ml /.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | *~ 3 | .*.swp 4 | -------------------------------------------------------------------------------- /test/defns/exportAssignment.d.ts: -------------------------------------------------------------------------------- 1 | export = an_identifier; 2 | 3 | -------------------------------------------------------------------------------- /test/defns/module.d.ts: -------------------------------------------------------------------------------- 1 | declare module A.b.c { 2 | var a; 3 | } 4 | -------------------------------------------------------------------------------- /.merlin: -------------------------------------------------------------------------------- 1 | S src 2 | S test 3 | B _build 4 | PKG js_of_ocaml 5 | EXT js 6 | -------------------------------------------------------------------------------- /src/unit_tests.mli: -------------------------------------------------------------------------------- 1 | val test_typescript : OUnit.test 2 | val run : unit -> unit 3 | 4 | -------------------------------------------------------------------------------- /test/defns/enum.d.ts: -------------------------------------------------------------------------------- 1 | export declare enum Yo { 2 | red=0, 3 | green=1, 4 | blue 5 | } 6 | -------------------------------------------------------------------------------- /test/collapsed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewray/DefinitelyMaybeTyped/HEAD/test/collapsed.png -------------------------------------------------------------------------------- /test/expanded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewray/DefinitelyMaybeTyped/HEAD/test/expanded.png -------------------------------------------------------------------------------- /src/print.mli: -------------------------------------------------------------------------------- 1 | module Make(O : sig val out : string -> unit end) : sig 2 | val print_ast : Ast.declarationElement list option -> unit 3 | end 4 | -------------------------------------------------------------------------------- /src/DefinitelyMaybeTyped.mldylib: -------------------------------------------------------------------------------- 1 | # OASIS_START 2 | # DO NOT EDIT (digest: 0deb74a2c4fbfc8c156a31215cfe3c31) 3 | DefinitelyMaybeTyped 4 | # OASIS_STOP 5 | -------------------------------------------------------------------------------- /src/DefinitelyMaybeTyped.mllib: -------------------------------------------------------------------------------- 1 | # OASIS_START 2 | # DO NOT EDIT (digest: 0deb74a2c4fbfc8c156a31215cfe3c31) 3 | DefinitelyMaybeTyped 4 | # OASIS_STOP 5 | -------------------------------------------------------------------------------- /src/DefinitelyMaybeTyped.mlpack: -------------------------------------------------------------------------------- 1 | # OASIS_START 2 | # DO NOT EDIT (digest: 05d809dd74be8ef27c0066451d061b51) 3 | Ast 4 | Ts 5 | Parser 6 | Print 7 | Summary 8 | Convert 9 | Unit_tests 10 | # OASIS_STOP 11 | -------------------------------------------------------------------------------- /src/summary.mli: -------------------------------------------------------------------------------- 1 | module type S = sig 2 | val ast : Ast.declarationElement list option -> unit 3 | end 4 | 5 | module Make(Show : sig 6 | val show : int -> string -> string -> unit 7 | end) : S 8 | 9 | module Print : S 10 | -------------------------------------------------------------------------------- /test/defns/extmodule.d.ts: -------------------------------------------------------------------------------- 1 | export = a; 2 | import a = require("b"); 3 | 4 | declare module "test" { 5 | 6 | var a : b; 7 | function a(b:c):d; 8 | 9 | import hello = require("balloon"); // stray semi 10 | 11 | export = toto; 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/ts.ml: -------------------------------------------------------------------------------- 1 | (* hacks *) 2 | type typeReference 3 | type typeQuery 4 | type typeLiteral 5 | 6 | (* predefined types *) 7 | type any = Js.Unsafe.any 8 | type number = float 9 | type string = Js.js_string Js.t 10 | type boolean = bool Js.t 11 | type void = unit 12 | -------------------------------------------------------------------------------- /test/jsoo/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |" ^ t ^ " " ^ n ^ "");
75 | Dom.appendChild parent il;
76 | build_list parent il level tl
77 | end else if level < l then begin
78 | (* create new ul, add it to prev, recurse *)
79 | let ul = Dom_html.createUl doc in
80 | Dom.appendChild prev ul;
81 | let elements = build_list ul ul (level+1) elements in
82 | build_list parent prev level elements
83 | end else
84 | (* drop back a level *)
85 | elements
86 | in
87 | let ul = Dom_html.createUl doc in
88 | ul##id <- Js.string "expList";
89 | Dom.appendChild div ul;
90 | let _ = build_list ul ul 0 elements in
91 | Js.Unsafe.fun_call (Js.Unsafe.variable "window.prepareList") [||] |> ignore
92 |
93 | let main _ =
94 | let () = init () in
95 | let () = summary() in
96 | let vec = jsnew vec(3,4) in
97 | let () = vec##add(2) in
98 | Js._true
99 |
100 | let _ = Dom_html.window##onload <- Dom_html.handler main
101 |
102 |
103 |
--------------------------------------------------------------------------------
/app/otypescript.ml:
--------------------------------------------------------------------------------
1 |
2 | (********************************************************************************)
3 | (* file utilities *)
4 |
5 | let rec readall path =
6 | let open Unix in
7 | let h = opendir path in
8 | let rec read () =
9 | match try Some(readdir h) with _ -> None with
10 | | None -> []
11 | | Some(x) when x<>"." && x<>".." -> (Filename.concat path x)::read()
12 | | _ -> read()
13 | in
14 | let all = read() in
15 | closedir h;
16 | all
17 |
18 | let rec findall path =
19 | let open Unix in
20 | let all = readall path in
21 | (* partition into sub-dirs and .d.ts files *)
22 | let rec classify dirs dts = function
23 | | [] -> dirs, dts
24 | | h::t ->
25 | match (stat h).st_kind with
26 | | S_DIR -> classify (h::dirs) dts t
27 | | S_REG when Filename.check_suffix h ".d.ts" -> classify dirs (h::dts) t
28 | | _ -> classify dirs dts t
29 | in
30 | let dirs, dts = classify [] [] all in
31 | List.fold_left (fun dts dir -> dts @ findall dir) dts dirs
32 |
33 | let preprocess input_name =
34 | let base = Filename.basename input_name in
35 | let output_name = Filename.concat "dump" base in
36 | let command = "cpp -P " ^ input_name ^ " " ^ output_name in
37 | Printf.printf "%s\n%!" command;
38 | Unix.system command |> ignore
39 |
40 | let with_file_in name f =
41 | let file = open_in name in
42 | try
43 | let r = f file in
44 | close_in file;
45 | r
46 | with x ->
47 | close_in file;
48 | raise x
49 |
50 | let with_file_out name f =
51 | let file = open_out name in
52 | try
53 | let r = f file in
54 | close_out file;
55 | r
56 | with x ->
57 | close_out file;
58 | raise x
59 |
60 | (********************************************************************************)
61 | (* command line *)
62 |
63 | let parse_file ?(verbose=false) name =
64 | let ast = with_file_in name (Parser.parse ~verbose:true name) in
65 | (*(if verbose then output_string stdout (Parser.to_string ast)
66 | else Summary.ast ast);*)
67 | (*Summary.Print.ast ast;*)
68 | let () =
69 | let module P = Print.Make(struct let out = print_string end) in
70 | P.print_ast ast
71 | in
72 | let base = Filename.(chop_suffix (basename name) ".d.ts") in
73 | let marshal = base ^ ".m" in
74 | let ml = base ^ ".ml" in
75 | (* marshalled ast *)
76 | (with_file_out marshal Marshal.(fun f -> to_channel f ast []));
77 | (* output ml file *)
78 | (with_file_out ml
79 | (fun f ->
80 | match ast with
81 | | None -> ()
82 | | Some(ast) -> Convert.convert (output_string f) ast))
83 |
84 | let parse_dir dir =
85 | let open Printf in
86 | let pass, fail, exn = ref 0, ref 0, ref 0 in
87 | List.iter
88 | (fun name ->
89 | try
90 | match with_file_in name (Parser.parse name) with
91 | | Some(x) -> begin
92 | printf "pass: %s\n%!" name;
93 | incr pass
94 | end
95 | | None -> begin
96 | printf "fail: %s\n%!" name;
97 | incr fail
98 | end
99 | with _ -> begin
100 | Printf.printf "exn : %s\n%!" name;
101 | incr exn;
102 | end)
103 | (findall dir);
104 | Printf.printf "pass=%i fail=%i exn=%i\n" !pass !fail !exn
105 |
106 | let () =
107 | let open Arg in
108 | parse (align [
109 | "-i", String(parse_file), "