about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--read.lua18
1 files changed, 16 insertions, 2 deletions
diff --git a/read.lua b/read.lua index 9561d9f..f23c5cc 100644 --- a/read.lua +++ b/read.lua
@@ -95,6 +95,11 @@ local consume_symbol = consume_token
95 95
96local function consume_number (chars) 96local function consume_number (chars)
97 local digits, chars = consume_token(chars) 97 local digits, chars = consume_token(chars)
98 -- The signs by themselves are symbols, as well as '...'
99 if digits:match("[-+.]") or digits == "..." then
100 return digits, chars
101 end
102 -- Otherwise try converting the digits to a number
98 local num = tonumber(digits) 103 local num = tonumber(digits)
99 if num == nil then error("Bad number: " .. num) end 104 if num == nil then error("Bad number: " .. num) end
100 return num, chars 105 return num, chars
@@ -121,7 +126,6 @@ read.readtable = {
121 ["'"] = function(chars) return pop(chars), "quote", chars end, 126 ["'"] = function(chars) return pop(chars), "quote", chars end,
122 ["`"] = function(chars) return pop(chars), "quote", chars end, 127 ["`"] = function(chars) return pop(chars), "quote", chars end,
123 [","] = function(chars) return pop(chars), "quote", chars end, 128 [","] = function(chars) return pop(chars), "quote", chars end,
124 ["."] = function(chars) return pop(chars), "dot", chars end,
125 ["\""] = consume_string, 129 ["\""] = consume_string,
126 [";"] = consume_comment, 130 [";"] = consume_comment,
127 -- ["#"] = ..., 131 -- ["#"] = ...,
@@ -139,9 +143,19 @@ function read.scan (chars)
139 return token, toktype 143 return token, toktype
140 elseif chars[1]:match("%s") then 144 elseif chars[1]:match("%s") then
141 chars = consume_whitespace(chars) 145 chars = consume_whitespace(chars)
142 elseif chars[1]:match("[%d-]") then 146 elseif chars[1]:match("%d") then
143 token, chars = consume_number(chars) 147 token, chars = consume_number(chars)
144 return token, "number" 148 return token, "number"
149 elseif chars[1]:match("[.+-]") then
150 -- special casing for ., ..., +, -
151 token, chars = consume_number(chars)
152 if token == "." then
153 return token, "dot"
154 elseif token == "..." then
155 return token, "symbol"
156 else
157 return token, "number"
158 end
145 else 159 else
146 token, chars = consume_symbol(chars) 160 token, chars = consume_symbol(chars)
147 return token, "symbol" 161 return token, "symbol"