~technomancy/fennel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Only replace _trailing_ "elseif true" with "else"

Details
Message ID
<20190903202425.3911-1-benaiah@mischenko.com>
DKIM signature
missing
Download raw message
Patch: +6 -1
---
 fennel.lua | 4 +++-
 test.lua   | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/fennel.lua b/fennel.lua
index c5e451b..1f3bbe7 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -1493,7 +1493,9 @@ SPECIALS['if'] = function(ast, scope, parent, opts)
        local branch = branches[i]
        local fstr = not branch.nested and 'if %s then' or 'elseif %s then'
        local cond = tostring(branch.cond)
        local condLine = (cond == "true" and branch.nested) and "else" or fstr:format(cond)
        local condLine = (cond == "true" and branch.nested and i == #branches)
            and "else"
            or fstr:format(cond)
        if branch.nested then
            emit(lastBuffer, branch.condchunk, ast)
        else
diff --git a/test.lua b/test.lua
index c815b6b..a049e5c 100644
--- a/test.lua
+++ b/test.lua
@@ -118,6 +118,9 @@ local cases = {
        ["(var a 884) (when nil (set a 192)) a"]=884,
        -- when body does not run on false
        ["(when (= 12 88) (os.exit 1)) false"]=false,
        -- make sure bad code isn't emitted when an always-true
        -- condition exists in the middle of an if
        ["(if false :y true :x :trailing :condition)"]="x",
    },

    core = {
-- 
2.23.0.rc1
Details
Message ID
<87y2z2jm4c.fsf@hagelb.org>
In-Reply-To
<20190903202425.3911-1-benaiah@mischenko.com> (view parent)
DKIM signature
missing
Download raw message
Thanks; just pushed this out.

-Phil

Benaiah Mischenko <benaiah@mischenko.com> writes:

> ---
>  fennel.lua | 4 +++-
>  test.lua   | 3 +++
>  2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fennel.lua b/fennel.lua
> index c5e451b..1f3bbe7 100644
> --- a/fennel.lua
> +++ b/fennel.lua
> @@ -1493,7 +1493,9 @@ SPECIALS['if'] = function(ast, scope, parent, opts)
>          local branch = branches[i]
>          local fstr = not branch.nested and 'if %s then' or 'elseif %s then'
>          local cond = tostring(branch.cond)
> -        local condLine = (cond == "true" and branch.nested) and "else" or fstr:format(cond)
> +        local condLine = (cond == "true" and branch.nested and i == #branches)
> +            and "else"
> +            or fstr:format(cond)
>          if branch.nested then
>              emit(lastBuffer, branch.condchunk, ast)
>          else
> diff --git a/test.lua b/test.lua
> index c815b6b..a049e5c 100644
> --- a/test.lua
> +++ b/test.lua
> @@ -118,6 +118,9 @@ local cases = {
>          ["(var a 884) (when nil (set a 192)) a"]=884,
>          -- when body does not run on false
>          ["(when (= 12 88) (os.exit 1)) false"]=false,
> +        -- make sure bad code isn't emitted when an always-true
> +        -- condition exists in the middle of an if
> +        ["(if false :y true :x :trailing :condition)"]="x",
>      },
>  
>      core = {