Littl repl improvements
This commit is contained in:
parent
a57446db93
commit
874dacf791
|
@ -16,7 +16,7 @@
|
||||||
(def prompt "=> ")
|
(def prompt "=> ")
|
||||||
|
|
||||||
(def base-ctx (merge prelude/prelude
|
(def base-ctx (merge prelude/prelude
|
||||||
{::repl true "foo" :bar
|
{::repl true
|
||||||
"repl"
|
"repl"
|
||||||
{
|
{
|
||||||
::data/struct true
|
::data/struct true
|
||||||
|
@ -60,13 +60,18 @@
|
||||||
(swap! sessions #(assoc % name session))
|
(swap! sessions #(assoc % name session))
|
||||||
session))
|
session))
|
||||||
|
|
||||||
|
(defn- exit []
|
||||||
|
(println "\nGoodbye!")
|
||||||
|
(System/exit 0))
|
||||||
|
|
||||||
(defn repl-loop []
|
(defn repl-loop []
|
||||||
(let [session-atom @current-session
|
(let [session-atom @current-session
|
||||||
session @session-atom
|
session @session-atom
|
||||||
orig-ctx (:ctx session)]
|
orig-ctx (:ctx session)]
|
||||||
(print (str (:name session) prompt))
|
(print (str (:name session) prompt))
|
||||||
(flush)
|
(flush)
|
||||||
(let [input (read-line)
|
(let [raw-input (read-line)
|
||||||
|
input (if raw-input raw-input (exit))
|
||||||
parsed (-> input (scanner/scan) (parser/parse))
|
parsed (-> input (scanner/scan) (parser/parse))
|
||||||
{result :result ctx :ctx} (interpreter/interpret-repl parsed (:ctx session))]
|
{result :result ctx :ctx} (interpreter/interpret-repl parsed (:ctx session))]
|
||||||
(if (= result ::interpreter/error)
|
(if (= result ::interpreter/error)
|
||||||
|
@ -79,7 +84,7 @@
|
||||||
|
|
||||||
(defn launch []
|
(defn launch []
|
||||||
(println "Welcome to Ludus (v. 0.1.0-alpha)")
|
(println "Welcome to Ludus (v. 0.1.0-alpha)")
|
||||||
(let [session (new-session "ludus")]
|
(let [session (new-session :ludus)]
|
||||||
(reset! current-session session)
|
(reset! current-session session)
|
||||||
(repl-loop)))
|
(repl-loop)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user