28 #include <boost/functional/hash.hpp> 29 #include <boost/lexical_cast.hpp> 38 using std::sregex_iterator;
39 using std::regex_constants::match_continuous;
40 using boost::hash_combine;
41 using boost::lexical_cast;
47 LUMIERA_ERROR_DEFINE (BINDING_PATTERN_SYNTAX,
"Unable to parse the given binding pattern definition");
56 const string matchSym =
"(\\w+(?:[\\.\\-]\\w+)*)";
57 const string matchArg =
"\\(\\s*"+matchSym+
"?\\s*\\)";
58 regex
findPredicate (
"\\s*"+matchSym+
"("+matchArg+
")?\\s*,?");
67 if (!match[2].matched)
return 0;
68 if (!match[3].matched)
return 0;
80 string::const_iterator end_of_last_match = def.begin();
89 end_of_last_match = match[0].second;
93 if ( end_of_last_match !=def.end()
94 && *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_)
146 Binding::calculateHash()
const 150 typedef NormalisedAtoms::const_iterator AIter;
151 AIter pos = atoms_.begin();
152 AIter end = atoms_.end();
153 for ( ; pos!=end ; ++pos)
155 hash_combine (hash, pos->sym());
156 hash_combine (hash, pos->arity());
157 hash_combine (hash, pos->arg());
175 if (b1.atoms_.size() != b2.atoms_.size())
178 ASSERT (b1.atoms_.size() == b2.atoms_.size());
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))
regex findPredicate("\*"+matchSym+"("+matchArg+")?\*,?")
sym(arg), groups: [symbol, parenthesis, argument symbol]
Conjunction of predicates to be matched against a collaboration partner for establishing an Advice co...
friend bool operator==(Binding const &, Binding const &)
bindings are considered equivalent if, after normalisation, their respective definitions are identica...
void parse_and_append(Literal def)
internal: parse into atoms, and insert them
inline string literal This is a marker type to indicate that
single predicate as part of an advice binding pattern
Derived specific exceptions within Lumiera's exception hierarchy.
A pattern to define and identify a specific attachment to the Advice system.
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...
void addPredicate(Literal spec)
extend the definition of this binding by adding a predicate according to the given textual definition...
size_t HashVal
a STL compatible hash value
Lumiera public interface.
uint detectArity(smatch const &match)
detect the arity of an predicate, as matched by findPredicate.
Binding()
create the empty binding, equivalent to true
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.