From: Mikko Rasa Date: Fri, 28 Sep 2012 22:54:06 +0000 (+0300) Subject: Add a flag to return also internal statements X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6653c7d83dbe1fe81a541a125be8bb808b234eb7;p=libs%2Fdatafile.git Add a flag to return also internal statements --- diff --git a/source/binaryparser.cpp b/source/binaryparser.cpp index fd91875..796a592 100644 --- a/source/binaryparser.cpp +++ b/source/binaryparser.cpp @@ -32,11 +32,11 @@ BinaryParser::BinaryParser(Input &i, const string &s): dict[-3] = DictEntry("__flt", "i"); } -Statement BinaryParser::parse() +Statement BinaryParser::parse(bool raw) { while(1) { - Statement st = parse_statement(); + Statement st = parse_statement(raw); if(st.keyword=="__kwd") { int id = st.args[0].get(); @@ -64,10 +64,13 @@ Statement BinaryParser::parse() float_precision = st.args[0].get(); else return st; + + if(raw) + return st; } } -Statement BinaryParser::parse_statement() +Statement BinaryParser::parse_statement(bool raw) { while(first && in.peek()=='\n') in.get(); @@ -107,7 +110,7 @@ Statement BinaryParser::parse_statement() unsigned nsub = parse_int(); for(unsigned j = 0; jparse(); + Statement st = mode->parse(raw); if(st.keyword=="__bin") { delete mode; @@ -56,10 +56,13 @@ Statement Parser::parse() else if(st.keyword=="__end") { good = false; - return Statement(); + return raw ? st : Statement(); } else return st; + + if(raw) + return st; } } catch(const exception &e) diff --git a/source/parser.h b/source/parser.h index 40907dc..aeab71d 100644 --- a/source/parser.h +++ b/source/parser.h @@ -35,7 +35,7 @@ public: marked as bad and no more statements may be read, even if the exception was caught. */ - Statement parse(); + Statement parse(bool raw = false); operator bool() const { return good && in; } }; diff --git a/source/parsermode.h b/source/parsermode.h index d599691..58a7e27 100644 --- a/source/parsermode.h +++ b/source/parsermode.h @@ -21,7 +21,7 @@ protected: public: virtual ~ParserMode() { } - virtual Statement parse() = 0; + virtual Statement parse(bool) = 0; }; } // namespace DataFile diff --git a/source/textparser.cpp b/source/textparser.cpp index 9bed08a..225425b 100644 --- a/source/textparser.cpp +++ b/source/textparser.cpp @@ -35,7 +35,7 @@ TextParser::TextParser(Input &i, const string &s): ParserMode(i, s) { } -Statement TextParser::parse() +Statement TextParser::parse(bool) { return parse_statement(0); } diff --git a/source/textparser.h b/source/textparser.h index ef7d68e..2ac4e88 100644 --- a/source/textparser.h +++ b/source/textparser.h @@ -13,7 +13,7 @@ class TextParser: public ParserMode public: TextParser(Input &, const std::string &); - virtual Statement parse(); + virtual Statement parse(bool); protected: Statement parse_statement(const Token *); Token parse_token();