about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-06-09 20:54:53 -0400
committerelioat <elioat@tilde.institute>2024-06-09 20:54:53 -0400
commit3ff223f2a297a7300fede33dbe69da63f08e0c84 (patch)
tree0576d764fe9ab6e22b735e261237502bd1cf7f31
parent252f3076873868dee5cec2b4b571b47673c1cf06 (diff)
downloadtour-3ff223f2a297a7300fede33dbe69da63f08e0c84.tar.gz
*
-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
re>8b8fdf4 ^
321c41f ^



8b8fdf4 ^
321c41f ^
8b8fdf4 ^
321c41f ^
8b8fdf4 ^









321c41f ^
3f6e81d ^








e71fd1a ^


















3c6b5ba ^







8b8fdf4 ^
11b0eb3 ^

3c6b5ba ^





11b0eb3 ^

3c6b5ba ^
8b8fdf4 ^


3c6b5ba ^

8b8fdf4 ^



0aa2204 ^
8b8fdf4 ^

e71fd1a ^
8b8fdf4 ^
e71fd1a ^
8b8fdf4 ^











11b0eb3 ^

3f6e81d ^
3c6b5ba ^
3f6e81d ^


7aa3e02 ^
e71fd1a ^
3f6e81d ^

b92f7fa ^

e71fd1a ^
b92f7fa ^

3f6e81d ^
8b8fdf4 ^


e71fd1a ^
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214