! @brief public parser interface @param[in] strict whether to expect the last token to be EOF @param[in,out] result parsed JSON value @throw parse_error.101 in case of an unexpected token @throw parse_error.102 if to_unicode fails or surrogate error @throw parse_error.103 if to_unicode fails */
| 11008 | @throw parse_error.103 if to_unicode fails |
| 11009 | */ |
| 11010 | void parse(const bool strict, BasicJsonType& result) |
| 11011 | { |
| 11012 | if (callback) |
| 11013 | { |
| 11014 | json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions); |
| 11015 | sax_parse_internal(&sdp); |
| 11016 | |
| 11017 | // in strict mode, input must be completely read |
| 11018 | if (strict && (get_token() != token_type::end_of_input)) |
| 11019 | { |
| 11020 | sdp.parse_error(m_lexer.get_position(), |
| 11021 | m_lexer.get_token_string(), |
| 11022 | parse_error::create(101, m_lexer.get_position(), |
| 11023 | exception_message(token_type::end_of_input, "value"), BasicJsonType())); |
| 11024 | } |
| 11025 | |
| 11026 | // in case of an error, return discarded value |
| 11027 | if (sdp.is_errored()) |
| 11028 | { |
| 11029 | result = value_t::discarded; |
| 11030 | return; |
| 11031 | } |
| 11032 | |
| 11033 | // set top-level value to null if it was discarded by the callback |
| 11034 | // function |
| 11035 | if (result.is_discarded()) |
| 11036 | { |
| 11037 | result = nullptr; |
| 11038 | } |
| 11039 | } |
| 11040 | else |
| 11041 | { |
| 11042 | json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions); |
| 11043 | sax_parse_internal(&sdp); |
| 11044 | |
| 11045 | // in strict mode, input must be completely read |
| 11046 | if (strict && (get_token() != token_type::end_of_input)) |
| 11047 | { |
| 11048 | sdp.parse_error(m_lexer.get_position(), |
| 11049 | m_lexer.get_token_string(), |
| 11050 | parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType())); |
| 11051 | } |
| 11052 | |
| 11053 | // in case of an error, return discarded value |
| 11054 | if (sdp.is_errored()) |
| 11055 | { |
| 11056 | result = value_t::discarded; |
| 11057 | return; |
| 11058 | } |
| 11059 | } |
| 11060 | |
| 11061 | result.assert_invariant(); |
| 11062 | } |
| 11063 | |
| 11064 | /*! |
| 11065 | @brief public accept interface |