~technomancy/fennel

3 2

[PATCH] Emit "else" instead of "elseif true then"

Details
Message ID
<20190902025557.21883-1-benaiah@mischenko.com>
DKIM signature
pass
Download raw message
Patch: +2 -1
---

 fennel.lua | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fennel.lua b/fennel.lua
index f68a38e..b1744a8 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -1448,7 +1448,8 @@ SPECIALS['if'] = function(ast, scope, parent, opts)
     for i = 1, #branches do
         local branch = branches[i]
         local fstr = not branch.nested and 'if %s then' or 'elseif %s then'
-        local condLine = fstr:format(tostring(branch.cond))
+        local cond = tostring(branch.cond)
+        local condLine = cond == "true" and "else" or fstr:format(cond)
         if branch.nested then
             emit(lastBuffer, branch.condchunk, ast)
         else
-- 
2.23.0.rc1
Details
Message ID
<87ftlfl4z3.fsf@hagelb.org>
In-Reply-To
<20190902025557.21883-1-benaiah@mischenko.com> (view parent)
DKIM signature
missing
Download raw message
Benaiah Mischenko <benaiah@mischenko.com> writes:

> -        local condLine = fstr:format(tostring(branch.cond))
> +        local cond = tostring(branch.cond)
> +        local condLine = cond == "true" and "else" or fstr:format(cond)

This one's actually causing some test failures; can you take another look?

thanks,
Phil
Details
Message ID
<87tv9v8gvj.fsf@mischenko.com>
In-Reply-To
<87ftlfl4z3.fsf@hagelb.org> (view parent)
DKIM signature
pass
Download raw message
Phil Hagelberg <phil@hagelb.org> writes:

> This one's actually causing some test failures; can you take another look?

Whoops, should have remembered to run the tests before I submitted the
patch. It was replacing every "if true then" to "else" as well, which
obviously doesn't work in lua. Thanks for catching this - submitting a
fixed and rebased patch now.

- benaiah
Details
Message ID
<87d0gilk59.fsf@hagelb.org>
In-Reply-To
<87tv9v8gvj.fsf@mischenko.com> (view parent)
DKIM signature
missing
Download raw message
Benaiah Mischenko <benaiah@mischenko.com> writes:

> Phil Hagelberg <phil@hagelb.org> writes:
>
>> This one's actually causing some test failures; can you take another look?
>
> Whoops, should have remembered to run the tests before I submitted the
> patch. It was replacing every "if true then" to "else" as well, which
> obviously doesn't work in lua. Thanks for catching this - submitting a
> fixed and rebased patch now.

No worries; thanks. Pushed this as well as the hashfn patch.

-Phil