|
337 | 337 | :key-matches-with-binding ::key-matches-with-binding
|
338 | 338 | :path-matches ::path-matches
|
339 | 339 | :path-matches-with-binding ::path-matches-with-binding))
|
340 |
| -(s/conform ::clause (list :k (list :compare-fn even?))) |
341 | 340 |
|
342 | 341 | (defn match-value->matcher
|
343 | 342 | [[kind match-value]]
|
|
347 | 346 | (= :compare-fn kind) (match-predicate (:fn match-value))
|
348 | 347 | :else (match-const match-value)))
|
349 | 348 |
|
| 349 | +(defn make-key |
| 350 | + "Returns k as a string if k is a symbol, otherwise returns k." |
| 351 | + [[kind k]] |
| 352 | + (if (= :symbol kind) (str k) k)) |
| 353 | + |
350 | 354 | (defn parse-clause
|
351 | 355 | [p]
|
352 | 356 | (letfn [(optional? [k]
|
|
362 | 366 | (case match
|
363 | 367 | :key-exists
|
364 | 368 | (if (optional? mode)
|
365 |
| - (opt (key-exists-clause (second (:key body)))) |
366 |
| - (key-exists-clause (second body))) |
| 369 | + (opt (key-exists-clause (make-key (:key body)))) |
| 370 | + (key-exists-clause (make-key body))) |
367 | 371 |
|
368 | 372 | :key-exists-with-binding
|
369 |
| - (let [clause (-> (key-exists-clause (second (:key body))) |
| 373 | + (let [clause (-> (key-exists-clause (make-key (:key body))) |
370 | 374 | (bind-match (:binding body)))]
|
371 | 375 | (if (optional? mode) (opt clause) clause))
|
372 | 376 |
|
373 | 377 | :path-exists
|
374 | 378 | (if (optional? mode)
|
375 |
| - (opt (path-exists-clause (mapv second (:path body)))) |
376 |
| - (path-exists-clause (mapv second body))) |
| 379 | + (opt (path-exists-clause (mapv make-key (:path body)))) |
| 380 | + (path-exists-clause (mapv make-key body))) |
377 | 381 |
|
378 | 382 | :path-exists-with-binding
|
379 | 383 | (let [{:keys [path binding]} body
|
380 | 384 |
|
381 |
| - components (mapv second path) |
| 385 | + components (mapv make-key path) |
382 | 386 | clause (bind-match (path-exists-clause components) binding)]
|
383 | 387 | (if (optional? mode) (opt clause) clause))
|
384 | 388 |
|
385 | 389 | :key-matches
|
386 | 390 | (let [{:keys [key match-value]} body
|
387 | 391 |
|
388 |
| - clause (key-matches-clause (second key) (match-value->matcher match-value))] |
| 392 | + clause (key-matches-clause (make-key key) (match-value->matcher match-value))] |
389 | 393 | (if (optional? mode) (opt clause) clause))
|
390 | 394 |
|
391 | 395 | :key-matches-with-binding
|
392 | 396 | (let [{:keys [key match-value binding]} body
|
393 | 397 |
|
394 |
| - clause (bind-match (key-matches-clause (second key) (match-value->matcher match-value)) binding)] |
| 398 | + clause (bind-match (key-matches-clause (make-key key) (match-value->matcher match-value)) binding)] |
395 | 399 | (if (optional? mode) (opt clause) clause))
|
396 | 400 |
|
397 | 401 | :path-matches
|
398 | 402 | (let [{:keys [path match-value]} body
|
399 | 403 |
|
400 |
| - components (mapv second path) |
| 404 | + components (mapv make-key path) |
401 | 405 | clause (path-matches-clause components (match-value->matcher match-value))]
|
402 | 406 | (if (optional? mode) (opt clause) clause))
|
403 | 407 |
|
404 | 408 | :path-matches-with-binding
|
405 | 409 | (let [{:keys [path match-value binding]} body
|
406 | 410 |
|
407 |
| - components (mapv second path) |
| 411 | + components (mapv make-key path) |
408 | 412 | clause (bind-match (path-matches-clause components (match-value->matcher match-value)) binding)]
|
409 | 413 | (if (optional? mode) (opt clause) clause))))))))
|
410 | 414 |
|
|
0 commit comments