1
0
mirror of https://github.com/janet-lang/janet synced 2024-07-04 11:03:15 +00:00
janet/libs/repl.gst
2017-05-09 19:21:30 -04:00

30 lines
649 B
Plaintext

(namespace-set! "gst.repl")
"Hold all compile time evaluators"
(export! "evaluators" {})
"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))
"Run a simple repl. Does not handle errors and other
such details."
(while 1
(: t (thread (fn []
(write stdout ">> ")
(: line (readline))
(while line
(: line (parse-charseq p line))
(if (parse-hasvalue p)
((compile (parse-consume p))))))))
(transfer t))