about summary refs log tree commit diff stats
path: root/lua/chupacabra
diff options
context:
space:
mode:
Diffstat (limited to 'lua/chupacabra')
-rw-r--r--lua/chupacabra/repl.lua36
-rw-r--r--lua/chupacabra/scratch.lua23
2 files changed, 44 insertions, 15 deletions
diff --git a/lua/chupacabra/repl.lua b/lua/chupacabra/repl.lua
index 302f306..990d62a 100644
--- a/lua/chupacabra/repl.lua
+++ b/lua/chupacabra/repl.lua
@@ -1,21 +1,29 @@
-local chupacabra = require("chupacabra") 
+local chupacabra = require("chupacabra")
 
--- simple repl to interact with chupacabra
+-- FIXME: this is dog water and doesn't work...at all
+
+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
+    end
+    str = str .. "}"
+    return str
+end
 
 while true do
-    io.write("chupacabra> ")
+    io.write("> ")
     local input = io.read()
     if input == "exit" then
         break
     end
-    local output = chupacabra.run(input, {})
-    if type(output) == "table" then
-        local outputString = ""
-        for _, value in ipairs(output) do
-            outputString = outputString .. " " .. value -- FIXME: this is dog water
-        end
-        print("["..outputString.."]")
-    else
-        print(output)
-    end
-end
+    local stack = chupacabra.run(" " .. input .. " ", {})
+    print("Stack: " .. table_to_string(stack))
+end
\ No newline at end of file
diff --git a/lua/chupacabra/scratch.lua b/lua/chupacabra/scratch.lua
index e0bab8c..204d383 100644
--- a/lua/chupacabra/scratch.lua
+++ b/lua/chupacabra/scratch.lua
@@ -1 +1,22 @@
-local chupacabra = require("chupacabra")
\ No newline at end of file
+local chupacabra = require("chupacabra")
+
+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 function scratch(input)
+    local output = chupacabra.run(input, {})
+    print("Input: " .. input)
+    print("Output: " .. table_to_string(output))
+end
+
+scratch("3 : + [1 1 1] [2 3 4] @+ @..")
+scratch("[2 4 6] 2 @..")
\ No newline at end of file