Skip to content

Commit

Permalink
change cljs.tools.reader.reader-types/log-source back to a macro
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Jul 5, 2015
1 parent 92f9344 commit d27be98
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 43 deletions.
69 changes: 34 additions & 35 deletions src/main/cljs/cljs/tools/reader.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
(:refer-clojure :exclude [read read-line read-string char
default-data-readers *default-data-reader-fn*
*data-readers* *suppress-read*])
(:require-macros [cljs.tools.reader.reader-types :refer [log-source]])
(:require [cljs.tools.reader.reader-types :refer
[read-char reader-error unread peek-char indexing-reader?
get-line-number get-column-number get-file-name
string-push-back-reader log-source]]
string-push-back-reader]]
[cljs.tools.reader.impl.utils :refer
[char ex-info? whitespace? numeric? desugar-meta next-id munge
ReaderConditional reader-conditional reader-conditional?]]
Expand Down Expand Up @@ -378,20 +379,19 @@
"Read metadata and return the following object with the metadata applied"
[rdr _ opts pending-forms]
(log-source rdr
(fn []
(let [[line column] (starting-line-col-info rdr)
m (desugar-meta (read* rdr true nil opts pending-forms))]
(when-not (map? m)
(reader-error rdr "Metadata must be Symbol, Keyword, String or Map"))
(let [o (read* rdr true nil opts pending-forms)]
(if (satisfies? IMeta o)
(let [m (if (and line (seq? o))
(assoc m :line line :column column)
m)]
(if (satisfies? IWithMeta o)
(with-meta o (merge (meta o) m))
(reset-meta! o m)))
(reader-error rdr "Metadata can only be applied to IMetas")))))))
(let [[line column] (starting-line-col-info rdr)
m (desugar-meta (read* rdr true nil opts pending-forms))]
(when-not (map? m)
(reader-error rdr "Metadata must be Symbol, Keyword, String or Map"))
(let [o (read* rdr true nil opts pending-forms)]
(if (satisfies? IMeta o)
(let [m (if (and line (seq? o))
(assoc m :line line :column column)
m)]
(if (satisfies? IWithMeta o)
(with-meta o (merge (meta o) m))
(reset-meta! o m)))
(reader-error rdr "Metadata can only be applied to IMetas"))))))

(defn- read-set
[rdr _ opts pending-forms]
Expand Down Expand Up @@ -835,26 +835,25 @@
(read* reader eof-error? sentinel nil opts pending-forms))
([reader eof-error? sentinel return-on opts pending-forms]
(try
((fn target []
(log-source reader
(fn []
(if (seq pending-forms)
(let [form (first pending-forms)]
(garray/removeAt pending-forms 0)
form)
(let [ch (read-char reader)]
(cond
(whitespace? ch) (trampoline target)
(nil? ch) (if eof-error? (reader-error reader "EOF") sentinel)
(= ch return-on) READ_FINISHED
(number-literal? reader ch) (read-number reader ch)
:else (let [f (macros ch)]
(if f
(let [res (f reader ch opts pending-forms)]
(if (identical? res reader)
(trampoline target)
res))
(read-symbol reader ch))))))))))
(loop []
(log-source reader
(if (seq pending-forms)
(let [form (first pending-forms)]
(garray/removeAt pending-forms 0)
form)
(let [ch (read-char reader)]
(cond
(whitespace? ch) (recur)
(nil? ch) (if eof-error? (reader-error reader "EOF") sentinel)
(= ch return-on) READ_FINISHED
(number-literal? reader ch) (read-number reader ch)
:else (let [f (macros ch)]
(if f
(let [res (f reader ch opts pending-forms)]
(if (identical? res reader)
(recur)
res))
(read-symbol reader ch))))))))
(catch js/Error e
(if (ex-info? e)
(let [d (ex-data e)]
Expand Down
10 changes: 10 additions & 0 deletions src/main/cljs/cljs/tools/reader/reader_types.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns cljs.tools.reader.reader-types)

(defmacro log-source
"If reader is a SourceLoggingPushbackReader, execute body in a source
logging context. Otherwise, execute body, returning the result."
[reader & body]
`(if (and (source-logging-reader? ~reader)
(not (cljs.tools.reader.impl.utils/whitespace? (peek-char ~reader))))
(log-source* ~reader (^:once fn* [] ~@body))
(do ~@body)))
8 changes: 0 additions & 8 deletions src/main/cljs/cljs/tools/reader/reader_types.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,3 @@ logging frames. Called when pushing a character back."
(finally
(swap! (.-frames reader) update-in [:offset] rest)))))

(defn log-source
"If reader is a SourceLoggingPushbackReader, execute body in a source
logging context. Otherwise, execute body, returning the result."
[reader body-fn]
(if (and (source-logging-reader? reader)
(not (whitespace? (peek-char reader))))
(log-source* reader body-fn)
(body-fn)))

0 comments on commit d27be98

Please sign in to comment.