about summary refs log tree commit diff stats
path: root/lua/chupacabra/repl.lua
blob: ba489e2e826154b7845c915d0ea31a98c8a3bcc5 (plain) (blame)
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
local chupacabra = require("chupacabra")

-- not a great, but a passable repl

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: " .. chupacabra.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