Reader conditionals

Description

See http://dev.clojure.org/display/design/Reader+Conditionals for design.

The implementation details contain several major parts:

1) LispReader changes to implement new conditional read syntax and features.

In RT:

  • suppress-read - new dynamic var

  • readString() - new arity that takes opts

In LispReader:

  • read(...) entry point - added new variants that take opts. The opts-only form will decode :eof into the correct values for eofIsError and eofValue. Internal forms take both opts and pendingForms (list).

  • All reader invoke dispatch methods now take both opts and pendingForms which get drug around the call stack.

  • Defined all option keys and well-known allowed values - OPT_EOF, OPT_FEATURES, OPT_READ_COND, EOFTHROW, PLATFORM_KEY, PLATFORM_FEATURES, COND_ALLOW, COND_PRESERVE.

  • read(...) entry point will ensure installation of {:features #{:clj}}, appropriately merging others or none. There is no path that will pass :features inside Clojure but users can call LispReader with it directly.

  • readDelimitedList() was refactored so it can share logic with readCondDelimited().

  • Luke can provide more detail on the guts of reader conditional reading if needed.

New ReaderConditional and TaggedLiteral types.

In clojure.core:

  • tagged-literal?, tagged-literal, reader-conditional?, reader-conditional - new functions to support the preserved data form of these

  • new print-method impls for TaggedLiteral and ReaderConditional

  • read - added new arity that takes opts and explain opts in docstring

  • read-string - added new arity that takes opts (placement matches edn/read-string and is designed for partial application)

2) cljc file changes.
In Compiler:

  • OPTS_COND_ALLOWED - keep around a map {:read-cond :allow} to invoke reader when reading .cljc files.

  • readerOpts() - new private function to determine reader options to use based on file name (.clj vs .cljc)

  • load() - use readerOpts() and invoke LispReader with them

  • compile() - use readerOpts() and invoke LispReader with them

In RT:

  • load(...) - check first for .clj file, then for .cljc file when looking by ns

In clojure.main - update code to allow for .clj and .cljc files
In clojure.repl - update code to allow for .clj and .cljc files

3) Tests + infrastructure updates.

  • Move test/clojure/test_clojure/reader.clj to test/clojure/test_clojure/reader.cljc so that we can test reader conditionals.

  • Bump version of test.generative to get newer version that depends on newer tools.namespace which is able to find .cljc files as source files. The test script at src/script/run_test.clj uses this to find Clojure test files and without the bump, it will not find the new reader.cljc test ns. Note: if you use the ant build, you need to re-run antsetup.sh for this to take effect.

  • src/script/run_test.clj - as part of the version bump, move from deprecated namespace to new namespace

  • Added lots of tests in reader.cljc

Patch: clj-1424-12.patch

Screened by:

Related: CLJS-27, TRDR-14

Environment

None

Attachments

12
  • 27 Mar 2015, 08:22 PM
  • 11 Mar 2015, 10:26 PM
  • 26 Feb 2015, 06:17 PM
  • 09 Feb 2015, 10:24 PM
  • 07 Feb 2015, 07:49 PM
  • 31 Jan 2015, 03:03 AM
  • 27 Jan 2015, 05:23 PM
  • 26 Jan 2015, 03:26 AM
  • 21 Jan 2015, 10:24 PM
  • 07 Nov 2014, 10:39 PM
  • 04 Aug 2014, 04:45 PM
  • 15 May 2014, 11:52 PM

Activity

Show:

Alex Miller April 2, 2015 at 4:15 PM

No, I think Stu just forgot to close it.

Nicola Mometto April 2, 2015 at 3:56 PM

Is there a reason why this ticket has been kept open despite the patch having been committed?

Alex Miller March 27, 2015 at 8:22 PM

-12 patch is same, just applies cleanly to current master

Fogus March 20, 2015 at 6:33 PM

I'm happy with the latest changes.

Alex Miller March 11, 2015 at 10:26 PM

Re fogus comments in new -11 patch:

  • clojure.core/read - updated docstring

  • clojure.core/read-string - clarified opts back-reference in docstring

  • clojure.core/tagged-literal - updated docstring

  • clojure.core/reader-conditional - updated docstring

  • clojure.core/print-method clojure.lang.TaggedLiteral - agreed, updated print form to match

  • Compiler.readerOpts - updated as suggested

  • LispReader.read(rdr, opts) - the IPersistentMap is intentional there and used via that interface, so no change

  • ConditionalReader.hasFeature() - improved error msg

  • ConditionalReader.invoke() - slightly altered error msg but I'm on the fence on this one. "form" is pretty precise there.

  • ConditionalReader.readCondDelimited() - this is in my opinion correct and expected as is

Completed

Details

Assignee

Reporter

Labels

Approval

Ok

Patch

Code and Test

Priority

Fix versions

Created May 15, 2014 at 11:50 PM
Updated April 2, 2015 at 4:15 PM
Resolved April 2, 2015 at 4:15 PM