blob: 6abbf46875df6e975cf6e87a9497e46c16fa066d (
plain) (
tree)
|
|
local chupacabra = require("chupacabra")
-- not a great, but a passable repl
local function table_to_string(t)
local str = "["
for i, v in ipairs(t) do
if i > 1 then
str = str .. " "
end
str = str .. tostring(v)
end
str = str .. "]"
return str
end
local stack = {}
local function scratch(input)
local output = chupacabra.run(input, {})
table.insert(stack, {input = input, output = output})
end
local function scratch_out()
for i, entry in ipairs(stack) do
print(" input: " .. entry.input)
if type(entry.output) == "table" then
print(" output: " .. table_to_string(entry.output))
else
print(" output: " .. tostring(entry.output))
end
end
end
while true do
io.write("> ")
local input = io.read()
if input == "bye" then
break
end
scratch(input)
scratch_out()
stack = {}
end
|