aboutsummaryrefslogtreecommitdiffstats
path: root/lua/chupacabra
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-06-09 19:21:18 -0400
committerelioat <elioat@tilde.institute>2024-06-09 19:21:18 -0400
commitab9c099df31d036c9bbd7e94e32a97e9cffc8e12 (patch)
tree89d6b4e07af484da415cc59508c14751d80eac82 /lua/chupacabra
parenta73134a79471fefef76c0668a375b722f5cd5605 (diff)
downloadtour-ab9c099df31d036c9bbd7e94e32a97e9cffc8e12.tar.gz
*
Diffstat (limited to 'lua/chupacabra')
-rw-r--r--lua/chupacabra/repl.lua34
-rw-r--r--lua/chupacabra/scratch.lua2
2 files changed, 25 insertions, 11 deletions
diff --git a/lua/chupacabra/repl.lua b/lua/chupacabra/repl.lua
index 990d62a..bed67c2 100644
--- a/lua/chupacabra/repl.lua
+++ b/lua/chupacabra/repl.lua
@@ -1,29 +1,43 @@
local chupacabra = require("chupacabra")
--- FIXME: this is dog water and doesn't work...at all
-
+-- 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
- if type(v) == "table" then
- str = str .. table_to_string(v)
- else
- str = str .. tostring(v)
- 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 print_stack()
+ 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 == "exit" then
+ if input == "bye" then
break
end
- local stack = chupacabra.run(" " .. input .. " ", {})
- print("Stack: " .. table_to_string(stack))
+ scratch(input)
+ print_stack()
+ stack = {}
end \ No newline at end of file
diff --git a/lua/chupacabra/scratch.lua b/lua/chupacabra/scratch.lua
index 6025888..c5e0ee2 100644
--- a/lua/chupacabra/scratch.lua
+++ b/lua/chupacabra/scratch.lua
@@ -37,4 +37,4 @@ scratch("[2 4 6] 2 @..")
scratch("1 2 3 4 5 6 7 @.. [1 2 3 0 5 6 7] @=")
scratch("2 3 +")
scratch("3 : + 6 =")
-print_stack()
+print_stack() \ No newline at end of file