about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lua/chupacabra/chupacabra.lua12
-rw-r--r--lua/chupacabra/refcard.md10
-rw-r--r--lua/chupacabra/repl.lua13
-rw-r--r--lua/chupacabra/scratch.lua18
-rw-r--r--lua/chupacabra/test_chupacabra.lua16
5 files changed, 27 insertions, 42 deletions
diff --git a/lua/chupacabra/chupacabra.lua b/lua/chupacabra/chupacabra.lua
index 562dc6b..dc02307 100644
--- a/lua/chupacabra/chupacabra.lua
+++ b/lua/chupacabra/chupacabra.lua
@@ -210,6 +210,18 @@ function chupacabra.evaluate(tokens, context)
     return table.remove(stack)
 end
 
+function chupacabra.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
+
 function chupacabra.run(str, context)
     local tokens = chupacabra.tokenize(str)
     return chupacabra.evaluate(tokens, context)
diff --git a/lua/chupacabra/refcard.md b/lua/chupacabra/refcard.md
index 26aa4f5..9eaf6e7 100644
--- a/lua/chupacabra/refcard.md
+++ b/lua/chupacabra/refcard.md
@@ -26,4 +26,12 @@ You can create test cases using the `tc` function from lua. The `tc` function ta
 
 For example, `tc("[1 1 1] [2 3 4] @+", {3, 4, 5})` tests that adding the arrays {1, 1, 1} and {2, 3, 4} results in the array {3, 4, 5}.
 
-There is also a totally shit repl. I'll make that better, soon...maybe.
\ No newline at end of file
+There is also a totally shit repl. I'll make that better, soon...maybe.
+
+## repl
+There is a basic repl provided to use when exploring chupacabra. First run, `chmod +x repl` and then every other time you should be able to run just `./repl`.
+
+## Other stuff
+- Nested arrays? lol, nope.
+- User defined words? Also a nope.
+- Lambdas? Maybe one day.
\ No newline at end of file
diff --git a/lua/chupacabra/repl.lua b/lua/chupacabra/repl.lua
index 6abbf46..ba489e2 100644
--- a/lua/chupacabra/repl.lua
+++ b/lua/chupacabra/repl.lua
@@ -1,17 +1,6 @@
 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 = {}
 
@@ -24,7 +13,7 @@ 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))
+            print("  output: " .. chupacabra.table_to_string(entry.output))
         else
             print("  output: " .. tostring(entry.output))
         end
diff --git a/lua/chupacabra/scratch.lua b/lua/chupacabra/scratch.lua
index 9dbe724..9fe504d 100644
--- a/lua/chupacabra/scratch.lua
+++ b/lua/chupacabra/scratch.lua
@@ -1,17 +1,5 @@
 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 stack = {}
 
 local function scratch(input)
@@ -19,11 +7,11 @@ local function scratch(input)
     table.insert(stack, {input = input, output = output})
 end
 
-local function print_stack()
+local function scratch_out()
     for i, entry in ipairs(stack) do
         print(i .. "  input: " .. entry.input)
         if type(entry.output) == "table" then
-            print("  output: " .. table_to_string(entry.output))
+            print("  output: " .. chupacabra.table_to_string(entry.output))
         else
             print("  output: " .. tostring(entry.output))
         end
@@ -37,4 +25,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()
\ No newline at end of file
+scratch_out()
\ No newline at end of file
diff --git a/lua/chupacabra/test_chupacabra.lua b/lua/chupacabra/test_chupacabra.lua
index 0a06124..5cf04e0 100644
--- a/lua/chupacabra/test_chupacabra.lua
+++ b/lua/chupacabra/test_chupacabra.lua
@@ -1,22 +1,10 @@
 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
-
 -- test cases
 local function tc(input, expected_output)
     local output = chupacabra.run(input, {})
-    local expected_output_str = type(expected_output) == "table" and table_to_string(expected_output) or tostring(expected_output)
-    local output_str = type(output) == "table" and table_to_string(output) or tostring(output)
+    local expected_output_str = type(expected_output) == "table" and chupacabra.table_to_string(expected_output) or tostring(expected_output)
+    local output_str = type(output) == "table" and chupacabra.table_to_string(output) or tostring(output)
     assert(output_str == expected_output_str, "Test failed: " .. input .. " => " .. output_str .. ", expected: " .. expected_output_str)
     print("Test passed: " .. input .. " => " .. output_str)
 end