|
315 | 315 | [& exclusions] |
316 | 316 | (complement (apply some-fn exclusions))) |
317 | 317 |
|
318 | | - |
319 | 318 | (s/def ::regex regex?) |
320 | 319 | (s/def ::compare-fn-token #{:compare-fn}) |
321 | 320 | (s/def ::fn? any?) |
|
347 | 346 |
|
348 | 347 | (s/def ::path-exists-without-binding |
349 | 348 | (s/or :flat ::path |
350 | | - :list (s/cat :path ::path))) |
| 349 | + :list (s/cat :path ::path))) |
351 | 350 |
|
352 | 351 | (s/def ::path-exists-with-binding |
353 | 352 | (s/cat :path ::path :binding-key ::binding-key :binding ::binding)) |
|
484 | 483 | :optional-path-with-default-binding |
485 | 484 | (let [path (mapv make-key (:path body)) |
486 | 485 | b (make-binding (:binding body))] |
487 | | - `(optional-path-with-default-binding-clause ~path ~(:default-value body) ~b))))))) |
| 486 | + `(optional-path-with-default-binding-clause ~path ~(:default-value body) ~b))))))) |
488 | 487 |
|
489 | 488 | (defmacro parse-clauses |
490 | 489 | [cs] |
|
550 | 549 | :key-matches-without-binding |
551 | 550 | (let [k (make-key (:key body)) |
552 | 551 | match (:match-value body) |
553 | | - predicate? (= :compare-fn (first match)) |
| 552 | + match-kind (first match) |
554 | 553 | match-value (second match)] |
555 | 554 | (cond |
556 | | - predicate? |
| 555 | + (= :compare-fn match-kind) |
557 | 556 | [`({~k ~'_} :guard [(constantly (~(:fn match-value) (get-in ~message [~k])))]) |
558 | 557 | `[]] |
| 558 | + (= :options match-kind) |
| 559 | + [`{~k (:or ~@(:options match-value))} |
| 560 | + `[]] |
559 | 561 | :else |
560 | 562 | [`{~k ~match-value} |
561 | 563 | `[]])) |
|
564 | 566 | (let [k (make-key (:key body)) |
565 | 567 | b (make-binding (:binding body)) |
566 | 568 | match (:match-value body) |
567 | | - predicate? (= :compare-fn (first match)) |
| 569 | + match-kind (first match) |
568 | 570 | match-value (second match)] |
569 | 571 | (cond |
570 | | - predicate? |
| 572 | + (= :compare-fn match-kind) |
571 | 573 | [`({~k ~'_} :guard [(constantly (~(:fn match-value) (get-in ~message [~k])))]) |
572 | 574 | `[~(symbol b) (get-in ~message [~k])]] |
| 575 | + (= :options match-kind) |
| 576 | + [`{~k (:or ~@(:options match-value))} |
| 577 | + `[~(symbol b) (get-in ~message [~k])]] |
573 | 578 | :else |
574 | 579 | [`{~k ~match-value} |
575 | 580 | `[~(symbol b) (get-in ~message [~k])]])) |
576 | 581 |
|
577 | 582 | :optional-key-with-default-binding |
578 | 583 | (let [k (make-key (:key body)) |
579 | 584 | b (make-binding (:binding body))] |
580 | | - [{} `[~(symbol b) (get-in ~message [~k] ~(:default-value body))]]) |
| 585 | + [{} `[~(symbol b) (get-in ~message [~k] ~(:default-value body))]]) |
581 | 586 |
|
582 | 587 | :path-matches-without-binding |
583 | 588 | (let [path (mapv make-key (:path body)) |
584 | 589 | match (:match-value body) |
585 | | - predicate? (= :compare-fn (first match)) |
586 | | - match-value (second match) |
587 | | - path-map (assoc-in {} path match-value)] |
| 590 | + match-kind (first match) |
| 591 | + match-value (second match)] |
588 | 592 | (cond |
589 | | - predicate? |
| 593 | + (= :compare-fn match-kind) |
590 | 594 | [`(~(fold-path path '_) :guard [(constantly (~(:fn match-value) (get-in ~message ~path)))]) |
591 | 595 | `[]] |
| 596 | + (= :options match-kind) |
| 597 | + [(assoc-in {} path `(:or ~@(:options match-value))) |
| 598 | + `[]] |
592 | 599 | :else |
593 | | - [`~path-map |
| 600 | + [`~(assoc-in {} path match-value) |
594 | 601 | `[]])) |
595 | 602 |
|
596 | 603 | :path-matches-with-binding |
597 | 604 | (let [path (mapv make-key (:path body)) |
598 | 605 | b (make-binding (:binding body)) |
599 | 606 | match (:match-value body) |
600 | | - predicate? (= :compare-fn (first match)) |
| 607 | + match-kind (first match) |
601 | 608 | match-value (second match) |
602 | 609 | path-map (assoc-in {} path match-value)] |
603 | 610 | (cond |
604 | | - predicate? |
| 611 | + (= :compare-fn match-kind) |
605 | 612 | [`(~(fold-path path '_) :guard [(constantly (~(:fn match-value) (get-in ~message ~path)))]) |
606 | 613 | `[~(symbol b) (get-in ~message ~path)]] |
| 614 | + (= :options match-kind) |
| 615 | + [(assoc-in {} path `(:or ~@(:options match-value))) |
| 616 | + `[~(symbol b) (get-in ~message ~path)]] |
607 | 617 | :else |
608 | 618 | [`~path-map |
609 | 619 | `[~(symbol b) (get-in ~message ~path)]])) |
|
625 | 635 | (defn parse-emit-match-syntax |
626 | 636 | [message [pattern rhs]] |
627 | 637 | (let [[lhss rhss] (reduce (fn [[clauses bindings] c] |
628 | | - (let [[clause binding] (parse-emit-syntax message c)] |
629 | | - [(conj clauses clause) |
630 | | - (conj bindings binding)])) |
631 | | - [[] []] |
632 | | - pattern)] |
| 638 | + (let [[clause binding] (parse-emit-syntax message c)] |
| 639 | + [(conj clauses clause) |
| 640 | + (conj bindings binding)])) |
| 641 | + [[] []] |
| 642 | + pattern)] |
633 | 643 | [(apply deep-merge lhss) |
634 | 644 | `(let ~(into [] (apply concat rhss)) |
635 | 645 | ~rhs)])) |
|
0 commit comments