package archetype

  1. Overview
  2. Docs

Source file error.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
let flag = ref `Raise

let exit_on_error () = flag := `Exit

let raise_on_error () = flag := `Raise

let resume_on_error () = flag := `Resume

let errors = ref []

exception Error of Position.t list * string

exception ParseError of (Position.t list * string) list

let print_error positions msg =
  Printf.sprintf "%s%s\n"
    (String.concat "\n"
       (List.map (fun p -> Position.string_of_pos p ^": ") positions))
    msg

let error_alert positions msg continue =
  output_string stderr (print_error positions msg);
  match !flag with
  | `Exit -> exit 1
  | `Raise -> raise (Error (positions, msg))
  | `Resume -> errors := (positions, msg)::!errors; continue ()

let global_error kind msg =
  error_alert [] (Printf.sprintf "Global Error (%s)\n  %s"  kind msg)

let errorN kind poss msg =
  error_alert poss (Printf.sprintf "Error (%s)\n  %s" kind msg)

let error kind pos = errorN kind [pos]
let error2 kind pos1 pos2 = errorN kind [pos1; pos2]
OCaml

Innovation. Community. Security.