Echo Writes Code

errors.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_ERRORS_INL
#define CRUCIBLE_PARSING_ERRORS_INL

#include "crucible/parsing/errors.hpp"

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

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

  template<typename STATE>
  auto Reject<STATE>::get_error() const -> ParsingError {
    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 make_reject(STATE const &state, ERROR const &error) -> core::either::Lhs<Reject<STATE>> {
    return core::either::make_lhs<Reject<STATE>>(state, ParsingError { error });
  }

  template<typename STATE, typename VALUE>
  auto make_accept(STATE const &state, VALUE const &value) -> core::either::Rhs<Accept<STATE, VALUE>> {
    return core::either::make_rhs<Accept<STATE, VALUE>>(state, value);
  }
}

#endif // CRUCIBLE_PARSING_ERRORS_INL