pEof

fun <I : Any, U : Any> pEof(): Parser<I, Unit, U>

Returns a Parser that succeeds with Unit only when all input has been consumed, and fails if any tokens remain.

pEof is typically used at the end of a top-level parser to assert that the entire input was consumed and no trailing content was left unparsed.

Behaviour

ConditionResult
Input is exhaustedSuccess with Unit; index unchanged
Tokens remainFailure — "Expected end of input but got \ at index \"

Type parameters

  • I — the token type.

  • U — the user context type threaded through unchanged.

Example

val digit = pSatisfy<Char, Unit> { it.isDigit() }
val singleDigit = pAnd(digit, pEof())

val input = ParserInput.of("3".toList(), Unit)
val result = singleDigit(input) // Success(Pair('3', Unit), nextIndex=1, ...)

val tooLong = ParserInput.of("3x".toList(), Unit)
val result2 = singleDigit(tooLong) // Failure — 'x' remains

Return

a Parser that succeeds with Unit at end of input.

See also