File tree Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change 27
27
[(comparator-ops op) (parse lhs) (parse rhs)]))
28
28
29
29
(defn parse-expr [expr]
30
- (cond
31
- (some boolean-ops-strings expr) (parse-boolean-expr expr)
32
- (some (set (keys comparator-ops)) expr) (parse-comparator-expr expr)
33
- :else [:bool (parse expr)]))
30
+ (let [first-el (first expr)]
31
+ (cond
32
+ (some boolean-ops-strings expr) (parse-boolean-expr expr)
33
+ (some (set (keys comparator-ops)) expr) (parse-comparator-expr expr)
34
+ (= first-el " true" ) [:val true ]
35
+ (= first-el " false" ) [:val false ]
36
+ (= " \" " first-el) [:val (apply str (extract-sub-tree " \" " " \" " expr))]
37
+ :else [:some (parse expr)])))
34
38
35
39
(defn parse-indexer [remaining]
36
40
(let [next (first remaining)]
Original file line number Diff line number Diff line change 22
22
(parse-expr '(" \" " " bar" " \" " " =" " 3.1415" )) => [:eq [:val " bar" ] [:val 3.1415 ]])
23
23
24
24
(facts " boolean expressions should be parseable"
25
- (parse-expr '(" \" " " bar" " \" " " &&" " \" " " bar" " \" " )) => [:and [:bool [ : val " bar" ]] [:bool [ : val " bar" ] ]]
26
- (parse-expr '(" \" " " bar" " \" " " &&" " true" )) => [:and [:bool [ : val " bar" ]] [:bool [ : val true ] ]]
27
- (parse-expr '(" false" " &&" " \" " " bar" " \" " )) => [:and [:bool [ : val false ]] [:bool [ : val " bar" ] ]]
28
- (parse-expr '(" \" " " bar" " \" " " ||" " \" " " bar" " \" " )) => [:or [:bool [ : val " bar" ]] [:bool [ : val " bar" ] ]]
29
- (parse-expr '(" \" " " bar" " \" " " =" " 42" " &&" " \" " " bar" " \" " )) => [:and [:eq [:val " bar" ] [:val 42 ]] [:bool [ : val " bar" ] ]])
25
+ (parse-expr '(" \" " " bar" " \" " " &&" " \" " " bar" " \" " )) => [:and [:val " bar" ] [:val " bar" ]]
26
+ (parse-expr '(" \" " " bar" " \" " " &&" " true" )) => [:and [:val " bar" ] [:val true ]]
27
+ (parse-expr '(" false" " &&" " \" " " bar" " \" " )) => [:and [:val false ] [:val " bar" ]]
28
+ (parse-expr '(" \" " " bar" " \" " " ||" " \" " " bar" " \" " )) => [:or [:val " bar" ] [:val " bar" ]]
29
+ (parse-expr '(" \" " " bar" " \" " " =" " 42" " &&" " \" " " bar" " \" " )) => [:and [:eq [:val " bar" ] [:val 42 ]] [:val " bar" ]])
30
30
31
31
(fact
32
32
(parse-indexer '(" *" )) => [:index " *" ]
51
51
(parse-path " $.foo[3]" ) => [:path [[:root ] [:child ] [:key " foo" ]] [:selector [:index " 3" ]]]
52
52
(parse-path " foo[*]" ) => [:path [[:key " foo" ]] [:selector [:index " *" ]]]
53
53
(parse-path " $[?(@.baz)]" ) => [:path [[:root ]]
54
- [:selector [:filter [:bool [:path [[:current ]
54
+ [:selector [:filter [:some [:path [[:current ]
55
55
[:child ]
56
56
[:key " baz" ]]]]]]]
57
57
(parse-path " $[?(@.bar<2)]" ) => [:path [[:root ]]
81
81
[:child ]
82
82
[:key " bar" ]]]
83
83
[:val 42 ]]
84
- [:bool [ : val true ] ]]]]]
84
+ [:val true ]]]]]
85
85
(parse-path " $[?(@.bar>42 || @.bar<44)]" ) => [:path [[:root ]]
86
86
[:selector [:filter
87
87
[:or
You can’t perform that action at this time.
0 commit comments