Echo Writes Code

result.inl

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_INL
#define CRUCIBLE_PARSING_RESULT_INL

#include "crucible/parsing/result.hpp"

namespace crucible::parsing::result {
  template<typename STATE, typename ERROR>
  Reject<STATE, ERROR>::Reject(STATE const &state, ERROR const &error) :
    my_state(state),
    my_error(error) {
  }

  template<typename STATE, typename ERROR>
  auto Reject<STATE, ERROR>::get_state() const -> STATE {
    return my_state;
  }

  template<typename STATE, typename ERROR>
  auto Reject<STATE, ERROR>::get_error() const -> ERROR {
    return my_error;
  }

  template<typename STATE, typename VALUE>
  Accept<STATE, VALUE>::Accept(STATE const &state, VALUE const &value) :
    my_state(state),
    my_value(value) {
  }

  template<typename STATE, typename VALUE>
  auto Accept<STATE, VALUE>::get_state() const -> STATE {
    return my_state;
  }

  template<typename STATE, typename VALUE>
  auto Accept<STATE, VALUE>::get_value() const -> VALUE {
    return my_value;
  }

  template<typename STATE, typename ERROR>
  auto reject(STATE const &state, ERROR const &error) -> core::result::Failure<Reject<STATE, ERROR>> {
    return core::result::make_failure<Reject<STATE, ERROR>>(state, error);
  }

  template<typename STATE, typename VALUE>
  auto accept(STATE const &state, VALUE const &value) -> core::result::Success<Accept<STATE, VALUE>> {
    return core::result::make_success<Accept<STATE, VALUE>>(state, value);
  }
}

#endif // CRUCIBLE_PARSING_RESULT_INL