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

Custom format for Typed and dispatch refactor

This commit is contained in:
Étienne Fildadut 2023-12-28 14:28:14 +01:00
parent e222f0fb28
commit 91e1311560
8 changed files with 75 additions and 26 deletions

View file

@ -1,3 +1,5 @@
-- for nodes that can be put in an Overload
local ast = require("ast")
return ast.abstract.Node {
@ -9,19 +11,21 @@ return ast.abstract.Node {
compatible_with_arguments = function(self, state, args)
error("not implemented for "..self.type)
end,
-- same as :call, but assumes :compatible_with_arguments was checked before the call
call_compatible = function(self, state, args)
error("not implemented for "..self.type)
end,
-- return string
format_parameters = function(self, state)
return self:format(state)
end,
-- default for :call
call = function(self, state, args)
assert(self:compatible_with_arguments(state, args))
return self:call_compatible(state, args)
end
-- can be called either after a successful :dispatch or :compatible_with_arguments
call_dispatched = function(self, state, args)
error("not implemented for "..self.type)
end,
-- default for :dispatch
dispatch = function(self, state, args)
local s, err = self:compatible_with_arguments(state, args)
if s then return self, args
else return nil, err end
end,
}