|
8 | 8 | (def boolean-ops
|
9 | 9 | {"&&" :and, "||" :or})
|
10 | 10 |
|
11 |
| -(def boolean-ops-strings (set (keys boolean-ops))) |
12 |
| - |
13 | 11 | (def comparator-ops
|
14 | 12 | {"=" :eq, "!=" :neq, "<" :lt, "<=" :lt-eq, ">" :gt, ">=" :gt-eq})
|
15 | 13 |
|
| 14 | +(def boolean-ops-strings (set (keys boolean-ops))) |
| 15 | +(def comparator-ops-strings (set (keys comparator-ops))) |
| 16 | + |
16 | 17 | (defn parse-boolean-expr [expr]
|
17 | 18 | (let [lhs (take-while #(not (boolean-ops-strings %)) expr)
|
18 | 19 | op (first (drop-while #(not (boolean-ops-strings %)) expr))
|
19 | 20 | rhs (rest (drop-while #(not (boolean-ops-strings %)) expr))]
|
20 | 21 | [(boolean-ops op) (parse-expr lhs) (parse-expr rhs)]))
|
21 | 22 |
|
22 | 23 | (defn parse-comparator-expr [expr]
|
23 |
| - (let [supported-ops (set (keys comparator-ops)) |
24 |
| - lhs (take-while #(not (supported-ops %)) expr) |
25 |
| - op (first (drop-while #(not (supported-ops %)) expr)) |
26 |
| - rhs (rest (drop-while #(not (supported-ops %)) expr))] |
27 |
| - ; (if (nil? op) |
28 |
| - ; [:some (parse lhs)]) |
| 24 | + (let [lhs (take-while #(not (comparator-ops-strings %)) expr) |
| 25 | + op (first (drop-while #(not (comparator-ops-strings %)) expr)) |
| 26 | + rhs (rest (drop-while #(not (comparator-ops-strings %)) expr))] |
29 | 27 | [(comparator-ops op) (parse lhs) (parse rhs)]))
|
30 | 28 |
|
31 | 29 | (defn parse-expr [expr]
|
|
34 | 32 | (some (set (keys comparator-ops)) expr) (parse-comparator-expr expr)
|
35 | 33 | :else [:some (parse expr)]))
|
36 | 34 |
|
37 |
| - ; (if (some boolean-ops-strings expr) |
38 |
| - ; (parse-boolean-expr expr) |
39 |
| - ; (parse-comparator-expr expr))) |
40 |
| - |
41 | 35 | (defn parse-indexer [remaining]
|
42 | 36 | (let [next (first remaining)]
|
43 | 37 | (cond
|
|
0 commit comments