| 8820 | template <typename SAX> |
| 8821 | JSON_HEDLEY_NON_NULL(2) |
| 8822 | bool sax_parse_internal(SAX* sax) |
| 8823 | { |
| 8824 | // stack to remember the hierarchy of structured values we are parsing |
| 8825 | // true = array; false = object |
| 8826 | std::vector<bool> states; |
| 8827 | // value to avoid a goto (see comment where set to true) |
| 8828 | bool skip_to_state_evaluation = false; |
| 8829 | |
| 8830 | while (true) |
| 8831 | { |
| 8832 | if (not skip_to_state_evaluation) |
| 8833 | { |
| 8834 | // invariant: get_token() was called before each iteration |
| 8835 | switch (last_token) |
| 8836 | { |
| 8837 | case token_type::begin_object: |
| 8838 | { |
| 8839 | if (JSON_HEDLEY_UNLIKELY(not sax->start_object(std::size_t(-1)))) |
| 8840 | { |
| 8841 | return false; |
| 8842 | } |
| 8843 | |
| 8844 | // closing } -> we are done |
| 8845 | if (get_token() == token_type::end_object) |
| 8846 | { |
| 8847 | if (JSON_HEDLEY_UNLIKELY(not sax->end_object())) |
| 8848 | { |
| 8849 | return false; |
| 8850 | } |
| 8851 | break; |
| 8852 | } |
| 8853 | |
| 8854 | // parse key |
| 8855 | if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string)) |
| 8856 | { |
| 8857 | return sax->parse_error(m_lexer.get_position(), |
| 8858 | m_lexer.get_token_string(), |
| 8859 | parse_error::create(101, m_lexer.get_position(), |
| 8860 | exception_message(token_type::value_string, "object key"))); |
| 8861 | } |
| 8862 | if (JSON_HEDLEY_UNLIKELY(not sax->key(m_lexer.get_string()))) |
| 8863 | { |
| 8864 | return false; |
| 8865 | } |
| 8866 | |
| 8867 | // parse separator (:) |
| 8868 | if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) |
| 8869 | { |
| 8870 | return sax->parse_error(m_lexer.get_position(), |
| 8871 | m_lexer.get_token_string(), |
| 8872 | parse_error::create(101, m_lexer.get_position(), |
| 8873 | exception_message(token_type::name_separator, "object separator"))); |
| 8874 | } |
| 8875 | |
| 8876 | // remember we are now inside an object |
| 8877 | states.push_back(false); |
| 8878 | |
| 8879 | // parse values |
nothing calls this directly
no test coverage detected