effect.hpp
Go to the documentation of this file.
1 // Copyright (C) 2022 Jonathan Müller and lexy contributors
2 // SPDX-License-Identifier: BSL-1.0
3 
4 #ifndef LEXY_DSL_EFFECT_HPP_INCLUDED
5 #define LEXY_DSL_EFFECT_HPP_INCLUDED
6 
8 #include <lexy/dsl/base.hpp>
9 
10 namespace lexyd
11 {
12 template <typename EffRule, typename State>
13 using _detect_eff_fn = decltype(EffRule::_fn()(LEXY_DECLVAL(State&)));
14 
15 template <LEXY_NTTP_PARAM Fn>
16 struct _eff : rule_base
17 {
18  static constexpr auto _fn()
19  {
20  return Fn;
21  }
22 
23  template <typename NextParser>
24  struct p
25  {
26  template <typename Context, typename Reader, typename... Args>
27  LEXY_PARSER_FUNC static bool parse(Context& context, Reader& reader, Args&&... args)
28  {
29  using control_block_type = LEXY_DECAY_DECLTYPE(*context.control_block);
30  using state_type = typename control_block_type::state_type;
31 
32  if constexpr (lexy::_detail::is_detected<_detect_eff_fn, _eff, state_type>)
33  {
34  using return_type = decltype(Fn(*context.control_block->parse_state));
35  if constexpr (std::is_void_v<return_type>)
36  {
37  Fn(*context.control_block->parse_state);
38  return NextParser::parse(context, reader, LEXY_FWD(args)...);
39  }
40  else
41  {
42  return NextParser::parse(context, reader, LEXY_FWD(args)...,
43  Fn(*context.control_block->parse_state));
44  }
45  }
46  else
47  {
48  using return_type = decltype(Fn());
49  if constexpr (std::is_void_v<return_type>)
50  {
51  Fn();
52  return NextParser::parse(context, reader, LEXY_FWD(args)...);
53  }
54  else
55  {
56  return NextParser::parse(context, reader, LEXY_FWD(args)..., Fn());
57  }
58  }
59  }
60  };
61 };
62 
64 template <LEXY_NTTP_PARAM Fn>
65 constexpr auto effect = _eff<Fn>{};
66 } // namespace lexyd
67 
68 #endif // LEXY_DSL_EFFECT_HPP_INCLUDED
69 
detect.hpp
lexyd::_eff::p
Definition: effect.hpp:24
LEXY_FWD
#define LEXY_FWD(...)
Definition: config.hpp:30
lexyd::effect
constexpr auto effect
Invokes Fn and produces its value as result.
Definition: effect.hpp:65
lexy::parse
constexpr auto parse(const Input &input, const ErrorCallback &callback)
Parses the production into a value, invoking the callback on error.
Definition: parse.hpp:171
lexyd::_detect_eff_fn
decltype(EffRule::_fn()(LEXY_DECLVAL(State &))) _detect_eff_fn
Definition: effect.hpp:13
LEXY_DECAY_DECLTYPE
#define LEXY_DECAY_DECLTYPE(...)
Definition: config.hpp:34
lexyd::rule_base
Definition: grammar.hpp:17
lexyd::_eff
Definition: effect.hpp:16
LEXY_PARSER_FUNC
#define LEXY_PARSER_FUNC
Definition: dsl/base.hpp:108
base.hpp
lexyd::_eff::_fn
static constexpr auto _fn()
Definition: effect.hpp:18
lexyd::_eff::p::parse
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
Definition: effect.hpp:27
LEXY_DECLVAL
#define LEXY_DECLVAL(...)
Definition: config.hpp:32
lexyd
Definition: trace.hpp:22


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:16