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

Add nil expression and fix return behavior with nil expression

This commit is contained in:
Étienne Fildadut 2021-04-12 01:10:42 +02:00
parent 6488bef75c
commit b9c6d1d704
10 changed files with 84 additions and 21 deletions

View file

@ -9,8 +9,14 @@ local unpack = table.unpack or unpack
-- returns evaluated value if success
-- returns nil, error if error
local function eval(state, exp)
-- nil
if exp.type == "nil" then
return {
type = "nil",
value = nil
}
-- number
if exp.type == "number" then
elseif exp.type == "number" then
return {
type = "number",
value = exp.value

View file

@ -95,11 +95,8 @@ local function run_line(state, line)
if e then return v, e end
if v then return v end
elseif line.type == "return" then
local v, e
if line.expression then
v, e = eval(state, line.expression)
if not v then return v, ("%s; at %s"):format(e, line.source) end
end
local v, e = eval(state, line.expression)
if not v then return v, ("%s; at %s"):format(e, line.source) end
return v
elseif line.type == "text" then
local t, er = eval_text(state, line.text)