forked from clojure/clojurescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Reader
levand edited this page Jul 15, 2011
·
3 revisions
The reader is mostly complete. It follows the basic outline of LispReader.java, except in a non-object-oriented style and with some simplifications.
The code is all in the reader.cljs file. The primary function is read
, which takes an instance of the PushbackReader
protocol. An implementation of this protocol is provided, StringPushbackReader
, and may be constructed easily using the push-back-reader
function, which takes a string and converts it to a StringPushBackReader
.
There are a number of known issues/limitations.
- There are some cases where a map may be incorrectly read as a set. An example that does this consistently is the form
(1 2 3 {:a 1 :b 2})
- Does not support hexadecimal or custom-radix numeric literals (e.g, 0xA3 or 8r3). These cases will throw an "Invalid Number Format" error. Octal numbers starting with a 0 are parsed as base-10 numbers. This is due to a difference in the Javascript and Java regex engines: the regex used in both cases is identical. The javascript one needs to be tested and modified before hex, octal and custom-radix numbers will work.
- The performance of the StringPushbackReader is currently poor, since it actually modifying a string on each read/unread. It would be much faster if it were rewritten to work by indexing into a constant string, with a separate small buffer to hold pushbacks.