#include <msp/strings/format.h>
#include "binaryparser.h"
-#include "dataerror.h"
+#include "except.h"
+#include "jsonparser.h"
#include "parser.h"
#include "statement.h"
#include "textparser.h"
Parser::Parser(IO::Base &i, const string &s):
in(i),
main_src(s),
- src(s),
- good(true),
- mode(new TextParser(in, src))
-{ }
+ src(s)
+{
+ char c = in.peek();
+ if(c=='{' || c=='[')
+ mode = new JsonParser(in, src);
+ else
+ mode = new TextParser(in, src);
+}
Parser::~Parser()
{
{
delete mode;
mode = new BinaryParser(in, src);
+
+ while(in.peek()=='\n')
+ in.get();
}
else if(st.keyword=="__text")
{
mode->process_control_statement(st);
}
+const StatementKey *Parser::peek(unsigned level)
+{
+ while(good)
+ {
+ const StatementKey *key = mode->peek(level);
+ if(key && !key->keyword.compare(0, 2, "__"))
+ process_control_statement(mode->parse());
+ else
+ return key;
+ }
+
+ return nullptr;
+}
+
+bool Parser::parse_and_load(unsigned level, Loader &ldr, const LoaderAction &act)
+{
+ // Peek first to get any control statements processed
+ peek(level);
+ return mode->parse_and_load(level, ldr, act);
+}
+
} // namespace DataFile
} // namespace Msp