not
not(p: Parser, m?: string): Parser
Applies a parser and succeeds without consuming input if that parser fails.
not cannot feasibly produce an automatic error message on failure. To add an error message, pass an expected error message in as the second argument.
Example
const parser = not(digit())
const s = parse(parser, 'a')
console.log(status(s)) // "ok"
console.log(success(s)) // null
const f = parse(parser, '1')
console.log(status(f)) // "fail"
console.log(failure(f)) // Parse error at (line 1, column 1):
//
// 1
// ^
// Unknown message(s)
Parameters
p: The parser to apply. If it fails,notsucceeds.m: The optional expected message that will be added ifnotfails.
Success
- Succeeds if
pfails or fails fatally. Does not consume input or return a result.
Failure
- Fails if
psucceeds. No input is consumed and the state is not changed.
Throws
- Throws an error if
pis not a parser. - Throws an error if
mexists and is not a string.