37 #include <boost/functional/hash.hpp> 38 #include <boost/lexical_cast.hpp> 47 using std::sregex_iterator;
48 using std::regex_constants::match_continuous;
49 using boost::hash_combine;
50 using boost::lexical_cast;
56 LUMIERA_ERROR_DEFINE (BINDING_PATTERN_SYNTAX,
"Unable to parse the given binding pattern definition");
65 const string matchSym =
"(\\w+(?:[\\.\\-]\\w+)*)";
66 const string matchArg =
"\\(\\s*"+matchSym+
"?\\s*\\)";
67 regex
findPredicate (
"\\s*"+matchSym+
"("+matchArg+
")?\\s*,?");
76 if (!match[2].matched)
return 0;
77 if (!match[3].matched)
return 0;
89 string::const_iterator end_of_last_match = def.begin();
98 end_of_last_match = match[0].second;
102 if ( end_of_last_match !=def.end()
103 && *end_of_last_match !=
'.' 106 , LUMIERA_ERROR_BINDING_PATTERN_SYNTAX);
130 Binding::operator string()
const 132 string repr(
"Binding[");
133 typedef NormalisedAtoms::const_iterator AIter;
134 AIter end = atoms_.end();
135 AIter pos = atoms_.begin();
136 for ( ; pos!=end ; ++pos)
137 repr +=
string(*pos)+
", ";
139 if (0 < atoms_.size())
140 repr.resize(repr.size()-2);
147 Binding::Atom::operator string()
const 149 return sym_+
"/"+lexical_cast<
string> (ari_)
155 Binding::calculateHash()
const 159 typedef NormalisedAtoms::const_iterator AIter;
160 AIter pos = atoms_.begin();
161 AIter end = atoms_.end();
162 for ( ; pos!=end ; ++pos)
164 hash_combine (hash, pos->sym());
165 hash_combine (hash, pos->arity());
166 hash_combine (hash, pos->arg());
184 if (b1.atoms_.size() != b2.atoms_.size())
187 ASSERT (b1.atoms_.size() == b2.atoms_.size());
189 typedef Binding::NormalisedAtoms::const_iterator Iter;
190 Iter end = b1.atoms_.end();
191 Iter p1 = b1.atoms_.begin();
192 Iter p2 = b2.atoms_.begin();
194 for ( ; p1!=end; ++p1, ++p2 )
195 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.