tetengo 1.8.2
A multipurpose library set
Loading...
Searching...
No Matches
json_grammar.hpp
Go to the documentation of this file.
1
7#if !defined(TETENGO_JSON_JSONGRAMMAR_HPP)
8#define TETENGO_JSON_JSONGRAMMAR_HPP
9
10#include <functional>
11#include <memory>
12#include <string_view>
13#include <unordered_map>
14
15#include <boost/core/noncopyable.hpp>
16
17
18namespace tetengo::json
19{
20 class reader;
21
22
28 class json_grammar : private boost::noncopyable
29 {
30 public:
31 // types
32
35 {
36 string,
37 number,
38 boolean,
39 null,
40 };
41
52 using primitive_handler_type = std::function<bool(primitive_type_type type, const std::string_view& value)>;
53
56 {
57 object,
58 member,
59 array,
60 };
61
64 {
65 open,
66 close,
67 };
68
80 using structure_handler_type = std::function<bool(
83 const std::unordered_map<std::string_view, std::string_view>& attributes)>;
84
85
86 // constructors and destructor
87
94 json_grammar(primitive_handler_type primitive_handler, structure_handler_type structure_handler);
95
100
101
102 // functions
103
112 [[nodiscard]] bool parse(reader& reader_) const;
113
114
115 private:
116 // types
117
118 class impl;
119
120
121 // variables
122
123 std::unique_ptr<impl> m_p_impl;
124 };
125
126
127}
128
129
130#endif
A JSON grammar.
Definition json_grammar.hpp:29
bool parse(reader &reader_) const
Parses a text.
~json_grammar()
Destroys the JSON grammar.
std::function< bool(primitive_type_type type, const std::string_view &value)> primitive_handler_type
The primitive handler type.
Definition json_grammar.hpp:52
structure_type_type
The structure type type.
Definition json_grammar.hpp:56
primitive_type_type
The primitive type type.
Definition json_grammar.hpp:35
json_grammar(primitive_handler_type primitive_handler, structure_handler_type structure_handler)
Creates a JSON grammar.
structure_open_close_type
The structure open-close type.
Definition json_grammar.hpp:64
std::function< bool( structure_type_type type, structure_open_close_type open_close, const std::unordered_map< std::string_view, std::string_view > &attributes)> structure_handler_type
The structure handler type.
Definition json_grammar.hpp:80
A reader.
Definition reader.hpp:19
A JSON library.