X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Floader.cpp;h=8d4f2bea35b07f0cf485cbc50a8d22fe146b5cd1;hb=256f7238bc60d6dcc31a564988f5cc02a60c4537;hp=cf1a5acae89dc0e4abe7583358e3926ab629277c;hpb=de02b5618273df1b94085934f699371b4be31783;p=libs%2Fdatafile.git diff --git a/source/loader.cpp b/source/loader.cpp index cf1a5ac..8d4f2be 100644 --- a/source/loader.cpp +++ b/source/loader.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspdatafile -Copyright © 2006 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2008 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -16,6 +16,7 @@ void Loader::load(const Statement &st) { for(list::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i) load_statement(*i); + finish(); } void Loader::load(Parser &p) @@ -26,6 +27,7 @@ void Loader::load(Parser &p) if(st.valid) load_statement(st); } + finish(); } Loader::~Loader() @@ -34,14 +36,45 @@ Loader::~Loader() delete i->second; } +void Loader::load_sub_with(Loader &ldr) +{ + if(!cur_st) + throw InvalidState("load_sub called without current statement"); + + ldr.load(*cur_st); +} + +void Loader::add(const string &k, LoaderAction *a) +{ + ActionMap::iterator i=actions.find(k); + if(i!=actions.end()) + { + delete i->second; + i->second=a; + } + else + actions[k]=a; +} + void Loader::load_statement(const Statement &st) { cur_st=&st; ActionMap::iterator j=actions.find(st.keyword); if(j==actions.end()) - throw KeyError(st.get_location()+": Unknown keyword '"+st.keyword+"'"); + throw_at(KeyError("Unknown keyword", st.keyword), st.get_location()); if(j->second) - j->second->execute(*this, st); + { + try + { + j->second->execute(*this, st); + } + catch(Exception &e) + { + if(!e.where()[0]) + e.at(st.get_location()); + throw; + } + } cur_st=0; }