It works!
This commit is contained in:
parent
4237f4bc53
commit
0d0b6bb808
1 changed files with 36 additions and 32 deletions
68
org-ql.el
68
org-ql.el
|
|
@ -194,13 +194,14 @@ See Info node `(org-ql)Queries'."
|
||||||
;; the function correctly, apparently because `org-ql-predicates'
|
;; the function correctly, apparently because `org-ql-predicates'
|
||||||
;; ends up being not defined correctly at expansion time.
|
;; ends up being not defined correctly at expansion time.
|
||||||
|
|
||||||
(defmacro org-ql--def-plain-query-fn ()
|
(defun org-ql--def-plain-query-fn ()
|
||||||
"Define function `org-ql--plain-query'.
|
"Define function `org-ql--plain-query'.
|
||||||
Builds the PEG expression using predicates defined in
|
Builds the PEG expression using predicates defined in
|
||||||
`org-ql-predicates' and `org-ql-predicates-extra-aliases'."
|
`org-ql-predicates' and `org-ql-predicates-extra-aliases'."
|
||||||
(let* ((predicates (--map (symbol-name (plist-get it :name))
|
(let* ((predicates (--map (symbol-name (plist-get (cdr it) :name))
|
||||||
org-ql-predicates))
|
org-ql-predicates))
|
||||||
(aliases (->> org-ql-predicates
|
(aliases (->> org-ql-predicates
|
||||||
|
(-map #'cdr)
|
||||||
(--map (plist-get it :aliases))
|
(--map (plist-get it :aliases))
|
||||||
-non-nil
|
-non-nil
|
||||||
-flatten
|
-flatten
|
||||||
|
|
@ -211,37 +212,40 @@ Builds the PEG expression using predicates defined in
|
||||||
;; obscure bug in `peg': when one keyword is a substring of another,
|
;; obscure bug in `peg': when one keyword is a substring of another,
|
||||||
;; and the shorter one is listed first, the shorter one fails to match.
|
;; and the shorter one is listed first, the shorter one fails to match.
|
||||||
(-sort (-on #'> #'length)))))
|
(-sort (-on #'> #'length)))))
|
||||||
`(cl-defun org-ql--plain-query (input &optional (boolean 'and))
|
(fset 'org-ql--plain-query
|
||||||
"Return query parsed from plain query string INPUT.
|
(byte-compile
|
||||||
|
`(cl-function
|
||||||
|
(lambda (input &optional (boolean 'and))
|
||||||
|
"Return query parsed from plain query string INPUT.
|
||||||
Multiple predicates are combined with BOOLEAN."
|
Multiple predicates are combined with BOOLEAN."
|
||||||
(unless (s-blank-str? input)
|
(unless (s-blank-str? input)
|
||||||
(let* ((query (org-ql--peg-parse-string
|
(let* ((query (org-ql--peg-parse-string
|
||||||
((query (+ term
|
((query (+ term
|
||||||
(opt (+ (syntax-class whitespace) (any)))))
|
(opt (+ (syntax-class whitespace) (any)))))
|
||||||
(term (or (and negation (list positive-term)
|
(term (or (and negation (list positive-term)
|
||||||
;; This is a bit confusing, but it seems to work. There's probably a better way.
|
;; This is a bit confusing, but it seems to work. There's probably a better way.
|
||||||
`(pred -- (list 'not (car pred))))
|
`(pred -- (list 'not (car pred))))
|
||||||
positive-term))
|
positive-term))
|
||||||
(positive-term (or (and predicate-with-args `(pred args -- (cons (intern pred) args)))
|
(positive-term (or (and predicate-with-args `(pred args -- (cons (intern pred) args)))
|
||||||
(and predicate-without-args `(pred -- (list (intern pred))))
|
(and predicate-without-args `(pred -- (list (intern pred))))
|
||||||
(and plain-string `(s -- (list 'regexp s)))))
|
(and plain-string `(s -- (list 'regexp s)))))
|
||||||
(plain-string (or quoted-arg unquoted-arg))
|
(plain-string (or quoted-arg unquoted-arg))
|
||||||
(predicate-with-args (substring predicate) ":" args)
|
(predicate-with-args (substring predicate) ":" args)
|
||||||
(predicate-without-args (substring predicate) ":")
|
(predicate-without-args (substring predicate) ":")
|
||||||
(predicate (or ,@predicates))
|
(predicate (or ,@predicates))
|
||||||
(args (list (+ (and (or keyword-arg quoted-arg unquoted-arg) (opt separator)))))
|
(args (list (+ (and (or keyword-arg quoted-arg unquoted-arg) (opt separator)))))
|
||||||
(keyword-arg (and keyword "=" `(kw -- (intern (concat ":" kw)))))
|
(keyword-arg (and keyword "=" `(kw -- (intern (concat ":" kw)))))
|
||||||
(keyword (substring (+ (not (or separator "=" "\"" (syntax-class whitespace))) (any))))
|
(keyword (substring (+ (not (or separator "=" "\"" (syntax-class whitespace))) (any))))
|
||||||
(quoted-arg "\"" (substring (+ (not (or separator "\"")) (any))) "\"")
|
(quoted-arg "\"" (substring (+ (not (or separator "\"")) (any))) "\"")
|
||||||
(unquoted-arg (substring (+ (not (or separator "\"" (syntax-class whitespace))) (any))))
|
(unquoted-arg (substring (+ (not (or separator "\"" (syntax-class whitespace))) (any))))
|
||||||
(negation "!")
|
(negation "!")
|
||||||
(separator "," ))
|
(separator "," ))
|
||||||
input 'noerror)))
|
input 'noerror)))
|
||||||
;; Discard the t that `peg-parse-string' always returns as the first
|
;; Discard the t that `peg-parse-string' always returns as the first
|
||||||
;; element. I don't know what it means, but we don't want it.
|
;; element. I don't know what it means, but we don't want it.
|
||||||
(if (> (length (cdr query)) 1)
|
(if (> (length (cdr query)) 1)
|
||||||
(cons boolean (nreverse (cdr query)))
|
(cons boolean (nreverse (cdr query)))
|
||||||
(cadr query))))))))
|
(cadr query)))))))))))
|
||||||
|
|
||||||
;;;;; Predicate definition
|
;;;;; Predicate definition
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue