Skip to content

Commit 61253ea

Browse files
committed
Namespaced maps now handle all Clojure whitespace
Was only allow spaces, now also allowing newlines and commas. Fixes #140
1 parent 56ff987 commit 61253ea

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ For a list of breaking changes see link:#v1-breaking[breaking changes].
1616

1717
=== Unreleased
1818

19+
* namespaced map should allow all Clojure whitespace between prefix and map https://github.com/clj-commons/rewrite-clj/issues/140[#140]
1920
* Beef up docs on node creation https://github.com/clj-commons/rewrite-clj/issues/97[#97]
2021
* Describe subedit in docs https://github.com/clj-commons/rewrite-clj/issues/111[#111]
2122

src/rewrite_clj/parser/namespaced_map.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns ^:no-doc rewrite-clj.parser.namespaced-map
22
(:require [rewrite-clj.node.namespaced-map :as nsmap]
33
[rewrite-clj.node.protocols :as node]
4+
[rewrite-clj.node.whitespace :as nws]
45
[rewrite-clj.reader :as reader] ))
56

67
#?(:clj (set! *warn-on-reflection* true))
@@ -16,7 +17,7 @@
1617
(defn- parse-to-next-elem [reader read-next]
1718
(loop [nodes []]
1819
(let [n (read-next reader)]
19-
(if (and n (= :whitespace (node/tag n)))
20+
(if (and n (nws/whitespace? n))
2021
(recur (conj nodes n))
2122
[nodes n]))))
2223

test/rewrite_clj/parser_test.cljc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@
345345
"#:abc {:x 1, :y 1}"
346346
{:abc/x 1, :abc/y 1}
347347

348+
"#:abc ,,, \n\n {:x 1 :y 2}"
349+
{:abc/x 1, :abc/y 2}
350+
348351
"#:foo{:kw 1, :n/kw 2, :_/bare 3, 0 4}"
349352
{:foo/kw 1, :n/kw 2, :bare 3, 0 4}
350353

@@ -372,6 +375,10 @@
372375
{:?_current-ns_?/x 1, :?_current-ns_?/y 1}
373376
{:booya.fooya/x 1, :booya.fooya/y 1}
374377

378+
"#:: \n,,\n,, {:x 1, :y 1}"
379+
{:?_current-ns_?/x 1, :?_current-ns_?/y 1}
380+
{:booya.fooya/x 1, :booya.fooya/y 1}
381+
375382
"#::{:kw 1, :n/kw 2, :_/bare 3, 0 4}"
376383
{:?_current-ns_?/kw 1, :n/kw 2, :bare 3, 0 4}
377384
{:booya.fooya/kw 1, :n/kw 2, :bare 3, 0 4}
@@ -403,6 +410,10 @@
403410
'{:??_nsalias_??/x 1, :??_nsalias_??/y 1}
404411
'{:bing.bang/x 1, :bing.bang/y 1}
405412

413+
"#::nsalias ,,,,,,,,,,\n,,,,,,\n,,,,, {:x 1, :y 1}"
414+
'{:??_nsalias_??/x 1, :??_nsalias_??/y 1}
415+
'{:bing.bang/x 1, :bing.bang/y 1}
416+
406417
"#::nsalias{:kw 1, :n/kw 2, :_/bare 3, 0 4}"
407418
'{:??_nsalias_??/kw 1, :n/kw 2, :bare 3, 0 4}
408419
'{:bing.bang/kw 1, :n/kw 2, :bare 3, 0 4}

0 commit comments

Comments
 (0)