aboutsummaryrefslogtreecommitdiff
path: root/Lua/test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Lua/test.lua')
-rw-r--r--Lua/test.lua28
1 files changed, 18 insertions, 10 deletions
diff --git a/Lua/test.lua b/Lua/test.lua
index df7a63d..c2fbb3c 100644
--- a/Lua/test.lua
+++ b/Lua/test.lua
@@ -10,24 +10,32 @@ bp.each = function(s, pat, index)
return iter, {s, pat, index}, index
end
+local function repr(obj)
+ if type(obj) == 'table' then
+ local ret = {}
+ for k,v in pairs(obj) do table.insert(ret, ("%s=%s"):format(k, repr(v))) end
+ return ("{%s}"):format(table.concat(ret,","))
+ elseif type(obj) == 'string' then
+ return string.format("%q", obj)
+ else
+ return tostring(obj)
+ end
+end
+
print("Matching:")
for m, i,j in bp.each("one two three", "(*`a-z) => '(@0)'") do
- print(("%q @%d len=%d"):format(tostring(m),i,j))
+ print(("%s @%d len=%d"):format(repr(m),i,j))
end
print(("Replacing: %q (%d replacements)"):format(bp.replace("one two three", "+`a-z", "(@0)")))
print("Captures:")
-local m = bp.match("one two three four", "_:` ;@first=+`a-z _ @second=(+`a-z => 'XX@0XX') _ @+`a-z _ @last=+`a-z")
-local function quote(x) return ("%q"):format(tostring(x)) end
-print("0", quote(m[0]))
-print("first", quote(m.first))
-print("second", m.second)
-print("1", m[1])
-print("last", m.last)
-
-print("Len:", #m, #tostring(m))
+local m = bp.match("one two three four", "@first=+`a-z _ @second=(+`a-z => 'XX@0XX') _ @+`a-z _ @last=+`a-z")
+print(repr(m))
+
+local m = bp.match("one two three four", "@dup=+`a-z _ @dup=+`a-z _ @two=(@a=+`a-z _ @b=+`a-z)")
+print(repr(m))
print("Testing parse errors:")