Liking cljdoc? Tell your friends :D

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?

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?]]
raw docstring

child-sexprsclj/s

(child-sexprs node)
(child-sexprs node opts)

Returns children for node converted to Clojure forms.

Optional opts can specify:

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)
sourceraw docstring

childrenclj/s

(children node)

Returns child nodes for node.

Returns child nodes for `node`.
sourceraw docstring

coerceclj/s

(coerce form)

Coerce form to node.

Coerce `form` to node.
sourceraw docstring

comma-nodeclj/s

(comma-node s)

Create comma node of string s, where s is one or more comma characters.

Create comma node of string `s`, where `s` is one or more comma characters.
sourceraw docstring

comma-separatedclj/s

(comma-separated nodes)

Interleave nodes with ", " nodes.

Interleave `nodes` with `", "` nodes.
sourceraw docstring

comma?clj/s

(comma? node)

Returns true if node represents one or more commas.

Returns true if `node` represents one or more commas.
sourceraw docstring

comment-nodeclj/s

(comment-node s)
(comment-node prefix s)

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
(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"
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"
```
sourceraw docstring

comment?clj/s

(comment? node)

Returns true if node is a comment.

Returns true if `node` is a comment.
sourceraw docstring

deref-nodeclj/s

(deref-node children)

Create node representing the dereferencing of a form where children is either a sequence of nodes or a single node.

(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"
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"
```
sourceraw docstring

eval-nodeclj/s

(eval-node children)

Create node representing an inline evaluation where children is either a sequence of nodes or a single node.

(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)"
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)"
```
sourceraw docstring

fn-nodeclj/s

(fn-node children)

Create node representing an anonymous function with children.

(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)"
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)"
```
sourceraw docstring

forms-nodeclj/s

(forms-node children)

Create top-level node wrapping multiple children. The forms node is equivalent to an implicit do at the top-level.

(require '[rewrite-clj.node :as n])

(-> (n/forms-node [(n/token-node 1)
                   (n/spaces 1)
                   (n/token-node 2)])
    n/string)
;; => "1 2"
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"
``` 
sourceraw docstring

inner?clj/s

(inner? node)

Returns true if node can have children.

Returns true if `node` can have children.
sourceraw docstring

integer-nodeclj/s

(integer-node value)
(integer-node value base)

Create node representing an integer value in base.

base defaults to 10.

(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.

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.
sourceraw docstring

keyword-nodeclj/s

(keyword-node k)
(keyword-node k auto-resolved?)

Create a node representing a keyword k.

Optionally include auto-resolved?, which defaults to false.

(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"
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"
```
sourceraw docstring

keyword-node?clj/s

(keyword-node? n)

Returns true if n is a node representing a keyword.

Returns true if `n` is a node representing a keyword.
sourceraw docstring

leader-lengthclj/s

(leader-length node)

Returns number of characters before children for node.

Returns number of characters before children for `node`.
sourceraw docstring

lengthclj/s

(length node)

Return number of characters for the string version of node.

Return number of characters for the string version of `node`.
sourceraw docstring

line-separatedclj/s

(line-separated nodes)

Interleave nodes with newline nodes.

Interleave `nodes` with newline nodes.
sourceraw docstring

linebreak?clj/s

(linebreak? node)

Returns true if node represents one or more linebreaks.

Returns true if `node` represents one or more linebreaks.
sourceraw docstring

list-nodeclj/s

(list-node children)

Create a node representing a list with children.

(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)"
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)"
```
sourceraw docstring

map-context-applyclj/s

(map-context-apply node map-qualifier)

Applies map-qualifier context to node

Applies `map-qualifier` context to `node`
sourceraw docstring

map-context-clearclj/s

(map-context-clear node)

Removes map-qualifier context for node

Removes map-qualifier context for `node`
sourceraw docstring

map-nodeclj/s

(map-node children)

Create a node representing a map with children.

(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 unbalanced maps:

(-> (n/map-node [(n/keyword-node :a)])
    (n/string))
;; => "{:a}"

Note also that sexpr will fail on an unbalanced map.

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 unbalanced maps:
```Clojure
(-> (n/map-node [(n/keyword-node :a)])
    (n/string))
;; => "{:a}"
```
Note also that [[sexpr]] will fail on an unbalanced map.
sourceraw docstring

map-qualifier-nodeclj/s

(map-qualifier-node auto-resolved? prefix)

Create a map qualifier node. The map qualifier node is a child node of namespaced-map-node.

(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"
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"
```
sourceraw docstring

meta-nodeclj/s

(meta-node children)
(meta-node metadata data)

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:

(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:

(-> (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

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]]
sourceraw docstring

namespaced-map-nodeclj/s

(namespaced-map-node children)

Create a namespaced map node with children.

(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.

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]].
sourceraw docstring

newline-nodeclj/s

(newline-node s)

Create newline node of string s, where s is one or more linebreak characters.

Create newline node of string `s`, where `s` is one or more linebreak characters.
sourceraw docstring

newlinesclj/s

(newlines n)

Create node representing n newline characters.

Create node representing `n` newline characters.
sourceraw docstring

node?clj/s

(node? x)

Returns true if x is a rewrite-clj created node.

