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

@ -63,9 +63,15 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
elseif s:match("^%b()") then
local content, r = s:match("^(%b())(.*)$")
content = content:gsub("^%(", ""):gsub("%)$", "")
local exp, r_paren = expression(content, state, namespace)
if not exp then return nil, "invalid expression inside parentheses: "..r_paren end
if r_paren:match("[^%s]") then return nil, ("unexpected %q at end of parenthesis expression"):format(r_paren) end
local exp
if content:match("[^%s]") then
local r_paren
exp, r_paren = expression(content, state, namespace)
if not exp then return nil, "invalid expression inside parentheses: "..r_paren end
if r_paren:match("[^%s]") then return nil, ("unexpected %q at end of parenthesis expression"):format(r_paren) end
else
exp = { type = "nil", return_type = "nil", value = nil }
end
return expression(r, state, namespace, currentPriority, {
type = "parentheses",
return_type = exp.return_type,

View file

@ -29,14 +29,10 @@ local function parse(state)
end
-- expressions
if line.expression then
if line.expression:match("[^%s]") then
local exp, rem = expression(line.expression, state, namespace)
if not exp then return nil, ("%s; at %s"):format(rem, line.source) end
if rem:match("[^%s]") then return nil, ("expected end of expression before %q; at %s"):format(rem, line.source) end
line.expression = exp
else
line.expression = nil
end
local exp, rem = expression(line.expression, state, namespace)
if not exp then return nil, ("%s; at %s"):format(rem, line.source) end
if rem:match("[^%s]") then return nil, ("expected end of expression before %q; at %s"):format(rem, line.source) end
line.expression = exp
-- function return type information
if line.type == "return" then
local variant = line.parent_function.variant

View file

@ -303,12 +303,22 @@ local function parse_line(line, state, namespace)
elseif l:match("^%#") then
r.type = "tag"
r.child = true
r.expression = l:match("^%#(.*)$")
local expr = l:match("^%#(.*)$")
if expr:match("[^%s]") then
r.expression = expr
else
r.expression = nil
end
-- return
elseif l:match("^%@") then
r.type = "return"
r.parent_function = true
r.expression = l:match("^%@(.*)$")
local expr = l:match("^%@(.*)$")
if expr:match("[^%s]") then
r.expression = expr
else
r.expression = "()"
end
-- text
elseif l:match("[^%s]") then
r.type = "text"