2017-05-08 01:36:04 +00:00
|
|
|
(namespace-set! "gst.repl")
|
|
|
|
|
|
|
|
"Read a line"
|
|
|
|
(export! "readline" (fn []
|
|
|
|
(: b (buffer))
|
|
|
|
(read stdin 1 b)
|
|
|
|
(while (not (= (get "\n" 0) (get b (- (length b) 1))))
|
|
|
|
(read stdin 1 b)
|
|
|
|
)
|
|
|
|
(string b)
|
|
|
|
))
|
|
|
|
|
|
|
|
"Create a parser"
|
|
|
|
(export! "p" (parser))
|
|
|
|
|
2017-05-10 00:06:53 +00:00
|
|
|
"Run a simple repl."
|
2017-05-08 01:36:04 +00:00
|
|
|
(while 1
|
2017-05-10 00:06:53 +00:00
|
|
|
(write stdout ">> ")
|
|
|
|
(: t (thread (fn [line]
|
|
|
|
(: ret 1)
|
2017-05-09 23:21:30 +00:00
|
|
|
(while line
|
|
|
|
(: line (parse-charseq p line))
|
|
|
|
(if (parse-hasvalue p)
|
2017-05-10 00:06:53 +00:00
|
|
|
(: ret ((compile (parse-consume p))))))
|
|
|
|
ret)))
|
|
|
|
(: res (tran t (readline)))
|
2017-05-11 21:08:29 +00:00
|
|
|
(if (= (status t) "dead") (print (debugp res)) (print "Error: " (debugp res))))
|