main
Matthew Butterick 4 years ago
parent 3f8f761d20
commit 6a5081211d

@ -9,7 +9,7 @@
(loop elem)))))) (loop elem))))))
(list->vector qs)) (list->vector qs))
(define (string->key str #:this [this? #false]) (define (string->key str)
(match str (match str
["doc" 'doc] ["doc" 'doc]
[(or "section" "sec" "s") 'section] [(or "section" "sec" "s") 'section]
@ -29,13 +29,8 @@
(for/list ([piece (in-list (string-split str ":"))]) (for/list ([piece (in-list (string-split str ":"))])
(match (regexp-match #px"^(.*)\\[(.*?)\\]$" piece) (match (regexp-match #px"^(.*)\\[(.*?)\\]$" piece)
[#false (cons (string->key piece) #false)] [#false (cons (string->key piece) #false)]
[(list _ name arg) (cons (hash-ref preds (string->key name)) (or (string->number arg) [(list _ name arg) (cons (hash-ref preds (string->key name))
(string->symbol arg)))]))) (or (string->number arg) (string->symbol arg)))])))
(define (vector-memf proc vec)
(for/first ([idx (in-range (vector-length vec))]
#:when (proc (vector-ref vec idx)))
idx))
(define (query quad-or-index query-str [starting-q #false]) (define (query quad-or-index query-str [starting-q #false])
(define vec (match quad-or-index (define vec (match quad-or-index
@ -47,10 +42,13 @@
#:break (not vidx)) #:break (not vidx))
(match query-piece (match query-piece
[(cons pred 'this) [(cons pred 'this)
;; resolve `this` by finding the querying quad, and searching backward ;; find the querying quad, and from there search backward
(for/first ([vidx (in-range (vector-memq starting-q vec) -1 -1)] (for/first ([vidx (in-range (vector-memq starting-q vec) -1 -1)]
#:when (pred (vector-ref vec vidx))) #:when (pred (vector-ref vec vidx)))
vidx)] vidx)]
[(cons pred 'last) (error 'unimplemented)]
[(cons pred 'prev) (error 'unimplemented)]
[(cons pred 'next) (error 'unimplemented)]
[(cons pred count) [(cons pred count)
(for/fold ([vidx vidx] (for/fold ([vidx vidx]
;; sub 1 because return values add 1 ;; sub 1 because return values add 1

Loading…
Cancel
Save