Echo Writes Code

result.hpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef CRUCIBLE_PARSING_RESULT_HPP
#define CRUCIBLE_PARSING_RESULT_HPP

#include "crucible/core/result.inl"

namespace crucible::parsing::result {
  template<typename STATE, typename ERROR>
  class Reject final {
  public:
    Reject(STATE const &state, ERROR const &error);

    [[nodiscard]]
    auto get_state() const -> STATE;

    [[nodiscard]]
    auto get_error() const -> ERROR;

  private:
    STATE my_state {};

    ERROR my_error {};
  };

  template<typename STATE, typename VALUE>
  class Accept final {
  public:
    Accept(STATE const &state, VALUE const &value);

    [[nodiscard]]
    auto get_state() const -> STATE;

    [[nodiscard]]
    auto get_value() const -> VALUE;

  private:
    STATE my_state {};

    VALUE my_value {};
  };

  template<typename STATE, typename ERROR>
  [[nodiscard]]
  auto reject(STATE const &state, ERROR const &error) -> core::result::Failure<Reject<STATE, ERROR>>;

  template<typename STATE, typename VALUE>
  [[nodiscard]]
  auto accept(STATE const &state, VALUE const &value) -> core::result::Success<Accept<STATE, VALUE>>;
}

#endif // CRUCIBLE_PARSING_RESULT_HPP