Skip to content
Browse files

Refactoring tag readers and providing more error checks

  • Loading branch information...
1 parent 73d4cd1 commit 6d777e99fcfba1be7254c85cacff0a3f02cac807 @fogus fogus committed Jun 14, 2012
Showing with 34 additions and 24 deletions.
  1. +2 −23 src/clj/cljs/compiler.clj
  2. +2 −1 src/clj/cljs/repl.clj
  3. +30 −0 src/clj/cljs/tagged_literals.clj
View
25 src/clj/cljs/compiler.clj
@@ -12,7 +12,7 @@
(:refer-clojure :exclude [munge macroexpand-1])
(:require [clojure.java.io :as io]
[clojure.string :as string]
- [clojure.instant :as inst])
+ [cljs.tagged-literals :as tags])
(:import java.lang.StringBuilder))
(declare resolve-var)
@@ -1576,27 +1576,6 @@
(set? form) (analyze-set env form name)
:else {:op :constant :env env :form form}))))
-(defn read-queue
- [form]
- (assert (vector? form) "Queue literal expects a vector for its elements.")
- (list 'cljs.core/into 'cljs.core.PersistentQueue/EMPTY form))
-
-(defn read-uuid
- [form]
- (assert (string? form) "UUID literal expects a string as its representation.")
- (list (symbol "UUID.") form))
-
-(defn read-inst
- [form]
- (assert (string? form) "Instance literal expects a string for its timestamp.")
- (let [^java.util.Date d (inst/read-instant-date form)]
- (list (symbol "js/Date.") (.getTime d))))
-
-(def ^:dynamic *cljs-data-readers*
- {'queue read-queue
- 'uuid read-uuid
- 'inst read-inst})
-
(defn analyze-file
[f]
(let [res (if (= \/ (first f)) f (io/resource f))]
@@ -1646,7 +1625,7 @@
(binding [*out* out
*cljs-ns* 'cljs.user
*cljs-file* (.getPath ^java.io.File src)
- *data-readers* *cljs-data-readers*
+ *data-readers* tags/*cljs-data-readers*
*position* (atom [0 0])]
(loop [forms (forms-seq src)
ns-name nil
View
3 src/clj/cljs/repl.clj
@@ -11,6 +11,7 @@
(:require [clojure.string :as string]
[clojure.java.io :as io]
[cljs.compiler :as comp]
+ [cljs.tagged-literals :as tags]
[cljs.closure :as cljsc]))
(def ^:dynamic *cljs-verbose* false)
@@ -130,7 +131,7 @@
(defn- read-next-form []
(try {:status :success :form (binding [*ns* (create-ns comp/*cljs-ns*)
- *data-readers* comp/*cljs-data-readers*]
+ *data-readers* tags/*cljs-data-readers*]
(read))}
(catch Exception e
(println (.getMessage e))
View
30 src/clj/cljs/tagged_literals.clj
@@ -0,0 +1,30 @@
+(ns cljs.tagged-literals
+ (:require [clojure.instant :as inst]))
+
+(defn read-queue
+ [form]
+ (assert (vector? form) "Queue literal expects a vector for its elements.")
+ (list 'cljs.core/into 'cljs.core.PersistentQueue/EMPTY form))
+
+(defn read-uuid
+ [form]
+ (assert (string? form) "UUID literal expects a string as its representation.")
+ (try
+ (let [uuid (java.util.UUID/fromString form)]
+ (list (symbol "UUID.") form))
+ (catch Throwable e
+ (throw (RuntimeException. (.getMessage e))))))
+
+(defn read-inst
+ [form]
+ (assert (string? form) "Instance literal expects a string for its timestamp.")
+ (try
+ (let [^java.util.Date d (inst/read-instant-date form)]
+ (list (symbol "js/Date.") (.getTime d)))
+ (catch Throwable e
+ (throw (RuntimeException. (.getMessage e))))))
+
+(def ^:dynamic *cljs-data-readers*
+ {'queue read-queue
+ 'uuid read-uuid
+ 'inst read-inst})

0 comments on commit 6d777e9

Please sign in to comment.
Something went wrong with that request. Please try again.