Go to the documentation of this file.
4 #ifndef LEXY_ACTION_TRACE_HPP_INCLUDED
5 #define LEXY_ACTION_TRACE_HPP_INCLUDED
24 template <
typename CharT, CharT... C>
27 template <
typename NextParser>
30 template <
typename Context,
typename Reader,
typename... Args>
34 context.on(
_ev::debug{}, reader.position(), str);
41 template <lexy::_detail::
string_literal Str>
42 constexpr
auto debug = lexy::_detail::to_type_string<_debug, Str>{};
45 #define LEXY_DEBUG(Str) \
46 LEXY_NTTP_STRING(::lexyd::_debug, Str) {}
52 template <
typename OutputIt,
typename TokenKind>
60 template <
typename Location>
67 _out = _detail::write_color<_detail::color::bold>(
_out,
_opts);
69 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
87 template <
typename Location,
typename Reader>
96 _out = _detail::write_color<_detail::color::bold>(
_out,
_opts);
98 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
107 template <
typename Location,
typename Reader>
115 _out = _detail::write_color<_detail::color::yellow, _detail::color::bold>(
_out,
_opts);
117 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
121 _out = _detail::write_color<_detail::color::yellow>(
_out,
_opts);
123 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
126 template <
typename Location,
typename Reader,
typename Tag>
134 _out = _detail::write_color<_detail::color::red, _detail::color::bold>(
_out,
_opts);
136 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
138 _out = _detail::write_color<_detail::color::red>(
_out,
_opts);
141 if constexpr (std::is_same_v<Tag, lexy::expected_literal>)
143 auto string = _detail::make_literal_lexeme<typename Reader::encoding>(
error.string(),
150 else if constexpr (std::is_same_v<Tag, lexy::expected_keyword>)
152 auto string = _detail::make_literal_lexeme<typename Reader::encoding>(
error.string(),
159 else if constexpr (std::is_same_v<Tag, lexy::expected_char_class>)
169 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
172 template <
typename Location>
179 _out = _detail::write_color<_detail::color::yellow, _detail::color::bold>(
_out,
_opts);
181 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
183 _out = _detail::write_color<_detail::color::yellow>(
_out,
_opts);
185 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
197 template <
typename Location>
205 _out = _detail::write_color<_detail::color::bold>(
_out,
_opts);
207 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
213 template <
typename Location>
221 _out = _detail::write_color<_detail::color::blue, _detail::color::bold>(
_out,
_opts);
223 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
225 _out = _detail::write_color<_detail::color::blue>(
_out,
_opts);
228 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
231 template <
typename Location>
238 template <
typename Location>
260 template <
typename Location>
268 _out = _detail::write_color<_detail::color::faint>(
_out,
_opts);
271 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
285 _out = _detail::write_color<_detail::color::yellow>(
_out,
_opts);
287 _out = _detail::write_color<_detail::color::reset>(
_out,
_opts);
305 template <
typename OutputIt,
typename Input,
typename TokenKind =
void>
333 handler.
_anchor = loc.anchor();
338 handler.
_writer.write_finish(loc);
343 handler.
_writer.write_cancel(loc);
352 handler.
_writer.write_production_start(loc,
"operation chain");
355 template <
typename Operation>
359 handler.
_writer.write_operation(loc, lexy::production_name<Operation>());
364 handler.
_writer.write_finish(loc);
367 template <
typename TK>
380 template <
typename Error>
390 handler.
_writer.write_recovery_start(loc);
395 handler.
_writer.write_finish(loc);
400 handler.
_writer.write_cancel(loc);
406 handler.
_writer.write_debug(loc, str);
416 template <
typename Production,
typename State>
437 template <
typename State,
typename Input,
typename OutputIt,
typename TokenKind =
void>
454 template <
typename U = State>
459 template <
typename Production>
462 auto reader =
input.reader();
468 template <
typename Production,
typename TokenKind =
void,
typename OutputIt,
typename Input>
471 return trace_action<void, Input, OutputIt, TokenKind>(out, opts)(Production{}, input);
473 template <
typename Production,
typename TokenKind =
void,
typename OutputIt,
typename Input,
477 return trace_action<State, Input, OutputIt, TokenKind>(state, out, opts)(Production{}, input);
479 template <
typename Production,
typename TokenKind =
void,
typename OutputIt,
typename Input,
481 OutputIt
trace_to(OutputIt out,
const Input& input,
const State& state,
484 return trace_action<const State, Input, OutputIt, TokenKind>(state, out, opts)(Production{},
488 template <
typename Production,
typename TokenKind =
void,
typename Input>
491 trace_to<Production, TokenKind>(cfile_output_iterator{file}, input, opts);
493 template <
typename Production,
typename TokenKind =
void,
typename Input,
typename State>
496 trace_to<Production, TokenKind>(cfile_output_iterator{file}, input, state, opts);
498 template <
typename Production,
typename TokenKind =
void,
typename Input,
typename State>
501 trace_to<Production, TokenKind>(cfile_output_iterator{file}, input, state, opts);
505 #endif // LEXY_ACTION_TRACE_HPP_INCLUDED
constexpr OutIt write_ellipsis(OutIt out, visualization_options opts)
void on(_th &handler, parse_events::debug, iterator pos, const char *str)
_th(OutputIt out, const Input &input, visualization_options opts={}) noexcept
void on(_th &handler, parse_events::production_start, iterator pos)
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
@ visualize_use_color
Visualization can use ANSI color escape sequences.
void on(_th &handler, parse_events::operation_chain_finish, int, iterator pos)
constexpr OutIt write_format(OutIt out, const char *fmt, const Args &... args)
void on(_th &handler, parse_events::recovery_finish, iterator pos)
constexpr trace_action(U &state, OutputIt out, visualization_options opts={})
typename lexy::input_reader< Input >::iterator iterator
constexpr OutIt write_str(OutIt out, const char *str)
trace_writer(OutputIt out, visualization_options opts)
unsigned char max_tree_depth
constexpr bool ignore_if_empty() const noexcept
constexpr bool empty() const noexcept
void on(_th &handler, parse_events::backtracked, iterator begin, iterator end)
Options that control visualization.
_detail::lazy_init< input_location_anchor< Input > > _previous_anchor
constexpr event_handler(production_info info)
void on(_th &handler, parse_events::production_cancel, iterator pos)
constexpr bool is_set(visualization_flags f) const noexcept
OutputIt trace_to(OutputIt out, const Input &input, visualization_options opts={})
constexpr visualization_options reset(visualization_flags f) const noexcept
void write_production_start(const Location &loc, const char *name)
void on(_th &, parse_events::grammar_start, iterator)
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.
void write_cancel(const Location &loc)
#define LEXY_PRECONDITION(Expr)
void on(_th &handler, parse_events::token, TK kind, iterator begin, iterator end)
constexpr auto end(const C &c) -> decltype(c.end())
void on(_th &, parse_events::grammar_finish, lexy::input_reader< Input > &)
void write_recovery_start(const Location &loc)
static constexpr unsigned char max_tree_depth_limit
OutputIt visualize_to(OutputIt out, lexy::code_point cp, visualization_options opts={})
int on(_th &handler, parse_events::operation_chain_start, iterator pos)
input_location_anchor< Input > _anchor
constexpr auto parse(const Input &input, const ErrorCallback &callback)
Parses the production into a value, invoking the callback on error.
constexpr trace_action(OutputIt out, visualization_options opts={})
void write_backtrack(const Location &loc, lexy::lexeme< Reader > lexeme)
void on(_th &handler, parse_events::production_finish, iterator pos)
void write_debug(const Location &loc, const char *str)
What sort of token it is.
void write_prefix(const Location &loc, prefix p)
void write_error(const Location &loc, const lexy::error< Reader, Tag > &error)
visualization_options _opts
input_location< Input > get_location(typename lexy::input_reader< Input >::iterator pos)
constexpr auto begin(const C &c) -> decltype(c.begin())
visualization_options _opts
void write_finish(const Location &loc)
void trace(std::FILE *file, const Input &input, visualization_options opts={})
void on(_th &handler, parse_events::recovery_start, iterator pos)
constexpr const char * name() const noexcept
void on(_th &handler, parse_events::recovery_cancel, iterator pos)
_detail::trace_writer< OutputIt, TokenKind > _writer
constexpr auto operator()(Production, const Input &input) const
void write_operation(const Location &loc, const char *name)
@ visualize_space
Visualize space ' ' as visible character/symbol.
void write_token(const Location &loc, lexy::token_kind< TokenKind > kind, lexy::lexeme< Reader > lexeme)
@ visualize_use_unicode
Visualization can use unicode characters.
decltype(LEXY_DECLVAL(Input).reader()) input_reader
constexpr auto p
Parses the production.
void on(_th &handler, parse_events::error, const Error &error)
_th< OutputIt, Input > handler
constexpr OutputIt get_result(bool) &&
void on(_th &, parse_events::grammar_cancel, lexy::input_reader< Input > &)
void on(_th &handler, parse_events::operation_chain_op, Operation, iterator pos)