times.hpp
Go to the documentation of this file.
1 // Copyright (C) 2020-2023 Jonathan Müller and lexy contributors
2 // SPDX-License-Identifier: BSL-1.0
3 
4 #ifndef LEXY_DSL_TIMES_HPP_INCLUDED
5 #define LEXY_DSL_TIMES_HPP_INCLUDED
6 
7 #include <lexy/dsl/base.hpp>
8 #include <lexy/dsl/sequence.hpp>
9 
10 namespace lexyd
11 {
12 template <std::size_t N, typename Rule, typename Sep>
13 struct _times : rule_base
14 {
15  template <std::size_t I = N>
16  static constexpr auto _repeated_rule()
17  {
18  if constexpr (I == 1)
19  {
20  if constexpr (std::is_same_v<Sep, void>)
21  return Rule{};
22  else
23  return Rule{} + typename Sep::trailing_rule{};
24  }
25  else
26  {
27  if constexpr (std::is_same_v<Sep, void>)
28  return Rule{} + _repeated_rule<I - 1>();
29  else
30  return Rule{} + typename Sep::rule{} + _repeated_rule<I - 1>();
31  }
32  }
33 
34  template <typename NextParser>
35  using p = lexy::parser_for<decltype(_repeated_rule()), NextParser>;
36 };
37 
39 template <std::size_t N, typename Rule>
40 constexpr auto times(Rule)
41 {
42  static_assert(N > 0);
43  return _times<N, Rule, void>{};
44 }
45 
47 template <std::size_t N, typename Rule, typename Sep>
48 constexpr auto times(Rule, Sep)
49 {
50  static_assert(N > 0);
51  static_assert(lexy::is_separator<Sep>);
52  return _times<N, Rule, Sep>{};
53 }
54 
55 template <typename Rule>
56 constexpr auto twice(Rule rule)
57 {
58  return times<2>(rule);
59 }
60 template <typename Rule, typename Sep>
61 constexpr auto twice(Rule rule, Sep sep)
62 {
63  return times<2>(rule, sep);
64 }
65 } // namespace lexyd
66 
67 #endif // LEXY_DSL_TIMES_HPP_INCLUDED
68 
lexyd::sep
constexpr auto sep(Branch)
Defines a separator for a list.
Definition: separator.hpp:91
lexyd::twice
constexpr auto twice(Rule rule)
Definition: times.hpp:56
sequence.hpp
lexyd::_times::p
lexy::parser_for< decltype(_repeated_rule()), NextParser > p
Definition: times.hpp:35
lexyd::_times::_repeated_rule
static constexpr auto _repeated_rule()
Definition: times.hpp:16
lexyd::rule_base
Definition: grammar.hpp:17
lexyd::_times
Definition: times.hpp:13
base.hpp
lexy::parser_for
typename Rule::template p< NextParser > parser_for
Definition: dsl/base.hpp:100
lexyd::times
constexpr auto times(Rule)
Repeats the rule N times in sequence.
Definition: times.hpp:40
lexyd
Definition: trace.hpp:22


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:08