~technomancy/fennel

[PATCH 1/2] Enforce issymbolchar at the beginning of symbols too.

Details
Message ID
<20190901161427.29654-2-phil@hagelb.org>
DKIM signature
missing
Download raw message
Patch: +5 -1
Previously we would allow symbols with illegal characters as long as
the illegal character was the first one.
---
 fennel.lua | 4 +++-
 test.lua   | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/fennel.lua b/fennel.lua
index 7792184..00a970b 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -361,7 +361,7 @@ local function parser(getbyte, filename)
                     end
                 end
                 ungetb(nextb)
-            else -- Try symbol
+            elseif issymbolchar(b) then -- Try symbol
                 local chars = {}
                 local bytestart = byteindex
                 repeat
@@ -394,6 +394,8 @@ local function parser(getbyte, filename)
                     end
                     dispatch(x)
                 end
+            else
+                parseError("illegal character: " .. string.char(b))
             end
         until done
         return true, retval
diff --git a/test.lua b/test.lua
index e313d3c..c148b47 100644
--- a/test.lua
+++ b/test.lua
@@ -506,6 +506,8 @@ local compile_failures = {
     ["(global 48 :forty-eight)"]="unable to bind 48",
     ["(let [t []] (set t.47 :forty-seven))"]=
         "can't start multisym segment with digit: t.47",
+    ["(local a~b 3)"]="illegal character: ~",
+    ["(print @)"]="illegal character: @",
     -- other
     ["(match [1 2 3] [a & b c] nil)"]="rest argument in final position",
     ["(x(y))"]="expected whitespace before opening delimiter %(",
-- 
2.11.0