-
Notifications
You must be signed in to change notification settings - Fork 10
/
parser.cljc
24 lines (22 loc) · 1.08 KB
/
parser.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(ns datalog.parser
(:require [datalog.parser.impl :as impl]
[datalog.parser.type :as t]
[datalog.parser.impl.util
#?(:cljs :refer-macros :clj :refer) [raise]]))
#?(:clj (set! *warn-on-reflection* true))
(defn parse [q]
(let [qm (cond
(map? q) q
(sequential? q) (impl/query->map q)
:else (raise "Query should be a vector or a map"
{:error :parser/query, :form q}))
res (t/map->Query {:qfind (impl/parse-find (:find qm))
:qwith (some-> qm :with impl/parse-with)
:qin (impl/parse-in (:in qm ['$]))
:qwhere (impl/parse-where (:where qm []))
:qlimit (-> qm :limit impl/parse-limit)
:qoffset (-> qm :offset impl/parse-offset)
:qreturnmaps (-> qm (select-keys [:keys :syms :strs])
(impl/parse-return-maps))})]
(impl/assert-valid res q qm)
res))