position.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_POSITION_HPP_INCLUDED
5 #define LEXY_DSL_POSITION_HPP_INCLUDED
6 
7 #include <lexy/dsl/base.hpp>
8 
9 namespace lexyd
10 {
11 struct _pos : rule_base
12 {
13  template <typename NextParser>
14  struct p
15  {
16  template <typename Context, typename Reader, typename... Args>
17  LEXY_PARSER_FUNC static bool parse(Context& context, Reader& reader, Args&&... args)
18  {
19  auto pos = reader.position();
20  context.on(_ev::token{}, lexy::position_token_kind, pos, pos);
21  return NextParser::parse(context, reader, LEXY_FWD(args)..., pos);
22  }
23  };
24 };
25 
26 template <typename Rule>
27 struct _posr : _copy_base<Rule>
28 {
29  template <typename Reader>
30  struct bp
31  {
33 
34  template <typename ControlBlock>
35  constexpr auto try_parse(const ControlBlock* cb, const Reader& reader)
36  {
37  return rule.try_parse(cb, reader);
38  }
39 
40  template <typename Context>
41  constexpr void cancel(Context& context)
42  {
43  rule.cancel(context);
44  }
45 
46  template <typename NextParser, typename Context, typename... Args>
47  LEXY_PARSER_FUNC auto finish(Context& context, Reader& reader, Args&&... args)
48  {
49  auto pos = reader.position();
50  context.on(_ev::token{}, lexy::position_token_kind, pos, pos);
51  return rule.template finish<NextParser>(context, reader, LEXY_FWD(args)..., pos);
52  }
53  };
54 
55  template <typename NextParser>
56  struct p
57  {
58  template <typename Context, typename Reader, typename... Args>
59  LEXY_PARSER_FUNC static bool parse(Context& context, Reader& reader, Args&&... args)
60  {
61  auto pos = reader.position();
62  context.on(_ev::token{}, lexy::position_token_kind, pos, pos);
63  return lexy::parser_for<Rule, NextParser>::parse(context, reader, LEXY_FWD(args)...,
64  pos);
65  }
66  };
67 };
68 
69 struct _pos_dsl : _pos
70 {
71  template <typename Rule>
72  constexpr auto operator()(Rule) const
73  {
74  return _posr<Rule>{};
75  }
76 };
77 
79 constexpr auto position = _pos_dsl{};
80 } // namespace lexyd
81 
82 #endif // LEXY_DSL_POSITION_HPP_INCLUDED
83 
lexyd::position
constexpr auto position
Produces an iterator to the current reader position without parsing anything.
Definition: position.hpp:79
lexyd::_posr::bp::rule
lexy::branch_parser_for< Rule, Reader > rule
Definition: position.hpp:32
lexyd::_pos
Definition: position.hpp:11
lexyd::_posr
Definition: position.hpp:27
lexy::position_token_kind
@ position_token_kind
Definition: grammar.hpp:82
lexy::branch_parser_for
typename BranchRule::template bp< Reader > branch_parser_for
Definition: dsl/base.hpp:103
lexyd::_pos::p
Definition: position.hpp:14
LEXY_FWD
#define LEXY_FWD(...)
Definition: config.hpp:22
lexyd::_posr::bp
Definition: position.hpp:30
lexyd::_pos_dsl
Definition: position.hpp:69
lexyd::_posr::bp::try_parse
constexpr auto try_parse(const ControlBlock *cb, const Reader &reader)
Definition: position.hpp:35
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::_posr::bp::finish
LEXY_PARSER_FUNC auto finish(Context &context, Reader &reader, Args &&... args)
Definition: position.hpp:47
lexyd::_posr::p
Definition: position.hpp:56
lexyd::rule_base
Definition: grammar.hpp:17
LEXY_PARSER_FUNC
#define LEXY_PARSER_FUNC
Definition: dsl/base.hpp:95
lexyd::_posr::p::parse
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
Definition: position.hpp:59
base.hpp
lexy::parse_events::token
Definition: dsl/base.hpp:44
lexyd::_posr::bp::cancel
constexpr void cancel(Context &context)
Definition: position.hpp:41
lexyd::_pos_dsl::operator()
constexpr auto operator()(Rule) const
Definition: position.hpp:72
lexyd::_pos::p::parse
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
Definition: position.hpp:17
lexyd
Definition: trace.hpp:22
lexyd::_copy_base
decltype(_copy_base_impl< Rule >()) _copy_base
Definition: dsl/base.hpp:91


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