mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
[stdlib] Add keep return(function)
This commit is contained in:
parent
87afa51baa
commit
760181eaf9
3 changed files with 18 additions and 0 deletions
|
|
@ -27,6 +27,16 @@ Function = ast.abstract.Overloadable {
|
||||||
return Function:new(parameters, ReturnBoundary:new(expression))
|
return Function:new(parameters, ReturnBoundary:new(expression))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
-- returns the same function, without the return boundary
|
||||||
|
-- this does not create a new function scope
|
||||||
|
without_return_boundary = function(self)
|
||||||
|
if ReturnBoundary:is(self.expression) then
|
||||||
|
return Function:new(self.parameters, self.expression.expression, self.scope, self.upvalues)
|
||||||
|
else
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
if self.parameters.assignment then
|
if self.parameters.assignment then
|
||||||
return "$"..self.parameters:format_short(...).."; "..self.expression:format_right(...)
|
return "$"..self.parameters:format_short(...).."; "..self.expression:format_right(...)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,13 @@ return {
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"keep return", "(f::is function)",
|
||||||
|
function(state, f)
|
||||||
|
return f:without_return_boundary()
|
||||||
|
end
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"_._", "(c::is function, s::is string)",
|
"_._", "(c::is function, s::is string)",
|
||||||
function(state, c, s)
|
function(state, c, s)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ return [[
|
||||||
|
|
||||||
:@défini = stdlib.defined
|
:@défini = stdlib.defined
|
||||||
:@surcharge = stdlib.overload
|
:@surcharge = stdlib.overload
|
||||||
|
:@préserver retour = stdlib.keep return
|
||||||
|
|
||||||
:@si = stdlib.if
|
:@si = stdlib.if
|
||||||
:@sinon = stdlib.else
|
:@sinon = stdlib.else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue