StructuralJsonParser.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
17* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
18* GNU General Public License
19*/
20
21#pragma once
22
23#include <memory>
24
25#include "JsonData.h"
26#include "JsonObject.h"
27
28namespace armarx
29{
30 class SimpleLexer;
31
33 using StructuralJsonParserPtr = std::shared_ptr<StructuralJsonParser>;
34
36 {
37 public:
53
54 StructuralJsonParser(const std::string& src,
55 bool acceptSingleValue = true,
56 bool accceptJsStyleKeys = true);
57
59
60 void parse();
61
63 bool iserr();
64 std::string geterr();
65 void geterrpos(int& line, int& col);
66 std::string geterrposstr();
67 std::string getlongerrposstr();
68
69 static bool DequoteString(std::string str, std::string& res);
70
71 private:
72 std::unique_ptr<SimpleLexer> lexer;
73 bool acceptSingleValue;
74 bool accceptJsStyleKeys;
75 LexerInfo previousTokenEndOffset;
76
77 void next();
78 std::string err;
79 std::string expected;
80
81 JsonDataPtr p_json();
82 JsonDataPtr p_object();
83 void p_pair(JsonObjectPtr o);
84 JsonDataPtr p_array();
85 JsonDataPtr p_item();
86 JsonDataPtr p_leaf();
87 JsonDataPtr error(const std::string& expected, const JsonDataPtr& toReturn = JsonDataPtr());
88 JsonDataPtr stringerror(const std::string& error,
89 const JsonDataPtr& toReturn = JsonDataPtr());
90 };
91} // namespace armarx
std::string str(const T &t)
StructuralJsonParser(const std::string &src, bool acceptSingleValue=true, bool accceptJsStyleKeys=true)
void geterrpos(int &line, int &col)
static bool DequoteString(std::string str, std::string &res)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< JsonObject > JsonObjectPtr
Definition JsonObject.h:34
std::shared_ptr< JsonData > JsonDataPtr
Definition JsonData.h:31
std::shared_ptr< StructuralJsonParser > StructuralJsonParserPtr