File: test_toplevel.ml

package info (click to toggle)
js-of-ocaml 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 37,932 kB
  • sloc: ml: 135,957; javascript: 58,364; ansic: 437; makefile: 422; sh: 12; perl: 4
file content (25 lines) | stat: -rw-r--r-- 630 bytes parent folder | download | duplicates (3)
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
let () =
  let content =
    {|
let () = print_endline "hello";;
1+1;;
1+;;
Missing_module.f;;
let y = float 1 /. float 3;;
|}
  in
  Topdirs.dir_directory "/static/cmis";
  Toploop.initialize_toplevel_env ();
  Toploop.input_name := "//toplevel//";
  let lexbuf = Lexing.from_string content in
  while true do
    try
      Location.reset ();
      let phr = !Toploop.parse_toplevel_phrase lexbuf in
      let res = Toploop.execute_phrase true Format.std_formatter phr in
      flush_all ();
      if not res then raise Exit
    with
    | End_of_file -> exit 0
    | x -> Location.report_exception Format.std_formatter x
  done