about summary refs log tree commit diff
path: root/src/error
diff options
context:
space:
mode:
authorMalte Voos <git@mal.tc>2024-06-24 00:24:24 +0200
committerMalte Voos <git@mal.tc>2024-06-24 00:24:24 +0200
commitb34ebf3fe3ecaf292be873d231dd54c80f16ad07 (patch)
tree92e51250cf692fef97e7db310d244d1e3e7112a3 /src/error
parent5d227bcd0055d02e1d49a3dcd27e80a756923d5b (diff)
downloadtoytt-b34ebf3fe3ecaf292be873d231dd54c80f16ad07.tar.gz
toytt-b34ebf3fe3ecaf292be873d231dd54c80f16ad07.zip
rename: Reporter -> Error
Diffstat (limited to 'src/error')
-rw-r--r--src/error/Error.ml40
-rw-r--r--src/error/dune4
2 files changed, 44 insertions, 0 deletions
diff --git a/src/error/Error.ml b/src/error/Error.ml
new file mode 100644
index 0000000..ee04c23
--- /dev/null
+++ b/src/error/Error.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
diff --git a/src/error/dune b/src/error/dune
new file mode 100644
index 0000000..857f7bc
--- /dev/null
+++ b/src/error/dune
@@ -0,0 +1,4 @@
+(library
+ (name Error)
+ (public_name toytt.error)
+ (libraries asai toytt.ident))