about summary refs log tree commit diff
path: root/src/error/Error.ml
blob: 555d41cc9b2187f65a9980f0bcbaef5d9c81216d (plain)
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
45
46
47
module Message =
struct
  type t =
    | IllegalCharacter
    | SyntaxError
    | UnboundVariable
    | TypeMismatch
    | NotInferable
    | Bug

  let default_severity : t -> Asai.Diagnostic.severity =
    function
    | IllegalCharacter -> Error
    | SyntaxError -> Error
    | UnboundVariable -> Error
    | TypeMismatch -> Error
    | NotInferable -> Error
    | Bug -> Bug

  let short_code : t -> string =
    function
    (* parser errors *)
    | IllegalCharacter -> "E101"
    | SyntaxError -> "E102"
    (* elaboration errors *)
    | UnboundVariable -> "E201"
    | TypeMismatch -> "E202"
    | NotInferable -> "E203"
    (* misc *)
    | Bug -> "E900"
end

include Asai.Reporter.Make(Message)

let illegal_character ~loc char = fatalf ~loc IllegalCharacter
    "illegal character '%s'" (Char.escaped char)
let syntax_error ~loc = fatalf ~loc SyntaxError
    "syntax error"
let unbound_variable id = fatalf UnboundVariable
    "unbound variable '%a'" Ident.pp id
let type_mismatch ?loc fmt_expected expected fmt_found found = fatalf ?loc TypeMismatch
    "@[<v>type mismatch:@,expected: @[%a@]@,   found: @[%a@]@]"
    fmt_expected expected fmt_found found
let not_inferable () = fatalf NotInferable
    "cannot infer type"

let bug msg = fatalf Bug msg