Use result type query methods on Decoder.Result

This commit is contained in:
Josh Holtrop 2023-03-09 19:04:15 -05:00
parent b00f53050b
commit 30004c571d

View File

@ -38,30 +38,44 @@ class <%= @classname %>
{ {
struct Result struct Result
{ {
enum : ubyte enum Type
{ {
SUCCESS, SUCCESS,
EOF, EOF,
DECODE_ERROR, DECODE_ERROR,
} }
ubyte result; private Type type;
alias result this;
uint code_point; uint code_point;
uint code_point_length; uint code_point_length;
static Result success(uint code_point, uint code_point_length) static Result success(uint code_point, uint code_point_length)
{ {
return Result(SUCCESS, code_point, code_point_length); return Result(Type.SUCCESS, code_point, code_point_length);
}
bool is_success()
{
return type == Type.SUCCESS;
} }
static Result eof() static Result eof()
{ {
return Result(EOF); return Result(Type.EOF);
}
bool is_eof()
{
return type == Type.EOF;
} }
static Result decode_error() static Result decode_error()
{ {
return Result(DECODE_ERROR); return Result(Type.DECODE_ERROR);
}
bool is_decode_error()
{
return type == Type.DECODE_ERROR;
} }
} }
@ -255,13 +269,13 @@ class <%= @classname %>
for (;;) for (;;)
{ {
auto decoded = Decoder.decode_code_point(m_input[(m_input_position + attempt_match_info.length)..(m_input.length)]); auto decoded = Decoder.decode_code_point(m_input[(m_input_position + attempt_match_info.length)..(m_input.length)]);
if (decoded == Decoder.Result.DECODE_ERROR) if (decoded.is_decode_error())
{ {
lt.token = _TOKEN_DECODE_ERROR; lt.token = _TOKEN_DECODE_ERROR;
return lt; return lt;
} }
bool lex_continue = false; bool lex_continue = false;
if (decoded != Decoder.Result.EOF) if (!decoded.is_eof())
{ {
uint dest = transition(current_state, decoded.code_point); uint dest = transition(current_state, decoded.code_point);
if (dest != cast(uint)-1) if (dest != cast(uint)-1)