28#include <boost/functional/hash.hpp>
29#include <boost/lexical_cast.hpp>
38using std::sregex_iterator;
39using std::regex_constants::match_continuous;
40using boost::hash_combine;
41using boost::lexical_cast;
56 const string matchSym =
"(\\w+(?:[\\.\\-]\\w+)*)";
67 if (!match[2].matched)
return 0;
68 if (!match[3].matched)
return 0;
80 string::const_iterator end_of_last_match = def.begin();
83 sregex_iterator pos (def.begin(),def.end(), findPredicate,
88 atoms_.insert (
Atom (match[1], detectArity(match), match[3]));
89 end_of_last_match = match[0].second;
93 if ( end_of_last_match !=def.end()
94 and *end_of_last_match !=
'.'
97 , LUMIERA_ERROR_BINDING_PATTERN_SYNTAX);
121 Binding::operator string()
const
123 string repr(
"Binding[");
124 typedef NormalisedAtoms::const_iterator AIter;
125 AIter end = atoms_.end();
126 AIter pos = atoms_.begin();
127 for ( ; pos!=end ; ++pos)
128 repr +=
string(*pos)+
", ";
130 if (0 < atoms_.size())
131 repr.resize(repr.size()-2);
138 Binding::Atom::operator string()
const
140 return sym_+
"/"+lexical_cast<string> (ari_)
150 typedef NormalisedAtoms::const_iterator AIter;
151 AIter pos =
atoms_.begin();
153 for ( ; pos!=end ; ++pos)
155 hash_combine (
hash, pos->sym());
156 hash_combine (
hash, pos->arity());
157 hash_combine (
hash, pos->arg());
180 typedef Binding::NormalisedAtoms::const_iterator Iter;
181 Iter end = b1.
atoms_.end();
182 Iter p1 = b1.
atoms_.begin();
183 Iter p2 = b2.
atoms_.begin();
185 for ( ; p1!=end; ++p1, ++p2 )
186 if (! p1->identical(*p2))
single predicate as part of an advice binding pattern
Conjunction of predicates to be matched against a collaboration partner for establishing an Advice co...
HashVal calculateHash() const
Binding()
create the empty binding, equivalent to true
void addPredicate(Literal spec)
extend the definition of this binding by adding a predicate according to the given textual definition
void parse_and_append(Literal def)
internal: parse into atoms, and insert them
A pattern to define and identify a specific attachment to the Advice system.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
regex findPredicate("\\s*"+matchSym+"("+matchArg+")?\\s*,?")
sym(arg), groups: [symbol, parenthesis, argument symbol]
uint detectArity(smatch const &match)
detect the arity of an predicate, as matched by findPredicate.
bool operator==(Binding const &b1, Binding const &b2)
bindings are considered equivalent if, after normalisation, their respective definitions are identica...
LumieraError< LERR_(INVALID)> Invalid
Lumiera public interface.
bool isnil(lib::time::Duration const &dur)
Marker types to indicate a literal string and a Symbol.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...