0
是否可以自定義cljs.reader/read-string
來處理類似"#(f 123)"
的問題?如何自定義「#(...)」的cljs.reader.read-string的調度宏
我嘗試這樣做:
(cljs.reader/register-tag-parser! \((fn [x] "test"))
(cljs.reader/read-string "#(f 123")
,但得到:
找不到標籤解析器(F IN( 「出師表」 的 「uuid」, 「排隊」, 「JS」 「(」)
更新:
多一點挖我碰到https://github.com/clojure/clojurescript/blob/6ff80dc2f309f961d2e363148b5c0da65ac320f9/src/test/cljs/cljs/pprint_test.cljs#L106來到後證實,這是目前不可能:
(simple-tests pprint-reader-macro-test
;;I'm not sure this will work without significant work on cljs. Short story, cljs
;;reader only takes valid EDN, so #(* % %) won't work.
;;see http://stackoverflow.com/a/25712675/546321 for more details
#_(with-pprint-dispatch code-dispatch
(write (reader/read-string "(map #(first %) [[1 2 3] [4 5 6] [7]])")
:stream nil))
#_"(map #(first %) [[1 2 3] [4 5 6] [7]])"
是的當然,我基本上是問如何擴展'dispatch-macros'函數的功能(https://github.com/clojure/clojurescript/blob/57819844b5a8da0464832f82426ac57ebdf2eaea/src/main/cljs/cljs/reader。 cljs#L443)通過'* tag-table *'方式在'read-dispatch'中分開使用,所以看起來可能有一種方法。在parens裏面的表達是可變的,所以我不能硬編碼'「(f」'。 – estolua