~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 fennel] Fix reserved word mangling

Details
Message ID
<20220107042226.73970-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

[fennel/patches/.build.yml] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CGZ5LNDYBYR2.21EENKC2ENAO6@cirno2>
In-Reply-To
<20220107042226.73970-1-xordspar0@gmail.com> (view parent)
DKIM signature
missing
Download raw message
fennel/patches/.build.yml: FAILED in 24s

[Fix reserved word mangling][0] from [Jordan Christiansen][1]

[0]: https://lists.sr.ht/~technomancy/fennel/patches/28025
[1]: xordspar0@gmail.com

✗ #665633 FAILED fennel/patches/.build.yml https://builds.sr.ht/~technomancy/job/665633

Re: [fennel/patches/.build.yml] build failed

Details
Message ID
<EGOB5R.LMW21A2PQCRU@gmail.com>
In-Reply-To
<CGZ5LNDYBYR2.21EENKC2ENAO6@cirno2> (view parent)
DKIM signature
pass
Download raw message
Sorry, wrong subject line. I'll resubmit this.
Reply to thread Export thread (mbox)