1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-28 00:59:31 +00:00

Add while loop line and operator

This commit is contained in:
Étienne Fildadut 2021-12-12 17:07:50 +01:00
parent f5382d2912
commit 48cabbf4c0
14 changed files with 500 additions and 61 deletions

View file

@ -122,6 +122,23 @@ local function eval(state, exp)
type = "nil",
value = nil
}
-- while loop
elseif exp.type == "~?" then
local right, righte = eval(state, exp.right)
if not right then return right, righte end
local l = {}
while truthy(right) do
local left, lefte = eval(state, exp.left)
if not left then return left, lefte end
table.insert(l, left)
-- next iteration
right, righte = eval(state, exp.right)
if not right then return right, righte end
end
return {
type = "list",
value = l
}
-- tag
elseif exp.type == "#" then
local right, righte = eval(state, exp.right)