MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / sax_parse_internal

Method sax_parse_internal

examples/server/json.hpp:12278–12556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12276 template<typename SAX>
12277 JSON_HEDLEY_NON_NULL(2)
12278 bool sax_parse_internal(SAX* sax)
12279 {
12280 // stack to remember the hierarchy of structured values we are parsing
12281 // true = array; false = object
12282 std::vector<bool> states;
12283 // value to avoid a goto (see comment where set to true)
12284 bool skip_to_state_evaluation = false;
12285
12286 while (true)
12287 {
12288 if (!skip_to_state_evaluation)
12289 {
12290 // invariant: get_token() was called before each iteration
12291 switch (last_token)
12292 {
12293 case token_type::begin_object:
12294 {
12295 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))
12296 {
12297 return false;
12298 }
12299
12300 // closing } -> we are done
12301 if (get_token() == token_type::end_object)
12302 {
12303 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
12304 {
12305 return false;
12306 }
12307 break;
12308 }
12309
12310 // parse key
12311 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
12312 {
12313 return sax->parse_error(m_lexer.get_position(),
12314 m_lexer.get_token_string(),
12315 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr));
12316 }
12317 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
12318 {
12319 return false;
12320 }
12321
12322 // parse separator (:)
12323 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
12324 {
12325 return sax->parse_error(m_lexer.get_position(),
12326 m_lexer.get_token_string(),
12327 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr));
12328 }
12329
12330 // remember we are now inside an object
12331 states.push_back(false);
12332
12333 // parse values
12334 get_token();
12335 continue;

Callers

nothing calls this directly

Calls 15

get_tokenFunction · 0.85
createFunction · 0.85
isfiniteFunction · 0.85
get_token_stringMethod · 0.80
concatFunction · 0.70
start_objectMethod · 0.45
end_objectMethod · 0.45
parse_errorMethod · 0.45
keyMethod · 0.45
get_stringMethod · 0.45
push_backMethod · 0.45
start_arrayMethod · 0.45

Tested by

no test coverage detected