2017-05-08 01:36:04 +00:00
|
|
|
(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))
|
|
|
|
|
2017-05-08 15:03:06 +00:00
|
|
|
"Run a simple repl. Does not handle errors and other
|
|
|
|
such details."
|
2017-05-08 01:36:04 +00:00
|
|
|
(while 1
|
2017-05-08 15:03:06 +00:00
|
|
|
(write stdout ">> ")
|
2017-05-08 01:36:04 +00:00
|
|
|
(: line (readline))
|
2017-05-08 15:03:06 +00:00
|
|
|
(while line
|
|
|
|
(: line (parse-charseq p line))
|
|
|
|
(if (parse-hasvalue p)
|
|
|
|
(print ((compile (parse-consume p)))))))
|