X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fparser.cpp;h=50948404921bd9903031946a8cc7f537ab37d1bc;hb=8955db30f9cd1c1566b349da29e669f065f84e36;hp=82ac0069b95d4f22e3d0de1ab0c0b66b04c76423;hpb=27630d44298cb67e075c166f4421288cc8ca117e;p=libs%2Fdatafile.git diff --git a/source/parser.cpp b/source/parser.cpp index 82ac006..5094840 100644 --- a/source/parser.cpp +++ b/source/parser.cpp @@ -1,12 +1,6 @@ -/* $Id$ - -This file is part of libmspdatafile -Copyright © 2006 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ -#include -#include +#include #include "binaryparser.h" +#include "dataerror.h" #include "parser.h" #include "statement.h" #include "textparser.h" @@ -16,8 +10,9 @@ using namespace std; namespace Msp { namespace DataFile { -Parser::Parser(istream &i, const string &s): +Parser::Parser(IO::Base &i, const string &s): in(i), + main_src(s), src(s), good(true), mode(new TextParser(in, src)) @@ -31,31 +26,44 @@ Parser::~Parser() Statement Parser::parse() { if(!good) - throw Exception("Parser is not good"); + throw logic_error("Parser::parse() !good"); try { while(1) { - Statement st=mode->parse(); + Statement st = mode->parse(); if(st.keyword=="__bin") { delete mode; - mode=new BinaryParser(in, src); + mode = new BinaryParser(in, src); } else if(st.keyword=="__text") { delete mode; - mode=new TextParser(in, src); + mode = new TextParser(in, src); + } + else if(st.keyword=="__z") + in.set_decompress(); + else if(st.keyword=="__src") + { + string s = st.args[0].get(); + if(s.empty()) + src = main_src; + else + src = format("%s[%s]", main_src, s); } else return st; } } - catch(const Exception &e) + catch(const exception &e) { - good=false; - throw; + good = false; + if(dynamic_cast(&e)) + throw; + else + throw data_error(src, in.get_line_number(), e); } }