author | Alan Dipert
<alan@dipert.org> 2019-08-29 15:28:38 UTC |
committer | Alan Dipert
<alan@dipert.org> 2019-08-29 15:28:38 UTC |
parent | 93590b0fa0339c86cd55637494cd89b149d19f47 |
jacl.js | +16 | -12 |
diff --git a/jacl.js b/jacl.js index 033c4c0..bd5ec01 100644 --- a/jacl.js +++ b/jacl.js @@ -240,16 +240,20 @@ const skipWhitespace = async stream => { }; const dotIsNext = async stream => { - const x = await stream.read(), - y = await stream.read(); + const x = await stream.read(); - if (x === '.' && isWhitespace(y)) { - return true; - } else { - stream.unread(y); + if (x !== '.') { stream.unread(x); return false; } + + const y = await stream.read(); + + if (isWhitespace(y)) return true; + + stream.unread(y); + stream.unread(x); + return false; }; const closeParenIsNext = async stream => { @@ -268,19 +272,16 @@ const readList = async stream => { await skipWhitespace(stream); - if (await closeParenIsNext(stream)) - return new Values(null); - if (await dotIsNext(stream)) throw new Error(`Nothing before . in list`); + if (await closeParenIsNext(stream)) + return new Values(null); + const car = await rdr.read(); await skipWhitespace(stream); - if (await closeParenIsNext(stream)) - return new Values(new Cons(car)); - if (await dotIsNext(stream)) { await skipWhitespace(stream); if (await closeParenIsNext(stream)) @@ -292,6 +293,9 @@ const readList = async stream => { throw new Error(`More than one object after . in list`); } + if (await closeParenIsNext(stream)) + return new Values(new Cons(car)); + return new Values(new Cons(car, (await readList(stream))[0])); }