action/scan.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_SCAN_HPP_INCLUDED
5 #define LEXY_ACTION_SCAN_HPP_INCLUDED
6 
7 #include <lexy/action/base.hpp>
9 #include <lexy/dsl/scan.hpp>
10 
11 namespace lexy
12 {
13 template <typename ControlProduction>
14 struct _scp;
15 template <>
16 struct _scp<void>
17 {
18  static LEXY_CONSTEVAL auto name()
19  {
20  return "scanner control production";
21  }
22 
23  static constexpr auto rule = dsl::scan;
24  static constexpr auto value = lexy::noop;
25 };
26 template <typename ControlProduction>
27 struct _scp : ControlProduction, _scp<void>
28 {};
29 
30 template <typename ControlProduction, typename Input, typename State, typename ErrorCallback>
31 class scanner : public _detail::scanner<scanner<ControlProduction, Input, State, ErrorCallback>,
32  lexy::input_reader<Input>>
33 {
38 
39 public:
40  constexpr explicit scanner(const Input& input, State* state, const ErrorCallback& callback)
41  : _impl(input.reader()), _input(&input), _sink(_get_error_sink(callback)),
43  {
45  }
46 
47  constexpr const auto& parse_state() const
48  {
49  return *_context.control_block->parse_state;
50  }
51 
53  {
54  auto parse_result = static_cast<bool>(*this);
55 
56  if (parse_result)
58  else
60 
61  return LEXY_MOV(_cb.parse_handler)
62  .template get_result<validate_result<ErrorCallback>>(parse_result);
63  }
64 
65 private:
66  auto& context() noexcept
67  {
68  return _context;
69  }
70 
75 
76  friend _impl;
77 };
78 
79 template <typename ControlProduction = void, typename Input, typename ErrorCallback>
80 constexpr auto scan(const Input& input, const ErrorCallback& callback)
81 {
83 }
84 
85 template <typename ControlProduction = void, typename Input, typename State, typename ErrorCallback>
86 constexpr auto scan(const Input& input, State& state, const ErrorCallback& callback)
87 {
89 }
90 template <typename ControlProduction = void, typename Input, typename State, typename ErrorCallback>
91 constexpr auto scan(const Input& input, const State& state, const ErrorCallback& callback)
92 {
94 }
95 } // namespace lexy
96 
97 #endif // LEXY_ACTION_SCAN_HPP_INCLUDED
98 
LEXY_MOV
#define LEXY_MOV(...)
Definition: config.hpp:29
lexy::parse_result
Definition: parse.hpp:16
lexy::parse_events::production_finish
Definition: dsl/base.hpp:34
LEXY_CONSTEVAL
#define LEXY_CONSTEVAL
Definition: config.hpp:98
lexy::noop
constexpr auto noop
A callback with sink that does nothing.
Definition: noop.hpp:30
lexy::_scp
Definition: action/scan.hpp:14
lexy::scanner::_context
_pc< _handler, State, _production > _context
Definition: action/scan.hpp:74
lexy::scanner::finish
constexpr auto finish() &&-> lexy::validate_result< ErrorCallback >
Definition: action/scan.hpp:52
lexy::_vh
Definition: validate.hpp:167
lexy::no_parse_state
constexpr void * no_parse_state
Definition: action/base.hpp:198
lexy::validate_result
Definition: validate.hpp:45
lexy
Definition: any_ref.hpp:12
detail::void
j template void())
Definition: json.hpp:4893
lexy::callback
constexpr auto callback(Fns &&... fns)
Creates a callback.
Definition: adapter.hpp:48
lexy::_scp< void >::name
static LEXY_CONSTEVAL auto name()
Definition: action/scan.hpp:18
lexy::_detail::parse_context_control_block
Definition: action/base.hpp:66
lexy::_get_error_sink
constexpr auto _get_error_sink(const Callback &callback)
Definition: validate.hpp:19
scan.hpp
lexy::scanner::_cb
_detail::parse_context_control_block< _handler, State > _cb
Definition: action/scan.hpp:73
lexy::scanner::_input
_detail::any_holder< const Input * > _input
Definition: action/scan.hpp:71
lexy::scanner::context
auto & context() noexcept
Definition: action/scan.hpp:66
lexy::parse_events::production_start
Definition: dsl/base.hpp:30
lexy::scanner::_impl
friend _impl
Definition: action/scan.hpp:76
lexy::scanner
Definition: action/scan.hpp:31
validate.hpp
lexy::parse_events::production_cancel
Definition: dsl/base.hpp:38
lexy::max_recursion_depth
LEXY_CONSTEVAL std::size_t max_recursion_depth()
Definition: grammar.hpp:181
lexy::_detail::scanner< scanner< ControlProduction, Input, State, ErrorCallback >, lexy::input_reader< Input > >::reader
constexpr lexy::input_reader< Input > & reader() noexcept
Definition: dsl/scan.hpp:404
lexy::scan
constexpr auto scan(const Input &input, const State &state, const ErrorCallback &callback)
Definition: action/scan.hpp:91
lexy::_detail::scanner< scanner< ControlProduction, Input, State, ErrorCallback >, lexy::input_reader< Input > >::position
constexpr auto position() const noexcept -> typename lexy::input_reader< Input > ::iterator
Definition: dsl/scan.hpp:185
lexy::scan
constexpr auto scan(const Input &input, const ErrorCallback &callback)
Definition: action/scan.hpp:80
base.hpp
lexy::scanner::scanner
constexpr scanner(const Input &input, State *state, const ErrorCallback &callback)
Definition: action/scan.hpp:40
lexy::_detail::scanner
Definition: dsl/scan.hpp:33
lexy::scanner::parse_state
constexpr const auto & parse_state() const
Definition: action/scan.hpp:47
lexy::scanner::_sink
_detail::any_holder< _error_sink_t< ErrorCallback > > _sink
Definition: action/scan.hpp:72
lexy::_detail::any_holder< const Input * >
lexy::input_reader
decltype(LEXY_DECLVAL(Input).reader()) input_reader
Definition: input/base.hpp:106
lexy::_pc
Definition: action/base.hpp:117


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