Header File lex/match_result.hpp
May 22, 2019 ยท View on GitHub
The file match_result.hpp defines the class lex::match_result, which is the result of a token match operation.
template <class TokenSpec>
struct match_result
{
token_kind<TokenSpec> kind;
std::size_t bump;
static match_result unmatched();
static match_result error(std::size_t bump);
static match_result success(token_kind<TokenSpec> kind, std::size_t bump);
static match_result eof();
bool is_unmatched() const;
bool is_error() const;
bool is_success() const;
bool is_eof() const;
bool is_matched() const;
};
All member functions are constexpr and noexcept.
Creation of a match_result is only possible using the named functions which put it in one of four states:
-
unmatched(): no token was matched. Thenkindis belex::error_tokenandbumpis0.is_unmatched()returnstrue, all others returnfalse. -
error(): the input is an error.Then
kindis belex::error_tokenandbumpis the number of characters to skip, which must be> 0.is_error()andis_matched()returntrue, all others returnfalse. -
success(): the input matched a token.Then
kindandbumpare as specified;bumpmust be greater than0andkindnotlex::error_tokenorlex::eof_token.is_success()andis_matched()returntrue, all others returnfalse. -
eof(): the end of the input was reached.Then
kindislex::eof_tokenandbumpis0.is_eof()andis_matched()returntrue, all others returnfalse.