import type { ImplicitParjser, ParjsCombinator } from "../../index"; import { wrapImplicit } from "../wrap-implicit"; import { defineCombinator } from "./combinator"; import { qthen, thenq } from "./then"; /** * Applies `pre`, the source parser, and then `post`. Yields the result of the source parser. * * @param pre The parser to precede the source. * @param post The parser to proceed the source. */ export function between( pre: ImplicitParjser, post: ImplicitParjser ): ParjsCombinator; /** * Applies the `surrounding` parser, followed by the source parser, and then another instance of * `surrounding`. Yields the result of the source parser. * * @param surrounding The parser to apply before and after the source. */ export function between(surrounding: ImplicitParjser): ParjsCombinator; export function between( implPre: ImplicitParjser, implPost?: ImplicitParjser ): ParjsCombinator { const pre = wrapImplicit(implPre); const post = implPost ? wrapImplicit(implPost) : pre; return defineCombinator(source => { return pre.pipe(qthen(source), thenq(post)); }); }