pNot
Returns a Parser that succeeds with Unit when parser would fail at the current position, and fails when parser would succeed. No input is consumed in either case.
pNot is a negative lookahead: it inverts the success/failure of parser without ever advancing the index. Use it to assert that a particular pattern does not appear at the current position before committing to another parse.
Behaviour
| Condition | Result |
|---|---|
| parser fails | Success with Unit; index unchanged |
| parser succeeds | Failure — "Unexpected match at index \ |
Type parameters
Example
val notDigit = pNot(pSatisfy<Char, Unit> { it.isDigit() })
val input = ParserInput.of("a1".toList(), Unit)
val result = notDigit(input) // Success(Unit, nextIndex=0, ...) — 'a' is not a digit
val digits = ParserInput.of("1a".toList(), Unit)
val result2 = notDigit(digits) // Failure — '1' would have matchedContent copied to clipboard
Return
a Parser that succeeds with Unit only when parser would fail.
Parameters
parser
the parser whose failure is required.