libzypp  17.37.5
json.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_CORE_PARSER_JSON_PARSER_H
13 #define ZYPP_CORE_PARSER_JSON_PARSER_H
14 
15 #include <optional>
20 #include "json/JsonValue.h"
21 
22 namespace zypp::json {
23 
24  class Parser : private base::NonCopyable
25  {
26  public:
28  Parser() = default;
29  Parser(const Parser &) = delete;
30  Parser(Parser &&) = delete;
31  Parser &operator=(const Parser &) = delete;
32  Parser &operator=(Parser &&) = delete;
33 
35  virtual ~Parser(){}
36 
40  zyppng::expected<Value> parse( const InputStream & input_r );
41 
42 
43  struct Token {
44 
45  enum Type {
59  TOK_END, // end of document
61  };
62 
64  std::string _token;
65 
66  static Token eof();
67  };
68 
70 
71  private:
72 
77 
78 
83 
84 
85  std::istream::char_type popChar();
86  std::istream::char_type peekChar();
87  void consumeChar();
88 
89  zyppng::expected<void> consumeString( const std::string &str );
90 
91  static inline std::istream::char_type eofChar() {
92  return std::istream::traits_type::eof();
93  }
94 
95  template <typename T = Token>
97  {
99  }
100 
101  std::optional<InputStream> _stream;
102  int _nestingDepth = 0; //< how deep is the nesting ( prevent memory overflow by too deep nesting )
103  };
104 }
105 #endif
static std::istream::char_type eofChar()
Definition: json.h:91
virtual ~Parser()
Dtor.
Definition: json.h:35
std::string _token
Definition: json.h:64
zyppng::expected< Token > parseNumberToken()
Definition: json.cc:323
String related utilities and Regular expression matching.
zyppng::expected< Value > finishParseValue(Token begin)
Definition: json.cc:265
zyppng::expected< T > makeParseError(const std::string &message, exception_detail::CodeLocation &&loc)
Definition: json.h:96
Helper to create and pass std::istream.
Definition: inputstream.h:56
zyppng::expected< Value > parseValue()
Definition: json.cc:252
std::optional< InputStream > _stream
Definition: json.h:101
zyppng::expected< Array > parseArray()
Definition: json.cc:184
zyppng::expected< Token > parseStringToken()
Definition: json.cc:594
std::istream::char_type peekChar()
Definition: json.cc:478
int _nestingDepth
Definition: json.h:102
Parser & operator=(const Parser &)=delete
zyppng::expected< void > consumeString(const std::string &str)
Definition: json.cc:496
static Token eof()
Definition: json.cc:752
zyppng::expected< Token > parseNullToken()
Definition: json.cc:293
void consumeChar()
Definition: json.cc:490
std::istream::char_type popChar()
Definition: json.cc:466
Keep FILE, FUNCTION and LINE.
Definition: Exception.h:35
zyppng::expected< Object > parseObject()
Definition: json.cc:87
zyppng::expected< Token > nextToken()
Definition: json.cc:508
std::exception_ptr do_ZYPP_EXCPT_PTR(TExcpt &&excpt_r, CodeLocation &&where_r)
Helper for ZYPP_EXCPT_PTR( Exception ).
Definition: Exception.h:435
zyppng::expected< Token > parseBoolToken()
Definition: json.cc:302
Parser()=default
Default ctor.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
zyppng::expected< Value > parse(const InputStream &input_r)
Parse the stream.
Definition: json.cc:37