diff --git a/src/errors.janet b/src/errors.janet index 898c3f0..5380409 100644 --- a/src/errors.janet +++ b/src/errors.janet @@ -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) diff --git a/src/ludus.janet b/src/ludus.janet index 3f4f5d5..fe43f0d 100644 --- a/src/ludus.janet +++ b/src/ludus.janet @@ -52,10 +52,15 @@ # (comment (do (def source ` -box foo = nil +match :foo with { + :bar -> :baz + :baz -> :quux + "thing {foo}" -> "worste" + 42 -> 23 +} `) (def out (-> source - ludus + ludus j/decode )) (setdyn :out stdout)