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 
28 namespace armarx
29 {
30  class SimpleLexer;
31 
32  class StructuralJsonParser;
33  using StructuralJsonParserPtr = std::shared_ptr<StructuralJsonParser>;
34 
36  {
37  public:
40  };
41  StructuralJsonParser(const std::string& src, bool acceptSingleValue = true, bool accceptJsStyleKeys = true);
42 
44 
45  void parse();
46 
48  bool iserr();
49  std::string geterr();
50  void geterrpos(int& line, int& col);
51  std::string geterrposstr();
52  std::string getlongerrposstr();
53 
54  static bool DequoteString(std::string str, std::string& res);
55 
56  private:
57  std::unique_ptr<SimpleLexer> lexer;
58  bool acceptSingleValue;
59  bool accceptJsStyleKeys;
60  LexerInfo previousTokenEndOffset;
61 
62  void next();
63  std::string err;
64  std::string expected;
65 
66  JsonDataPtr p_json();
67  JsonDataPtr p_object();
68  void p_pair(JsonObjectPtr o);
69  JsonDataPtr p_array();
70  JsonDataPtr p_item();
71  JsonDataPtr p_leaf();
72  JsonDataPtr error(const std::string& expected, const JsonDataPtr& toReturn = JsonDataPtr());
73  JsonDataPtr stringerror(const std::string& error, const JsonDataPtr& toReturn = JsonDataPtr());
74 
75 
76  };
77 }
78 
armarx::StructuralJsonParser::eOpeningSquareBracket
@ eOpeningSquareBracket
Definition: StructuralJsonParser.h:38
JsonData.h
armarx::StructuralJsonParser::eColon
@ eColon
Definition: StructuralJsonParser.h:39
armarx::StructuralJsonParser::getlongerrposstr
std::string getlongerrposstr()
Definition: StructuralJsonParser.cpp:354
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:42
JsonObject.h
armarx::StructuralJsonParser::geterrpos
void geterrpos(int &line, int &col)
Definition: StructuralJsonParser.cpp:342
armarx::StructuralJsonParser::eNumber
@ eNumber
Definition: StructuralJsonParser.h:39
armarx::StructuralJsonParser::eClosingCurlyBracket
@ eClosingCurlyBracket
Definition: StructuralJsonParser.h:38
armarx::StructuralJsonParser::DequoteString
static bool DequoteString(std::string str, std::string &res)
Definition: StructuralJsonParser.cpp:361
armarx::StructuralJsonParser::StructuralJsonParser
StructuralJsonParser(const std::string &src, bool acceptSingleValue=true, bool accceptJsStyleKeys=true)
Definition: StructuralJsonParser.cpp:28
armarx::StructuralJsonParser::eClosingSquareBracket
@ eClosingSquareBracket
Definition: StructuralJsonParser.h:38
armarx::StructuralJsonParser::eString
@ eString
Definition: StructuralJsonParser.h:39
armarx::StructuralJsonParser::iserr
bool iserr()
Definition: StructuralJsonParser.cpp:332
armarx::StructuralJsonParser::eComma
@ eComma
Definition: StructuralJsonParser.h:39
armarx::StructuralJsonParser::geterrposstr
std::string geterrposstr()
Definition: StructuralJsonParser.cpp:347
armarx::StructuralJsonParser::parse
void parse()
Definition: StructuralJsonParser.cpp:53
armarx::StructuralJsonParser::eWhitespace
@ eWhitespace
Definition: StructuralJsonParser.h:38
armarx::StructuralJsonParser::geterr
std::string geterr()
Definition: StructuralJsonParser.cpp:337
armarx::LexerInfo
Definition: LexerInfo.h:30
armarx::JsonDataPtr
std::shared_ptr< JsonData > JsonDataPtr
Definition: JsonData.h:31
armarx::StructuralJsonParserPtr
std::shared_ptr< StructuralJsonParser > StructuralJsonParserPtr
Definition: StructuralJsonParser.h:33
armarx::StructuralJsonParser::eOpeningCurlyBracket
@ eOpeningCurlyBracket
Definition: StructuralJsonParser.h:38
armarx::StructuralJsonParser::~StructuralJsonParser
~StructuralJsonParser()
Definition: StructuralJsonParser.cpp:48
armarx::StructuralJsonParser::eNull
@ eNull
Definition: StructuralJsonParser.h:39
armarx::StructuralJsonParser
Definition: StructuralJsonParser.h:35
armarx::StructuralJsonParser::parsedJson
JsonDataPtr parsedJson
Definition: StructuralJsonParser.h:47
armarx::StructuralJsonParser::eId
@ eId
Definition: StructuralJsonParser.h:39
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::StructuralJsonParser::eBoolean
@ eBoolean
Definition: StructuralJsonParser.h:39
armarx::JsonObjectPtr
std::shared_ptr< JsonObject > JsonObjectPtr
Definition: JsonObject.h:34
armarx::StructuralJsonParser::TokenType
TokenType
Definition: StructuralJsonParser.h:38