unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob eded98e7133828ec80e99f753140bc28bec57d79 1779 bytes (raw)
name: lib/parse-sexp.cc 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 
#include <xapian.h>
#include "notmuch-private.h"
#include "sexp.h"

typedef struct  {
    const char *name;
    Xapian::Query::op xapian_op;
    Xapian::Query initial;
} _sexp_op_t;

static _sexp_op_t operations[] =
{
    { "and",    Xapian::Query::OP_AND,          Xapian::Query::MatchAll },
    { "not",    Xapian::Query::OP_AND_NOT,      Xapian::Query::MatchAll },
    { "or",     Xapian::Query::OP_OR,           Xapian::Query::MatchNothing },
    { }
};

static Xapian::Query _sexp_to_xapian_query (sexp_t *sx);

static Xapian::Query
_sexp_combine_query (Xapian::Query::op operation,
		     Xapian::Query left,
		     sexp_t *sx)
{

    /* if we run out elements, return accumulator */

    if (! sx)
	return left;

    return _sexp_combine_query (operation,
				Xapian::Query (operation,
					       left,
					       _sexp_to_xapian_query (sx)),
				sx->next);
}

Xapian::Query
_notmuch_sexp_string_to_xapian_query (notmuch_database_t *notmuch, const char *querystr)
{
    sexp_t *sx = NULL;
    char *buf = talloc_strdup (notmuch, querystr);

    sx = parse_sexp (buf, strlen (querystr));
    return _sexp_to_xapian_query (sx);
}

/* Here we expect the s-expression to be a proper list, with first
 * element defining and operation, or as a special case the empty
 * list */

static Xapian::Query
_sexp_to_xapian_query (sexp_t *sx)
{

    const _sexp_op_t *op;

    /* Currently we don't understand atoms */
    assert (sx->ty == SEXP_LIST);

    /* Empty list */
    if (! sx->list)
	return Xapian::Query::MatchAll;

    for (op = operations; op && op->name; op++) {
	if (strcasecmp (op->name, hd_sexp (sx)->val) == 0)
	    return _sexp_combine_query (op->xapian_op, op->initial, sx->list->next);
    }

    INTERNAL_ERROR ("unimplemented prefix %s\n", sx->list->val);
}

debug log:

solving eded98e7 ...
found eded98e7 in https://yhetil.org/notmuch/20210714000239.804384-6-david@tethera.net/

applying [1/1] https://yhetil.org/notmuch/20210714000239.804384-6-david@tethera.net/
diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc
new file mode 100644
index 00000000..eded98e7

Checking patch lib/parse-sexp.cc...
Applied patch lib/parse-sexp.cc cleanly.

index at:
100644 eded98e7133828ec80e99f753140bc28bec57d79	lib/parse-sexp.cc

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).