module Message = struct type t = | FileError | IllegalCharacter | SyntaxError | UnboundVariable | TypeMismatch | NotInferable | Bug let default_severity : t -> Asai.Diagnostic.severity = function | FileError -> Error | IllegalCharacter -> Error | SyntaxError -> Error | UnboundVariable -> Error | TypeMismatch -> Error | NotInferable -> Error | Bug -> Bug let short_code : t -> string = function (* operating system errors *) | FileError -> "E101" (* parser errors *) | IllegalCharacter -> "E201" | SyntaxError -> "E202" (* elaboration errors *) | UnboundVariable -> "E301" | TypeMismatch -> "E302" | NotInferable -> "E303" (* misc *) | Bug -> "E900" end include Asai.Reporter.Make(Message) let file_open_error ~path ~msg = fatalf FileError "unable to open file '%s': %s" path msg 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 "@[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