pLabel
Returns a Parser that runs parser and, if it fails, replaces the failure message with message.
pLabel is the primary way to produce human-readable error messages. Instead of exposing low-level diagnostic text from pSatisfy or nested combinators, wrap a parser in pLabel to emit a single, intent-describing message when it fails.
On success the result is passed through unchanged.
Behaviour
| Condition | Result |
|---|---|
| parser succeeds | Success propagated unchanged |
| parser fails | Failure with message; index and input from the original failure |
Type parameters
U — the user context type threaded through unchanged.
Example
val digit = pLabel(pSatisfy<Char, Unit> { it.isDigit() }, "a digit")
val input = ParserInput.of("abc".toList(), Unit)
val result = digit(input)
// Failure("a digit", index=0, ...)Content copied to clipboard
Return
a Parser that propagates success and replaces failure messages.
Parameters
parser
the parser to run.
message
the failure message to use when parser fails.