! @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 */
| 91 | @throw parse_error.103 if to_unicode fails |
| 92 | */ |
| 93 | void parse(const bool strict, BasicJsonType& result) |
| 94 | { |
| 95 | if (callback) |
| 96 | { |
| 97 | json_sax_dom_callback_parser<BasicJsonType, InputAdapterType> sdp(result, callback, allow_exceptions, &m_lexer); |
| 98 | sax_parse_internal(&sdp); |
| 99 | |
| 100 | // in strict mode, input must be completely read |
| 101 | if (strict && (get_token() != token_type::end_of_input)) |
| 102 | { |
| 103 | sdp.parse_error(m_lexer.get_position(), |
| 104 | m_lexer.get_token_string(), |
| 105 | parse_error::create(101, m_lexer.get_position(), |
| 106 | exception_message(token_type::end_of_input, "value"), nullptr)); |
| 107 | } |
| 108 | |
| 109 | // in case of an error, return a discarded value |
| 110 | if (sdp.is_errored()) |
| 111 | { |
| 112 | result = value_t::discarded; |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | // set top-level value to null if it was discarded by the callback |
| 117 | // function |
| 118 | if (result.is_discarded()) |
| 119 | { |
| 120 | result = nullptr; |
| 121 | } |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | json_sax_dom_parser<BasicJsonType, InputAdapterType> sdp(result, allow_exceptions, &m_lexer); |
| 126 | sax_parse_internal(&sdp); |
| 127 | |
| 128 | // in strict mode, input must be completely read |
| 129 | if (strict && (get_token() != token_type::end_of_input)) |
| 130 | { |
| 131 | sdp.parse_error(m_lexer.get_position(), |
| 132 | m_lexer.get_token_string(), |
| 133 | parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr)); |
| 134 | } |
| 135 | |
| 136 | // in case of an error, return a discarded value |
| 137 | if (sdp.is_errored()) |
| 138 | { |
| 139 | result = value_t::discarded; |
| 140 | return; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | result.assert_invariant(); |
| 145 | } |
| 146 | |
| 147 | /*! |
| 148 | @brief public accept interface |
no test coverage detected