+ cur_st = &st;
+
+ try
+ {
+ LoaderAction *act = find_action(ActionKey(st.keyword, st.get_signature()));
+ if(act)
+ {
+ sub_loaded = false;
+ act->execute(*this, st);
+ if(check_sub_loads && !st.sub.empty() && !sub_loaded)
+ throw Exception("Substatements were not loaded");
+ }
+ }
+ catch(Exception &e)
+ {
+ cur_st = 0;
+ if(!e.where()[0])
+ e.at(st.get_location());
+
+ throw;
+ }
+
+ cur_st = 0;
+}
+
+void Loader::load_sub_with(Loader &ldr)
+{
+ if(!cur_st)
+ throw InvalidState("load_sub called without current statement");
+
+ ldr.load(*cur_st);
+ sub_loaded = true;
+}
+
+void Loader::add(const string &kwd, LoaderAction *act)
+{
+ ActionKey key(kwd, (act ? act->get_signature() : "*"));
+ ActionMap::iterator i = actions.find(key);
+ if(i!=actions.end())
+ {
+ delete i->second;
+ i->second = act;
+ }
+ else
+ actions[key] = act;
+}
+
+LoaderAction *Loader::find_action(const ActionKey &key) const
+{
+ ActionMap::const_iterator begin = actions.lower_bound(ActionKey(key.keyword, string()));
+ ActionMap::const_iterator end = actions.upper_bound(ActionKey(key.keyword, "~"));
+
+ if(begin==end)
+ throw KeyError("Unknown keyword", key.keyword);
+
+ for(ActionMap::const_iterator i=begin; i!=end; ++i)
+ if(signature_match(key.signature, i->first.signature))
+ return i->second;
+
+ throw KeyError(format("Keyword '%s' does not accept signature '%s'", key.keyword, key.signature));
+}
+
+
+Loader::ActionKey::ActionKey(const string &k, const string &s):
+ keyword(k),
+ signature(s)
+{ }
+
+bool Loader::ActionKey::operator<(const ActionKey &other) const
+{
+ if(keyword!=other.keyword)
+ return keyword<other.keyword;
+ return signature<other.signature;