pEof
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
| Condition | Result |
|---|---|
| Input is exhausted | Success with Unit; index unchanged |
| Tokens remain | Failure — "Expected end of input but got \ |
Type parameters
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' remainsContent copied to clipboard