diff options
author | Case Duckworth | 2024-03-20 21:55:09 -0500 |
---|---|---|
committer | Case Duckworth | 2024-03-20 21:55:09 -0500 |
commit | 4dde2320effedfc1baac0a0b2011ab2ddbc20c74 (patch) | |
tree | 0fa7d06410633b2f0e715e96670735e85e3299e9 /read.lua | |
parent | Add luarepl target (diff) | |
download | lam-4dde2320effedfc1baac0a0b2011ab2ddbc20c74.tar.gz lam-4dde2320effedfc1baac0a0b2011ab2ddbc20c74.zip |
Support dotted lists in reader
Diffstat (limited to 'read.lua')
-rw-r--r-- | read.lua | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/read.lua b/read.lua index d21e4cb..064be61 100644 --- a/read.lua +++ b/read.lua | |||
@@ -121,6 +121,7 @@ read.readtable = { | |||
121 | ["'"] = function(chars) return pop(chars), "quote", chars end, | 121 | ["'"] = function(chars) return pop(chars), "quote", chars end, |
122 | ["`"] = function(chars) return pop(chars), "quote", chars end, | 122 | ["`"] = function(chars) return pop(chars), "quote", chars end, |
123 | [","] = function(chars) return pop(chars), "quote", chars end, | 123 | [","] = function(chars) return pop(chars), "quote", chars end, |
124 | ["."] = function(chars) return pop(chars), "dot", chars end, | ||
124 | ["\""] = consume_string, | 125 | ["\""] = consume_string, |
125 | [";"] = consume_comment, | 126 | [";"] = consume_comment, |
126 | -- ["#"] = | 127 | -- ["#"] = |
@@ -161,12 +162,20 @@ end | |||
161 | read.readmacros = { | 162 | read.readmacros = { |
162 | open = | 163 | open = |
163 | function (token, tokens) | 164 | function (token, tokens) |
164 | local L = {} | 165 | local L, lt = {}, nil |
165 | while tokens[1].type ~= "close" do | 166 | while tokens[1].type ~= "close" do |
166 | table.insert(L, read.parse(tokens)) | 167 | local nt = read.parse(tokens) |
168 | -- this isn't .. my /favorite/ implementation, | ||
169 | -- but it works | ||
170 | if nt == "." then | ||
171 | lt = read.parse(tokens) | ||
172 | break | ||
173 | else | ||
174 | table.insert(L, nt) | ||
175 | end | ||
167 | end | 176 | end |
168 | pop(tokens) -- remove final ")" | 177 | pop(tokens) -- remove final ")" |
169 | return type.List(L) | 178 | return type.List(L, lt) |
170 | end, | 179 | end, |
171 | close = | 180 | close = |
172 | function (token, tokens) | 181 | function (token, tokens) |