Skip to content

Commit e0e8d2e

Browse files
oakmaccburgmer
authored andcommitted
return :some value to parser, remove :bool
1 parent ddf4be4 commit e0e8d2e

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/json_path/parser.clj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@
2727
[(comparator-ops op) (parse lhs) (parse rhs)]))
2828

2929
(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)])))
3438

3539
(defn parse-indexer [remaining]
3640
(let [next (first remaining)]

test/json_path/test/parser_test.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
(parse-expr '("\"" "bar" "\"" "=" "3.1415")) => [:eq [:val "bar"] [:val 3.1415]])
2323

2424
(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"]])
3030

3131
(fact
3232
(parse-indexer '("*")) => [:index "*"]
@@ -51,7 +51,7 @@
5151
(parse-path "$.foo[3]") => [:path [[:root] [:child] [:key "foo"]] [:selector [:index "3"]]]
5252
(parse-path "foo[*]") => [:path [[:key "foo"]] [:selector [:index "*"]]]
5353
(parse-path "$[?(@.baz)]") => [:path [[:root]]
54-
[:selector [:filter [:bool [:path [[:current]
54+
[:selector [:filter [:some [:path [[:current]
5555
[:child]
5656
[:key "baz"]]]]]]]
5757
(parse-path "$[?(@.bar<2)]") => [:path [[:root]]
@@ -81,7 +81,7 @@
8181
[:child]
8282
[:key "bar"]]]
8383
[:val 42]]
84-
[:bool [:val true]]]]]]
84+
[:val true]]]]]
8585
(parse-path "$[?(@.bar>42 || @.bar<44)]") => [:path [[:root]]
8686
[:selector [:filter
8787
[:or

0 commit comments

Comments
 (0)