Skip to content

Instantly share code, notes, and snippets.

@cgrand
Last active April 21, 2017 08:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cgrand/8103832c25c5d84b489eb4ee5a4afa78 to your computer and use it in GitHub Desktop.

While writing a new reader I used clojure.lang.LispReader code as the reference and I discovered there are two type of spaces:

  • pure whitespace (anything that matches #"[ \t\n\r,]+"),
  • unvalued stuff (any sequence of: whitespace, comments, discard (#_), elided conditionals).

This leads to some quirks. For example in namespaced map syntax is:

namespaced-map:
  "#:" (?! whitespace) unvalued-stuff symbol whitespace map
| "#::" symbol? whitespace map

(where ?! is negative lookahead)

And indeed,

#:#_()#! bang bang
#?(:whatever 42); now a blank line

#?@(:default ())foo
{:bar :baz}

is readable and evaluates to #:foo{:bar :baz} just fine.

Note: many REPLs choke on this input (use clojure.main -r or call (read-string {:read-cond :allow} evil-string))

Likewise tagged literals actual syntax is:

tagged-literal:
  "#" (?! dispatch-char) unvalued-stuff symbol unvalued-stuff form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment