pLookAhead
Returns a Parser that runs parser and, if it succeeds, returns its value without consuming any input.
pLookAhead peeks ahead in the input: the index is always reset to its original position after a successful match. A failure from parser is propagated unchanged, also without consuming input.
Behaviour
| Condition | Result |
|---|---|
| parser succeeds | Success with parser's value; index unchanged |
| parser fails | Failure propagated from parser; index unchanged |
Type parameters
U — the user context type threaded through unchanged.
Example
val digit = pSatisfy<Char, Unit> { it.isDigit() }
val peek = pLookAhead(digit)
val input = ParserInput.of("1a".toList(), Unit)
val result = peek(input) // Success('1', nextIndex=0, ...) — index stays at 0Content copied to clipboard
Return
a Parser that succeeds without advancing the index.
Parameters
parser
the parser to run as a lookahead.