24 #include <boost/algorithm/string.hpp> 32 using std::regex_search;
33 using std::sregex_iterator;
44 using ChPredicate = std::function<bool(string::value_type)> ;
46 ChPredicate is_alpha = boost::algorithm::is_alpha();
47 ChPredicate is_upper = boost::algorithm::is_upper();
54 id = util::sanitise(
id);
55 if (isnil(
id) || !is_alpha (
id[0]))
60 REQUIRE (is_alpha (
id[0]));
64 id[0] = std::tolower (first);
72 map<Symbol, regex> regexTable;
74 Literal MATCH_ARGUMENT = R
"~(\(\s*([\w_\.\-]+)\s*\),?\s*)~"; 75 const regex FIND_PREDICATE{
string{
"(\\w+)"} + MATCH_ARGUMENT};
80 if (!contains (regexTable, sym))
81 regexTable[sym] = regex (
string(sym)+MATCH_ARGUMENT);
82 return regexTable[sym];
95 if (regex_search (termString, match, getTermRegex (sym)))
112 if (regex_search (queryString, match, getTermRegex (sym)))
114 string res (sym); res +=
"("+match[1]+
")";
115 queryString.erase (match.position(), match[0].length());
124 hasTerm (
Symbol sym,
string const& queryString)
127 return regex_search (queryString, match, getTermRegex (sym));
141 for (sregex_iterator i (q.begin(),q.end(), FIND_PREDICATE);
154 return isnil(pred1)? pred2
155 : isnil(pred2)? pred1
156 : 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