/** * A {@link Parser} that returns {@code true} if {@code this} fails, {@code false} otherwise. */ public final Parser<Boolean> fails() { return ifelse(Parsers.FALSE, Parsers.TRUE); }
/** * A {@link Parser} that returns {@code true} if {@code this} succeeds, {@code false} otherwise. */ public final Parser<Boolean> succeeds() { return ifelse(Parsers.TRUE, Parsers.FALSE); }
/** * A {@link Parser} that runs {@code consequence} if {@code this} succeeds, or {@code alternative} otherwise. */ public final <R> Parser<R> ifelse(Parser<? extends R> consequence, Parser<? extends R> alternative) { return ifelse(__ -> consequence, alternative); }
/** * A {@link Parser} that fails if {@code this} succeeds. Any input consumption is undone. * * @param unexpected the name of what we don't expect. */ public final Parser<?> not(String unexpected) { return peek().ifelse(Parsers.unexpected(unexpected), Parsers.always()); }