X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fparser.cpp;h=3957cf343642b54f2f5b6123be3e907bc200436e;hb=6653c7d83dbe1fe81a541a125be8bb808b234eb7;hp=99ece49a0375d57345cf1c905d4d395a37eeb167;hpb=3b0d6fb8462bf87956099365d02ebb28435509cd;p=libs%2Fdatafile.git diff --git a/source/parser.cpp b/source/parser.cpp index 99ece49..3957cf3 100644 --- a/source/parser.cpp +++ b/source/parser.cpp @@ -1,5 +1,6 @@ #include #include "binaryparser.h" +#include "dataerror.h" #include "parser.h" #include "statement.h" #include "textparser.h" @@ -22,16 +23,16 @@ 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; @@ -42,6 +43,8 @@ Statement Parser::parse() delete mode; mode = new TextParser(in, src); } + else if(st.keyword=="__z") + in.set_decompress(); else if(st.keyword=="__src") { string s = st.args[0].get(); @@ -50,14 +53,25 @@ Statement Parser::parse() 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; + if(dynamic_cast(&e)) + throw; + else + throw data_error(src, in.get_line_number(), e); } }