unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob 1be5e209576bdda3dc32ff030fa510f404aeb511 1560 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
 
#include "database-private.h"
#include "sexp.h"

#if HAVE_SFSEXP

/* _sexp is used for file scope symbols to avoid clashing with
 * definitions from sexp.h */

/* 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 notmuch_status_t
_sexp_to_xapian_query (notmuch_database_t *notmuch, const sexp_t *sx,
		       Xapian::Query &output)
{

    if (sx->ty == SEXP_VALUE) {
	std::string term = Xapian::Unicode::tolower (sx->val);
	Xapian::Stem stem = *(notmuch->stemmer);
	if (sx->aty == SEXP_BASIC)
	    term = "Z" + stem (term);

	output = Xapian::Query (term);
	return NOTMUCH_STATUS_SUCCESS;
    }

    /* Empty list */
    if (! sx->list) {
	output = Xapian::Query::MatchAll;
	return NOTMUCH_STATUS_SUCCESS;
    }

    if (sx->list->ty == SEXP_VALUE)
	_notmuch_database_log (notmuch, "unknown prefix '%s'\n", sx->list->val);
    else
	_notmuch_database_log (notmuch, "unexpected list in field/operation position\n",
			       sx->list->val);

    return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
}

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

    sx = parse_sexp (buf, strlen (querystr));
    if (! sx) {
	_notmuch_database_log (notmuch, "invalid s-expression: '%s'\n", querystr);
	return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
    }

    return _sexp_to_xapian_query (notmuch, sx, output);
}
#endif

debug log:

solving 1be5e209 ...
found 1be5e209 in https://yhetil.org/notmuch/20210812170728.1348333-9-david@tethera.net/ ||
	https://yhetil.org/notmuch/20210730125607.2165433-9-david@tethera.net/
found 1ce3c9d4 in https://yhetil.org/notmuch/20210812170728.1348333-7-david@tethera.net/ ||
	https://yhetil.org/notmuch/20210730125607.2165433-7-david@tethera.net/

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

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

skipping https://yhetil.org/notmuch/20210730125607.2165433-7-david@tethera.net/ for 1ce3c9d4
index at:
100644 1ce3c9d42e8ce614ed481153018d744f276290ca	lib/parse-sexp.cc

applying [2/2] https://yhetil.org/notmuch/20210812170728.1348333-9-david@tethera.net/
diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc
index 1ce3c9d4..1be5e209 100644

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

skipping https://yhetil.org/notmuch/20210730125607.2165433-9-david@tethera.net/ for 1be5e209
index at:
100644 1be5e209576bdda3dc32ff030fa510f404aeb511	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).