if.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_DSL_IF_HPP_INCLUDED
5 #define LEXY_DSL_IF_HPP_INCLUDED
6 
7 #include <lexy/dsl/base.hpp>
8 #include <lexy/dsl/branch.hpp>
9 
10 namespace lexyd
11 {
12 template <typename Branch>
13 struct _if : rule_base
14 {
15  template <typename NextParser>
16  struct p
17  {
18  template <typename Context, typename Reader, typename... Args>
19  LEXY_PARSER_FUNC static bool parse(Context& context, Reader& reader, Args&&... args)
20  {
22  if (branch.try_parse(context.control_block, reader))
23  // We take the branch.
24  return branch.template finish<NextParser>(context, reader, LEXY_FWD(args)...);
25  else
26  {
27  // We don't take the branch.
28  branch.cancel(context);
29  return NextParser::parse(context, reader, LEXY_FWD(args)...);
30  }
31  }
32  };
33 };
34 
36 template <typename Branch>
37 constexpr auto if_(Branch)
38 {
39  LEXY_REQUIRE_BRANCH_RULE(Branch, "if()");
40  if constexpr (lexy::is_unconditional_branch_rule<Branch>)
41  // Branch is always taken, so don't wrap in if_().
42  return Branch{};
43  else
44  return _if<Branch>{};
45 }
46 } // namespace lexyd
47 
48 #endif // LEXY_DSL_IF_HPP_INCLUDED
49 
lexy::branch_parser_for
typename BranchRule::template bp< Reader > branch_parser_for
Definition: dsl/base.hpp:116
LEXY_FWD
#define LEXY_FWD(...)
Definition: config.hpp:30
LEXY_REQUIRE_BRANCH_RULE
#define LEXY_REQUIRE_BRANCH_RULE(Rule, Name)
Definition: grammar.hpp:73
lexyd::_if::p::parse
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
Definition: if.hpp:19
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::rule_base
Definition: grammar.hpp:17
lexyd::_if
Definition: if.hpp:13
LEXY_PARSER_FUNC
#define LEXY_PARSER_FUNC
Definition: dsl/base.hpp:108
base.hpp
lexyd::if_
constexpr auto if_(Branch)
If the branch condition matches, matches the branch then.
Definition: if.hpp:37
lexyd::_if::p
Definition: if.hpp:16
lexyd
Definition: trace.hpp:22
branch.hpp


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