diff options
author | Case Duckworth | 2024-03-23 15:52:53 -0500 |
---|---|---|
committer | Case Duckworth | 2024-03-23 15:52:53 -0500 |
commit | 52b8d26e8c86fed84edae447169962dfbbec1659 (patch) | |
tree | 3a9eb938384e8c286739849b297d738dcb2b6750 | |
parent | Improve repl (diff) | |
download | lam-52b8d26e8c86fed84edae447169962dfbbec1659.tar.gz lam-52b8d26e8c86fed84edae447169962dfbbec1659.zip |
Read negative numbers
-rw-r--r-- | read.lua | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/read.lua b/read.lua index c3f3f64..9561d9f 100644 --- a/read.lua +++ b/read.lua | |||
@@ -124,13 +124,13 @@ read.readtable = { | |||
124 | ["."] = function(chars) return pop(chars), "dot", chars end, | 124 | ["."] = function(chars) return pop(chars), "dot", chars end, |
125 | ["\""] = consume_string, | 125 | ["\""] = consume_string, |
126 | [";"] = consume_comment, | 126 | [";"] = consume_comment, |
127 | -- ["#"] = | 127 | -- ["#"] = ..., |
128 | } | 128 | } |
129 | 129 | ||
130 | function read.scan (chars) | 130 | function read.scan (chars) |
131 | local chars = chars | 131 | local chars = chars |
132 | return function() | 132 | return function () |
133 | if #chars == 0 then return nil end | 133 | if not next(chars) then return nil end |
134 | local token, toktype = "", nil | 134 | local token, toktype = "", nil |
135 | while true do | 135 | while true do |
136 | if read.readtable[chars[1]] then | 136 | if read.readtable[chars[1]] then |
@@ -139,7 +139,7 @@ function read.scan (chars) | |||
139 | return token, toktype | 139 | return token, toktype |
140 | elseif chars[1]:match("%s") then | 140 | elseif chars[1]:match("%s") then |
141 | chars = consume_whitespace(chars) | 141 | chars = consume_whitespace(chars) |
142 | elseif chars[1]:match("%d") then | 142 | elseif chars[1]:match("[%d-]") then |
143 | token, chars = consume_number(chars) | 143 | token, chars = consume_number(chars) |
144 | return token, "number" | 144 | return token, "number" |
145 | else | 145 | else |