reader: one-char literals for non-symbol chars (\{ \( \, \%)
read-char read the char name with symbol-char?, so a literal whose char isn't a
symbol char (\{, \(, \), \,, \%, …) came back as an empty name and errored
'Unsupported character'. Now a single non-symbol char after \ is taken as a
one-character literal of that char. Surfaced by funcool/cuerdas (uses \{), which
now loads. Spec cases added.
This commit is contained in:
parent
b3a145f124
commit
d724aa7069
3 changed files with 18 additions and 5 deletions
|
|
@ -314,9 +314,15 @@
|
|||
|
||||
(defn read-char [s pos]
|
||||
# pos is at backslash; produce a char value directly (self-evaluating)
|
||||
(let [end (read-char-name-end s (+ pos 1))
|
||||
char-name (string/slice s (+ pos 1) end)]
|
||||
[(char-from-name char-name) end]))
|
||||
(when (>= (+ pos 1) (length s))
|
||||
(error "unexpected end of input after \\"))
|
||||
(let [end (read-char-name-end s (+ pos 1))]
|
||||
(if (= end (+ pos 1))
|
||||
# The char right after \ isn't a symbol char (e.g. \{ \( \, \% \" ): it's a
|
||||
# one-character literal of that character itself.
|
||||
[(make-char (s (+ pos 1))) (+ pos 2)]
|
||||
(let [char-name (string/slice s (+ pos 1) end)]
|
||||
[(char-from-name char-name) end]))))
|
||||
|
||||
(defn read-anon-fn [s pos]
|
||||
# pos is at #, next char is (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue