/
node.cljc
846 lines (684 loc) · 27.2 KB
/
node.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
;; DO NOT EDIT FILE, automatically generated from: ./template/rewrite_clj/node.cljc
(ns rewrite-clj.node
"Create, update, convert and integorate nodes.
All nodes represent Clojure/ClojureScript/EDN.
Because this API contains many functions, we offer the following categorized listing:
**Node creation**
[[comma-node]]
[[comment-node]]
[[deref-node]]
[[eval-node]]
[[fn-node]]
[[forms-node]]
[[integer-node]]
[[keyword-node]]
[[map-node]]
[[map-qualifier-node]]
[[meta-node]]
[[namespaced-map-node]]
[[newline-node]]
[[quote-node]]
[[raw-meta-node]]
[[reader-macro-node]]
[[regex-node]]
[[set-node]]
[[string-node]]
[[syntax-quote-node]]
[[token-node]]
[[uneval-node]]
[[unquote-node]]
[[unquote-splicing-node]]
[[var-node]]
[[vector-node]]
[[whitespace-node]]
**Whitespace creation convenience**
[[spaces]]
[[newlines]]
[[comma-separated]]
[[line-separated]]
[[whitespace-nodes]]
**Convert form to node**
[[coerce]]
**Convert node to form**
[[sexpr-able?]]
[[sexpr]]
[[sexprs]]
[[child-sexprs]]
**Convert node to string**
[[string]]
**Node interogation**
[[tag]]
[[inner?]]
[[children]]
[[length]]
[[leader-length]]
[[printable-only?]]
**Update node**
[[replace-children]]
**Namespaced map element support**
[[map-context-apply]]
[[map-context-clear]]
**Test type**
[[node?]]
[[comment?]]
[[whitespace-or-comment?]]
[[keyword-node?]]
[[symbol-node?]]
[[linebreak?]]
[[comma?]]"
^{:added "0.4.0"}
(:refer-clojure :exclude [string coerce])
(:require [rewrite-clj.node.coercer]
[rewrite-clj.node.comment]
[rewrite-clj.node.extras]
[rewrite-clj.node.fn]
[rewrite-clj.node.forms]
[rewrite-clj.node.integer]
[rewrite-clj.node.keyword]
[rewrite-clj.node.meta]
[rewrite-clj.node.namespaced-map]
[rewrite-clj.node.protocols]
[rewrite-clj.node.quote]
[rewrite-clj.node.reader-macro]
[rewrite-clj.node.regex]
[rewrite-clj.node.seq]
[rewrite-clj.node.stringz]
[rewrite-clj.node.token]
[rewrite-clj.node.uneval]
[rewrite-clj.node.whitespace]))
#?(:clj (set! *warn-on-reflection* true))
;; ## API Facade
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn coerce
"Coerce `form` to node."
[form] (rewrite-clj.node.protocols/coerce form))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn children
"Returns child nodes for `node`."
[node] (rewrite-clj.node.protocols/children node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn child-sexprs
"Returns children for `node` converted to Clojure forms.
Optional `opts` can specify:
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)"
([node] (rewrite-clj.node.protocols/child-sexprs node))
([node opts] (rewrite-clj.node.protocols/child-sexprs node opts)))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn inner?
"Returns true if `node` can have children."
[node] (rewrite-clj.node.protocols/inner? node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn leader-length
"Returns number of characters before children for `node`."
[node] (rewrite-clj.node.protocols/leader-length node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn length
"Return number of characters for the string version of `node`."
[node] (rewrite-clj.node.protocols/length node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn node?
"Returns true if `x` is a rewrite-clj created node."
[x] (rewrite-clj.node.protocols/node? x))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn printable-only?
"Return true if `node` cannot be converted to an s-expression element."
[node] (rewrite-clj.node.protocols/printable-only? node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn replace-children
"Returns `node` replacing current children with `children`."
[node children] (rewrite-clj.node.protocols/replace-children node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn sexpr
"Return `node` converted to form.
Optional `opts` can specify:
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)
See docs for [sexpr nuances](/doc/01-user-guide.adoc#sexpr-nuances)."
([node] (rewrite-clj.node.protocols/sexpr node))
([node opts] (rewrite-clj.node.protocols/sexpr node opts)))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn sexpr-able?
"Return true if [[sexpr]] is supported for `node`'s element type.
See [related docs in user guide](/doc/01-user-guide.adoc#not-all-clojure-is-sexpr-able)"
[node] (rewrite-clj.node.protocols/sexpr-able? node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn sexprs
"Return forms for `nodes`. Nodes that do not represent s-expression are skipped.
Optional `opts` can specify:
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)
See docs for [sexpr nuances](/doc/01-user-guide.adoc#sexpr-nuances)."
([nodes] (rewrite-clj.node.protocols/sexprs nodes))
([nodes opts] (rewrite-clj.node.protocols/sexprs nodes opts)))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn map-context-apply
"Applies `map-qualifier` context to `node`"
[node map-qualifier] (rewrite-clj.node.protocols/map-context-apply node map-qualifier))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn map-context-clear
"Removes map-qualifier context for `node`"
[node] (rewrite-clj.node.protocols/map-context-clear node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn string
"Return the string version of `node`."
[node] (rewrite-clj.node.protocols/string node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn tag
"Returns keyword representing type of `node`."
[node] (rewrite-clj.node.protocols/tag node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.protocols
(defn ^{:deprecated "0.4.0"} value
"DEPRECATED: Get first child as a pair of tag/sexpr (if inner node),
or just the node's own sexpr. (use explicit analysis of `children`
`child-sexprs` instead) "
[node] (rewrite-clj.node.protocols/value node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.comment
(defn comment-node
"Create node representing a comment with text `s`.
You may optionally specify a `prefix` of `\";\"` or `\"#!\"`, defaults is `\";\"`.
Argument `s`:
- must not include the `prefix`
- usually includes the trailing newline character, otherwise subsequent nodes will be on the comment line
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/comment-node \"; my comment\\n\")
n/string)
;; => \";; my comment\\n\"
(-> (n/comment-node \"#!\" \"/usr/bin/env bb\\n\")
n/string)
;; => \"#!/usr/bin/env bb\\n\"
```"
([s] (rewrite-clj.node.comment/comment-node s))
([prefix s] (rewrite-clj.node.comment/comment-node prefix s)))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.comment
(defn comment?
"Returns true if `node` is a comment."
[node] (rewrite-clj.node.comment/comment? node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.extras
(defn whitespace-or-comment?
"Check whether the given node represents whitespace or comment."
[node] (rewrite-clj.node.extras/whitespace-or-comment? node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.fn
(defn fn-node
"Create node representing an anonymous function with `children`.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/fn-node [(n/token-node '+)
(n/spaces 1)
(n/token-node 1)
(n/spaces 1)
(n/token-node '%1)])
n/string)
;; => \"#(+ 1 %1)\"
```"
[children] (rewrite-clj.node.fn/fn-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.forms
(defn forms-node
"Create top-level node wrapping multiple `children`.
The forms node is equivalent to an implicit `do` at the top-level.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/forms-node [(n/token-node 1)
(n/spaces 1)
(n/token-node 2)])
n/string)
;; => \"1 2\"
```
"
[children] (rewrite-clj.node.forms/forms-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.integer
(defn integer-node
"Create node representing an integer `value` in `base`.
`base` defaults to 10.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/integer-node 42)
n/string)
;; => \"42\"
(-> (n/integer-node 31 2)
n/string)
;; => \"2r11111\"
```
Note: the parser does not currently parse to integer-nodes, but they fully supported for output."
([value] (rewrite-clj.node.integer/integer-node value))
([value base] (rewrite-clj.node.integer/integer-node value base)))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.keyword
(defn keyword-node
"Create a node representing a keyword `k`.
Optionally include `auto-resolved?`, which defaults to `false`.
```Clojure
(require '[rewrite-clj.node :as n])
;; unqualified keyword
(-> (n/keyword-node :kw)
n/string)
;; => \":kw\"
;; qualified keyword
(-> (n/keyword-node :my-prefix/kw)
n/string)
;; => \":my-prefix/kw\"
;; keyword auto-resolved to current ns
(-> (n/keyword-node :kw true)
n/string)
;; => \"::kw\"
;; keyword auto-resolved to a namespace with given alias
(-> (n/keyword-node :ns-alias/kw true)
n/string)
;; => \"::ns-alias/kw\"
```"
([k auto-resolved?] (rewrite-clj.node.keyword/keyword-node k auto-resolved?))
([k] (rewrite-clj.node.keyword/keyword-node k)))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.keyword
(defn keyword-node?
"Returns true if `n` is a node representing a keyword."
[n] (rewrite-clj.node.keyword/keyword-node? n))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.meta
(defn meta-node
"Create a node representing a form with metadata.
When creating manually, you can specify `metadata` and `data` and spacing between the 2 elems will be included:
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/meta-node (n/keyword-node :foo)
(n/vector-node [(n/token-node 1)]))
n/string)
;; => \"^:foo [1]\"
(-> (n/meta-node (n/map-node [:foo (n/spaces 1) 42])
(n/vector-node [(n/token-node 1)]))
n/string)
;; => \"^{:foo 42} [1]\"
```
When specifying a sequence of `children`, spacing is explicit:
```Clojure
(-> (n/meta-node [(n/keyword-node :foo)
(n/spaces 1)
(n/vector-node [(n/token-node 1)])])
n/string)
;; => \"^:foo [1]\"
```
See also: [[raw-meta-node]]"
([children] (rewrite-clj.node.meta/meta-node children))
([metadata data] (rewrite-clj.node.meta/meta-node metadata data)))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.meta
(defn raw-meta-node
"Create a node representing a form with metadata that renders to the reader syntax.
When creating manually, you can specify `metadata` and `data` and spacing between the 2 elems will be included:
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/raw-meta-node (n/keyword-node :foo)
(n/vector-node [(n/token-node 2)]))
n/string)
;; => \"#^:foo [2]\"
(-> (n/raw-meta-node (n/map-node [:foo (n/spaces 1) 42])
(n/vector-node [(n/token-node 2)]))
n/string)
;; => \"#^{:foo 42} [2]\"
```
When specifying a sequence of `children`, spacing is explicit:
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/raw-meta-node [(n/keyword-node :foo)
(n/spaces 1)
(n/vector-node [(n/token-node 2)])])
n/string)
;; => \"#^:foo [2]\"
```
See also: [[meta-node]]"
([children] (rewrite-clj.node.meta/raw-meta-node children))
([metadata data] (rewrite-clj.node.meta/raw-meta-node metadata data)))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.namespaced-map
(defn map-qualifier-node
"Create a map qualifier node.
The map qualifier node is a child node of [[namespaced-map-node]].
```Clojure
(require '[rewrite-clj.node :as n])
;; qualified
(-> (n/map-qualifier-node false \"my-prefix\")
n/string)
;; => \":my-prefix\"
;; auto-resolved to current ns
(-> (n/map-qualifier-node true nil)
n/string)
;; => \"::\"
;; auto-resolve to namespace with alias
(-> (n/map-qualifier-node true \"my-ns-alias\")
n/string)
;; => \"::my-ns-alias\"
```"
[auto-resolved? prefix] (rewrite-clj.node.namespaced-map/map-qualifier-node auto-resolved? prefix))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.namespaced-map
(defn namespaced-map-node
"Create a namespaced map node with `children`.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/namespaced-map-node [(n/map-qualifier-node true \"my-ns-alias\")
(n/spaces 1)
(n/map-node [(n/keyword-node :a)
(n/spaces 1)
(n/token-node 1)])])
n/string)
;; => \"#::my-ns-alias {:a 1}\"
```
Map qualifier context is automatically applied to map keys for sexpr support.
See also [[map-qualifier-node]] and [[map-node]]."
[children] (rewrite-clj.node.namespaced-map/namespaced-map-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.regex
(defn regex-node
"Create node representing a regex with `pattern-string`.
Use same escape rules for `pattern-string` as you would for `(re-pattern \"pattern-string\")`
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/regex-node \"my\\\\.lil.*regex\")
n/string)
;; => \"#\\\"my\\\\.lil.*regex\\\"\"
```"
[pattern-string] (rewrite-clj.node.regex/regex-node pattern-string))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.reader-macro
(defn deref-node
"Create node representing the dereferencing of a form
where `children` is either a sequence of nodes or a single node.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/deref-node (n/token-node 'my-var))
n/string)
;; => \"@my-var\"
;; specifying a sequence allows for whitespace between @ and form
(-> (n/deref-node [(n/spaces 2)
(n/token-node 'my-var)])
n/string)
;; => \"@ my-var\"
```"
[children] (rewrite-clj.node.reader-macro/deref-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.reader-macro
(defn eval-node
"Create node representing an inline evaluation
where `children` is either a sequence of nodes or a single node.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/eval-node (n/list-node [(n/token-node 'inc)
(n/spaces 1)
(n/token-node 1)]))
n/string)
;; => \"#=(inc 1)\"
;; specifying a sequence allows for whitespace between the
;; prefix and the form
(-> (n/eval-node [(n/spaces 3)
(n/list-node [(n/token-node 'inc)
(n/spaces 1)
(n/token-node 1)])])
n/string)
;; => \"#= (inc 1)\"
```"
[children] (rewrite-clj.node.reader-macro/eval-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.reader-macro
(defn reader-macro-node
"Create node representing a reader macro with `macro-node` and `form-node` or `children`.
```Clojure
(require '[rewrite-clj.node :as n])
;; here we call with macro-node and form-node
(-> (n/reader-macro-node (n/token-node 'my-macro)
(n/token-node 42))
n/string)
;; => \"#my-macro 42\"
;; calling with a sequence of children gives us control over whitespace
(-> (n/reader-macro-node [(n/token-node 'my-macro)
(n/spaces 4)
(n/token-node 42)])
n/string)
;; => \"#my-macro 42\"
```"
([children] (rewrite-clj.node.reader-macro/reader-macro-node children))
([macro-node form-node] (rewrite-clj.node.reader-macro/reader-macro-node macro-node form-node)))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.reader-macro
(defn var-node
"Create node representing a var where `children` is either a
sequence of nodes or a single node.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/var-node (n/token-node 'my-var))
n/string)
;; => \"#'my-var\"
;; specifying a sequence allows for whitespace between the
;; prefix and the var
(-> (n/var-node [(n/spaces 2)
(n/token-node 'my-var)])
n/string)
;; => \"#' my-var\"
```"
[children] (rewrite-clj.node.reader-macro/var-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.seq
(defn list-node
"Create a node representing a list with `children`.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/list-node [(n/token-node 1)
(n/spaces 1)
(n/token-node 2)
(n/spaces 1)
(n/token-node 3)])
n/string)
;; => \"(1 2 3)\"
```"
[children] (rewrite-clj.node.seq/list-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.seq
(defn map-node
"Create a node representing a map with `children`.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/map-node [(n/keyword-node :a)
(n/spaces 1)
(n/token-node 1)
(n/spaces 1)
(n/keyword-node :b)
(n/spaces 1)
(n/token-node 2)])
(n/string))
;; => \"{:a 1 :b 2}\"
```
Note that rewrite-clj allows the, technically illegal, unbalanced map:
```Clojure
(-> (n/map-node [(n/keyword-node :a)])
(n/string))
;; => \"{:a}\"
```
See [docs on unbalanced maps](/doc/01-user-guide.adoc#unbalanced-maps).
Rewrite-clj also allows the, also technically illegal, map with duplicate keys:
```Clojure
(-> (n/map-node [(n/keyword-node :a)
(n/spaces 1)
(n/token-node 1)
(n/spaces 1)
(n/keyword-node :a)
(n/spaces 1)
(n/token-node 2)])
(n/string))
;; => \"{:a 1 :a 2}\"
```
See [docs on maps with duplicate keys](/doc/01-user-guide.adoc#maps-with-duplicate-keys)."
[children] (rewrite-clj.node.seq/map-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.seq
(defn set-node
"Create a node representing a set with `children`.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/set-node [(n/token-node 1)
(n/spaces 1)
(n/token-node 2)
(n/spaces 1)
(n/token-node 3)])
n/string)
;; => \"#{1 2 3}\"
```
Note that rewrite-clj allows the, technically illegal, set with duplicate values:
```Clojure
(-> (n/set-node [(n/token-node 1)
(n/spaces 1)
(n/token-node 1)])
(n/string))
;; => \"#{1 1}\"
```
See [docs on sets with duplicate values](/doc/01-user-guide.adoc#sets-with-duplicate-values)."
[children] (rewrite-clj.node.seq/set-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.seq
(defn vector-node
"Create a node representing a vector with `children`.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/vector-node [(n/token-node 1)
(n/spaces 1)
(n/token-node 2)
(n/spaces 1)
(n/token-node 3)])
n/string)
;; => \"[1 2 3]\"
```"
[children] (rewrite-clj.node.seq/vector-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.stringz
(defn string-node
"Create node representing a string value where `lines` can be a sequence of strings or a single string.
When `lines` is a sequence, the resulting node will `tag` will be `:multi-line`, otherwise `:token`.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/string-node \"hello\")
n/string)
;; => \"\\\"hello\\\"\"
(-> (n/string-node [\"line1\" \"\" \"line3\"])
n/string)
;; => \"\\\"line1\\n\\nline3\\\"\"
```"
[lines] (rewrite-clj.node.stringz/string-node lines))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.quote
(defn quote-node
"Create node representing a single quoted form where `children`
is either a sequence of nodes or a single node.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/quote-node (n/token-node 'sym))
(n/string))
;; => \"'sym\"
;; specifying a sequence allows for whitespace between the
;; quote and the quoted
(-> (n/quote-node [(n/spaces 10)
(n/token-node 'sym1) ])
n/string)
;; => \"' sym1\"
```"
[children] (rewrite-clj.node.quote/quote-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.quote
(defn syntax-quote-node
"Create node representing a single syntax-quoted form where `children`
is either a sequence of nodes or a single node.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/syntax-quote-node (n/token-node 'map))
n/string)
;; => \"`map\"
;; specifying a sequence allows for whitespace between the
;; syntax quote and the syntax quoted
(-> (n/syntax-quote-node [(n/spaces 3)
(n/token-node 'map)])
n/string)
;; => \"` map\"
```"
[children] (rewrite-clj.node.quote/syntax-quote-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.quote
(defn unquote-node
"Create node representing a single unquoted form where `children`
is either a sequence of nodes or a single node.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/unquote-node (n/token-node 'my-var))
n/string)
;; => \"~my-var\"
;; specifying a sequence allows for whitespace between the
;; unquote and the uquoted
(-> (n/unquote-node [(n/spaces 4)
(n/token-node 'my-var)])
n/string)
;; => \"~ my-var\"
```"
[children] (rewrite-clj.node.quote/unquote-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.quote
(defn unquote-splicing-node
"Create node representing a single unquote-spliced form where `children`
is either a sequence of nodes or a single node.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/unquote-splicing-node (n/token-node 'my-var))
n/string)
;; => \"~@my-var\"
;; specifying a sequence allows for whitespace between the
;; splicing unquote and the splicing unquoted
(-> (n/unquote-splicing-node [(n/spaces 2)
(n/token-node 'my-var)])
n/string)
;; => \"~@ my-var\"
```"
[children] (rewrite-clj.node.quote/unquote-splicing-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.token
(defn token-node
"Create node for an unspecified token of `value`.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/token-node 'sym) n/string)
;; => \"sym\"
(-> (n/token-node 42) n/string)
;; => \"42\"
```"
([value] (rewrite-clj.node.token/token-node value))
([value string-value] (rewrite-clj.node.token/token-node value string-value)))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.token
(defn symbol-node?
"Returns true if `n` is a node representing a symbol."
[n] (rewrite-clj.node.token/symbol-node? n))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.uneval
(defn uneval-node
"Create node representing an unevaled form with `children`.
```Clojure
(require '[rewrite-clj.node :as n])
(-> (n/uneval-node [(n/spaces 1)
(n/token-node 42)])
n/string)
;; => \"#_ 42\"
```"
[children] (rewrite-clj.node.uneval/uneval-node children))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn comma-separated
"Interleave `nodes` with `\", \"` nodes."
[nodes] (rewrite-clj.node.whitespace/comma-separated nodes))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn line-separated
"Interleave `nodes` with newline nodes."
[nodes] (rewrite-clj.node.whitespace/line-separated nodes))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn linebreak?
"Returns true if `node` represents one or more linebreaks."
[node] (rewrite-clj.node.whitespace/linebreak? node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn newlines
"Create node representing `n` newline characters."
[n] (rewrite-clj.node.whitespace/newlines n))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn newline-node
"Create newline node of string `s`, where `s` is one or more linebreak characters."
[s] (rewrite-clj.node.whitespace/newline-node s))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn spaces
"Create node representing `n` spaces."
[n] (rewrite-clj.node.whitespace/spaces n))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn whitespace-node
"Create whitespace node of string `s`, where `s` is one or more space characters."
[s] (rewrite-clj.node.whitespace/whitespace-node s))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn whitespace?
"Returns true if `node` represents Clojure whitespace."
[node] (rewrite-clj.node.whitespace/whitespace? node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn comma-node
"Create comma node of string `s`, where `s` is one or more comma characters."
[s] (rewrite-clj.node.whitespace/comma-node s))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn comma?
"Returns true if `node` represents one or more commas."
[node] (rewrite-clj.node.whitespace/comma? node))
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.whitespace
(defn whitespace-nodes
"Convert string `s` of whitespace to whitespace/newline nodes."
[s] (rewrite-clj.node.whitespace/whitespace-nodes s))