~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
2 2

[PATCH antifennel] Fix reserved word mangling

Details
Message ID
<20220107042919.74567-1-xordspar0@gmail.com>
DKIM signature
pass
Download raw message
Patch: +19 -5
Previously, reserved words like match would get mangled to ___match-__.
While this is technically valid, it's a really strange variable name.
The new mangling logic produces the intended ___match___.
---
 antifennel.lua          | 7 +++++--
 antifennel_expected.fnl | 7 ++++---
 test.lua                | 5 +++++
 test_expected.fnl       | 5 +++++
 4 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/antifennel.lua b/antifennel.lua
index 680473b..593bbe4 100644
--- a/antifennel.lua
+++ b/antifennel.lua
@@ -28,8 +28,11 @@ local function uncamelize(name)
end

local function mangle(name, field)
   if not field and reserved[name] then name = "___" .. name .. "___" end
   return field and name or uncamelize(name):gsub("([a-z0-9])_", "%1-")
   if not field then
      name = uncamelize(name):gsub("([a-z0-9])_", "%1-")
      name = reserved[name] and "___" .. name .. "___" or name
   end
   return name
end

local function compile(rdr, filename)
diff --git a/antifennel_expected.fnl b/antifennel_expected.fnl
index 5670d73..c115c4c 100644
--- a/antifennel_expected.fnl
+++ b/antifennel_expected.fnl
@@ -33,9 +33,10 @@
  (name:gsub "([a-z0-9])([A-Z])" splicedash))

(fn mangle [name field]
  (when (and (not field) (. reserved name))
    (set-forcibly! name (.. "___" name "___")))
  (or (and field name) (: (uncamelize name) :gsub "([a-z0-9])_" "%1-")))
  (when (not field)
    (set-forcibly! name (: (uncamelize name) :gsub "([a-z0-9])_" "%1-"))
    (set-forcibly! name (or (and (. reserved name) (.. "___" name "___")) name)))
  name)

(fn compile [rdr filename]
  (let [ls (lex-setup rdr filename)
diff --git a/test.lua b/test.lua
index 5e6f799..e01872b 100644
--- a/test.lua
+++ b/test.lua
@@ -61,4 +61,9 @@ end
local _, _, two = bcd("two", "three")
assert(two == 2, "two")

local worldObjects, will_o_the_wisp
for i, match in ipairs({}) do
   noprint()
end

return (f123("path") or {}).mode
diff --git a/test_expected.fnl b/test_expected.fnl
index f97c5a6..32860dc 100644
--- a/test_expected.fnl
+++ b/test_expected.fnl
@@ -64,5 +64,10 @@

(assert (= two 2) :two)

(local (world-objects will-o-the-wisp) nil)

(each [i ___match___ (ipairs {})]
  (noprint))

(. (or (f123 :path) {}) :mode)

-- 
2.32.0
Details
Message ID
<87bl0mzrpl.fsf@mntre-builder>
In-Reply-To
<20220107042919.74567-1-xordspar0@gmail.com> (view parent)
DKIM signature
permerror
Download raw message
Jordan Christiansen <xordspar0@gmail.com> writes:

> Previously, reserved words like match would get mangled to ___match-__.
> While this is technically valid, it's a really strange variable name.
> The new mangling logic produces the intended ___match___.

Great catch; thanks! Applied and pushed, with a little tweak to the test
to make it a little more thorough.

-Phil
Details
Message ID
<OUHE5R.P4N6K7O7HXX2@gmail.com>
In-Reply-To
<87bl0mzrpl.fsf@mntre-builder> (view parent)
DKIM signature
pass
Download raw message
On Fri, Jan 7, 2022 at 10:06 pm, Phil Hagelberg <phil@hagelb.org> wrote:

> Great catch; thanks! Applied and pushed, with a little tweak to the 
> test
> to make it a little more thorough.

That is a good addition to the test. Thanks for the review and merge!
Reply to thread Export thread (mbox)