X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Fparser.cpp;h=7e4d3dd7f93942b9d4c9c3b69f2715d93b25b492;hp=9ad70d8742884bfdfa40d5bebbc467b9e289afe7;hb=705aca1ca0f63e7314a25f528e6e7c76765c04b8;hpb=3b78eeb8b92dc3524d6a0456b4daf0a0f3dbf813 diff --git a/source/parser.cpp b/source/parser.cpp index 9ad70d8..7e4d3dd 100644 --- a/source/parser.cpp +++ b/source/parser.cpp @@ -1,6 +1,7 @@ #include #include "binaryparser.h" -#include "dataerror.h" +#include "except.h" +#include "jsonparser.h" #include "parser.h" #include "statement.h" #include "textparser.h" @@ -14,9 +15,14 @@ Parser::Parser(IO::Base &i, const string &s): in(i), main_src(s), src(s), - good(true), - mode(new TextParser(in, src)) -{ } + good(true) +{ + char c = in.peek(); + if(c=='{' || c=='[') + mode = new JsonParser(in, src); + else + mode = new TextParser(in, src); +} Parser::~Parser() { @@ -88,7 +94,7 @@ void Parser::process_control_statement(const Statement &st) const StatementKey *Parser::peek(unsigned level) { - while(1) + while(good) { const StatementKey *key = mode->peek(level); if(key && !key->keyword.compare(0, 2, "__")) @@ -96,6 +102,8 @@ const StatementKey *Parser::peek(unsigned level) else return key; } + + return 0; } bool Parser::parse_and_load(unsigned level, Loader &ldr, const LoaderAction &act)