]> git.tdb.fi Git - libs/datafile.git/commitdiff
Add a flag to return also internal statements
authorMikko Rasa <tdb@tdb.fi>
Fri, 28 Sep 2012 22:54:06 +0000 (01:54 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 28 Sep 2012 22:54:06 +0000 (01:54 +0300)
source/binaryparser.cpp
source/binaryparser.h
source/parser.cpp
source/parser.h
source/parsermode.h
source/textparser.cpp
source/textparser.h

index fd918758294fd6c1d66ac497af5d5674d629c691..796a592d3e84d05a70e2e8316abdcccbe543f3bf 100644 (file)
@@ -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<int>();
@@ -64,10 +64,13 @@ Statement BinaryParser::parse()
                        float_precision = st.args[0].get<unsigned>();
                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; j<nsub; ++j)
-               result.sub.push_back(parse());
+               result.sub.push_back(parse(raw));
 
        result.valid = true;
 
index b4fec6b4c9e681f6f635a7e348868d65097eddeb..e6735f2435a71c447450ecd58aacbf46342859be 100644 (file)
@@ -26,9 +26,9 @@ private:
 public:
        BinaryParser(Input &i, const std::string &s);
 
-       virtual Statement parse();
+       virtual Statement parse(bool);
 private:
-       Statement parse_statement();
+       Statement parse_statement(bool);
        IntType::Store parse_int();
        FloatType::Store parse_float();
        StringType::Store parse_string();
index fce12e245b3f6ab011e4ca45851b0086847a4e5f..3957cf343642b54f2f5b6123be3e907bc200436e 100644 (file)
@@ -23,7 +23,7 @@ Parser::~Parser()
        delete mode;
 }
 
-Statement Parser::parse()
+Statement Parser::parse(bool raw)
 {
        if(!good)
                throw logic_error("Parser::parse() !good");
@@ -32,7 +32,7 @@ Statement Parser::parse()
        {
                while(1)
                {
-                       Statement st = mode->parse();
+                       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)
index 40907dcdb86b4b6b5a21b7635463f5d242b310f2..aeab71d2d3fbd4022e30a9c8b26b0ab3d14a31ed 100644 (file)
@@ -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; }
 };
index d599691b11e7f7889e21232ebea2a5db7e016f1b..58a7e27de1704a2ab0aee90aa13a5b14c0145a0a 100644 (file)
@@ -21,7 +21,7 @@ protected:
 public:
        virtual ~ParserMode() { }
 
-       virtual Statement parse() = 0;
+       virtual Statement parse(bool) = 0;
 };
 
 } // namespace DataFile
index 9bed08ac9e0ea5a154208b24cda76dc75925267b..225425b4e23166eea05fe0697f16974c327ab1c0 100644 (file)
@@ -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);
 }
index ef7d68e2eb706129558f26391fd374a3d2d2e851..2ac4e88bf1fcbaba640d71da45c0c444556af3fa 100644 (file)
@@ -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();