File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 297
297
(s/def ::qmark #{'?})
298
298
299
299
(s/def ::key-exists
300
- (s/or :required ::key
300
+ (s/or :required (s/or :flat ::key
301
+ :list (s/cat :key ::key ))
301
302
:optional (s/cat :qmark ::qmark :key ::key )))
302
303
303
304
(s/def ::key-exists-with-binding
304
305
(s/or :required (s/cat :key ::key :binding-key ::binding-key :binding ::binding )
305
306
:optional (s/cat :qmark ::qmark :key ::key :binding-key ::binding-key :binding ::binding )))
306
307
307
308
(s/def ::path-exists
308
- (s/or :required ::path
309
+ (s/or :required (s/or :flat ::path
310
+ :list (s/cat :path ::path ))
309
311
:optional (s/cat :qmark ::qmark :path ::path )))
310
312
311
313
(s/def ::path-exists-with-binding
351
353
[[kind k]]
352
354
(if (= :symbol kind) (str k) k))
353
355
356
+ (def flat? (partial = :flat ))
357
+
354
358
(defn parse-clause
355
359
[p]
356
360
(letfn [(optional? [k]
367
371
:key-exists
368
372
(if (optional? mode)
369
373
(opt (key-exists-clause (make-key (:key body))))
370
- (key-exists-clause (make-key body)))
374
+ (let [[mode body] body]
375
+ (if (flat? mode)
376
+ (key-exists-clause (make-key body))
377
+ (key-exists-clause (make-key (:key body))))))
371
378
372
379
:key-exists-with-binding
373
380
(let [clause (-> (key-exists-clause (make-key (:key body)))
377
384
:path-exists
378
385
(if (optional? mode)
379
386
(opt (path-exists-clause (mapv make-key (:path body))))
380
- (path-exists-clause (mapv make-key body)))
387
+ (let [[mode body] body]
388
+ (if (flat? mode)
389
+ (path-exists-clause (mapv make-key body))
390
+ (path-exists-clause (mapv make-key (:path body))))))
381
391
382
392
:path-exists-with-binding
383
393
(let [{:keys [path binding ]} body
Original file line number Diff line number Diff line change 6
6
7
7
(t/deftest parse-clause-test
8
8
(t/testing " key exists clause"
9
- (t/is (= (p/make-key-exists-clause :k p/the-existence-matcher 'k)
10
- (p/parse-clause :k ))))
9
+ (t/testing " flat"
10
+ (t/is (= (p/make-key-exists-clause :k p/the-existence-matcher 'k)
11
+ (p/parse-clause :k ))))
12
+ (t/testing " list"
13
+ (t/is (= (p/make-key-exists-clause :k p/the-existence-matcher 'k)
14
+ (p/parse-clause (list :k ))))))
11
15
12
16
(t/testing " key exists with binding clause"
13
17
(t/is (= (p/make-key-exists-clause :k p/the-existence-matcher 'Binding)
14
18
(p/parse-clause (list :k :as 'Binding)))))
15
19
16
20
(t/testing " path exists clause"
17
- (t/is (= (p/make-path-exists-clause [:k " V" ] p/the-existence-matcher 'V)
18
- (p/parse-clause [:k 'V]))))
21
+ (t/testing " flat"
22
+ (t/is (= (p/make-path-exists-clause [:k " V" ] p/the-existence-matcher 'V)
23
+ (p/parse-clause [:k 'V]))))
24
+ (t/testing " list"
25
+ (t/is (= (p/make-path-exists-clause [:k " V" ] p/the-existence-matcher 'V)
26
+ (p/parse-clause (list [:k 'V]))))))
19
27
20
28
(t/testing " path exists clause with binding"
21
29
(t/is (= (p/make-path-exists-clause [:k " V" ] p/the-existence-matcher 'Binding)
You can’t perform that action at this time.
0 commit comments