From 760181eaf95f420ffc8eacf8ff97e06053f7ecb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Tue, 9 Jan 2024 18:06:04 +0100 Subject: [PATCH] [stdlib] Add keep return(function) --- anselme/ast/Function.lua | 10 ++++++++++ anselme/stdlib/function.lua | 7 +++++++ anselme/stdlib/language/frFR.lua | 1 + 3 files changed, 18 insertions(+) diff --git a/anselme/ast/Function.lua b/anselme/ast/Function.lua index 9ef9a1c..a8085df 100644 --- a/anselme/ast/Function.lua +++ b/anselme/ast/Function.lua @@ -27,6 +27,16 @@ Function = ast.abstract.Overloadable { return Function:new(parameters, ReturnBoundary:new(expression)) 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, ...) if self.parameters.assignment then return "$"..self.parameters:format_short(...).."; "..self.expression:format_right(...) diff --git a/anselme/stdlib/function.lua b/anselme/stdlib/function.lua index 570134d..f08a49e 100644 --- a/anselme/stdlib/function.lua +++ b/anselme/stdlib/function.lua @@ -26,6 +26,13 @@ return { end }, + { + "keep return", "(f::is function)", + function(state, f) + return f:without_return_boundary() + end + }, + { "_._", "(c::is function, s::is string)", function(state, c, s) diff --git a/anselme/stdlib/language/frFR.lua b/anselme/stdlib/language/frFR.lua index 4463953..09c8d47 100644 --- a/anselme/stdlib/language/frFR.lua +++ b/anselme/stdlib/language/frFR.lua @@ -12,6 +12,7 @@ return [[ :@défini = stdlib.defined :@surcharge = stdlib.overload +:@préserver retour = stdlib.keep return :@si = stdlib.if :@sinon = stdlib.else