match.hpp
Go to the documentation of this file.
1 // Copyright (C) 2020-2024 Jonathan Müller and lexy contributors
2 // SPDX-License-Identifier: BSL-1.0
3 
4 #ifndef LEXY_ACTION_MATCH_HPP_INCLUDED
5 #define LEXY_ACTION_MATCH_HPP_INCLUDED
6 
7 #include <lexy/action/base.hpp>
8 
9 namespace lexy
10 {
11 class _mh
12 {
13 public:
14  constexpr _mh() : _failed(false) {}
15 
17  {
18  public:
20 
21  template <typename Error>
22  constexpr void on(_mh& handler, parse_events::error, Error&&)
23  {
24  handler._failed = true;
25  }
26 
27  template <typename Event, typename... Args>
28  constexpr int on(_mh&, Event, const Args&...)
29  {
30  return 0; // operation_chain_start needs to return something
31  }
32  };
33 
34  template <typename Production, typename State>
36 
37  template <typename>
38  constexpr bool get_result(bool rule_parse_result) &&
39  {
40  return rule_parse_result && !_failed;
41  }
42 
43 private:
44  bool _failed;
45 };
46 
47 template <typename State, typename Input>
49 {
50  State* _state = nullptr;
51 
52  using handler = _mh;
53  using state = State;
54  using input = Input;
55 
56  template <typename>
57  using result_type = bool;
58 
59  constexpr match_action() = default;
60  template <typename U = State>
61  constexpr explicit match_action(U& state) : _state(&state)
62  {}
63 
64  template <typename Production>
65  constexpr auto operator()(Production, const Input& input) const
66  {
67  auto reader = input.reader();
68  return lexy::do_action<Production, result_type>(handler(), _state, reader);
69  }
70 };
71 
72 template <typename Production, typename Input>
73 constexpr bool match(const Input& input)
74 {
75  return match_action<void, Input>()(Production{}, input);
76 }
77 template <typename Production, typename Input, typename State>
78 constexpr bool match(const Input& input, State& state)
79 {
80  return match_action<State, Input>(state)(Production{}, input);
81 }
82 template <typename Production, typename Input, typename State>
83 constexpr bool match(const Input& input, const State& state)
84 {
85  return match_action<const State, Input>(state)(Production{}, input);
86 }
87 } // namespace lexy
88 
89 #endif // LEXY_ACTION_MATCH_HPP_INCLUDED
90 
lexy::_mh::event_handler
Definition: match.hpp:16
lexy::_mh::_failed
bool _failed
Definition: match.hpp:44
lexy::match_action::_state
State * _state
Definition: match.hpp:50
lexy
Definition: any_ref.hpp:12
lexy::match_action::result_type
bool result_type
Definition: match.hpp:57
lexy::match_action::handler
_mh handler
Definition: match.hpp:52
lexy::match_action::operator()
constexpr auto operator()(Production, const Input &input) const
Definition: match.hpp:65
lexy::parse_events::error
Definition: dsl/base.hpp:68
lexy::_mh::event_handler::on
constexpr int on(_mh &, Event, const Args &...)
Definition: match.hpp:28
lexy::_mh::event_handler::on
constexpr void on(_mh &handler, parse_events::error, Error &&)
Definition: match.hpp:22
lexy::_detail::void_value_callback
Definition: action/base.hpp:253
lexy::match_action
Definition: match.hpp:48
lexy::match_action::match_action
constexpr match_action(U &state)
Definition: match.hpp:61
lexy::production_info
Definition: grammar.hpp:192
lexy::match
constexpr bool match(const Input &input)
Definition: match.hpp:73
base.hpp
lexy::match_action::input
Input input
Definition: match.hpp:54
lexy::_mh::get_result
constexpr bool get_result(bool rule_parse_result) &&
Definition: match.hpp:38
lexy::_mh::event_handler::event_handler
constexpr event_handler(production_info)
Definition: match.hpp:19
lexy::_mh::_mh
constexpr _mh()
Definition: match.hpp:14
lexy::_mh
Definition: match.hpp:11
lexy::match_action::match_action
constexpr match_action()=default
lexy::match_action::state
State state
Definition: match.hpp:53


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