ParseResult

sealed class ParseResult<out I : Any, out O, U : Any>

The result of running a Parser against a ParserInput.

Exactly one of two subtypes is returned:

  • Success — the parser matched and produced a value.

  • Failure — the parser did not match and produced a diagnostic message.

Exhaustive handling via when:

when (val result = parser(input)) {
is Success -> println("Parsed: ${result.value}")
is Failure -> println("Error at ${result.index}: ${result.message}")
}

Type parameters

  • I — the token type from the originating ParserInput. Covariant.

  • O — the output value type on success. Covariant; may be nullable. Failure fixes this to Nothing so a Failure<I, U> is a subtype of any ParseResult<I, O, U>.

  • U — the user context type. Invariant.

See also

Inheritors