module /** */ import { ParsingState } from "../state" ; import { ParjsCombinator } from "../../" ; import { ParjserBase } from "../parser" ; import { defineCombinator } from "./combinator" ; /**
 * Applies the source parser. If it succeeds, backtracks to the current position in the input
 * and yields the result.
 */ export function backtrack < T > ( ) { return defineCombinator ( source => { return new class Backtrack extends ParjserBase { type = "backtrack" ; expecting = source . expecting ; _apply ( ps ) { let { position } = ps ; source . apply ( ps ) ; if ( ps . isOk ) { ps . position = position ; } } } ( ) ; } ) ; }