@@ -74,6 +74,48 @@ function readsymbol(io::IO)
7474 String (take! (buf))
7575end
7676
77+ """
78+ A dot as in (a . b).
79+ """
80+ struct Dot end
81+
82+ """
83+ Build an improper list (a b . c).
84+ """
85+ function improperlist (prefix, terminal)
86+ if isempty (prefix)
87+ terminal
88+ else
89+ Cons (prefix[1 ], improperlist (prefix[2 : end ], terminal))
90+ end
91+ end
92+
93+ """
94+ Check that there are no . in objs, and return the list if so. Otherwise process the dots as
95+ they should be.
96+ """
97+ function listify (objs) :: List
98+ objs_ = collect (objs)
99+ dots = count (equalto (Dot ()), objs_)
100+ if dots == 0
101+ objs_
102+ elseif dots == 1
103+ if length (objs_) ≤ 2 || objs_[end - 1 ] != = Dot ()
104+ error (" invalid use of ." )
105+ else
106+ improperlist (objs_[1 : end - 2 ], objs_[end ])
107+ end
108+ elseif dots == 2
109+ if length (objs_) == 5 && objs_[2 ] === objs_[4 ] === Dot ()
110+ [objs_[3 ], objs_[1 ], objs_[5 ]]
111+ else
112+ error (" invalid use of ." )
113+ end
114+ else
115+ error (" invalid use of ." )
116+ end
117+ end
118+
77119"""
78120 nextobject(io::IO)
79121
@@ -94,7 +136,7 @@ function nextobject(io::IO)
94136 read (io, Char)
95137 cl = closer (c)
96138 objects = readobjectsuntil (io, cl)
97- Nullable (convert (List, objects))
139+ Nullable (listify ( objects))
98140 elseif c in " )]}"
99141 error (" mismatched superfluous $c " )
100142 elseif c in keys (_READER_MACROS)
@@ -109,7 +151,7 @@ function nextobject(io::IO)
109151 else
110152 str = readsymbol (io)
111153 if str == " ."
112- error ( " . currently unsupported " )
154+ Nullable ( Dot () )
113155 else
114156 asnumber = tryparse (Number, str)
115157 Nullable (get (asnumber, Symbol (str)))
0 commit comments