about summary refs log tree commit diff
path: root/src/reporter/Reporter.ml
diff options
context:
space:
mode:
authorMalte Voos <git@mal.tc>2024-06-23 23:31:59 +0200
committerMalte Voos <git@mal.tc>2024-06-24 00:16:55 +0200
commit5d227bcd0055d02e1d49a3dcd27e80a756923d5b (patch)
treeda468ad3a8f3caf709b731ca2678c86a5a015990 /src/reporter/Reporter.ml
parent8d40541003736d5319ec981278338e8c8c66daf6 (diff)
downloadtoytt-5d227bcd0055d02e1d49a3dcd27e80a756923d5b.tar.gz
toytt-5d227bcd0055d02e1d49a3dcd27e80a756923d5b.zip
split code into smaller libraries and make a better repl
Diffstat (limited to 'src/reporter/Reporter.ml')
-rw-r--r--src/reporter/Reporter.ml40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/reporter/Reporter.ml b/src/reporter/Reporter.ml
new file mode 100644
index 0000000..ee04c23
--- /dev/null
+++ b/src/reporter/Reporter.ml
@@ -0,0 +1,40 @@
+module Message =
+struct
+  type t =
+    | IllegalCharacter
+    | SyntaxError
+    | UnboundVariable
+    | IllTyped
+    | CannotInferType
+    | Bug
+
+  let default_severity : t -> Asai.Diagnostic.severity =
+    function
+    | IllegalCharacter -> Error
+    | SyntaxError -> Error
+    | UnboundVariable -> Error
+    | IllTyped -> Error
+    | CannotInferType -> Error
+    | Bug -> Bug
+
+  let short_code : t -> string =
+    function
+    (* parser errors *)
+    | IllegalCharacter -> "E101"
+    | SyntaxError -> "E102"
+    (* elaboration errors *)
+    | UnboundVariable -> "E201"
+    | IllTyped -> "E202"
+    | CannotInferType -> "E202"
+    (* 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 expected_universe fmt x = fatalf IllTyped "expected a universe but got %a" fmt x
+
+let bug msg = fatalf Bug msg