MCPcopy Create free account
hub / github.com/boostorg/parser / parse

Function parse

example/callback_json.cpp:237–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235 // return type is just bool.
236 template<typename Callbacks>
237 bool parse(
238 std::string_view str,
239 std::string_view filename,
240 Callbacks const & callbacks,
241 int max_recursion = 512)
242 {
243 auto const range = boost::parser::as_utf32(str);
244 using iter_t = decltype(range.begin());
245
246 if (max_recursion <= 0)
247 max_recursion = INT_MAX;
248
249 global_state globals{0, max_recursion};
250 // This is a different error handler from the json.cpp example, just
251 // to show different options.
252 bp::stream_error_handler error_handler(filename);
253 auto const parser = bp::with_error_handler(
254 bp::with_globals(value, globals), error_handler);
255
256 try {
257 // This is identical to the parse() call in json.cpp, except that
258 // it is callback_parse() instead, and it takes the callbacks
259 // parameter.
260 return bp::callback_parse(range, parser, ws, callbacks);
261 } catch (excessive_nesting<iter_t> const & e) {
262 std::string const message = "error: Exceeded maximum number (" +
263 std::to_string(max_recursion) +
264 ") of open arrays and/or objects";
265 bp::write_formatted_message(
266 std::cout,
267 filename,
268 range.begin(),
269 e.iter,
270 range.end(),
271 message);
272 }
273
274 return {};
275 }
276
277}
278

Callers 1

mainFunction · 0.70

Calls 4

with_error_handlerFunction · 0.85
with_globalsFunction · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected