X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fparser.cpp;h=3957cf343642b54f2f5b6123be3e907bc200436e;hb=0d8df25704366f3576c417436c90fbac2e479632;hp=06e5a8c33745e78e3855a32f4148e939e93e390f;hpb=6dd94a7fe90c6467024685fbac769067ddb74688;p=libs%2Fdatafile.git diff --git a/source/parser.cpp b/source/parser.cpp index 06e5a8c..3957cf3 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" @@ -18,6 +12,7 @@ namespace DataFile { Parser::Parser(IO::Base &i, const string &s): in(i), + main_src(s), src(s), good(true), mode(new TextParser(in, src)) @@ -28,34 +23,55 @@ Parser::~Parser() delete mode; } -Statement Parser::parse() +Statement Parser::parse(bool raw) { 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(raw); 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 if(st.keyword=="__end") + { + good = false; + return raw ? st : Statement(); } else return st; + + if(raw) + 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); } }