Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Support for parsing literal symbols, chars, booleans, regexes and nil

  • Loading branch information...
commit 1b944180def23f269f34ed91bebd87ff7aebde65 1 parent a83216f
Tero Parviainen authored
Showing with 8 additions and 6 deletions.
  1. +8 −6 src/marginalia/parser.clj
14 src/marginalia/parser.clj
@@ -109,7 +109,7 @@
(defn parse* [reader]
- :form
+ #(not= :_eof (:form %))
(fn []
@@ -118,7 +118,7 @@
(let [start (.getLineNumber reader)
form (binding [*comments* sub-level-comments]
(try (. clojure.lang.LispReader
- (read reader false nil false))
+ (read reader false :_eof false))
(catch Exception ex
(let [msg (str "Problem parsing near line " start
" <" (.readLine reader) ">"
@@ -247,12 +247,14 @@
[form raw nspace-sym]
[nil raw])
+(defn- literal-form? [form]
+ (or (string? form) (number? form) (keyword? form) (symbol? form)
+ (char? form) (true? form) (false? form) (instance? java.util.regex.Pattern form)))
(defmethod dispatch-form :default
[form raw nspace-sym]
- ;; Strings which are inlined into clojure files outside of forms are parsed
- ;; as `String` instances, while numbers - as `Number` subclasses.
- (cond (or (string? form) (number? form) (keyword? form))
- (dispatch-literal form raw nspace-sym)
+ (cond (literal-form? form)
+ (dispatch-literal form raw nspace-sym)
(and (first form)
(.isInstance clojure.lang.Named (first form))
(re-find #"^def" (-> form first name)))
Please sign in to comment.
Something went wrong with that request. Please try again.