An error handler that allows users to supply callbacks to handle the reporting of warnings and errors. The reporting of errors and/or warnings can be suppressed by supplying one or both default-constructed callbacks. */
| 188 | warnings can be suppressed by supplying one or both |
| 189 | default-constructed callbacks. */ |
| 190 | struct callback_error_handler |
| 191 | { |
| 192 | using callback_type = std::function<void(std::string const &)>; |
| 193 | |
| 194 | callback_error_handler() {} |
| 195 | callback_error_handler( |
| 196 | callback_type error, callback_type warning = callback_type()) : |
| 197 | error_(error), warning_(warning) |
| 198 | {} |
| 199 | callback_error_handler( |
| 200 | std::string_view filename, |
| 201 | callback_type error, |
| 202 | callback_type warning = callback_type()) : |
| 203 | error_(error), warning_(warning), filename_(filename) |
| 204 | {} |
| 205 | #if defined(_MSC_VER) || defined(BOOST_PARSER_DOXYGEN) |
| 206 | /** This overload is Windows-only. */ |
| 207 | callback_error_handler( |
| 208 | std::wstring_view filename, |
| 209 | callback_type error, |
| 210 | callback_type warning = callback_type()) : |
| 211 | error_(error), warning_(warning) |
| 212 | { |
| 213 | auto const r = filename | parser::detail::text::as_utf8; |
| 214 | filename_.assign(r.begin(), r.end()); |
| 215 | } |
| 216 | #endif |
| 217 | template<typename Iter, typename Sentinel> |
| 218 | error_handler_result |
| 219 | operator()(Iter first, Sentinel last, parse_error<Iter> const & e) const |
| 220 | { |
| 221 | if (error_) { |
| 222 | std::stringstream ss; |
| 223 | parser::write_formatted_expectation_failure_error_message( |
| 224 | ss, filename_, first, last, e); |
| 225 | error_(ss.str()); |
| 226 | } |
| 227 | return error_handler_result::fail; |
| 228 | } |
| 229 | |
| 230 | template<typename Context, typename Iter> |
| 231 | void diagnose( |
| 232 | diagnostic_kind kind, |
| 233 | std::string_view message, |
| 234 | Context const & context, |
| 235 | Iter it) const |
| 236 | { |
| 237 | callback_type const & cb = |
| 238 | kind == diagnostic_kind::error ? error_ : warning_; |
| 239 | if (!cb) |
| 240 | return; |
| 241 | std::stringstream ss; |
| 242 | parser::write_formatted_message( |
| 243 | ss, |
| 244 | filename_, |
| 245 | parser::_begin(context), |
| 246 | it, |
| 247 | parser::_end(context), |
nothing calls this directly
no outgoing calls
no test coverage detected