module /** */ import { ResultKind } from "../result" ; import { ParsingState } from "../state" ; import { ParjsCombinator } from "../../" ; import { defineCombinator } from "./combinator" ; import { ParjserBase } from "../parser" ; /**
 * Applies the source parser. Succeeds if if it fails softly, and fails otherwise.
 */ export function not ( ) { return defineCombinator ( source => { return new class Not extends ParjserBase { type = "not" ; expecting = `not expecting: ${ source . expecting }` ; _apply ( ps ) { let { position } = ps ; source . apply ( ps ) ; if ( ps . isOk ) { ps . position = position ; ps . kind = ResultKind . SoftFail ; } else if ( ps . kind === ResultKind . HardFail || ps . kind === ResultKind . SoftFail ) { ps . kind = ResultKind . Ok ; ps . position = position ; return ; } } } ( ) ; } ) ; }