String module

parse_enum

procedure · 1 overloadSource

Reads the next token and looks it up by name among the values of the enum type T. The second result is false when no value has that name, and then the value is zero. The name is case sensitive.

parse_enum :: (
    line: *string,
    $T: Type,
    delimiters := DEFAULT_DELIMITERS,
    spaces := DEFAULT_SPACES
) -> (value: T, success: bool)

Parameters

line: *string
$T: Type
delimiters := DEFAULT_DELIMITERS
spaces := DEFAULT_SPACES

Returns

value: T
success: bool
ExampleOpen in playground ↗
Color :: enum { RED; GREEN; }

line := "GREEN;";
value, ok := parse_enum(*line, Color);
assert(ok && value == .GREEN && line == ";");

See also