Go to the documentation of this file.
4 #ifndef LEXY_EXT_REPORT_ERROR_HPP_INCLUDED
5 #define LEXY_EXT_REPORT_ERROR_HPP_INCLUDED
39 template <
typename Input>
51 template <
typename OutputIt,
typename Writer>
60 out = write_color<color::red, color::bold>(out,
_opts);
64 out = write_color<color::yellow, color::bold>(out,
_opts);
68 out = write_color<color::bold>(out,
_opts);
72 out = write_color<color::bold>(out,
_opts);
76 out = write_color<color::bold>(out,
_opts);
80 out = write_color<color::bold>(out,
_opts);
84 out = write_color<color::bold>(out,
_opts);
88 out = write_color<color::reset>(out,
_opts);
90 out = message(out,
_opts);
97 template <
typename OutputIt>
98 OutputIt
write_path(OutputIt out,
const char* path)
const
103 out = write_color<color::blue>(out,
_opts);
105 out = write_color<color::reset>(out,
_opts);
113 template <
typename OutputIt>
129 template <
typename OutputIt,
typename Location,
typename IteratorOrSize,
typename Writer>
131 IteratorOrSize
end,
const Writer& message)
const
139 auto annotate_eof = line.truncated_multiline && !line.annotated_newline;
143 out = write_color<color::blue>(out,
_opts);
144 out =
write_format(out,
"%4zd ", begin_location.line_nr());
145 out = write_color<color::reset>(out,
_opts);
155 out = write_color<color::reset>(out,
_opts);
169 for (
auto i = 0u; i != indent_count; ++i)
177 for (
auto i = 0u; i != underline_count; ++i)
179 if (underline_count == 0 || annotate_eof)
187 return write_color<color::reset>(out,
_opts);
199 template <
typename OutputIt>
208 return write_color<color::red, color::bold>(out,
_opts);
210 return write_color<color::yellow>(out,
_opts);
236 template <
typename OutputIt,
typename Input,
typename Reader,
typename Tag>
260 if (location.line_nr() != context_location.line_nr())
271 if constexpr (std::is_same_v<Tag, lexy::expected_literal>)
273 auto string = lexy::_detail::make_literal_lexeme<typename Reader::encoding>(
error.string(),
278 out = lexy::_detail::write_str(out,
"expected '");
279 out = lexy::visualize_to(out, string, opts);
280 out = lexy::_detail::write_str(out,
"'");
284 else if constexpr (std::is_same_v<Tag, lexy::expected_keyword>)
286 auto string = lexy::_detail::make_literal_lexeme<typename Reader::encoding>(
error.string(),
291 out = lexy::_detail::write_str(out,
"expected keyword '");
292 out = lexy::visualize_to(out, string, opts);
293 out = lexy::_detail::write_str(out,
"'");
297 else if constexpr (std::is_same_v<Tag, lexy::expected_char_class>)
320 template <
typename OutputIterator>
336 template <
typename Input,
typename Reader,
typename Tag>
359 return {_iter,
_opts, path};
363 template <
typename OI>
366 return {out,
_opts, _path};
372 return {_iter, opts, _path};
380 #endif // LEXY_EXT_REPORT_ERROR_HPP_INCLUDED
constexpr auto position() const noexcept
The starting position of the production.
lexy::visualization_options _opts
@ visualize_use_color
Visualization can use ANSI color escape sequences.
constexpr OutIt write_format(OutIt out, const char *fmt, const Args &... args)
OutputIt write_annotation(OutputIt out, annotation_kind kind, const Location &begin_location, IteratorOrSize end, const Writer &message) const
std::size_t visualization_display_width(const T &obj, visualization_options opts={})
lexy::visualization_options _opts
constexpr OutIt write_str(OutIt out, const char *str)
diagnostic_kind
The kind of diagnostic message.
diagnostic_writer(const Input &input, lexy::visualization_options opts={})
Options that control visualization.
constexpr auto sink() const
constexpr bool is_set(visualization_flags f) const noexcept
constexpr Iterator next(Iterator iter)
OutputIt write_error(OutputIt out, const lexy::error_context< Input > &context, const lexy::error< Reader, Tag > &error, lexy::visualization_options opts, const char *path)
constexpr visualization_options reset(visualization_flags f) const noexcept
constexpr _report_error opts(lexy::visualization_options opts) const
Overrides visualization options.
lexy::visualization_options _opts
constexpr auto get_input_location(const Input &input, typename lexy::input_reader< Input >::iterator position, input_location_anchor< Input > anchor) -> input_location< Input, Counting >
The location for a position in the input; search starts at the anchor.
Contains information about the context of an error, production is type-erased.
const char * production() const noexcept
The name of the production where the error occurred.
constexpr auto end(const C &c) -> decltype(c.end())
OutputIt colorize_underline(OutputIt out, annotation_kind kind) const
OutputIt visualize_to(OutputIt out, lexy::code_point cp, visualization_options opts={})
OutputIt write_message(OutputIt out, diagnostic_kind kind, const Writer &message) const
const auto * column() const
constexpr auto get_input_line_annotation(const Input &input, const input_location< Input, Counting > &begin_location, typename lexy::input_reader< Input >::iterator end) -> input_line_annotation< Input >
constexpr _report_error path(const char *path) const
Specifies a path that will be printed alongside the diagnostic.
constexpr auto report_error
An error callback that uses diagnostic_writer to print to stderr (by default).
OutputIt write_path(OutputIt out, const char *path) const
Writes a path.
OutputIt write_empty_annotation(OutputIt out) const
Formats and writes diagnostic messages.
annotation_kind
Classifies a source code annotation.
constexpr const auto & input() const noexcept
The input.
constexpr _report_error< OI > to(OI out) const
Specifies an output iterator where the errors are written to.
@ visualize_use_unicode
Visualization can use unicode characters.
const auto * underline(annotation_kind kind) const
void operator()(const lexy::error_context< Input > &context, const lexy::error< Reader, Tag > &error)