/
parser.clj
52 lines (48 loc) · 1.61 KB
/
parser.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(ns matcher-combinators.parser
(:require [matcher-combinators.core :as core]
[matcher-combinators.matchers :as matchers]
[matcher-combinators.model :as model])
(:import [clojure.lang Keyword Symbol Ratio BigInt IPersistentMap
IPersistentVector IPersistentList IPersistentSet
LazySeq Repeat Cons]
[java.util UUID Date]
[java.util.regex Pattern]
[java.time LocalDate LocalDateTime YearMonth]))
(defmacro mimic-matcher [matcher-builder & types]
`(extend-protocol
core/Matcher
~@(mapcat (fn [t] `(~t
(match [this# actual#]
(core/match (~matcher-builder this#) actual#)))) types)))
(extend-type clojure.lang.Fn
core/Matcher
(match [this actual]
(core/match-pred this actual)))
(mimic-matcher matchers/equals
nil
Integer
Long
Float
Double
String
Symbol
Keyword
Boolean
UUID
Date
LocalDate
LocalDateTime
YearMonth
Ratio
BigDecimal
BigInteger
BigInt
Character)
(mimic-matcher matchers/embeds IPersistentMap)
(mimic-matcher matchers/equals IPersistentVector)
(mimic-matcher matchers/equals IPersistentList)
(mimic-matcher matchers/equals IPersistentSet)
(mimic-matcher matchers/equals Cons)
(mimic-matcher matchers/equals Repeat)
(mimic-matcher matchers/equals LazySeq)
(mimic-matcher matchers/regex Pattern)