|
1 | 1 | (ns rewrite-clj.node.reader-macro
|
2 |
| - (:require [rewrite-clj.node.protocols :as node])) |
| 2 | + (:require [rewrite-clj.node |
| 3 | + [protocols :as node] |
| 4 | + [whitespace :as ws]])) |
3 | 5 |
|
4 | 6 | ;; ## Node
|
5 | 7 |
|
|
98 | 100 | children))
|
99 | 101 |
|
100 | 102 | (defn var-node
|
| 103 | + "Create node representing a var. |
| 104 | + Takes either a seq of nodes or a single one." |
101 | 105 | [children]
|
102 |
| - (->node :var "'" "" #(list* 'var %) 1 children)) |
| 106 | + (if (sequential? children) |
| 107 | + (->node :var "'" "" #(list* 'var %) 1 children) |
| 108 | + (recur [children]))) |
103 | 109 |
|
104 | 110 | (defn fn-node
|
| 111 | + "Create node representing an anonymous function." |
105 | 112 | [children]
|
106 | 113 | (->node :fn "(" ")" nil nil children))
|
107 | 114 |
|
108 | 115 | (defn eval-node
|
| 116 | + "Create node representing an inline evaluation. (`#=...`) |
| 117 | + Takes either a seq of nodes or a single one." |
109 | 118 | [children]
|
110 |
| - (->node |
111 |
| - :eval "=" "" |
112 |
| - #(list 'eval (list* 'quote %)) |
113 |
| - 1 children)) |
| 119 | + (if (sequential? children) |
| 120 | + (->node |
| 121 | + :eval "=" "" |
| 122 | + #(list 'eval (list* 'quote %)) |
| 123 | + 1 children) |
| 124 | + (recur [children]))) |
114 | 125 |
|
115 | 126 | (defn uneval-node
|
| 127 | + "Create node representing a form ignored by the reader. (`#_...`) |
| 128 | + Takes either a seq of nodes or a single one." |
116 | 129 | [children]
|
117 |
| - (->node :uneval "_" "" nil 1 children)) |
| 130 | + (if (sequential? children) |
| 131 | + (->node :uneval "_" "" nil 1 children) |
| 132 | + (recur [children]))) |
118 | 133 |
|
119 | 134 | (defn reader-macro-node
|
120 |
| - [children] |
121 |
| - (->ReaderMacroNode children)) |
| 135 | + "Create node representing a reader macro. (`#... ...`)" |
| 136 | + ([children] |
| 137 | + (->ReaderMacroNode children)) |
| 138 | + ([macro-node form-node] |
| 139 | + (->ReaderMacroNode [macro-node (ws/spaces 1) form-node]))) |
122 | 140 |
|
123 | 141 | (defn deref-node
|
| 142 | + "Create node representing the dereferencing of a form. (`@...`) |
| 143 | + Takes either a seq of nodes or a single one." |
124 | 144 | [children]
|
125 |
| - (->DerefNode children)) |
| 145 | + (if (sequential? children) |
| 146 | + (->DerefNode children) |
| 147 | + (->DerefNode [children]))) |
0 commit comments