From 422f5a6c500c7a8aa9cd9da466a53117d7596d8c Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 30 Mar 2024 22:29:02 -0500 Subject: Fix dotted list reading --- read.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/read.lua b/read.lua index 226af51..f50fa40 100644 --- a/read.lua +++ b/read.lua @@ -97,7 +97,6 @@ function m.scan (cs) while true do if m.readtable[cs[1]] then token, toktype, cs = m.readtable[cs[1]](cs) - -- return { v = token, u = toktype }, cs return token, toktype, cs elseif cs[1]:match("%s") then _, cs = consume_whitespace(cs) @@ -108,20 +107,16 @@ function m.scan (cs) local token, cs = consume_token(cs) if token:match("[-+]") or token == "..." then return token, "symbol", cs - -- return { v = token, u = "symbol" }, cs elseif token == "." then return token, "dot", cs - -- return { v = token, u = "dot" }, cs else local n = tonumber(token) assert (n ~= nil, "Bad number: "..n) return n, "number", cs - -- return { v = n, u = "number" }, cs end else token, cs = consume_token(cs) return token, "symbol", cs - -- return { v = token, u = "symbol" }, cs end end end @@ -145,6 +140,16 @@ function m.read (port) local tok, toktype = port:next_token() if toktype == "close" then return t.list(L) + elseif toktype == "dot" then + local nxt, nxttype = port:next_token() + if nxttype == "close" then + error("Unexpected ')'") + end + local fin, fintype = port:next_token() + if fintype ~= "close" then + error("Too many after dot") + end + return t.list(L, nxt) else table.insert(L, read_ahead(tok, toktype)) -- cgit 1.4.1-21-gabe81