|
6 | 6 | [clojure-refactoring.ast :only [defparsed-fn]])
|
7 | 7 | (:require [clojure-refactoring.ast :as ast]))
|
8 | 8 |
|
9 |
| -(defn parsley-map-lookup? [ast] |
| 9 | +(defn map-lookup? [ast] |
10 | 10 | (let [content (ast/relevant-content ast)]
|
11 | 11 | (and (ast/tag= :list ast)
|
12 | 12 | (count= (filter ast/keyword? content) 1)
|
13 | 13 | (count= content 2))))
|
14 | 14 |
|
15 |
| -(defn parsley-key->sym [kw-node] |
| 15 | +(defn key->sym [kw-node] |
16 | 16 | (ast/replace-content kw-node
|
17 | 17 | (list
|
18 | 18 | (str-join ""
|
19 | 19 | (drop 1 (first (:content kw-node)))))))
|
20 | 20 |
|
21 |
| -(defn parsley-find-lookups [node] |
| 21 | +(defn find-lookups [node] |
22 | 22 | "Returns all the map lookups in a node as a set of parsley asts"
|
23 | 23 | (->> (ast/sub-nodes node)
|
24 |
| - (filter parsley-map-lookup?) |
| 24 | + (filter map-lookup?) |
25 | 25 | set))
|
26 | 26 |
|
27 | 27 | (defn- swap-first-with-last [ast]
|
|
34 | 34 | (ast/replace-content ast
|
35 | 35 | (swap-first-with-last ast)))
|
36 | 36 |
|
37 |
| -(defn parsley-lookup-to-canoninical-form [lookup-ast] |
| 37 | +(defn lookup->canoninical-form [lookup-ast] |
38 | 38 | (let [[maybe-keyword] (ast/relevant-content lookup-ast)]
|
39 | 39 | (if (ast/keyword? maybe-keyword)
|
40 | 40 | lookup-ast
|
|
52 | 52 | ~@(drop 1 (:content m)))))
|
53 | 53 |
|
54 | 54 | (def relevant-content-from-canoninical-form
|
55 |
| - (comp ast/relevant-content parsley-lookup-to-canoninical-form)) |
| 55 | + (comp ast/relevant-content lookup->canoninical-form)) |
56 | 56 |
|
57 | 57 | (defn- add-lookup-to-binding-map [binding-map lookup]
|
58 | 58 | "Adds a lookup (a node of the form (:a a)) to a binding map."
|
59 | 59 | (let [[key m] (relevant-content-from-canoninical-form lookup)]
|
60 | 60 | (assoc binding-map m
|
61 | 61 | (add-to-parsley-map
|
62 | 62 | (get binding-map m ast/empty-map)
|
63 |
| - (parsley-key->sym key) key)))) |
| 63 | + (key->sym key) key)))) |
64 | 64 |
|
65 | 65 | (defn lookups-to-binding-map [lookups]
|
66 | 66 | "Turns a set of lookups to a map of map-symbols to lookups"
|
|
80 | 80 | (fn [new-ast lookup]
|
81 | 81 | (ast/tree-replace
|
82 | 82 | lookup
|
83 |
| - (parsley-key->sym (first (ast/relevant-content (parsley-lookup-to-canoninical-form lookup)))) |
| 83 | + (key->sym (first (ast/relevant-content (lookup->canoninical-form lookup)))) |
84 | 84 | new-ast))
|
85 | 85 | ast
|
86 | 86 | lookups))
|
|
92 | 92 |
|
93 | 93 | (defparsed-fn destructure-map [root-ast]
|
94 | 94 | "Destructures all calls to maps"
|
95 |
| - (let [lookups (parsley-find-lookups root-ast)] |
| 95 | + (let [lookups (find-lookups root-ast)] |
96 | 96 | (ast/ast->string
|
97 | 97 | (replace-lookups-with-destructured-symbols
|
98 | 98 | lookups
|
|
0 commit comments