diff options
| author | Your Name <agrawalshagun07@gmail.com> | 2025-03-16 14:53:45 +0530 |
|---|---|---|
| committer | Your Name <agrawalshagun07@gmail.com> | 2025-03-16 14:53:45 +0530 |
| commit | 277319fa392f5ee9f21eedf2c4d224739f045690 (patch) | |
| tree | f2e3a89de7946647d7560db242e7ce22fda25a5c /cljcc-compiler/src/cljcc/core/exception.cljc | |
| parent | 39b6930e14cfda58fd066805f5da447c685ab67f (diff) | |
Add common functions for handling cljcc compiler
Diffstat (limited to 'cljcc-compiler/src/cljcc/core/exception.cljc')
| -rw-r--r-- | cljcc-compiler/src/cljcc/core/exception.cljc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/cljcc-compiler/src/cljcc/core/exception.cljc b/cljcc-compiler/src/cljcc/core/exception.cljc new file mode 100644 index 0000000..19245aa --- /dev/null +++ b/cljcc-compiler/src/cljcc/core/exception.cljc @@ -0,0 +1,34 @@ +(ns cljcc.core.exception + (:require [cljcc.core.format :refer [safe-format]])) + +(defn try-catch-ex + ([f] + (try + (f) + (catch #?(:clj Throwable :cljs :default) e + [:error e]))) + ([f default] + (try + (f) + (catch #?(:clj Throwable :cljs :default) e + default)))) + +(defn lex-error [{line :line col :col :as data}] + (throw (ex-info + (safe-format "Invalid token at line: %s, col: %s." line col) + (merge {:error/type :lexer} data)))) + +(defn parser-error [msg data] + (throw (ex-info msg (merge {:error/type :parser} data)))) + +(defn analyzer-error [msg data] + (throw (ex-info msg (merge {:error/type :analyzer} data)))) + +(defn tacky-error [msg data] + (throw (ex-info msg (merge {:error/type :tacky} data)))) + +(defn compiler-error [msg data] + (throw (ex-info msg (merge {:error/type :compiler} data)))) + +(defn emit-error [msg data] + (throw (ex-info msg (merge {:error/type :emit} data)))) |
