mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 08:39:30 +00:00
Add implicit multiplication
This commit is contained in:
parent
4214fafc68
commit
fd07db83f2
2 changed files with 19 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ local binops_prio = {
|
|||
[12] = {}
|
||||
}
|
||||
local pair_priority = 8
|
||||
local implicit_multiply_priority = 7.5 -- just above / so 1/2x gives 1/(2x)
|
||||
-- unop priority
|
||||
local prefix_unops_prio = {
|
||||
[1] = {},
|
||||
|
|
@ -398,6 +399,22 @@ local function expression(s, state, namespace, current_priority, operating_on)
|
|||
if not variant then return variant, err end
|
||||
return expression(r, state, namespace, current_priority, variant)
|
||||
end
|
||||
-- implicit multiplication
|
||||
if implicit_multiply_priority > current_priority then
|
||||
if s:match("^"..identifier_pattern) then
|
||||
local right, r = expression(s, state, namespace, implicit_multiply_priority)
|
||||
if right then
|
||||
local args = {
|
||||
type = "list",
|
||||
left = operating_on,
|
||||
right = right
|
||||
}
|
||||
local variant, err = find_function(state, namespace, "_*_", args, true)
|
||||
if not variant then return variant, err end
|
||||
return expression(r, state, namespace, current_priority, variant)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- nothing to operate
|
||||
return operating_on, s
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,4 +8,6 @@ return [[
|
|||
:pair="pair"
|
||||
:function reference="function reference"
|
||||
:variable reference="variable reference"
|
||||
|
||||
:pi=3.1415926535898
|
||||
]]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue