import type { Parjser } from "../parjser"; import { ParjserBase } from "../parser"; import { ResultKind } from "../result"; import type { ParsingState } from "../state"; class Result extends ParjserBase { type = "result"; expecting = "expecting anything"; constructor(private value: T) { super(); } _apply(ps: ParsingState): void { ps.value = this.value; ps.kind = ResultKind.Ok; } } /** * Returns a parser that succeeds without consuming input and yields the constant `value`. * * @param value The value the returned parser will yield. */ export function result(value: T): Parjser { return new Result(value); }