blob: 41dacb654510fddc31b55ef02bcfe29d52e32e09 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
; 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 get-non-empty-input ()
(def tmp "")
(while (eq? "" tmp)
(redef tmp (strip (read-line (prompt next-cmd-num)))))
tmp)
(func print-result (res)
;(def calc res)
(print (concat "=> "
(if (eq? :string (typeof res))
(raw res)
(->string res)))))
; this is the actual loop part
(while #true
(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
;(eval (first (parse-neb this-cmd)))
(quote (first (parse-neb this-cmd)))
;(quote (map eval (parse-neb this-cmd)))
;(parse-neb this-cmd)
(block
(redef panicked #true)
_panic_)))
;(print evaluated)
(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)
|