aboutsummaryrefslogtreecommitdiff
path: root/repl.neb
diff options
context:
space:
mode:
authormryouse2022-07-11 02:00:24 +0000
committermryouse2022-07-11 02:00:24 +0000
commit6cb8aa19bc47301ae34eecf8c119723c12da34bd (patch)
treebd31d0b6a1a458d04a9488c0f69f8f10472fccb1 /repl.neb
parent3b2907af59fb7ed451dc4a73ae645d466f62ba13 (diff)
parent0ed39a708e332399b871a88bf6c7a777630f9247 (diff)
Merge branch 'master' into feature/listtypes
Diffstat (limited to 'repl.neb')
-rw-r--r--repl.neb35
1 files changed, 26 insertions, 9 deletions
diff --git a/repl.neb b/repl.neb
index e8cb9b5..cc8ae06 100644
--- a/repl.neb
+++ b/repl.neb
@@ -26,18 +26,35 @@
(print "version: < 0")
(def next-cmd-num 1)
- (func evaluate-cmd (cmd)
- (def evaluated (parse-neb cmd))
- (print (concat "=> " (->string evaluated)))
- (redef next-cmd-num (+ 1 next-cmd-num))
- (redef _history_ (append _history_ cmd)))
+
+ (func get-non-empty-input ()
+ (def tmp "")
+ (while (eq? "" tmp)
+ (redef tmp (strip (read-line (prompt next-cmd-num)))))
+ tmp)
+
+ (func print-result (res)
+ (print (concat "=> "
+ (if (eq? :string (typeof res))
+ (concat "\"" res "\"")
+ (->string res)))))
; this is the actual loop part
(while #true
- (def this-cmd (strip (read-line (prompt next-cmd-num))))
- (if (not (eq? "" this-cmd))
+ (def this-cmd (get-non-empty-input))
+ (def panicked #false) ; we may not need this two-step if there's a :panic type
+ (def evaluated
(try
- (evaluate-cmd this-cmd)
- (print (concat "panic! " _panic_))))))
+ (eval (parse-neb this-cmd))
+ (block
+ (redef panicked #true)
+ _panic_)))
+
+ (if panicked
+ (print (concat "panic! " evaluated))
+ (block
+ (print-result evaluated)
+ (redef next-cmd-num (+ 1 next-cmd-num))
+ (redef _history_ (append _history_ this-cmd))))))
(repl)