]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/parser.cpp
Add a flag to return also internal statements
[libs/datafile.git] / source / parser.cpp
index 957018f7a35c1e302e659da5f4ac5650f14aeca6..3957cf343642b54f2f5b6123be3e907bc200436e 100644 (file)
@@ -1,5 +1,6 @@
-#include <msp/strings/formatter.h>
+#include <msp/strings/format.h>
 #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<string>();
@@ -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<const data_error *>(&e))
+                       throw;
+               else
+                       throw data_error(src, in.get_line_number(), e);
        }
 }