diff options
| author | mryouse | 2022-07-09 02:19:54 +0000 |
|---|---|---|
| committer | mryouse | 2022-07-09 02:19:54 +0000 |
| commit | 4fb8873f45c8596ba044c87060191778b8238952 (patch) | |
| tree | c611f4dc7d1afa4a20c543e970caa18f1fb3e1dc | |
| parent | 5d16387be0437fe711f51933b9b10674da18f116 (diff) | |
initial commit of neb REPL
| -rw-r--r-- | repl.neb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/repl.neb b/repl.neb new file mode 100644 index 0000000..e8cb9b5 --- /dev/null +++ b/repl.neb @@ -0,0 +1,43 @@ +; repl.neb +; by mryouse +; +; a REPL for neb, written in neb + +(def _history_ (list)) + +(func history () + _history_) + +(func !! () + (def cmd (first (list-reverse (history)))) + (print (->string cmd)) + (eval (parse-neb cmd))) + +(func save-repl (filename :string) + (def fil (open-write filename)) + (write (concat (join (history) "\n") "\n") fil) + (close fil)) + +(func prompt (nxt) + (concat "#" (->string nxt) "> ")) + +(func repl () + (print "### neb :)(: IN NEB!") + (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))) + + ; this is the actual loop part + (while #true + (def this-cmd (strip (read-line (prompt next-cmd-num)))) + (if (not (eq? "" this-cmd)) + (try + (evaluate-cmd this-cmd) + (print (concat "panic! " _panic_)))))) + +(repl) |
