Skip to content

Commit

Permalink
ht filter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
inconvergent committed Mar 11, 2024
1 parent 0134d02 commit 7ec0015
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/pre-qry.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
(etypecase ty (number `(when-equal ,k ,ty))
(keyword `(and (str? ,k) (isub? ,k ,(ct/kw/str ty))))
(string `(and (str? ,k) (sub? ,k ,ty)))
(symbol `(when (,ty ,k) ,k))
(symbol `(when (,ty ,k) ,k)) ; TODO: attempt to parse as float, int?
(cons ty) (boolean `(when-equal ,ty ,k))))

(defun pre/scan-clause (q &optional (full t))
Expand Down
31 changes: 16 additions & 15 deletions src/qry.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,28 @@
(loop for (m expr) in (strip-all cd) if (member m mm :test #'eq) collect expr))

(defun compile/** (rec conf d) ; [...] ; sel, filter
(awg (k i kres ires itr par) ; TODO: tests for hts, (key)
`(let ((,par ,(gk conf :dat)))
(labels
((do-vec () (loop with ,par = (vec! ,par)
with ,ires of-type vector = (mav)
for ,itr across ,par for ,i from 0
do ,(compile/?xpr rec `((:par . ,par) (:dat . ,itr)
(:cnt . ,i) (:itr . ,itr) (:key . ,i))
(awg (k i kres ires itr par)
`(let ((,par ,(gk conf :dat)))
(labels
((do-vec () (loop with ,par = (vec! ,par) with ,ires of-type vector = (mav) for ,i from 0
for ,itr across ,par
do ,(compile/?xpr rec
`((:par . ,par) (:dat . ,itr) (:cnt . ,i) (:itr . ,itr) (:key . ,i))
`(,@d (vex ,ires ,@(or (xpr/get-modes d :%) `(,itr)))
nil))
finally (return ,ires)))
(do-ht () (loop with ,kres of-type hash-table = (new$) ; todo: handle _
for ,i from 0
(do-ht () (loop with ,kres of-type hash-table = (new$) for ,i from 0
for ,itr being the hash-values of ,par using (hash-key ,k)
do ,(compile/?xpr rec `((:par . ,par) (:dat . ,itr)
(:cnt . ,i) (:itr . ,itr) (:key . ,k))
`(,@d (setf (gethash ,k ,kres) ,@(or (xpr/get-modes d :%) `(,itr)))
do ,(compile/?xpr rec
`((:par . ,par) (:dat . ,itr) (:cnt . ,i) (:itr . ,itr) (:key . ,k))
`(,@d (setf (gethash ,k ,kres)
,@(or (xpr/get-modes d :%) `(,itr)))
nil))
finally (return ,kres))))
(typecase ,par (null nil) (hash-table (do-ht)) (list (do-vec))
(vector (do-vec)) (simple-vector (do-vec)))))))
(typecase ,par
(null nil) (hash-table (do-ht)) (list (do-vec))
(vector (do-vec)) (simple-vector (do-vec))
(otherwise (error "RT: ** bad type. expected hash-table or vector:~%got: ~a." ,par)))))))

(defun compile/?xpr/bool (rec conf cd)
(labels ((rec (expr) (funcall rec conf expr)))
Expand Down
4 changes: 4 additions & 0 deletions test/test-lqn-2.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
(is (lqn:qry "a b c x def x 27" (splt _ :x) [_ -@int!?]) #("a b c" "def") :test #'equalp)
(is (lqn:qry "a b c x def x 27" (splt _ :x) [-@int!?]) #("a b c" "def") :test #'equalp)

(is (lqn:qry "a b c x def x 27" (splt _ :x) [-@int!?]) #("a b c" "def") :test #'equalp)
(is (lqn:ldnout (lqn:qry (lqn:jsnloads "{\"a\": 1, \"b\": 23}") [_ (-@= _ 1)])) '((:B . 23)))
(is (lqn:ldnout (lqn:qry (lqn:jsnloads "{\"a\": 1, \"b\": 23}") [(equal (key) "a")])) '((:A . 1)))

(is (lqn:qry "1 xx x 2 3" (splt _ :x t)) #("1" "" "" "2 3") :test #'equalp)
(is (lqn:qry "1 xx x 2 3" (splt _ :x t t)) #("1" "2 3") :test #'equalp)
(is (lqn:qry "1 xx x 2 3" (splt _ :x nil)) #("1 " "" " " " 2 3") :test #'equalp)
Expand Down

0 comments on commit 7ec0015

Please sign in to comment.