33 #include <boost/algorithm/string.hpp> 41 using std::regex_search;
42 using std::sregex_iterator;
53 using ChPredicate = std::function<bool(string::value_type)> ;
55 ChPredicate is_alpha = boost::algorithm::is_alpha();
56 ChPredicate is_upper = boost::algorithm::is_upper();
63 id = util::sanitise(
id);
64 if (isnil(
id) || !is_alpha (
id[0]))
69 REQUIRE (is_alpha (
id[0]));
73 id[0] = std::tolower (first);
81 map<Symbol, regex> regexTable;
83 Literal MATCH_ARGUMENT = R
"~(\(\s*([\w_\.\-]+)\s*\),?\s*)~"; 84 const regex FIND_PREDICATE{
string{
"(\\w+)"} + MATCH_ARGUMENT};
89 if (!contains (regexTable, sym))
90 regexTable[sym] = regex (
string(sym)+MATCH_ARGUMENT);
91 return regexTable[sym];
104 if (regex_search (termString, match, getTermRegex (sym)))
121 if (regex_search (queryString, match, getTermRegex (sym)))
123 string res (sym); res +=
"("+match[1]+
")";
124 queryString.erase (match.position(), match[0].length());
133 hasTerm (
Symbol sym,
string const& queryString)
136 return regex_search (queryString, match, getTermRegex (sym));
150 for (sregex_iterator i (q.begin(),q.end(), FIND_PREDICATE);
163 return isnil(pred1)? pred2
164 : isnil(pred2)? pred1
165 : pred1 +
", " + pred2;
Utilities to support working with predicate queries.
uint countPred(const string &q)
count the top-level predicates in the query string.
void normaliseID(string &id)
ensure standard format for a given id string.
inline string literal This is a marker type to indicate that
Implementation namespace for support and library code.
string appendTerms(string const &pred1, string const &pred2)
string extractID(Symbol sym, const string &termString)
(preliminary) helper: instead of really parsing and evaluating the terms, just do a regular expressio...
Token or Atom with distinct identity.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
string removeTerm(Symbol sym, string &queryString)
(preliminary) helper: cut a term with the given symbol.
Lumiera error handling (C++ interface).
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container