mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 09:09:31 +00:00
Switch a few remaining variables to snake_case
This commit is contained in:
parent
7433d27da5
commit
e2b95b751b
1 changed files with 38 additions and 38 deletions
|
|
@ -32,17 +32,17 @@ local unops_prio = {
|
||||||
--- parse an expression
|
--- parse an expression
|
||||||
-- return expr, remaining if success
|
-- return expr, remaining if success
|
||||||
-- returns nil, err if error
|
-- returns nil, err if error
|
||||||
local function expression(s, state, namespace, currentPriority, operatingOn)
|
local function expression(s, state, namespace, current_priority, operating_on)
|
||||||
s = s:match("^%s*(.*)$")
|
s = s:match("^%s*(.*)$")
|
||||||
currentPriority = currentPriority or 0
|
current_priority = current_priority or 0
|
||||||
if not operatingOn then
|
if not operating_on then
|
||||||
-- number
|
-- number
|
||||||
if s:match("^%d*%.%d+") or s:match("^%d+") then
|
if s:match("^%d*%.%d+") or s:match("^%d+") then
|
||||||
local d, r = s:match("^(%d*%.%d+)(.*)$")
|
local d, r = s:match("^(%d*%.%d+)(.*)$")
|
||||||
if not d then
|
if not d then
|
||||||
d, r = s:match("^(%d+)(.*)$")
|
d, r = s:match("^(%d+)(.*)$")
|
||||||
end
|
end
|
||||||
return expression(r, state, namespace, currentPriority, {
|
return expression(r, state, namespace, current_priority, {
|
||||||
type = "number",
|
type = "number",
|
||||||
value = tonumber(d)
|
value = tonumber(d)
|
||||||
})
|
})
|
||||||
|
|
@ -76,7 +76,7 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
l[j] = ls:gsub("\\.", string_escapes)
|
l[j] = ls:gsub("\\.", string_escapes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return expression(r, state, namespace, currentPriority, {
|
return expression(r, state, namespace, current_priority, {
|
||||||
type = "string",
|
type = "string",
|
||||||
value = l
|
value = l
|
||||||
})
|
})
|
||||||
|
|
@ -93,7 +93,7 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
else
|
else
|
||||||
exp = { type = "nil", value = nil }
|
exp = { type = "nil", value = nil }
|
||||||
end
|
end
|
||||||
return expression(r, state, namespace, currentPriority, {
|
return expression(r, state, namespace, current_priority, {
|
||||||
type = "parentheses",
|
type = "parentheses",
|
||||||
expression = exp
|
expression = exp
|
||||||
})
|
})
|
||||||
|
|
@ -108,7 +108,7 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
if not exp then return nil, "invalid expression inside list parentheses: "..r_paren end
|
if not exp then return nil, "invalid expression inside list parentheses: "..r_paren end
|
||||||
if r_paren:match("[^%s]") then return nil, ("unexpected %q at end of list parenthesis expression"):format(r_paren) end
|
if r_paren:match("[^%s]") then return nil, ("unexpected %q at end of list parenthesis expression"):format(r_paren) end
|
||||||
end
|
end
|
||||||
return expression(r, state, namespace, currentPriority, {
|
return expression(r, state, namespace, current_priority, {
|
||||||
type = "list_brackets",
|
type = "list_brackets",
|
||||||
expression = exp
|
expression = exp
|
||||||
})
|
})
|
||||||
|
|
@ -132,12 +132,12 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
-- find compatible variant
|
-- find compatible variant
|
||||||
local variant, err = find_function_variant(state, namespace, ":", args, true)
|
local variant, err = find_function_variant(state, namespace, ":", args, true)
|
||||||
if not variant then return variant, err end
|
if not variant then return variant, err end
|
||||||
return expression(r, state, namespace, currentPriority, variant)
|
return expression(r, state, namespace, current_priority, variant)
|
||||||
end
|
end
|
||||||
-- variables
|
-- variables
|
||||||
local var, vfqm = find(state.aliases, state.variables, namespace, name)
|
local var, vfqm = find(state.aliases, state.variables, namespace, name)
|
||||||
if var then
|
if var then
|
||||||
return expression(r, state, namespace, currentPriority, {
|
return expression(r, state, namespace, current_priority, {
|
||||||
type = "variable",
|
type = "variable",
|
||||||
name = vfqm
|
name = vfqm
|
||||||
})
|
})
|
||||||
|
|
@ -147,7 +147,7 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
if sname then
|
if sname then
|
||||||
local svar, svfqm = find(state.aliases, state.variables, namespace, sname)
|
local svar, svfqm = find(state.aliases, state.variables, namespace, sname)
|
||||||
if svar then
|
if svar then
|
||||||
return expression(suffix..r, state, namespace, currentPriority, {
|
return expression(suffix..r, state, namespace, current_priority, {
|
||||||
type = "variable",
|
type = "variable",
|
||||||
name = svfqm
|
name = svfqm
|
||||||
})
|
})
|
||||||
|
|
@ -171,7 +171,7 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
-- find compatible variant
|
-- find compatible variant
|
||||||
local variant, err = find_function_variant(state, namespace, name, args, explicit_call)
|
local variant, err = find_function_variant(state, namespace, name, args, explicit_call)
|
||||||
if not variant then return variant, err end
|
if not variant then return variant, err end
|
||||||
return expression(r, state, namespace, currentPriority, variant)
|
return expression(r, state, namespace, current_priority, variant)
|
||||||
end
|
end
|
||||||
-- unops
|
-- unops
|
||||||
for prio, oplist in ipairs(unops_prio) do
|
for prio, oplist in ipairs(unops_prio) do
|
||||||
|
|
@ -183,7 +183,7 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
-- find variant
|
-- find variant
|
||||||
local variant, err = find_function_variant(state, namespace, op, right, true)
|
local variant, err = find_function_variant(state, namespace, op, right, true)
|
||||||
if not variant then return variant, err end
|
if not variant then return variant, err end
|
||||||
return expression(r, state, namespace, currentPriority, variant)
|
return expression(r, state, namespace, current_priority, variant)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -191,7 +191,7 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
else
|
else
|
||||||
-- binop
|
-- binop
|
||||||
for prio, oplist in ipairs(binops_prio) do
|
for prio, oplist in ipairs(binops_prio) do
|
||||||
if prio >= currentPriority then
|
if prio >= current_priority then
|
||||||
for _, op in ipairs(oplist) do
|
for _, op in ipairs(oplist) do
|
||||||
local escaped = escape(op)
|
local escaped = escape(op)
|
||||||
if s:match("^"..escaped) then
|
if s:match("^"..escaped) then
|
||||||
|
|
@ -216,27 +216,27 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
end
|
end
|
||||||
-- add first argument
|
-- add first argument
|
||||||
if not args then
|
if not args then
|
||||||
args = operatingOn
|
args = operating_on
|
||||||
else
|
else
|
||||||
args = {
|
args = {
|
||||||
type = "list",
|
type = "list",
|
||||||
left = operatingOn,
|
left = operating_on,
|
||||||
right = args
|
right = args
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
-- find compatible variant
|
-- find compatible variant
|
||||||
local variant, err = find_function_variant(state, namespace, name, args, explicit_call)
|
local variant, err = find_function_variant(state, namespace, name, args, explicit_call)
|
||||||
if not variant then return variant, err end
|
if not variant then return variant, err end
|
||||||
return expression(r, state, namespace, currentPriority, variant)
|
return expression(r, state, namespace, current_priority, variant)
|
||||||
-- other binops
|
-- other binops
|
||||||
else
|
else
|
||||||
local right, r = expression(sright, state, namespace, prio)
|
local right, r = expression(sright, state, namespace, prio)
|
||||||
if not right then return nil, ("invalid expression after binop %q: %s"):format(op, r) end
|
if not right then return nil, ("invalid expression after binop %q: %s"):format(op, r) end
|
||||||
-- list constructor
|
-- list constructor
|
||||||
if op == "," then
|
if op == "," then
|
||||||
return expression(r, state, namespace, currentPriority, {
|
return expression(r, state, namespace, current_priority, {
|
||||||
type = "list",
|
type = "list",
|
||||||
left = operatingOn,
|
left = operating_on,
|
||||||
right = right
|
right = right
|
||||||
})
|
})
|
||||||
-- special binops
|
-- special binops
|
||||||
|
|
@ -245,7 +245,7 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
if op ~= ":=" then
|
if op ~= ":=" then
|
||||||
local args = {
|
local args = {
|
||||||
type = "list",
|
type = "list",
|
||||||
left = operatingOn,
|
left = operating_on,
|
||||||
right = right
|
right = right
|
||||||
}
|
}
|
||||||
local variant, err = find_function_variant(state, namespace, op:match("^(.*)%=$"), args, true)
|
local variant, err = find_function_variant(state, namespace, op:match("^(.*)%=$"), args, true)
|
||||||
|
|
@ -253,32 +253,32 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
right = variant
|
right = variant
|
||||||
end
|
end
|
||||||
-- assign to a function
|
-- assign to a function
|
||||||
if operatingOn.type == "function" then
|
if operating_on.type == "function" then
|
||||||
-- remove non-assignment functions
|
-- remove non-assignment functions
|
||||||
for i=#operatingOn.variants, 1, -1 do
|
for i=#operating_on.variants, 1, -1 do
|
||||||
if not operatingOn.variants[i].assignment then
|
if not operating_on.variants[i].assignment then
|
||||||
table.remove(operatingOn.variants, i)
|
table.remove(operating_on.variants, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #operatingOn.variants == 0 then
|
if #operating_on.variants == 0 then
|
||||||
return nil, ("trying to perform assignment on function %s with no compatible assignment variant"):format(operatingOn.called_name)
|
return nil, ("trying to perform assignment on function %s with no compatible assignment variant"):format(operating_on.called_name)
|
||||||
end
|
end
|
||||||
-- rewrite function to perform assignment
|
-- rewrite function to perform assignment
|
||||||
operatingOn.assignment = right
|
operating_on.assignment = right
|
||||||
return expression(r, state, namespace, currentPriority, operatingOn)
|
return expression(r, state, namespace, current_priority, operating_on)
|
||||||
elseif operatingOn.type ~= "variable" then
|
elseif operating_on.type ~= "variable" then
|
||||||
return nil, ("trying to perform assignment on a %s expression"):format(operatingOn.type)
|
return nil, ("trying to perform assignment on a %s expression"):format(operating_on.type)
|
||||||
end
|
end
|
||||||
-- assign to a variable
|
-- assign to a variable
|
||||||
return expression(r, state, namespace, currentPriority, {
|
return expression(r, state, namespace, current_priority, {
|
||||||
type = ":=",
|
type = ":=",
|
||||||
left = operatingOn,
|
left = operating_on,
|
||||||
right = right
|
right = right
|
||||||
})
|
})
|
||||||
elseif op == "&" or op == "|" then
|
elseif op == "&" or op == "|" then
|
||||||
return expression(r, state, namespace, currentPriority, {
|
return expression(r, state, namespace, current_priority, {
|
||||||
type = op,
|
type = op,
|
||||||
left = operatingOn,
|
left = operating_on,
|
||||||
right = right
|
right = right
|
||||||
})
|
})
|
||||||
-- normal binop
|
-- normal binop
|
||||||
|
|
@ -286,13 +286,13 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
-- find variant
|
-- find variant
|
||||||
local args = {
|
local args = {
|
||||||
type = "list",
|
type = "list",
|
||||||
left = operatingOn,
|
left = operating_on,
|
||||||
-- wrap in parentheses to avoid appending to argument list if right is a list
|
-- wrap in parentheses to avoid appending to argument list if right is a list
|
||||||
right = { type = "parentheses", expression = right }
|
right = { type = "parentheses", expression = right }
|
||||||
}
|
}
|
||||||
local variant, err = find_function_variant(state, namespace, op, args, true)
|
local variant, err = find_function_variant(state, namespace, op, args, true)
|
||||||
if not variant then return variant, err end
|
if not variant then return variant, err end
|
||||||
return expression(r, state, namespace, currentPriority, variant)
|
return expression(r, state, namespace, current_priority, variant)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -306,13 +306,13 @@ local function expression(s, state, namespace, currentPriority, operatingOn)
|
||||||
local right, r_paren = expression(content, state, namespace)
|
local right, r_paren = expression(content, state, namespace)
|
||||||
if not right then return right, r_paren end
|
if not right then return right, r_paren end
|
||||||
if r_paren:match("[^%s]") then return nil, ("unexpected %q at end of index expression"):format(r_paren) end
|
if r_paren:match("[^%s]") then return nil, ("unexpected %q at end of index expression"):format(r_paren) end
|
||||||
local args = { type = "list", left = operatingOn, right = right }
|
local args = { type = "list", left = operating_on, right = right }
|
||||||
local variant, err = find_function_variant(state, namespace, "()", args, true)
|
local variant, err = find_function_variant(state, namespace, "()", args, true)
|
||||||
if not variant then return variant, err end
|
if not variant then return variant, err end
|
||||||
return expression(r, state, namespace, currentPriority, variant)
|
return expression(r, state, namespace, current_priority, variant)
|
||||||
end
|
end
|
||||||
-- nothing to operate
|
-- nothing to operate
|
||||||
return operatingOn, s
|
return operating_on, s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue