Reading comment should not throw exception

Description

I have notice a discrepancy in how comments are read between cljs.tools.reader/read-string and cljs.reader/read-string.

In cljs.reader, as shown here no exception is thrown but nil is returned, concretely ignoring the comment.

Conversely, the following throws:

(r/read-string {:read-cond :allow :features #{:cljs ;; comment) ;;+> EOF

In my opinion the cljs.reader is the correct one and cljs.tools.reader should be patched, but of course there might be a reason I ignore to throw an exception.

Environment

None

Activity

Show:
Nicola Mometto
November 17, 2015, 9:24 PM

This is consistent with how the clojure reader works, and the correct behaviour.
Reading a comment is not the same as reading nil

Andrea Richiardi
November 17, 2015, 11:40 PM

Can you expand on this a bit? The reader should ignore comments, so it is like the reader is actually reading nothing (therefore nil). Maybe I am missing?

Nicola Mometto
November 17, 2015, 11:45 PM

The reader must return the object it read. If there's nothing to read, an EOF exception signales that the stream terminated before it could find an object to read. Otherwise reading nil and reading nothing would mean different things in different contexts

Andrea Richiardi
November 17, 2015, 11:49 PM

Thanks, it was just for curiosity, of course a lot of clever people have already thought about this. I am then a bit surprised by the different behaviour in cljs.reader but this is another story.

Declined

Assignee

Nicola Mometto

Reporter

Andrea Richiardi

Labels

None

Approval

None

Patch

None

Priority

Minor