Remove duplicate error messages.

This commit is contained in:
Scott Richmond 2023-12-17 23:16:12 -05:00
parent 53b71fe790
commit 4e646101e2

View File

@ -818,16 +818,16 @@
(defn- interpret-literal [ast] (-> ast :data first))
(defn- interpret-panic [ast ctx]
(let [msg-value (interpret-ast (:data ast) ctx)
(let [msg-value (interpret-ast (-> ast :data first) ctx)
msg-string (show/show msg-value)]
(throw (ex-info (str "Ludus panicked: " msg-string) {:ast ast}))))
(throw (ex-info msg-string {:ast ast}))))
(defn interpret-ast [ast ctx]
(case (:type ast)
(:nil :true :false :number :string :keyword) (interpret-literal ast)
:panic! (interpret-panic ast ctx)
:panic (interpret-panic ast ctx)
:let-expr (interpret-let ast ctx)
@ -893,7 +893,7 @@
; :struct-literal
; (interpret-struct ast ctx)
(throw (ex-info (str "Unknown AST node type " (get ast :type :err) " on line " (get-in ast [:token :line])) {:ast ast}))))
(throw (ex-info (str "Unknown AST node type " (get ast :type :none) " on line " (get-in ast [:token :line])) {:ast ast}))))
(defn get-line [source line]
(if line
@ -984,24 +984,35 @@
:message (ex-message e)}
))))
; No prelude; helps when there are errors in the prelude
(defn interpret-bare [source parsed ctx]
(let [base-ctx (volatile! {::parent (volatile! ctx)})]
(try
(interpret-ast parsed base-ctx)
(catch Throwable e
{::data/error true
:line (get-in (ex-data e) [:ast :token :line])
:message (ex-message e)}))))
;; repl
(comment
(do
(println "***********")
(def source "
let times = 1.3
repeat times { print! (:foo) }
panic! (:oh, :no)
")
(def tokens (-> source scanner/scan :tokens))
(def ast (p/apply-parser g/script tokens))
(def result (interpret-safe source ast {}))
(def result (interpret-bare source ast {}))
;(-> ast prettify-ast println)
(println tokens)
(-> ast prettify-ast println)
(println result)