Returns true if `x` is a rewrite-clj created node.
sourceraw docstring

printable-only?clj/s

(printable-only? node)

Return true if node cannot be converted to an s-expression element.

Return true if `node` cannot be converted to an s-expression element.
sourceraw docstring

quote-nodeclj/s

(quote-node children)

Create node representing a single quoted form where children is either a sequence of nodes or a single node.

(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"
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"
```
sourceraw docstring

raw-meta-nodeclj/s

(raw-meta-node children)
(raw-meta-node metadata data)

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:

(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:

(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

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]]
sourceraw docstring

reader-macro-nodeclj/s

(reader-macro-node children)
(reader-macro-node macro-node form-node)

Create node representing a reader macro with macro-node and form-node or children.

(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" 
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" 
```
sourceraw docstring

regex-nodeclj/s

(regex-node pattern-string)

Create node representing a regex with pattern-string. Use same escape rules for pattern-string as you would for (re-pattern "pattern-string")

(require '[rewrite-clj.node :as n])

(-> (n/regex-node "my\\.lil.*regex")
    n/string)
;; => "#\"my\\.lil.*regex\""  
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\""  
```
sourceraw docstring

replace-childrenclj/s

(replace-children node children)

Returns node replacing current children with children.

Returns `node` replacing current children with `children`.
sourceraw docstring

set-nodeclj/s

(set-node children)

Create a node representing a set with children.

(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}"
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}"
```
sourceraw docstring

sexprclj/s

(sexpr node)
(sexpr node opts)

Return node converted to form.

Optional opts can specify:

See docs for sexpr nuances.

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).
sourceraw docstring

sexpr-able?clj/s

(sexpr-able? node)

Return true if sexpr is supported for node.

Return true if [[sexpr]] is supported for `node`.
sourceraw docstring

sexprsclj/s

(sexprs nodes)
(sexprs nodes opts)

Return forms for nodes. Nodes that do not represent s-expression are skipped.

Optional opts can specify:

See docs for sexpr nuances.

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).
sourceraw docstring

spacesclj/s

(spaces n)

Create node representing n spaces.

Create node representing `n` spaces.
sourceraw docstring

stringclj/s

(string node)

Return the string version of node.

Return the string version of `node`.
sourceraw docstring

string-nodeclj/s

(string-node lines)

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.

(require '[rewrite-clj.node :as n])

(-> (n/string-node "hello")
    n/string)
;; => "\"hello\""

(-> (n/string-node ["line1" "" "line3"])
     n/string)
;; => "\"line1\n\nline3\""
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\""
```
sourceraw docstring

symbol-node?clj/s

(symbol-node? n)

Returns true if n is a node representing a symbol.

Returns true if `n` is a node representing a symbol.
sourceraw docstring

syntax-quote-nodeclj/s

(syntax-quote-node children)

Create node representing a single syntax-quoted form where children is either a sequence of nodes or a single node.

(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"
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"
```
sourceraw docstring

tagclj/s

(tag node)

Returns keyword representing type of node.

Returns keyword representing type of `node`.
sourceraw docstring

token-nodeclj/s

(token-node value)
(token-node value string-value)

Create node for an unspecified token of value.

(require '[rewrite-clj.node :as n])

(-> (n/token-node 'sym) n/string)
;; => "sym"

(-> (n/token-node 42) n/string)
;; => "42"
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"
```
sourceraw docstring

uneval-nodeclj/s

(uneval-node children)

Create node representing an unevaled form with children.

(require '[rewrite-clj.node :as n])

(-> (n/uneval-node [(n/spaces 1)
                    (n/token-node 42)])
    n/string)
;; => "#_ 42"
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"
```
sourceraw docstring

unquote-nodeclj/s

(unquote-node children)

Create node representing a single unquoted form where children is either a sequence of nodes or a single node.

(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"
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"
```
sourceraw docstring

unquote-splicing-nodeclj/s

(unquote-splicing-node children)

Create node representing a single unquote-spliced form where children is either a sequence of nodes or a single node.

(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"   
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"   
```
sourceraw docstring

valueclj/sdeprecated

(value node)

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)

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) 
sourceraw docstring

var-nodeclj/s

(var-node children)

Create node representing a var where children is either a sequence of nodes or a single node.

(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"
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"
```
sourceraw docstring

vector-nodeclj/s

(vector-node children)

Create a node representing a vector with children.

(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]"
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]"
```
sourceraw docstring

whitespace-nodeclj/s

(whitespace-node s)

Create whitespace node of string s, where s is one or more space characters.

Create whitespace node of string `s`, where `s` is one or more space characters.
sourceraw docstring

whitespace-nodesclj/s

(whitespace-nodes s)

Convert string s of whitespace to whitespace/newline nodes.

Convert string `s` of whitespace to whitespace/newline nodes.
sourceraw docstring

whitespace-or-comment?clj/s

(whitespace-or-comment? node)

Check whether the given node represents whitespace or comment.

Check whether the given node represents whitespace or comment.
sourceraw docstring

whitespace?clj/s

(whitespace? node)

Returns true if node represents Clojure whitespace.

Returns true if `node` represents Clojure whitespace.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close