mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Fix conflict between comparison & compound operators
Everyone makes mistakes.
This commit is contained in:
parent
a7f2362199
commit
8eb4bd5ac5
2 changed files with 23 additions and 19 deletions
|
|
@ -5,16 +5,19 @@ local assignment = require("parser.expression.secondary.infix.assignment")
|
|||
local assignment_call = require("parser.expression.secondary.infix.assignment_call")
|
||||
|
||||
local infixes = require("common").regular_operators.infixes
|
||||
local operator_priority = require("common").operator_priority
|
||||
|
||||
local generated = {}
|
||||
|
||||
for _, infix in ipairs(infixes) do
|
||||
local operator = infix[1].."="
|
||||
local compound_operator = infix[1].."="
|
||||
local identifier = "_=_"
|
||||
local infix_identifier = "_"..infix[1].."_"
|
||||
|
||||
-- avoid a lot of unecessary trouble with <= & friends. why would you ever want to use i <= 7 as i = i < 7 anyway.
|
||||
if not operator_priority["_"..compound_operator.."_"] then
|
||||
table.insert(generated, assignment {
|
||||
operator = operator,
|
||||
operator = compound_operator,
|
||||
identifier = identifier,
|
||||
build_ast = function(self, left, right)
|
||||
right = Call:new(Identifier:new(infix_identifier), ArgumentTuple:new(left, right))
|
||||
|
|
@ -23,13 +26,14 @@ for _, infix in ipairs(infixes) do
|
|||
})
|
||||
|
||||
table.insert(generated, assignment_call {
|
||||
operator = operator,
|
||||
operator = compound_operator,
|
||||
identifier = identifier,
|
||||
build_ast = function(self, left, right)
|
||||
right = Call:new(Identifier:new(infix_identifier), ArgumentTuple:new(left, right))
|
||||
return assignment_call.build_ast(self, left, right)
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
return generated
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@ local secondaries = {
|
|||
}
|
||||
|
||||
-- add generated assignement+infix operator combos, before the rest
|
||||
local assignment_operators = r("infix.assignment_with_infix")
|
||||
for i, op in ipairs(assignment_operators) do
|
||||
local compound_assignments = r("infix.assignment_with_infix")
|
||||
for i, op in ipairs(compound_assignments) do
|
||||
table.insert(secondaries, i, op)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue