improve errors, a bit
This commit is contained in:
parent
1841915d92
commit
aa5795e168
|
@ -78,27 +78,51 @@
|
|||
(def {:line line-num :source source :input input :start start} (get-in e [:node :token]))
|
||||
(def source-line (get-line source line-num))
|
||||
(print " on line " line-num " in " input ", ")
|
||||
(print " binding " (b/show (e :value)))
|
||||
(print " matching: " (b/show (e :value)))
|
||||
(def pattern (get-in e [:node :data 0]))
|
||||
(print " to " (b/show-patt pattern))
|
||||
(print " with pattern: " (b/show-patt pattern))
|
||||
(print " >>> " source-line)
|
||||
(print (caret source line-num start))
|
||||
e)
|
||||
|
||||
(defn- match-no-match [e]
|
||||
(print "Ludus panicked! no match")
|
||||
(def {:line line-num :source source :input input :start start} (get-in e [:node :token]))
|
||||
(print " on line " line-num " in " input ", ")
|
||||
(def value (e :value))
|
||||
(print " matching: " (b/show value))
|
||||
(print " with patterns:")
|
||||
(def clauses (get-in e [:node :data 1]))
|
||||
(def patterns (b/pretty-patterns {:body clauses}))
|
||||
(def fmt-patt (do
|
||||
(def lines (string/split "\n" patterns))
|
||||
(def indented (map (fn [x] (string " " x)) lines))
|
||||
(string/join indented "\n")
|
||||
))
|
||||
(print fmt-patt)
|
||||
(def source-line (get-line source line-num))
|
||||
(print " >>> " source-line)
|
||||
(print (caret source line-num start))
|
||||
e)
|
||||
|
||||
(defn- generic-panic [e]
|
||||
(def msg (e :msg))
|
||||
(def {:line line-num :source source :input input} (get-in e [:node :token]))
|
||||
(def {:line line-num :source source :input input :start start} (get-in e [:node :token]))
|
||||
(def source-line (get-line source line-num))
|
||||
(print "Ludus panicked! " msg)
|
||||
(print " on line " line-num " in " input ":")
|
||||
(print " >>> " source-line))
|
||||
(print " >>> " source-line)
|
||||
(print (caret source line-num start))
|
||||
e)
|
||||
|
||||
(defn- unbound-name [e]
|
||||
(def {:line line-num :source source :lexeme name :input input} (get-in e [:node :token]))
|
||||
(def {:line line-num :source source :lexeme name :input input :start start} (get-in e [:node :token]))
|
||||
(def source-line (get-line source line-num))
|
||||
(print "Ludus panicked! unbound name " name)
|
||||
(print " on line " line-num " in " input ":")
|
||||
(print " >>> " source-line))
|
||||
(print " >>> " source-line)
|
||||
(print (caret source line-num start))
|
||||
e)
|
||||
|
||||
(defn runtime-error [e]
|
||||
(when (= :string (type e))
|
||||
|
@ -109,6 +133,8 @@
|
|||
(case msg
|
||||
"no match: function call" (fn-no-match e)
|
||||
"no match: let binding" (let-no-match e)
|
||||
"no match: match form" (match-no-match e)
|
||||
"no match: when form" (generic-panic e)
|
||||
"unbound name" (unbound-name e)
|
||||
(generic-panic e))
|
||||
e)
|
||||
|
|
|
@ -52,7 +52,12 @@
|
|||
# (comment
|
||||
(do
|
||||
(def source `
|
||||
box foo = nil
|
||||
match :foo with {
|
||||
:bar -> :baz
|
||||
:baz -> :quux
|
||||
"thing {foo}" -> "worste"
|
||||
42 -> 23
|
||||
}
|
||||
`)
|
||||
(def out (-> source
|
||||
ludus
|
||||
|
|
Loading…
Reference in New Issue
Block a user