import type { Parser } from "../api.js" ; remarks Depending on `capture` (default: false), the result of the `ahead`
 * parser is captured or omitted and the final read position is adjusted
 * accordingly.
 *
 * Currently, iff `capture` is disabled, the `ahead` parser MUST discard
 * its own result (e.g. via  discard ). On successful match the
 * final read position will then be restored to the beginning of `ahead`
 * pattern.
 *
 * Iff `capture` is enabled, the `ahead` parser MAY discard its own
 * result, but the final read position will not be re-adjusted as in the
 * non-capturing version.
 *
 * **Important:** Since the main term will be repeated automatically, DO
 * NOT use repetition modifiers `?` or `*`, since both of these will
 * cause the parser to go into an infinite loop. This is expected
 * behavior and not a bug.
 *
 *  example example param parser param ahead param capture param id export const lookahead = < T > ( parser , ahead , capture = false , id = "lookahead" ) : Parser < T > => ( ctx ) => { if ( ctx . done ) return false ; ctx . start ( id ) ; let pass = false ; while ( true ) { const state = capture ? null : { ... ctx . state } ; if ( ahead ( ctx ) ) { ! capture && ( ctx . state = state ! ) ; return pass ? ctx . end ( ) : ctx . discard ( ) ; } if ( ! parser ( ctx ) ) return ctx . discard ( ) ; pass = true ; } } ;